選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

172 行
3.8 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. #include "common.h"
  18. #if defined(USE_CONIO)
  19. #include <dos.h>
  20. #include <conio.h>
  21. #if defined(SCREENUPDATE_IN_PC_H)
  22. # include <pc.h>
  23. #endif
  24. #include <stdlib.h>
  25. #include "caca.h"
  26. #include "caca_internals.h"
  27. #include "cucul.h"
  28. #include "cucul_internals.h"
  29. struct driver_private
  30. {
  31. struct text_info ti;
  32. char *screen;
  33. };
  34. static int conio_init_graphics(caca_display_t *dp)
  35. {
  36. dp->drv.p = malloc(sizeof(struct driver_private));
  37. _wscroll = 0;
  38. _setcursortype(_NOCURSOR);
  39. clrscr();
  40. gettextinfo(&dp->drv.p->ti);
  41. dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
  42. * dp->drv.p->ti.screenheight * sizeof(char));
  43. if(dp->drv.p->screen == NULL)
  44. return -1;
  45. # if defined(SCREENUPDATE_IN_PC_H)
  46. ScreenRetrieve(dp->drv.p->screen);
  47. # else
  48. /* FIXME */
  49. # endif
  50. _cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
  51. dp->drv.p->ti.screenheight);
  52. return 0;
  53. }
  54. static int conio_end_graphics(caca_display_t *dp)
  55. {
  56. _wscroll = 1;
  57. textcolor((enum COLORS)WHITE);
  58. textbackground((enum COLORS)BLACK);
  59. gotoxy(dp->cv->width, dp->cv->height);
  60. cputs("\r\n");
  61. _setcursortype(_NORMALCURSOR);
  62. free(dp->drv.p->screen);
  63. free(dp->drv.p);
  64. return 0;
  65. }
  66. static int conio_set_display_title(caca_display_t *dp, char const *title)
  67. {
  68. return 0;
  69. }
  70. static unsigned int conio_get_display_width(caca_display_t *dp)
  71. {
  72. /* Fallback to a 6x10 font */
  73. return dp->cv->width * 6;
  74. }
  75. static unsigned int conio_get_display_height(caca_display_t *dp)
  76. {
  77. /* Fallback to a 6x10 font */
  78. return dp->cv->height * 10;
  79. }
  80. static void conio_display(caca_display_t *dp)
  81. {
  82. char *screen = dp->drv.p->screen;
  83. uint32_t *attr = dp->cv->attr;
  84. uint32_t *chars = dp->cv->chars;
  85. int n;
  86. for(n = dp->cv->height * dp->cv->width; n--; )
  87. {
  88. *screen++ = _cucul_utf32_to_cp437(*chars++);
  89. *screen++ = _cucul_argb32_to_ansi8(*attr++);
  90. }
  91. # if defined(SCREENUPDATE_IN_PC_H)
  92. ScreenUpdate(dp->drv.p->screen);
  93. # else
  94. /* FIXME */
  95. # endif
  96. }
  97. static void conio_handle_resize(caca_display_t *dp)
  98. {
  99. /* We know nothing about our window */
  100. dp->resize.w = dp->cv->width;
  101. dp->resize.h = dp->cv->height;
  102. }
  103. static int conio_get_event(caca_display_t *dp, caca_event_t *ev)
  104. {
  105. unsigned char ch;
  106. caca_event_t release;
  107. if(!_conio_kbhit())
  108. {
  109. ev->type = CACA_EVENT_NONE;
  110. return 0;
  111. }
  112. ch = getch();
  113. ev->type = CACA_EVENT_KEY_PRESS;
  114. ev->data.key.ch = ch;
  115. ev->data.key.utf32 = (uint32_t)ch;
  116. ev->data.key.utf8[0] = ch;
  117. ev->data.key.utf8[1] = '\0';
  118. release = *ev;
  119. release.type = CACA_EVENT_KEY_RELEASE;
  120. _push_event(dp, &release);
  121. return 1;
  122. }
  123. /*
  124. * Driver initialisation
  125. */
  126. int conio_install(caca_display_t *dp)
  127. {
  128. dp->drv.driver = CACA_DRIVER_CONIO;
  129. dp->drv.init_graphics = conio_init_graphics;
  130. dp->drv.end_graphics = conio_end_graphics;
  131. dp->drv.set_display_title = conio_set_display_title;
  132. dp->drv.get_display_width = conio_get_display_width;
  133. dp->drv.get_display_height = conio_get_display_height;
  134. dp->drv.display = conio_display;
  135. dp->drv.handle_resize = conio_handle_resize;
  136. dp->drv.get_event = conio_get_event;
  137. dp->drv.set_mouse = NULL;
  138. return 0;
  139. }
  140. #endif /* USE_CONIO */