Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

162 linhas
3.5 KiB

  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 <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_t *kk)
  36. {
  37. kk->drv.p = malloc(sizeof(struct driver_private));
  38. _wscroll = 0;
  39. _setcursortype(_NOCURSOR);
  40. clrscr();
  41. gettextinfo(&kk->drv.p->ti);
  42. kk->drv.p->screen = malloc(2 * kk->drv.p->ti.screenwidth
  43. * kk->drv.p->ti.screenheight * sizeof(char));
  44. if(kk->drv.p->screen == NULL)
  45. return -1;
  46. # if defined(SCREENUPDATE_IN_PC_H)
  47. ScreenRetrieve(kk->drv.p->screen);
  48. # else
  49. /* FIXME */
  50. # endif
  51. cucul_set_size(kk->qq, kk->drv.p->ti.screenwidth,
  52. kk->drv.p->ti.screenheight);
  53. return 0;
  54. }
  55. static int conio_end_graphics(caca_t *kk)
  56. {
  57. _wscroll = 1;
  58. textcolor((enum COLORS)WHITE);
  59. textbackground((enum COLORS)BLACK);
  60. gotoxy(kk->qq->width, kk->qq->height);
  61. cputs("\r\n");
  62. _setcursortype(_NORMALCURSOR);
  63. free(kk->drv.p->screen);
  64. free(kk->drv.p);
  65. return 0;
  66. }
  67. static int conio_set_window_title(caca_t *kk, char const *title)
  68. {
  69. return 0;
  70. }
  71. static unsigned int conio_get_window_width(caca_t *kk)
  72. {
  73. /* Fallback to a 6x10 font */
  74. return kk->qq->width * 6;
  75. }
  76. static unsigned int conio_get_window_height(caca_t *kk)
  77. {
  78. /* Fallback to a 6x10 font */
  79. return kk->qq->height * 10;
  80. }
  81. static void conio_display(caca_t *kk)
  82. {
  83. char *screen = kk->drv.p->screen;
  84. uint8_t *attr = kk->qq->attr;
  85. uint32_t *chars = kk->qq->chars;
  86. int n;
  87. for(n = kk->qq->height * kk->qq->width; n--; )
  88. {
  89. uint32_t c = *chars++;
  90. if(c > 0x00000020 && c < 0x00000080)
  91. *screen++ = (char)c;
  92. else
  93. *screen++ = ' ';
  94. *screen++ = *attr++;
  95. }
  96. # if defined(SCREENUPDATE_IN_PC_H)
  97. ScreenUpdate(kk->drv.p->screen);
  98. # else
  99. /* FIXME */
  100. # endif
  101. }
  102. static void conio_handle_resize(caca_t *kk)
  103. {
  104. /* We know nothing about our window */
  105. kk->resize.w = kk->qq->width;
  106. kk->resize.h = kk->qq->height;
  107. }
  108. static unsigned int conio_get_event(caca_t *kk)
  109. {
  110. unsigned int event;
  111. if(!_conio_kbhit())
  112. return CACA_EVENT_NONE;
  113. event = getch();
  114. _push_event(kk, CACA_EVENT_KEY_RELEASE | event);
  115. return CACA_EVENT_KEY_PRESS | event;
  116. }
  117. /*
  118. * Driver initialisation
  119. */
  120. void conio_init_driver(caca_t *kk)
  121. {
  122. kk->drv.driver = CACA_DRIVER_CONIO;
  123. kk->drv.init_graphics = conio_init_graphics;
  124. kk->drv.end_graphics = conio_end_graphics;
  125. kk->drv.set_window_title = conio_set_window_title;
  126. kk->drv.get_window_width = conio_get_window_width;
  127. kk->drv.get_window_height = conio_get_window_height;
  128. kk->drv.display = conio_display;
  129. kk->drv.handle_resize = conio_handle_resize;
  130. kk->drv.get_event = conio_get_event;
  131. }
  132. #endif /* USE_CONIO */