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