Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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