Fix OPL2 timer detection and VGA BIOS screen information
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 25 Oct 2026 17:30:04 +0000 (17:30 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 25 Oct 2026 17:30:04 +0000 (17:30 +0000)
cpu.c
cpu.h
interrupts.c

diff --git a/cpu.c b/cpu.c
index c82f0d9f6395505d8227199164b1e26f1b963e1d..2fd746115c8b47cb0924a9749d407469a4def5e7 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -1541,10 +1541,23 @@ static void sb_dsp_reply (CPU8086 *cpu, uint8_t value) {
 
 }
 
-static uint8_t opl_status (CPU8086 *cpu) {
+static uint64_t opl_clock_advance (CPU8086 *cpu) {
 
     uint64_t now = pit_clock_ns ();
     
+    if (cpu->opl_clock_ns && now < cpu->opl_clock_ns + 1250) {
+        now = cpu->opl_clock_ns + 1250;
+    }
+    
+    cpu->opl_clock_ns = now;
+    return now;
+
+}
+
+static uint8_t opl_status (CPU8086 *cpu) {
+
+    uint64_t now = opl_clock_advance (cpu);
+    
     if ((cpu->opl_control & 1) && now - cpu->opl_timer1_started_ns >= (uint64_t) (256 - cpu->opl_timer1) * 80000ULL) {
         cpu->opl_status |= 0x40;
     }
@@ -1587,11 +1600,11 @@ static void opl_write (CPU8086 *cpu, uint8_t value) {
             cpu->opl_control = value;
             
             if ((value & 1) && !(old_control & 1)) {
-                cpu->opl_timer1_started_ns = pit_clock_ns ();
+                cpu->opl_timer1_started_ns = cpu->opl_clock_ns;
             }
             
             if ((value & 2) && !(old_control & 2)) {
-                cpu->opl_timer2_started_ns = pit_clock_ns ();
+                cpu->opl_timer2_started_ns = cpu->opl_clock_ns;
             }
             
             break;
@@ -2291,11 +2304,15 @@ static void io_write8 (CPU8086 *cpu, uint16_t port, uint8_t value) {
         
         case 0x388:                     /* OPL2 register index */
         
+            opl_clock_advance (cpu);
+            
             cpu->opl_index = value;
             break;
         
         case 0x389:                     /* OPL2 register data */
         
+            opl_clock_advance (cpu);
+            
             opl_write (cpu, value);
             break;
         
diff --git a/cpu.h b/cpu.h
index fee568975caa9e77f92ed540c7339d4f14604e23..071c251b41cc997d04d3d97bb3e6c7fbfd578d67 100644 (file)
--- a/cpu.h
+++ b/cpu.h
@@ -105,7 +105,8 @@ typedef struct __attribute__ ((packed)) CPU8086 {
     
     uint8_t opl_index, opl_timer1, opl_timer2, opl_control, opl_status;
     uint64_t opl_timer1_started_ns, opl_timer2_started_ns;
-
+    
+    uint64_t opl_clock_ns;
     uint8_t mpu_uart, mpu_ack_pending;
     
     PITCounter pit[3];
index 7c34fe3e948337be38fa23a1365a5d239e219c38..7f4bc60724ac862b3c0f190f5a663710a73e4d2c 100644 (file)
@@ -10431,6 +10431,9 @@ static void bios_video_update_bda (CPU8086 *cpu) {
     mem_write8 (cpu->mem, cpu->mem_size, 0x465, (mem_read8 (cpu->mem, cpu->mem_size, 0x465) & ~0x20) | (bios_video_blink_enabled ? 0x20 : 0));
     mem_write8 (cpu->mem, cpu->mem_size, 0x466, 0);
     
+    mem_write8 (cpu->mem, cpu->mem_size, 0x484, (uint8_t) (bios_video_rows - 1));
+    mem_write16 (cpu->mem, cpu->mem_size, 0x485, bios_video_mode == 0x13 ? 8 : 16);
+    
     cpu->vga_attr_registers[0x10] = (cpu->vga_attr_registers[0x10] & ~0x08) | (bios_video_blink_enabled ? 0x08 : 0);
     cpu->crtc_base = bios_video_mode == 7 ? 0x3B4 : 0x3D4;