1987 · Pandora

Into the Eagle's Nest

This minisite was contributed by air, Nico-van-der-Zijden. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/into-the-eagles-nest with me to Gold.

A castle of four floors, 16 kilobytes of map each, built from a kilobyte of description and a table of blocks. The guards never fire a shot, and the high score screen hides a cheat.

01 · The game

What the game sends you in to do

A top-down shooter from 1987, written for the Commodore 64 by Andrew Challis with graphics by Robin Chapman.

The title screen: a castle on a crag under a blue sky, with the game's name above it.
The title picture, loaded from tape before the game itself and shown while the rest of the tape reads in.
The first room: the player as a green figure at the bottom left, two guards above, and a panel on the right reading KEYS, AMMO and HITS.
The first room of a mission. The player is the green figure; the panel on the right counts the keys, the rounds and the hits he has taken.

You play a soldier who has smuggled himself into a Nazi fortress. Three prisoners are held inside it, and explosive charges have already been planted on each of its four floors. The joystick walks you from room to room, fire shoots in the direction you are walking, and a lift moves you between the floors.

Before each mission the game asks which one you want. Three of them fetch a prisoner out; the fourth sets off the charges and brings the castle down. Along the way there are paintings, vases, pendants and jewels to pick up, keys for the steel doors, boxes of ammunition and food and first aid for the hits you take.

02 · Music

Music: three streams of note numbers

The attract loop's tune, played here by the game's own driver.

The driver at $1947, ported to JavaScript and fed the game's own tables from the listing. It plays through the site's model of the SID. Checked against the game's code run on the kit's 6502 simulator, every register after every call for 2,000 calls (test_music.js).

The C64 makes its sound with a chip called the SID, which has three voices, and a short piece of code called a driver tells it what to play. The game calls its driver once a frame, and this one acts on every third call: on a PAL machine, the European one that draws 50 frames a second, that is about 16.7 times a second. Each of the three voices has a stream of note numbers of its own, kept at the addresses $15E2, $1680 and $1768 (written in hexadecimal, base 16, as every address on this machine is), and a counter saying how many ticks of the current note are left. When a counter runs out, the voice takes the next number from its stream and looks it up in three tables: the frequency's high byte at $17F8, its low byte at $1842, and the note's length at $188C.

A note number of $FF ends the tune, and the driver then starts all three streams again from the beginning, so the music never stops. The test for it reads voice one's number whichever voice is being served, so it is voice one that decides when the tune goes round.

Each voice keeps its waveform in a three-byte table at $1930: a pulse for voices one and three and a sawtooth for voice two. To start a note the driver writes that byte with bit 0 cleared, which closes the gate, and then writes it again, which opens it.

03 · Sound

Sound: nine effects on one voice

Every noise the game makes in play, as the game plays it.

The effects at $6404 and the footsteps at $6790, ported and run through the site's model of the SID. Each effect sets its own attack, decay, pulse width, frequency and waveform on voice one, and a length in frames.

A routine that wants a noise leaves its number in $02D5, and the sound's own frame at $63E6 starts it. Finding something, a key, a treasure or a lift pass, is 1, and so is arming a detonator. A shot that hits something useless is 2, a shot at a locked door 3, healing 4 and firing 5. Unlocking a door with a key is 6, and the explosives in a chest going off 7. A guard killed is 8, and so is the object worth 2500 that $67FD breaks; a shot that opens a door or hits a pickup is 9. The footsteps are separate, on voice two, and alternate between two pitches as the player's walking frame flips.

Voice three has another job. When a game starts, $67CA sets it to noise at the highest frequency, reads its own oscillator 256 times into a table at $8700, and silences it again. That table is the game's dice: the chip's noise generator, read once a game and kept, and the chests are the only thing that ever throws them (Discoveries).

04 · One frame

The screen, rebuilt from memory

Not a screenshot. This is the play screen drawn from the bytes in the listing, the way the video chip would read them.

One frame of play recorded in VICE: the video chip's registers as the frame began and every write to them afterwards, with the memory the drawing reads. All 104,448 pixels match the emulator's own picture of the same frame.

The picture is drawn twice in one frame. Everything on the screen is made of characters, as on a typewriter, and the shapes those characters take come from a character set the game supplies. This game has two. The set at $2000 holds the castle's walls and floors, and the set at $2800 holds the letters the message line at the bottom is written in.

The video chip can point at only one set at a time, so the game moves the pointer part way down the screen. It does that with an interrupt: a routine the chip starts itself when the beam drawing the picture reaches a line the game has named. In the recorded frame the set changes on line 228, just below the play area, and multicolour is turned off there for the message line.

The play area itself mixes two modes, chosen cell by cell from each cell's colour: the walls are drawn in hires and the floors in multicolour. The Graphics tab takes the screen apart that way, with both character sets and the sprites.

05 · The castle

A floor is stored as one byte for each block of its map

A floor of the castle is 128 tiles across and 128 down, 16 kilobytes of map. The tape stores it as one byte for every block of four tiles by four: a kilobyte.

Block
One block, four tiles by four.
The basement, built from its description. Each block above is one byte of it.

Drawn from the listing: the description at $D000, the blocks at $7000, the tiles at $2000 and their colours at $8600. All four floors are on the Maps tab, at full size.

The description is 32 rows of 32 bytes, and every byte names one of the blocks kept at $7000. A block is sixteen bytes: four tiles across and four down. The builder at $6A4B works through the description, copies each block's sixteen tiles into the map at $9000, and so turns a kilobyte into sixteen.

The map is too big to live anywhere the video chip can see it, so the game keeps it at $9000 and draws the 28 tiles by 21 the screen shows from it, one row at a time. The descriptions themselves are stored under the input and output chips at $D000, in the memory the C64 keeps there behind them, and the builder switches the chips out of the way to read them.

Some bytes of a description mean more than a block. $30 to $37 are guards, a pair of bytes for each of the four directions a guard can start out walking, and every one found is added to a list of figures.

06 · The player and the guards

The player is in the map as well as in front of it

He is drawn with sprites, and also stamped into the map as a tile, for the length of one interrupt.

Show
The tiles round the player, as the map holds them.

The sixteen tiles the player's square covers, before and after $5B1B stamps tile $55 over them. The grid is read from the map at $9000 by $5C55.

The player is drawn with four sprites, two across and two down. A sprite is a small picture the video chip draws wherever the program puts it, over the top of everything else, and the C64 has eight of them. The four are placed round a position kept in $02DF and $02E0, and his twelve poses are on the Graphics tab. He moves 8 pixels, one tile, every four frames, and a move is allowed only when the four tiles he would cover all have a code below $2D. Everything from $2D up is a wall, a door, furniture, a guard or something to pick up.

The guards are not sprites. They are drawn into the map as tiles, like the walls, and they move by the same rule: the four tiles ahead must be empty. That leaves the game with a problem, because a sprite is not in the map and a guard checking the tiles ahead would walk straight through the player.

The answer is $5B1B. Before the guards take their turn it writes tile $55 over the sixteen tiles the player covers, keeping what was there in four small buffers; after they have moved, it puts the sixteen tiles back. A guard that finds $55 ahead of it has found the player, and that is the only way the player is ever hurt.

There is no shooting from the guards at all. $639F is the one routine that adds to the hit count, and its four callers are the four branches of the guards' movement where the tile ahead holds the stamp. The manual says the soldiers shoot and do great damage; in this version they walk into you, one hit at a time, and fifty hits end the mission.

07 · Controls

One joystick and one key

ControlWhat it doesWhere
Joystick, port 2Walks one tile every four frames. The direction is also the direction a shot goes.$4297
FireShoots, and spends one round. Two shots can be in the air at once, the second once the first has taken eight steps of 8 pixels.$45BD, $463F
SPACEPauses, and pauses again to carry on. The message line reads ...PAUSING....$5FCB, $4899
RESTOREAbandons the game and returns to the attract loop.$8031

Every one of these was tried in the emulator from a snapshot of play, one input at a time.

The game does not use the KERNAL's keyboard scan. Its own interrupt never passes control to the system's handler, so the keyboard is never read for it, and the pause key is read by hand: $5FCB drives one row of the keyboard matrix and reads one column, which is SPACE, and leaves the answer in $C5. That is the byte the KERNAL itself uses for the last key it saw, borrowed for a single key.

08 · The loader

The tape loader does all its reading in an interrupt

Interceptor Micros' "WILD SAVE", signed by Andrew Challis, the game's own programmer. The processor waits in a loop of one instruction while every pulse off the tape interrupts it.

Tape timeBlockBytesWhat it is

Every block on the tape, read from the tape image by the loader's own rules. All sixteen checksums are good, and 49,728 of the 49,729 bytes that reach RAM are what memory holds when the game starts; the other is changed by the game before then. Point at the tape or a row for what each block is.

The KERNAL, the machine's own system, loads the first file in its own format: half a minute of tape that brings the turbo loader with it. The loader switches the KERNAL out, points the interrupt vector at its own code at $0100, and leaves the processor in JMP $02E8. Every pulse from the tape interrupts it. The handler reads CIA 1's timer and restarts it: a pulse longer than about 480 cycles of the processor's clock is a 1 and a shorter one a 0, and on this tape they are about 390 and 580. The border is dark grey only while the handler runs, which is what draws the loading stripes.

A block starts with five bytes, its last address, its length and a flag, and its data comes in from that address downwards, each byte XORed with the low byte of the address it goes to. A checksum closes it, and a wrong one turns the border into a cycle of colours that never stops. A flag of 0 writes with the input and output chips switched out, which is how the four floors reach the memory behind them at $D000.

Some of the blocks are a single byte, and they land in the video chip and CIA 2: that is how the title picture is switched on, with no code for it at all (Discoveries). The last block is 89 bytes over the loader's own set-up, written while the processor waits in it; it keeps JMP $02E8 at the same address, so the waiting loop never notices, and it is what the end of the tape jumps into.