Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

171 righe
3.7 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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains the libcaca DOS/conio.h input and output driver
  15. */
  16. #include "config.h"
  17. #if defined(USE_CONIO)
  18. #include <dos.h>
  19. #include <conio.h>
  20. #if defined(SCREENUPDATE_IN_PC_H)
  21. # include <pc.h>
  22. #endif
  23. #include <stdlib.h>
  24. #include "caca.h"
  25. #include "caca_internals.h"
  26. #include "cucul.h"
  27. #include "cucul_internals.h"
  28. struct driver_private
  29. {
  30. struct text_info ti;
  31. char *screen;
  32. };
  33. static int conio_init_graphics(caca_t *kk)
  34. {
  35. kk->drv.p = malloc(sizeof(struct driver_private));
  36. _wscroll = 0;
  37. _setcursortype(_NOCURSOR);
  38. clrscr();
  39. gettextinfo(&kk->drv.p->ti);
  40. kk->drv.p->screen = malloc(2 * kk->drv.p->ti.screenwidth
  41. * kk->drv.p->ti.screenheight * sizeof(char));
  42. if(kk->drv.p->screen == NULL)
  43. return -1;
  44. # if defined(SCREENUPDATE_IN_PC_H)
  45. ScreenRetrieve(kk->drv.p->screen);
  46. # else
  47. /* FIXME */
  48. # endif
  49. _cucul_set_size(kk->qq, kk->drv.p->ti.screenwidth,
  50. kk->drv.p->ti.screenheight);
  51. return 0;
  52. }
  53. static int conio_end_graphics(caca_t *kk)
  54. {
  55. _wscroll = 1;
  56. textcolor((enum COLORS)WHITE);
  57. textbackground((enum COLORS)BLACK);
  58. gotoxy(kk->qq->width, kk->qq->height);
  59. cputs("\r\n");
  60. _setcursortype(_NORMALCURSOR);
  61. free(kk->drv.p->screen);
  62. free(kk->drv.p);
  63. return 0;
  64. }
  65. static int conio_set_window_title(caca_t *kk, char const *title)
  66. {
  67. return 0;
  68. }
  69. static unsigned int conio_get_window_width(caca_t *kk)
  70. {
  71. /* Fallback to a 6x10 font */
  72. return kk->qq->width * 6;
  73. }
  74. static unsigned int conio_get_window_height(caca_t *kk)
  75. {
  76. /* Fallback to a 6x10 font */
  77. return kk->qq->height * 10;
  78. }
  79. static void conio_display(caca_t *kk)
  80. {
  81. char *screen = kk->drv.p->screen;
  82. uint32_t *attr = kk->qq->attr;
  83. uint32_t *chars = kk->qq->chars;
  84. int n;
  85. for(n = kk->qq->height * kk->qq->width; n--; )
  86. {
  87. *screen++ = _cucul_utf32_to_cp437(*chars++);
  88. *screen++ = _cucul_argb32_to_ansi8(*attr++);
  89. }
  90. # if defined(SCREENUPDATE_IN_PC_H)
  91. ScreenUpdate(kk->drv.p->screen);
  92. # else
  93. /* FIXME */
  94. # endif
  95. }
  96. static void conio_handle_resize(caca_t *kk)
  97. {
  98. /* We know nothing about our window */
  99. kk->resize.w = kk->qq->width;
  100. kk->resize.h = kk->qq->height;
  101. }
  102. static int conio_get_event(caca_t *kk, caca_event_t *ev)
  103. {
  104. unsigned char ch;
  105. caca_event_t release;
  106. if(!_conio_kbhit())
  107. {
  108. ev->type = CACA_EVENT_NONE;
  109. return 0;
  110. }
  111. ch = getch();
  112. ev->type = CACA_EVENT_KEY_PRESS;
  113. ev->data.key.c = ch;
  114. ev->data.key.ucs4 = (uint32_t)ch;
  115. ev->data.key.utf8[0] = ch;
  116. ev->data.key.utf8[1] = '\0';
  117. release = *ev;
  118. release.type = CACA_EVENT_KEY_RELEASE;
  119. _push_event(kk, &release);
  120. return 1;
  121. }
  122. /*
  123. * Driver initialisation
  124. */
  125. int conio_install(caca_t *kk)
  126. {
  127. kk->drv.driver = CACA_DRIVER_CONIO;
  128. kk->drv.init_graphics = conio_init_graphics;
  129. kk->drv.end_graphics = conio_end_graphics;
  130. kk->drv.set_window_title = conio_set_window_title;
  131. kk->drv.get_window_width = conio_get_window_width;
  132. kk->drv.get_window_height = conio_get_window_height;
  133. kk->drv.display = conio_display;
  134. kk->drv.handle_resize = conio_handle_resize;
  135. kk->drv.get_event = conio_get_event;
  136. kk->drv.set_mouse = NULL;
  137. return 0;
  138. }
  139. #endif /* USE_CONIO */