// === CODE ===
/**
- * \fn void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Pitch, Uint32 BGC, Uint32 FGC)
* \brief Render a font character
*/
-void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Pitch, Uint32 BGC, Uint32 FGC)
+void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Depth, int Pitch, Uint32 BGC, Uint32 FGC)
{
Uint8 *font;
- Uint32 *buf = Buffer;
int x, y;
- font = VT_Font_GetChar(Codepoint);
-
- for(y = 0; y < FONT_HEIGHT; y ++)
+ // 8-bpp and below
+ if( Depth <= 8 )
{
- for(x = 0; x < FONT_WIDTH; x ++)
+ Uint8 *buf = Buffer;
+
+ font = VT_Font_GetChar(Codepoint);
+
+ for(y = 0; y < FONT_HEIGHT; y ++)
{
- if(*font & (1 << (FONT_WIDTH-x-1)))
- buf[x] = FGC;
- else
- buf[x] = BGC;
+ for(x = 0; x < FONT_WIDTH; x ++)
+ {
+ if(*font & (1 << (FONT_WIDTH-x-1)))
+ buf[x] = FGC;
+ else
+ buf[x] = BGC;
+ }
+ buf = (void*)( (tVAddr)buf + Pitch );
+ font ++;
+ }
+ }
+ // 16-bpp and below
+ else if( Depth <= 16 )
+ {
+ Uint16 *buf = Buffer;
+
+ font = VT_Font_GetChar(Codepoint);
+
+ for(y = 0; y < FONT_HEIGHT; y ++)
+ {
+ for(x = 0; x < FONT_WIDTH; x ++)
+ {
+ if(*font & (1 << (FONT_WIDTH-x-1)))
+ buf[x] = FGC;
+ else
+ buf[x] = BGC;
+ }
+ buf = (void*)( (tVAddr)buf + Pitch );
+ font ++;
+ }
+ }
+ // 24-bpp colour
+ // - Special handling to not overwrite the next pixel
+ //TODO: Endian issues here
+ else if( Depth == 24 )
+ {
+ Uint8 *buf = Buffer;
+ Uint8 bg_r = (BGC >> 16) & 0xFF;
+ Uint8 bg_g = (BGC >> 8) & 0xFF;
+ Uint8 bg_b = (BGC >> 0) & 0xFF;
+ Uint8 fg_r = (FGC >> 16) & 0xFF;
+ Uint8 fg_g = (FGC >> 8) & 0xFF;
+ Uint8 fg_b = (FGC >> 0) & 0xFF;
+
+ font = VT_Font_GetChar(Codepoint);
+
+ for(y = 0; y < FONT_HEIGHT; y ++)
+ {
+ for(x = 0; x < FONT_WIDTH; x ++)
+ {
+ Uint8 r, g, b;
+
+ if(*font & (1 << (FONT_WIDTH-x-1))) {
+ r = fg_r; g = fg_g; b = fg_b;
+ }
+ else {
+ r = bg_r; g = bg_g; b = bg_b;
+ }
+ buf[x*3+0] = b;
+ buf[x*3+1] = g;
+ buf[x*3+2] = r;
+ }
+ buf = (void*)( (tVAddr)buf + Pitch );
+ font ++;
+ }
+ }
+ // 32-bpp colour (nice and easy)
+ else if( Depth == 32 )
+ {
+ Uint32 *buf = Buffer;
+
+ font = VT_Font_GetChar(Codepoint);
+
+ for(y = 0; y < FONT_HEIGHT; y ++)
+ {
+ for(x = 0; x < FONT_WIDTH; x ++)
+ {
+ if(*font & (1 << (FONT_WIDTH-x-1)))
+ buf[x] = FGC;
+ else
+ buf[x] = BGC;
+ }
+ buf = (Uint32*)( (tVAddr)buf + Pitch );
+ font ++;
}
- buf += Pitch;
- font ++;
}
}
/**
* \fn Uint32 VT_Colour12to24(Uint16 Col12)
- * \brief Converts a
+ * \brief Converts a 12-bit colour into 24 bits
*/
Uint32 VT_Colour12to24(Uint16 Col12)
{
ret |= (tmp << 16) | (tmp << 20);
return ret;
}
+/**
+ * \brief Converts a 12-bit colour into 15 bits
+ */
+Uint16 VT_Colour12to15(Uint16 Col12)
+{
+ Uint32 ret;
+ int tmp;
+ tmp = Col12 & 0xF;
+ ret = (tmp << 1) | (tmp & 1);
+ tmp = (Col12 & 0xF0) >> 4;
+ ret |= ( (tmp << 1) | (tmp & 1) ) << 5;
+ tmp = (Col12 & 0xF00) >> 8;
+ ret |= ( (tmp << 1) | (tmp & 1) ) << 10;
+ return ret;
+}
+
+/**
+ * \brief Converts a 12-bit colour into any other depth
+ * \param Col12 12-bit source colour
+ * \param Depth Desired bit deptj
+ * \note Green then blue get the extra avaliable bits (16:5-6-5, 14:4-5-5)
+ */
+Uint32 VT_Colour12toN(Uint16 Col12, int Depth)
+{
+ Uint32 ret;
+ Uint32 r, g, b;
+ int rSize, gSize, bSize;
+
+ // Fast returns
+ if( Depth == 24 ) return VT_Colour12to24(Col12);
+ if( Depth == 15 ) return VT_Colour12to15(Col12);
+
+ // Bounds checks
+ if( Depth < 8 ) return 0;
+ if( Depth > 32 ) return 0;
+
+ r = Col12 & 0xF;
+ g = (Col12 & 0xF0) >> 4;
+ b = (Col12 & 0xF00) >> 8;
+
+ rSize = gSize = bSize = Depth / 3;
+ if( rSize + gSize + bSize < Depth ) // Depth % 3 == 1
+ gSize ++;
+ if( rSize + gSize + bSize < Depth ) // Depth % 3 == 2
+ bSize ++;
+
+ // Expand
+ r <<= rSize - 4; g <<= gSize - 4; b <<= bSize - 4;
+ // Fill with the lowest bit
+ if( Col12 & 0x001 ) r |= (1 << (rSize - 4)) - 1;
+ if( Col12 & 0x010 ) r |= (1 << (gSize - 4)) - 1;
+ if( Col12 & 0x100 ) r |= (1 << (bSize - 4)) - 1;
+
+ // Create output
+ ret = r;
+ ret |= g << rSize;
+ ret |= b << (rSize + gSize);
+
+ return ret;
+}
/**
* \fn Uint8 *VT_Font_GetChar(Uint32 Codepoint)
//! \brief Defines the height of a rendered character\r
extern int giVT_CharHeight;\r
/**\r
- * \fn void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Pitch, Uint32 BGC, Uint32 FGC)\r
* \brief Driver helper that renders a character to a buffer\r
* \param Codepoint Unicode character to render\r
- * \param Buffer Buffer to render to (32-bpp)\r
- * \param Pitch Number of DWords per line\r
+ * \param Buffer Buffer to render to\r
+ * \param Depth Bit depth of the destination buffer\r
+ * \param Pitch Number of bytes per line\r
* \param BGC 32-bit Background Colour\r
* \param FGC 32-bit Foreground Colour\r
* \r
* text mode by keeping the character rendering abstracted from the driver,\r
* easing the driver development and reducing code duplication.\r
*/\r
-extern void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Pitch, Uint32 BGC, Uint32 FGC);\r
+extern void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Depth, int Pitch, Uint32 BGC, Uint32 FGC);\r
/**\r
* \fn Uint32 VT_Colour12to24(Uint16 Col12)\r
- * \brief Converts a colour from 12bpp to 32bpp\r
+ * \brief Converts a colour from 12bpp to 24bpp\r
* \param Col12 12-bpp input colour\r
* \return Expanded 32-bpp (24-bit colour) version of \a Col12\r
*/\r
extern Uint32 VT_Colour12to24(Uint16 Col12);\r
+/**\r
+ * \brief Converts a colour from 12bpp to 14bpp\r
+ * \param Col12 12-bpp input colour\r
+ * \return 15 bits per pixel value\r
+ */\r
+extern Uint16 VT_Colour12to15(Uint16 Col12);\r
+/**\r
+ * \brief Converts a colour from 12bpp to 32bpp\r
+ * \param Col12 12-bpp input colour\r
+ * \param Depth Desired bit depth\r
+ * \return \a Depth bit number, denoting Col12\r
+ * \r
+ * Expands the source colour into a \a Depth bits per pixel representation.\r
+ * The colours are expanded with preference to Green, Blue and Red in that order\r
+ * (so, green gets the first spare pixel, blue gets the next, and red never gets\r
+ * the spare). \n\r
+ * The final bit of each component is used to fill the lower bits of the output.\r
+ */\r
+extern Uint32 VT_Colour12toN(Uint16 Col12, int Depth);\r
\r
/**\r
* \brief Handlers for eTplVideo_2DCommands\r
{\r
gVesa_Modes[i].flags |= FLAG_LFB;\r
gVesa_Modes[i].framebuffer = modeinfo->physbase;\r
- gVesa_Modes[i].fbSize = modeinfo->Xres*modeinfo->Yres*modeinfo->bpp/8;\r
+ gVesa_Modes[i].fbSize = modeinfo->Yres*modeinfo->pitch;\r
} else {\r
gVesa_Modes[i].framebuffer = 0;\r
gVesa_Modes[i].fbSize = 0;\r
case VIDEO_BUFFMT_TEXT:\r
{\r
tVT_Char *chars = Buffer;\r
- int pitch = gVesa_Modes[giVesaCurrentMode].width;\r
+ int pitch = gVesa_Modes[giVesaCurrentMode].pitch;\r
+ int depth = gVesa_Modes[giVesaCurrentMode].bpp;\r
int widthInChars = gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth;\r
int heightInChars = gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight;\r
int x, y;\r
- Uint32 *dest = (void*)gpVesa_Framebuffer;\r
+ Uint8 *dest = (void*)gpVesa_Framebuffer;\r
int i;\r
\r
Length /= sizeof(tVT_Char);\r
Offset /= sizeof(tVT_Char);\r
\r
- LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width);\r
+ LOG("gVesa_Modes[%i] = {height:%i, width:%i, pitch:%i}",\r
+ giVesaCurrentMode,\r
+ gVesa_Modes[giVesaCurrentMode].height,\r
+ gVesa_Modes[giVesaCurrentMode].width,\r
+ gVesa_Modes[giVesaCurrentMode].pitch\r
+ );\r
x = Offset % widthInChars;\r
y = Offset / widthInChars;\r
- LOG("(x,y) = (%i,%i) = [%i,%i]", x, y, x * giVT_CharWidth, y * giVT_CharHeight * pitch);\r
+ LOG("(x,y) = (%i,%i) = [%i,%i]",\r
+ x,\r
+ y,\r
+ x * giVT_CharWidth * depth / 8,\r
+ y * giVT_CharHeight * pitch\r
+ );\r
LOG("(w,h) = (%i,%i) = [%i,%i]",\r
(int)(Length % widthInChars),\r
(int)(Length / widthInChars),\r
- (int)((Length % widthInChars) * giVT_CharWidth),\r
+ (int)((Length % widthInChars) * giVT_CharWidth * depth / 8),\r
(int)((Length / widthInChars) * giVT_CharHeight * pitch)\r
);\r
\r
}\r
\r
dest += y * giVT_CharHeight * pitch;\r
- dest += x * giVT_CharWidth;\r
\r
LOG("dest = %p", dest);\r
\r
for( i = 0; i < (int)Length; i++ )\r
{\r
+ if(\r
+ !MM_GetPhysAddr( (tVAddr)dest + x*giVT_CharWidth*depth/8 )\r
+ // || !MM_GetPhysAddr( (tVAddr)dest + x*giVT_CharWidth*depth/8 + pitch*giVT_CharHeight-1)\r
+ )\r
+ {\r
+ Log_Notice("VESA", "Stopped at %i, not mapped", i);\r
+ break;\r
+ }\r
+ if( y >= heightInChars )\r
+ {\r
+ Log_Notice("VESA", "Stopped at %i", i);\r
+ break;\r
+ }\r
+ \r
VT_Font_Render(\r
chars->Ch,\r
- dest + x*giVT_CharWidth, pitch,\r
- VT_Colour12to24(chars->BGCol),\r
- VT_Colour12to24(chars->FGCol)\r
+ dest + x*giVT_CharWidth*depth/8, depth, pitch,\r
+ VT_Colour12toN(chars->BGCol, depth),\r
+ VT_Colour12toN(chars->FGCol, depth)\r
);\r
\r
chars ++;\r
x ++;\r
- if( x >= widthInChars ) {\r
+ if( x >= widthInChars )\r
+ {\r
x = 0;\r
y ++;\r
dest += pitch*giVT_CharHeight;\r
}\r
}\r
- Length *= sizeof(tVT_Char);\r
+ Length = i * sizeof(tVT_Char);\r
}\r
break;\r
\r
LOG("buffer = %p", Buffer);\r
LOG("Updating Framebuffer (%p to %p)", destBuf, destBuf + (Uint)Length);\r
\r
+ //TODO: Handle non 32-bpp framebuffer modes\r
\r
// Copy to Frambuffer\r
memcpy(destBuf, Buffer, Length);\r
* \brief Updates the video mode\r
*/\r
int Vesa_Int_SetMode(int mode)\r
-{\r
- Log_Log("VESA", "Setting mode to %i", mode);\r
- \r
+{ \r
// Sanity Check values\r
if(mode < 0 || mode > giVesaModeCount) return -1;\r
+\r
+ Log_Log("VESA", "Setting mode to %i (%ix%i %ibpp)",\r
+ mode,\r
+ gVesa_Modes[mode].width, gVesa_Modes[mode].height,\r
+ gVesa_Modes[mode].bpp\r
+ );\r
\r
// Check for fast return\r
if(mode == giVesaCurrentMode) return 1;\r
giVesaPageCount = (gVesa_Modes[mode].fbSize + 0xFFF) >> 12;\r
gpVesa_Framebuffer = (void*)MM_MapHWPages(gVesa_Modes[mode].framebuffer, giVesaPageCount);\r
\r
- Log_Log("VESA", "Framebuffer (Phys) = 0x%x", gVesa_Modes[mode].framebuffer);\r
- Log_Log("VESA", "Framebuffer (Virt) = 0x%x", gpVesa_Framebuffer);\r
+ Log_Log("VESA", "Framebuffer (Phys) = 0x%x, (Virt) = 0x%x, Size = 0x%x",\r
+ gVesa_Modes[mode].framebuffer, gpVesa_Framebuffer, giVesaPageCount << 12);\r
\r
// Record Mode Set\r
giVesaCurrentMode = mode;\r
{\r
LOG("Mode %i (%ix%ix%i)", i, gVesa_Modes[i].width, gVesa_Modes[i].height, gVesa_Modes[i].bpp);\r
\r
- if(gVesa_Modes[i].width == data->width\r
- && gVesa_Modes[i].height == data->height\r
- && gVesa_Modes[i].bpp == data->bpp)\r
+ if(gVesa_Modes[i].width == data->width && gVesa_Modes[i].height == data->height)\r
{\r
- LOG("Perfect!");\r
- best = i;\r
- break;\r
+ if( (data->bpp == 32 || data->bpp == 24)\r
+ && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) )\r
+ {\r
+ LOG("Perfect!");\r
+ best = i;\r
+ break;\r
+ }\r
}\r
\r
tmp = gVesa_Modes[i].width * gVesa_Modes[i].height;\r
*/\r
void Vesa_FlipCursor(void *Arg)\r
{\r
- int pitch = gpVesaCurMode->pitch/4;\r
+ int pitch = gpVesaCurMode->pitch;\r
+ int bytes_per_px = (gpVesaCurMode->bpp + 7) / 8;\r
int x = giVesaCursorX*giVT_CharWidth;\r
int y = giVesaCursorY*giVT_CharHeight;\r
int i;\r
- Uint32 *fb = (void*)gpVesa_Framebuffer;\r
+ Uint8 *fb = (void*)gpVesa_Framebuffer;\r
\r
//Debug("Cursor flip");\r
\r
// Sanity check\r
if(giVesaCursorX < 0 || giVesaCursorY < 0\r
- || y*pitch + x + (giVT_CharHeight-1)*pitch > (int)gpVesaCurMode->fbSize/4) {\r
+ || y*pitch + x + (giVT_CharHeight-1)*pitch > (int)gpVesaCurMode->fbSize) {\r
Log_Notice("VESA", "Cursor OOB (%i,%i)", x, y);\r
giVesaCursorTimer = -1;\r
return;\r
}\r
\r
// Draw cursor\r
- fb += (y+1)*pitch + x;\r
- for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch )\r
- *fb = ~*fb;\r
+ fb += (y+1)*pitch + x*bytes_per_px;\r
+ \r
+ switch(bytes_per_px)\r
+ {\r
+ case 1:\r
+ for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch )\r
+ *fb = ~*fb;\r
+ break;\r
+ case 2:\r
+ for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
+ fb[0] = ~fb[0];\r
+ fb[1] = ~fb[1];\r
+ }\r
+ break;\r
+ case 3:\r
+ for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
+ fb[0] = ~fb[0];\r
+ fb[1] = ~fb[1];\r
+ fb[2] = ~fb[2];\r
+ }\r
+ break;\r
+ case 4:\r
+ for( i = 1; i < giVT_CharHeight-1; i++, fb += pitch ) {\r
+ fb[0] = ~fb[0];\r
+ fb[1] = ~fb[1];\r
+ fb[2] = ~fb[2];\r
+ fb[3] = ~fb[3];\r
+ }\r
+ break;\r
+ default:\r
+ Log_Error("VESA", "Vesa_FlipCursor - Bug Report, unknown bytes_per_px (%i)", bytes_per_px);\r
+ giVesaCursorTimer = -1;\r
+ return ;\r
+ }\r
\r
#if BLINKING_CURSOR\r
giVesaCursorTimer = Time_CreateTimer(VESA_CURSOR_PERIOD, Vesa_FlipCursor, Arg);\r
// ------------------------\r
void Vesa_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour)\r
{\r
+ // TODO: Handle non-32bit modes\r
int pitch = gpVesaCurMode->pitch/4;\r
Uint32 *buf = (Uint32*)gpVesa_Framebuffer + Y*pitch + X;\r
while( H -- ) {\r
\r
void Vesa_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H)\r
{\r
- int scrnpitch = gVesa_Modes[giVesaCurrentMode].pitch;\r
+ int scrnpitch = gpVesaCurMode->pitch;\r
+ int bytes_per_px = (gpVesaCurMode->bpp + 7) / 8;\r
int dst = DstY*scrnpitch + DstX;\r
int src = SrcY*scrnpitch + SrcX;\r
int tmp;\r
//Log("Vesa_2D_Blit: (Ent=%p, DstX=%i, DstY=%i, SrcX=%i, SrcY=%i, W=%i, H=%i)",\r
// Ent, DstX, DstY, SrcX, SrcY, W, H);\r
\r
- if(SrcX + W > gVesa_Modes[giVesaCurrentMode].width)\r
- W = gVesa_Modes[giVesaCurrentMode].width - SrcX;\r
- if(DstX + W > gVesa_Modes[giVesaCurrentMode].width)\r
- W = gVesa_Modes[giVesaCurrentMode].width - DstX;\r
- if(SrcY + H > gVesa_Modes[giVesaCurrentMode].height)\r
- H = gVesa_Modes[giVesaCurrentMode].height - SrcY;\r
- if(DstY + H > gVesa_Modes[giVesaCurrentMode].height)\r
- H = gVesa_Modes[giVesaCurrentMode].height - DstY;\r
+ if(SrcX + W > gpVesaCurMode->width)\r
+ W = gpVesaCurMode->width - SrcX;\r
+ if(DstX + W > gpVesaCurMode->width)\r
+ W = gpVesaCurMode->width - DstX;\r
+ if(SrcY + H > gpVesaCurMode->height)\r
+ H = gpVesaCurMode->height - SrcY;\r
+ if(DstY + H > gpVesaCurMode->height)\r
+ H = gpVesaCurMode->height - DstY;\r
\r
//Debug("W = %i, H = %i", W, H);\r
\r
while( H -- ) {\r
dst -= scrnpitch;\r
src -= scrnpitch;\r
- tmp = W;\r
+ tmp = W*bytes_per_px;\r
for( tmp = W; tmp --; ) {\r
- *(Uint32*)(gpVesa_Framebuffer + dst + tmp) = *(Uint32*)(gpVesa_Framebuffer + src + tmp);\r
+ *(Uint8*)(gpVesa_Framebuffer + dst + tmp) = *(Uint8*)(gpVesa_Framebuffer + src + tmp);\r
}\r
}\r
}\r
else {\r
// Normal copy is OK\r
while( H -- ) {\r
- memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*sizeof(Uint32));\r
+ memcpy((void*)gpVesa_Framebuffer + dst, (void*)gpVesa_Framebuffer + src, W*bytes_per_px);\r
dst += scrnpitch;\r
src += scrnpitch;\r
}\r
}\r
+ //Log("Vesa_2D_Blit: RETURN");\r
}\r