Skip to content

Commit 8c37d68

Browse files
committed
Add ascii rep in mem dump
1 parent cdb761a commit 8c37d68

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sim/aviron/src/lib/Cpu.zig

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,32 @@ pub fn dump_system_state(cpu: *Cpu) void {
141141
}
142142

143143
std.debug.print("0x{X:0>4}: ", .{sram_base + @as(u24, @intCast(i))});
144+
// hex bytes
144145
j = 0;
145146
while (j < row_len) : (j += 1) {
146147
std.debug.print("{X:0>2} ", .{cur_row[j]});
147148
}
148-
std.debug.print("\n", .{});
149+
150+
// pad hex area for short rows to align ASCII column
151+
if (row_len < row_width) {
152+
var pad: usize = row_width - row_len;
153+
while (pad > 0) : (pad -= 1) {
154+
std.debug.print(" ", .{});
155+
}
156+
}
157+
158+
// ASCII representation
159+
std.debug.print(" |", .{});
160+
j = 0;
161+
while (j < row_len) : (j += 1) {
162+
const b = cur_row[j];
163+
if (b >= 32 and b <= 126) {
164+
std.debug.print("{c}", .{b});
165+
} else {
166+
std.debug.print(".", .{});
167+
}
168+
}
169+
std.debug.print("|\n", .{});
149170

150171
// store as previous row
151172
@memcpy(prev_row[0..row_len], cur_row[0..row_len]);

0 commit comments

Comments
 (0)