From: Robert Pengelly Date: Sun, 25 Oct 2026 17:30:04 +0000 (+0000) Subject: Fix OPL2 timer detection and VGA BIOS screen information X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=67038ceeac1ad365cbe8027128e5835f3ba99925;p=dosemu.git Fix OPL2 timer detection and VGA BIOS screen information --- diff --git a/cpu.c b/cpu.c index c82f0d9..2fd7461 100644 --- 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 fee5689..071c251 100644 --- 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]; diff --git a/interrupts.c b/interrupts.c index 7c34fe3..7f4bc60 100644 --- a/interrupts.c +++ b/interrupts.c @@ -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;