From 13877785aa812501843ea8260016f292833fdc45 Mon Sep 17 00:00:00 2001 From: Nathaniel Walizer Date: Sun, 22 Dec 2024 19:40:11 -0800 Subject: [PATCH] Define HCF feature (tight loop detection); debug fixup --- e6502.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/e6502.c b/e6502.c index be977b8..c65451e 100644 --- a/e6502.c +++ b/e6502.c @@ -207,6 +207,7 @@ static inline void eor(e6502_Core *core, e6502_Address adr) { } static inline void asl(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr); core->registers.P &= ~(e6502_Status_C | e6502_Status_Z | @@ -231,6 +232,7 @@ static inline void asl_a(e6502_Core *core, e6502_Address adr) { } static inline void lsr(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr); core->registers.P &= ~(e6502_Status_C | e6502_Status_Z | @@ -255,6 +257,7 @@ static inline void lsr_a(e6502_Core *core, e6502_Address adr) { } static inline void rol(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr); uint8_t new_c = (val & 0x80) ? e6502_Status_C : 0; val <<= 1; @@ -283,6 +286,7 @@ static inline void rol_a(e6502_Core *core, e6502_Address adr) { } static inline void ror(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr); uint8_t new_c = (val & e6502_Status_C); val >>= 1; @@ -509,6 +513,7 @@ static inline void sbc(e6502_Core *core, e6502_Address adr) { } static inline void inc(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr) + 1; core->registers.P &= ~(e6502_Status_Z | e6502_Status_N); core->registers.P |= (val & e6502_Status_N); @@ -533,6 +538,7 @@ static inline void iny(e6502_Core *core, e6502_Address) { } static inline void dec(e6502_Core *core, e6502_Address adr) { + // TODO: Emulate double-read or double-write uint8_t val = e6502_adr_r8(core, adr) - 1; core->registers.P &= ~(e6502_Status_Z | e6502_Status_N); core->registers.P |= (val & e6502_Status_N); @@ -892,7 +898,7 @@ int e6502_dump_instr(e6502_Core* core, e6502_Mem_Addr addr, */ #ifdef E6502_DEBUG -int e6502_dump_regs(e6502_Core* core, FILE* file) { +void e6502_dump_regs(e6502_Core* core, FILE* file) { fprintf(file, "S:%02x A:%02x X:%02x Y:%02x P:%02x\n", core->registers.S, core->registers.A, core->registers.X, core->registers.Y, @@ -930,18 +936,21 @@ int e6502_run(e6502_Core* core, int end = start + remaining; int last_pc = -1; while ((instructions ? i_count : core->cycle) < end) { +#ifdef E6502_HCF if (core->registers.PC == last_pc) { // Trapped. status = -2; break; } +#endif last_pc = core->registers.PC; + (void)last_pc; uint8_t opcode = e6502_r8(core, core->registers.PC); const e6502_Instruction* instr = &e6502_instructions[opcode]; if (!instr->operator) { #ifdef E6502_DEBUG - fprintf(stdout, "$%04x: %02x\n", last_pc, opcode); + fprintf(stdout, "$%04x: $%02x\n", last_pc, opcode); #endif status = -1; break;