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