summaryrefslogtreecommitdiff
path: root/anim/scenes
diff options
context:
space:
mode:
Diffstat (limited to 'anim/scenes')
-rw-r--r--anim/scenes/intro.zig228
-rw-r--r--anim/scenes/intro_code.zig106
-rw-r--r--anim/scenes/intro_memory.zig52
-rw-r--r--anim/scenes/intro_registers.zig326
-rw-r--r--anim/scenes/intro_stack.zig252
5 files changed, 691 insertions, 273 deletions
diff --git a/anim/scenes/intro.zig b/anim/scenes/intro.zig
new file mode 100644
index 0000000..2289981
--- /dev/null
+++ b/anim/scenes/intro.zig
@@ -0,0 +1,228 @@
+//! The introduction (design/motion.md, "A scene: the introduction"): one
+//! scene, one video, four chapters on one recording (`intro`: list.c from
+//! main's push(9) to line 22) and one clock counted forward only, from the
+//! recording's first stop at line 40. Each chapter opens on the last
+//! picture of the one before, at a seam that says its title in the
+//! caption's place (`title`) and keeps its name as the clock's label:
+//! I Memory (`intro_memory.zig`), II Registers (`intro_registers.zig`),
+//! III The stack (`intro_stack.zig`), IV Code and meaning (`intro_code.zig`),
+//! each a function this scene calls in order.
+const std = @import("std");
+const anim = @import("anim");
+const sk = @import("sketch");
+const canim = @import("canim");
+const recordings = @import("recordings");
+const memory = @import("intro_memory.zig");
+const registers = @import("intro_registers.zig");
+const stack = @import("intro_stack.zig");
+const code = @import("intro_code.zig");
+
+pub const background = canim.background;
+pub const scene = anim.Live(frame, struct {});
+
+const t = canim.theme.time;
+
+/// The chapters' names, as the clock's label says them (`II registers`).
+const names = [_][]const u8{ "I memory", "II registers", "III the stack", "IV code and meaning" };
+
+fn frame(s: *anim.Frame) void {
+ const rec = canim.open(recordings.intro);
+ // The list's nodes are the chunks in use on glibc's heap (no agent told the allocations).
+ rec.allocationsFromHeap();
+ // list.c's types as the pass would tell them: the recording is of the
+ // plain build, which tells none (its locals are the debug info's).
+ rec.declare("head", "*`struct node`");
+ rec.declare("`struct node`", "struct(16){value@0:i64;next@8:*`struct node`;}");
+ const label: Label = .{ .which = s.value(0), .docked = s.value(0) };
+
+ // I: its title from nothing (in at 6 f, read, out), the chapter's first text 6 f after it.
+ s.cursor = f(6);
+ const first = say(s, "I", "Memory");
+ first.out(s);
+ const one = memory.chapter(s, rec);
+ const two_title = seam(s, one.e, &.{one.caption}, "II", "Registers", label, 1);
+ const two = registers.chapter(s, rec, one, two_title, label);
+ const three_title = seam(s, two.e, two.texts(s), "III", "The stack", label, 2);
+ const three = stack.chapter(s, rec, two, three_title);
+ const four_title = seam(s, three.e, three.texts(s), "IV", "Code and meaning", label, 3);
+ code.chapter(s, rec, three, four_title);
+
+ // The clock's label, over every clock, from the first frame (the scene's end is where the cursor is left).
+ const end = s.cursor;
+ s.cursor = 0;
+ const o = place(s, s.new(canim.ChapterLabel{ .names = &names, .which = label.which, .docked = label.docked, .widest = "moment 193 of 193" }));
+ s.play(.{o.fadeIn()}, .{ .seconds = 0 });
+ s.cursor = end;
+}
+
+/// The clock's label: which chapter (`ChapterLabel.which`), and whether the clock is there to stand beside.
+pub const Label = struct { which: anim.Value, docked: anim.Value };
+
+/// A chapter's title on screen, and when it has been read.
+pub const Title = struct {
+ obj: anim.Obj,
+ read_by: f32,
+
+ /// It leaves at its reading time or now, the later (12 f); the cursor
+ /// 6 f after: where the chapter's first text arrives.
+ pub fn out(ti: Title, s: *anim.Frame) void {
+ s.wait(@max(ti.read_by - s.cursor, 0));
+ s.play(.{ti.obj.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
+ s.wait(t.caption_gap);
+ }
+};
+
+/// A chapter's title said in the caption's place (18 f, rising 8); the cursor where it has landed.
+pub fn say(s: *anim.Frame, numeral: []const u8, name: []const u8) Title {
+ const o = canim.add(s, canim.Title{ .numeral = numeral, .name = name });
+ s.play(.{o.fadeIn()}, .{ .seconds = t.caption_in, .ease = canim.ease.enter });
+ return .{ .obj = o, .read_by = s.cursor + t.caption(@intCast(numeral.len + 2 + name.len)) };
+}
+
+/// A seam (design/README.md, `title`), from `e`, the frame the chapter
+/// before has its last text read: still 30 f; `going` (its texts) leave
+/// together (12 f); the title arrives (48 to 66, rising 8), the clock's
+/// label crossfading to the chapter's with it (54 to 66, secondary);
+/// still to 126, where the cursor is left: the next chapter's opening.
+pub fn seam(s: *anim.Frame, e: f32, going: []const anim.Obj, numeral: []const u8, name: []const u8, label: Label, chapter: f32) Title {
+ for (going) |o| {
+ s.cursor = e + f(30);
+ s.play(.{o.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
+ }
+ s.cursor = e + f(48);
+ const ti = say(s, numeral, name);
+ s.cursor = e + f(54);
+ s.play(.{label.which.to(chapter)}, .{ .seconds = f(12), .ease = anim.ease.linear });
+ s.cursor = e + f(126);
+ return ti;
+}
+
+pub fn f(frames: f32) f32 {
+ return frames / 60;
+}
+
+/// Clock `v` from 0 to `frames`, linear, from the cursor; the cursor after it.
+pub fn run(s: *anim.Frame, v: anim.Value, frames: f32) void {
+ s.play(.{v.to(0)}, .{ .seconds = 0 });
+ s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
+}
+
+/// The same, the cursor left where it was.
+pub fn start(s: *anim.Frame, v: anim.Value, frames: f32) void {
+ const at = s.cursor;
+ run(s, v, frames);
+ s.cursor = at;
+}
+
+/// `v` to `to` over `frames`, linear, the cursor left where it was.
+pub fn to(s: *anim.Frame, v: anim.Value, value: f32, frames: f32) void {
+ const at = s.cursor;
+ s.play(.{v.to(value)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
+ s.cursor = at;
+}
+
+/// A value at once, from the cursor.
+pub fn set(s: *anim.Frame, v: anim.Value, value: f32) void {
+ s.play(.{v.to(value)}, .{ .seconds = 0 });
+}
+
+pub fn place(s: *anim.Frame, data: anytype) anim.Obj {
+ return s.custom(data, .{ .x = -640, .y = -360, .scale = canim.ui.scale });
+}
+
+/// The page over a part of a panel the beat has not reached: lifted (its fade out) as the beat says it.
+pub const Cover = struct {
+ box: canim.Rect,
+ pub fn draw(c: *const Cover, fr: *sk.Frame, placed: anim.Placed) void {
+ (canim.ui.Ui{ .f = fr, .at = placed }).fill(c.box, canim.theme.color.page);
+ }
+};
+
+/// A value framed as read (6 f in with its object's fade).
+pub const Read = struct {
+ box: canim.Rect,
+ pub fn draw(r: *const Read, fr: *sk.Frame, placed: anim.Placed) void {
+ (canim.ui.Ui{ .f = fr, .at = placed }).read(r.box, 1);
+ }
+};
+
+/// A part of a disassembly row framed as read on a beat (an echo): the row
+/// of `addr` where the panel says it is this frame, from `x` (from the
+/// panel's left: the address 40, the operands 264, `disasm.zig`'s columns)
+/// `w` wide, `shows` of it.
+pub const RowRead = struct {
+ addr: u64,
+ x: f32,
+ w: f32,
+ shows: anim.Value,
+ pub fn draw(r: *const RowRead, fr: *sk.Frame, placed: anim.Placed) void {
+ const shows = std.math.clamp(placed.value(r.shows), 0, 1);
+ if (shows <= 0) return;
+ const px = canim.findPlace(fr, .{ .row = r.addr }) orelse return;
+ const u = canim.fixed(fr, placed, 0);
+ // Canvas pixels to the design's units (the camera is home: the frame fitted into the canvas).
+ const w = @max(@floor(fr.in.window_width), 1);
+ const h = @max(@floor(fr.in.window_height), 1);
+ const k = @min(w / canim.theme.canvas.width, h / canim.theme.canvas.height);
+ const left = (px[0] - w / 2) / k + canim.theme.canvas.width / 2.0;
+ const top = (px[1] - h / 2) / k + canim.theme.canvas.height / 2.0;
+ u.read(.{ .x = left + r.x, .y = top, .w = r.w, .h = canim.theme.metric.context.row }, shows);
+ }
+};
+
+pub fn cover(s: *anim.Frame, box: canim.Rect) anim.Obj {
+ const o = place(s, s.new(Cover{ .box = box }));
+ s.play(.{o.fadeIn()}, .{ .seconds = 0 });
+ return o;
+}
+
+/// Every one of `objs` there at once, from the cursor (a panel and the page over what it has not said yet).
+pub fn show(s: *anim.Frame, objs: []const ?anim.Obj) void {
+ const at = s.cursor;
+ for (objs) |o| if (o) |obj| {
+ s.cursor = at;
+ s.play(.{obj.fadeIn()}, .{ .seconds = 0 });
+ };
+ s.cursor = at;
+}
+
+/// A panel's tag and rules under the page, for `frame up`: its tag, its left, right and bottom rules, and its strip.
+pub fn chrome(s: *anim.Frame, b: canim.Rect, strip: bool) [5]?anim.Obj {
+ const w = canim.theme.stroke.rule;
+ const tag = canim.theme.metric.context.tag;
+ return .{
+ cover(s, .{ .x = b.x, .y = b.y, .w = b.w, .h = tag }),
+ cover(s, .{ .x = b.x, .y = b.y + tag, .w = w, .h = b.h - tag }),
+ cover(s, .{ .x = b.x + b.w - w, .y = b.y + tag, .w = w, .h = b.h - tag }),
+ cover(s, .{ .x = b.x, .y = b.y + b.h - w, .w = b.w, .h = w }),
+ if (strip) cover(s, .{ .x = b.x + b.w - canim.theme.strip.cost, .y = b.y + tag, .w = canim.theme.strip.cost - w, .h = b.h - tag - w }) else null,
+ };
+}
+
+/// Lifts `covers` one after another, `apart` frames apart, `each` frames each, from the cursor; the cursor after the last.
+pub fn lift(s: *anim.Frame, covers: []const ?anim.Obj, apart: f32, each: f32) void {
+ const at = s.cursor;
+ var end = at;
+ for (covers, 0..) |o, i| if (o) |obj| {
+ s.cursor = at + f(apart * @as(f32, @floatFromInt(i)));
+ s.play(.{obj.fadeOut()}, .{ .seconds = f(each), .ease = anim.ease.linear });
+ end = s.cursor;
+ };
+ s.cursor = end;
+}
+
+/// The first moment from `from` at an instruction whose text has `text` in it.
+pub fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 {
+ var buf: [256]u8 = undefined;
+ var i = from;
+ while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.indexOf(u8, here.text, text) != null) return i;
+ return from;
+}
+
+/// A clock counting the recording from its first stop at line 40 (`moment 6 of 193`), on `cursor`'s steps, in `ctx`'s frame.
+pub fn clock(s: *anim.Frame, rec: *canim.Recording, cursor: canim.Cursor, ctx: canim.Context) anim.Obj {
+ var counts = cursor;
+ counts.first = rec.lineMoment(40, 0);
+ counts.last = rec.end();
+ return canim.add(s, canim.Clock{ .cursor = counts, .map = ctx.map, .stage = ctx.stage });
+}
diff --git a/anim/scenes/intro_code.zig b/anim/scenes/intro_code.zig
index eb66554..7682842 100644
--- a/anim/scenes/intro_code.zig
+++ b/anim/scenes/intro_code.zig
@@ -1,44 +1,30 @@
-//! The introduction, chapter III: code and meaning (design/motion.md, "A
-//! scene: the introduction", III1 to III5; mocks 32, 33, 36). On the
+//! The introduction, chapter IV: code and meaning (design/motion.md, "A
+//! scene: the introduction", IV1 to IV5; mocks 32, 33, 36), a function the
+//! scene `intro` calls after III's seam. On the
//! `intro` recording at the load in `reverse` (line 21, `node *next =
//! cur->next;`, the instruction that reads `cur->next`): the code's bytes
//! as a dump row, that instruction's four framed; `decode`d into its row
//! of `aligned` (`interleaved`), its neighbours at a run, each line level
//! with its run; then `align` to `columns`; then the working frame with the
//! nodes drawn from the heap's bytes, each pane's minimap drawing itself
-//! last; then the map (`surface`). It opens on chapter II's last picture,
-//! its state column staying veiled until the decoded code spans it. The
+//! last; then the map (`surface`). It opens on chapter III's last picture,
+//! its state column staying veiled until the decoded code spans it, and
+//! the one clock steps on to the load as the working frame assembles. The
//! texts `above` the aligned panel, then below the working frame, the
//! last landing before the map surfaces under it.
const std = @import("std");
const anim = @import("anim");
const sk = @import("sketch");
const canim = @import("canim");
-const recordings = @import("recordings");
-const two = @import("intro_stack.zig");
-
-pub const background = canim.background;
-pub const scene = anim.Live(frame, struct {});
+const intro = @import("intro.zig");
+const stack = @import("intro_stack.zig");
const t = canim.theme.time;
+const f = intro.f;
+const run = intro.run;
+const on = intro.on;
-fn f(frames: f32) f32 {
- return frames / 60;
-}
-
-fn run(s: *anim.Frame, v: anim.Value, frames: f32) void {
- s.play(.{v.to(0)}, .{ .seconds = 0 });
- s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
-}
-
-fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 {
- var buf: [256]u8 = undefined;
- var i = from;
- while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.indexOf(u8, here.text, text) != null) return i;
- return from;
-}
-
-/// The page over a part not drawn yet (a pane's minimap until III4).
+/// The page over a part not drawn yet (a pane's minimap until IV4).
const Page = struct {
box: canim.Rect,
pub fn draw(c: *const Page, fr: *sk.Frame, placed: anim.Placed) void {
@@ -46,46 +32,11 @@ const Page = struct {
}
};
-/// Chapter II's last picture (scenes/intro_stack.zig, its layout and texts
-/// as there): its registers and stack, a context of their own at II's last
-/// moment, the window held as II holds it; main's rows, faint, and reverse's
-/// first rows under them; II4's text dimmed and II5's.
-fn lastOfTwo(s: *anim.Frame, rec: *canim.Recording) struct { state: [2]anim.Obj, code: [2]anim.Obj, texts: [2]anim.Obj } {
- const enter = rec.call("reverse", 0).enter;
- const last = enter + 3;
- var at = canim.cursor(s, rec, enter);
- at.journey(.moment, last);
- at.levels = .{ .fire = .disasm, .source_rows = 14, .introduction = true };
- // As II walked it: its push, `mov` and `sub` the steps behind its last moment.
- at.jumpWalked(s, enter, last);
- var split = canim.layout.split.none;
- split.backtrace.h = 0;
- const ctx = canim.context(s, at, .{ .split = split });
- const g = two.layout(ctx.stage, rec, enter);
- two.hold(s, ctx.stage, enter);
- const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage });
- // (Placed at the origin: it draws at its own box.)
- const caller = s.custom(s.new(canim.descent.Caller{ .rec = rec, .at = enter, .call = rec.register(enter - 1, "rip"), .box = g.caller, .in = s.value(999), .faint = s.value(1) }), .{ .x = -640, .y = -360, .scale = canim.ui.scale });
- const left = canim.theme.canvas.margin_x;
- const said = [2]canim.Aside{
- .{ .text = two.texts[two.texts.len - 2], .x = left, .level = g.span_y, .dim = s.value(1) },
- .{ .text = two.texts[two.texts.len - 1], .x = left, .level = g.registers_y, .dim = s.value(0) },
- };
- var texts: [2]anim.Obj = undefined;
- for (said, &texts) |a, *o| o.* = s.custom(s.new(a), .{ .x = -640, .y = -360, .scale = canim.ui.scale });
- for ([_]anim.Obj{ ctx.registers, stack, caller, ctx.disasm, texts[0], texts[1] }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 });
- return .{ .state = .{ ctx.registers, stack }, .code = .{ caller, ctx.disasm }, .texts = texts };
-}
-
/// The variables whose tags the nodes carry, as the list scene's.
const tracked = [_][]const u8{ "prev", "cur", "next", "head" };
-fn frame(s: *anim.Frame) void {
- const rec = canim.open(recordings.intro);
- // list.c's types as the pass would tell them: the recording is of the
- // plain build, which tells none (its locals are the debug info's).
- rec.declare("head", "*`struct node`");
- rec.declare("`struct node`", "struct(16){value@0:i64;next@8:*`struct node`;}");
+/// From the seam's opening (the cursor), on chapter III's last picture.
+pub fn chapter(s: *anim.Frame, rec: *canim.Recording, three: stack.Three, title: intro.Title) void {
const reverse = rec.call("reverse", 0);
// The load: `cur->next` read, line 21's second instruction.
const moment = on(rec, rec.lineMoment(21, reverse.enter), "[rax + 8]");
@@ -100,9 +51,8 @@ fn frame(s: *anim.Frame) void {
for (code[0..insn.len], 0..) |b, k| hex.print(s.arena, "{s}{x:0>2}", .{ if (k > 0) " " else "", b }) catch {};
const text = std.mem.replaceOwned(u8, s.arena, insn.text, "qword ptr ", "") catch insn.text;
- // Chapter II's last picture, which this chapter opens on (II's own
- // context at II's last moment, laid out as II has it, under this one's).
- const opening = lastOfTwo(s, rec);
+ const opening = three;
+ const begun = s.cursor;
var at = canim.cursor(s, rec, moment);
at.journey(.moment, moment + 1);
@@ -110,6 +60,8 @@ fn frame(s: *anim.Frame) void {
const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject });
const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked, .named = true });
ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked, .named = true });
+ // The one clock (II's and III's cursor), over this context's map: it takes the old one's place at once, the same picture.
+ const clock = intro.clock(s, rec, opening.at, ctx);
// The relations, and rax's link to the node as III3 names it.
const joins, const rax_link = ctx.tiesWith(s, "rax", 1.0);
@@ -122,19 +74,18 @@ fn frame(s: *anim.Frame) void {
const al = s.new(canim.Aligned.init(s, rec, moment));
const panel = s.custom(al, .{ .x = -640, .y = -360, .scale = canim.ui.scale });
+ s.cursor = begun;
s.play(.{panel.fadeIn()}, .{ .seconds = 0 });
// Texts above the panel that spans both columns: twice a beside's line (two lines in the band of 120).
var asides: canim.Asides = .{ .wrap = 2 * 40 };
const left = canim.theme.canvas.margin_x;
const above = canim.theme.canvas.stage.y + 40;
- // From II's last picture: its texts and code give way (12 f, 18 f); its
- // state column stays, veiled at 50%, until the decoded code takes both columns.
- s.wait(t.beat);
- s.play(.{ opening.texts[0].fadeOut(), opening.texts[1].fadeOut() }, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
- s.cursor -= t.caption_out;
- s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear });
- s.wait(t.beat);
+ // The opening, from III's last picture (its texts gone at the seam): its code gives
+ // way (18 f); its state column stays, veiled at 50%, until the decoded code takes both
+ // columns; the clock and its label stay, under the stage.
+ s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.code[2].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear });
+ title.out(s);
// III1: the code's bytes, one instruction's framed.
asides.say(s, std.fmt.allocPrint(s.arena, "Code is bytes too: `{s}` is one instruction.", .{hex.items}) catch "", left, above);
@@ -171,7 +122,14 @@ fn frame(s: *anim.Frame) void {
s.play(.{ strips[0].fadeIn(), strips[1].fadeIn(), strips[2].fadeIn(), strips[3].fadeIn() }, .{ .seconds = 0 });
s.play(.{ ctx.source.fadeIn(), ctx.disasm.fadeIn(), panel.fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear });
var says: canim.Narrator = .{};
- canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, joins });
+ // The one clock goes on, forward, to IV's moment: the chapters before's cursor taken
+ // there (its panels gone), the count changing and its gold fading in as a step's (12 f).
+ const later: canim.Plan = .{ .advance = 0, .travel = 0, .total = t.quick };
+ const counted = s.cursor;
+ s.play(.{ opening.clock.fadeOut(), clock.fadeIn() }, .{ .seconds = 0 });
+ opening.at.step(s, moment, later, later.total);
+ s.cursor = counted;
+ canim.establish(s, .{ ctx.registers, ctx.stack, joins });
// III3: the node it reads, as bytes and drawn: the band comes in, its
// elements rising from their bytes. No camera: at x1.5 the drawing's
// nodes and its bytes do not both fit the frame, and the band is whole at x1.
diff --git a/anim/scenes/intro_memory.zig b/anim/scenes/intro_memory.zig
index 2dfda5e..7b25098 100644
--- a/anim/scenes/intro_memory.zig
+++ b/anim/scenes/intro_memory.zig
@@ -1,5 +1,6 @@
//! The introduction, chapter I: memory (design/motion.md, "A scene: the
-//! introduction", I1 to I10; mocks 29, 30, 34, 37). The frame built from
+//! introduction", I1 to I10; mocks 29, 30, 34, 37), a function the scene
+//! `intro` calls after its title (`chapter`). The frame built from
//! its bytes up, on the `intro` recording (the list program from main's
//! call of `reverse`) at reverse's first instruction, its `push rbp` (the
//! push chapter II walks; rsp holds the way back to main), each part in
@@ -13,33 +14,27 @@
const std = @import("std");
const anim = @import("anim");
const canim = @import("canim");
-const recordings = @import("recordings");
-
-pub const background = canim.background;
-pub const scene = anim.Live(frame, struct {});
+const intro = @import("intro.zig");
const t = canim.theme.time;
+const f = intro.f;
+const run = intro.run;
+const start = intro.start;
-fn f(frames: f32) f32 {
- return frames / 60;
-}
+/// The chapter's last picture, which chapter II opens on: the address
+/// space, the 128 bytes and their place's tie (each an object of its
+/// own), the last text, and `e`, the frame it has been read by.
+pub const One = struct {
+ space: *canim.Segments,
+ dump: *canim.Words,
+ objs: [3]anim.Obj,
+ caption: anim.Obj,
+ e: f32,
+};
-/// Clock `v` from 0 to `frames`, linear, from the cursor; the cursor after it.
-fn run(s: *anim.Frame, v: anim.Value, frames: f32) void {
- s.play(.{v.to(0)}, .{ .seconds = 0 });
- s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
-}
-
-/// The same, the cursor left where it was.
-fn start(s: *anim.Frame, v: anim.Value, frames: f32) void {
- const at = s.cursor;
- run(s, v, frames);
- s.cursor = at;
-}
-
-fn frame(s: *anim.Frame) void {
- const rec = canim.open(recordings.intro);
- // reverse's first instruction (its call's first moment): its `push rbp`, which chapter II walks.
+/// From the cursor, where its first text arrives.
+pub fn chapter(s: *anim.Frame, rec: *canim.Recording) One {
+ // reverse's first instruction (its call's first moment): its `push rbp`, which chapter III walks.
const moment = rec.call("reverse", 0).enter;
const ui = canim.ui;
const at = canim.regroup.at;
@@ -62,7 +57,7 @@ fn frame(s: *anim.Frame) void {
}
space.n_echoes = order.len;
- const objs = .{ s.custom(space, .{ .x = -640, .y = -360, .scale = ui.scale }), s.custom(dump, .{ .x = -640, .y = -360, .scale = ui.scale }), s.custom(place, .{ .x = -640, .y = -360, .scale = ui.scale }) };
+ const objs = [3]anim.Obj{ s.custom(space, .{ .x = -640, .y = -360, .scale = ui.scale }), s.custom(dump, .{ .x = -640, .y = -360, .scale = ui.scale }), s.custom(place, .{ .x = -640, .y = -360, .scale = ui.scale }) };
inline for (objs) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 });
// The camera at x2 on the dump from the first frame (I1 to I3), with the
@@ -78,7 +73,6 @@ fn frame(s: *anim.Frame) void {
// I1: the bytes, a row at a time (18 f apart), a text's lead (60 f) after it lands, not
// the first's 120: little "here" over an empty stage, and they come while it is read.
- s.wait(1.0);
const said_at = s.cursor;
says.line(s, "A running program is bytes in memory:\nhere are 128 of them.");
const lead_end = s.cursor;
@@ -182,8 +176,8 @@ fn frame(s: *anim.Frame) void {
says.line(s, "Follow an address and you reach another word: a chain.\n`→` points to a word, `←` holds a value.");
run(s, dump.left, 24);
run(s, dump.chains, 36 * 2 + 30);
- s.wait(t.beat);
- // The chapter's last picture.
- says.close(s);
+ // The chapter's last picture, held until its text is read: then the seam.
+ s.wait(@max(says.read_by - s.cursor, 0));
cam.apply(s);
+ return .{ .space = space, .dump = dump, .objs = objs, .caption = says.current.?, .e = s.cursor };
}
diff --git a/anim/scenes/intro_registers.zig b/anim/scenes/intro_registers.zig
new file mode 100644
index 0000000..326bcd0
--- /dev/null
+++ b/anim/scenes/intro_registers.zig
@@ -0,0 +1,326 @@
+//! The introduction, chapter II: registers (design/motion.md, "A scene: the
+//! introduction", II1 to II8; mocks 58 to 61), opening on chapter I's last
+//! picture at its seam (mock 62). The recording begins before I's moment:
+//! push(9) at line 11, its `mov edi, 0x10` and its `call malloc@plt`, then
+//! on to reverse's first instruction, where I's 128 bytes were read. The
+//! 128 bytes fold to the shelf while II's moments run, and come back as I
+//! left them once II reaches that instruction.
+//!
+//! II1 to II3 in the working frame with the text below, the address space
+//! in the program column: the registers built a row at a time, every
+//! register a row; rip, `frame up` and the clock; the stack's and the
+//! heap's registers, `segments` live (`◂ rip`, rbp and rsp in the stack's
+//! band). II4 to II8 beside, on the left, over push's rows at the program
+//! column's foot (no panel round them until III's `frame up`): rip and the
+//! row; rdi opened into its parts around `mov edi, 0x10` (`unpack`, the
+//! step, `pack`); `call malloc@plt` stepped over (its result first, then
+//! the wave); a continue to reverse; the quiet registers `fold`ed and the
+//! 128 bytes back at the rows III's stack will give them.
+const std = @import("std");
+const anim = @import("anim");
+const canim = @import("canim");
+const intro = @import("intro.zig");
+const memory = @import("intro_memory.zig");
+
+const t = canim.theme.time;
+const row = canim.theme.metric.context.row;
+const f = intro.f;
+const run = intro.run;
+const to = intro.to;
+const set = intro.set;
+const place = intro.place;
+const cover = intro.cover;
+const lift = intro.lift;
+
+/// The chapter's last picture, which chapter III opens on, and what III goes on with.
+pub const Two = struct {
+ ctx: canim.Context,
+ at: canim.Cursor,
+ registers: anim.Obj,
+ disasm: anim.Obj,
+ clock: anim.Obj,
+ /// The disassembly's tag, rules and strip, under the page until III's `frame up`.
+ disasm_chrome: [5]?anim.Obj,
+ dump: *canim.Words,
+ dump_obj: anim.Obj,
+ asides: canim.Asides,
+ e: f32,
+
+ /// The texts standing at its end.
+ pub fn texts(two: *const Two, s: *anim.Frame) []const anim.Obj {
+ return standing(s, &two.asides);
+ }
+};
+
+/// The texts `asides` has standing.
+pub fn standing(s: *anim.Frame, asides: *const canim.Asides) []const anim.Obj {
+ var out: std.ArrayList(anim.Obj) = .empty;
+ for (asides.shown[0..asides.n]) |o| if (o) |obj| out.append(s.arena, obj) catch {};
+ return out.items;
+}
+
+/// A register's place in the recording's registers, a bit each.
+fn bit(name: []const u8) u32 {
+ for (canim.ztrace.Regs.names, 0..) |known, i| if (std.mem.eql(u8, known, name)) return @as(u32, 1) << @intCast(i);
+ unreachable;
+}
+
+/// Row `k` of the registers panel (pwndbg's order, rip the 17th): its top.
+fn rowY(box: canim.Rect, k: f32) f32 {
+ return box.y + canim.theme.metric.context.tag + canim.theme.metric.context.pad + row * k;
+}
+
+/// From the seam's opening (the cursor), `e` the frame I's last text was read.
+pub fn chapter(s: *anim.Frame, rec: *canim.Recording, one: memory.One, title: intro.Title, label: intro.Label) Two {
+ const e = one.e;
+ // The moments: push(9)'s `mov edi, 0x10`, its call of malloc, the row after it, reverse's first instruction.
+ const push = rec.call("push", 0);
+ const start = intro.on(rec, push.enter, "edi, 0x10");
+ const call = start + 1;
+ const call_at = rec.register(call, "rip");
+ var back = call + 1;
+ while (back < rec.end() and rec.register(back, "rip") != call_at + 5) back += 1;
+ const reverse = rec.call("reverse", 0).enter;
+
+ // One set of registers for the four chapters: those II's steps change, with rsp, rbp and rip.
+ var moves: u32 = bit("rsp") | bit("rbp") | bit("rip");
+ for ([_][2]u64{ .{ start, call }, .{ call, back }, .{ back, reverse }, .{ reverse, reverse + 3 } }) |w| moves |= rec.registersChanged(w[0], w[1]);
+ moves &= (1 << 17) - 1;
+
+ var at = canim.cursor(s, rec, start);
+ at.journey(.moment, reverse + 3);
+ at.levels = .{ .fire = .disasm, .source_rows = 14, .introduction = true };
+ var split = canim.layout.split.none;
+ split.backtrace.h = 0;
+ const ctx = canim.context(s, at, .{ .split = split, .moves = moves });
+ // The code at the program column's foot: six rows, 712 to 888 (its rows 740 to 884).
+ const program = canim.theme.layout.program;
+ ctx.stage.first.disasm = .{ .x = program.x, .y = canim.theme.canvas.stage.y + canim.theme.canvas.stage.h - canim.layout.panelH(6), .w = program.w, .h = canim.layout.panelH(6) };
+
+ // The registers: every register a row, folded on II8; rdi opened into its parts on II5;
+ // rip, rbp, rsp, rax, rcx, rsi and rdi framed as read on their beats.
+ const fold = s.value(0);
+ const parts = s.new(canim.Registers.Parts{ .name = "rdi", .unpack = s.value(-1), .pack = s.value(-1), .echo = s.value(0) });
+ const framed_names = [_][]const u8{ "rip", "rbp", "rsp", "rax", "rcx", "rsi", "rdi" };
+ const framed = s.arena.alloc(canim.Registers.Framed, framed_names.len) catch unreachable;
+ for (framed, framed_names) |*fr, name| fr.* = .{ .name = name, .shows = s.value(0) };
+ const shows = struct {
+ fn of(all: []const canim.Registers.Framed, name: []const u8) anim.Value {
+ for (all) |fr| if (std.mem.eql(u8, fr.name, name)) return fr.shows;
+ unreachable;
+ }
+ }.of;
+ const registers = canim.add(s, canim.Registers{ .cursor = ctx.cursor, .stage = ctx.stage, .moves = moves, .fold = fold, .parts = parts, .framed = framed });
+ const mark_in = s.value(0);
+ const disasm = canim.add(s, canim.Disasm{ .cursor = ctx.cursor, .stage = ctx.stage, .mark_in = mark_in });
+ const clock = intro.clock(s, rec, ctx.cursor, ctx);
+ // The 128 bytes, over the registers from here (their tag crosses the panel when they come back).
+ const dump = one.dump;
+ const dump_obj = place(s, dump);
+
+ // What the beats have not reached, under the page: each register's name and its chain,
+ // rip's row, the panel's chrome; there with the panel, once the 128 bytes have left
+ // the state column (216), as the code's are with its rows (II's way into the code).
+ const opening = s.cursor;
+ s.cursor = e + f(216);
+ const rb = ctx.stage.first.registers;
+ var names: [16]?anim.Obj = undefined;
+ var chains: [16]?anim.Obj = undefined;
+ const name_w: f32 = 58;
+ for (0..16) |k| {
+ const y = rowY(rb, @floatFromInt(k));
+ names[k] = cover(s, .{ .x = rb.x + 2, .y = y, .w = name_w, .h = row });
+ chains[k] = cover(s, .{ .x = rb.x + 2 + name_w, .y = y, .w = rb.w - 4 - name_w, .h = row });
+ }
+ const rip_row = cover(s, .{ .x = rb.x + 2, .y = rowY(rb, 16), .w = rb.w - 4, .h = row });
+ const tall: canim.Rect = .{ .x = rb.x, .y = rb.y, .w = rb.w, .h = canim.layout.panelH(17) };
+ const regs_chrome = intro.chrome(s, tall, false);
+ s.play(.{registers.fadeIn()}, .{ .seconds = 0 });
+ s.cursor = opening;
+ const db = ctx.stage.first.disasm;
+ var code_rows: [6]?anim.Obj = undefined;
+ for (&code_rows, 0..) |*o, k| o.* = place(s, s.new(intro.Cover{ .box = .{ .x = db.x + 2, .y = db.y + canim.theme.metric.context.tag + canim.theme.metric.context.pad + row * @as(f32, @floatFromInt(k)), .w = db.w - 4, .h = row } }));
+ var disasm_chrome: [5]?anim.Obj = undefined;
+ for (&disasm_chrome, [_]canim.Rect{
+ .{ .x = db.x, .y = db.y, .w = db.w, .h = canim.theme.metric.context.tag },
+ .{ .x = db.x, .y = db.y + canim.theme.metric.context.tag, .w = canim.theme.stroke.rule, .h = db.h - canim.theme.metric.context.tag },
+ .{ .x = db.x + db.w - canim.theme.stroke.rule, .y = db.y + canim.theme.metric.context.tag, .w = canim.theme.stroke.rule, .h = db.h - canim.theme.metric.context.tag },
+ .{ .x = db.x, .y = db.y + db.h - canim.theme.stroke.rule, .w = db.w, .h = canim.theme.stroke.rule },
+ .{ .x = db.x + db.w - canim.theme.strip.cost, .y = db.y + canim.theme.metric.context.tag, .w = canim.theme.strip.cost - canim.theme.stroke.rule, .h = db.h - canim.theme.metric.context.tag - canim.theme.stroke.rule },
+ }) |*o, box| o.* = place(s, s.new(intro.Cover{ .box = box }));
+ // Echoes on the code: the pc's row's address (II4), the operand `edi` (II5).
+ const pc_shows = s.value(0);
+ const operand_shows = s.value(0);
+ const pc_read = place(s, s.new(intro.RowRead{ .addr = rec.register(start, "rip"), .x = 40, .w = 6 * 12, .shows = pc_shows }));
+ const operand_read = place(s, s.new(intro.RowRead{ .addr = rec.register(start, "rip"), .x = 264, .w = 3 * 12, .shows = operand_shows }));
+ const space = one.space;
+ space.pins = .{ .rip = s.value(0), .stack = s.value(0) };
+ const echo = struct {
+ fn add(sp: *canim.Segments, sf: *anim.Frame, addr: u64) anim.Value {
+ sp.echoes[sp.n_echoes] = .{ .addr = addr, .shows = sf.value(0) };
+ sp.n_echoes += 1;
+ return sp.echoes[sp.n_echoes - 1].shows;
+ }
+ }.add;
+ const code_echo = echo(space, s, rec.register(start, "rip"));
+ const stack_echo = echo(space, s, rec.register(start, "rsp"));
+ const heap_names = [_][]const u8{ "rax", "rcx", "rsi" };
+ var heap_echoes: [3]anim.Value = undefined;
+ for (&heap_echoes, heap_names) |*h, name| h.* = echo(space, s, rec.register(start, name));
+
+ inline for (.{ pc_read, operand_read }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 });
+ s.cursor = opening;
+ // The opening (126 to 216): the dump's tie and link fade (18 f); its header comes
+ // back over its rows (12 f); the rows glide up into it, it becomes the tag, and
+ // the tag goes to the shelf over the program column (48 f): the bytes wait there,
+ // folded, while the chapter's moments run, which come before I's.
+ s.play(.{ one.objs[1].fadeOut(), dump_obj.fadeIn() }, .{ .seconds = 0 });
+ s.play(.{one.objs[2].fadeOut()}, .{ .seconds = f(18), .ease = anim.ease.linear });
+ s.play(.{dump.back.to(1)}, .{ .seconds = f(12), .ease = anim.ease.linear });
+ s.cursor = e + f(168);
+ run(s, dump.fold, 48);
+ title.out(s);
+
+ var says: canim.Narrator = .{};
+ const left = canim.theme.canvas.margin_x;
+
+ // II1: every register a row, top down, the name and then the chain (12 f each, 14 f apart).
+ const said = s.cursor;
+ says.line(s, "The CPU keeps sixteen words of its own, named, not addressed: the registers.");
+ s.cursor = said + t.caption_in + t.caption_lead;
+ const rows_from = s.cursor;
+ for (0..16) |k| {
+ s.cursor = rows_from + f(14 * @as(f32, @floatFromInt(k)));
+ lift(s, &.{names[k]}, 0, 12);
+ s.cursor = rows_from + f(14 * @as(f32, @floatFromInt(k)) + 6);
+ lift(s, &.{chains[k]}, 0, 12);
+ }
+
+ // II2: rip's row, its value framed, list's code band and its row framed and `◂ rip`;
+ // `frame up` on the registers; the clock comes, and the label goes beside it.
+ says.line(s, "And `rip`: where the CPU is, an address in list's code.");
+ lift(s, &.{rip_row}, 0, 12);
+ to(s, shows(framed, "rip"), 1, 6);
+ s.wait(f(24));
+ to(s, code_echo, 1, 6);
+ to(s, space.pins.?.rip, 1, 12);
+ s.wait(f(72));
+ to(s, shows(framed, "rip"), 0, 18);
+ to(s, code_echo, 0, 18);
+ s.wait(f(18));
+ lift(s, regs_chrome[1..4], 0, 12);
+ lift(s, &.{regs_chrome[0]}, 0, 12);
+ // The label leaves where it stood alone (12 f), then comes beside the count as the clock comes (12 f).
+ s.play(.{label.docked.to(1)}, .{ .seconds = f(24), .ease = anim.ease.linear });
+ s.cursor -= f(12);
+ s.play(.{clock.fadeIn()}, .{ .seconds = f(12), .ease = anim.ease.linear });
+
+ // II3: rbp and rsp framed, the stack's band and its row, their pin in it; held;
+ // then rax, rcx and rsi at a run, each framed with the heap's band.
+ says.line(s, "`rsp` and `rbp` point into the stack,\n`rax`, `rcx` and `rsi` into the heap.");
+ to(s, shows(framed, "rbp"), 1, 6);
+ s.wait(f(6));
+ to(s, shows(framed, "rsp"), 1, 6);
+ s.wait(f(18));
+ to(s, stack_echo, 1, 6);
+ to(s, space.pins.?.stack, 1, 12);
+ s.wait(f(102));
+ for ([_][]const u8{ "rbp", "rsp" }) |name| to(s, shows(framed, name), 0, 18);
+ to(s, stack_echo, 0, 18);
+ s.wait(f(24));
+ const heaps = s.cursor;
+ for (heap_names, heap_echoes, 0..) |name, h, k| {
+ s.cursor = heaps + f(2 * @as(f32, @floatFromInt(k)));
+ to(s, shows(framed, name), 1, 4);
+ to(s, h, 1, 4);
+ s.wait(f(4));
+ to(s, shows(framed, name), 0, 8);
+ to(s, h, 0, 8);
+ }
+ s.cursor = heaps + f(2 * 2 + 12);
+
+ // Into the code: the text leaves; the address space goes with its pins; push's six rows
+ // round the pc arrive at the program column's foot (12 f each, 2 f apart), no panel round them.
+ s.wait(@max(says.read_by - s.cursor, 0));
+ s.play(.{says.current.?.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
+ s.wait(f(6));
+ s.play(.{one.objs[0].fadeOut()}, .{ .seconds = f(18), .ease = anim.ease.linear });
+ s.wait(f(6));
+ s.play(.{disasm.fadeIn()}, .{ .seconds = 0 });
+ intro.show(s, &code_rows);
+ intro.show(s, &disasm_chrome);
+ lift(s, &code_rows, 2, 12);
+
+ var asides: canim.Asides = .{ .floor = ctx.stage.first.disasm.y - 12 };
+ const level = struct {
+ /// Level with row `k` of the registers (`room` rows lower for an opened register's parts), under the shelf.
+ fn of(box: canim.Rect, k: f32) f32 {
+ return @max(rowY(box, k) + row / 2, 124);
+ }
+ }.of;
+
+ // II4: the pc's mark comes to its row; rip's value and the row's address framed together.
+ asides.say(s, "`rip` holds this row's address: the next to run, in push(9).", left, level(rb, 16));
+ // (Eased: its first frame barely there, as the mark's own in is.)
+ s.play(.{mark_in.to(1)}, .{ .seconds = f(12), .ease = canim.ease.glide });
+ to(s, shows(framed, "rip"), 1, 6);
+ to(s, pc_shows, 1, 6);
+ s.wait(f(102));
+ to(s, shows(framed, "rip"), 0, 18);
+ to(s, pc_shows, 0, 18);
+
+ // II5: rdi framed (push's argument); `unpack`; `mov edi, 0x10` walked, the byte that changes
+ // struck with the row's annotation; `pack`.
+ asides.say(s, "`rdi` holds push's argument, 9. Its low four bytes are `edi`, as `eax` are `rax`'s.", left, level(rb, 5));
+ to(s, shows(framed, "rdi"), 1, 6);
+ s.wait(f(12));
+ to(s, shows(framed, "rdi"), 0, 12);
+ run(s, parts.unpack, 54);
+ s.wait(f(24));
+ var plan = at.planned(start, call, false);
+ plan.at[0] = f(36);
+ plan.advance = f(72);
+ plan.total = plan.advance + plan.travel + t.rest;
+ const stepped = s.cursor;
+ at.step(s, call, plan, plan.total);
+ const after_step = s.cursor;
+ s.cursor = stepped + f(18);
+ to(s, parts.echo, 1, 6);
+ to(s, operand_shows, 1, 6);
+ s.cursor = stepped + plan.advance;
+ to(s, parts.echo, 0, 12);
+ to(s, operand_shows, 0, 12);
+ s.cursor = stepped + f(102);
+ run(s, parts.pack, 36);
+ s.cursor = @max(s.cursor, after_step);
+
+ // II6: `call malloc@plt` stepped over: rdi framed with the argument hanging under the call;
+ // rax struck with the result, the row's C form with it; the others in a wave.
+ asides.say(s, "Arguments go in `rdi`, `rsi`…; the result comes back in `rax`.", left, level(rb, 0));
+ const over = s.cursor;
+ s.cursor = over + f(18);
+ to(s, shows(framed, "rdi"), 1, 6);
+ s.cursor = over + f(48);
+ to(s, shows(framed, "rdi"), 0, 6);
+ s.cursor = over;
+ at.over(s, back);
+
+ // II7: on to reverse's first instruction, a continue: the wave, the code fading through.
+ asides.say(s, "On, into `reverse()`: `rsp` and `rbp` move with the calls.", left, level(rb, 7));
+ at.@"continue"(s, reverse);
+
+ // II8: the registers the scene never changes fold, three to a row, under a rule; then the
+ // 128 bytes come back from the shelf, as I left them, at the rows III's stack gives them.
+ asides.say(s, "Registers we will not follow fold, three to a row. We are back where the 128 bytes were read.", left, level(rb, 6));
+ s.play(.{fold.to(1)}, .{ .seconds = f(36), .ease = anim.ease.linear });
+ s.play(.{fold.to(4.0 / 3.0)}, .{ .seconds = f(12), .ease = anim.ease.linear });
+ s.wait(f(12));
+ // rsp's word at 480: four free rows over it in III's stack, under the registers' eleven rows.
+ const stack_top = rb.y + canim.layout.panelH(11) + canim.theme.canvas.row_gap + canim.theme.metric.context.tag + canim.theme.metric.context.pad;
+ set(s, dump.top, stack_top + 4 * row);
+ s.play(.{dump.fold.to(0)}, .{ .seconds = f(48), .ease = anim.ease.linear });
+ s.play(.{dump.back.to(0)}, .{ .seconds = f(12), .ease = anim.ease.linear });
+ s.wait(@max(asides.read_by - s.cursor, 0));
+
+ return .{ .ctx = ctx, .at = at, .registers = registers, .disasm = disasm, .clock = clock, .disasm_chrome = disasm_chrome, .dump = dump, .dump_obj = dump_obj, .asides = asides, .e = s.cursor };
+}
diff --git a/anim/scenes/intro_stack.zig b/anim/scenes/intro_stack.zig
index 378d624..3fb0213 100644
--- a/anim/scenes/intro_stack.zig
+++ b/anim/scenes/intro_stack.zig
@@ -1,121 +1,64 @@
-//! The introduction, chapter II: the stack (design/motion.md, "A scene: the
-//! introduction", II1 to II4, here six beats; mock 31). It opens on chapter
-//! I's last picture, at the same moment of the `intro` recording (reverse's
-//! first instruction, its `push rbp`): the address space and the dump's link
-//! fade, the words glide into the stack panel's rows where it stands in the
-//! working frame (sixteen of them and four `free` over rsp, the window held
-//! there so that nothing in the panel moves while the frame is made) and
-//! become it; the convention said there (lower addresses drawn higher), the
-//! offsets coming down the rows. rsp's and rbp's rows arrive over the stack,
-//! rsp's pin landing on the top word. The call first: the way back main
-//! left framed, main's three rows round its call arriving in the program
-//! column, the word aimed at the row it returns to (`aim`, drawn head first,
-//! standing at 60% through the push). Then reverse's first rows under
-//! main's (the disassembly) and `push rbp` walked: the pc's mark on its
-//! row, the touch to the word, rbp's value carried to it and struck, rsp's
-//! pin climbing. `mov rbp, rsp` and `sub rsp` walked: the frame; its roles
-//! (the way back named) and spans, a `column` each, the panels' tags last
-//! (`frame up`). Then the registers built over it a row at a time, their
-//! tag last. The text stands beside on the left, in the program column,
-//! over the code.
+//! The introduction, chapter III: the stack (design/motion.md, "A scene:
+//! the introduction", III1 to III5; mock 31), a function the scene `intro`
+//! calls after II's seam. It goes on from chapter II's last picture, on
+//! II's context (its registers, folded to the scene's one set; reverse's
+//! rows at the program column's foot, no panel round them; the clock): the
+//! 128 bytes, back at the rows II gave them, become the stack panel where
+//! they stand (sixteen words and four `free` over rsp, the window held
+//! there so that nothing in the panel moves while the frame is made); the
+//! convention said there (lower addresses drawn higher), the offsets coming
+//! down the rows; rsp's pin landing on the top word and its link to it. The
+//! call first: the way back main left framed, main's three rows round its
+//! call arriving in the program column, the word aimed at the row it
+//! returns to (`aim`, drawn head first, standing at 60% through the push).
+//! Then `push rbp` walked: the pc's mark on its row, the touch to the word,
+//! rbp's value carried to it and struck, rsp's pin climbing. `mov rbp, rsp`
+//! and `sub rsp` walked: the frame; its roles (the way back named) and
+//! spans, a `column` each, the panels' tags last (`frame up`). The text
+//! stands beside on the left, in the program column, over the code.
//!
-//! What a beat has not reached yet is under the page (`Cover`, and the
+//! What a beat has not reached yet is under the page (`intro.Cover`, and the
//! stack's own `reveal`), lifted as the beat says it: the context's panels
//! draw every column at once.
const std = @import("std");
const anim = @import("anim");
-const sk = @import("sketch");
const canim = @import("canim");
-const recordings = @import("recordings");
-
-pub const background = canim.background;
-pub const scene = anim.Live(frame, struct {});
+const intro = @import("intro.zig");
+const registers = @import("intro_registers.zig");
const t = canim.theme.time;
const row = canim.theme.metric.context.row;
-const tag = canim.theme.metric.context.tag;
-const pad = canim.theme.metric.context.pad;
-
-fn f(frames: f32) f32 {
- return frames / 60;
-}
-
-fn place(s: *anim.Frame, data: anytype) anim.Obj {
- return s.custom(data, .{ .x = -640, .y = -360, .scale = canim.ui.scale });
-}
+const f = intro.f;
+const run = intro.run;
+const place = intro.place;
+const cover = intro.cover;
+const lift = intro.lift;
-/// The page over a part of a panel the beat has not reached: lifted (its fade out) as the beat says it.
-const Cover = struct {
- box: canim.Rect,
- pub fn draw(c: *const Cover, fr: *sk.Frame, placed: anim.Placed) void {
- (canim.ui.Ui{ .f = fr, .at = placed }).fill(c.box, canim.theme.color.page);
- }
-};
+/// The chapter's last picture, which chapter IV opens on.
+pub const Three = struct {
+ /// The state column (the registers, the stack) and the code (main's rows, reverse's, the ties).
+ state: [2]anim.Obj,
+ code: [3]anim.Obj,
+ clock: anim.Obj,
+ /// The cursor the clock counts on (II's and III's).
+ at: canim.Cursor,
+ asides: canim.Asides,
+ e: f32,
-/// A value framed as read (6 f in with its object's fade).
-const Read = struct {
- box: canim.Rect,
- pub fn draw(r: *const Read, fr: *sk.Frame, placed: anim.Placed) void {
- (canim.ui.Ui{ .f = fr, .at = placed }).read(r.box, 1);
+ pub fn texts(three: *const Three, s: *anim.Frame) []const anim.Obj {
+ return registers.standing(s, &three.asides);
}
};
-fn cover(s: *anim.Frame, box: canim.Rect) anim.Obj {
- const o = place(s, s.new(Cover{ .box = box }));
- s.play(.{o.fadeIn()}, .{ .seconds = 0 });
- return o;
-}
-
-/// A panel's tag and rules under the page, for `frame up`.
-fn chrome(s: *anim.Frame, b: canim.Rect, strip: bool) [5]?anim.Obj {
- const w = canim.theme.stroke.rule;
- return .{
- cover(s, .{ .x = b.x, .y = b.y, .w = b.w, .h = tag }),
- cover(s, .{ .x = b.x, .y = b.y + tag, .w = w, .h = b.h - tag }),
- cover(s, .{ .x = b.x + b.w - w, .y = b.y + tag, .w = w, .h = b.h - tag }),
- cover(s, .{ .x = b.x, .y = b.y + b.h - w, .w = b.w, .h = w }),
- if (strip) cover(s, .{ .x = b.x + b.w - canim.theme.strip.cost, .y = b.y + tag, .w = canim.theme.strip.cost - w, .h = b.h - tag - w }) else null,
- };
-}
-
-/// Lifts `covers` one after another, `apart` frames apart, `each` frames each, from the cursor; the cursor after the last.
-fn lift(s: *anim.Frame, covers: []const ?anim.Obj, apart: f32, each: f32) void {
- const at = s.cursor;
- var end = at;
- for (covers, 0..) |o, i| if (o) |obj| {
- s.cursor = at + f(apart * @as(f32, @floatFromInt(i)));
- s.play(.{obj.fadeOut()}, .{ .seconds = f(each), .ease = anim.ease.linear });
- end = s.cursor;
- };
- s.cursor = end;
-}
-
-/// A value at once, from the cursor.
-fn set(s: *anim.Frame, v: anim.Value, to: f32) void {
- s.play(.{v.to(to)}, .{ .seconds = 0 });
-}
-
-/// Clock `v` from 0 to `frames`, linear, from the cursor; the cursor after it.
-fn run(s: *anim.Frame, v: anim.Value, frames: f32) void {
- s.play(.{v.to(0)}, .{ .seconds = 0 });
- s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
-}
-
-fn frame(s: *anim.Frame) void {
- const rec = canim.open(recordings.intro);
- const reverse = rec.call("reverse", 0);
+/// From the seam's opening (the cursor), on chapter II's context.
+pub fn chapter(s: *anim.Frame, rec: *canim.Recording, two: registers.Two, title: intro.Title) Three {
+ const ctx = two.ctx;
+ var at = two.at;
// Chapter I's moment: reverse's first instruction, `push rbp`; then `mov rbp, rsp` and `sub rsp, 0x18`.
- const moment = reverse.enter;
+ const moment = rec.call("reverse", 0).enter;
const framed = moment + 3;
- var at = canim.cursor(s, rec, moment);
- at.journey(.moment, framed);
- at.levels = .{ .fire = .disasm, .source_rows = 14, .introduction = true };
- var split = canim.layout.split.none;
- split.backtrace.h = 0;
- const ctx = canim.context(s, at, .{ .split = split });
const g = layout(ctx.stage, rec, moment);
const sb = g.stack;
- const rb = ctx.stage.first.registers;
const rsp = g.rsp;
const first = g.first;
const top = g.top;
@@ -123,78 +66,57 @@ fn frame(s: *anim.Frame) void {
// The window held where it is, four `free` words over rsp: the push and `sub rsp` fill them.
hold(s, ctx.stage, moment);
- // The panels and the page over what they have not said yet, first: chapter I's
- // picture, the words gliding into the stack among them, draws over them.
// The stack, its offsets, roles and spans under the page until their beats.
// (Rows 4 f apart: the offsets come down while the convention is read.)
const reveal: canim.Stack.Reveal = .{ .offsets = s.value(-1), .roles = s.value(-1), .spans = s.value(-1), .apart = 4 };
const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage, .reveal = reveal });
- // The registers, under the page: rbp's and rsp's rows (the scene's two, the first two), the rest, the chrome.
- s.play(.{ctx.registers.fadeIn()}, .{ .seconds = 0 });
- var regs_rows: [16]?anim.Obj = @splat(null);
- for (0..@min(canim.layout.rowsIn(rb.h), 16)) |k|
- // (From the third row on 2 higher: the rule over the folded rows goes with them.)
- regs_rows[k] = cover(s, .{ .x = rb.x + 2, .y = rb.y + tag + pad + row * @as(f32, @floatFromInt(k)) - @as(f32, if (k >= 2) 2 else 0), .w = rb.w - 4, .h = row + @as(f32, if (k >= 2) 2 else 0) });
- const regs_chrome = chrome(s, rb, false);
// The pins' lane: rsp's row's lifted with rsp, the rest (rbp's pin) with the push.
var lane: [32]?anim.Obj = @splat(null);
const rsp_row: usize = held_free;
for (0..@min(slots, 32)) |k| lane[k] = cover(s, .{ .x = sb.x + 2, .y = top + row * @as(f32, @floatFromInt(k)), .w = canim.theme.metric.slot.lane_end - 2, .h = row });
- const stack_chrome = chrome(s, sb, true);
- // Reverse's first rows, the disassembly under main's: its rows with the push, its tag and strip last.
- const disasm_chrome = chrome(s, ctx.stage.first.disasm, true);
+ const stack_chrome = intro.chrome(s, sb, true);
- // Chapter I's last picture: the address space, the words with their chains, the link standing.
- const space = s.new(canim.Segments.init(s, rec, moment));
- const dump = s.new(canim.Words.init(s, rec, moment));
+ // The 128 bytes become the stack's rows where they stand (II8 put them there).
+ const dump = two.dump;
dump.panel = .{ .x = sb.x, .top = top, .first = first };
- const at_ = canim.regroup.at;
- const tie = s.new(canim.segments.Place{ .segments = space, .addr = rsp, .x = at_.bracket, .y0 = at_.top + 2, .y1 = at_.top + 16 * 24 - 2, .clock = s.value(60), .quiet = s.value(24) });
- for ([_]anim.Value{ space.form, dump.placed }) |v| set(s, v, 1);
- set(s, space.whole, 999);
- for (space.rides) |v| set(s, v, 999);
- for ([_]anim.Value{ dump.in, dump.ink, dump.chains }) |v| set(s, v, 999);
- set(s, dump.regroup, canim.regroup.regroup_frames);
- set(s, dump.left, 24);
- const objs = .{ place(s, space), place(s, dump), place(s, tie) };
- inline for (objs) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 });
+ // (Over the page that covers the stack's lane: the addresses travel across it.)
+ const dump_obj = place(s, dump);
// main's rows, in the program column over reverse's; the aim joins them to the word.
const back_y = rowY(top, first, rsp);
const main_rows = s.new(canim.descent.Caller{ .rec = rec, .at = moment, .call = rec.register(moment - 1, "rip"), .box = g.caller, .in = s.value(-1), .faint = s.value(0) });
- s.play(.{place(s, main_rows).fadeIn()}, .{ .seconds = 0 });
+ const caller = place(s, main_rows);
const main_word: canim.Rect = .{ .x = sb.x + canim.theme.metric.slot.address + 12 * 12 + canim.theme.metric.context.arrow_w, .y = back_y, .w = @as(f32, @floatFromInt(canim.ui.digits(rec.register(moment - 1, "rip") + 5))) * 12, .h = row };
- const word_frame = place(s, s.new(Read{ .box = main_word }));
- // The relations, and rsp's link to its word as II2 names it.
+ const word_frame = place(s, s.new(intro.Read{ .box = main_word }));
+ // The relations, and rsp's link to its word as III2 names it.
const joins, const rsp_link = ctx.tiesWith(s, "rsp", 1.0);
- s.play(.{joins.fadeIn()}, .{ .seconds = 0 });
+ const opening = s.cursor;
+ s.play(.{ caller.fadeIn(), joins.fadeIn(), two.dump_obj.fadeOut(), dump_obj.fadeIn() }, .{ .seconds = 0 });
+ s.cursor = opening;
var asides: canim.Asides = .{};
const left = canim.theme.canvas.margin_x;
- // II1: the address space and the link fade (18 f); the words glide into
- // the stack's rows (36 f) and become the panel (12 f). Where it first
- // stands, its convention said, unlike the bar's: the offsets come down
- // its rows (a column, 4 f apart), growing as the addresses do.
- s.wait(t.beat);
- s.play(.{ objs[0].fadeOut(), objs[2].fadeOut() }, .{ .seconds = f(18), .ease = anim.ease.linear });
+ // The opening (126 to 174): the bytes fade, the addresses and the words glide into the
+ // stack's rows (36 f) and become the panel (12 f). Where it first stands, its convention
+ // said, unlike the bar's: the offsets come down its rows (a column, 4 f apart).
s.play(.{dump.become.to(1)}, .{ .seconds = f(36), .ease = anim.ease.linear });
- s.play(.{ stack.fadeIn(), objs[1].fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear });
+ s.play(.{ stack.fadeIn(), dump_obj.fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear });
+ title.out(s);
asides.say(s, texts[0], left, rowY(top, first, first) + row / 2);
const column = reveal.apart * @as(f32, @floatFromInt(slots)) + 12;
run(s, reveal.offsets, column);
s.wait(t.beat);
- // II2: rsp's and rbp's rows arrive over the stack (12 f), rsp's pin lands on the top word (12 f),
- // then rsp's link from its row down to the word, held, drawn back.
+ // III2: rsp's pin lands on the top word (12 f), then rsp's link from its row down to the
+ // word, held, drawn back. Its row was built in II: nothing arrives.
asides.say(s, texts[1], left, back_y + row / 2);
- lift(s, &.{ regs_rows[0], regs_rows[1] }, 0, 12);
lift(s, &.{lane[rsp_row]}, 0, 12);
rsp_link.play(s);
s.wait(rsp_link.total());
s.wait(f(18));
s.wait(t.beat);
- // II3: the call, first: the way back main left, framed; main's rows; the aim drawn to its row.
+ // III3: the call, first: the way back main left, framed; main's rows; the aim drawn to its row.
asides.say(s, texts[2], left, back_y + row / 2);
s.play(.{word_frame.fadeIn()}, .{ .seconds = f(6), .ease = anim.ease.linear });
s.wait(f(12));
@@ -204,12 +126,11 @@ fn frame(s: *anim.Frame) void {
s.wait(f(24 + 30));
s.wait(t.beat);
- // II4: the push: reverse's first rows under main's, rbp's pin; `push rbp` walked
- // (its row fires, the touch to the word, rbp's value carried there and struck, rsp's pin climbing).
+ // III4: the push: rbp's pin; `push rbp` walked (its row fires, the touch to the word,
+ // rbp's value carried there and struck, rsp's pin climbing). Reverse's rows are on screen since II.
asides.say(s, texts[3], left, rowY(top, first, rsp - 8) + row / 2);
at.aim(s, .standing);
s.play(.{ word_frame.fadeOut(), main_rows.faint.to(1) }, .{ .seconds = f(18), .ease = anim.ease.linear });
- s.play(.{ctx.disasm.fadeIn()}, .{ .seconds = f(12), .ease = anim.ease.linear });
var lanes: [32]?anim.Obj = lane;
lanes[rsp_row] = null;
lift(s, &lanes, 0, 12);
@@ -219,7 +140,7 @@ fn frame(s: *anim.Frame) void {
at.levels.carry = .off;
s.wait(t.beat);
- // II5: the frame made (`mov rbp, rsp`, `sub rsp`); its roles, spans, and the tags last.
+ // III5: the frame made (`mov rbp, rsp`, `sub rsp`); its roles, spans, and the tags last.
asides.say(s, texts[4], left, g.span_y);
at.aim(s, .off);
at.walk(s, .moment, moment + 2);
@@ -229,48 +150,40 @@ fn frame(s: *anim.Frame) void {
s.wait(t.beat);
// `frame up`: the rules (12 f), then the tags and strips (12 f).
const at_rules = s.cursor;
- lift(s, disasm_chrome[1..4], 0, 12);
+ lift(s, two.disasm_chrome[1..4], 0, 12);
s.cursor = at_rules;
lift(s, stack_chrome[1..4], 0, 12);
const at_tags = s.cursor;
- lift(s, &.{ disasm_chrome[0], disasm_chrome[4] }, 0, 12);
+ lift(s, &.{ two.disasm_chrome[0], two.disasm_chrome[4] }, 0, 12);
s.cursor = at_tags;
lift(s, &.{ stack_chrome[0], stack_chrome[4] }, 0, 12);
- s.wait(t.beat);
-
- // II6: the registers built over the stack, a row at a time, their tag last.
- asides.say(s, texts[5], left, g.registers_y);
- lift(s, regs_rows[2..], 12, 12);
- lift(s, regs_chrome[1..4], 0, 12);
- lift(s, &.{regs_chrome[0]}, 0, 12);
- // The chapter's last picture.
+ // The chapter's last picture, held until its last text is read: then the seam.
s.wait(@max(asides.read_by - s.cursor, 0));
- s.wait(t.before_cut);
+ return .{ .state = .{ two.registers, stack }, .code = .{ caller, two.disasm, joins }, .clock = two.clock, .at = at, .asides = asides, .e = s.cursor };
}
-/// The chapter's texts, in order (chapter III opens on the last two).
+/// The chapter's texts, in order.
pub const texts = [_][]const u8{
"Here lower addresses are drawn higher: down a word is up a row.",
"`rsp` holds the address of the top of the stack.",
"A call pushes the address to come back to: here, `main+50`.",
"A push moves `rsp` down a word and stores there: `push rbp` keeps the caller's `rbp`.",
"`rbp` marks the frame's base. A function's words are its frame: the saved rbp, its locals, the way back.",
- "The registers are the other place values live: seventeen of them.",
};
/// Free words over rsp in the held window.
-pub const held_free = 4;
+const held_free = 4;
-/// The stack's window held from the first frame (no scroll to it), `held_free` words over rsp at `moment`.
-pub fn hold(s: *anim.Frame, stage: *canim.Stage, moment: u64) void {
+/// The stack's window held from here (no scroll to it), `held_free` words over rsp at `moment`.
+fn hold(s: *anim.Frame, stage: *canim.Stage, moment: u64) void {
s.play(.{ stage.hold.to(@floatFromInt(moment)), stage.hold_free.to(held_free), stage.hold_in.to(1) }, .{ .seconds = 0 });
}
-/// Where the chapter's parts stand (chapter III opens on its last picture,
-/// laid out the same): the stack under the registers, its window from
-/// `first` (four free words over rsp), its rows from `top`; main's rows
-/// in the program column level with the lower stack, reverse's under them.
-pub fn layout(stage: *canim.Stage, rec: *canim.Recording, moment: u64) struct { stack: canim.Rect, rsp: u64, first: u64, top: f32, caller: canim.Rect, span_y: f32, registers_y: f32 } {
+/// Where the chapter's parts stand: the stack under the registers' eleven
+/// rows (356 to 868), its window from `first` (four free words over rsp),
+/// its rows from `top`; main's rows in the program column (604 to 700) over
+/// reverse's six, where chapter II put them (712 to 888).
+fn layout(stage: *canim.Stage, rec: *canim.Recording, moment: u64) struct { stack: canim.Rect, rsp: u64, first: u64, top: f32, caller: canim.Rect, span_y: f32 } {
const rb = stage.first.registers;
// Sixteen slots and the headroom under the registers' box (the words
// become them where they stand), not the column's rest.
@@ -279,12 +192,11 @@ pub fn layout(stage: *canim.Stage, rec: *canim.Recording, moment: u64) struct {
const sb = stage.first.stack;
const rsp = rec.register(moment, "rsp");
const first = rsp - 8 * held_free;
- const top = sb.y + tag + pad;
- const caller: canim.Rect = .{ .x = canim.theme.layout.program.x, .y = rowY(top, first, rsp) + row / 2 + 152, .w = canim.theme.layout.program.w, .h = 4 * row };
- // Seven rows: reverse's from its first, which none of the chapter's steps scrolls away.
- stage.first.disasm = .{ .x = caller.x, .y = caller.y + caller.h + canim.theme.canvas.row_gap, .w = caller.w, .h = canim.layout.panelH(7) };
+ const top = sb.y + canim.theme.metric.context.tag + canim.theme.metric.context.pad;
+ const code = stage.first.disasm;
+ const caller: canim.Rect = .{ .x = code.x, .y = code.y - canim.theme.canvas.row_gap - 4 * row, .w = code.w, .h = 4 * row };
const rsp_framed = rec.register(moment + 3, "rsp");
- return .{ .stack = sb, .rsp = rsp, .first = first, .top = top, .caller = caller, .span_y = (rowY(top, first, rsp_framed) + rowY(top, first, rsp + 8)) / 2, .registers_y = rb.y + tag + pad + row * 2.5 };
+ return .{ .stack = sb, .rsp = rsp, .first = first, .top = top, .caller = caller, .span_y = (rowY(top, first, rsp_framed) + rowY(top, first, rsp + 8)) / 2 };
}
fn rowY(t0: f32, from: u64, addr: u64) f32 {