dos fixes and vga modex
[dosdemo] / src / dos / vga.c
1 #include "vga.h"
2 #include "vgaregs.h"
3 #include "cdpmi.h"
4 #include "dosutil.h"
5
6 static void crtc_write(int reg, unsigned char val);
7 static unsigned char crtc_read(int reg);
8
9 int vga_setmode(int mode)
10 {
11         struct dpmi_regs regs = {0};
12
13         regs.eax = mode;        /* func 00 | mode */
14         dpmi_int(0x10, &regs);
15         return 0;
16 }
17
18 static unsigned short crtc_modex_regs[] = {
19         0x0d06, /* vertical total */
20         0x3e07, /* vcount overflow bit */
21         0x4109, /* double-scan */
22         0xea10, /* vsync start */
23         0xac11, /* vsync end & protect */
24         0xdf12, /* vertical visible */
25         0x0014, /* no dword mode */
26         0xe715, /* vblank start */
27         0x0616, /* vblank end */
28         0xe317, /* byte mode */
29         0
30 };
31
32 int vga_setmodex(void)
33 {
34         int i;
35         unsigned char val;
36
37         vga_setmode(0x13);
38
39         /* disable chain-4 (C4=0, O/E=1 (sequential), EM=1 (extmem), A/G=0 (gfx) */
40         outpw(VGA_SC_ADDR_PORT, VGA_SC_MEMMODE_REG | 0x0600);
41         /* pull reset low */
42         outpw(VGA_SC_ADDR_PORT, VGA_SC_RESET_REG | 0x0100);
43         /* 25mhz dot clock, 60hz scan */
44         outp(VGA_MISC_PORT, VGA_MISC_480 | VGA_MISC_PG1 | VGA_MISC_CLK25 |
45                         VGA_MISC_CPUEN | VGA_MISC_COLOR);
46         /* return reset high */
47         outpw(VGA_SC_ADDR_PORT, VGA_SC_RESET_REG | 0x0300);
48
49         /* disable CRTC write-protect */
50         crtc_write(CRTC_VRETEND_REG, crtc_read(CRTC_VRETEND_REG) & ~CRTC_VRETEND_PR);
51         /* change CRTC registers */
52         for(i=0; crtc_modex_regs[i]; i++) {
53                 outpw(VGA_CRTC_PORT, crtc_modex_regs[i]);
54         }
55
56         vga_planemask(0xf);
57         memset(VGA_FBADDR, 3, 320 * 240 / 4);
58         return 0;
59 }
60
61 static void crtc_write(int reg, unsigned char val)
62 {
63         outpw(VGA_CRTC_ADDR_PORT, reg | ((unsigned int)val << 8));
64 }
65
66 static unsigned char crtc_read(int reg)
67 {
68         outp(VGA_CRTC_ADDR_PORT, reg);
69         return inp(VGA_CRTC_DATA_PORT);
70 }