xref: /reactos/win32ss/drivers/miniport/vga/initvga.c (revision c2c66aff)
1 #include "vgamp.h"
2 
3 #include "vgavideo.h"
4 
5 static VGA_REGISTERS Mode12Regs =
6 {
7    /* CRT Controller Registers */
8    {0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, 0x40, 0x00, 0x00,
9     0x00, 0x00, 0x00, 0x59, 0xEA, 0x8C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3},
10    /* Attribute Controller Registers */
11    {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
12     0x0C, 0x0D, 0x0E, 0x0F, 0x81, 0x00, 0x0F, 0x00, 0x00},
13    /* Graphics Controller Registers */
14    {0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x0F, 0xFF},
15    /* Sequencer Registers */
16    {0x03, 0x01, 0x0F, 0x00, 0x06},
17    /* Misc Output Register */
18    0xE3
19 };
20 
21 VGA_REGISTERS TextModeRegs;
22 
23 static VOID FASTCALL
vgaSaveRegisters(PVGA_REGISTERS Registers)24 vgaSaveRegisters(PVGA_REGISTERS Registers)
25 {
26    UCHAR i;
27 
28    for (i = 0; i < sizeof(Registers->CRT); i++)
29    {
30       VideoPortWritePortUchar(CRTC, i);
31       Registers->CRT[i] = VideoPortReadPortUchar(CRTCDATA);
32    }
33 
34    for (i = 0; i < sizeof(Registers->Attribute); i++)
35    {
36       VideoPortReadPortUchar(STATUS);
37       VideoPortWritePortUchar(ATTRIB, i);
38       Registers->Attribute[i] = VideoPortReadPortUchar(ATTRIBREAD);
39    }
40 
41    for (i = 0; i < sizeof(Registers->Graphics); i++)
42    {
43       VideoPortWritePortUchar(GRAPHICS, i);
44       Registers->Graphics[i] = VideoPortReadPortUchar(GRAPHICSDATA);
45    }
46 
47    for (i = 0; i < sizeof(Registers->Sequencer); i++)
48    {
49       VideoPortWritePortUchar(SEQ, i);
50       Registers->Sequencer[i] = VideoPortReadPortUchar(SEQDATA);
51    }
52 
53    Registers->Misc = VideoPortReadPortUchar(MISC);
54 }
55 
56 static VOID FASTCALL
vgaSetRegisters(PVGA_REGISTERS Registers)57 vgaSetRegisters(PVGA_REGISTERS Registers)
58 {
59    UCHAR i;
60 
61    /* Update misc output register */
62    VideoPortWritePortUchar(MISC, Registers->Misc);
63 
64    /* Synchronous reset on */
65    VideoPortWritePortUchar(SEQ, 0x00);
66    VideoPortWritePortUchar(SEQDATA, 0x01);
67 
68    /* Write sequencer registers */
69    for (i = 1; i < sizeof(Registers->Sequencer); i++)
70    {
71       VideoPortWritePortUchar(SEQ, i);
72       VideoPortWritePortUchar(SEQDATA, Registers->Sequencer[i]);
73    }
74 
75    /* Synchronous reset off */
76    VideoPortWritePortUchar(SEQ, 0x00);
77    VideoPortWritePortUchar(SEQDATA, 0x03);
78 
79    /* Deprotect CRT registers 0-7 */
80    VideoPortWritePortUchar(CRTC, 0x11);
81    VideoPortWritePortUchar(CRTCDATA, Registers->CRT[0x11] & 0x7f);
82 
83    /* Write CRT registers */
84    for (i = 0; i < sizeof(Registers->CRT); i++)
85    {
86       VideoPortWritePortUchar(CRTC, i);
87       VideoPortWritePortUchar(CRTCDATA, Registers->CRT[i]);
88    }
89 
90    /* Write graphics controller registers */
91    for (i = 0; i < sizeof(Registers->Graphics); i++)
92    {
93       VideoPortWritePortUchar(GRAPHICS, i);
94       VideoPortWritePortUchar(GRAPHICSDATA, Registers->Graphics[i]);
95    }
96 
97    /* Write attribute controller registers */
98    for (i = 0; i < sizeof(Registers->Attribute); i++)
99    {
100       VideoPortReadPortUchar(STATUS);
101       VideoPortWritePortUchar(ATTRIB, i);
102       VideoPortWritePortUchar(ATTRIB, Registers->Attribute[i]);
103    }
104 
105    /* Renable screen. */
106    VideoPortWritePortUchar(ATTRIB, 0x20);
107 }
108 
109 VOID
InitVGAMode(VOID)110 InitVGAMode(VOID)
111 {
112    vgaSaveRegisters(&TextModeRegs);
113    vgaSetRegisters(&Mode12Regs);
114 }
115 
116 VOID
VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)117 VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
118 {
119    vgaSetRegisters(&TextModeRegs);
120 }
121