Modules/Display/VESA - Fixes to mode select
authorJohn Hodge <[email protected]>
Sun, 27 Feb 2011 10:42:34 +0000 (18:42 +0800)
committerJohn Hodge <[email protected]>
Sun, 27 Feb 2011 10:42:34 +0000 (18:42 +0800)
- Also cleaned up write function

Modules/Display/VESA/main.c

index 9929c35..04e339b 100644 (file)
@@ -235,6 +235,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                tVT_Char        *chars = Buffer;\r
                 int    pitch = gVesa_Modes[giVesaCurrentMode].pitch;\r
                 int    depth = gVesa_Modes[giVesaCurrentMode].bpp;\r
+                int    bytes_per_px = gVesa_Modes[giVesaCurrentMode].bpp / 8;\r
                 int    widthInChars = gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth;\r
                 int    heightInChars = gVesa_Modes[giVesaCurrentMode].height/giVT_CharHeight;\r
                 int    x, y;\r
@@ -244,6 +245,8 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                Length /= sizeof(tVT_Char);\r
                Offset /= sizeof(tVT_Char);\r
                \r
+               if( depth == 32 )       depth = 24;     // Actually 24-colour bits\r
+               \r
                LOG("gVesa_Modes[%i] = {height:%i, width:%i, pitch:%i}",\r
                        giVesaCurrentMode,\r
                        gVesa_Modes[giVesaCurrentMode].height,\r
@@ -255,13 +258,13 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                LOG("(x,y) = (%i,%i) = [%i,%i]",\r
                        x,\r
                        y,\r
-                       x * giVT_CharWidth * depth / 8,\r
+                       x * giVT_CharWidth * bytes_per_px,\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 * depth / 8),\r
+                       (int)((Length % widthInChars) * giVT_CharWidth * bytes_per_px),\r
                        (int)((Length / widthInChars) * giVT_CharHeight * pitch)\r
                        );\r
                \r
@@ -290,7 +293,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                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*bytes_per_px )\r
                        // || !MM_GetPhysAddr( (tVAddr)dest + x*giVT_CharWidth*depth/8 + pitch*giVT_CharHeight-1)\r
                                )\r
                        {\r
@@ -305,7 +308,7 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                        \r
                        VT_Font_Render(\r
                                chars->Ch,\r
-                               dest + x*giVT_CharWidth*depth/8, depth, pitch,\r
+                               dest + x*giVT_CharWidth*bytes_per_px, bytes_per_px*8, pitch,\r
                                VT_Colour12toN(chars->BGCol, depth),\r
                                VT_Colour12toN(chars->FGCol, depth)\r
                                );\r
@@ -497,8 +500,9 @@ int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data)
        \r
                if(gVesa_Modes[i].width == data->width && gVesa_Modes[i].height == data->height)\r
                {\r
-                       if( (data->bpp == 32 || data->bpp == 24)\r
-                        && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) )\r
+                       //if( (data->bpp == 32 || data->bpp == 24)\r
+                       // && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) )\r
+                       if( data->bpp == gVesa_Modes[i].bpp )\r
                        {\r
                                LOG("Perfect!");\r
                                best = i;\r
@@ -509,15 +513,20 @@ int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data)
                tmp = gVesa_Modes[i].width * gVesa_Modes[i].height;\r
                tmp -= data->width * data->height;\r
                tmp = tmp < 0 ? -tmp : tmp;\r
-               factor = tmp * 100 / (data->width * data->height);\r
+               factor = tmp * 1000 / (data->width * data->height);\r
+               \r
+               if( data->bpp == 8 && gVesa_Modes[i].bpp != 8 ) continue;\r
+               if( data->bpp == 16 && gVesa_Modes[i].bpp != 16 )       continue;\r
                \r
                if( (data->bpp == 32 || data->bpp == 24)\r
                 && (gVesa_Modes[i].bpp == 32 || gVesa_Modes[i].bpp == 24) )\r
                {\r
-                       \r
+                       if( data->bpp == gVesa_Modes[i].bpp )\r
+                               factor /= 2;\r
                }\r
                else {\r
-                       factor *= 10;\r
+                       if( data->bpp != gVesa_Modes[i].bpp )\r
+                               continue ;\r
                }\r
                \r
                LOG("factor = %i", factor);\r

UCC git Repository :: git.ucc.asn.au