Skip to content

Commit 41ae681

Browse files
committed
Only elide sram dump of all zeroes
1 parent 8c37d68 commit 41ae681

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

sim/aviron/src/lib/Cpu.zig

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ pub fn dump_system_state(cpu: *Cpu) void {
115115
std.debug.print("\nSRAM DUMP (0x{X:0>4}-0x{X:0>4}, {d} bytes):\n", .{ sram_base, sram_end, cpu.sram.size });
116116

117117
const row_width = 16;
118-
var prev_row: [row_width]u8 = undefined;
118+
var prev_row: ?[row_width]u8 = null;
119119
var prev_len: usize = 0;
120-
var have_prev = false;
121120
var elided = false;
122121

123122
var i: usize = 0;
@@ -130,9 +129,18 @@ pub fn dump_system_state(cpu: *Cpu) void {
130129
cur_row[j] = cpu.sram.read(sram_base + @as(u24, @intCast(i + j)));
131130
}
132131

133-
// 'Don't show repeated lines to minimize the size of the dump
134-
const same_as_prev = have_prev and prev_len == row_len and std.mem.eql(u8, prev_row[0..prev_len], cur_row[0..row_len]);
135-
if (same_as_prev) {
132+
// Only elide repeated lines of all zeroes
133+
const is_all_zeros = blk: {
134+
for (cur_row[0..row_len]) |byte| {
135+
if (byte != 0) break :blk false;
136+
}
137+
break :blk true;
138+
};
139+
const same_as_prev = if (prev_row) |prev|
140+
prev_len == row_len and std.mem.eql(u8, prev[0..prev_len], cur_row[0..row_len])
141+
else
142+
false;
143+
if (same_as_prev and is_all_zeros) {
136144
elided = true;
137145
} else {
138146
if (elided) {
@@ -169,9 +177,11 @@ pub fn dump_system_state(cpu: *Cpu) void {
169177
std.debug.print("|\n", .{});
170178

171179
// store as previous row
172-
@memcpy(prev_row[0..row_len], cur_row[0..row_len]);
180+
if (prev_row == null) {
181+
prev_row = [_]u8{0} ** row_width;
182+
}
183+
@memcpy(prev_row.?[0..row_len], cur_row[0..row_len]);
173184
prev_len = row_len;
174-
have_prev = true;
175185
}
176186
}
177187
if (elided)

0 commit comments

Comments
 (0)