From 5606ebba46eb493a5bc45482f748701120b5b32d Mon Sep 17 00:00:00 2001 From: tomcw Date: Thu, 13 Mar 2025 22:13:51 +0000 Subject: [PATCH] Fix IRQ; fix MB special writes --- source/CPU.cpp | 30 ++++++++++++++++++++++-------- source/Mockingboard.cpp | 18 +++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index 2c00b6e0..eda2238a 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -452,14 +452,28 @@ static __forceinline bool IRQ(ULONG& uExecutedCycles, BOOL& flagc, BOOL& flagn, #ifdef _DEBUG g_nCycleIrqStart = g_nCumulativeCycles + uExecutedCycles; #endif - _PUSH(regs.pc >> 8) - _PUSH(regs.pc & 0xFF) - EF_TO_AF - _PUSH(regs.ps & ~AF_BREAK) - regs.ps |= AF_INTERRUPT; - if (GetMainCpu() == CPU_65C02) // GH#1099 - regs.ps &= ~AF_DECIMAL; - regs.pc = * (WORD*) (mem+0xFFFE); + if (GetIsMemCacheValid()) + { + _PUSH(regs.pc >> 8) + _PUSH(regs.pc & 0xFF) + EF_TO_AF; + _PUSH(regs.ps & ~AF_BREAK) + regs.ps |= AF_INTERRUPT; + if (GetMainCpu() == CPU_65C02) // GH#1099 + regs.ps &= ~AF_DECIMAL; + regs.pc = *(WORD*)(mem + 0xFFFE); + } + else + { + _PUSH_ALT(regs.pc >> 8) + _PUSH_ALT(regs.pc & 0xFF) + EF_TO_AF; + _PUSH_ALT(regs.ps & ~AF_BREAK) + regs.ps |= AF_INTERRUPT; + if (GetMainCpu() == CPU_65C02) // GH#1099 + regs.ps &= ~AF_DECIMAL; + regs.pc = READ_WORD_ALT(0xFFFE); + } UINT uExtraCycles = 0; // Needed for CYC(a) macro CYC(7); #if defined(_DEBUG) && LOG_IRQ_TAKEN_AND_RTI diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index 0085c0d6..3d647736 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -619,7 +619,7 @@ BYTE MockingboardCard::IOReadInternal(WORD PC, WORD nAddr, BYTE bWrite, BYTE nVa if (!IS_APPLE2 && MemCheckINTCXROM()) { _ASSERT(0); // Card ROM disabled, so IO_Cxxx() returns the internal ROM - return mem[nAddr]; + return ReadByteFromMemory(nAddr); } #endif @@ -691,22 +691,22 @@ BYTE MockingboardCard::IOWriteInternal(WORD PC, WORD nAddr, BYTE bWrite, BYTE nV #endif // Support 6502/65C02 false-reads of 6522 (GH#52) - if ( ((mem[(PC-2)&0xffff] == 0x91) && GetMainCpu() == CPU_6502) || // sta (zp),y - 6502 only (no-PX variant only) (UTAIIe:4-23) - (mem[(PC-3)&0xffff] == 0x99) || // sta abs16,y - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27) - (mem[(PC-3)&0xffff] == 0x9D) ) // sta abs16,x - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27) + if ( ((ReadByteFromMemory((PC-2)&0xffff) == 0x91) && GetMainCpu() == CPU_6502) || // sta (zp),y - 6502 only (no-PX variant only) (UTAIIe:4-23) + (ReadByteFromMemory((PC-3)&0xffff) == 0x99) || // sta abs16,y - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27) + (ReadByteFromMemory((PC-3)&0xffff) == 0x9D) ) // sta abs16,x - 6502/65C02, but for 65C02 only the no-PX variant that does the false-read (UTAIIe:4-27) { WORD base; WORD addr16; - if (mem[(PC-2)&0xffff] == 0x91) + if (ReadByteFromMemory((PC-2)&0xffff) == 0x91) { - BYTE zp = mem[(PC-1)&0xffff]; - base = (mem[zp] | (mem[(zp+1)&0xff]<<8)); + BYTE zp = ReadByteFromMemory((PC-1)&0xffff); + base = (ReadByteFromMemory(zp) | (ReadByteFromMemory((zp+1)&0xff)<<8)); addr16 = base + regs.y; } else { - base = mem[(PC-2)&0xffff] | (mem[(PC-1)&0xffff]<<8); - addr16 = base + ((mem[(PC-3)&0xffff] == 0x99) ? regs.y : regs.x); + base = ReadByteFromMemory((PC-2)&0xffff) | (ReadByteFromMemory((PC-1)&0xffff)<<8); + addr16 = base + ((ReadByteFromMemory((PC-3)&0xffff) == 0x99) ? regs.y : regs.x); } if (((base ^ addr16) >> 8) == 0) // Only the no-PX variant does the false read (to the same I/O SELECT page)