Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / drivers / dd / vga / miniport / initvga.c
1 #define NTOS_KERNEL_MODE
2 #include <ntos.h>
3 #include <ntos/ntddvid.h>
4 #include <ddk/ntddk.h>
5 #include <debug.h>
6 #include "vgavideo.h"
7
8 void outxay(PUSHORT ad, UCHAR x, UCHAR y)
9 {
10 USHORT xy = (x << 8) + y;
11
12 VideoPortWritePortUshort(ad, xy);
13 }
14
15 void setMode(VideoMode mode)
16 {
17 unsigned char x;
18 unsigned int y, c, a, m, n;
19
20 VideoPortWritePortUchar((PUCHAR)MISC, mode.Misc);
21 VideoPortWritePortUchar((PUCHAR)STATUS, 0);
22 VideoPortWritePortUchar((PUCHAR)FEATURE, mode.Feature);
23
24 for(x=0; x<5; x++)
25 {
26 outxay((PUSHORT)SEQ, mode.Seq[x], x);
27 }
28
29 VideoPortWritePortUshort((PUSHORT)CRTC, 0x11);
30 VideoPortWritePortUshort((PUSHORT)CRTC, (mode.Crtc[0x11] & 0x7f));
31
32 for(x=0; x<25; x++)
33 {
34 outxay((PUSHORT)CRTC, mode.Crtc[x], x);
35 }
36
37 for(x=0; x<9; x++)
38 {
39 outxay((PUSHORT)GRAPHICS, mode.Gfx[x], x);
40 }
41
42 x=VideoPortReadPortUchar((PUCHAR)FEATURE);
43
44 for(x=0; x<21; x++)
45 {
46 VideoPortWritePortUchar((PUCHAR)ATTRIB, x);
47 VideoPortWritePortUchar((PUCHAR)ATTRIB, mode.Attrib[x]);
48 }
49
50 x=VideoPortReadPortUchar((PUCHAR)STATUS);
51
52 VideoPortWritePortUchar((PUCHAR)ATTRIB, 0x20);
53 }
54
55 VideoMode Mode12 = {
56 0xa000, 0xe3, 0x00,
57
58 {0x03, 0x01, 0x0f, 0x00, 0x06 },
59
60 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
62 0xff},
63
64 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff},
65
66 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
67 0x0c, 0x0d, 0x0e, 0x0f, 0x81, 0x00, 0x0f, 0x00, 0x00}
68 };
69
70 void InitVGAMode()
71 {
72 int i;
73 VIDEO_X86_BIOS_ARGUMENTS vxba;
74 NTSTATUS vps;
75
76 // FIXME: Use Vidport to map the memory properly
77 vidmem = (char *)(0xd0000000 + 0xa0000);
78 memset(&vxba, 0, sizeof(vxba));
79 vxba.Eax = 0x0012;
80 vps = VideoPortInt10(NULL, &vxba);
81
82 // Get VGA registers into the correct state (mainly for setting up the palette registers correctly)
83 setMode(Mode12);
84
85 // Get the VGA into the mode we want to work with
86 WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08); // Set
87 WRITE_PORT_UCHAR((PUCHAR)0x3cf,0); // the MASK
88 WRITE_PORT_USHORT((PUSHORT)0x3ce,0x0205); // write mode = 2 (bits 0,1) read mode = 0 (bit 3)
89 i = READ_REGISTER_UCHAR(vidmem); // Update bit buffer
90 WRITE_REGISTER_UCHAR(vidmem, 0); // Write the pixel
91 WRITE_PORT_UCHAR((PUCHAR)0x3ce,0x08);
92 WRITE_PORT_UCHAR((PUCHAR)0x3cf,0xff);
93
94 // Zero out video memory (clear a possibly trashed screen)
95 RtlZeroMemory(vidmem, 64000);
96
97 vgaPreCalc();
98 }
99
100 VOID VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
101 {
102 char *vidmem;
103 HANDLE Event;
104 OBJECT_ATTRIBUTES Attr;
105 UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\TextConsoleRefreshEvent");
106 NTSTATUS Status;
107 VIDEO_X86_BIOS_ARGUMENTS vxba;
108 NTSTATUS vps;
109 ULONG ThreadRelease = 1;
110
111 CHECKPOINT;
112 Event = 0;
113
114 memset(&vxba, 0, sizeof(vxba));
115 vxba.Eax = 0x0003;
116 vps = VideoPortInt10(NULL, &vxba);
117 memset(&vxba, 0, sizeof(vxba));
118 vxba.Eax = 0x1112;
119 vps = VideoPortInt10(NULL, &vxba);
120 InitializeObjectAttributes( &Attr, &Name, 0, 0, 0 );
121 Status = ZwOpenEvent( &Event, STANDARD_RIGHTS_ALL, &Attr );
122 if( !NT_SUCCESS( Status ) )
123 DbgPrint( "VGA: Failed to open refresh event\n" );
124 else {
125 ZwSetEvent( Event, &ThreadRelease );
126 ZwClose( Event );
127 }
128 }