1988 · Lucasfilm Games

Zak McKracken and the Alien Mindbenders

This minisite was contributed by air. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/zak-mckracken-and-the-alien-mindbenders with me to Gold.

Very little of what happens in this game is decided by the program in the computer's memory. The story is written in a language of its own, as scripts that come off the disk room by room, and the program is the machine that runs them.

01 · The game

A tabloid reporter who dreams about aliens

The title over Zak's bed at night
The title comes up over Zak's bed, in the dream that opens the game.
Zak standing in his bedroom, with the verbs below the picture
Zak's bedroom, where play begins. The sentence line, the verbs and the inventory sit under the room.

You play Zak McKracken, who is tired of making up stories for a tabloid paper, the National Inquisitor. The game opens on his dream about aliens, and the dream turns out to matter. Later you also play three others, Annie, Melissa, and Leslie, and switch between the four with the function keys. The journey goes round the world by plane and on to Mars.

You play by making sentences. Pick a verb from the list under the picture, such as Open, Pick up, or Use, then click on something in the room or in your inventory. "Walk to" comes back after every sentence, so a click on the floor walks there. Rooms wider than the screen scroll as Zak walks, and the game asks you to swap disk sides as you travel.

Words on this page: a room is one place, wider than the screen or not. An actor is a character who walks about in it, and a script is a piece of the story, written in the game's own language, that tells the actors and the room what to do.

02 · Music

Music: the tunes play on a program of their own, loaded from the disk

Press a tune to hear it played by the game's own code: the opening, the tune for saving the world, the one for a game over, and the one that plays on after either end.

The player starts when the page has loaded the game's code.

Played by the game's own code, run here on a model of the computer's processor: the music's program (sound 1) and the sound engine, with their bytes from the listing. A test beside this page runs the same code over the whole of the game's memory, with each tune placed elsewhere, and checks that every write to the sound chip, in every frame, is the same as the page's, until the tune ends: 102, 59, 46, and 33 seconds.

Numbers written with a $ are addresses in the computer's memory, in hexadecimal; each one links to the game's code on the Source code tab. The game's sound engine ($3CDF to $4460) plays sound effects on the sound chip's three voices, each of which plays one note at a time. The music is not part of it. It is sound 1 on the disk, 1,078 bytes of program and tables. A script instruction takes five pages off the top of the heap, the memory the game loads things into, and loads sound 1 there, at $C300, where nothing will move it ($6183). The script's startMusic loads the tune and calls $C304 with its number ($57A5). From then on, once a frame, the engine calls the music's program at $C395 for as long as music plays ($3FE0).

The music does not write to the chip itself. It plays its three voices as three sound effects, sounds 3, 4, and 5, which are built into the program ($4406, $4433, $4460). For each note it rewrites a voice's sound with the new instrument and pitch and starts it through the engine, which then plays it like any other. While the music holds all three voices, no sound effect can start ($3CDF).

There are four tunes on the disks, sounds 95, 102, 103, and 104, all in the same file as the music's program. A search of the scripts' bytes for startMusic finds 95, the opening, in global scripts 1 and 48; 102, for the world saved, in 48 and 149, the epilogue; 103 in 78 and 135, the game over after a death and after the jail; and 104 in script 128, which plays it again and again once 103 has finished, and in an object of the Crystalabra's room, which does the same after 102. The music also keeps playing while a new room loads, which Discoveries explains.

03 · Sound

Sound: each effect is a list of commands for the engine

Every sound effect on the disks, named for the first thing in the game that plays it. Some play on until they are stopped: press Stop to end those.

The player starts when the page has loaded the game's code.

Played by the game's sound engine, run as for the music, and started as a script's startSound starts it: the sound is stopped if it was playing ($3E52), put on the list of sounds to start ($3FCE) and begun by the engine in the frame after the game's next pass ($12A2). The same test checks every effect's writes to the chip, frame by frame, until it ends or for five minutes. 24 of them play on until they are stopped. Sound 126 is silent: the byte that lists its parts is 0, so it has none.

A sound effect is a resource of its own, from 11 to 469 bytes. Its first byte is its priority, and its second says which parts it has: one, two, or three voices, a part for a voice's pulse width (the shape of its square wave), and one for the chip's filter. When no voice is free, the engine stops the playing sound of lowest priority if the new one's is as high; otherwise the new sound waits, if it may, or is dropped ($3CDF).

Each part is a list of commands. One sets a frequency, a pulse width, or a filter setting, with a time to hold it and an amount to slide it by every frame; others set the envelope and the waveform, turn the voice on or off, or loop back over earlier commands a number of times. A command of 0 ends the part ($419B). Every frame the engine copies each channel's values to the chip and steps each channel on ($414E).

04 · The interpreter

The story is a program, and the game reads it an instruction at a time

The 256 instructions of the game's script language. Click one to see what it does, or a group to pick out its instructions.

Loading the game's code…

Read from the game's table of instructions ($D000, $D100) in the listing. The name and the description are those the listing gives the routine each instruction runs. The groups are this page's.

Each script is a list of instructions, one byte each, with what they work on after them. The program fetches each instruction in turn and runs the routine for it, from two tables kept in the memory under the chips ($4C58). The 256 instructions share 110 routines. Many come in pairs or fours because the top bits of an instruction say whether each thing it works on is a number written in the script or a variable to look up ($4ED0, $4EC8, $4EC0): instruction $1C starts the sound the script names, and $9C starts the sound a variable holds.

Up to 19 scripts run at once, each in a slot of its own ($4DD5). Once a pass, the program runs every running slot until its script gives way, by waiting or by breakHere ($4C2F, $50CE), so many scripts carry on side by side. Scripts keep their numbers in 16-bit variables ($FE6E, $FD6F); variable 0 is the actor you control and variable 4 the room. A slot runs a global script, a room's entry or exit script, or the script an object has for a verb ($4CCA).

Lucasfilm Games called the language SCUMM, and this is the second game written in it. The scripts are the bulk of the game: 151 global scripts, 50,590 bytes, besides the scripts each room and its objects carry.

05 · Scrolling

A room wider than the screen is decoded a column at a time

The street outside Zak's flat is 120 columns wide, and the screen shows 40. Move the camera a column at a time, or press Pan, and watch which columns the game has to decode.

The street drawn by the page's port of the game's room decoder, the one the Maps tab uses for every room, checked byte for byte against the game's own. Red marks the columns decoded for the move just made. The camera moves a column for each pass of the game, about eight a second, as Pan does.

A room is stored as four streams packed in runs: its characters, their colours, the mask that says what stands in front of the actors, and the mask's own characters. Each stream holds the room a column at a time, top to bottom, so a column is a run of bytes in the middle of a stream. To start decoding there, the game needs to know where the column begins and how far into a run it is. When a room is shown, the game decodes all of it once and keeps, for every column and each of three streams, the place it starts and the run under way: twelve bytes a column, in a block of its own in memory ($38D9).

The camera is centred on a column ($CBC2) and moves one column a pass towards its target, never closer than 20 columns to either end of the room. When it follows an actor, the target moves to the actor whenever the actor comes within 10 columns of the edge of the screen ($CAD0). After a move of one column, the game shifts the room across the screen by one character and decodes only the column that came into view; after any longer jump it decodes all 40 ($3610). It draws on the screen not being shown and swaps the two when the drawing is done ($063A), so the scroll never shows half drawn.

The actors are sprites over the room, put together from eight limbs each. The Graphics tab draws every costume and a frame of the bedroom from the bytes the video chip read.

06 · Memory

Everything but the program is loaded from the disk when it is needed

What the disks hold, beside the space the game loads it into. Press a row for more about it.

Sizes from the resource index the game reads at start-up ($6E4E) and the resources on the two disk sides it points at. The space they are loaded into is the heap, from $77D5 to $C7FF.

Rooms, costumes, scripts, and sounds are loaded into one stretch of memory, the heap, when they are needed, each into the smallest free block it fits ($4699). When nothing fits, the game closes up the gaps and throws resources out, a kind at a time: the room left longest ago, a costume, every sound, and every script that is neither running nor locked ($497D). In Zak's bedroom, the heap holds room 1, 16 global scripts, 3 costumes, and 20 sounds. The music's program takes the top five pages of the heap while music plays.

Every resource lives inside a room's file on the disk, which runs on from the room's first track and sector ($2FCF). The game sends the disk drive a program of its own at start-up and reads whole sectors through it, two bits at a time ($7C59, $3BF8), rather than through the computer's own disk routines, which are switched out of memory while the game plays.