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