VGA: Simplify scrolling implementation.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 31 May 2009 05:37:54 +0000 (01:37 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 31 May 2009 05:37:54 +0000 (01:37 -0400)
Check for nblines==0 in calling function.
Eliminate full screen clearing optimization.

vgasrc/vga.c
vgasrc/vgafb.c

index 180fc991c004ba04b377df357825d265f0a90a87..c28d8915f3dee27c592f66a9993e5a097522f95d 100644 (file)
@@ -492,18 +492,21 @@ verify_scroll(struct bregs *regs, int dir)
     struct cursorpos ul = {regs->cl, regs->ch, page};
     struct cursorpos lr = {regs->dl, regs->dh, page};
 
-    if (ul.x > lr.x || ul.y > lr.y)
-        return;
-
     u16 nbrows = GET_BDA(video_rows) + 1;
-    u16 nbcols = GET_BDA(video_cols);
-
     if (lr.y >= nbrows)
         lr.y = nbrows - 1;
+    u16 nbcols = GET_BDA(video_cols);
     if (lr.x >= nbcols)
         lr.x = nbcols - 1;
 
-    vgafb_scroll(dir * regs->al, regs->bh, ul, lr);
+    if (ul.x > lr.x || ul.y > lr.y)
+        return;
+
+    u16 nblines = regs->al;
+    if (!nblines || nblines > lr.y - ul.y + 1)
+        nblines = lr.y - ul.y + 1;
+
+    vgafb_scroll(dir * nblines, regs->bh, ul, lr);
 }
 
 static void
index 3e36b1cdf73f14fc1a6ab89f61bc3503a15e4497..dbceb2c103c0f828d975b75ef5e9d12ffbc63ca4 100644 (file)
@@ -64,26 +64,15 @@ scroll_pl4(struct vgamode_s *vmode_g, int nblines, int attr
         dir = SCROLL_DOWN;
     }
     // Get the dimensions
-    u16 nbrows = GET_BDA(video_rows) + 1;
     u16 nbcols = GET_BDA(video_cols);
-    if (nblines > nbrows)
-        nblines = 0;
     u8 cols = lr.x - ul.x + 1;
 
     struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
     u8 cheight = GET_GLOBAL(vparam_g->cheight);
-    if (nblines == 0 && ul.y == 0 && ul.x == 0 && lr.y == nbrows - 1
-        && lr.x == nbcols - 1) {
-        outw(0x0205, VGAREG_GRDC_ADDRESS);
-        memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr,
-                   nbrows * nbcols * cheight);
-        outw(0x0005, VGAREG_GRDC_ADDRESS);
-        return;
-    }
     if (dir == SCROLL_UP) {
         u16 i;
         for (i = ul.y; i <= lr.y; i++)
-            if ((i + nblines > lr.y) || (nblines == 0))
+            if (i + nblines > lr.y)
                 vgamem_fill_pl4(ul.x, i, cols, nbcols, cheight,
                                 attr);
             else
@@ -92,16 +81,13 @@ scroll_pl4(struct vgamode_s *vmode_g, int nblines, int attr
         return;
     }
     u16 i;
-    for (i = lr.y; i >= ul.y; i--) {
-        if ((i < ul.y + nblines) || (nblines == 0))
+    for (i = lr.y; i >= ul.y; i--)
+        if (i < ul.y + nblines)
             vgamem_fill_pl4(ul.x, i, cols, nbcols, cheight,
                             attr);
         else
             vgamem_copy_pl4(ul.x, i, i - nblines, cols,
                             nbcols, cheight);
-        if (i > lr.y)
-            break;
-    }
 }
 
 static void
@@ -147,21 +133,12 @@ scroll_cga(struct vgamode_s *vmode_g, int nblines, int attr
         dir = SCROLL_DOWN;
     }
     // Get the dimensions
-    u16 nbrows = GET_BDA(video_rows) + 1;
     u16 nbcols = GET_BDA(video_cols);
-    if (nblines > nbrows)
-        nblines = 0;
     u8 cols = lr.x - ul.x + 1;
 
     struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
     u8 cheight = GET_GLOBAL(vparam_g->cheight);
     u8 bpp = GET_GLOBAL(vmode_g->pixbits);
-    if (nblines == 0 && ul.y == 0 && ul.x == 0 && lr.y == nbrows - 1
-        && lr.x == nbcols - 1) {
-        memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr,
-                   nbrows * nbcols * cheight * bpp);
-        return;
-    }
     if (bpp == 2) {
         ul.x <<= 1;
         cols <<= 1;
@@ -171,7 +148,7 @@ scroll_cga(struct vgamode_s *vmode_g, int nblines, int attr
     if (dir == SCROLL_UP) {
         u16 i;
         for (i = ul.y; i <= lr.y; i++)
-            if ((i + nblines > lr.y) || (nblines == 0))
+            if (i + nblines > lr.y)
                 vgamem_fill_cga(ul.x, i, cols, nbcols, cheight,
                                 attr);
             else
@@ -180,16 +157,13 @@ scroll_cga(struct vgamode_s *vmode_g, int nblines, int attr
         return;
     }
     u16 i;
-    for (i = lr.y; i >= ul.y; i--) {
-        if ((i < ul.y + nblines) || (nblines == 0))
+    for (i = lr.y; i >= ul.y; i--)
+        if (i < ul.y + nblines)
             vgamem_fill_cga(ul.x, i, cols, nbcols, cheight,
                             attr);
         else
             vgamem_copy_cga(ul.x, i, i - nblines, cols,
                             nbcols, cheight);
-        if (i > lr.y)
-            break;
-    }
 }
 
 static void
@@ -206,9 +180,6 @@ scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
     // Get the dimensions
     u16 nbrows = GET_BDA(video_rows) + 1;
     u16 nbcols = GET_BDA(video_cols);
-
-    if (nblines > nbrows)
-        nblines = 0;
     u8 cols = lr.x - ul.x + 1;
 
     // Compute the address
@@ -216,16 +187,10 @@ scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
     dprintf(3, "Scroll, address %p (%d %d %02x)\n"
             , address_far, nbrows, nbcols, ul.page);
 
-    if (nblines == 0 && ul.y == 0 && ul.x == 0 && lr.y == nbrows - 1
-        && lr.x == nbcols - 1) {
-        memset16_far(GET_GLOBAL(vmode_g->sstart), address_far
-                     , (u16)attr * 0x100 + ' ', nbrows * nbcols * 2);
-        return;
-    }
     if (dir == SCROLL_UP) {
         u16 i;
         for (i = ul.y; i <= lr.y; i++)
-            if ((i + nblines > lr.y) || (nblines == 0))
+            if (i + nblines > lr.y)
                 memset16_far(GET_GLOBAL(vmode_g->sstart)
                              , address_far + (i * nbcols + ul.x) * 2
                              , (u16)attr * 0x100 + ' ', cols * 2);
@@ -237,10 +202,9 @@ scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
                              , cols * 2);
         return;
     }
-
     u16 i;
-    for (i = lr.y; i >= ul.y; i--) {
-        if ((i < ul.y + nblines) || (nblines == 0))
+    for (i = lr.y; i >= ul.y; i--)
+        if (i < ul.y + nblines)
             memset16_far(GET_GLOBAL(vmode_g->sstart)
                          , address_far + (i * nbcols + ul.x) * 2
                          , (u16)attr * 0x100 + ' ', cols * 2);
@@ -250,9 +214,6 @@ scroll_text(struct vgamode_s *vmode_g, int nblines, int attr
                          , GET_GLOBAL(vmode_g->sstart)
                          , (void*)(((i - nblines) * nbcols + ul.x) * 2)
                          , cols * 2);
-        if (i > lr.y)
-            break;
-    }
 }
 
 void