Debugger: Fix LBR so it's updated only if branch is taken (#987)

This commit is contained in:
tomcw 2021-10-16 11:58:09 +01:00
parent 8575238d69
commit 4f8b30506d
5 changed files with 34 additions and 23 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;