vgabios: Add support for vbe get/set line length function.
[seabios.git] / vgasrc / stdvga.c
index d1841bf35e8d47ff2ee865830e9d7bd652a6cfe7..a310167aca13ee38a4dfbd2f657c7db9c68d0428 100644 (file)
@@ -10,7 +10,6 @@
 #include "farptr.h" // SET_FARVAR
 #include "biosvar.h" // GET_GLOBAL
 #include "util.h" // memcpy_far
-#include "vbe.h" // VBE_RETURN_STATUS_FAILED
 
 
 /****************************************************************
@@ -159,6 +158,20 @@ stdvga_set_text_block_specifier(u8 spec)
     stdvga_sequ_write(0x03, spec);
 }
 
+// Enable reads and writes to the given "plane" when in planar4 mode.
+void
+stdvga_planar4_plane(int plane)
+{
+    if (plane < 0) {
+        // Return to default mode (read plane0, write all planes)
+        stdvga_sequ_write(0x02, 0x0f);
+        stdvga_grdc_write(0x04, 0);
+    } else {
+        stdvga_sequ_write(0x02, 1<<plane);
+        stdvga_grdc_write(0x04, plane);
+    }
+}
+
 
 /****************************************************************
  * Font loading
@@ -216,6 +229,22 @@ stdvga_get_crtc(void)
     return VGAREG_MDA_CRTC_ADDRESS;
 }
 
+// Return the multiplication factor needed for the vga offset register.
+int
+stdvga_bpp_factor(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);
+    case MM_PLANAR:
+        return 1;
+    default:
+        return 4;
+    }
+}
+
 void
 stdvga_set_cursor_shape(u8 start, u8 end)
 {
@@ -257,6 +286,33 @@ stdvga_get_vde(void)
     return vde;
 }
 
+int
+stdvga_get_window(struct vgamode_s *vmode_g, int window)
+{
+    return -1;
+}
+
+int
+stdvga_set_window(struct vgamode_s *vmode_g, int window, int val)
+{
+    return -1;
+}
+
+int
+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;
+}
+
+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));
+    return 0;
+}
+
 
 /****************************************************************
  * Save/Restore/Set state
@@ -346,13 +402,12 @@ clear_screen(struct vgamode_s *vmode_g)
 }
 
 int
-stdvga_set_mode(int mode, int flags)
+stdvga_set_mode(struct vgamode_s *vmode_g, int flags)
 {
-    // find the entry in the video modes
-    struct vgamode_s *vmode_g = stdvga_find_mode(mode);
-    dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
-    if (!vmode_g)
-        return VBE_RETURN_STATUS_FAILED;
+    if (! stdvga_is_mode(vmode_g)) {
+        warn_internalerror();
+        return -1;
+    }
     struct stdvga_mode_s *stdmode_g = container_of(
         vmode_g, struct stdvga_mode_s, info);
 
@@ -422,9 +477,6 @@ stdvga_set_mode(int mode, int flags)
     if (memmodel == MM_TEXT)
         stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, 0, 16);
 
-    // Setup BDA variables
-    modeswitch_set_bda(mode, flags, vmode_g);
-
     return 0;
 }