VGA: Comment and name update.
authorKevin O'Connor <kevin@koconnor.net>
Mon, 1 Jun 2009 02:00:20 +0000 (22:00 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Mon, 1 Jun 2009 02:00:20 +0000 (22:00 -0400)
Remove remaining "biosfn_" prefixes from functions.
Don't use register names as function parameters.
vgafb_read_pixel should return a value (instead of passing in a pointer)

vgasrc/vga.c
vgasrc/vgafb.c
vgasrc/vgatables.h

index 7d40c8bde2c2c7734abf8b9b6f0eb48e28e103bd..88cbb01fd39b707d9bd688e6c152bc56f4ffaf09 100644 (file)
@@ -8,10 +8,6 @@
 
 // TODO:
 //  * review correctness of converted asm by comparing with RBIL
-//  * refactor redundant code into sub-functions
-//  * See if there is a method to the in/out stuff that can be encapsulated.
-//  * remove "biosfn" prefixes
-//  * verify all funcs static
 //
 //  * convert vbe/clext code
 
 
 #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
 
+
+/****************************************************************
+ * Helper functions
+ ****************************************************************/
+
 static inline void
 call16_vgaint(u32 eax, u32 ebx)
 {
@@ -43,7 +44,7 @@ call16_vgaint(u32 eax, u32 ebx)
 }
 
 static void
-biosfn_perform_gray_scale_summing(u16 start, u16 count)
+perform_gray_scale_summing(u16 start, u16 count)
 {
     vgahw_screen_disable();
     int i;
@@ -62,28 +63,28 @@ biosfn_perform_gray_scale_summing(u16 start, u16 count)
 }
 
 static void
-biosfn_set_cursor_shape(u8 CH, u8 CL)
+set_cursor_shape(u8 start, u8 end)
 {
-    CH &= 0x3f;
-    CL &= 0x1f;
+    start &= 0x3f;
+    end &= 0x1f;
 
-    u16 curs = (CH << 8) + CL;
+    u16 curs = (start << 8) + end;
     SET_BDA(cursor_type, curs);
 
     u8 modeset_ctl = GET_BDA(modeset_ctl);
     u16 cheight = GET_BDA(char_height);
-    if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
-        if (CL != (CH + 1))
-            CH = ((CH + 1) * cheight / 8) - 1;
+    if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
+        if (end != (start + 1))
+            start = ((start + 1) * cheight / 8) - 1;
         else
-            CH = ((CL + 1) * cheight / 8) - 2;
-        CL = ((CL + 1) * cheight / 8) - 1;
+            start = ((end + 1) * cheight / 8) - 2;
+        end = ((end + 1) * cheight / 8) - 1;
     }
-    vgahw_set_cursor_shape(CH, CL);
+    vgahw_set_cursor_shape(start, end);
 }
 
 static u16
-biosfn_get_cursor_shape(u8 page)
+get_cursor_shape(u8 page)
 {
     if (page > 7)
         return 0;
@@ -134,7 +135,7 @@ get_cursor_pos(u8 page)
 }
 
 static void
-biosfn_set_active_page(u8 page)
+set_active_page(u8 page)
 {
     if (page > 7)
         return;
@@ -175,6 +176,27 @@ biosfn_set_active_page(u8 page)
     set_cursor_pos(cp);
 }
 
+static void
+set_scan_lines(u8 lines)
+{
+    vgahw_set_scan_lines(lines);
+    if (lines == 8)
+        set_cursor_shape(0x06, 0x07);
+    else
+        set_cursor_shape(lines - 4, lines - 3);
+    SET_BDA(char_height, lines);
+    u16 vde = vgahw_get_vde();
+    u8 rows = vde / lines;
+    SET_BDA(video_rows, rows - 1);
+    u16 cols = GET_BDA(video_cols);
+    SET_BDA(video_pagesize, rows * cols * 2);
+}
+
+
+/****************************************************************
+ * Character writing
+ ****************************************************************/
+
 // Scroll the screen one line.  This function is designed to be called
 // tail-recursive to reduce stack usage.
 static void noinline
@@ -266,24 +288,13 @@ write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
     }
 }
 
-static void
-set_scan_lines(u8 lines)
-{
-    vgahw_set_scan_lines(lines);
-    if (lines == 8)
-        biosfn_set_cursor_shape(0x06, 0x07);
-    else
-        biosfn_set_cursor_shape(lines - 4, lines - 3);
-    SET_BDA(char_height, lines);
-    u16 vde = vgahw_get_vde();
-    u8 rows = vde / lines;
-    SET_BDA(video_rows, rows - 1);
-    u16 cols = GET_BDA(video_cols);
-    SET_BDA(video_pagesize, rows * cols * 2);
-}
+
+/****************************************************************
+ * Save and restore bda state
+ ****************************************************************/
 
 static void
-biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
+save_bda_state(u16 seg, struct saveBDAstate *info)
 {
     SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
     SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
@@ -306,7 +317,7 @@ biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
 }
 
 static void
-biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
+restore_bda_state(u16 seg, struct saveBDAstate *info)
 {
     SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
     SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
@@ -386,7 +397,7 @@ handle_1000(struct bregs *regs)
         }
 
         if ((modeset_ctl & 0x02) == 0x02)
-            biosfn_perform_gray_scale_summing(0x00, 0x100);
+            perform_gray_scale_summing(0x00, 0x100);
     }
 
     struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
@@ -423,7 +434,7 @@ handle_1000(struct bregs *regs)
 
     // Set cursor shape
     if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
-        biosfn_set_cursor_shape(0x06, 0x07);
+        set_cursor_shape(0x06, 0x07);
     // Set cursor pos for page 0..7
     int i;
     for (i = 0; i < 8; i++) {
@@ -432,7 +443,7 @@ handle_1000(struct bregs *regs)
     }
 
     // Set active page 0
-    biosfn_set_active_page(0x00);
+    set_active_page(0x00);
 
     // Write the fonts in memory
     if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
@@ -458,7 +469,7 @@ handle_1000(struct bregs *regs)
 static void
 handle_1001(struct bregs *regs)
 {
-    biosfn_set_cursor_shape(regs->ch, regs->cl);
+    set_cursor_shape(regs->ch, regs->cl);
 }
 
 static void
@@ -471,7 +482,7 @@ handle_1002(struct bregs *regs)
 static void
 handle_1003(struct bregs *regs)
 {
-    regs->cx = biosfn_get_cursor_shape(regs->bh);
+    regs->cx = get_cursor_shape(regs->bh);
     struct cursorpos cp = get_cursor_pos(regs->bh);
     regs->dl = cp.x;
     regs->dh = cp.y;
@@ -488,7 +499,7 @@ handle_1004(struct bregs *regs)
 static void
 handle_1005(struct bregs *regs)
 {
-    biosfn_set_active_page(regs->al);
+    set_active_page(regs->al);
 }
 
 static void
@@ -592,15 +603,15 @@ handle_100b(struct bregs *regs)
 static void
 handle_100c(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
+    // XXX - page (regs->bh) is unused
+    vgafb_write_pixel(regs->al, regs->cx, regs->dx);
 }
 
 static void
 handle_100d(struct bregs *regs)
 {
-    // XXX - inline
-    biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
+    // XXX - page (regs->bh) is unused
+    regs->al = vgafb_read_pixel(regs->cx, regs->dx);
 }
 
 static void noinline
@@ -725,7 +736,7 @@ handle_10101a(struct bregs *regs)
 static void
 handle_10101b(struct bregs *regs)
 {
-    biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
+    perform_gray_scale_summing(regs->bx, regs->cx);
 }
 
 static void
@@ -1130,7 +1141,7 @@ handle_101c01(struct bregs *regs)
         data += sizeof(struct saveVideoHardware);
     }
     if (flags & 2) {
-        biosfn_save_bda_state(seg, data);
+        save_bda_state(seg, data);
         data += sizeof(struct saveBDAstate);
     }
     if (flags & 4)
@@ -1149,7 +1160,7 @@ handle_101c02(struct bregs *regs)
         data += sizeof(struct saveVideoHardware);
     }
     if (flags & 2) {
-        biosfn_restore_bda_state(seg, data);
+        restore_bda_state(seg, data);
         data += sizeof(struct saveBDAstate);
     }
     if (flags & 4)
index 59607c7454df189d1eb6fa52e858a5b7288ec19c..00842fba12fdce24c4b0533a8002127e67a019dc 100644 (file)
@@ -11,7 +11,6 @@
 
 // TODO
 //  * extract hw code from framebuffer code
-//  * normalize params (don't use AX/BX/CX/etc.)
 
 
 /****************************************************************
@@ -402,7 +401,7 @@ fail: ;
  ****************************************************************/
 
 void
-biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX)
+vgafb_write_pixel(u8 color, u16 x, u16 y)
 {
     // Get the mode
     struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
@@ -415,34 +414,34 @@ biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX)
     switch (GET_GLOBAL(vmode_g->memmodel)) {
     case PLANAR4:
     case PLANAR1:
-        addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols));
-        mask = 0x80 >> (CX & 0x07);
+        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);
-        if (AL & 0x80)
+        if (color & 0x80)
             outw(0x1803, VGAREG_GRDC_ADDRESS);
-        SET_FARVAR(SEG_GRAPH, *addr_far, AL);
+        SET_FARVAR(SEG_GRAPH, *addr_far, color);
         outw(0xff08, VGAREG_GRDC_ADDRESS);
         outw(0x0005, VGAREG_GRDC_ADDRESS);
         outw(0x0003, VGAREG_GRDC_ADDRESS);
         break;
     case CGA:
         if (GET_GLOBAL(vmode_g->pixbits) == 2)
-            addr_far = (void*)((CX >> 2) + (DX >> 1) * 80);
+            addr_far = (void*)((x >> 2) + (y >> 1) * 80);
         else
-            addr_far = (void*)((CX >> 3) + (DX >> 1) * 80);
-        if (DX & 1)
+            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) {
-            attr = (AL & 0x03) << ((3 - (CX & 0x03)) * 2);
-            mask = 0x03 << ((3 - (CX & 0x03)) * 2);
+            attr = (color & 0x03) << ((3 - (x & 0x03)) * 2);
+            mask = 0x03 << ((3 - (x & 0x03)) * 2);
         } else {
-            attr = (AL & 0x01) << (7 - (CX & 0x07));
-            mask = 0x01 << (7 - (CX & 0x07));
+            attr = (color & 0x01) << (7 - (x & 0x07));
+            mask = 0x01 << (7 - (x & 0x07));
         }
-        if (AL & 0x80) {
+        if (color & 0x80) {
             data ^= attr;
         } else {
             data &= ~mask;
@@ -451,28 +450,28 @@ biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX)
         SET_FARVAR(SEG_CTEXT, *addr_far, data);
         break;
     case LINEAR8:
-        addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8));
-        SET_FARVAR(SEG_GRAPH, *addr_far, AL);
+        addr_far = (void*)(x + y * (GET_BDA(video_cols) * 8));
+        SET_FARVAR(SEG_GRAPH, *addr_far, color);
         break;
     }
 }
 
-void
-biosfn_read_pixel(u8 BH, u16 CX, u16 DX, u16 *AX)
+u8
+vgafb_read_pixel(u16 x, u16 y)
 {
     // Get the mode
     struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
     if (!vmode_g)
-        return;
+        return 0;
     if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
-        return;
+        return 0;
 
     u8 *addr_far, mask, attr=0, data, i;
     switch (GET_GLOBAL(vmode_g->memmodel)) {
     case PLANAR4:
     case PLANAR1:
-        addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols));
-        mask = 0x80 >> (CX & 0x07);
+        addr_far = (void*)(x / 8 + y * GET_BDA(video_cols));
+        mask = 0x80 >> (x & 0x07);
         attr = 0x00;
         for (i = 0; i < 4; i++) {
             outw((i << 8) | 0x04, VGAREG_GRDC_ADDRESS);
@@ -482,21 +481,21 @@ biosfn_read_pixel(u8 BH, u16 CX, u16 DX, u16 *AX)
         }
         break;
     case CGA:
-        addr_far = (void*)((CX >> 2) + (DX >> 1) * 80);
-        if (DX & 1)
+        addr_far = (void*)((x >> 2) + (y >> 1) * 80);
+        if (y & 1)
             addr_far += 0x2000;
         data = GET_FARVAR(SEG_CTEXT, *addr_far);
         if (GET_GLOBAL(vmode_g->pixbits) == 2)
-            attr = (data >> ((3 - (CX & 0x03)) * 2)) & 0x03;
+            attr = (data >> ((3 - (x & 0x03)) * 2)) & 0x03;
         else
-            attr = (data >> (7 - (CX & 0x07))) & 0x01;
+            attr = (data >> (7 - (x & 0x07))) & 0x01;
         break;
     case LINEAR8:
-        addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8));
+        addr_far = (void*)(x + y * (GET_BDA(video_cols) * 8));
         attr = GET_FARVAR(SEG_GRAPH, *addr_far);
         break;
     }
-    *AX = (*AX & 0xff00) | attr;
+    return attr;
 }
 
 
index 2eb0c71977138b90c88e1423dbdf91f06d5e610e..5663b0c6a6aa9caaa89b5da2cfa31f2ef2e23046 100644 (file)
@@ -164,8 +164,8 @@ void vgafb_scroll(int nblines, int attr
                   , struct cursorpos ul, struct cursorpos lr);
 void vgafb_write_char(struct cursorpos cp, struct carattr ca);
 struct carattr vgafb_read_char(struct cursorpos cp);
-void biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX);
-void biosfn_read_pixel(u8 BH, u16 CX, u16 DX, u16 *AX);
+void vgafb_write_pixel(u8 color, u16 x, u16 y);
+u8 vgafb_read_pixel(u16 x, u16 y);
 void vgafb_load_font(u16 seg, void *src_far, u16 count
                      , u16 start, u8 destflags, u8 fontsize);