Browse Source

Add raw instruction debug output; add option to ignore illegal instructions

master
Nathaniel Walizer 11 months ago
parent
commit
fa9d26d34d
1 changed files with 14 additions and 7 deletions
  1. +14
    -7
      e6502.c

+ 14
- 7
e6502.c View File

@@ -515,7 +515,9 @@ 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;
uint8_t val = e6502_adr_r8(core, adr);
e6502_adr_w8(core, adr, val);
val += 1;
core->registers.P &= ~(e6502_Status_Z | e6502_Status_N);
core->registers.P |= (val & e6502_Status_N);
if (!val) core->registers.P |= e6502_Status_Z;
@@ -869,7 +871,7 @@ static const e6502_Instruction e6502_instructions[256] = {

};

/*
#ifdef E6502_DEBUG
int e6502_instr_size(uint8_t opcode) {
const e6502_Instruction* instr = &e6502_instructions[opcode];
if ( instr->address == adr_imp ||
@@ -884,7 +886,7 @@ int e6502_instr_size(uint8_t opcode) {
}
}

int e6502_dump_instr(e6502_Core* core, e6502_Mem_Addr addr,
void e6502_dump_instr(e6502_Core* core, e6502_Mem_Addr addr,
FILE* file) {
uint8_t opcode = e6502_r8(core, addr);
int size = e6502_instr_size(opcode);
@@ -894,11 +896,9 @@ int e6502_dump_instr(e6502_Core* core, e6502_Mem_Addr addr,
} else if (size == 3) {
fprintf(file, " $%04x", e6502_r16(core, addr + 1));
}
fputc('\n', file);
// fputc('\n', file);
}
*/

#ifdef E6502_DEBUG
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,
@@ -938,9 +938,14 @@ int e6502_step(e6502_Core* core) {
&e6502_instructions[opcode];
if (!instr->operator) {
#ifdef E6502_DEBUG
fprintf(stdout, "$%04x: $%02x\n", last_pc, opcode);
fprintf(stdout, "$%04x: $%02x -> ILLEGAL\n", last_pc, opcode);
#endif
#ifndef E6502_ILLEGAL
core->cycle = -1;
#else
core->registers.PC++;
core->cycle += 1;
#endif

} else {
core->registers.PC++;
@@ -954,6 +959,8 @@ int e6502_step(e6502_Core* core) {
}
e6502_dump_regs(core, stdout);
fprintf(stdout, "$%04x: ", last_pc);
e6502_dump_instr(core, last_pc, stdout);
fputs(" -> ", stdout);
e6502_fprintf_instr(stdout, opcode, (uint8_t*)&val);
fputc('\n', stdout);
#endif


Loading…
Cancel
Save