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.
28 #if 0 /* This stuff isn't used and as far as I'm concerned it can go - GvG */
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 U32 Width
, Height
, Depth
;
235 MachVideoGetDisplaySize(&Width
, &Height
, &Depth
);
238 VideoSetPixelRGB_24Bit(X
, Y
, Red
, Green
, Blue
);
240 else if (Depth
>= 16)
242 VideoSetPixelRGB_16Bit(X
, Y
, Red
, Green
, Blue
);
244 else if (Depth
== 15)
246 VideoSetPixelRGB_15Bit(X
, Y
, Red
, Green
, Blue
);
250 BugCheck((DPRINT_UI
, "This function does not support %d bits per pixel!", Depth
));
254 VOID
VideoSetPixel16_OffScreen(U32 X
, U32 Y
, U8 Color
)
258 VOID
VideoSetPixel256_OffScreen(U32 X
, U32 Y
, U8 Color
)
262 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
+ VideoGetOffScreenMemoryOffsetForPixel(X
, Y
));
264 *MemoryPointer
= Color
;
267 VOID
VideoSetPixelRGB_15Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
273 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
274 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
280 Pixel
= Red
<< 11 | Green
<< 6 | Blue
<< 1;
282 MemoryPointer
[Offset
] = Pixel
& 0xFF;
283 MemoryPointer
[Offset
+1] = Pixel
>> 8;
286 VOID
VideoSetPixelRGB_16Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
292 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
293 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
299 Pixel
= (U16
)Red
<< 11 | (U16
)Green
<< 5 | (U16
)Blue
<< 0;
301 MemoryPointer
[Offset
] = Pixel
& 0xFF;
302 MemoryPointer
[Offset
+1] = Pixel
>> 8;
305 VOID
VideoSetPixelRGB_24Bit_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
310 MemoryPointer
= (U8
*)(VideoOffScreenBuffer
);
311 Offset
= VideoGetOffScreenMemoryOffsetForPixel(X
, Y
);
313 MemoryPointer
[Offset
] = Blue
;
314 MemoryPointer
[Offset
+1] = Green
;
315 MemoryPointer
[Offset
+2] = Red
;
318 VOID
VideoSetPixelRGB_OffScreen(U32 X
, U32 Y
, U8 Red
, U8 Green
, U8 Blue
)
320 U32 Width
, Height
, Depth
;
322 MachVideoGetDisplaySize(&Width
, &Height
, &Depth
);
325 VideoSetPixelRGB_24Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
327 else if (Depth
>= 16)
329 VideoSetPixelRGB_16Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
331 else if (Depth
== 15)
333 VideoSetPixelRGB_15Bit_OffScreen(X
, Y
, Red
, Green
, Blue
);
337 BugCheck((DPRINT_UI
, "This function does not support %d bits per pixel!", Depth
));