diff options
Diffstat (limited to 'src/board_memory.zig')
| -rw-r--r-- | src/board_memory.zig | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/board_memory.zig b/src/board_memory.zig index f99fc106..702b130d 100644 --- a/src/board_memory.zig +++ b/src/board_memory.zig @@ -296,11 +296,22 @@ pub fn poke(p: *Pardes, id: usize, argument: []const u8) !void { ) catch unreachable); } -/// `Hexdump <addr> [len]` — len bytes, 16 to a row, hex columns and an ASCII -/// gutter, in `hexdump -C`'s layout because that is the one everyone can -/// already read. BYTE reads, so a partial row at the end of the space is a -/// short row rather than a refusal, and no alignment is required: this is the -/// word you reach for when you do not yet know what is there. +/// Bytes per dumped row, and it is a different number on the board. +/// +/// `hexdump -C`'s sixteen is the layout everyone can already read, and it needs 79 columns: ten for +/// the address, forty-eight for the hex, a gap, and the eighteen-column ASCII gutter. The P4 drives +/// a 56-column grid of which seven go to the line-number gutter, so a sixteen-byte row wraps onto a +/// second display line and the columns stop lining up - which is the entire value of the layout. +/// +/// Eight fits in 46 and keeps every property that matters: address on the left, fixed-width hex +/// columns, ASCII on the right, and a gap at the halfway mark because the eye counts in fours and +/// eights rather than in sixteens. +const row_bytes: u32 = if (pardes.platform == .p4) 8 else 16; + +/// `Hexdump <addr> [len]` — len bytes, `row_bytes` to a row, hex columns and an ASCII gutter, in +/// `hexdump -C`'s layout because that is the one everyone can already read. BYTE reads, so a partial +/// row at the end of the space is a short row rather than a refusal, and no alignment is required: +/// this is the word you reach for when you do not yet know what is there. pub fn hexdump(p: *Pardes, id: usize, argument: []const u8) !void { var it = std.mem.tokenizeAny(u8, argument, " \t\r\n"); const addr = try parseAddr(it.next() orelse return Error.MissingAddress); @@ -312,15 +323,14 @@ pub fn hexdump(p: *Pardes, id: usize, argument: []const u8) !void { errdefer out.deinit(); try writeNote(&out.writer, e, requested, "bytes"); var row: u32 = 0; - while (row < e.count) : (row += 16) { - const n = @min(@as(u32, 16), e.count - row); - var bytes: [16]u8 = undefined; + while (row < e.count) : (row += row_bytes) { + const n = @min(row_bytes, e.count - row); + var bytes: [row_bytes]u8 = undefined; for (0..n) |i| bytes[i] = readByte(addr + row + @as(u32, @intCast(i))); try out.writer.print("0x{x:0>8} ", .{addr + row}); - for (0..16) |i| { - // hexdump -C's gap after the eighth column: the eye counts to - // eight, not to sixteen - if (i == 8) try out.writer.writeByte(' '); + for (0..row_bytes) |i| { + // The gap at the halfway mark: the eye counts to four or eight, not to sixteen. + if (i == row_bytes / 2) try out.writer.writeByte(' '); if (i < n) try out.writer.print(" {x:0>2}", .{bytes[i]}) else |
