core z80, cycle counting fixes (reset, bus request)

This commit is contained in:
kub 2024-05-07 23:10:27 +02:00
parent c9f9453414
commit 274dd51a60
6 changed files with 14 additions and 12 deletions

View file

@ -312,7 +312,7 @@ static int SekSyncM68k(int once);
void pcd_run_cpus_normal(int m68k_cycles)
{
// TODO this is suspicious. ~1 cycle refresh delay every 256 cycles?
SekAimM68k(m68k_cycles, 0x43); // Fhey area
SekAimM68k(m68k_cycles, 0x42); // Fhey area
while (CYCLES_GT(Pico.t.m68c_aim, Pico.t.m68c_cnt)) {
if (SekShouldInterrupt()) {

View file

@ -389,7 +389,6 @@ void PDebugZ80Frame(void)
else
lines = 262;
z80_resetCycles(Pico.t.z80c_aim);
PsndStartFrame();
if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
@ -407,6 +406,7 @@ void PDebugZ80Frame(void)
PsndGetSamples(lines);
timers_cycle(Pico.t.z80c_aim);
z80_resetCycles();
Pico.t.m68c_aim = Pico.t.m68c_cnt;
}

View file

@ -530,20 +530,21 @@ void NOINLINE ctl_write_z80busreq(u32 d)
{
if (d)
{
Pico.t.z80c_cnt = z80_cycles_from_68k() + (Pico.t.z80_busdelay >> 8);
Pico.t.z80c_aim = Pico.t.z80c_cnt = z80_cycles_from_68k() + (Pico.t.z80_busdelay >> 8) + 2;
Pico.t.z80_busdelay &= 0xff;
}
else
{
if ((PicoIn.opt & POPT_EN_Z80) && !Pico.m.z80_reset) {
// Z80 grants bus 2 cycles after the next M cycle, even within an insn
// Z80 grants bus after the current M cycle, even within an insn
// simulate this by accumulating the last insn overhang in busdelay
unsigned granted = z80_cycles_from_68k() + 6;
unsigned granted;
pprof_start(m68k);
PicoSyncZ80(SekCyclesDone());
pprof_end_sub(m68k);
granted = Pico.t.z80c_aim + 6; // M cycle is 3-6 cycles
Pico.t.z80_busdelay += (Pico.t.z80c_cnt - granted) << 8;
Pico.t.z80c_cnt = granted;
pprof_end_sub(m68k);
}
}
Pico.m.z80Run = d;
@ -563,12 +564,13 @@ void NOINLINE ctl_write_z80reset(u32 d)
PicoSyncZ80(SekCyclesDone());
pprof_end_sub(m68k);
}
Pico.t.z80_busdelay &= 0xff; // also resets bus request
YM2612ResetChip();
timers_reset();
}
else
{
Pico.t.z80c_cnt = z80_cycles_from_68k() + 2;
Pico.t.z80c_aim = Pico.t.z80c_cnt = z80_cycles_from_68k() + 2;
z80_reset();
}
Pico.m.z80_reset = d;

View file

@ -81,7 +81,7 @@ static __inline void SekAimM68k(int cyc, int mult)
static __inline void SekRunM68k(int cyc)
{
// TODO 0x100 would be 2 cycles/128, moreover far too sensitive
SekAimM68k(cyc, 0x10c); // OutRunners, testpico, VDPFIFOTesting
SekAimM68k(cyc, 0x108); // OutRunners, testpico, VDPFIFOTesting
SekSyncM68k(0);
}
@ -141,7 +141,6 @@ static int PicoFrameHints(void)
skip = PicoIn.skipFrame;
z80_resetCycles(cycles_68k_to_z80(Pico.t.m68c_aim - Pico.t.m68c_frame_start));
Pico.t.m68c_frame_start = Pico.t.m68c_aim;
PsndStartFrame();
@ -340,6 +339,7 @@ static int PicoFrameHints(void)
PsndGetSamples(y);
timers_cycle(cycles_68k_to_z80(Pico.t.m68c_aim - Pico.t.m68c_frame_start));
z80_resetCycles();
pv->hint_cnt = hint;

View file

@ -201,8 +201,8 @@ extern struct DrZ80 drZ80;
#define Z80_STATE_SIZE 0x60
#define z80_resetCycles(aim) \
Pico.t.z80c_cnt -= (aim < Pico.t.z80c_cnt ? aim : Pico.t.z80c_cnt), Pico.t.z80c_aim = Pico.t.z80_scanline = 0
#define z80_resetCycles() \
Pico.t.z80c_cnt -= Pico.t.z80c_aim, Pico.t.z80c_aim = Pico.t.z80_scanline = 0
#define z80_cyclesDone() \
(Pico.t.z80c_aim - z80_cyclesLeft)

View file

@ -846,7 +846,6 @@ void PicoFrameMS(void)
int nmi;
int y;
z80_resetCycles(Pico.t.z80c_aim);
PsndStartFrame();
// for SMS the pause button generates an NMI, for GG ths is not the case
@ -923,6 +922,7 @@ void PicoFrameMS(void)
z80_exec(Pico.t.z80c_line_start + cycles_line);
}
z80_resetCycles();
PsndGetSamplesMS(lines);
}