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.
 
 
 
 
 
 

165 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_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. { 0, 0x20, 0x20, 0x20 },
  29. { 1, 0x20, 0x20, 0x7f },
  30. { 2, 0x20, 0x7f, 0x20 },
  31. { 3, 0x20, 0x7f, 0x7f },
  32. { 4, 0x7f, 0x20, 0x20 },
  33. { 5, 0x7f, 0x20, 0x7f },
  34. { 0x14, 0x7f, 0x7f, 0x20 },
  35. { 7, 0x7f, 0x7f, 0x7f },
  36. { 0x38, 0x40, 0x40, 0x40 },
  37. { 0x39, 0x40, 0x40, 0xff },
  38. { 0x3a, 0x40, 0xff, 0x40 },
  39. { 0x3b, 0x40, 0xff, 0xff },
  40. { 0x3c, 0xff, 0x40, 0x40 },
  41. { 0x3d, 0xff, 0x40, 0xff },
  42. { 0x3e, 0xff, 0xff, 0x40 },
  43. { 0x3f, 0xff, 0xff, 0xff }
  44. };
  45. static int vga_init_graphics(caca_t *kk)
  46. {
  47. int i;
  48. uint8_t tmp;
  49. /* Blank screen */
  50. memset(VGA_SCREEN, 0, 80 * 25 * 2);
  51. /* Fill VGA palette */
  52. for(i = 0; i < 16; i++)
  53. {
  54. outb(vga_colors[i][0], 0x3c8);
  55. outb(vga_colors[i][1], 0x3c9);
  56. outb(vga_colors[i][2], 0x3c9);
  57. outb(vga_colors[i][3], 0x3c9);
  58. }
  59. /* Hide cursor */
  60. outb(0x0a, 0x3d4);
  61. tmp = inb(0x3d5);
  62. tmp |= 0x20;
  63. outb(0x0a, 0x3d4);
  64. outb(tmp, 0x3d5);
  65. return 0;
  66. }
  67. static int vga_end_graphics(caca_t *kk)
  68. {
  69. uint8_t tmp;
  70. /* Show cursor again */
  71. outb(0x0a, 0x3d4);
  72. tmp = inb(0x3d5);
  73. tmp &= 0xdf;
  74. outb(0x0a, 0x3d4);
  75. outb(tmp, 0x3d5);
  76. return 0;
  77. }
  78. static int vga_set_window_title(caca_t *kk, char const *title)
  79. {
  80. /* Unsupported, of course. */
  81. return 0;
  82. }
  83. static unsigned int vga_get_window_width(caca_t *kk)
  84. {
  85. /* Fallback to a 6x10 font */
  86. return kk->qq->width * 6;
  87. }
  88. static unsigned int vga_get_window_height(caca_t *kk)
  89. {
  90. /* Fallback to a 6x10 font */
  91. return kk->qq->height * 10;
  92. }
  93. static void vga_display(caca_t *kk)
  94. {
  95. char *screen = (char *)(intptr_t)0x000b8000;
  96. uint8_t *attr = kk->qq->attr;
  97. uint32_t *chars = kk->qq->chars;
  98. int n;
  99. for(n = kk->qq->height * kk->qq->width; n--; )
  100. {
  101. uint32_t c = *chars++;
  102. if(c > 0x00000020 && c < 0x00000080)
  103. *screen++ = (char)c;
  104. else
  105. *screen++ = ' ';
  106. *screen++ = *attr++;
  107. }
  108. }
  109. static void vga_handle_resize(caca_t *kk)
  110. {
  111. /* We know nothing about our window */
  112. kk->resize.w = kk->qq->width;
  113. kk->resize.h = kk->qq->height;
  114. }
  115. static unsigned int vga_get_event(caca_t *kk)
  116. {
  117. /* FIXME */
  118. return CACA_EVENT_NONE;
  119. }
  120. /*
  121. * Driver initialisation
  122. */
  123. void vga_init_driver(caca_t *kk)
  124. {
  125. kk->drv.driver = CACA_DRIVER_VGA;
  126. kk->drv.init_graphics = vga_init_graphics;
  127. kk->drv.end_graphics = vga_end_graphics;
  128. kk->drv.set_window_title = vga_set_window_title;
  129. kk->drv.get_window_width = vga_get_window_width;
  130. kk->drv.get_window_height = vga_get_window_height;
  131. kk->drv.display = vga_display;
  132. kk->drv.handle_resize = vga_handle_resize;
  133. kk->drv.get_event = vga_get_event;
  134. }
  135. #endif /* USE_VGA */