Patch by Jonathon Wilson:
[reactos.git] / reactos / drivers / dd / vga / display / objects / screen.c
1 #include "../vgaddi.h"
2
3 static WORD PaletteBuffer[] = {
4 16, 0, // 16 entries, start with 0
5 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
6 };
7
8 static BYTE ColorBuffer[] = {
9 16, // 16 entries
10 0, 0,
11 0, // start with 0
12 0x00, 0x00, 0x00, 0x00, // black
13 0x2A, 0x00, 0x15, 0x00, // red
14 0x00, 0x2A, 0x15, 0x00, // green
15 0x2A, 0x2A, 0x15, 0x00, // brown
16 0x00, 0x00, 0x2A, 0x00, // blue
17 0x2A, 0x15, 0x2A, 0x00, // magenta
18 0x15, 0x2A, 0x2A, 0x00, // cyan
19 0x21, 0x22, 0x23, 0x00, // dark gray
20 0x30, 0x31, 0x32, 0x00, // light gray
21 0x3F, 0x00, 0x00, 0x00, // bright red
22 0x00, 0x3F, 0x00, 0x00, // bright green
23 0x3F, 0x3F, 0x00, 0x00, // bright yellow
24 0x00, 0x00, 0x3F, 0x00, // bright blue
25 0x3F, 0x00, 0x3F, 0x00, // bright magenta
26 0x00, 0x3F, 0x3F, 0x00, // bright cyan
27 0x3F, 0x3F, 0x3F, 0x00 // bright white
28 };
29
30 DWORD getAvailableModes(HANDLE Driver,
31 PVIDEO_MODE_INFORMATION *modeInformation,
32 DWORD *ModeSize)
33 {
34 ULONG Temp;
35 VIDEO_NUM_MODES modes;
36 PVIDEO_MODE_INFORMATION VideoTemp;
37
38 // get number of modes supported
39 if (EngDeviceIoControl(Driver,
40 IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
41 NULL,
42 0,
43 &modes,
44 sizeof(VIDEO_NUM_MODES),
45 &Temp))
46 {
47 // get modes failed
48 return(0);
49 }
50
51 *ModeSize = modes.ModeInformationLength;
52
53 // allocate buffer for the mini-port to write the modes in
54 *modeInformation = (PVIDEO_MODE_INFORMATION)
55 EngAllocMem(0, modes.NumModes *
56 modes.ModeInformationLength, ALLOC_TAG);
57
58 if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
59 {
60 // couldn't allocate buffer
61 return 0;
62 }
63
64 // Ask the mini-port to fill in the available modes.
65 if (EngDeviceIoControl(Driver,
66 IOCTL_VIDEO_QUERY_AVAIL_MODES,
67 NULL,
68 0,
69 *modeInformation,
70 modes.NumModes * modes.ModeInformationLength,
71 &Temp))
72 {
73 // failed to query modes
74 EngFreeMem(*modeInformation);
75 *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
76
77 return(0);
78 }
79
80 // Which modes supported by miniport driver are also suppoted by us, the
81 // display driver
82
83 Temp = modes.NumModes;
84 VideoTemp = *modeInformation;
85
86 // Reject mode if it's not 4 planes or not graphic or not 1 bits per pel
87 while (Temp--)
88 {
89 if ((VideoTemp->NumberOfPlanes != 4 ) ||
90 !(VideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
91 (VideoTemp->BitsPerPlane != 1) ||
92 BROKEN_RASTERS(VideoTemp->ScreenStride, VideoTemp->VisScreenHeight))
93
94 {
95 VideoTemp->Length = 0;
96 }
97
98 VideoTemp = (PVIDEO_MODE_INFORMATION)(((PUCHAR)VideoTemp) + modes.ModeInformationLength);
99 }
100
101 return modes.NumModes;
102 }
103
104 BOOL InitVGA(PPDEV ppdev, BOOL bFirst)
105 {
106 ULONG ReturnedDataLength;
107
108 ppdev->sizeSurf.cx = 640;
109 ppdev->sizeSurf.cy = 480;
110 ppdev->ModeNum = 12;
111
112 // Set the mode that was requested
113 if (EngDeviceIoControl(ppdev->KMDriver,
114 IOCTL_VIDEO_SET_CURRENT_MODE,
115 &ppdev->ModeNum,
116 sizeof(VIDEO_MODE),
117 NULL,
118 0,
119 &ReturnedDataLength)) {
120 return(FALSE);
121 }
122
123 // set up internal palette
124 if (EngDeviceIoControl(ppdev->KMDriver,
125 IOCTL_VIDEO_SET_PALETTE_REGISTERS,
126 (PVOID) PaletteBuffer,
127 sizeof (PaletteBuffer),
128 NULL,
129 0,
130 &ReturnedDataLength)) {
131 return(FALSE);
132 }
133
134 // set up the DAC
135 if (EngDeviceIoControl(ppdev->KMDriver,
136 IOCTL_VIDEO_SET_COLOR_REGISTERS,
137 (PVOID) ColorBuffer,
138 sizeof (ColorBuffer),
139 NULL,
140 0,
141 &ReturnedDataLength)) {
142 return(FALSE);
143 }
144
145 /*
146
147 gotta fix this up.. it prevents drawing to vidmem right now
148
149 if (bFirst) {
150 // map video memory into virtual memory
151 VideoMemory.RequestedVirtualAddress = NULL;
152
153 if (EngDeviceIoControl(ppdev->KMDriver,
154 IOCTL_VIDEO_MAP_VIDEO_MEMORY,
155 (PVOID) &VideoMemory,
156 sizeof (VIDEO_MEMORY),
157 (PVOID) &VideoMemoryInfo,
158 sizeof (VideoMemoryInfo),
159 &ReturnedDataLength)) {
160 // Failed to map to virtual memory
161 return (FALSE);
162 }
163
164 ppdev->fbScreen = VideoMemoryInfo.FrameBufferBase;
165 }
166 */
167 return TRUE;
168 }