Implement BIOS INT 10h AH=06h screen scrolling and clearing
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 10:40:05 +0000 (11:40 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 10:40:05 +0000 (11:40 +0100)
interrupts.c

index a19937f05fdb72a5b33deb72afeedf244c233615..67a86ed093b9232b594c0f65d08ee0ae36f706de 100644 (file)
@@ -5902,6 +5902,63 @@ static void int_10 (CPU8086 *cpu) {
         
         }
         
+        case 0x06: {                    /* scroll window up */
+        
+            uint8_t lines = get_reg8 (cpu, REG_AX);
+            uint8_t attr = (uint8_t) (cpu->regs[REG_BX] >> 8);
+            
+            uint8_t top = (uint8_t) (cpu->regs[REG_CX] >> 8);
+            uint8_t left = (uint8_t) cpu->regs[REG_CX];
+            uint8_t bottom = (uint8_t) (cpu->regs[REG_DX] >> 8);
+            uint8_t right = (uint8_t) cpu->regs[REG_DX];
+            
+            unsigned row;
+            unsigned col;
+            unsigned height;
+            
+            if (top >= 25 || left >= 80 || bottom >= 25 || right >= 80 || top > bottom || left > right) {
+                break;
+            }
+            
+            height = (unsigned) bottom - top + 1;
+            
+            if (lines == 0 || lines >= height) {
+            
+                /* Blank only the requested window, leaving the cursor in place. */
+                fputs ("\0337", stdout);
+                fprintf (stdout, "\033[%um\033[%um", 40 + (attr >> 4 & 7), 30 + (attr & 7));
+                
+                for (row = top; row <= bottom; row++) {
+                
+                    fprintf (stdout, "\033[%u;%uH", row + 1, (unsigned) left + 1);
+                    
+                    for (col = left; col <= right; col++) {
+                        fputc (' ', stdout);
+                    }
+                
+                }
+                
+                fputs ("\033[0m\0338", stdout);
+            
+            } else if (left == 0 && right == 79) {
+            
+                /* ANSI scrolling margins act on whole terminal rows. */
+                fputs ("\0337", stdout);
+                fprintf (stdout, "\033[%u;%ur\033[%uS\033[r", (unsigned) top + 1, (unsigned) bottom + 1, (unsigned) lines);
+                fputs ("\0338", stdout);
+            
+            } else {
+            
+                /* A partial-width scroll requires a video-cell buffer. */
+                fprintf (stderr, "Unsupported partial-width INT 10h AH=06h scroll\n");
+            
+            }
+            
+            fflush (stdout);
+            break;
+        
+        }
+        
         case 0x09: {                    /* write character and attribute */
         
             uint8_t page = (uint8_t) (cpu->regs[REG_BX] >> 8);