}
-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;
}
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;
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;
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];
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;