Retro computing with Jennifer

Jennifer

Commodore™ 1541 disk images and Infocom-style text adventures, byte by byte, with the @skiffyard/d64 and @skiffyard/zmachine decks.

November 2026, by @mplx.
Based on Jennifer 0.27.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 18

Why retro, why Jennifer

jvc add @skiffyard/d64
jvc add @skiffyard/zmachine
2 / 18

A 1541 disk in one slide

ThingValue
Tracks35 (40 or 42 with speeder DOSes)
Sectors per track21 outside, 19, 18, 17 inside
Block256 bytes: 2 bytes link, 254 bytes payload
Track 18BAM (sector 0) and directory (from sector 1)
Free on a blank disk664 blocks

d64.sectorsPerTrack(1) is 21, d64.sectorsPerTrack(35) is 17.

3 / 18

Format a disk, list it

def blank as d64.Image init d64.formatDisk("jennifer demo", "jd");
def img as d64.Image init d64.writeProgram($blank, "maze", BASIC, maze());
$img = d64.writeText($img, "readme", d64.FileType.Seq,
    "load\"maze\",8\nrun\n");
io.printf("%s", d64.directoryText($img));
d64.save($img, "demo.d64");
0 "jennifer demo   " jd 2a
   1 "maze"              prg
   1 "readme"            seq
662 blocks free.
4 / 18

A BASIC program is just bytes

# 10 PRINT CHR$(205.5+RND(1));:GOTO 10, as the C64 stores it
func maze() {   # loaded at BASIC = 0x0801
    def line as bytes init encoding.fromText("hex", "0a00" + "9920c728"
        + "3230352e35" + "aabb28312929" + "3b3a89203130" + "00");
    def next as int init BASIC + 2 + len($line);   # the next line
    def prg as bytes;
    $prg[] = $next & 0xff;   # low byte first
    $prg[] = $next >> 8;
    for (def b in $line) { $prg[] = $b; }
    return binary.concat($prg, binary.make(2));   # a zero link ends it
}
5 / 18

Reading it back

def again as d64.Image init d64.open("demo.d64");
def info as d64.FileInfo init d64.fileInfo($again, "maze");
io.printf("maze: %d bytes, loads at $%d|base=16, first block %d/%d\n",
    $info.size, $info.loadAddress, $info.chain[0].track,
    $info.chain[0].sector);
def p as d64.Program init d64.readProgram($again, "maze");
io.printf("%s\n", encoding.toText("hex", $p.data));
maze: 30 bytes, loads at $801, first block 17/0
1b080a009920c7283230352e35aabb283129293b3a89203130000000
6 / 18

The BAM, byte by byte

def bam as bytes init d64.readSector($again, 18, 0);
io.printf("%s\n", encoding.toText("hex", $bam[0..8]));
1201410015ffff1f
BytesMeaning
12 01the directory starts at track 18, sector 1
41DOS version "A"; a 1541 refuses to write another
15track 1 has 21 free blocks
ff ff 1fone bit per sector of track 1, 1 = free (21 ones)
7 / 18

Files, the classic way

CallWhat it does
listFiles(img)the directory as Entry values
findFiles(img, "?e*")the drive's * and ? patterns
readFile / readTextraw bytes, or PETSCII as text
updateFile, renameFile, deleteFilereplace, rename, scratch
lockFile(img, name)listed with <, scratch refuses it
readSector / writeSectorany block, BAM untouched
maze prg 1 17/0
readme seq 1 17/10
8 / 18

PETSCII: why names are lower case

d64.toPetscii("hello");   # 48 45 4c 4c 4f: the C64 shows HELLO
d64.toPetscii("Hello");   # c8 45 4c 4c 4f
io.printf("%s", d64.directoryTextIn($again, d64.Charset.Unshifted));
0 "JENNIFER DEMO   " jd 2a
   1 "MAZE"              prg
   1 "README"            seq
9 / 18

Values, not files: undo and errors

io.printf("blank still: %d free\n", d64.blocksFree($blank));
try {
    $img = d64.writeText($img, "README", d64.FileType.Seq, "x");
} catch (e) {
    io.printf("%s: %s\n", $e.kind, $e.message);
}
blank still: 664 free
d64: a file named "README" is already on this disk
10 / 18

The Z-machine

import "@skiffyard/zmachine/" as zmachine;
11 / 18

Start a story

def m as zmachine.Machine init zmachine.open("lantern.z5");
def i as zmachine.Info init zmachine.info($m);
io.printf("version %d, release %d, serial %s\n", $i.version, $i.release,
    $i.serial);
$m = zmachine.run(zmachine.setScreen($m, 60, 24));
io.printf("%s", zmachine.output($m));
version 5, release 1, serial 261102
Lantern
A test game for the zmachine deck.
...
12 / 18

Playing from a script

for (def line in ["take lamp", "north", "drop lamp", "inventory"]) {
    $m = zmachine.send($m, $line);
    io.printf("%s\n%s", $line, zmachine.output($m));
}
io.printf("status: %s\n", zmachine.upperWindow($m)[0]);
>take lamp
Taken.

>north
Garden
An overgrown garden. The hall is to the south.
...
>status:  Garden            Turns: 4
13 / 18

What does the game want?

while (true) {
    io.printf("%s", zmachine.output($m));
    def w as zmachine.Wait init zmachine.waiting($m);
    if ($w == zmachine.Wait.Quit) { break; }
    if ($w == zmachine.Wait.Save) {
        fs.writeBytes($saveFile, zmachine.saveData($m));
        $m = zmachine.resume($m, true);
        continue;
    }
    # Wait.Restore: zmachine.restore($m, data) or resume($m, false)
    if (io.eof()) { break; }
    $m = zmachine.send($m, io.readLine());   # Wait.Line or Wait.Key
}
14 / 18

Save, undo, restore

>take lamp    Taken.
>save         [Wait.Save] quetzal 166 bytes, starts FORM
              Saved.
>north        Garden ...
>undo         Undone.
>restore      [Wait.Restore] restore($m, $q)
              Saved.
15 / 18

A game in a bot, a test in CI

zmachine: zmachine: version 0 stories are not supported (3, 4, 5, 7 and 8 are)
16 / 18

Where to find games and disks

17 / 18

Read more

Based on Jennifer 0.27.0, November 2026.

18 / 18