3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 // I really really hate 16 color bit plane modes.
32 // They should all burn in hell for what they've
33 // done to my sleeping habits. And I still can't
34 // get this code to work and I have absolutely
37 // Someone else can take up this portion of the
38 // boot loader because my give up...
40 // I was going to store the offscreen buffer as
41 // a big array of bytes (as opposed to four bits)
42 // and that makes it a bit easier to set a pixel
43 // on the offscreen buffer, but will have to be
44 // handled in the VideoCopyOffScreenBufferToVRAM()
47 VOID
VideoSetPixel16(U32 X
, U32 Y
, U8 Color
)
56 MemoryPointer
= (U8
*)(VIDEOVGA_MEM_ADDRESS
);
58 // Calculate the byte offset into the bit-plane
59 // where the pixel is to be set and the bit
60 // offset in that byte.
61 //ByteOffset = (Y * VideoGetBytesPerScanLine()) + (X >> 3);
62 //ByteOffset = (Y * 80) + (X >> 3);
63 ByteOffset
= (Y
* 640) + X
;
64 BitInByte
= ByteOffset
& 7;
65 ByteOffset
= ByteOffset
>> 3;
66 //BitToChange = 0x80 >> BitInByte;
69 DbgPrint((DPRINT_WARNING
, "X = %d Y = %d Color = %d ByteOffset = %d BitInByte = %d BitToChange = %d\n", X
, Y
, Color
, ByteOffset
, BitInByte
, BitToChange
));
72 // Read the byte of memory to be changed. This is a
73 // read for the video card latches and the data read
74 // from memory does not need to be used.
75 ReadByte
= MemoryPointer
[ByteOffset
];
77 // Select the bit or bits in the byte that need to be
78 // changed through index 8 of the VGA card address
79 // register by sending an 8 out to I/O port 3CEh.
80 // Next get the bits to be changed (a one-bit represents
81 // a bit to be changed) and send this out to I/O
82 // port 3CFh, the bit mask register (BMR).
83 //WRITE_PORT_USHORT((U16*)0x3CE, (((U16)BitToChange) << 8) + 0x08);
84 WRITE_PORT_UCHAR((U8
*)0x3CE, 0x08);
85 //WRITE_PORT_UCHAR((U8*)0x3CF, BitToChange);
86 WRITE_PORT_UCHAR((U8
*)0x3CF, BitInByte
);
88 // Next set all mask bits to 1111 in the map mask register
89 // (MMR) at sequencer offset 2, and write color 0 to the
90 // VGA card to set the color to black. The mask bits select
91 // the bit planes to be changed. If all are selected and a
92 // color of 0 is written, all four bit-planes are clear to zero.
93 WRITE_PORT_USHORT((U16
*)0x3C4, 0x0F02);
94 //WRITE_PORT_UCHAR((U8*)0x3C4, 0x02);
95 //WRITE_PORT_UCHAR((U8*)0x3C5, 0x0F); // Mask to 1111 binary
96 MemoryPointer
[ByteOffset
] = 0x00;
98 // Send the desired color number to the map mask register and
99 // write an FFh to the video memory. This places a logic one
100 // in only the selected bit planes to write a new color to
101 // a pixel or dot on the screen.
102 WRITE_PORT_UCHAR((U8
*)0x3C4, 0x02);
103 //WRITE_PORT_UCHAR((U8*)0x3C5, Color);
104 WRITE_PORT_UCHAR((U8
*)0x3C5, 0x0F);
105 //WRITE_PORT_USHORT((U16*)0x3C4, 0x0A02);
106 MemoryPointer
[ByteOffset
] = 0xFF;
109 /*CurrentColor = Color;
111 MemoryPointer = (U8*)(VIDEOVGA_MEM_ADDRESS);
113 WRITE_PORT_USHORT((U16*)0x3CE, 0x00 | (CurrentColor << 8));
114 WRITE_PORT_USHORT((U16*)0x3CE, 0x08 | 0x8000 >> (X & 7));
116 MemoryPointer += (Y * VideoGetBytesPerScanLine()) + (X >> 3);
118 *MemoryPointer = *MemoryPointer;
122 // First select the color plane
123 //ColorPlane = Color;
124 //ColorPlane = (ColorPlane << 8) + 0x02;
125 //WRITE_PORT_USHORT((U16*)0x3C4, ColorPlane);
127 // Now calculate the byte offset in the
128 // color plane that contains our pixel
129 // Since there are 8 pixels per byte we
130 // have to adjust accordingly
131 /*ByteOffset = (Y * VideoGetCurrentModeResolutionX()) + X;
132 BitInByte = ByteOffset % 8;
133 ByteOffset = ByteOffset / 8;
135 // Shift the color to the right bit
137 Color = Color << BitInByte;
139 // Get the current color
140 CurrentColor = MemoryPointer[ByteOffset];
143 CurrentColor = CurrentColor | Color;
146 MemoryPointer[ByteOffset] = CurrentColor;*/
149 VOID
VideoSetPixel256(U32 X
, U32 Y
, U8 Color
)
155 MemoryPointer
= (U8
*)(VIDEOVGA_MEM_ADDRESS
);
157 Bank
= VideoGetMemoryBankForPixel(X
, Y
);
158 Offset
= VideoGetBankOffsetForPixel(X
, Y
);
160 VideoSetMemoryBank(Bank
);
162 MemoryPointer
[Offset
] = Color
;
165 VOID
VideoSetPixelRGB_15Bit(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
172 MemoryPointer
= (U8
*)(VIDEOVGA_MEM_ADDRESS
);
174 Bank
= VideoGetMemoryBankForPixel(X
, Y
);
175 Offset
= VideoGetBankOffsetForPixel(X
, Y
);
177 VideoSetMemoryBank(Bank
);
183 Pixel
= Red
<< 11 | Green
<< 6 | Blue
<< 1;
185 MemoryPointer
[Offset
] = Pixel
& 0xFF;
186 MemoryPointer
[Offset
+1] = Pixel
>> 8;
189 VOID
VideoSetPixelRGB_16Bit(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
196 MemoryPointer
= (U8
*)(VIDEOVGA_MEM_ADDRESS
);
198 Bank
= VideoGetMemoryBankForPixel(X
, Y
);
199 Offset
= VideoGetBankOffsetForPixel(X
, Y
);
201 VideoSetMemoryBank(Bank
);
207 Pixel
= (U16
)Red
<< 11 | (U16
)Green
<< 5 | (U16
)Blue
<< 0;
209 MemoryPointer
[Offset
] = Pixel
& 0xFF;
210 MemoryPointer
[Offset
+1] = Pixel
>> 8;
213 VOID
VideoSetPixelRGB_24Bit(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
219 MemoryPointer
= (U8
*)(VIDEOVGA_MEM_ADDRESS
);
221 Bank
= VideoGetMemoryBankForPixel(X
, Y
);
222 Offset
= VideoGetBankOffsetForPixel(X
, Y
);
224 VideoSetMemoryBank(Bank
);
226 MemoryPointer
[Offset
] = Blue
;
227 MemoryPointer
[Offset
+1] = Green
;
228 MemoryPointer
[Offset
+2] = Red
;
231 VOID
VideoSetPixelRGB(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
233 if (VesaVideoModeInformation
.BitsPerPixel
>= 24)
235 VideoSetPixelRGB_24Bit(X
, Y
, Red
, Green
, Blue
);
237 else if (VesaVideoModeInformation
.BitsPerPixel
>= 16)
239 // 16-bit color modes give green an extra bit (5:6:5)
240 // 15-bit color modes have just 5:5:5 for R:G:B
241 if (VesaVideoModeInformation
.GreenMaskSize
== 6)
243 VideoSetPixelRGB_16Bit(X
, Y
, Red
, Green
, Blue
);
247 VideoSetPixelRGB_15Bit(X
, Y
, Red
, Green
, Blue
);
252 BugCheck((DPRINT_UI
, "This function does not support %d bits per pixel!", VesaVideoModeInformation
.BitsPerPixel
));
256 VOID
VideoSetPixel16_OffScreen(U32 X
, U32 Y
, U8 Color
)
260 VOID
VideoSetPixel256_OffScreen(U32 X
, U32 Y
, U8 Color
)
264 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
+ VideoGetOffScreenMemoryOffsetForPixel(X
, Y
));
266 *MemoryPointer
= Color
;
269 VOID
VideoSetPixelRGB_15Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
275 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
276 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
282 Pixel
= Red
<< 11 | Green
<< 6 | Blue
<< 1;
284 MemoryPointer
[Offset
] = Pixel
& 0xFF;
285 MemoryPointer
[Offset
+1] = Pixel
>> 8;
288 VOID
VideoSetPixelRGB_16Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
294 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
295 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
301 Pixel
= (U16
)Red
<< 11 | (U16
)Green
<< 5 | (U16
)Blue
<< 0;
303 MemoryPointer
[Offset
] = Pixel
& 0xFF;
304 MemoryPointer
[Offset
+1] = Pixel
>> 8;
307 VOID
VideoSetPixelRGB_24Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
312 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
313 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
315 MemoryPointer
[Offset
] = Blue
;
316 MemoryPointer
[Offset
+1] = Green
;
317 MemoryPointer
[Offset
+2] = Red
;
320 VOID
VideoSetPixelRGB_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
322 if (VesaVideoModeInformation
.BitsPerPixel
>= 24)
324 VideoSetPixelRGB_24Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
326 else if (VesaVideoModeInformation
.BitsPerPixel
>= 16)
328 // 16-bit color modes give green an extra bit (5:6:5)
329 // 15-bit color modes have just 5:5:5 for R:G:B
330 if (VesaVideoModeInformation
.GreenMaskSize
== 6)
332 VideoSetPixelRGB_16Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
336 VideoSetPixelRGB_15Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
341 BugCheck((DPRINT_UI
, "This function does not support %d bits per pixel!", VesaVideoModeInformation
.BitsPerPixel
));