From bec5bbc85ca477949779478c263d2f0068b12ec4 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 18 Apr 2016 15:34:55 -0500 Subject: [PATCH] Add smart padding for disassembled bytes. --- src/disassembler.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/disassembler.c b/src/disassembler.c index 04968d3..699bbdc 100644 --- a/src/disassembler.c +++ b/src/disassembler.c @@ -257,8 +257,9 @@ static void mark_header(const ROM *rom, ROMBank *banks) */ static void render_binary(Disassembly *dis, size_t *idx, const ROMBank *bank) { - size_t span = 1, i; - while (span < MAX_BYTES_PER_LINE && bank->types[*idx + span] == DT_BINARY) + size_t span = 1, tabs, i; + while (span < MAX_BYTES_PER_LINE && *idx + span < bank->size && + bank->types[*idx + span] == DT_BINARY) span++; char buf[4 * MAX_BYTES_PER_LINE + 1]; @@ -266,7 +267,13 @@ static void render_binary(Disassembly *dis, size_t *idx, const ROMBank *bank) sprintf(buf + 4 * i, "$%02X ", bank->data[*idx + i]); buf[4 * span - 1] = '\0'; - WRITE_LINE(dis, ".byte %s", buf) + char padding[16]; + tabs = span <= 16 ? 8 - (span - 1) / 2 : 1; + padding[tabs] = '\0'; + while (tabs-- > 0) + padding[tabs] = '\t'; + + WRITE_LINE(dis, ".byte %s%s; $%04zX", buf, padding, *idx) (*idx) += span; }