vgabios: Add the geode GX2 functionality.
[seabios.git] / vgasrc / vgafb.c
index 00842fba12fdce24c4b0533a8002127e67a019dc..85e4ab3e9fbc6d26479625c04c517de3036992c4 100644 (file)
@@ -7,10 +7,8 @@
 
 #include "biosvar.h" // GET_BDA
 #include "util.h" // memset_far
-#include "vgatables.h" // find_vga_entry
-
-// TODO
-//  * extract hw code from framebuffer code
+#include "vgabios.h" // find_vga_entry
+#include "stdvga.h" // stdvga_grdc_write
 
 
 /****************************************************************
@@ -43,97 +41,129 @@ static void
 scroll_pl4(struct vgamode_s *vmode_g, int nblines, int attr
            , struct cursorpos ul, struct cursorpos lr)
 {
-    struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
-    u8 cheight = GET_GLOBAL(vparam_g->cheight);
-    int stride = GET_BDA(video_cols);
+    int cheight = GET_GLOBAL(vmode_g->cheight);
+    int cwidth = 1;
+    int stride = GET_BDA(video_cols) * cwidth;
     void *src_far, *dest_far;
     if (nblines >= 0) {
-        dest_far = (void*)(ul.y * cheight * stride + ul.x);
+        dest_far = (void*)(ul.y * cheight * stride + ul.x * cwidth);
         src_far = dest_far + nblines * cheight * stride;
     } else {
         // Scroll down
         nblines = -nblines;
-        dest_far = (void*)(lr.y * cheight * stride + ul.x);
+        dest_far = (void*)(lr.y * cheight * stride + ul.x * cwidth);
         src_far = dest_far - nblines * cheight * stride;
         stride = -stride;
     }
     int cols = lr.x - ul.x + 1;
     int rows = lr.y - ul.y + 1;
     if (nblines < rows) {
-        outw(0x0105, VGAREG_GRDC_ADDRESS);
-        dest_far = memcpy_stride(SEG_GRAPH, dest_far, src_far, cols, stride
-                                 , (rows - nblines) * cheight);
+        stdvga_grdc_write(0x05, 0x01);
+        dest_far = memcpy_stride(SEG_GRAPH, dest_far, src_far, cols * cwidth
+                                 , stride, (rows - nblines) * cheight);
     }
     if (attr < 0)
         attr = 0;
-    outw(0x0205, VGAREG_GRDC_ADDRESS);
-    memset_stride(SEG_GRAPH, dest_far, attr, cols, stride, nblines * cheight);
-    outw(0x0005, VGAREG_GRDC_ADDRESS);
+    stdvga_grdc_write(0x05, 0x02);
+    memset_stride(SEG_GRAPH, dest_far, attr, cols * cwidth
+                  , stride, nblines * cheight);
+    stdvga_grdc_write(0x05, 0x00);
 }
 
 static void
 scroll_cga(struct vgamode_s *vmode_g, int nblines, int attr
             , struct cursorpos ul, struct cursorpos lr)
 {
-    struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
-    u8 cheight = GET_GLOBAL(vparam_g->cheight);
-    u8 bpp = GET_GLOBAL(vmode_g->pixbits);
-    int stride = GET_BDA(video_cols) * bpp;
+    int cheight = GET_GLOBAL(vmode_g->cheight) / 2;
+    int cwidth = GET_GLOBAL(vmode_g->pixbits);
+    int stride = GET_BDA(video_cols) * cwidth;
     void *src_far, *dest_far;
     if (nblines >= 0) {
-        dest_far = (void*)(ul.y * cheight * stride + ul.x * bpp);
+        dest_far = (void*)(ul.y * cheight * stride + ul.x * cwidth);
         src_far = dest_far + nblines * cheight * stride;
     } else {
         // Scroll down
         nblines = -nblines;
-        dest_far = (void*)(lr.y * cheight * stride + ul.x * bpp);
+        dest_far = (void*)(lr.y * cheight * stride + ul.x * cwidth);
         src_far = dest_far - nblines * cheight * stride;
         stride = -stride;
     }
-    int cols = (lr.x - ul.x + 1) * bpp;
+    int cols = lr.x - ul.x + 1;
     int rows = lr.y - ul.y + 1;
     if (nblines < rows) {
-        memcpy_stride(SEG_CTEXT, dest_far + 0x2000, src_far + 0x2000, cols
-                      , stride, (rows - nblines) * cheight / 2);
-        dest_far = memcpy_stride(SEG_CTEXT, dest_far, src_far, cols
-                                 , stride, (rows - nblines) * cheight / 2);
+        memcpy_stride(SEG_CTEXT, dest_far+0x2000, src_far+0x2000, cols * cwidth
+                      , stride, (rows - nblines) * cheight);
+        dest_far = memcpy_stride(SEG_CTEXT, dest_far, src_far, cols * cwidth
+                                 , stride, (rows - nblines) * cheight);
     }
     if (attr < 0)
         attr = 0;
-    memset_stride(SEG_CTEXT, dest_far + 0x2000, attr, cols
-                  , stride, nblines * cheight / 2);
-    memset_stride(SEG_CTEXT, dest_far, attr, cols
-                  , stride, nblines * cheight / 2);
+    memset_stride(SEG_CTEXT, dest_far + 0x2000, attr, cols * cwidth
+                  , stride, nblines * cheight);
+    memset_stride(SEG_CTEXT, dest_far, attr, cols * cwidth
+                  , stride, nblines * cheight);
+}
+
+static void
+scroll_lin(struct vgamode_s *vmode_g, int nblines, int attr
+           , struct cursorpos ul, struct cursorpos lr)
+{
+    int cheight = 8;
+    int cwidth = 8;
+    int stride = GET_BDA(video_cols) * cwidth;
+    void *src_far, *dest_far;
+    if (nblines >= 0) {
+        dest_far = (void*)(ul.y * cheight * stride + ul.x * cwidth);
+        src_far = dest_far + nblines * cheight * stride;
+    } else {
+        // Scroll down
+        nblines = -nblines;
+        dest_far = (void*)(lr.y * cheight * stride + ul.x * cwidth);
+        src_far = dest_far - nblines * cheight * stride;
+        stride = -stride;
+    }
+    int cols = lr.x - ul.x + 1;
+    int rows = lr.y - ul.y + 1;
+    if (nblines < rows)
+        dest_far = memcpy_stride(SEG_GRAPH, dest_far, src_far, cols * cwidth
+                                 , stride, (rows - nblines) * cheight);
+    if (attr < 0)
+        attr = 0;
+    memset_stride(SEG_GRAPH, dest_far, attr, cols * cwidth
+                  , stride, nblines * cheight);
 }
 
 static void
 scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
             , struct cursorpos ul, struct cursorpos lr)
 {
+    int cheight = 1;
+    int cwidth = 2;
     u16 nbrows = GET_BDA(video_rows) + 1;
     u16 nbcols = GET_BDA(video_cols);
+    int stride = nbcols * cwidth;
     void *src_far, *dest_far = (void*)SCREEN_MEM_START(nbcols, nbrows, ul.page);
-    int stride = nbcols * 2;
     if (nblines >= 0) {
-        dest_far += ul.y * stride + ul.x * 2;
-        src_far = dest_far + nblines * stride;
+        dest_far += ul.y * cheight * stride + ul.x * cwidth;
+        src_far = dest_far + nblines * cheight * stride;
     } else {
         // Scroll down
         nblines = -nblines;
-        dest_far += lr.y * stride + ul.x * 2;
-        src_far = dest_far - nblines * stride;
+        dest_far += lr.y * cheight * stride + ul.x * cwidth;
+        src_far = dest_far - nblines * cheight * stride;
         stride = -stride;
     }
-    int cols = (lr.x - ul.x + 1) * 2;
+    int cols = lr.x - ul.x + 1;
     int rows = lr.y - ul.y + 1;
     u16 seg = GET_GLOBAL(vmode_g->sstart);
     if (nblines < rows)
-        dest_far = memcpy_stride(seg, dest_far, src_far, cols, stride
-                                 , (rows - nblines));
+        dest_far = memcpy_stride(seg, dest_far, src_far, cols * cwidth
+                                 , stride, (rows - nblines) * cheight);
     if (attr < 0)
         attr = 0x07;
     attr = (attr << 8) | ' ';
-    memset16_stride(seg, dest_far, attr, cols, stride, nblines);
+    memset16_stride(seg, dest_far, attr, cols * cwidth
+                    , stride, nblines * cheight);
 }
 
 void
@@ -157,29 +187,9 @@ vgafb_scroll(int nblines, int attr, struct cursorpos ul, struct cursorpos lr)
     case CGA:
         scroll_cga(vmode_g, nblines, attr, ul, lr);
         break;
-    default:
-        dprintf(1, "Scroll in graphics mode\n");
-    }
-}
-
-void
-clear_screen(struct vgamode_s *vmode_g)
-{
-    switch (GET_GLOBAL(vmode_g->memmodel)) {
-    case CTEXT:
-    case MTEXT:
-        memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024);
-        break;
-    case CGA:
-        memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024);
+    case LINEAR8:
+        scroll_lin(vmode_g, nblines, attr, ul, lr);
         break;
-    default: {
-        outb(0x02, VGAREG_SEQU_ADDRESS);
-        u8 mmask = inb(VGAREG_SEQU_DATA);
-        outb(0x0f, VGAREG_SEQU_DATA);   // all planes
-        memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 64*1024);
-        outb(mmask, VGAREG_SEQU_DATA);
-    }
     }
 }
 
@@ -196,8 +206,7 @@ write_gfx_char_pl4(struct vgamode_s *vmode_g
     if (cp.x >= nbcols)
         return;
 
-    struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
-    u8 cheight = GET_GLOBAL(vparam_g->cheight);
+    u8 cheight = GET_GLOBAL(vmode_g->cheight);
     u8 *fdata_g;
     switch (cheight) {
     case 14:
@@ -211,29 +220,29 @@ write_gfx_char_pl4(struct vgamode_s *vmode_g
     }
     u16 addr = cp.x + cp.y * cheight * nbcols;
     u16 src = ca.car * cheight;
-    outw(0x0f02, VGAREG_SEQU_ADDRESS);
-    outw(0x0205, VGAREG_GRDC_ADDRESS);
+    stdvga_sequ_write(0x02, 0x0f);
+    stdvga_grdc_write(0x05, 0x02);
     if (ca.attr & 0x80)
-        outw(0x1803, VGAREG_GRDC_ADDRESS);
+        stdvga_grdc_write(0x03, 0x18);
     else
-        outw(0x0003, VGAREG_GRDC_ADDRESS);
+        stdvga_grdc_write(0x03, 0x00);
     u8 i;
     for (i = 0; i < cheight; i++) {
         u8 *dest_far = (void*)(addr + i * nbcols);
         u8 j;
         for (j = 0; j < 8; j++) {
             u8 mask = 0x80 >> j;
-            outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS);
-            GET_FARVAR(SEG_GRAPH, *dest_far);
+            stdvga_grdc_write(0x08, mask);
+            GET_FARVAR(SEG_GRAPH, *(volatile u8*)dest_far);
             if (GET_GLOBAL(fdata_g[src + i]) & mask)
                 SET_FARVAR(SEG_GRAPH, *dest_far, ca.attr & 0x0f);
             else
                 SET_FARVAR(SEG_GRAPH, *dest_far, 0x00);
         }
     }
-    outw(0xff08, VGAREG_GRDC_ADDRESS);
-    outw(0x0005, VGAREG_GRDC_ADDRESS);
-    outw(0x0003, VGAREG_GRDC_ADDRESS);
+    stdvga_grdc_write(0x08, 0xff);
+    stdvga_grdc_write(0x05, 0x00);
+    stdvga_grdc_write(0x03, 0x00);
 }
 
 static void
@@ -416,15 +425,15 @@ vgafb_write_pixel(u8 color, u16 x, u16 y)
     case PLANAR1:
         addr_far = (void*)(x / 8 + y * GET_BDA(video_cols));
         mask = 0x80 >> (x & 0x07);
-        outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS);
-        outw(0x0205, VGAREG_GRDC_ADDRESS);
-        data = GET_FARVAR(SEG_GRAPH, *addr_far);
+        stdvga_grdc_write(0x08, mask);
+        stdvga_grdc_write(0x05, 0x02);
+        GET_FARVAR(SEG_GRAPH, *(volatile u8*)addr_far);
         if (color & 0x80)
-            outw(0x1803, VGAREG_GRDC_ADDRESS);
+            stdvga_grdc_write(0x03, 0x18);
         SET_FARVAR(SEG_GRAPH, *addr_far, color);
-        outw(0xff08, VGAREG_GRDC_ADDRESS);
-        outw(0x0005, VGAREG_GRDC_ADDRESS);
-        outw(0x0003, VGAREG_GRDC_ADDRESS);
+        stdvga_grdc_write(0x08, 0xff);
+        stdvga_grdc_write(0x05, 0x00);
+        stdvga_grdc_write(0x03, 0x00);
         break;
     case CGA:
         if (GET_GLOBAL(vmode_g->pixbits) == 2)
@@ -474,7 +483,7 @@ vgafb_read_pixel(u16 x, u16 y)
         mask = 0x80 >> (x & 0x07);
         attr = 0x00;
         for (i = 0; i < 4; i++) {
-            outw((i << 8) | 0x04, VGAREG_GRDC_ADDRESS);
+            stdvga_grdc_write(0x04, i);
             data = GET_FARVAR(SEG_GRAPH, *addr_far) & mask;
             if (data > 0)
                 attr |= (0x01 << i);
@@ -497,22 +506,3 @@ vgafb_read_pixel(u16 x, u16 y)
     }
     return attr;
 }
-
-
-/****************************************************************
- * Font loading
- ****************************************************************/
-
-void
-vgafb_load_font(u16 seg, void *src_far, u16 count
-                , u16 start, u8 destflags, u8 fontsize)
-{
-    get_font_access();
-    u16 blockaddr = ((destflags & 0x03) << 14) + ((destflags & 0x04) << 11);
-    void *dest_far = (void*)(blockaddr + start*32);
-    u16 i;
-    for (i = 0; i < count; i++)
-        memcpy_far(SEG_GRAPH, dest_far + i*32
-                   , seg, src_far + i*fontsize, fontsize);
-    release_font_access();
-}