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.
 
 
 
 
 
 

166 lines
3.6 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_vga.c
  12. * \version \$Id$
  13. * \author Sam Hocevar <sam@zoy.org>
  14. * \brief VGA driver
  15. *
  16. * This file contains the libcaca VGA input and output driver
  17. */
  18. #include "config.h"
  19. #if defined(USE_VGA)
  20. #include "caca.h"
  21. #include "caca_internals.h"
  22. #include "cucul.h"
  23. #include "cucul_internals.h"
  24. /* Address of the VGA screen */
  25. #define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
  26. static uint8_t const vga_colors[][4] =
  27. {
  28. /* Colour values range from 0x00 to 0x3f */
  29. { 0, 0x00, 0x00, 0x00 },
  30. { 1, 0x00, 0x00, 0x1f },
  31. { 2, 0x00, 0x1f, 0x00 },
  32. { 3, 0x00, 0x1f, 0x1f },
  33. { 4, 0x1f, 0x00, 0x00 },
  34. { 5, 0x1f, 0x00, 0x1f },
  35. { 0x14, 0x1f, 0x1f, 0x00 },
  36. { 7, 0x1f, 0x1f, 0x1f },
  37. { 0x38, 0x0f, 0x0f, 0x0f },
  38. { 0x39, 0x0f, 0x0f, 0x3f },
  39. { 0x3a, 0x0f, 0x3f, 0x0f },
  40. { 0x3b, 0x0f, 0x3f, 0x3f },
  41. { 0x3c, 0x3f, 0x0f, 0x0f },
  42. { 0x3d, 0x3f, 0x0f, 0x3f },
  43. { 0x3e, 0x3f, 0x3f, 0x0f },
  44. { 0x3f, 0x3f, 0x3f, 0x3f },
  45. };
  46. static int vga_init_graphics(caca_t *kk)
  47. {
  48. int i;
  49. uint8_t tmp;
  50. /* Blank screen */
  51. memset(VGA_SCREEN, 0, 80 * 25 * 2);
  52. /* Fill VGA palette */
  53. for(i = 0; i < 16; i++)
  54. {
  55. outb(vga_colors[i][0], 0x3c8);
  56. outb(vga_colors[i][1], 0x3c9);
  57. outb(vga_colors[i][2], 0x3c9);
  58. outb(vga_colors[i][3], 0x3c9);
  59. }
  60. /* Hide cursor */
  61. outb(0x0a, 0x3d4);
  62. tmp = inb(0x3d5);
  63. tmp |= 0x20;
  64. outb(0x0a, 0x3d4);
  65. outb(tmp, 0x3d5);
  66. return 0;
  67. }
  68. static int vga_end_graphics(caca_t *kk)
  69. {
  70. uint8_t tmp;
  71. /* Show cursor again */
  72. outb(0x0a, 0x3d4);
  73. tmp = inb(0x3d5);
  74. tmp &= 0xdf;
  75. outb(0x0a, 0x3d4);
  76. outb(tmp, 0x3d5);
  77. return 0;
  78. }
  79. static int vga_set_window_title(caca_t *kk, char const *title)
  80. {
  81. /* Unsupported, of course. */
  82. return 0;
  83. }
  84. static unsigned int vga_get_window_width(caca_t *kk)
  85. {
  86. /* Fallback to a 6x10 font */
  87. return kk->qq->width * 6;
  88. }
  89. static unsigned int vga_get_window_height(caca_t *kk)
  90. {
  91. /* Fallback to a 6x10 font */
  92. return kk->qq->height * 10;
  93. }
  94. static void vga_display(caca_t *kk)
  95. {
  96. char *screen = (char *)(intptr_t)0x000b8000;
  97. uint8_t *attr = kk->qq->attr;
  98. uint32_t *chars = kk->qq->chars;
  99. int n;
  100. for(n = kk->qq->height * kk->qq->width; n--; )
  101. {
  102. uint32_t c = *chars++;
  103. if(c > 0x00000020 && c < 0x00000080)
  104. *screen++ = (char)c;
  105. else
  106. *screen++ = ' ';
  107. *screen++ = *attr++;
  108. }
  109. }
  110. static void vga_handle_resize(caca_t *kk)
  111. {
  112. /* We know nothing about our window */
  113. kk->resize.w = kk->qq->width;
  114. kk->resize.h = kk->qq->height;
  115. }
  116. static unsigned int vga_get_event(caca_t *kk)
  117. {
  118. /* FIXME */
  119. return CACA_EVENT_NONE;
  120. }
  121. /*
  122. * Driver initialisation
  123. */
  124. void vga_init_driver(caca_t *kk)
  125. {
  126. kk->drv.driver = CACA_DRIVER_VGA;
  127. kk->drv.init_graphics = vga_init_graphics;
  128. kk->drv.end_graphics = vga_end_graphics;
  129. kk->drv.set_window_title = vga_set_window_title;
  130. kk->drv.get_window_width = vga_get_window_width;
  131. kk->drv.get_window_height = vga_get_window_height;
  132. kk->drv.display = vga_display;
  133. kk->drv.handle_resize = vga_handle_resize;
  134. kk->drv.get_event = vga_get_event;
  135. }
  136. #endif /* USE_VGA */