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.

vga.h 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. *
  3. * modified
  4. * by Steve M. Gehlbach <steve@kesa.com>
  5. *
  6. * Originally from linux/drivers/video/vga16.c by
  7. * Ben Pfaff <pfaffben@debian.org> and Petr Vandrovec <VANDROVE@vc.cvut.cz>
  8. * Copyright 1999 Ben Pfaff <pfaffben@debian.org> and Petr Vandrovec <VANDROVE@vc.cvut.cz>
  9. * Based on VGA info at http://www.goodnet.com/~tinara/FreeVGA/home.htm
  10. * Based on VESA framebuffer (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
  11. *
  12. */
  13. #ifndef VGA_H_INCL
  14. #define VGA_H_INCL 1
  15. //#include <cpu/p5/io.h>
  16. #define u8 unsigned char
  17. #define u16 unsigned short
  18. #define u32 unsigned int
  19. #define __u32 u32
  20. #define VERROR -1
  21. #define CHAR_HEIGHT 16
  22. #define LINES 25
  23. #define COLS 80
  24. // macros for writing to vga regs
  25. #define write_crtc(data,addr) outb(addr,CRT_IC); outb(data,CRT_DC)
  26. #define write_att(data,addr) inb(IS1_RC); inb(0x80); outb(addr,ATT_IW); inb(0x80); outb(data,ATT_IW); inb(0x80)
  27. #define write_seq(data,addr) outb(addr,SEQ_I); outb(data,SEQ_D)
  28. #define write_gra(data,addr) outb(addr,GRA_I); outb(data,GRA_D)
  29. u8 read_seq_b(u16 addr);
  30. u8 read_gra_b(u16 addr);
  31. u8 read_crtc_b(u16 addr);
  32. u8 read_att_b(u16 addr);
  33. #ifdef VGA_HARDWARE_FIXUP
  34. void vga_hardware_fixup(void);
  35. #else
  36. #define vga_hardware_fixup() do{} while(0)
  37. #endif
  38. #define SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */
  39. #define SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */
  40. #define SYNC_EXT 4 /* external sync */
  41. #define SYNC_COMP_HIGH_ACT 8 /* composite sync high active */
  42. #define SYNC_BROADCAST 16 /* broadcast video timings */
  43. /* vtotal = 144d/288n/576i => PAL */
  44. /* vtotal = 121d/242n/484i => NTSC */
  45. #define SYNC_ON_GREEN 32 /* sync on green */
  46. #define VMODE_NONINTERLACED 0 /* non interlaced */
  47. #define VMODE_INTERLACED 1 /* interlaced */
  48. #define VMODE_DOUBLE 2 /* double scan */
  49. #define VMODE_MASK 255
  50. #define VMODE_YWRAP 256 /* ywrap instead of panning */
  51. #define VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */
  52. #define VMODE_CONUPDATE 512 /* don't update x/yoffset */
  53. /* VGA data register ports */
  54. #define CRT_DC 0x3D5 /* CRT Controller Data Register - color emulation */
  55. #define CRT_DM 0x3B5 /* CRT Controller Data Register - mono emulation */
  56. #define ATT_R 0x3C1 /* Attribute Controller Data Read Register */
  57. #define GRA_D 0x3CF /* Graphics Controller Data Register */
  58. #define SEQ_D 0x3C5 /* Sequencer Data Register */
  59. #define MIS_R 0x3CC // Misc Output Read Register
  60. #define MIS_W 0x3C2 // Misc Output Write Register
  61. #define IS1_RC 0x3DA /* Input Status Register 1 - color emulation */
  62. #define IS1_RM 0x3BA /* Input Status Register 1 - mono emulation */
  63. #define PEL_D 0x3C9 /* PEL Data Register */
  64. #define PEL_MSK 0x3C6 /* PEL mask register */
  65. /* EGA-specific registers */
  66. #define GRA_E0 0x3CC /* Graphics enable processor 0 */
  67. #define GRA_E1 0x3CA /* Graphics enable processor 1 */
  68. /* VGA index register ports */
  69. #define CRT_IC 0x3D4 /* CRT Controller Index - color emulation */
  70. #define CRT_IM 0x3B4 /* CRT Controller Index - mono emulation */
  71. #define ATT_IW 0x3C0 /* Attribute Controller Index & Data Write Register */
  72. #define GRA_I 0x3CE /* Graphics Controller Index */
  73. #define SEQ_I 0x3C4 /* Sequencer Index */
  74. #define PEL_IW 0x3C8 /* PEL Write Index */
  75. #define PEL_IR 0x3C7 /* PEL Read Index */
  76. /* standard VGA indexes max counts */
  77. #define CRTC_C 25 /* 25 CRT Controller Registers sequentially set*/
  78. // the remainder are not in the par array
  79. #define ATT_C 21 /* 21 Attribute Controller Registers */
  80. #define GRA_C 9 /* 9 Graphics Controller Registers */
  81. #define SEQ_C 5 /* 5 Sequencer Registers */
  82. #define MIS_C 1 /* 1 Misc Output Register */
  83. #define CRTC_H_TOTAL 0
  84. #define CRTC_H_DISP 1
  85. #define CRTC_H_BLANK_START 2
  86. #define CRTC_H_BLANK_END 3
  87. #define CRTC_H_SYNC_START 4
  88. #define CRTC_H_SYNC_END 5
  89. #define CRTC_V_TOTAL 6
  90. #define CRTC_OVERFLOW 7
  91. #define CRTC_PRESET_ROW 8
  92. #define CRTC_MAX_SCAN 9
  93. #define CRTC_CURSOR_START 0x0A
  94. #define CRTC_CURSOR_END 0x0B
  95. #define CRTC_START_HI 0x0C
  96. #define CRTC_START_LO 0x0D
  97. #define CRTC_CURSOR_HI 0x0E
  98. #define CRTC_CURSOR_LO 0x0F
  99. #define CRTC_V_SYNC_START 0x10
  100. #define CRTC_V_SYNC_END 0x11
  101. #define CRTC_V_DISP_END 0x12
  102. #define CRTC_OFFSET 0x13
  103. #define CRTC_UNDERLINE 0x14
  104. #define CRTC_V_BLANK_START 0x15
  105. #define CRTC_V_BLANK_END 0x16
  106. #define CRTC_MODE 0x17
  107. #define CRTC_LINE_COMPARE 0x18
  108. #define ATC_MODE 0x10
  109. #define ATC_OVERSCAN 0x11
  110. #define ATC_PLANE_ENABLE 0x12
  111. #define ATC_PEL 0x13
  112. #define ATC_COLOR_PAGE 0x14
  113. #define SEQ_CLOCK_MODE 0x01
  114. #define SEQ_PLANE_WRITE 0x02
  115. #define SEQ_CHARACTER_MAP 0x03
  116. #define SEQ_MEMORY_MODE 0x04
  117. #define GDC_SR_VALUE 0x00
  118. #define GDC_SR_ENABLE 0x01
  119. #define GDC_COMPARE_VALUE 0x02
  120. #define GDC_DATA_ROTATE 0x03
  121. #define GDC_PLANE_READ 0x04
  122. #define GDC_MODE 0x05
  123. #define GDC_MISC 0x06
  124. #define GDC_COMPARE_MASK 0x07
  125. #define GDC_BIT_MASK 0x08
  126. // text attributes
  127. #define VGA_ATTR_CLR_RED 0x4
  128. #define VGA_ATTR_CLR_GRN 0x2
  129. #define VGA_ATTR_CLR_BLU 0x1
  130. #define VGA_ATTR_CLR_YEL (VGA_ATTR_CLR_RED | VGA_ATTR_CLR_GRN)
  131. #define VGA_ATTR_CLR_CYN (VGA_ATTR_CLR_GRN | VGA_ATTR_CLR_BLU)
  132. #define VGA_ATTR_CLR_MAG (VGA_ATTR_CLR_BLU | VGA_ATTR_CLR_RED)
  133. #define VGA_ATTR_CLR_BLK 0
  134. #define VGA_ATTR_CLR_WHT (VGA_ATTR_CLR_RED | VGA_ATTR_CLR_GRN | VGA_ATTR_CLR_BLU)
  135. #define VGA_ATTR_BNK 0x80
  136. #define VGA_ATTR_ITN 0x08
  137. /*
  138. * vga register parameters
  139. * these are copied to the
  140. * registers.
  141. *
  142. */
  143. struct vga_par {
  144. u8 crtc[CRTC_C];
  145. u8 atc[ATT_C];
  146. u8 gdc[GRA_C];
  147. u8 seq[SEQ_C];
  148. u8 misc; // the misc register, MIS_W
  149. u8 vss;
  150. };
  151. /* Interpretation of offset for color fields: All offsets are from the right,
  152. * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
  153. * can use the offset as right argument to <<). A pixel afterwards is a bit
  154. * stream and is written to video memory as that unmodified. This implies
  155. * big-endian byte order if bits_per_pixel is greater than 8.
  156. */
  157. struct fb_bitfield {
  158. __u32 offset; /* beginning of bitfield */
  159. __u32 length; /* length of bitfield */
  160. __u32 msb_right; /* != 0 : Most significant bit is */
  161. /* right */
  162. };
  163. struct screeninfo {
  164. __u32 xres; /* visible resolution */
  165. __u32 yres;
  166. __u32 xres_virtual; /* virtual resolution */
  167. __u32 yres_virtual;
  168. __u32 xoffset; /* offset from virtual to visible */
  169. __u32 yoffset; /* resolution */
  170. __u32 bits_per_pixel; /* guess what */
  171. __u32 grayscale; /* != 0 Graylevels instead of colors */
  172. struct fb_bitfield red; /* bitfield in fb mem if true color, */
  173. struct fb_bitfield green; /* else only length is significant */
  174. struct fb_bitfield blue;
  175. struct fb_bitfield transp; /* transparency */
  176. __u32 nonstd; /* != 0 Non standard pixel format */
  177. __u32 activate; /* see FB_ACTIVATE_* */
  178. __u32 height; /* height of picture in mm */
  179. __u32 width; /* width of picture in mm */
  180. __u32 accel_flags; /* acceleration flags (hints) */
  181. /* Timing: All values in pixclocks, except pixclock (of course) */
  182. __u32 pixclock; /* pixel clock in ps (pico seconds) */
  183. __u32 left_margin; /* time from sync to picture */
  184. __u32 right_margin; /* time from picture to sync */
  185. __u32 upper_margin; /* time from sync to picture */
  186. __u32 lower_margin;
  187. __u32 hsync_len; /* length of horizontal sync */
  188. __u32 vsync_len; /* length of vertical sync */
  189. __u32 sync; /* sync polarity */
  190. __u32 vmode; /* interlaced etc */
  191. __u32 reserved[6]; /* Reserved for future compatibility */
  192. };
  193. #endif