Browse Source

Add smart padding for disassembled bytes.

master
Ben Kurtovic 8 years ago
parent
commit
bec5bbc85c
1 changed files with 10 additions and 3 deletions
  1. +10
    -3
      src/disassembler.c

+ 10
- 3
src/disassembler.c View File

@@ -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;
}



Loading…
Cancel
Save