From 70937cd61f63e159d5de226fa640d102c8fb0d14 Mon Sep 17 00:00:00 2001 From: vin Date: Sat, 20 Jul 2024 20:27:55 -0400 Subject: [PATCH] replace tabs with spaces to better match nestest.log --- cpu.c | 63 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/cpu.c b/cpu.c index 4b55818..a4be93c 100644 --- a/cpu.c +++ b/cpu.c @@ -841,8 +841,8 @@ XAS(uint16_t arg) static void interpret(void) { - uint8_t op; - uint16_t arg, mem, deref; + uint8_t op, spaces; + uint16_t arg; enum addressing_mode mode; for (;;) { @@ -854,16 +854,13 @@ interpret(void) for (uint8_t i = 0; i < opcodes[op].bytes - 1; i++) printf(" %02X", peek(regs.pc + i)); - if (opcodes[op].unofficial) { - if (opcodes[op].bytes == 1) - printf(" "); - else if (opcodes[op].bytes == 2) - printf(" "); - else if (opcodes[op].bytes == 3) - putchar(' '); - putchar('*'); - } else - putchar('\t'); + if (opcodes[op].bytes == 1) + printf(" "); + else if (opcodes[op].bytes == 2) + printf(" "); + else if (opcodes[op].bytes == 3) + putchar(' '); + putchar((opcodes[op].unofficial) ? '*' : ' '); printf("%s ", opcodes[op].name); mode = opcodes[op].mode; @@ -896,27 +893,53 @@ interpret(void) printf("($%04X) = %04X", arg, peek16(arg)); break; case AM_IND_X: - printf("($%02X,X) @ %02X = %04X", peek(regs.pc - 1), peek(regs.pc - 1) + regs.x, arg); + printf("($%02X,X) @ %02X = %04X", peek(regs.pc - 1), (peek(regs.pc - 1) + regs.x) & 0xFF, arg); break; case AM_IND_Y: printf("($%02X),Y = %04X @ %04X", peek(regs.pc - 1), (uint16_t)(arg - regs.y), arg); break; case AM_ACC: case AM_NONE: - putchar('\t'); - break; - default: - printf("\t\t\t\t"); + printf(" "); break; } + spaces = 9; + if (opcodes[op].memread || opcodes[op].memwrite) printf(" = %02X", peek(arg)); + else + spaces += 5; if (mode != AM_IND && mode != AM_ABS_X && mode != AM_ABS_Y) - putchar('\t'); - if (mode != AM_IND_X && mode != AM_IND_Y) - printf("\t\t"); + spaces += 7; + + switch (opcodes[op].mode) { + case AM_IND_X: + spaces -= 12; + break; + case AM_IND_Y: + spaces -= 14; + break; + case AM_ZP: + spaces += 4; + break; + case AM_ZP_X: + case AM_ZP_Y: + case AM_REL: + case AM_ABS: + spaces += 2; + break; + case AM_IMM: + case AM_ACC: + case AM_NONE: + spaces += 3; + break; + default: + break; + } + + while (spaces--) putchar(' '); printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n", regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles);