Use vidport-functions instead of ntdll-functions
[reactos.git] / reactos / drivers / dd / vga / miniport / initvga.c
1 #include <ntddk.h>
2 #include <debug.h>
3 #include "vgavideo.h"
4
5 void outxay(USHORT ad, UCHAR x, UCHAR y)
6 {
7 USHORT xy = (x << 8) + y;
8
9 VideoPortWritePortUshort((PUSHORT)ad, xy);
10 }
11
12 void setMode(VideoMode mode)
13 {
14 unsigned char x;
15 unsigned int y, c, a, m, n;
16
17 VideoPortWritePortUchar((PUCHAR)MISC, mode.Misc);
18 VideoPortWritePortUchar((PUCHAR)STATUS, 0);
19 VideoPortWritePortUchar((PUCHAR)FEATURE, mode.Feature);
20
21 for(x=0; x<5; x++)
22 {
23 outxay(SEQ, mode.Seq[x], x);
24 }
25
26 VideoPortWritePortUshort((PUSHORT)CRTC, 0x11);
27 VideoPortWritePortUshort((PUSHORT)CRTC, (mode.Crtc[0x11] & 0x7f));
28
29 for(x=0; x<25; x++)
30 {
31 outxay(CRTC, mode.Crtc[x], x);
32 }
33
34 for(x=0; x<9; x++)
35 {
36 outxay(GRAPHICS, mode.Gfx[x], x);
37 }
38
39 x=VideoPortReadPortUchar((PUCHAR)FEATURE);
40
41 for(x=0; x<21; x++)
42 {
43 VideoPortWritePortUchar((PUCHAR)ATTRIB, x);
44 VideoPortWritePortUchar((PUCHAR)ATTRIB, mode.Attrib[x]);
45 }
46
47 x=VideoPortReadPortUchar((PUCHAR)STATUS);
48
49 VideoPortWritePortUchar((PUCHAR)ATTRIB, 0x20);
50 }
51
52 VideoMode Mode12 = {
53 0xa000, /* 0xe3, */ 0xc3, 0x00,
54
55 {0x02, 0x01, 0x0f, 0x00, 0x06 },
56
57 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
59 0xff},
60
61 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x0f, 0xff},
62
63 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
64 0x0c, 0x0d, 0x0e, 0x0f, 0x81, 0x00, 0x0f, 0x00, 0x00}
65 };
66
67 VideoMode Mode13 = {
68 0xa000, 0x63, 0x00,
69
70 {0x03, 0x01, 0x0f, 0x00, 0x0e},
71
72 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f, 0x00, 0x41, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x9c, 0x0e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
74 0xff},
75
76 {0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x07, 0x0f, 0xff},
77
78 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
79 0x0c, 0x0d, 0x0e, 0x0f, 0x41, 0x00, 0x0f, 0x00, 0x00}
80 };
81
82 VideoMode Mode3 = {
83 0xb800, 0x67, 0x00,
84 { 0x03, 0x00, 0x3, 0x00, 0x2 },
85
86 { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f, 0x0e, 0x0f,
87 0x00, 0x00, 0x00, 0x00, 0x9c, 0x0e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
88 0xff },
89
90 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff },
91
92 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
93 0x0c, 0x0d, 0x0e, 0x0f, 0x0c, 0x00, 0x0f, 0x08, 0x00 }
94 };
95
96 void InitVGAMode()
97 {
98 int i;
99
100 // FIXME: Use Vidport to map the memory properly
101 vidmem = (char *)(0xd0000000 + 0xa0000);
102 setMode(Mode12);
103
104 WRITE_PORT_USHORT((PUSHORT)0x3C4, 0x0f02); // index=MASK MAP, write to all bitplanes
105 i = vidmem[0];
106 // VideoPortZeroMemory(vidmem, 38400);
107 VideoPortZeroMemory(vidmem, 64000);
108
109 vgaPreCalc();
110 }
111
112
113 VOID VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
114 {
115 char *vidmem;
116 HANDLE Event;
117 OBJECT_ATTRIBUTES Attr;
118 UNICODE_STRING Name;
119 NTSTATUS Status;
120
121 CHECKPOINT;
122 Event = 0;
123 setMode( Mode3 );
124 RtlInitUnicodeString( &Name, L"\\TextConsoleRefreshEvent" );
125 InitializeObjectAttributes( &Attr, &Name, 0, 0, 0 );
126 Status = NtOpenEvent( &Event, STANDARD_RIGHTS_ALL, &Attr );
127 if( !NT_SUCCESS( Status ) )
128 DbgPrint( "VGA: Failed to open refresh event\n" );
129 else {
130 NtSetEvent( Event, 1 );
131 NtClose( Event );
132 }
133 }
134
135
136