From 6b160c6ca26ba629a403ec907886f7f3b362d979 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 19 Jan 2018 12:18:24 -0600 Subject: [PATCH] Show the dereferenced value for a given address --- include/mos6502.h | 2 +- src/mos6502.c | 6 +++--- src/mos6502.dis.c | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/mos6502.h b/include/mos6502.h index dea1e71..a38e816 100644 --- a/include/mos6502.h +++ b/include/mos6502.h @@ -149,7 +149,7 @@ extern void mos6502_set_status(mos6502 *, vm_8bit); * Below are some functions that are defined in mos6502.addr.c */ extern int mos6502_addr_mode(vm_8bit); -extern mos6502_address_resolver mos6502_get_address_resolver(vm_8bit); +extern mos6502_address_resolver mos6502_get_address_resolver(int); /* * All of our address modes diff --git a/src/mos6502.c b/src/mos6502.c index 64c5cf5..3a0839d 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -352,7 +352,7 @@ mos6502_execute(mos6502 *cpu) // First, we need to know how to resolve our effective address and // how to execute anything. - resolver = mos6502_get_address_resolver(opcode); + resolver = mos6502_get_address_resolver(mos6502_addr_mode(opcode)); handler = mos6502_get_instruction_handler(opcode); // The operand is the effective operand, the value that the @@ -454,9 +454,9 @@ mos6502_would_jump(int inst_code) * cpu) that an instruction will use. */ mos6502_address_resolver -mos6502_get_address_resolver(vm_8bit opcode) +mos6502_get_address_resolver(int addr_mode) { - switch (mos6502_addr_mode(opcode)) { + switch (addr_mode) { case ACC: return mos6502_resolve_acc; case ABS: return mos6502_resolve_abs; case ABX: return mos6502_resolve_abx; diff --git a/src/mos6502.dis.c b/src/mos6502.dis.c index f57e19e..be94b03 100644 --- a/src/mos6502.dis.c +++ b/src/mos6502.dis.c @@ -12,6 +12,7 @@ static char s_inst[4], s_oper[10], + s_value[3], s_label[13], s_state[51], s_bytes[12]; @@ -94,38 +95,53 @@ mos6502_dis_operand(mos6502 *cpu, { int rel_address; int ind_address; + vm_8bit eff_value; + mos6502_address_resolver resolv; + + resolv = mos6502_get_address_resolver(addr_mode); + eff_value = resolv(cpu); switch (addr_mode) { case ACC: break; case ABS: snprintf(str, len, "$%04X", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case ABX: snprintf(str, len, "$%04X,X", value); + eff_value = resolv(cpu); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case ABY: snprintf(str, len, "$%04X,Y", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case IMM: snprintf(str, len, "#$%02X", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case IMP: + snprintf(s_value, sizeof(s_value), "%02X", 0); break; case IND: ind_address = mos6502_get(cpu, value + 1) << 8; ind_address |= mos6502_get(cpu, value); if (jump_table[ind_address]) { mos6502_dis_label(str, len, ind_address); + snprintf(s_value, sizeof(s_value), "%02X", 0); } else { snprintf(str, len, "($%04X)", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); } break; case IDX: snprintf(str, len, "($%02X,X)", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case IDY: snprintf(str, len, "($%02X),Y", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case REL: rel_address = address + value; @@ -134,17 +150,21 @@ mos6502_dis_operand(mos6502 *cpu, } mos6502_dis_label(str, len, rel_address); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case ZPG: // We add a couple of spaces here to help our output // comments line up. snprintf(str, len, "$%02X", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case ZPX: snprintf(str, len, "$%02X,X", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; case ZPY: snprintf(str, len, "$%02X,Y", value); + snprintf(s_value, sizeof(s_value), "%02x", eff_value); break; } } @@ -301,9 +321,9 @@ mos6502_dis_opcode(mos6502 *cpu, FILE *stream, int address) // what the PC was at the point of this opcode sequence; two, // the opcode; snprintf(s_state, sizeof(s_state) - 1, - "pc:%02x%02x cy:%02d val:%04x a:%02x x:%02x y:%02x p:%02x s:%02x", + "pc:%02x%02x cy:%02d val:%2s a:%02x x:%02x y:%02x p:%02x s:%02x", cpu->PC >> 8, cpu->PC & 0xff, - mos6502_cycles(cpu, opcode), operand, + mos6502_cycles(cpu, opcode), s_value, cpu->A, cpu->X, cpu->Y, cpu->P, cpu->S); // And three, the operand, if any. Remembering that the operand