vgabios: Extract out common parts of struct vgamode_s.
[seabios.git] / vgasrc / vgafb.c
index 0f337209aaef9fd21c84efa33269f0ce3a5754c8..b6daba651ca26544caacae489610ab38571f1fcc 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "biosvar.h" // GET_BDA
 #include "util.h" // memset_far
-#include "vgabios.h" // find_vga_entry
+#include "vgahw.h" // vgahw_find_mode
 #include "stdvga.h" // stdvga_grdc_write
 
 
@@ -75,7 +75,7 @@ scroll_cga(struct vgamode_s *vmode_g, int nblines, int attr
             , struct cursorpos ul, struct cursorpos lr)
 {
     int cheight = GET_GLOBAL(vmode_g->cheight) / 2;
-    int cwidth = GET_GLOBAL(vmode_g->pixbits);
+    int cwidth = GET_GLOBAL(vmode_g->depth);
     int stride = GET_BDA(video_cols) * cwidth;
     void *src_far, *dest_far;
     if (nblines >= 0) {
@@ -139,10 +139,8 @@ scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
 {
     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 = GET_BDA(video_cols) * cwidth;
+    void *src_far, *dest_far = (void*)(GET_BDA(video_pagesize) * ul.page);
     if (nblines >= 0) {
         dest_far += ul.y * cheight * stride + ul.x * cwidth;
         src_far = dest_far + nblines * cheight * stride;
@@ -170,7 +168,7 @@ void
 vgafb_scroll(int nblines, int attr, struct cursorpos ul, struct cursorpos lr)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -253,7 +251,7 @@ write_gfx_char_cga(struct vgamode_s *vmode_g
         return;
 
     u8 *fdata_g = vgafont8;
-    u8 bpp = GET_GLOBAL(vmode_g->pixbits);
+    u8 bpp = GET_GLOBAL(vmode_g->depth);
     u16 addr = (cp.x * bpp) + cp.y * 320;
     u16 src = ca.car * 8;
     u8 i;
@@ -330,12 +328,9 @@ static void
 write_text_char(struct vgamode_s *vmode_g
                 , struct cursorpos cp, struct carattr ca)
 {
-    // Get the dimensions
-    u16 nbrows = GET_BDA(video_rows) + 1;
-    u16 nbcols = GET_BDA(video_cols);
-
     // Compute the address
-    void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, cp.page)
+    u16 nbcols = GET_BDA(video_cols);
+    void *address_far = (void*)(GET_BDA(video_pagesize) * cp.page
                                 + (cp.x + cp.y * nbcols) * 2);
 
     if (ca.use_attr) {
@@ -350,7 +345,7 @@ void
 vgafb_write_char(struct cursorpos cp, struct carattr ca)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -376,7 +371,7 @@ struct carattr
 vgafb_read_char(struct cursorpos cp)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         goto fail;
 
@@ -386,12 +381,9 @@ vgafb_read_char(struct cursorpos cp)
         goto fail;
     }
 
-    // Get the dimensions
-    u16 nbrows = GET_BDA(video_rows) + 1;
-    u16 nbcols = GET_BDA(video_cols);
-
     // Compute the address
-    u16 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, cp.page)
+    u16 nbcols = GET_BDA(video_cols);
+    u16 *address_far = (void*)(GET_BDA(video_pagesize) * cp.page
                                + (cp.x + cp.y * nbcols) * 2);
     u16 v = GET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far);
     struct carattr ca = {v, v>>8, 0};
@@ -411,7 +403,7 @@ void
 vgafb_write_pixel(u8 color, u16 x, u16 y)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return;
 
@@ -431,14 +423,14 @@ vgafb_write_pixel(u8 color, u16 x, u16 y)
         stdvga_grdc_write(0x03, 0x00);
         break;
     case MM_CGA:
-        if (GET_GLOBAL(vmode_g->pixbits) == 2)
+        if (GET_GLOBAL(vmode_g->depth) == 2)
             addr_far = (void*)((x >> 2) + (y >> 1) * 80);
         else
             addr_far = (void*)((x >> 3) + (y >> 1) * 80);
         if (y & 1)
             addr_far += 0x2000;
         data = GET_FARVAR(SEG_CTEXT, *addr_far);
-        if (GET_GLOBAL(vmode_g->pixbits) == 2) {
+        if (GET_GLOBAL(vmode_g->depth) == 2) {
             attr = (color & 0x03) << ((3 - (x & 0x03)) * 2);
             mask = 0x03 << ((3 - (x & 0x03)) * 2);
         } else {
@@ -467,7 +459,7 @@ u8
 vgafb_read_pixel(u16 x, u16 y)
 {
     // Get the mode
-    struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
+    struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
     if (!vmode_g)
         return 0;
 
@@ -489,7 +481,7 @@ vgafb_read_pixel(u16 x, u16 y)
         if (y & 1)
             addr_far += 0x2000;
         data = GET_FARVAR(SEG_CTEXT, *addr_far);
-        if (GET_GLOBAL(vmode_g->pixbits) == 2)
+        if (GET_GLOBAL(vmode_g->depth) == 2)
             attr = (data >> ((3 - (x & 0x03)) * 2)) & 0x03;
         else
             attr = (data >> (7 - (x & 0x07))) & 0x01;