vgabios: Rename stdvga_bpp_factor to stdvga_vram_ratio.

Invert the values returned by stdvga_bpp_factor and rename it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c
index b93213c..fcdf7e9 100644
--- a/vgasrc/bochsvga.c
+++ b/vgasrc/bochsvga.c
@@ -412,7 +412,7 @@
         u16 height = GET_GLOBAL(m->info.height);
         u8 depth = GET_GLOBAL(m->info.depth);
         u32 mem = (height * DIV_ROUND_UP(width * vga_bpp(&m->info), 8)
-                   * 4 / stdvga_bpp_factor(&m->info));
+                   * stdvga_vram_ratio(&m->info));
 
         if (width > max_xres || depth > max_bpp || mem > totalmem) {
             dprintf(1, "Removing mode %x\n", GET_GLOBAL(m->mode));
diff --git a/vgasrc/clext.c b/vgasrc/clext.c
index 012e2b1..8377da1 100644
--- a/vgasrc/clext.c
+++ b/vgasrc/clext.c
@@ -328,17 +328,16 @@
     u16 crtc_addr = stdvga_get_crtc();
     u8 reg13 = stdvga_crtc_read(crtc_addr, 0x13);
     u8 reg1b = stdvga_crtc_read(crtc_addr, 0x1b);
-    return (((reg1b & 0x10) << 4) + reg13) * stdvga_bpp_factor(vmode_g) * 2;
+    return (((reg1b & 0x10) << 4) + reg13) * 8 / stdvga_vram_ratio(vmode_g);
 }
 
 int
 clext_set_linelength(struct vgamode_s *vmode_g, int val)
 {
     u16 crtc_addr = stdvga_get_crtc();
-    int factor = stdvga_bpp_factor(vmode_g) * 2;
-    int new_line_offset = DIV_ROUND_UP(val, factor);
-    stdvga_crtc_write(crtc_addr, 0x13, new_line_offset);
-    stdvga_crtc_mask(crtc_addr, 0x1b, 0x10, (new_line_offset & 0x100) >> 4);
+    val = DIV_ROUND_UP(val * stdvga_vram_ratio(vmode_g), 8);
+    stdvga_crtc_write(crtc_addr, 0x13, val);
+    stdvga_crtc_mask(crtc_addr, 0x1b, 0x10, (val & 0x100) >> 4);
     return 0;
 }
 
@@ -352,14 +351,14 @@
     u8 b4 = stdvga_crtc_read(crtc_addr, 0x1d);
     int val = (b1 | (b2<<8) | ((b3 & 0x01) << 16) | ((b3 & 0x0c) << 15)
                | ((b4 & 0x80) << 12));
-    return val * stdvga_bpp_factor(vmode_g);
+    return val * 4 / stdvga_vram_ratio(vmode_g);
 }
 
 int
 clext_set_displaystart(struct vgamode_s *vmode_g, int val)
 {
     u16 crtc_addr = stdvga_get_crtc();
-    val /= stdvga_bpp_factor(vmode_g);
+    val = val * stdvga_vram_ratio(vmode_g) / 4;
     stdvga_crtc_write(crtc_addr, 0x0d, val);
     stdvga_crtc_write(crtc_addr, 0x0c, val >> 8);
     stdvga_crtc_mask(crtc_addr, 0x1d, 0x80, (val & 0x0800) >> 4);
diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c
index 1dd947e..3c92eec 100644
--- a/vgasrc/stdvga.c
+++ b/vgasrc/stdvga.c
@@ -212,19 +212,19 @@
     return VGAREG_MDA_CRTC_ADDRESS;
 }
 
-// Return the multiplication factor needed for the vga offset register.
+// Ratio between system visible framebuffer ram and the actual videoram used.
 int
-stdvga_bpp_factor(struct vgamode_s *vmode_g)
+stdvga_vram_ratio(struct vgamode_s *vmode_g)
 {
     switch (GET_GLOBAL(vmode_g->memmodel)) {
     case MM_TEXT:
         return 2;
     case MM_CGA:
-        return GET_GLOBAL(vmode_g->depth);
+        return 4 / GET_GLOBAL(vmode_g->depth);
     case MM_PLANAR:
-        return 1;
-    default:
         return 4;
+    default:
+        return 1;
     }
 }
 
@@ -278,14 +278,14 @@
 stdvga_get_linelength(struct vgamode_s *vmode_g)
 {
     u8 val = stdvga_crtc_read(stdvga_get_crtc(), 0x13);
-    return val * stdvga_bpp_factor(vmode_g) * 2;
+    return val * 8 / stdvga_vram_ratio(vmode_g);
 }
 
 int
 stdvga_set_linelength(struct vgamode_s *vmode_g, int val)
 {
-    int factor = stdvga_bpp_factor(vmode_g) * 2;
-    stdvga_crtc_write(stdvga_get_crtc(), 0x13, DIV_ROUND_UP(val, factor));
+    val = DIV_ROUND_UP(val * stdvga_vram_ratio(vmode_g), 8);
+    stdvga_crtc_write(stdvga_get_crtc(), 0x13, val);
     return 0;
 }
 
@@ -295,14 +295,14 @@
     u16 crtc_addr = stdvga_get_crtc();
     int addr = (stdvga_crtc_read(crtc_addr, 0x0c) << 8
                 | stdvga_crtc_read(crtc_addr, 0x0d));
-    return addr * stdvga_bpp_factor(vmode_g);
+    return addr * 4 / stdvga_vram_ratio(vmode_g);
 }
 
 int
 stdvga_set_displaystart(struct vgamode_s *vmode_g, int val)
 {
     u16 crtc_addr = stdvga_get_crtc();
-    val /= stdvga_bpp_factor(vmode_g);
+    val = val * stdvga_vram_ratio(vmode_g) / 4;
     stdvga_crtc_write(crtc_addr, 0x0c, val >> 8);
     stdvga_crtc_write(crtc_addr, 0x0d, val);
     return 0;
diff --git a/vgasrc/stdvga.h b/vgasrc/stdvga.h
index d712a32..bb8b8d8 100644
--- a/vgasrc/stdvga.h
+++ b/vgasrc/stdvga.h
@@ -90,7 +90,7 @@
 void stdvga_load_font(u16 seg, void *src_far, u16 count
                       , u16 start, u8 destflags, u8 fontsize);
 u16 stdvga_get_crtc(void);
-int stdvga_bpp_factor(struct vgamode_s *vmode_g);
+int stdvga_vram_ratio(struct vgamode_s *vmode_g);
 void stdvga_set_cursor_shape(u8 start, u8 end);
 void stdvga_set_cursor_pos(int address);
 void stdvga_set_scan_lines(u8 lines);