Changed from Nt to Zw functions in VGAResetDevice.
[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(PUSHORT ad, UCHAR x, UCHAR y)
6 {
7 USHORT xy = (x << 8) + y;
8
9 VideoPortWritePortUshort(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((PUSHORT)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((PUSHORT)CRTC, mode.Crtc[x], x);
32 }
33
34 for(x=0; x<9; x++)
35 {
36 outxay((PUSHORT)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, 0x00,
54
55 {0x03, 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, 0x00, 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 void InitVGAMode()
68 {
69 int i;
70 VIDEO_X86_BIOS_ARGUMENTS vxba;
71 VP_STATUS vps;
72
73 // FIXME: Use Vidport to map the memory properly
74 vidmem = (char *)(0xd0000000 + 0xa0000);
75 memset(&vxba, 0, sizeof(vxba));
76 vxba.Eax = 0x0012;
77 vps = VideoPortInt10(NULL, &vxba);
78
79 // Get VGA registers into the correct state (mainly for setting up the palette registers correctly)
80 setMode(Mode12);
81
82 // Get the VGA into the mode we want to work with
83 WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08); // Set
84 WRITE_PORT_UCHAR((PUCHAR)0x3cf,0); // the MASK
85 WRITE_PORT_USHORT((PUSHORT)0x3ce,0x0205); // write mode = 2 (bits 0,1) read mode = 0 (bit 3)
86 i = READ_REGISTER_UCHAR(vidmem); // Update bit buffer
87 WRITE_REGISTER_UCHAR(vidmem, 0); // Write the pixel
88 WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);
89 WRITE_PORT_UCHAR((PUCHAR)0x3cf,0xff);
90
91 // Zero out video memory (clear a possibly trashed screen)
92 RtlZeroMemory(vidmem, 64000);
93
94 vgaPreCalc();
95 }
96
97 VOID VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
98 {
99 char *vidmem;
100 HANDLE Event;
101 OBJECT_ATTRIBUTES Attr;
102 UNICODE_STRING Name;
103 NTSTATUS Status;
104 VIDEO_X86_BIOS_ARGUMENTS vxba;
105 VP_STATUS vps;
106 ULONG ThreadRelease = 1;
107
108 CHECKPOINT;
109 Event = 0;
110
111 memset(&vxba, 0, sizeof(vxba));
112 vxba.Eax = 0x0003;
113 vps = VideoPortInt10(NULL, &vxba);
114 memset(&vxba, 0, sizeof(vxba));
115 vxba.Eax = 0x1112;
116 vps = VideoPortInt10(NULL, &vxba);
117 RtlInitUnicodeString( &Name, L"\\TextConsoleRefreshEvent" );
118 InitializeObjectAttributes( &Attr, &Name, 0, 0, 0 );
119 Status = ZwOpenEvent( &Event, STANDARD_RIGHTS_ALL, &Attr );
120 if( !NT_SUCCESS( Status ) )
121 DbgPrint( "VGA: Failed to open refresh event\n" );
122 else {
123 ZwSetEvent( Event, &ThreadRelease );
124 ZwClose( Event );
125 }
126 }
127
128
129