Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. static inline uint8_t inb(uint16_t port)
  5. {
  6. uint8_t ret;
  7. asm volatile ( "inb %1, %0"
  8. : "=a"(ret)
  9. : "Nd"(port) );
  10. return ret;
  11. }
  12. static inline void outb(uint16_t port, uint8_t val)
  13. {
  14. asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
  15. }
  16. unsigned char gdump[] =
  17. {
  18. 0x63, 0x03, 0x01, 0x0F, 0x00, 0x0E, 0x5F, 0x4F,
  19. 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, 0x41,
  20. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x0E,
  21. 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF, 0x00,
  22. 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
  23. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  24. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  25. 0x41, 0x00, 0x0F, 0x00, 0x00
  26. };
  27. void setg(unsigned char *dump)
  28. {
  29. unsigned int i;
  30. outb(0x3C2, *dump);
  31. dump++;
  32. for(i = 0; i < 5; i++)
  33. {
  34. outb(0x3C4, i);
  35. outb(0x3C5, *dump);
  36. dump++;
  37. }
  38. outb(0x3D4, 0x03);
  39. outb(0x3D5, inb(0x3D5) | 0x80);
  40. outb(0x3D4, 0x11);
  41. outb(0x3D5, inb(0x3D5) & ~0x80);
  42. dump[0x03] |= 0x80;
  43. dump[0x11] &= ~0x80;
  44. for(i = 0; i < 25; i++)
  45. {
  46. outb(0x3D4, i);
  47. outb(0x3D5, *dump);
  48. dump++;
  49. }
  50. for(i = 0; i < 9; i++)
  51. {
  52. outb(0x3CE, i);
  53. outb(0x3CF, *dump);
  54. dump++;
  55. }
  56. for(i = 0; i < 21; i++)
  57. {
  58. (void)inb(0x3DA);
  59. outb(0x3C0, i);
  60. outb(0x3C0, *dump);
  61. dump++;
  62. }
  63. (void)inb(0x3DA);
  64. outb(0x3C0, 0x20);
  65. }
  66. enum vga_color {
  67. BLACK = 0,
  68. BLUE = 1,
  69. GREEN = 2,
  70. CYAN = 3,
  71. RED = 4,
  72. MAGENTA = 5,
  73. BROWN = 6,
  74. LIGHT_GREY = 7,
  75. DARK_GREY = 8,
  76. LIGHT_BLUE = 9,
  77. LIGHT_GREEN = 10,
  78. LIGHT_CYAN = 11,
  79. LIGHT_RED = 12,
  80. LIGHT_MAGENTA = 13,
  81. LIGHT_BROWN = 14,
  82. WHITE = 15,
  83. };
  84. static inline void setp(int x, int y, unsigned char color) {
  85. static unsigned char * vga_mem = (unsigned char *) 0xA0000;
  86. if (x > 320 || x < 0 || y > 200 || y < 0) return;
  87. vga_mem[320 * y + x] = color;
  88. }
  89. void vga_clear(unsigned char c)
  90. {
  91. for(int y = 0; y < 200; y++)
  92. for(int x = 0; x < 320; x++)
  93. setp(x, y, c);
  94. }
  95. void hline(int x, int y, int idk, int c)
  96. {
  97. for (int a = x; a < x + idk; a++)
  98. setp(a, y, c);
  99. }
  100. void vline(int x, int y, int idk, int c)
  101. {
  102. for (int a = y; a < y + idk; a++)
  103. setp(x, a, c);
  104. }
  105. void fillrectangle(int x, int y, int height, int width, unsigned char c)
  106. {
  107. for (int a = x; a < x + width; a++)
  108. for (int b = y; b < y + height; b++)
  109. setp(a, b, c);
  110. }
  111. void rectangle(int x, int y, int height, int width, unsigned char c)
  112. {
  113. hline(x, y, width, c);
  114. hline(x, y + height, width, c);
  115. vline(x, y, height, c);
  116. vline(x + width, y, height, c);
  117. }
  118. void vgatest()
  119. {
  120. vga_clear(3);
  121. fillrectangle(10, 10, 100, 50, RED);
  122. hline(10, 10, 40, BLUE);
  123. vline(10, 10, 40, BLUE);
  124. rectangle(70, 60, 60, 70, MAGENTA);
  125. }
  126. void vgasetup()
  127. {
  128. setg(gdump);
  129. vgatest();
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement