From a5ee22f1f54069c92c7e255f3a7c21244c88aabc Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Tue, 14 May 2013 00:40:10 -0700 Subject: Update Z80 vint timing --- blastem.c | 4 +++- vdp.c | 12 ++++++++++++ vdp.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/blastem.c b/blastem.c index d2e07b7..a25bba3 100644 --- a/blastem.c +++ b/blastem.c @@ -162,14 +162,16 @@ uint8_t new_busack = 0; void sync_z80(z80_context * z_context, uint32_t mclks) { if (z80_enabled && !reset && !busreq) { + genesis_context * gen = z_context->system; if (need_reset) { z80_reset(z_context); need_reset = 0; } z_context->sync_cycle = mclks / MCLKS_PER_Z80; + uint32_t vint_cycle = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80; while (z_context->current_cycle < z_context->sync_cycle) { if (z_context->iff1 && z_context->current_cycle < ZVINT_CYCLE) { - z_context->int_cycle = ZVINT_CYCLE; + z_context->int_cycle = vint_cycle; } z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; dprintf("Running Z80 from cycle %d to cycle %d. Native PC: %p\n", z_context->current_cycle, z_context->sync_cycle, z_context->native_pc); diff --git a/vdp.c b/vdp.c index 881d54f..1ef315f 100644 --- a/vdp.c +++ b/vdp.c @@ -1572,6 +1572,18 @@ uint32_t vdp_next_vint(vdp_context * context) return vcycle; } +uint32_t vdp_next_vint_z80(vdp_context * context) +{ + uint32_t active_lines = context->latched_mode & BIT_PAL ? PAL_ACTIVE : NTSC_ACTIVE; + uint32_t vcycle = MCLKS_LINE * active_lines; + if (context->latched_mode & BIT_H40) { + vcycle += VINT_CYCLE_H40; + } else { + vcycle += VINT_CYCLE_H32; + } + return vcycle; +} + void vdp_int_ack(vdp_context * context, uint16_t int_num) { if (int_num == 6) { diff --git a/vdp.h b/vdp.h index 1b623ec..a5aa6ab 100644 --- a/vdp.h +++ b/vdp.h @@ -140,6 +140,7 @@ uint16_t vdp_hv_counter_read(vdp_context * context); void vdp_adjust_cycles(vdp_context * context, uint32_t deduction); uint32_t vdp_next_hint(vdp_context * context); uint32_t vdp_next_vint(vdp_context * context); +uint32_t vdp_next_vint_z80(vdp_context * context); void vdp_int_ack(vdp_context * context, uint16_t int_num); void vdp_print_sprite_table(vdp_context * context); void vdp_print_reg_explain(vdp_context * context); -- cgit v1.2.3