Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

183 rindas
4.1 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains the libcaca DOS/conio.h input and output driver
  16. */
  17. #include "config.h"
  18. #include "common.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 <stdlib.h>
  26. #include "caca.h"
  27. #include "caca_internals.h"
  28. #include "cucul.h"
  29. #include "cucul_internals.h"
  30. struct driver_private
  31. {
  32. struct text_info ti;
  33. char *screen;
  34. };
  35. static int conio_init_graphics(caca_display_t *dp)
  36. {
  37. dp->drv.p = malloc(sizeof(struct driver_private));
  38. _wscroll = 0;
  39. _setcursortype(_NOCURSOR);
  40. clrscr();
  41. gettextinfo(&dp->drv.p->ti);
  42. dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
  43. * dp->drv.p->ti.screenheight * sizeof(char));
  44. if(dp->drv.p->screen == NULL)
  45. return -1;
  46. # if defined(SCREENUPDATE_IN_PC_H)
  47. ScreenRetrieve(dp->drv.p->screen);
  48. # else
  49. /* FIXME */
  50. # endif
  51. __cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
  52. dp->drv.p->ti.screenheight);
  53. return 0;
  54. }
  55. static int conio_end_graphics(caca_display_t *dp)
  56. {
  57. _wscroll = 1;
  58. textcolor((enum COLORS)WHITE);
  59. textbackground((enum COLORS)BLACK);
  60. gotoxy(dp->cv->width, dp->cv->height);
  61. cputs("\r\n");
  62. _setcursortype(_NORMALCURSOR);
  63. free(dp->drv.p->screen);
  64. free(dp->drv.p);
  65. return 0;
  66. }
  67. static int conio_set_display_title(caca_display_t *dp, char const *title)
  68. {
  69. return -1;
  70. }
  71. static unsigned int conio_get_display_width(caca_display_t const *dp)
  72. {
  73. /* Fallback to a 6x10 font */
  74. return dp->cv->width * 6;
  75. }
  76. static unsigned int conio_get_display_height(caca_display_t const *dp)
  77. {
  78. /* Fallback to a 6x10 font */
  79. return dp->cv->height * 10;
  80. }
  81. static void conio_display(caca_display_t *dp)
  82. {
  83. char *screen = dp->drv.p->screen;
  84. uint32_t *attrs = dp->cv->attrs;
  85. uint32_t *chars = dp->cv->chars;
  86. unsigned int n;
  87. for(n = dp->cv->height * dp->cv->width; n--; )
  88. {
  89. char ch = cucul_utf32_to_cp437(*chars++);
  90. if(n && *chars == CUCUL_MAGIC_FULLWIDTH)
  91. {
  92. *screen++ = '[';
  93. *screen++ = cucul_attr_to_ansi(*attrs++);
  94. ch = ']';
  95. chars++;
  96. n--;
  97. }
  98. *screen++ = ch;
  99. *screen++ = cucul_attr_to_ansi(*attrs++);
  100. }
  101. # if defined(SCREENUPDATE_IN_PC_H)
  102. ScreenUpdate(dp->drv.p->screen);
  103. # else
  104. /* FIXME */
  105. # endif
  106. }
  107. static void conio_handle_resize(caca_display_t *dp)
  108. {
  109. /* We know nothing about our window */
  110. dp->resize.w = dp->cv->width;
  111. dp->resize.h = dp->cv->height;
  112. }
  113. static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev)
  114. {
  115. unsigned char ch;
  116. caca_privevent_t release;
  117. if(!_conio_kbhit())
  118. {
  119. ev->type = CACA_EVENT_NONE;
  120. return 0;
  121. }
  122. ch = getch();
  123. ev->type = CACA_EVENT_KEY_PRESS;
  124. ev->data.key.ch = ch;
  125. ev->data.key.utf32 = (uint32_t)ch;
  126. ev->data.key.utf8[0] = ch;
  127. ev->data.key.utf8[1] = '\0';
  128. release = *ev;
  129. release.type = CACA_EVENT_KEY_RELEASE;
  130. _push_event(dp, &release);
  131. return 1;
  132. }
  133. /*
  134. * Driver initialisation
  135. */
  136. int conio_install(caca_display_t *dp)
  137. {
  138. dp->drv.driver = CACA_DRIVER_CONIO;
  139. dp->drv.init_graphics = conio_init_graphics;
  140. dp->drv.end_graphics = conio_end_graphics;
  141. dp->drv.set_display_title = conio_set_display_title;
  142. dp->drv.get_display_width = conio_get_display_width;
  143. dp->drv.get_display_height = conio_get_display_height;
  144. dp->drv.display = conio_display;
  145. dp->drv.handle_resize = conio_handle_resize;
  146. dp->drv.get_event = conio_get_event;
  147. dp->drv.set_mouse = NULL;
  148. dp->drv.set_cursor = NULL;
  149. return 0;
  150. }
  151. #endif /* USE_CONIO */