z80_intf.cpp: fix for: ZetNmi and CPU_IRQSTATUS_AUTO loses cycles. Now, take for instance that some soundcpus generate a NMI per sample to dac, or msm5205. this causes the sound sync to go off the wall - generating distortion/clicks

This commit is contained in:
dinkc64 2018-10-15 02:25:54 +00:00
parent 5c7ceea83d
commit 4802edb954

View File

@ -25,6 +25,7 @@ struct ZetExt {
};
static INT32 nZetCyclesDone[MAX_Z80];
static INT32 nZetCyclesDelayed[MAX_Z80];
static INT32 nZetCyclesTotal;
static INT32 nZ80ICount[MAX_Z80];
static UINT32 Z80EA[MAX_Z80];
@ -219,6 +220,7 @@ INT32 ZetInit(INT32 nCPU)
Z80GetContext(&ZetCPUContext[nCPU]->reg);
nZetCyclesDone[nCPU] = 0;
nZetCyclesDelayed[nCPU] = 0;
nZ80ICount[nCPU] = 0;
for (INT32 j = 0; j < (0x0100 * 4); j++) {
@ -378,14 +380,24 @@ INT32 ZetRun(INT32 nCycles)
#endif
if (nCycles <= 0) return 0;
INT32 nDelayed = 0; // handle delayed cycle counts (from nmi / irq)
if (nZetCyclesDelayed[nOpenedCPU]) {
nDelayed = nZetCyclesDelayed[nOpenedCPU];
nZetCyclesDelayed[nOpenedCPU] = 0;
nCycles -= nDelayed;
}
if (ZetCPUContext[nOpenedCPU]->BusReq) {
nCycles += nDelayed;
nZetCyclesTotal += nCycles;
return nCycles;
}
nCycles = Z80Execute(nCycles);
nCycles += nDelayed;
nZetCyclesTotal += nCycles;
return nCycles;
@ -563,6 +575,7 @@ void ZetReset()
if (nOpenedCPU == -1) bprintf(PRINT_ERROR, _T("ZetReset called when no CPU open\n"));
#endif
nZetCyclesDelayed[nOpenedCPU] = 0;
Z80Reset();
}
@ -683,6 +696,7 @@ INT32 ZetScan(INT32 nAction)
SCAN_VAR(Z80EA[i]);
SCAN_VAR(nZ80ICount[i]);
SCAN_VAR(nZetCyclesDone[i]);
SCAN_VAR(nZetCyclesDelayed[i]);
SCAN_VAR(ZetCPUContext[i]->BusReq);
}
@ -702,14 +716,14 @@ void ZetSetIRQLine(const INT32 line, const INT32 status)
case CPU_IRQSTATUS_NONE:
Z80SetIrqLine(line, 0);
break;
case CPU_IRQSTATUS_ACK:
case CPU_IRQSTATUS_ACK:
Z80SetIrqLine(line, 1);
break;
case CPU_IRQSTATUS_AUTO:
Z80SetIrqLine(line, 1);
Z80Execute(0);
nZetCyclesDelayed[nOpenedCPU] += Z80Execute(0);
Z80SetIrqLine(0, 0);
Z80Execute(0);
nZetCyclesDelayed[nOpenedCPU] += Z80Execute(0);
break;
case CPU_IRQSTATUS_HOLD:
ActiveZ80SetIRQHold();
@ -746,13 +760,11 @@ INT32 ZetNmi()
#endif
Z80SetIrqLine(Z80_INPUT_LINE_NMI, 1);
Z80Execute(0);
nZetCyclesDelayed[nOpenedCPU] += Z80Execute(0);
Z80SetIrqLine(Z80_INPUT_LINE_NMI, 0);
Z80Execute(0);
INT32 nCycles = 12;
nZetCyclesTotal += nCycles;
nZetCyclesDelayed[nOpenedCPU] += Z80Execute(0);
return nCycles;
return 0;
}
INT32 ZetIdle(INT32 nCycles)