vgabios: Fix linelength calculations in bochsvga and vbe.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 29 Jan 2012 16:42:44 +0000 (11:42 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 2 Feb 2012 02:58:38 +0000 (21:58 -0500)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
vgasrc/bochsvga.c
vgasrc/vbe.c

index e40a1fd507eefa92a5a234d20dcd094711f93539..36688324c20951c6975de6f1e2bf6aec6aeefea2 100644 (file)
@@ -171,7 +171,8 @@ static int mode_valid(struct vgamode_s *vmode_g)
     u16 width = GET_GLOBAL(vmode_g->width);
     u16 height = GET_GLOBAL(vmode_g->height);
     u8 depth = GET_GLOBAL(vmode_g->depth);
     u16 width = GET_GLOBAL(vmode_g->width);
     u16 height = GET_GLOBAL(vmode_g->height);
     u8 depth = GET_GLOBAL(vmode_g->depth);
-    u32 mem = width * height * DIV_ROUND_UP(depth, 8);
+    u32 mem = (height * DIV_ROUND_UP(width * vga_bpp(vmode_g), 8)
+               * 4 / stdvga_bpp_factor(vmode_g));
 
     return width <= max_xres && depth <= max_bpp && mem <= max_mem;
 }
 
     return width <= max_xres && depth <= max_bpp && mem <= max_mem;
 }
index 55ad97eca58d93a2b0489bbb9e03179daeea53ea..77b09344c5019a15bfa24a53603f6727108ba09e 100644 (file)
@@ -108,25 +108,20 @@ vbe_104f01(struct bregs *regs)
                , SEGOFF(get_global_seg(), (u32)entry_104f05));
     int width = GET_GLOBAL(vmode_g->width);
     int height = GET_GLOBAL(vmode_g->height);
                , SEGOFF(get_global_seg(), (u32)entry_104f05));
     int width = GET_GLOBAL(vmode_g->width);
     int height = GET_GLOBAL(vmode_g->height);
-    int linesize = width * DIV_ROUND_UP(depth, 8);
+    int linesize = DIV_ROUND_UP(width * vga_bpp(vmode_g), 8);
     SET_FARVAR(seg, info->bytes_per_scanline, linesize);
     SET_FARVAR(seg, info->xres, width);
     SET_FARVAR(seg, info->yres, height);
     SET_FARVAR(seg, info->xcharsize, GET_GLOBAL(vmode_g->cwidth));
     SET_FARVAR(seg, info->ycharsize, GET_GLOBAL(vmode_g->cheight));
     SET_FARVAR(seg, info->bytes_per_scanline, linesize);
     SET_FARVAR(seg, info->xres, width);
     SET_FARVAR(seg, info->yres, height);
     SET_FARVAR(seg, info->xcharsize, GET_GLOBAL(vmode_g->cwidth));
     SET_FARVAR(seg, info->ycharsize, GET_GLOBAL(vmode_g->cheight));
-    if (depth == 4)
-        SET_FARVAR(seg, info->planes, 4);
-    else
-        SET_FARVAR(seg, info->planes, 1);
+    int planes = (depth == 4) ? 4 : 1;
+    SET_FARVAR(seg, info->planes, planes);
     SET_FARVAR(seg, info->bits_per_pixel, depth);
     SET_FARVAR(seg, info->banks, 1);
     SET_FARVAR(seg, info->mem_model, GET_GLOBAL(vmode_g->memmodel));
     SET_FARVAR(seg, info->bank_size, 0);
     u32 pages = GET_GLOBAL(VBE_total_memory) / (height * linesize);
     SET_FARVAR(seg, info->bits_per_pixel, depth);
     SET_FARVAR(seg, info->banks, 1);
     SET_FARVAR(seg, info->mem_model, GET_GLOBAL(vmode_g->memmodel));
     SET_FARVAR(seg, info->bank_size, 0);
     u32 pages = GET_GLOBAL(VBE_total_memory) / (height * linesize);
-    if (depth == 4)
-        SET_FARVAR(seg, info->pages, (pages / 4) - 1);
-    else
-        SET_FARVAR(seg, info->pages, pages - 1);
+    SET_FARVAR(seg, info->pages, (pages / planes) - 1);
     SET_FARVAR(seg, info->reserved0, 1);
 
     u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
     SET_FARVAR(seg, info->reserved0, 1);
 
     u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;