From 4f8b30506d18cbbdb5f2727a8544f8e6821a9101 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 16 Oct 2021 11:58:09 +0100 Subject: [PATCH] Debugger: Fix LBR so it's updated only if branch is taken (#987) --- source/CPU.cpp | 10 ---------- source/CPU.h | 12 ++++++++++++ source/Debugger/Debug.cpp | 13 ++++++++++++- source/Debugger/Debugger_Types.h | 12 ++++++++++-- test/TestCPU6502/TestCPU6502.cpp | 10 ---------- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index f069380a..1319be8e 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -107,16 +107,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define LOG_IRQ_TAKEN_AND_RTI 0 -// 6502 Accumulator Bit Flags - #define AF_SIGN 0x80 - #define AF_OVERFLOW 0x40 - #define AF_RESERVED 0x20 - #define AF_BREAK 0x10 - #define AF_DECIMAL 0x08 - #define AF_INTERRUPT 0x04 - #define AF_ZERO 0x02 - #define AF_CARRY 0x01 - #define SHORTOPCODES 22 #define BENCHOPCODES 33 diff --git a/source/CPU.h b/source/CPU.h index 8b1b95b0..e04ba508 100644 --- a/source/CPU.h +++ b/source/CPU.h @@ -13,6 +13,18 @@ struct regsrec BYTE bJammed; // CPU has crashed (NMOS 6502 only) }; +// 6502 Processor Status flags +enum { + AF_SIGN = 0x80, + AF_OVERFLOW = 0x40, + AF_RESERVED = 0x20, + AF_BREAK = 0x10, + AF_DECIMAL = 0x08, + AF_INTERRUPT = 0x04, + AF_ZERO = 0x02, + AF_CARRY = 0x01 +}; + extern regsrec regs; extern unsigned __int64 g_nCumulativeCycles; diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index c8ff0434..4a3cc4c8 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -8170,7 +8170,18 @@ static void UpdateLBR(void) isControlFlowOpcode = true; if (g_aOpcodes[nOpcode].nAddressMode == AM_R) - isControlFlowOpcode = true; + { + if ( (nOpcode == OPCODE_BRA) || + (nOpcode == OPCODE_BPL && !(regs.ps & AF_SIGN)) || + (nOpcode == OPCODE_BMI && (regs.ps & AF_SIGN)) || + (nOpcode == OPCODE_BVC && !(regs.ps & AF_OVERFLOW)) || + (nOpcode == OPCODE_BVS && (regs.ps & AF_OVERFLOW)) || + (nOpcode == OPCODE_BCC && !(regs.ps & AF_CARRY)) || + (nOpcode == OPCODE_BCS && (regs.ps & AF_CARRY)) || + (nOpcode == OPCODE_BNE && !(regs.ps & AF_ZERO)) || + (nOpcode == OPCODE_BEQ && (regs.ps & AF_ZERO)) ) + isControlFlowOpcode = true; // Branch taken + } if (isControlFlowOpcode) g_LBR = regs.pc; diff --git a/source/Debugger/Debugger_Types.h b/source/Debugger/Debugger_Types.h index afae7630..dc27a878 100644 --- a/source/Debugger/Debugger_Types.h +++ b/source/Debugger/Debugger_Types.h @@ -1075,7 +1075,15 @@ const DisasmData_t* pDisasmData; // If != NULL then bytes are marked up as data enum Opcode_e { - OPCODE_BRA = 0x80, + OPCODE_BPL = 0x10, + OPCODE_BMI = 0x30, + OPCODE_BVC = 0x50, + OPCODE_BVS = 0x70, + OPCODE_BCC = 0x90, + OPCODE_BCS = 0xB0, + OPCODE_BNE = 0xD0, + OPCODE_BEQ = 0xF0, + OPCODE_BRA = 0x80, // 65C02 OPCODE_BRK = 0x00, OPCODE_JSR = 0x20, @@ -1083,7 +1091,7 @@ const DisasmData_t* pDisasmData; // If != NULL then bytes are marked up as data OPCODE_JMP_A = 0x4C, // Absolute OPCODE_RTS = 0x60, OPCODE_JMP_NA = 0x6C, // Indirect Absolute - OPCODE_JMP_IAX = 0x7C, // Indexed (Absolute Indirect, X) + OPCODE_JMP_IAX = 0x7C, // Indexed (Absolute Indirect, X); 65C02 OPCODE_LDA_A = 0xAD, // Absolute OPCODE_NOP = 0xEA, // No operation diff --git a/test/TestCPU6502/TestCPU6502.cpp b/test/TestCPU6502/TestCPU6502.cpp index 2c3cf3a5..7eafbd69 100644 --- a/test/TestCPU6502/TestCPU6502.cpp +++ b/test/TestCPU6502/TestCPU6502.cpp @@ -22,16 +22,6 @@ BYTE __stdcall IO_F8xx(WORD programcounter, WORD address, BYTE write, BYTE value return 0; } -// From CPU.cpp -#define AF_SIGN 0x80 -#define AF_OVERFLOW 0x40 -#define AF_RESERVED 0x20 -#define AF_BREAK 0x10 -#define AF_DECIMAL 0x08 -#define AF_INTERRUPT 0x04 -#define AF_ZERO 0x02 -#define AF_CARRY 0x01 - regsrec regs; bool g_irqOnLastOpcodeCycle = false;