vgabios: Add support for vbe get/set line length function.
[seabios.git] / vgasrc / clext.c
index 363ef5df51bf1ada2f6856b62ae456e21f13e9ca..27af8109defd1dcb6ba933536ee8ee5cb7c9cdec 100644 (file)
@@ -400,6 +400,41 @@ cirrus_get_memsize(void)
     return 0x04 << x;
 }
 
+int
+clext_get_window(struct vgamode_s *vmode_g, int window)
+{
+    return stdvga_grdc_read(window + 9);
+}
+
+int
+clext_set_window(struct vgamode_s *vmode_g, int window, int val)
+{
+    if (val >= 0x100)
+        return -1;
+    stdvga_grdc_write(window + 9, val);
+    return 0;
+}
+
+int
+clext_get_linelength(struct vgamode_s *vmode_g)
+{
+    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;
+}
+
+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);
+    return 0;
+}
+
 static void
 cirrus_enable_16k_granularity(void)
 {
@@ -578,15 +613,6 @@ cirrus_get_bpp_bytes(void)
     return v;
 }
 
-static void
-cirrus_set_line_offset(u16 new_line_offset)
-{
-    new_line_offset /= 8;
-    u16 crtc_addr = stdvga_get_crtc();
-    stdvga_crtc_write(crtc_addr, 0x13, new_line_offset);
-    stdvga_crtc_mask(crtc_addr, 0x1b, 0x10, (new_line_offset & 0x100) >> 4);
-}
-
 static u16
 cirrus_get_line_offset(void)
 {
@@ -619,49 +645,6 @@ cirrus_get_start_addr(void)
             | ((b4 & 0x80) << 12));
 }
 
-static void
-cirrus_vesa_05h(struct bregs *regs)
-{
-    if (regs->bl > 1)
-        goto fail;
-    if (regs->bh == 0) {
-        // set mempage
-        if (regs->dx >= 0x100)
-            goto fail;
-        stdvga_grdc_write(regs->bl + 9, regs->dx);
-    } else if (regs->bh == 1) {
-        // get mempage
-        regs->dx = stdvga_grdc_read(regs->bl + 9);
-    } else
-        goto fail;
-
-    regs->ax = 0x004f;
-    return;
-fail:
-    regs->ax = 0x014f;
-}
-
-static void
-cirrus_vesa_06h(struct bregs *regs)
-{
-    if (regs->bl > 2) {
-        regs->ax = 0x0100;
-        return;
-    }
-
-    if (regs->bl == 0x00) {
-        cirrus_set_line_offset(cirrus_get_bpp_bytes() * regs->cx);
-    } else if (regs->bl == 0x02) {
-        cirrus_set_line_offset(regs->cx);
-    }
-
-    u32 v = cirrus_get_line_offset();
-    regs->cx = v / cirrus_get_bpp_bytes();
-    regs->bx = v;
-    regs->dx = GET_GLOBAL(VBE_total_memory) / v;
-    regs->ax = 0x004f;
-}
-
 static void
 cirrus_vesa_07h(struct bregs *regs)
 {
@@ -714,8 +697,6 @@ void
 cirrus_vesa(struct bregs *regs)
 {
     switch (regs->al) {
-    case 0x05: cirrus_vesa_05h(regs); break;
-    case 0x06: cirrus_vesa_06h(regs); break;
     case 0x07: cirrus_vesa_07h(regs); break;
     case 0x10: cirrus_vesa_10h(regs); break;
     default:   cirrus_vesa_not_handled(regs); break;