From 321da7e437581a91f48bb72b41ec0f281af761eb Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 4 Jan 2025 22:31:24 +0000 Subject: [PATCH] CPU emu: add _IABS_CMOS and IABS_NMOS macros --- source/CPU.cpp | 8 ++++++++ source/CPU/cpu_general.inl | 16 +++++++++++++++- test/TestCPU6502/TestCPU6502.cpp | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index f479261e..f81ad35f 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -500,6 +500,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #define WRITE(value) _WRITE(value) #define POP _POP #define PUSH(value) _PUSH(value) +#define IABS_CMOS _IABS_CMOS #include "CPU/cpu65C02.h" // WDC 65C02 @@ -507,6 +508,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS //------- @@ -515,6 +517,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #define WRITE(value) _WRITE_ALT(value) #define POP _POP_ALT #define PUSH(value) _PUSH_ALT(value) +#define IABS_CMOS _IABS_CMOS_ALT #define Cpu65C02 Cpu65C02_altRW #include "CPU/cpu65C02.h" // WDC 65C02 @@ -524,6 +527,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS #undef HEATMAP_X //----------------- @@ -570,6 +574,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #define WRITE(value) Heatmap_WriteByte(addr, value, uExecutedCycles); #define POP _POP #define PUSH(value) _PUSH(value) +#define IABS_CMOS _IABS_CMOS #define Cpu65C02 Cpu65C02_debug #include "CPU/cpu65C02.h" // WDC 65C02 @@ -579,6 +584,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS //------- @@ -587,6 +593,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #define WRITE(value) _WRITE_ALT(value) #define POP _POP_ALT #define PUSH(value) _PUSH_ALT(value) +#define IABS_CMOS _IABS_CMOS_ALT #define Cpu65C02 Cpu65C02_debug_altRW #include "CPU/cpu65C02.h" // WDC 65C02 @@ -596,6 +603,7 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS #undef HEATMAP_X //=========================================================================== diff --git a/source/CPU/cpu_general.inl b/source/CPU/cpu_general.inl index bef190e0..a88fe25f 100644 --- a/source/CPU/cpu_general.inl +++ b/source/CPU/cpu_general.inl @@ -175,16 +175,30 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define ABSY_CONST base = *(LPWORD)(mem+regs.pc); addr = base+(WORD)regs.y; regs.pc += 2; // TODO Optimization Note (just for IABSCMOS): uExtraCycles = ((base & 0xFF) + 1) >> 8; -#define IABS_CMOS base = *(LPWORD)(mem+regs.pc); \ +#define _IABS_CMOS base = *(LPWORD)(mem+regs.pc); \ addr = *(LPWORD)(mem+base); \ if ((base & 0xFF) == 0xFF) uExtraCycles=1; \ regs.pc += 2; +#define _IABS_CMOS_ALT base = *(LPWORD)(mem+regs.pc); \ + if (memreadPageType[base >> 8] == MEM_Aux1K) \ + base = TEXT_PAGE1_BEGIN + (base & (TEXT_PAGE1_SIZE-1)); \ + addr = *(LPWORD)(mem+base); \ + if ((base & 0xFF) == 0xFF) uExtraCycles=1; \ + regs.pc += 2; #define IABS_NMOS base = *(LPWORD)(mem+regs.pc); \ if ((base & 0xFF) == 0xFF) \ addr = *(mem+base)+((WORD)*(mem+(base&0xFF00))<<8);\ else \ addr = *(LPWORD)(mem+base); \ regs.pc += 2; +#define _IABS_NMOS_ALT base = *(LPWORD)(mem+regs.pc); \ + if (memreadPageType[base >> 8] == MEM_Aux1K) \ + base = TEXT_PAGE1_BEGIN + (base & (TEXT_PAGE1_SIZE-1)); \ + if ((base & 0xFF) == 0xFF) \ + addr = *(mem+base)+((WORD)*(mem+(base&0xFF00))<<8); \ + else \ + addr = *(LPWORD)(mem+base); \ + regs.pc += 2; #define IMM addr = regs.pc++; diff --git a/test/TestCPU6502/TestCPU6502.cpp b/test/TestCPU6502/TestCPU6502.cpp index 2a79cfe6..fea1c0f2 100644 --- a/test/TestCPU6502/TestCPU6502.cpp +++ b/test/TestCPU6502/TestCPU6502.cpp @@ -99,6 +99,7 @@ void NTSC_VideoUpdateCycles( long cycles6502 ) #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS //------- @@ -106,6 +107,7 @@ void NTSC_VideoUpdateCycles( long cycles6502 ) #define WRITE(a) _WRITE(a) #define POP _POP #define PUSH(a) _PUSH(a) +#define IABS_CMOS _IABS_CMOS_ALT #include "../../source/CPU/cpu65C02.h" // WDC 65C02 @@ -113,6 +115,7 @@ void NTSC_VideoUpdateCycles( long cycles6502 ) #undef WRITE #undef POP #undef PUSH +#undef IABS_CMOS #undef HEATMAP_X //-------------------------------------