Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

driver_vga.c 4.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains the libcaca VGA input and output driver
  16. */
  17. #include "config.h"
  18. #if defined(USE_VGA)
  19. #include "cucul.h"
  20. #include "caca.h"
  21. #include "caca_internals.h"
  22. /* Address of the VGA screen */
  23. #define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
  24. static uint8_t const vga_colors[][4] =
  25. {
  26. /* Colour values range from 0x00 to 0x3f */
  27. { 0, 0x00, 0x00, 0x00 },
  28. { 1, 0x00, 0x00, 0x1f },
  29. { 2, 0x00, 0x1f, 0x00 },
  30. { 3, 0x00, 0x1f, 0x1f },
  31. { 4, 0x1f, 0x00, 0x00 },
  32. { 5, 0x1f, 0x00, 0x1f },
  33. { 0x14, 0x1f, 0x1f, 0x00 },
  34. { 7, 0x1f, 0x1f, 0x1f },
  35. { 0x38, 0x0f, 0x0f, 0x0f },
  36. { 0x39, 0x0f, 0x0f, 0x3f },
  37. { 0x3a, 0x0f, 0x3f, 0x0f },
  38. { 0x3b, 0x0f, 0x3f, 0x3f },
  39. { 0x3c, 0x3f, 0x0f, 0x0f },
  40. { 0x3d, 0x3f, 0x0f, 0x3f },
  41. { 0x3e, 0x3f, 0x3f, 0x0f },
  42. { 0x3f, 0x3f, 0x3f, 0x3f },
  43. };
  44. static int vga_init_graphics(caca_display_t *dp)
  45. {
  46. int i;
  47. uint8_t tmp;
  48. /* Blank screen */
  49. memset(VGA_SCREEN, 0, 80 * 25 * 2);
  50. /* Fill VGA palette */
  51. for(i = 0; i < 16; i++)
  52. {
  53. outb(vga_colors[i][0], 0x3c8);
  54. outb(vga_colors[i][1], 0x3c9);
  55. outb(vga_colors[i][2], 0x3c9);
  56. outb(vga_colors[i][3], 0x3c9);
  57. }
  58. /* Hide cursor */
  59. outb(0x0a, 0x3d4);
  60. tmp = inb(0x3d5);
  61. tmp |= 0x20;
  62. outb(0x0a, 0x3d4);
  63. outb(tmp, 0x3d5);
  64. /* We don't have much choice */
  65. dp->resize.allow = 1;
  66. cucul_set_canvas_size(dp->cv, 80, 25);
  67. dp->resize.allow = 0;
  68. return 0;
  69. }
  70. static int vga_end_graphics(caca_display_t *dp)
  71. {
  72. uint8_t tmp;
  73. /* Show cursor again */
  74. outb(0x0a, 0x3d4);
  75. tmp = inb(0x3d5);
  76. tmp &= 0xdf;
  77. outb(0x0a, 0x3d4);
  78. outb(tmp, 0x3d5);
  79. return 0;
  80. }
  81. static int vga_set_display_title(caca_display_t *dp, char const *title)
  82. {
  83. /* Unsupported, of course. */
  84. return -1;
  85. }
  86. static unsigned int vga_get_display_width(caca_display_t const *dp)
  87. {
  88. /* Fallback to a 320x200 screen */
  89. return 320;
  90. }
  91. static unsigned int vga_get_display_height(caca_display_t const *dp)
  92. {
  93. /* Fallback to a 320x200 screen */
  94. return 200;
  95. }
  96. static void vga_display(caca_display_t *dp)
  97. {
  98. char *screen = (char *)(intptr_t)0x000b8000;
  99. uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
  100. uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
  101. unsigned int width = cucul_get_canvas_width(dp->cv);
  102. unsigned int height = cucul_get_canvas_height(dp->cv);
  103. int n;
  104. for(n = height * width; n--; )
  105. {
  106. char ch = cucul_utf32_to_cp437(*cvchars++);
  107. if(n && *cvchars == CUCUL_MAGIC_FULLWIDTH)
  108. {
  109. *screen++ = '[';
  110. *screen++ = cucul_attr_to_ansi(*cvattrs++);
  111. ch = ']';
  112. cvchars++;
  113. n--;
  114. }
  115. *screen++ = ch;
  116. *screen++ = cucul_attr_to_ansi(*cvattrs++);
  117. }
  118. }
  119. static void vga_handle_resize(caca_display_t *dp)
  120. {
  121. /* We know nothing about our window */
  122. dp->resize.w = cucul_get_canvas_width(dp->cv);
  123. dp->resize.h = cucul_get_canvas_height(dp->cv);
  124. }
  125. static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev)
  126. {
  127. /* FIXME */
  128. ev->type = CACA_EVENT_NONE;
  129. return 0;
  130. }
  131. /*
  132. * Driver initialisation
  133. */
  134. int vga_install(caca_display_t *dp)
  135. {
  136. dp->drv.id = CACA_DRIVER_VGA;
  137. dp->drv.driver = "vga";
  138. dp->drv.init_graphics = vga_init_graphics;
  139. dp->drv.end_graphics = vga_end_graphics;
  140. dp->drv.set_display_title = vga_set_display_title;
  141. dp->drv.get_display_width = vga_get_display_width;
  142. dp->drv.get_display_height = vga_get_display_height;
  143. dp->drv.display = vga_display;
  144. dp->drv.handle_resize = vga_handle_resize;
  145. dp->drv.get_event = vga_get_event;
  146. dp->drv.set_mouse = NULL;
  147. dp->drv.set_cursor = NULL;
  148. return 0;
  149. }
  150. #endif /* USE_VGA */