//! A page of the Intel SDM as a talk: Figure 2-1, the instruction format //! (Vol. 2, page 31), comes alive. The page is Typst's import of the PDF, //! every glyph and rule a vector shape; the fields are `part`s of it, cut //! out by rectangles in the page's units (read off the player's guides and //! `pdftotext -bbox`, points to units: (pt - 306) * 4/3 across, (pt - 396) //! * 4/3 down). `83 C0 01`, `add eax, 1`, is written below, its bytes fly //! into their fields, and C0 splits into its ModR/M bits. //! //! The PDF is the build's `-Dmanual` (`~/01-resources/intel-devref-ii.pdf` //! by default) and is never committed; without it the scene says so. //! //! click, space, page down next step page up back const std = @import("std"); const anim = @import("anim"); const pdf: ?[]const u8 = @import("manual").pdf; pub const name = "manual"; pub const hold = 1.5; pub const typst_preamble = \\#set page(width: auto, height: auto, margin: 0pt, fill: none) \\#set text(font: "DejaVu Sans Mono", size: 14pt, fill: rgb("#c0392b")) ; pub const typst = struct { pub const page = "#image(\"" ++ (pdf orelse "") ++ "\", page: 31)"; pub const title = "#text(font: \"New Computer Modern\", size: 40pt, fill: rgb(\"#ece6e2\"))[Figure 2-1, alive]"; pub const from = "#text(font: \"New Computer Modern\", size: 16pt, fill: rgb(\"#8c8c8c\"))[IntelĀ® 64 and IA-32 SDM, Vol. 2, page 31]"; pub const add = "#text(fill: rgb(\"#555555\"))[add eax, 1]"; pub const b83 = "83"; pub const c0 = "C0"; pub const b01 = "01"; pub const bits = "11000000"; pub const direct = "#text(size: 8pt, fill: rgb(\"#555555\"))[direct]"; pub const is_add = "#text(size: 8pt, fill: rgb(\"#555555\"))[/0 ADD]"; pub const eax = "#text(size: 8pt, fill: rgb(\"#555555\"))[EAX]"; }; const missing = struct { pub const note = "#text(font: \"New Computer Modern\", size: 24pt, fill: rgb(\"#ece6e2\"))[No manual: build with `-Dmanual=/path/to/intel-sdm-vol2.pdf`]"; }; pub const scene = anim.Live(if (pdf == null) placeholder else talk, if (pdf == null) missing else typst); fn placeholder(s: *anim.Frame) void { s.play(.{s.typst(missing.note, .{}).write()}, .{}); } /// Rectangles in the page's units, as `s.part` and `s.rect` take them. const Area = struct { x: f32, y: f32, w: f32, h: f32 }; /// The labels of the figure's top row of fields: Prefixes, Opcode, /// ModR/M, SIB, Displacement, Immediate (inside the rules, which stay). const fields = [_]Area{ .{ .x = -199.5, .y = -110.7, .w = 69.3, .h = 33.3 }, .{ .x = -127.5, .y = -110.7, .w = 69.3, .h = 33.3 }, .{ .x = -55.5, .y = -110.7, .w = 69.3, .h = 33.3 }, .{ .x = 16.5, .y = -110.7, .w = 69.3, .h = 33.3 }, .{ .x = 100.5, .y = -110.7, .w = 93.3, .h = 33.3 }, .{ .x = 184.9, .y = -110.7, .w = 70.1, .h = 33.3 }, }; const opcode = 1; const modrm = 2; const immediate = 5; /// The ModR/M byte's own boxes: Mod, Reg/Opcode, R/M. const bit_boxes = [_]Area{ .{ .x = -144.0, .y = 5.3, .w = 33.3, .h = 25.3 }, .{ .x = -102.0, .y = 5.3, .w = 45.3, .h = 25.3 }, .{ .x = -53.7, .y = 5.3, .w = 46.0, .h = 25.3 }, }; /// The ModR/M byte's three boxes together, across. const byte_x = -95.7; /// The figure: both rows of boxes, the arrows and the notes; and its /// footnotes, under it. const figure: Area = .{ .x = -7.3, .y = -54.7, .w = 468, .h = 160 }; const footnotes: Area = .{ .x = -8, .y = 70.7, .w = 453, .h = 56 }; /// `11000000` in its own units: 8 characters of 0.6 em at 14 pt. const char = 0.6 * 14 * 4.0 / 3.0; fn talk(s: *anim.Frame) void { // The page, whole, on paper; the camera far enough out to see it all. const paper = s.rect(.{ .w = 816, .h = 1056, .fill = 0xffffff }); const page = s.typst(typst.page, .{}); const title = s.typst(typst.title, .{ .x = -700, .y = -380 }); const from = s.typst(typst.from, .{ .x = -700, .y = -325 }); // A tint over each field's label box (the same rectangle as its part), // laid before the parts so that they draw over it. var tints: [fields.len]anim.Obj = undefined; for (&tints, fields) |*t, f| t.* = s.rect(.{ .x = f.x, .y = f.y, .w = f.w, .h = f.h, .fill = 0x58c4dd60 }); s.play(.{anim.camera(.{ .zoom = 0.65 })}, .{ .seconds = 0 }); s.play(.{ title.write(), from.fadeIn(), paper.fadeIn(), page.fadeIn() }, .{ .seconds = 2 }); s.pause(); // Onto the figure. Its labels, the ModR/M byte's boxes, the figure // around them and its footnotes become parts of the page; the rest of // the page greys, and the footnotes go, to make room. var labels: [fields.len]anim.Obj = undefined; for (&labels, fields) |*l, f| l.* = s.part(page, f); var boxes: [bit_boxes.len]anim.Obj = undefined; for (&boxes, bit_boxes) |*b, area| b.* = s.part(page, area); _ = s.part(page, figure); const notes = s.part(page, footnotes); s.play(.{ anim.camera(.{ .zoom = 2.3, .x = -7, .y = -35 }), page.move(.{ .opacity = 0.25 }), notes.fadeOut(), title.fadeOut(), from.fadeOut() }, .{ .seconds = 1.5 }); s.pause(); // Each field in turn. for (labels, tints, 0..) |label, tint, i| { if (i > 0) s.play(.{ tints[i - 1].fadeOut(), label.indicate(), tint.fadeIn() }, .{}) else s.play(.{ label.indicate(), tint.fadeIn() }, .{}); s.pause(); } s.play(.{tints[fields.len - 1].fadeOut()}, .{ .seconds = 0.5 }); // An instruction: add eax, 1. const b83 = s.typst(typst.b83, .{ .x = -40, .y = 70 }); const c0 = s.typst(typst.c0, .{ .y = 70 }); const b01 = s.typst(typst.b01, .{ .x = 40, .y = 70 }); const add = s.typst(typst.add, .{ .x = 150, .y = 70 }); s.play(.{ b83.write(), c0.write(), b01.write(), add.write() }, .{ .seconds = 1.5, .lag = 0.3 }); s.pause(); // Each byte flies into its field; the fields it has none for fade. var flights: [fields.len + 3]anim.Animation = undefined; for (labels, 0..) |label, i| flights[i] = switch (i) { opcode, modrm, immediate => label.fadeOut(), else => label.move(.{ .opacity = 0.3 }), }; flights[6] = b83.move(.{ .x = fields[opcode].x, .y = fields[opcode].y, .scale = 1.3 }); flights[7] = c0.move(.{ .x = fields[modrm].x, .y = fields[modrm].y, .scale = 1.3 }); flights[8] = b01.move(.{ .x = fields[immediate].x, .y = fields[immediate].y, .scale = 1.3 }); s.play(flights, .{ .seconds = 1.5, .lag = 0.2 }); s.pause(); // C0 is a ModR/M byte: down the arrow into its boxes, as bits. const bits = s.typst(typst.bits, .{ .x = byte_x, .y = bit_boxes[0].y }); s.play(.{ boxes[0].fadeOut(), boxes[1].fadeOut(), boxes[2].fadeOut(), c0.transformInto(bits) }, .{ .seconds = 1.5 }); s.pause(); // 11 000 000: mod, reg, r/m, each into its box, and what it says. const mod = s.part(bits, .{ .x = -3 * char, .w = 2 * char, .h = 40 }); const reg = s.part(bits, .{ .x = -0.5 * char, .w = 3 * char, .h = 40 }); const rm = s.part(bits, .{ .x = 2.5 * char, .w = 3 * char, .h = 40 }); const says = [_]anim.Obj{ s.typst(typst.direct, .{ .x = bit_boxes[0].x, .y = 28 }), s.typst(typst.is_add, .{ .x = bit_boxes[1].x, .y = 28 }), s.typst(typst.eax, .{ .x = bit_boxes[2].x, .y = 28 }), }; s.play(.{ mod.move(.{ .x = bit_boxes[0].x }), reg.move(.{ .x = bit_boxes[1].x }), rm.move(.{ .x = bit_boxes[2].x }), says[0].write(), says[1].write(), says[2].write(), }, .{ .seconds = 1.5 }); s.pause(); // Back to the page, filled in. s.play(.{ anim.camera(.{ .zoom = 0.65, .x = 0, .y = 0 }), page.move(.{ .opacity = 1 }), notes.fadeIn(), add.fadeOut(), title.fadeIn(), from.fadeIn() }, .{ .seconds = 1.5 }); }