diff options
Diffstat (limited to 'anim/src/rows.zig')
| -rw-r--r-- | anim/src/rows.zig | 81 |
1 files changed, 64 insertions, 17 deletions
diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 1d097a1..69aa62b 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -58,6 +58,41 @@ pub const Marks = struct { lead: usize = 0, }; +/// `chain` of a memory access narrower than a word: its address, then what +/// the access reads there at its width (`7fffffffecc4 ◂ 15`), the marks +/// as `chain` takes them (`first`, `read` on the address; `changed` 1 on the value). +pub fn narrow(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, addr: u64, len: u64, room: f32, marks: Marks) Hops { + const base = baseline(y); + const w = ui.Value.of(addr, true).width(); + const at_addr: Rect = .{ .x = x, .y = y, .w = w, .h = row_h }; + var face_ink: ui.Ink = .{ .ink = ui.rgb(ink(regionOf(moment, addr))) }; + if (u.written(at_addr, marks.first)) |struck| face_ink = struck; + if (marks.read == 0) u.read(at_addr, marks.read_shows); + _ = u.address(x, base, addr, .{ .ink = face_ink.ink, .face = face_ink.face, .lead = marks.lead }); + var hops: Hops = .{ .n = 1, .end = x + w }; + hops.x[0] = x; + hops.w[0] = w; + var raw: [8]u8 = @splat(0); + var known: [8]bool = @splat(false); + moment.read(addr, raw[0..@min(len, 8)], known[0..@min(len, 8)]) catch return hops; + if (std.mem.indexOfScalar(bool, known[0..@min(len, 8)], false) != null) return hops; + const value = std.mem.readInt(u64, &raw, .little); + const shown = ui.Value.of(value, false); + if (hops.end + m.arrow_w + shown.width() > room) return hops; + const at = u.arrow(hops.end, y + row_h / 2, .holds); + const marked: Rect = .{ .x = at, .y = y, .w = shown.width(), .h = row_h }; + var value_ink: ui.Ink = .{ .ink = ui.rgb(t.primary) }; + if (marks.changed == 1) if (u.written(marked, marks.changed_heat)) |struck| { + value_ink = struck; + }; + _ = u.value(at, base, value, false, value_ink); + hops.x[1] = at; + hops.w[1] = shown.width(); + hops.n = 2; + hops.end = at + shown.width() + if (shown.decimal) 8 + @as(f32, @floatFromInt(std.fmt.count("{d}", .{value}))) * adv else 0; + return hops; +} + /// Where a chain's hops were drawn: x and width of each one's digits. pub const Hops = struct { x: [6]f32 = undefined, @@ -348,6 +383,11 @@ pub const Run = struct { /// Its mark: struck (heat), read (shows), held is in the heat. heat: ui.Heat = .none, read: f32 = 0, + /// The bytes of it whose value the heat's step changed, first and last + /// (from `first`): what the strike, the arm and the corner cover. Null: all of it. + changed: ?[2]u8 = null, + /// Frames between the strikes of its bytes, from the low address. + apart: f32 = 1, }; /// `bytes`: a hexdump row of sixteen bytes at `addr`: a bracket at 7 @@ -384,22 +424,28 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons const r: Rect = .{ .x = x0, .y = y + 1, .w = x1 - x0, .h = row_h - 2 }; const field = run.kind == .number or run.kind == .pointer or run.kind == .text; if (field) u.fill(r, theme.color.raised); - // Marks per run, never per byte: struck (the softened paper, the - // digits bold and bright), read (a frame 3 out), held (a turned - // corner at the run's top left). - var face: ui.Face = .mono; - var struck_ink: ?ui.Color = null; + // Read is per run (a frame 3 out). A write's marks cover the bytes + // whose value changed, first to last (`changed`): armed, then struck + // a byte a frame from the low address (the softened paper, the + // digits bold and bright), held by a turned corner on the first. const h = run.heat; - if (h.arm > 0) u.faded(h.arm).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.write).solid, 2); - const solid = if (h.level >= 1) h.solid * h.in else 0; - if (solid > 0) { - u.fill(.{ .x = r.x - h.out, .y = r.y - h.out, .w = r.w + 2 * h.out, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); - if (solid >= 0.5) { - face = .mono_bold; - struck_ink = ui.rgb(t.bright); - } - } - u.corner(x0, y + 2, m.corner, h.level * h.corner); + const lo: u8 = if (run.changed) |c| c[0] else 0; + const hi: u8 = if (run.changed) |c| c[1] else run.len - 1; + const s0 = byteX(run.first + lo) - 4; + const s1 = byteX(run.first + hi) + 28; + if (h.arm > 0) u.faded(h.arm).frame(.{ .x = s0 - 3, .y = y - 1, .w = s1 - s0 + 6, .h = row_h + 2 }, theme.mark(.write).solid, 2); + var solid_of: [16]f32 = @splat(0); + if (h.level >= 1 and h.solid > 0) for (lo..@as(usize, hi) + 1) |j| { + const i: u8 = @intCast(run.first + j); + const solid = h.solid * std.math.clamp(h.in - @as(f32, @floatFromInt(j - lo)) * run.apart / (60.0 * theme.time.strike.in), 0, 1); + solid_of[j] = solid; + if (solid <= 0) continue; + // Each byte's paper up to the next one's, the pulse on the span's outer edges. + const bx0 = byteX(i) - 4 - if (j == lo) h.out else 0; + const bx1 = (if (j < hi) byteX(i + 1) - 4 else byteX(i) + 28) + if (j == hi) h.out else 0; + u.fill(.{ .x = bx0, .y = r.y - h.out, .w = bx1 - bx0, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); + }; + u.corner(s0, y + 2, m.corner, h.level * h.corner); if (run.read > 0) u.faded(run.read).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.read).solid, 2); // A little-endian word: the bytes above its highest non-zero one are its padding. var top: usize = 0; @@ -422,8 +468,9 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons u.fill(.{ .x = x + 15, .y = y + 11, .w = 4, .h = 4 }, t.faint); continue; } - const c = struck_ink orelse if (j <= top) run_ink else ui.mix(run_ink, theme.color.page, theme.metric.context.pad_alpha); - u.text(face, size, x, base, u.print("{x:0>2}", .{values[i]}), c); + const struck = solid_of[j] >= 0.5; + const c = if (struck) ui.rgb(t.bright) else if (j <= top) run_ink else ui.mix(run_ink, theme.color.page, theme.metric.context.pad_alpha); + u.text(if (struck) .mono_bold else .mono, size, x, base, u.print("{x:0>2}", .{values[i]}), c); } } } |
