10 static int init(void);
11 static void cleanup(void);
12 static int setmode(int mode);
13 static int curmode(void);
15 static void setpal4(int idx, int count, const struct vid_color *col);
16 static void getpal4(int idx, int count, struct vid_color *col);
17 static void clear4(uint32_t color);
18 static void blitfb4(void *fb, int pitch);
19 static void fill4(int x, int y, int w, int h, uint32_t color);
21 static void clear8(uint32_t color);
22 static void blitfb8(void *fb, int pitch);
23 static void fill8(int x, int y, int w, int h, uint32_t color);
26 static struct vid_driver drv;
27 static struct vid_drvops drvops = {init, cleanup, setmode, curmode};
28 static struct vid_modeinfo modes[] = {
34 static struct vid_gfxops gfxops_mode12h = {
35 0, 0, setpal4, getpal4, vga_vsync, clear4, blitfb4, 0, fill4 };
36 static struct vid_gfxops gfxops_mode13h = {
37 0, 0, vga_setpal, vga_getpal, vga_vsync, clear8, blitfb8, 0, fill8 };
39 void vid_register_vga(void)
47 drv.num_modes = sizeof modes / sizeof *modes;
49 for(i=0; i<drv.num_modes; i++) {
51 modes[i].vmem_addr = 0xa0000;
53 switch(modes[i].modeno) {
55 modes[i].vmem_addr = 0xb8000;
59 modes[i].ops = gfxops_mode13h;
63 modes[i].ops = gfxops_mode12h;
68 vid_drvlist[vid_numdrv++] = &drv;
73 while(inp(VGA_STAT1_PORT) & 8);
74 while((inp(VGA_STAT1_PORT) & 8) == 0);
77 void vga_setpal(int idx, int count, const struct vid_color *col)
80 outp(VGA_DAC_WADDR_PORT, idx);
81 for(i=0; i<count; i++) {
82 outp(VGA_DAC_DATA_PORT, col->r >> 2);
83 outp(VGA_DAC_DATA_PORT, col->g >> 2);
84 outp(VGA_DAC_DATA_PORT, col->b >> 2);
89 void vga_getpal(int idx, int count, struct vid_color *col)
92 outp(VGA_DAC_RADDR_PORT, idx);
93 for(i=0; i<count; i++) {
94 col->r = inp(VGA_DAC_DATA_PORT) << 2;
95 col->g = inp(VGA_DAC_DATA_PORT) << 2;
96 col->b = inp(VGA_DAC_DATA_PORT) << 2;
102 static int init(void)
107 static void cleanup(void)
111 static int setmode(int mode)
113 union REGS regs = {0};
115 int386(0x10, ®s, ®s);
119 static int curmode(void)
121 union REGS regs = {0};
123 int386(0x10, ®s, ®s);
124 return regs.x.eax & 0xff;
127 static void setpal4(int idx, int count, const struct vid_color *col)
131 static void getpal4(int idx, int count, struct vid_color *col)
135 static void clear4(uint32_t color)
139 static void blitfb4(void *fb, int pitch)
143 static void fill4(int x, int y, int w, int h, uint32_t color)
147 static void clear8(uint32_t color)
149 memset((void*)0xa0000, color, 64000);
152 static void blitfb8(void *fb, int pitch)
155 unsigned char *src = fb;
156 unsigned char *dest = (unsigned char*)0xa0000;
157 for(i=0; i<200; i++) {
158 memcpy(dest, src, 320);
164 static void fill8(int x, int y, int w, int h, uint32_t color)
167 unsigned char *fbptr = (unsigned char*)0xa0000;
169 fbptr += y * 320 + x;
171 memset(fbptr, color, w);