diff --git a/HISTORY.txt b/HISTORY.txt index a51c80c..271c3ae 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -95,6 +95,7 @@ Genesis Plus GX 1.7.5 (xx/xx/xxxx) (Eke-Eke) * improved Mode 5 sprites rendering timings (fixes "Overdrive" demo) * improved FIFO timings accuracy (fixes "Overdrive" Demo) * improved H-Counter accuracy in H32 mode +* improved VDP status timing accuracy * improved accuracy of Master System color palette brightness range (verified against real hardware) * fixed misaligned buffer writes in Mode 4 when -DALIGN_LONG option is used * fixed alpha channel for 15-bit (RGB555) and 32-bit (RGB888) color support diff --git a/builds/genesis_plus_gx_libretro.dll b/builds/genesis_plus_gx_libretro.dll index becc6d7..dd2f193 100644 Binary files a/builds/genesis_plus_gx_libretro.dll and b/builds/genesis_plus_gx_libretro.dll differ diff --git a/builds/genplus_cube.dol b/builds/genplus_cube.dol index 833ea45..d8e2623 100644 Binary files a/builds/genplus_cube.dol and b/builds/genplus_cube.dol differ diff --git a/builds/genplus_wii.dol b/builds/genplus_wii.dol index f918af7..30ffba9 100644 Binary files a/builds/genplus_wii.dol and b/builds/genplus_wii.dol differ diff --git a/core/system.c b/core/system.c index 97c3ebf..5c3f6e6 100644 --- a/core/system.c +++ b/core/system.c @@ -481,12 +481,6 @@ void system_frame_gen(int do_skip) /* refresh inputs just before VINT (Warriors of Eternal Sun) */ osd_input_update(); - /* delay between VINT flag & Vertical Interrupt (Ex-Mutants, Tyrant) */ - m68k_run(588); - - /* set VINT flag */ - status |= 0x80; - /* delay between VBLANK flag & Vertical Interrupt (Dracula, OutRunners, VR Troopers) */ m68k_run(788); if (zstate == 1) @@ -498,6 +492,9 @@ void system_frame_gen(int do_skip) Z80.cycles = 788; } + /* set VINT flag */ + status |= 0x80; + /* Vertical Interrupt */ vint_pending = 0x20; if (reg[1] & 0x20) @@ -853,12 +850,6 @@ void system_frame_scd(int do_skip) /* refresh inputs just before VINT */ osd_input_update(); - /* delay between VINT flag & Vertical Interrupt (Ex-Mutants, Tyrant) */ - m68k_run(588); - - /* set VINT flag */ - status |= 0x80; - /* delay between VBLANK flag & Vertical Interrupt (Dracula, OutRunners, VR Troopers) */ m68k_run(788); if (zstate == 1) @@ -870,6 +861,9 @@ void system_frame_scd(int do_skip) Z80.cycles = 788; } + /* set VINT flag */ + status |= 0x80; + /* Vertical Interrupt */ vint_pending = 0x20; if (reg[1] & 0x20) diff --git a/core/vdp_ctrl.c b/core/vdp_ctrl.c index 50d43d6..f630765 100644 --- a/core/vdp_ctrl.c +++ b/core/vdp_ctrl.c @@ -1134,6 +1134,9 @@ unsigned int vdp_68k_ctrl_r(unsigned int cycles) { unsigned int temp; + /* Cycle-accurate VDP status read (68k read cycle takes four CPU cycles i.e 28 Mcycles) */ + cycles += 4 * 7; + /* Update FIFO status flags if not empty */ if (fifo_write_cnt) { @@ -1160,14 +1163,25 @@ unsigned int vdp_68k_ctrl_r(unsigned int cycles) /* Clear SOVR & SCOL flags */ status &= 0xFF9F; - /* Display OFF: VBLANK flag is set */ + /* VBLANK flag is set when display is disabled */ if (!(reg[1] & 0x40)) { temp |= 0x08; } - /* HBLANK flag (Sonic 3 and Sonic 2 "VS Modes", Lemmings 2, Mega Turrican, V.R Troopers, Gouketsuji Ichizoku,...) */ - /* NB: this is not 100% accurate and need to be verified on real hardware */ + /* Cycle-accurate VINT flag (Ex-Mutants, Tyrant / Mega-Lo-Mania) */ + /* this allows VINT flag to be read just before vertical interrupt is being triggered */ + if ((v_counter == bitmap.viewport.h) && (cycles >= (mcycles_vdp + 788))) + { + /* check Z80 interrupt state to assure VINT has not already been triggered (and flag cleared) */ + if (Z80.irq_state != ASSERT_LINE) + { + temp |= 0x80; + } + } + + /* Cycle-accurate HBLANK flag (Sonic 3 & Sonic 2 "VS Modes", Bugs Bunny Double Trouble, Lemmings 2, Mega Turrican, V.R Troopers, Gouketsuji Ichizoku,...) */ + /* NB: this is not 100% accurate (see hvc.h for horizontal events timings in H32 and H40 mode) but is close enough to make no noticeable difference for games */ if ((cycles % MCYCLES_PER_LINE) < 588) { temp |= 0x04;