Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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