From f8e111fe51593700f8cf850ca55bd325539b1353 Mon Sep 17 00:00:00 2001 From: tomcw Date: Wed, 12 Mar 2025 22:14:28 +0000 Subject: [PATCH] Fix for regs.pc++ - move this outside of CPP macros --- source/CPU.cpp | 8 ++++++-- source/CPU/cpu_general.inl | 15 ++++++++------- source/Memory.cpp | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index 28a09be9..4e1d1dd9 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -774,7 +774,11 @@ void CpuReset() regs.ps |= AF_INTERRUPT; if (GetMainCpu() == CPU_65C02) // GH#1099 regs.ps &= ~AF_DECIMAL; - regs.pc = *(WORD*)(mem + 0xFFFC); + + const uint16_t resetVector = 0xFFFC; + _ASSERT(memshadow[resetVector >> 8] != NULL); + regs.pc = *(uint16_t*)(memshadow[resetVector >> 8] + (resetVector & 0xff)); + regs.sp = 0x0100 | ((regs.sp - 3) & 0xFF); regs.bJammed = 0; @@ -787,7 +791,7 @@ void CpuReset() //=========================================================================== -void CpuSetupBenchmark () +void CpuSetupBenchmark() { regs.a = 0; regs.x = 0; diff --git a/source/CPU/cpu_general.inl b/source/CPU/cpu_general.inl index 64b76685..43b9f6aa 100644 --- a/source/CPU/cpu_general.inl +++ b/source/CPU/cpu_general.inl @@ -239,7 +239,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA else \ addr = *(LPWORD)(mem+base); #define _INDX_ALT \ - base = (READ_BYTE_ALT(regs.pc++)+regs.x) & 0xFF; \ + base = (READ_BYTE_ALT(regs.pc)+regs.x) & 0xFF; regs.pc++; \ if (base == 0xFF) \ addr = READ_BYTE_ALT(0xFF) | (READ_BYTE_ALT(0x00)<<8); \ else \ @@ -253,11 +253,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA regs.pc++; \ addr = base+(WORD)regs.y; #define _INDY_CONST_ALT \ - base = READ_BYTE_ALT(regs.pc++); \ + base = READ_BYTE_ALT(regs.pc); \ if (base == 0xFF) \ base = READ_BYTE_ALT(0xFF) | (READ_BYTE_ALT(0x00)<<8); \ else \ base = READ_WORD_ALT(base); \ + regs.pc++; \ addr = base+(WORD)regs.y; // Optimised for page-cross @@ -270,14 +271,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA else \ addr = *(LPWORD)(mem+base); #define _IZPG_ALT \ - base = READ_BYTE_ALT(regs.pc++); \ + base = READ_BYTE_ALT(regs.pc); regs.pc++; \ if (base == 0xFF) \ addr = READ_BYTE_ALT(0xFF) | (READ_BYTE_ALT(0x00)<<8); \ else \ addr = READ_WORD_ALT(base); #define _REL addr = (signed char)*(mem+regs.pc++); -#define _REL_ALT addr = (signed char)READ_BYTE_ALT(regs.pc++); +#define _REL_ALT addr = (signed char)READ_BYTE_ALT(regs.pc); regs.pc++; // TODO Optimization Note: // . Opcodes that generate zero-page addresses can't be accessing $C000..$CFFF @@ -286,9 +287,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define _ZPGX addr = ((*(mem+regs.pc++))+regs.x) & 0xFF; #define _ZPGY addr = ((*(mem+regs.pc++))+regs.y) & 0xFF; -#define _ZPG_ALT addr = READ_BYTE_ALT(regs.pc++); -#define _ZPGX_ALT addr = (READ_BYTE_ALT(regs.pc++) + regs.x) & 0xFF; -#define _ZPGY_ALT addr = (READ_BYTE_ALT(regs.pc++) + regs.y) & 0xFF; +#define _ZPG_ALT addr = READ_BYTE_ALT(regs.pc); regs.pc++; +#define _ZPGX_ALT addr = (READ_BYTE_ALT(regs.pc) + regs.x) & 0xFF; regs.pc++; +#define _ZPGY_ALT addr = (READ_BYTE_ALT(regs.pc) + regs.y) & 0xFF; regs.pc++; // Tidy 3 char opcodes & addressing modes to keep the opcode table visually aligned, clean, and readable. #undef asl diff --git a/source/Memory.cpp b/source/Memory.cpp index 25d838ab..dfe52e5f 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1304,7 +1304,6 @@ static void UpdatePaging(BOOL initialize) } const bool alt = IsAppleIIe(GetApple2Type()) && (GetCardMgr().QueryAux() == CT_Empty || GetCardMgr().QueryAux() == CT_80Col); - if (!alt) { // MOVE MEMORY BACK AND FORTH AS NECESSARY BETWEEN THE SHADOW AREAS AND // THE MAIN RAM IMAGE TO KEEP BOTH SETS OF MEMORY CONSISTENT WITH THE NEW @@ -1325,7 +1324,8 @@ static void UpdatePaging(BOOL initialize) ((*(memdirty + loop) & 1) || (loop <= 1))) { *(memdirty + loop) &= ~1; - memcpy(oldshadow[loop], mem + (loop << 8), 256); + if (!alt) // DEBUG: move this "if" here (from above) so that this "for-loop" is run, and mem gets updated and the debugger (sort of) works! + memcpy(oldshadow[loop], mem + (loop << 8), 256); } memcpy(mem + (loop << 8), memshadow[loop], 256);