From 1bfa876c364c5dcb8d23697067430291501ac805 Mon Sep 17 00:00:00 2001 From: dinkc64 Date: Thu, 9 May 2019 23:50:36 -0400 Subject: [PATCH] endrun fix: z180, tlcs90, upd7810 --- src/cpu/tlcs90/tlcs90.cpp | 15 ++++++++++----- src/cpu/upd7810/upd7810.cpp | 6 +++--- src/cpu/z180/z180.cpp | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/cpu/tlcs90/tlcs90.cpp b/src/cpu/tlcs90/tlcs90.cpp index 78141f44b..295776be6 100644 --- a/src/cpu/tlcs90/tlcs90.cpp +++ b/src/cpu/tlcs90/tlcs90.cpp @@ -1410,6 +1410,8 @@ INT32 tlcs90Run(INT32 nCycles) } cpustate->extra_cycles = 0; + cpustate->run_end = 0; + do { INT32 prev_cycles = cpustate->icount; // for timers @@ -2049,10 +2051,13 @@ INT32 tlcs90Run(INT32 nCycles) } while( cpustate->icount > 0 && cpustate->run_end == 0 ); - cpustate->run_end = 0; - cpustate->total_cycles += nCycles; + cpustate->total_cycles += cpustate->nCycles - cpustate->icount; - return nCycles; + INT32 ret = cpustate->nCycles - cpustate->icount; + + cpustate->nCycles = cpustate->icount = 0; + + return ret; } INT32 tlcs90Idle(INT32 cycles) @@ -2079,7 +2084,7 @@ void tlcs90RunEnd() cpustate->run_end = 1; } - + INT32 tlcs90TotalCycles() { @@ -2087,7 +2092,7 @@ INT32 tlcs90TotalCycles() // bprintf (0, _T("TotalCycles: %d\n"), cpustate->total_cycles + (cpustate->nCycles - cpustate->icount)); - return cpustate->total_cycles;// + (cpustate->nCycles - cpustate->icount); + return cpustate->total_cycles + (cpustate->nCycles - cpustate->icount); } void tlcs90Reset() diff --git a/src/cpu/upd7810/upd7810.cpp b/src/cpu/upd7810/upd7810.cpp index 07d30e206..fa7d9c3b7 100644 --- a/src/cpu/upd7810/upd7810.cpp +++ b/src/cpu/upd7810/upd7810.cpp @@ -1889,6 +1889,8 @@ INT32 upd7810Run(INT32 cycles) upd7810_current_cycles = cycles; upd7810_icount = cycles; + run_end = 0; + do { int cc = 0; @@ -1998,9 +2000,7 @@ void upd7810NewFrame() void upd7810RunEnd() { - upd7810_total_cycles += (upd7810_current_cycles - upd7810_icount); - upd7810_current_cycles = 0; - upd7810_icount = 0; + run_end = 1; } INT32 upd7810Idle(INT32 cycles) diff --git a/src/cpu/z180/z180.cpp b/src/cpu/z180/z180.cpp index 4d7d06c82..efd3e05ac 100644 --- a/src/cpu/z180/z180.cpp +++ b/src/cpu/z180/z180.cpp @@ -2064,6 +2064,8 @@ void z180_write_internal_io(UINT32 port, UINT8 data) } } +static INT32 end_run; + /**************************************************************************** * Execute 'cycles' T-states. Return number of T-states really executed ****************************************************************************/ @@ -2073,6 +2075,8 @@ int z180_execute(int cycles) z180_icount = cycles; current_cycles = cycles; + end_run = 0; + /* check for NMIs on the way in; they can only be set externally */ /* via timers, and can't be dynamically enabled, so it is safe */ /* to just check here */ @@ -2125,11 +2129,11 @@ again: /* If DMA is done break out to the faster loop */ if ((IO_DSTAT & Z180_DSTAT_DME) != Z180_DSTAT_DME) break; - } while( z180_icount > 0 ); + } while( z180_icount > 0 && !end_run); } } - if (z180_icount > 0) + if (z180_icount > 0 && !end_run) { do { @@ -2146,17 +2150,21 @@ again: if ((IO_DSTAT & Z180_DSTAT_DME) == Z180_DSTAT_DME) goto again; - } while( z180_icount > 0 ); + } while( z180_icount > 0 && !end_run ); } total_cycles += cycles - z180_icount; - return cycles - z180_icount; + INT32 ret = cycles - z180_icount; + + z180_icount = current_cycles = 0; + + return ret; } void z180_run_end() { - z180_icount = 0; + end_run = 1; } INT32 z180_total_cycles()