2 * PROJECT: ReactOS Framebuffer Display Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: boot/drivers/video/displays/vga/palette.c
5 * PURPOSE: Palette Support
6 * PROGRAMMERS: Copyright (c) 1992-1995 Microsoft Corporation
11 // eVb: 4.1 [VGARISC Change] - Add static 16-color VGA palette from VGA NT4 DDK Sample
13 /******************************Public*Data*Struct*************************\
16 * This is the palette for the VGA.
18 \**************************************************************************/
20 // Little bit of hacking to get this to compile happily.
22 typedef struct _VGALOGPALETTE
26 PALETTEENTRY palPalEntry
[16];
29 const VGALOGPALETTE logPalVGA
=
32 0x400, // driver version
36 { 0x80,0, 0, 0 }, // 1
37 { 0, 0x80,0, 0 }, // 2
38 { 0x80,0x80,0, 0 }, // 3
39 { 0, 0, 0x80,0 }, // 4
40 { 0x80,0, 0x80,0 }, // 5
41 { 0, 0x80,0x80,0 }, // 6
42 { 0x80,0x80,0x80,0 }, // 7
44 { 0xC0,0xC0,0xC0,0 }, // 8
45 { 0xFF,0, 0, 0 }, // 9
46 { 0, 0xFF,0, 0 }, // 10
47 { 0xFF,0xFF,0, 0 }, // 11
48 { 0, 0, 0xFF,0 }, // 12
49 { 0xFF,0, 0xFF,0 }, // 13
50 { 0, 0xFF,0xFF,0 }, // 14
51 { 0xFF,0xFF,0xFF,0 } // 15
56 BOOL
bInitDefaultPalette(PPDEV ppdev
, DEVINFO
*pDevInfo
);
58 /******************************Public*Routine******************************\
61 * Initializes the palette information for this PDEV.
63 * Called by DrvEnablePDEV.
65 \**************************************************************************/
67 BOOL
bInitPaletteInfo(PPDEV ppdev
, DEVINFO
*pDevInfo
)
69 if (!bInitDefaultPalette(ppdev
, pDevInfo
))
75 /******************************Public*Routine******************************\
78 * Frees resources allocated by bInitPaletteInfo.
80 \**************************************************************************/
82 VOID
vDisablePalette(PPDEV ppdev
)
84 // Delete the default palette if we created one.
86 if (ppdev
->hpalDefault
)
88 EngDeletePalette(ppdev
->hpalDefault
);
89 ppdev
->hpalDefault
= (HPALETTE
) 0;
92 // eVb: 4.2 [VGARISC Change] - VGA Palette is static, no need to free
94 if (ppdev
->pPal
!= (PPALETTEENTRY
)NULL
)
95 EngFreeMem((PVOID
)ppdev
->pPal
);
100 /******************************Public*Routine******************************\
101 * bInitDefaultPalette
103 * Initializes default palette for PDEV.
105 \**************************************************************************/
107 BOOL
bInitDefaultPalette(PPDEV ppdev
, DEVINFO
*pDevInfo
)
109 // eVb: 4.3 [VGARISC Change] - VGA Palette is static, no need to build
111 if (ppdev
->ulBitCount
== 8)
117 // Allocate our palette
120 ppdev
->pPal
= (PPALETTEENTRY
)EngAllocMem(0, sizeof(PALETTEENTRY
) * 256,
123 if ((ppdev
->pPal
) == NULL
) {
124 RIP("DISP bInitDefaultPalette() failed EngAllocMem\n");
129 // Generate 256 (8*4*4) RGB combinations to fill the palette
132 jRed
= jGre
= jBlu
= 0;
134 for (ulLoop
= 0; ulLoop
< 256; ulLoop
++)
136 ppdev
->pPal
[ulLoop
].peRed
= jRed
;
137 ppdev
->pPal
[ulLoop
].peGreen
= jGre
;
138 ppdev
->pPal
[ulLoop
].peBlue
= jBlu
;
139 ppdev
->pPal
[ulLoop
].peFlags
= (BYTE
)0;
147 // Fill in Windows Reserved Colors from the WIN 3.0 DDK
148 // The Window Manager reserved the first and last 10 colors for
149 // painting windows borders and for non-palette managed applications.
152 for (ulLoop
= 0; ulLoop
< 10; ulLoop
++)
158 ppdev
->pPal
[ulLoop
] = BASEPALETTE
[ulLoop
];
164 ppdev
->pPal
[246 + ulLoop
] = BASEPALETTE
[ulLoop
+10];
170 // Create handle for palette.
174 pDevInfo
->hpalDefault
= EngCreatePalette(PAL_INDEXED
,
175 // eVb: 4.4 [VGARISC Change] - VGA Palette is 16 colors, not 256, and static
177 (PULONG
) &logPalVGA
.palPalEntry
,
181 if (ppdev
->hpalDefault
== (HPALETTE
) 0)
183 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
184 // eVb: 4.5 [VGARISC Change] - VGA Palette is static, no need to free
185 //EngFreeMem(ppdev->pPal);
191 // Initialize the hardware with the initial palette.
196 // eVb: 4.6 [VGARISC Change] - VGA Palette is static, no bitfield palette needed
201 pDevInfo
->hpalDefault
= EngCreatePalette(PAL_BITFIELDS
,
207 if (ppdev
->hpalDefault
== (HPALETTE
) 0)
209 RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
219 /******************************Public*Routine******************************\
220 * bInit256ColorPalette
222 * Initialize the hardware's palette registers.
224 \**************************************************************************/
226 BOOL
bInit256ColorPalette(PPDEV ppdev
)
228 BYTE ajClutSpace
[MAX_CLUT_SIZE
];
229 PVIDEO_CLUT pScreenClut
;
230 ULONG ulReturnedDataLength
;
232 PVIDEO_CLUTDATA pScreenClutData
;
234 if (ppdev
->ulBitCount
== 8)
237 // Fill in pScreenClut header info:
240 pScreenClut
= (PVIDEO_CLUT
) ajClutSpace
;
241 pScreenClut
->NumEntries
= 256;
242 pScreenClut
->FirstEntry
= 0;
249 pScreenClutData
= (PVIDEO_CLUTDATA
) (&(pScreenClut
->LookupTable
[0]));
253 pScreenClutData
[cColors
].Red
= ppdev
->pPal
[cColors
].peRed
>>
254 ppdev
->cPaletteShift
;
255 pScreenClutData
[cColors
].Green
= ppdev
->pPal
[cColors
].peGreen
>>
256 ppdev
->cPaletteShift
;
257 pScreenClutData
[cColors
].Blue
= ppdev
->pPal
[cColors
].peBlue
>>
258 ppdev
->cPaletteShift
;
259 pScreenClutData
[cColors
].Unused
= 0;
263 // Set palette registers:
266 if (EngDeviceIoControl(ppdev
->hDriver
,
267 IOCTL_VIDEO_SET_COLOR_REGISTERS
,
272 &ulReturnedDataLength
))
274 DISPDBG((0, "Failed bEnablePalette"));
279 DISPDBG((5, "Passed bEnablePalette"));
284 /******************************Public*Routine******************************\
287 * DDI entry point for manipulating the palette.
289 \**************************************************************************/
298 BYTE ajClutSpace
[MAX_CLUT_SIZE
];
299 PVIDEO_CLUT pScreenClut
;
300 PVIDEO_CLUTDATA pScreenClutData
;
303 UNREFERENCED_PARAMETER(fl
);
305 ppdev
= (PDEV
*) dhpdev
;
308 // Fill in pScreenClut header info:
311 pScreenClut
= (PVIDEO_CLUT
) ajClutSpace
;
312 pScreenClut
->NumEntries
= (USHORT
) cColors
;
313 pScreenClut
->FirstEntry
= (USHORT
) iStart
;
315 pScreenClutData
= (PVIDEO_CLUTDATA
) (&(pScreenClut
->LookupTable
[0]));
317 if (cColors
!= PALOBJ_cGetColors(ppalo
, iStart
, cColors
,
318 (ULONG
*) pScreenClutData
))
320 DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors\n"));
325 // Set the high reserved byte in each palette entry to 0.
326 // Do the appropriate palette shifting to fit in the DAC.
329 if (ppdev
->cPaletteShift
)
333 pScreenClutData
[cColors
].Red
>>= ppdev
->cPaletteShift
;
334 pScreenClutData
[cColors
].Green
>>= ppdev
->cPaletteShift
;
335 pScreenClutData
[cColors
].Blue
>>= ppdev
->cPaletteShift
;
336 pScreenClutData
[cColors
].Unused
= 0;
343 pScreenClutData
[cColors
].Unused
= 0;
348 // Set palette registers
351 if (EngDeviceIoControl(ppdev
->hDriver
,
352 IOCTL_VIDEO_SET_COLOR_REGISTERS
,
359 DISPDBG((0, "DrvSetPalette failed EngDeviceIoControl\n"));