vgabios: Move bocshvga mode checking from runtime to init.
[seabios.git] / vgasrc / vgabios.c
index d35cb0272293eb4dcfdc8743bd88b05d1a96c84e..e69c6c511a0138cc3c90e7c9a928333c7d4ad429 100644 (file)
@@ -63,6 +63,22 @@ struct pci_data rom_pci_data VAR16VISIBLE = {
  * Helper functions
  ****************************************************************/
 
+// Return the bits per pixel in system memory for a given mode.
+int
+vga_bpp(struct vgamode_s *vmode_g)
+{
+    switch (GET_GLOBAL(vmode_g->memmodel)) {
+    case MM_TEXT:
+        return 16;
+    case MM_PLANAR:
+        return 1;
+    }
+    u8 depth = GET_GLOBAL(vmode_g->depth);
+    if (depth > 8)
+        return ALIGN(depth, 8);
+    return depth;
+}
+
 u16
 calc_page_size(u8 memmodel, u16 width, u16 height)
 {
@@ -122,11 +138,9 @@ set_cursor_pos(struct cursorpos cp)
         return;
 
     // Calculate the memory address
-    u16 nbcols = GET_BDA(video_cols);
-    u16 address = (GET_BDA(video_pagesize) * cp.page
-                   + (cp.x + cp.y * nbcols) * 2);
-
-    stdvga_set_cursor_pos(address / 2);
+    int address = (GET_BDA(video_pagesize) * cp.page
+                   + (cp.x + cp.y * GET_BDA(video_cols)) * 2);
+    stdvga_set_cursor_pos(address);
 }
 
 static struct cursorpos
@@ -160,9 +174,8 @@ set_active_page(u8 page)
     struct cursorpos cp = get_cursor_pos(page);
 
     // Calculate memory address of start of page
-    u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
-    u16 address = GET_BDA(video_pagesize) * page;
-    stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
+    int address = GET_BDA(video_pagesize) * page;
+    vgahw_set_displaystart(vmode_g, address);
 
     // And change the BIOS page
     SET_BDA(video_pagestart, address);
@@ -1266,8 +1279,10 @@ vga_post(struct bregs *regs)
 
     if (CONFIG_VGA_PCI) {
         u16 bdf = regs->ax;
-        if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
-            && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
+        if ((pci_config_readw(bdf, PCI_VENDOR_ID)
+             == GET_GLOBAL(rom_pci_data.vendor))
+            && (pci_config_readw(bdf, PCI_DEVICE_ID)
+                == GET_GLOBAL(rom_pci_data.device)))
             SET_VGA(VgaBDF, bdf);
     }