瀏覽代碼

Nicer bytestring formatting in disassembly.

master
Ben Kurtovic 8 年之前
父節點
當前提交
ff25c1d436
共有 2 個文件被更改,包括 18 次插入9 次删除
  1. +15
    -6
      src/disassembler.c
  2. +3
    -3
      src/z80.c

+ 15
- 6
src/disassembler.c 查看文件

@@ -50,18 +50,27 @@ typedef struct {
*/
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)
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++) {
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;
}



+ 3
- 3
src/z80.c 查看文件

@@ -226,8 +226,8 @@ static inline void trace_instruction(Z80 *z80)
return;
}
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;
}

@@ -238,7 +238,7 @@ static inline void trace_instruction(Z80 *z80)
uint8_t bytes[4] = {quad, quad >> 8, quad >> 16, quad >> 24};
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);
}



Loading…
取消
儲存