Implement BIOS cursor visibility control and restore on exit
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 11:30:45 +0000 (12:30 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 11:30:45 +0000 (12:30 +0100)
interrupts.c
main.c

index 5c8edd5450bcd8cab2171ba58fa1de562ba7c2a2..450201238b29ddc7b2831038f9df0c092ed13bc4 100644 (file)
@@ -6044,6 +6044,10 @@ static void bios_video_initialize (void) {
     }
 
     bios_video_initialized = 1;
+    
+    /* The BIOS text screen starts blank; remove any previous host output. */
+    fputs ("\033[2J\033[H", stdout);
+    fflush (stdout);
 
 }
 
@@ -6087,6 +6091,9 @@ static void int_10 (CPU8086 *cpu) {
             bios_cursor_start = (uint8_t) (cpu->regs[REG_CX] >> 8);
             bios_cursor_end = (uint8_t) cpu->regs[REG_CX];
             
+            fputs ((bios_cursor_start & 0x20) ? "\033[?25l" : "\033[?25h", stdout);
+            fflush (stdout);
+            
             break;
         
         case 0x02: {                    /* set cursor position */
diff --git a/main.c b/main.c
index 14d9a348e867e180df39bc50b538ae5d9d7136a3..d27e6963ff7789faa15fadac8ee45127d4c28bf8 100644 (file)
--- a/main.c
+++ b/main.c
 #define     MEM_SIZE                    (640UL << 10)
 #define     EXE_LOAD_SEG                0x0060
 
+static void restore_terminal_cursor (void) {
+
+    fputs ("\033[?25h", stdout);
+    fflush (stdout);
+
+}
+
 static void usage (const char *argv0) {
     fprintf (stderr, "Usage: %s [--trace] program.com\n", argv0);
 }
@@ -270,6 +277,15 @@ int main (int argc, char **argv) {
     
     }
     
+    if (atexit (restore_terminal_cursor) != 0) {
+    
+        fprintf (stderr, "Failed to register terminal cursor cleanup\n");
+        
+        free (mem);
+        return 1;
+    
+    }
+    
     /* init_dos_heap(&cpu, 0x2000); */
     init_ivt (&cpu);