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.
 
 
 
 
 
 

171 lines
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. #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_display_t *dp)
  34. {
  35. dp->drv.p = malloc(sizeof(struct driver_private));
  36. _wscroll = 0;
  37. _setcursortype(_NOCURSOR);
  38. clrscr();
  39. gettextinfo(&dp->drv.p->ti);
  40. dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
  41. * dp->drv.p->ti.screenheight * sizeof(char));
  42. if(dp->drv.p->screen == NULL)
  43. return -1;
  44. # if defined(SCREENUPDATE_IN_PC_H)
  45. ScreenRetrieve(dp->drv.p->screen);
  46. # else
  47. /* FIXME */
  48. # endif
  49. _cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
  50. dp->drv.p->ti.screenheight);
  51. return 0;
  52. }
  53. static int conio_end_graphics(caca_display_t *dp)
  54. {
  55. _wscroll = 1;
  56. textcolor((enum COLORS)WHITE);
  57. textbackground((enum COLORS)BLACK);
  58. gotoxy(dp->cv->width, dp->cv->height);
  59. cputs("\r\n");
  60. _setcursortype(_NORMALCURSOR);
  61. free(dp->drv.p->screen);
  62. free(dp->drv.p);
  63. return 0;
  64. }
  65. static int conio_set_display_title(caca_display_t *dp, char const *title)
  66. {
  67. return 0;
  68. }
  69. static unsigned int conio_get_display_width(caca_display_t *dp)
  70. {
  71. /* Fallback to a 6x10 font */
  72. return dp->cv->width * 6;
  73. }
  74. static unsigned int conio_get_display_height(caca_display_t *dp)
  75. {
  76. /* Fallback to a 6x10 font */
  77. return dp->cv->height * 10;
  78. }
  79. static void conio_display(caca_display_t *dp)
  80. {
  81. char *screen = dp->drv.p->screen;
  82. uint32_t *attr = dp->cv->attr;
  83. uint32_t *chars = dp->cv->chars;
  84. int n;
  85. for(n = dp->cv->height * dp->cv->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(dp->drv.p->screen);
  92. # else
  93. /* FIXME */
  94. # endif
  95. }
  96. static void conio_handle_resize(caca_display_t *dp)
  97. {
  98. /* We know nothing about our window */
  99. dp->resize.w = dp->cv->width;
  100. dp->resize.h = dp->cv->height;
  101. }
  102. static int conio_get_event(caca_display_t *dp, 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.ch = 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(dp, &release);
  120. return 1;
  121. }
  122. /*
  123. * Driver initialisation
  124. */
  125. int conio_install(caca_display_t *dp)
  126. {
  127. dp->drv.driver = CACA_DRIVER_CONIO;
  128. dp->drv.init_graphics = conio_init_graphics;
  129. dp->drv.end_graphics = conio_end_graphics;
  130. dp->drv.set_display_title = conio_set_display_title;
  131. dp->drv.get_display_width = conio_get_display_width;
  132. dp->drv.get_display_height = conio_get_display_height;
  133. dp->drv.display = conio_display;
  134. dp->drv.handle_resize = conio_handle_resize;
  135. dp->drv.get_event = conio_get_event;
  136. dp->drv.set_mouse = NULL;
  137. return 0;
  138. }
  139. #endif /* USE_CONIO */