7aceede903e9ee09c5c2fda034771d0a75ac335c
[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,
93 VideoTemp->VisScreenHeight))
94
95 {
96 VideoTemp->Length = 0;
97 }
98
99 VideoTemp = (PVIDEO_MODE_INFORMATION)
100 (((PUCHAR)VideoTemp) + modes.ModeInformationLength);
101 }
102
103 return modes.NumModes;
104 }
105
106 BOOL InitVGA(PPDEV ppdev, BOOL bFirst)
107 {
108 UINT ReturnedDataLength;
109 VIDEO_MEMORY VideoMemory;
110 VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
111
112 ppdev->ModeNum = 12;
113
114 // Set the mode that was requested
115 if (EngDeviceIoControl(ppdev->KMDriver,
116 IOCTL_VIDEO_SET_CURRENT_MODE,
117 &ppdev->ModeNum,
118 sizeof(VIDEO_MODE),
119 NULL,
120 0,
121 &ReturnedDataLength)) {
122 return(FALSE);
123 }
124
125 // set up internal palette
126 if (EngDeviceIoControl(ppdev->KMDriver,
127 IOCTL_VIDEO_SET_PALETTE_REGISTERS,
128 (PVOID) PaletteBuffer,
129 sizeof (PaletteBuffer),
130 NULL,
131 0,
132 &ReturnedDataLength)) {
133 return(FALSE);
134 }
135
136 // set up the DAC
137 if (EngDeviceIoControl(ppdev->KMDriver,
138 IOCTL_VIDEO_SET_COLOR_REGISTERS,
139 (PVOID) ColorBuffer,
140 sizeof (ColorBuffer),
141 NULL,
142 0,
143 &ReturnedDataLength)) {
144 return(FALSE);
145 }
146
147 if (bFirst) {
148
149 // map video memory into virtual memory
150 VideoMemory.RequestedVirtualAddress = NULL;
151
152 if (EngDeviceIoControl(ppdev->KMDriver,
153 IOCTL_VIDEO_MAP_VIDEO_MEMORY,
154 (PVOID) &VideoMemory,
155 sizeof (VIDEO_MEMORY),
156 (PVOID) &VideoMemoryInfo,
157 sizeof (VideoMemoryInfo),
158 &ReturnedDataLength)) {
159 // Failed to map to virtual memory
160 return (FALSE);
161 }
162
163 ppdev->fbScreen = VideoMemoryInfo.FrameBufferBase;
164 }
165
166 return TRUE;
167 }