You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * libcaca ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Do What The Fuck You Want To
  8. * Public License, Version 2, as published by Sam Hocevar. See
  9. * http://sam.zoy.org/wtfpl/COPYING for more details.
  10. */
  11. /** \file driver_conio.c
  12. * \version \$Id$
  13. * \author Sam Hocevar <sam@zoy.org>
  14. * \brief DOS/conio.h driver
  15. *
  16. * This file contains the libcaca DOS/conio.h input and output driver
  17. */
  18. #include "config.h"
  19. #if defined(USE_CONIO)
  20. #include <dos.h>
  21. #include <conio.h>
  22. #if defined(SCREENUPDATE_IN_PC_H)
  23. # include <pc.h>
  24. #endif
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #if defined(HAVE_UNISTD_H)
  28. # include <unistd.h>
  29. #endif
  30. #include <stdarg.h>
  31. #if defined(HAVE_SYS_IOCTL_H)
  32. # include <sys/ioctl.h>
  33. #endif
  34. #include "caca.h"
  35. #include "caca_internals.h"
  36. #include "cucul.h"
  37. #include "cucul_internals.h"
  38. static int conio_init_graphics(caca_t *kk)
  39. {
  40. _wscroll = 0;
  41. _setcursortype(_NOCURSOR);
  42. clrscr();
  43. gettextinfo(&kk->conio.ti);
  44. kk->conio.screen = malloc(2 * kk->conio.ti.screenwidth
  45. * kk->conio.ti.screenheight * sizeof(char));
  46. if(kk->conio.screen == NULL)
  47. return -1;
  48. # if defined(SCREENUPDATE_IN_PC_H)
  49. ScreenRetrieve(kk->conio.screen);
  50. # else
  51. /* FIXME */
  52. # endif
  53. cucul_set_size(kk->qq, kk->conio.ti.screenwidth,
  54. kk->conio.ti.screenheight);
  55. return 0;
  56. }
  57. static int conio_end_graphics(caca_t *kk)
  58. {
  59. _wscroll = 1;
  60. textcolor((enum COLORS)WHITE);
  61. textbackground((enum COLORS)BLACK);
  62. gotoxy(_caca_width, _caca_height);
  63. cputs("\r\n");
  64. _setcursortype(_NORMALCURSOR);
  65. free(kk->conio.screen);
  66. return 0;
  67. }
  68. static int conio_set_window_title(caca_t *kk, char const *title)
  69. {
  70. return 0;
  71. }
  72. static unsigned int conio_get_window_width(caca_t *kk)
  73. {
  74. /* Fallback to a 6x10 font */
  75. return kk->qq->width * 6;
  76. }
  77. static unsigned int conio_get_window_height(caca_t *kk)
  78. {
  79. /* Fallback to a 6x10 font */
  80. return kk->qq->height * 10;
  81. }
  82. static void conio_display(caca_t *kk)
  83. {
  84. int n;
  85. char *screen = kk->conio.screen;
  86. uint8_t *attr = kk->qq->attr;
  87. uint32_t *chars = kk->qq->chars;
  88. for(n = kk->qq->height * kk->qq->width; n--; )
  89. {
  90. *screen++ = *chars++ & 0x7f;
  91. *screen++ = *attr++;
  92. }
  93. # if defined(SCREENUPDATE_IN_PC_H)
  94. ScreenUpdate(kk->conio.screen);
  95. # else
  96. /* FIXME */
  97. # endif
  98. }
  99. static void conio_handle_resize(caca_t *kk, unsigned int *new_width,
  100. unsigned int *new_height)
  101. {
  102. *new_width = kk->qq->width;
  103. *new_height = kk->qq->height;
  104. }
  105. /*
  106. * Driver initialisation
  107. */
  108. void conio_init_driver(caca_t *kk)
  109. {
  110. kk->driver.driver = CACA_DRIVER_CONIO;
  111. kk->driver.init_graphics = conio_init_graphics;
  112. kk->driver.end_graphics = conio_end_graphics;
  113. kk->driver.set_window_title = conio_set_window_title;
  114. kk->driver.get_window_width = conio_get_window_width;
  115. kk->driver.get_window_height = conio_get_window_height;
  116. kk->driver.display = conio_display;
  117. kk->driver.handle_resize = conio_handle_resize;
  118. }
  119. #endif /* USE_CONIO */