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.

пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
пре 18 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. #include "common.h"
  18. #if defined(USE_VGA)
  19. #include "caca.h"
  20. #include "caca_internals.h"
  21. #include "cucul.h"
  22. #include "cucul_internals.h"
  23. /* Address of the VGA screen */
  24. #define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
  25. static uint8_t const vga_colors[][4] =
  26. {
  27. /* Colour values range from 0x00 to 0x3f */
  28. { 0, 0x00, 0x00, 0x00 },
  29. { 1, 0x00, 0x00, 0x1f },
  30. { 2, 0x00, 0x1f, 0x00 },
  31. { 3, 0x00, 0x1f, 0x1f },
  32. { 4, 0x1f, 0x00, 0x00 },
  33. { 5, 0x1f, 0x00, 0x1f },
  34. { 0x14, 0x1f, 0x1f, 0x00 },
  35. { 7, 0x1f, 0x1f, 0x1f },
  36. { 0x38, 0x0f, 0x0f, 0x0f },
  37. { 0x39, 0x0f, 0x0f, 0x3f },
  38. { 0x3a, 0x0f, 0x3f, 0x0f },
  39. { 0x3b, 0x0f, 0x3f, 0x3f },
  40. { 0x3c, 0x3f, 0x0f, 0x0f },
  41. { 0x3d, 0x3f, 0x0f, 0x3f },
  42. { 0x3e, 0x3f, 0x3f, 0x0f },
  43. { 0x3f, 0x3f, 0x3f, 0x3f },
  44. };
  45. static int vga_init_graphics(caca_display_t *dp)
  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. /* We don't have much choice */
  66. _cucul_set_canvas_size(dp->cv, 80, 25);
  67. return 0;
  68. }
  69. static int vga_end_graphics(caca_display_t *dp)
  70. {
  71. uint8_t tmp;
  72. /* Show cursor again */
  73. outb(0x0a, 0x3d4);
  74. tmp = inb(0x3d5);
  75. tmp &= 0xdf;
  76. outb(0x0a, 0x3d4);
  77. outb(tmp, 0x3d5);
  78. return 0;
  79. }
  80. static int vga_set_display_title(caca_display_t *dp, char const *title)
  81. {
  82. /* Unsupported, of course. */
  83. return 0;
  84. }
  85. static unsigned int vga_get_display_width(caca_display_t *dp)
  86. {
  87. /* Fallback to a 320x200 screen */
  88. return 320;
  89. }
  90. static unsigned int vga_get_display_height(caca_display_t *dp)
  91. {
  92. /* Fallback to a 320x200 screen */
  93. return 200;
  94. }
  95. static void vga_display(caca_display_t *dp)
  96. {
  97. char *screen = (char *)(intptr_t)0x000b8000;
  98. uint32_t *attr = dp->cv->attr;
  99. uint32_t *chars = dp->cv->chars;
  100. int n;
  101. for(n = dp->cv->height * dp->cv->width; n--; )
  102. {
  103. *screen++ = _cucul_utf32_to_cp437(*chars++);
  104. *screen++ = _cucul_argb32_to_ansi8(*attr++);
  105. }
  106. }
  107. static void vga_handle_resize(caca_display_t *dp)
  108. {
  109. /* We know nothing about our window */
  110. dp->resize.w = dp->cv->width;
  111. dp->resize.h = dp->cv->height;
  112. }
  113. static int vga_get_event(caca_display_t *dp, caca_event-t *ev)
  114. {
  115. /* FIXME */
  116. ev->type = CACA_EVENT_NONE;
  117. return 0;
  118. }
  119. /*
  120. * Driver initialisation
  121. */
  122. int vga_install(caca_display_t *dp)
  123. {
  124. dp->drv.driver = CACA_DRIVER_VGA;
  125. dp->drv.init_graphics = vga_init_graphics;
  126. dp->drv.end_graphics = vga_end_graphics;
  127. dp->drv.set_display_title = vga_set_display_title;
  128. dp->drv.get_display_width = vga_get_display_width;
  129. dp->drv.get_display_height = vga_get_display_height;
  130. dp->drv.display = vga_display;
  131. dp->drv.handle_resize = vga_handle_resize;
  132. dp->drv.get_event = vga_get_event;
  133. dp->drv.set_mouse = NULL;
  134. return 0;
  135. }
  136. #endif /* USE_VGA */