Browse Source

Nicer bytestring formatting in disassembly.

master
Ben Kurtovic 8 years ago
parent
commit
ff25c1d436
2 changed files with 18 additions and 9 deletions
  1. +15
    -6
      src/disassembler.c
  2. +3
    -3
      src/z80.c

+ 15
- 6
src/disassembler.c View File

@@ -50,18 +50,27 @@ typedef struct {
*/ */
static char* format_bytestring(const uint8_t *bytes, size_t size) static char* format_bytestring(const uint8_t *bytes, size_t size)
{ {
// TODO: smarter alignment; pad to full len (then remove pad from TRACE())
if (!size) if (!size)
return NULL; return NULL;


char *str = cr_malloc(sizeof(char) * (3 * size));
size_t i;
char *str = cr_malloc(sizeof(char) * 16);
size_t offset = 2, i;
uint8_t b = bytes[0];

if (b == 0xCB || b == 0xDD || b == 0xED || b == 0xFD) {
offset--;
if ((b == 0xDD || b == 0xFD) && bytes[1] == 0xCB)
offset--;
}


for (i = 0; i < offset; i++) {
str[3 * i] = str[3 * i + 1] = str[3 * i + 2] = ' ';
}
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
snprintf(&str[3 * i], 3, "%02X", bytes[i]);
str[3 * i + 2] = ' ';
snprintf(&str[3 * (i + offset)], 3, "%02X", bytes[i]);
str[3 * (i + offset) + 2] = ' ';
} }
str[3 * size - 1] = '\0';
str[3 * (size + offset) - 1] = '\0';
return str; return str;
} }




+ 3
- 3
src/z80.c View File

@@ -226,8 +226,8 @@ static inline void trace_instruction(Z80 *z80)
return; return;
} }
if (z80->trace.fresh) { if (z80->trace.fresh) {
TRACE("PC ADDR RAW INSTR\tARGS")
TRACE("------- --- -----\t----")
TRACE("PC ADDR P1 P2 OP A1 A2 INSTR\tARGS")
TRACE("------- -------------- -----\t----")
z80->trace.fresh = false; z80->trace.fresh = false;
} }


@@ -238,7 +238,7 @@ static inline void trace_instruction(Z80 *z80)
uint8_t bytes[4] = {quad, quad >> 8, quad >> 16, quad >> 24}; uint8_t bytes[4] = {quad, quad >> 8, quad >> 16, quad >> 24};
DisasInstr *instr = disassemble_instruction(bytes); DisasInstr *instr = disassemble_instruction(bytes);


TRACE("0x%04X: %11s %s", z80->regfile.pc, instr->bytestr, instr->line)
TRACE("0x%04X: %-14s %s", z80->regfile.pc, instr->bytestr, instr->line)
disas_instr_free(instr); disas_instr_free(instr);
} }




Loading…
Cancel
Save