1985 · Ocean Software

The NeverEnding Story

This minisite was contributed by air, 64kramsystem. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/neverending-story with me to Gold.

A text adventure in three parts whose whole story is bytecode for one small interpreter. Its only random number is the line the TV picture has reached when a script asks.

01 · The game

Atreyu's quest

The NeverEnding Story follows the film of 1984. Fantasia is being eaten away by the Nothing, its Childlike Empress is ill, and the boy Atreyu is sent to find a cure. The player is Atreyu, and types what he should do: GET AURYN, RIDE ARTAX, BLOW HORN, FLY SOUTH. The game answers in a few lines of text, with a picture of the place or the event at the top left of the screen and a small picture of each thing Atreyu carries at the top right.

The game is in three parts, loaded one after another: the Great Forest, the Swamps of Sadness and the Southern Oracle; the ruins of Spook City, its well and its dungeons; then the asteroids left of Fantasia, the mazes of the Ivory Tower and the Empress at the top of it. Whatever Atreyu carries at the end of a part he keeps for the next, except Auryn, which Part 2 takes away on its first turn and puts on the hill, room $36, when he has the golden key in the treasure room ($2F06). He has a strength that the swamps, the fog and poison wear down, a light that he needs underground, and the werewolf Gmork on his heels through the first part.

Ocean published it in 1985. Ian Weatherburn designed and programmed it, Steve Cain drew the graphics and Martin Galway wrote the music (the opening's credits). The copy analysed here is a disk crack of Ocean's cassette release.

The opening: the title in large red letters and the credits in yellow on grey
The opening, while the title tune plays.
The first room of Part 1: a picture of Rockbiter at the top, the room's description and a prompt below
The first room, with Rockbiter passing through.

02 · The sound

Music: Martin Galway's title tune

The only sound in the game is the tune that plays over the opening, until a key is pressed. The player below runs the game's own music driver.

The driver's code ($9680-$9FEE), its data ($F000-$F768) and its zero page run inside the page, called as the opening calls them: MUSIC_STOP and MUSIC_INIT once, then MUSIC_PLAY once a frame.

The tune is three voices from three streams of notes and commands ($F250, $F5F3 and $F6BE). Voice 1 has the melody, with a vibrato in four phases and a sweep of its pulse width; voices 2 and 3 play broken chords and a bass from short patterns that the stream calls again and again at different pitches ($9BE4, $9E26).

Some of the tune is code. Stream command $9C calls a routine at an address inside the tune's own data ($98DC): the fade out near the end of each pass and the fade in at its start are two such routines ($F406, $F400), and two more flip a note of voice 1 and one of voice 2 between a rest and a pitch each time their phrase comes round, three times a pass ($F495, $F553). The tune therefore repeats exactly only every other pass. One pass is 11,328 frames, 3 minutes 46 seconds.

Once the game starts, it never writes to the sound chip: the driver's memory from $9700 is overwritten by the disk loader the moment the opening ends ($070F).

03 · The play screen

One screen in two modes

The top ten character rows are a multicolour bitmap; the fifteen below are text. A raster interrupt switches the video chip between the two as the beam passes.

Drawn by the page from one frame of Part 2's first room after LOOK: memory as the frame began and the eight writes during it that change the picture, to $D011, $D016, $D018 and $D021, with the line and cycle of each. The interrupt's other six writes only set the next line to stop at and acknowledge the interrupt.

The interrupt runs three times a frame ($A7E0, which picks its phase with a branch it rewrites). On line 49 it sets the background black and turns on the multicolour bitmap at $E000 ($A7E3); on line 130 it sets the background grey and the text mode with the game's own character set at $F800 ($A80A); on line 138 it only arms the next frame. The screen bytes at $CC00 serve both: as colours for the bitmap above the switch and as characters below it.

The band is built in layers. The backdrop, a sunset over the Ivory Tower, is copied back from a saved copy at $BC00; then come the icons of what Atreyu carries, at the right; then the picture of the room or the event, at the left (RENDER_ROOM_GRAPHICS, $0570).

04 · Pictures

Every picture is a patch on one painted sunset

Every picture is a rectangle of character cells copied over the backdrop. Pick one; the page draws it with a port of the game's own copying routine.

A picture record ($0BF9, six bytes) gives the character row and column to draw at, the address of the picture's bytes, and its height and width in cells. BLIT_ROOM_GRAPHIC ($05BF) copies it one character row at a time: eight bitmap bytes for each cell of the row, then a screen byte for each (two colours), then a colour byte for each (a third). A picture of h rows and w cells is therefore h × w × 10 bytes, and the routine needs no other table than the three that give each row's address in the bitmap, the screen and colour memory ($0BBD, $0BD1, $0BE5).

Picture 0, an open book on a desk, stays in memory with the engine ($A100); 59 of the 125 rooms show it. Pictures 1-20 come with Part 1, 21-36 with Part 2 and 37-56 with Part 3, each part's set starting at $4300 in its file. OBJ_ROOM_TABLE ($0D4F) names each room's picture, and a script can show any picture of the part for an event.

The 36 icon slots at $A560, 4 × 4 cells and 160 bytes each, drawn by the same port. Pick one to put it in the band above. Eight are never shown. Slots 4 and 5 hold the raster interrupt's code ($A7E0), 29 to 31 the opening's title and credits ($B780), and 27, a crucifix, is drawn but no object or script uses it: each holds 0, Auryn's object number, in the map of icon slots to objects at $22A4, and the search for Auryn stops at slot 0. Slot 9 is the spider's web, which a command can never take (GET WEB runs $2D86, which never does), and slot 11 the padlock, which starts the game gone and which none of the words or scripts names.

Icons are pictures too. Each of the six icon records at $2943 is a picture record whose address the engine changes: TAKE puts the address of the object's icon into the first free one of the five for objects ($0F3A), and the scripts put Falkor's or Artax's into the sixth, the companion's ($113D). A record whose address has a high byte of 0 is skipped.

05 · Text

A capital letter marks where each word starts

The game's texts are stored without spaces. Pick a text; the page prints it with a port of the game's printer, in the game's own letters.

a word of the dictionarya word written outthe end, @

A text is a run of words, each starting with a capital letter: "YouAreDeepInThe" is stored with no spaces at all, and the printer (PROCESS_TERM, $0A0E) finds the end of each word at the next capital. A byte with its top bit set stands for a word of a dictionary of 94 ($25DD), whose pointer table the printer reads through $1C67. The printer puts a space after every word unless the next one starts with a full stop, and starts a new line before any word that would not fit in the 40 columns.

The capitals are only in the bytes. When it prints a letter A-Z, the printer adds $20 to make it lower case unless the flag at $0AFF is set, which a full stop, the start of each message and event and each word from the dictionary set, and the next capital clears (PRINT_WORD, $0ADB; $0B12, $09A1, $09D8, $0ABF). A room's description starts with a capital two cells high, in yellow ($0957): four glyphs of the character set, two on one line and two on the next, with 38 spaces printed between them.

06 · Commands

The parser reads three letters of each word

Type a command. The page runs a port of the game's parser on it and shows what the engine makes of it.

    The line editor keeps letters and spaces only, folded to lower case, up to 78 of them ($0806). The parser (PARSE_INPUT, $122F) splits the line at spaces and looks each word up by its first three letters in a vocabulary of 142 entries ($1A2E), each the three letters and an id. A word it cannot find ends the line: "I don't understand the word", and the word in quotes. Ids below $32 are verbs, among them the ten directions; $32 and up are nouns, and a noun's id less $32 is the number of the object it names (six of the 54 objects have no word, so a command can never name them); 0 is a word to skip, such as THE, GO or AT.

    Three letters are not enough for the diagonal directions, so the parser looks further for two of them: NORTH or SOUTH with THE or THW as its letters 4-6 becomes northeast, northwest, southeast or southwest ($1335). Then RESOLVE_VERB_NOUN ($1396) takes the first verb, and the next word after it that is not one to skip as the noun, and DISPATCH_COMMAND ($1403) finds the first of 70 verb-and-noun pairs that matches ($19A0), whose script it runs. AND, or any word after the noun, starts the next command.

    07 · The scripts

    The whole story is bytecode

    All of the game's story is bytecode: tests and actions run by one small interpreter. Pick a script to read it decoded.

      A script is clauses. Each clause is tests, opcodes $80-$89, then actions, $00-$20, and ends with $FE; $FF ends the script. A test that fails skips the rest of its clause (RUN_SCRIPT, $1605). The tests ask whether an object is here, carried or gone, whether a flag is set, what a counter holds, which room the player is in, or take a chance; the actions move objects and the player, set flags and counters, print events and sentences, show pictures and icons, and load the next part.

      Each turn the engine runs the resident turn script ($1C6F), which keeps Atreyu's strength and his light; the part's turn script ($2F06 in each part), which runs Gmork's chase in Part 1; and the script of the room Atreyu is in. Then it reads a line and runs the script of the pair the command matched. 54 object locations, 32 flags and 16 counters ($28BF, $290F, $292F) are most of the game's state, with the room, the part and the icons on show ($293F, $2940, $2943). The scripts of every room are on the Map tab.

      08 · Chance

      The only random number is the raster line

      The game has one random number: the line the video chip is drawing when a script asks. Move the slider to choose a test's number; each line of the frame below shows whether the test passes there.

      The page's test is a port of COND_RANDOM ($1222).

      The test $88 n reads the raster register, $D012, and passes when n is at least the value it reads ($0695, $1222). The register holds the low eight bits of the line, and a PAL frame has 312 lines, so the values 0-55 come round twice a frame and the rest once. When the test can fall anywhere in the frame, a number n passes on n + 1 + min(n, 55) + 1 of the 312 lines: 102 for 50, a third, where 51 in 256, a fifth, is what the number suggests.

      At the sphinxes the game uses it twice. Each turn there, a test of 25 decides whether the sphinxes' eyes blink (52 lines of 312). Going south while the eyes are open, a test of 200 kills Atreyu on 257 lines; he survives only on the 55 lines whose low byte is 201-255, about one try in six, and then needs Auryn too. Going south on the turn the eyes have just blinked, with Auryn, always works.

      09 · Three parts

      The engine stays, the story changes

      The engine loads once and stays in memory to the end. Each part is a file that loads over the same 26,368 bytes, $2F00-$95FF. Pick a block of memory to see what is in it.

      A part holds its rooms' descriptions and scripts, its events and its pictures, and nothing else: no code at all. The engine keeps everything that has to last, which is why objects carried from one part to the next arrive in the next: their locations are in the engine ($28BF), and a load never touches them. Rooms are numbered across the game, $00-$28 in Part 1, $29-$4C in Part 2 and $4D-$7C in Part 3, and the engine subtracts the loaded part's first room before it reads that part's tables ($0DCC).

      A part ends with a script action, $1F (ACTION_NEXT_PART, $0FF1): the engine counts the part on, puts Atreyu in the new part's starting room (Part 3's first, $4D, but Part 2's $34, at $0427), asks for Space and loads. The loader in this copy is the crackers': it adds one to the digit in the name "PART 0" and loads that file, whichever part the game asked for, which goes wrong after a restart (Discoveries).