summaryrefslogtreecommitdiff
path: root/anim/src/cursor.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 11:32:59 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:19:32 -0300
commiteab50d1c040774351f332a1568fa332c377860bd (patch)
tree0e727f9bf323e49aa6a2f55bb4fabd166aa9a492 /anim/src/cursor.zig
parent38971edd9b49a802e6e726fb51d162df1bf58b83 (diff)
downloadcomputeranim-eab50d1c040774351f332a1568fa332c377860bd.tar.gz
computeranim-eab50d1c040774351f332a1568fa332c377860bd.zip
canim: the introduction as one video, with a chapter on registers
From the user. One scene, intro, in four chapters: memory, registers, the stack, code and meaning (210 s). The registers chapter builds the panel before the stack needs it: sixteen rows with their chains, rip pinned on the code band and rsp and rbp on the stack's, rdi opened into its parts as mov edi changes one byte, a call to malloc stepped over with its result in rax, the registers a scene never changes folded. The chapters join at seams that say their title and keep it as the clock's label; one recording (from push(9), no agent, the heap from --heap) and one clock. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/cursor.zig')
-rw-r--r--anim/src/cursor.zig40
1 files changed, 36 insertions, 4 deletions
diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig
index c145823..f574941 100644
--- a/anim/src/cursor.zig
+++ b/anim/src/cursor.zig
@@ -129,12 +129,17 @@ pub const Plan = struct {
pins: [2]f32 = .{ -1, -1 },
follow: f32 = -1,
project: f32 = -1,
+ /// A call stepped over (design/motion.md, "A call stepped over"): its
+ /// result first, rax armed and struck as a walked register in the CPU's
+ /// slot, the call's row taking its C form with it; the others it changed
+ /// in a wave from here (seconds from the step's first frame); -1: none.
+ result: f32 = -1,
/// How many values a plan is on the timeline (`pack`).
- const values = 18;
+ const values = 19;
fn pack(p: Plan) [values]f32 {
- return .{ @floatFromInt(@intFromEnum(p.gait)), p.at[0], p.at[1], p.at[2], p.advance, p.travel, p.total, @floatFromInt(@intFromBool(p.wave)), @floatFromInt(@intFromBool(p.fires)), p.cooling, p.touch, p.read, p.carry, @floatFromInt(@intFromBool(p.carry_value)), p.pins[0], p.pins[1], p.follow, p.project };
+ return .{ @floatFromInt(@intFromEnum(p.gait)), p.at[0], p.at[1], p.at[2], p.advance, p.travel, p.total, @floatFromInt(@intFromBool(p.wave)), @floatFromInt(@intFromBool(p.fires)), p.cooling, p.touch, p.read, p.carry, @floatFromInt(@intFromBool(p.carry_value)), p.pins[0], p.pins[1], p.follow, p.project, p.result };
}
fn unpack(v: [values]f32) Plan {
@@ -154,6 +159,7 @@ pub const Plan = struct {
.pins = .{ v[14], v[15] },
.follow = v[16],
.project = v[17],
+ .result = v[18],
};
}
@@ -178,7 +184,11 @@ pub const quiet: u32 = blk: {
break :blk mask;
};
-/// rsp's and rbp's places in `Regs.names`.
+/// rax's, rsp's and rbp's places in `Regs.names`.
+pub const rax_index: u5 = blk: {
+ for (zt.Regs.names, 0..) |name, i| if (std.mem.eql(u8, name, "rax")) break :blk i;
+ unreachable;
+};
pub const sp_index: u5 = blk: {
for (zt.Regs.names, 0..) |name, i| if (std.mem.eql(u8, name, "rsp")) break :blk i;
unreachable;
@@ -523,6 +533,28 @@ pub const Cursor = struct {
c.step(s, to, plan, plan.total);
}
+ /// A call stepped over (design/motion.md, "A call stepped over"), from
+ /// the call's row to the row after it: fire; the arguments framed as read
+ /// (18 to 24, `Registers`, `Disasm`); still while it runs; rax armed and
+ /// struck at 48, the row's C form and result with it; the others it
+ /// changed in a wave from 66, 2 f apart; a hold of 36 f; the advance; a rest.
+ pub fn over(c: Cursor, s: *anim.Frame, to: u64) void {
+ const f = 1.0 / 60.0;
+ const from = c.moment(s);
+ var plan = c.timetable(from, to, true);
+ const changed = c.rec.registersChanged(from, to) & ~quiet;
+ const others: f32 = @floatFromInt(@popCount(changed & ~(@as(u32, 1) << rax_index)));
+ plan.at[0] = 48 * f;
+ plan.result = 66 * f;
+ const last = if (others > 0) plan.result + (others - 1) * time.continue_wave else plan.at[0];
+ // What it left in memory is not this beat's: its slot with the wave's end.
+ plan.at[1] = last;
+ plan.at[2] = last;
+ plan.advance = last + time.read_value;
+ plan.total = plan.advance + plan.travel + time.rest;
+ c.step(s, to, plan, plan.total);
+ }
+
fn timetable(c: Cursor, from: u64, to: u64, wave: bool) Plan {
if (c.levels.annotation == .tied and !wave) return c.tiedTable(from, to);
const rec = c.rec;
@@ -1280,7 +1312,7 @@ pub const Now = struct {
/// The mark of a register: the CPU's level. In a continue's wave, no arm and no pulse.
pub fn register(n: Now, reg: usize, delay: f32) ui.Heat {
var h = n.heat(n.registerAge(reg), n.registerAgeFrom(reg, 1), n.since(.cpu, delay));
- if (n.plan.wave) {
+ if (n.plan.wave and !(n.plan.result >= 0 and reg == rax_index)) {
h.arm = 0;
h.out = 0;
}