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.
 
 
 
 
 
 

165 rader
3.6 KiB

  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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains the libcaca VGA input and output driver
  15. */
  16. #include "config.h"
  17. #if defined(USE_VGA)
  18. #include "caca.h"
  19. #include "caca_internals.h"
  20. #include "cucul.h"
  21. #include "cucul_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. _cucul_set_canvas_size(dp->cv, 80, 25);
  66. return 0;
  67. }
  68. static int vga_end_graphics(caca_display_t *dp)
  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_display_title(caca_display_t *dp, char const *title)
  80. {
  81. /* Unsupported, of course. */
  82. return 0;
  83. }
  84. static unsigned int vga_get_display_width(caca_display_t *dp)
  85. {
  86. /* Fallback to a 320x200 screen */
  87. return 320;
  88. }
  89. static unsigned int vga_get_display_height(caca_display_t *dp)
  90. {
  91. /* Fallback to a 320x200 screen */
  92. return 200;
  93. }
  94. static void vga_display(caca_display_t *dp)
  95. {
  96. char *screen = (char *)(intptr_t)0x000b8000;
  97. uint32_t *attr = dp->cv->attr;
  98. uint32_t *chars = dp->cv->chars;
  99. int n;
  100. for(n = dp->cv->height * dp->cv->width; n--; )
  101. {
  102. *screen++ = _cucul_utf32_to_cp437(*chars++);
  103. *screen++ = _cucul_argb32_to_ansi8(*attr++);
  104. }
  105. }
  106. static void vga_handle_resize(caca_display_t *dp)
  107. {
  108. /* We know nothing about our window */
  109. dp->resize.w = dp->cv->width;
  110. dp->resize.h = dp->cv->height;
  111. }
  112. static int vga_get_event(caca_display_t *dp, caca_event-t *ev)
  113. {
  114. /* FIXME */
  115. ev->type = CACA_EVENT_NONE;
  116. return 0;
  117. }
  118. /*
  119. * Driver initialisation
  120. */
  121. int vga_install(caca_display_t *dp)
  122. {
  123. dp->drv.driver = CACA_DRIVER_VGA;
  124. dp->drv.init_graphics = vga_init_graphics;
  125. dp->drv.end_graphics = vga_end_graphics;
  126. dp->drv.set_display_title = vga_set_display_title;
  127. dp->drv.get_display_width = vga_get_display_width;
  128. dp->drv.get_display_height = vga_get_display_height;
  129. dp->drv.display = vga_display;
  130. dp->drv.handle_resize = vga_handle_resize;
  131. dp->drv.get_event = vga_get_event;
  132. dp->drv.set_mouse = NULL;
  133. return 0;
  134. }
  135. #endif /* USE_VGA */