1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-23 21:10:57 +01:00

util/dump.c: Add ASCII view to dump output

This commit is contained in:
Tau 2018-11-09 15:59:01 -05:00
parent c1dee321f3
commit 5df0994458

View File

@ -11,7 +11,9 @@
void dump(const void *ptr, size_t nbytes)
{
const uint8_t *bytes;
uint8_t c;
size_t i;
size_t j;
assert(ptr != NULL);
@ -21,16 +23,31 @@ void dump(const void *ptr, size_t nbytes)
bytes = ptr;
for (i = 0 ; i < nbytes ; i++) {
if (i % 16 == 0) {
dprintf("\t%08x:", i);
for (i = 0 ; i < nbytes ; i += 16) {
dprintf(" %08x:", i);
for (j = 0 ; i + j < nbytes && j < 16 ; j++) {
dprintf(" %02x", bytes[i + j]);
}
dprintf(" %02x", bytes[i]);
if (i % 16 == 15) {
dprintf("\n");
while (j < 16) {
dprintf(" ");
j++;
}
dprintf(" ");
for (j = 0 ; i + j < nbytes && j < 16 ; j++) {
c = bytes[i + j];
if (c < 0x20 || c >= 0x7F) {
c = '.';
}
dprintf("%c", c);
}
dprintf("\n");
}
dprintf("\n");