1990 · Domark

Castle Master

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/castle-master with me to Gold.

A castle of 33 places built from boxes, pyramids and flat panels, every door, key and potion of it run by 193 small scripts in the game's own language, and one music driver that plays both the theme and every sound effect.

01 · The game

Castle Eternity

Castle Master is a first-person adventure in solid 3D, drawn by Incentive Software's Freescape engine. The prince or the princess, as the player chooses at the start, comes to Castle Eternity to rescue a twin held in one of its towers by the Magister, who means to make spirit slaves of them both. The player walks, runs, crawls, turns and looks up and down, throws rocks, and uses an action key to open, push, eat, drink and read.

The castle is the Wilderness outside, the Courtyard, 26 rooms, and five caverns. Doors are opened by finding ten keys and by solving riddles carved on panels, and the twin's door in the Magister's room opens only to a player holding all ten. On the way the player's strength runs down, guardian spirits wait to be destroyed, and three potions wait to be found. A game ends when strength runs out, in a fatal fall, when the spirits overpower the player, or when the twins escape together.

The C64 version was published by Domark in 1990. Ian Andrew designed it; Chris Andrew, Paul Gregory, and Sean Ellis programmed it; Mike Salmon and Team 7 drew the graphics, Mel Croucher wrote the story and the riddles, and Teque Software Development wrote the music (the manual's credits).

The loading picture: the castle on its hill
The picture shown while the game loads, drawn from the disk's own bytes on Graphics.
The first view of play: the castle seen from the Wilderness
The first view of play, from the Wilderness.

02 · The sound

Music: one driver plays the theme and every effect

Every sound in the game is a tune of the same driver: the title theme, the escape's tune, and fifteen short effects. The player below runs the game's own driver.

The driver's code and its state, $C800-$CFFF, and its tables, $065A-$1046, run inside the page, called as the game calls them: SID_PLAYER_INITIALIZE ($CF1B) with the tune in A, then SID_PLAYER_TICK ($C885) once a frame.

The sound menu, F on the information screen, switches between music and effects ($123A). With music on, the theme loops through play, started again whenever it ends ($7393), and the effects are never heard. With effects on, every request goes through SID_INITIALIZE_IF_ENABLED ($CFD8), which plays effect n as tune n + 1. The game asks for them from these places:

TuneEffectAsked for by
21scripts
32RUN_VIEWPORT_TRANSITION ($8306, $8363) and scripts
43movement ($5F46), centring the sights ($634B), the information menu ($79DD), $4A2B, $834B and scripts
54scripts: the three potions, and the 13 objects that give 4 strength
65a rock thrown ($63B5) and scripts
76nothing
87every move to another area ($6CE0)
98lightning ($484F), a fall ($8164) and scripts
109nothing
1110scripts: a key found
1211scripts: a door opening, and the treasure chest
1312walking into something ($53D1, $54A1)
1413moves to another area once the escape has begun ($6D3D), and scripts
1514scripts
16–the sensors' alarm, started directly by the raster interrupt in effects mode ($73A1); it has a bug of its own

Effects 6 and 9 are in the driver and the game never asks for them. Tune 1, the escape's, is started by the script that sets flag 31, which also turns the switch to music ($6C70).

03 · One frame

One frame of play, rebuilt from memory

The first view of play, drawn by this page from the bytes of the video chip, the bitmap, and the colour memory as the frame began.

The first frame of play in the Wilderness, drawn from the game's memory and the video chip's registers.

Everything but the view is loaded once, from the files CNBMAP, CNCOL1 and CNCOL2, and stays: the towers, the title, the strength and spirit gauges, and the line of text. The VIC shows a multicolour bitmap at $E000 with its colours at $C400, and the game never moves either. The 3D view is 120 by 120 pixels, each pixel two wide on the screen. It is drawn into a buffer of its own, 120 rows of 30 bytes at $87CC-$95DB, and only then copied into the 30 by 15 character cells of the bitmap that start at $E528 (BLIT_LINEAR_BUFFER_FORWARD_TO_VIC_BITMAP, $65E7), so the reader never sees a half-drawn room.

Inside the buffer the objects are drawn whole, farthest first, from a sorted queue. Each kind of shape has its builder: cuboids at $2D20, pyramids at $2F21, lines and polygons at $32E1, and flat rectangles at $33A3. The projection at $3C05 puts the centre of the screen at (60, 60) and clips each face to the view's edges before it is filled.

04 · The castle's database

Each area is a list of objects, and each object can carry a script

The whole castle is one block of 8,848 bytes at $9D00-$BF8F: 34 areas, 546 objects, and 193 scripts. Pick any object to see its bytes.

Read from the listing by the same code as the Maps tab, where every area is drawn.

A directory of 34 offsets at $9D4F finds each area's eight-byte header: the fills of its sky and floor, its object count, its id, where its own scripts begin, its scale, one of the four colours of its view, and the slot of its name among the messages. The objects follow, each with its type in the low four bits of the first byte and its state in the high four ($40 hidden, $20 destroyed), a position and a size in units of 64, an id, and its length. The type decides how many bytes of shape come next: the face colours of a cuboid, a pyramid's top, a polygon's corners. Whatever is left of the record after that is its script.

One area, with the id 255, is not a place but a store of 100 shared objects: 58 cuboids, six of which (128 to 133) stand in 21 to 29 areas each, the three spirits, and 22 entrances, some of them holding the scripts that many objects hand over to. When an area is entered, $7C5A hides all 100 and then shows the ones named by a list in the area itself, an object of type 0 with the id 255 that is not a script at all. 31 of the 33 areas carry one.

The scripts

A script is a run of tokens. The low six bits of a token's first byte are its opcode, and the top two say which event it waits for: a move, the 10-second timer, a shot, or the action key. An object's script runs when the player walks into it, shoots it, or acts on it; then the five global scripts run, then the area's own (DISPATCH_FRAME_CONDITIONS, $4A58). FCL_TOKEN_LENGTHS ($13AE) gives 39 opcodes a length, and the castle's scripts use 29 of them: they add to the score and to strength, show, hide and destroy objects here or in another area, keep flags and variables, test them, print messages and riddles, play sound effects, wait, redraw, and move the player to another area.

The opcodes
OpcodeArgumentsWhat it does
$01n, 24 bitsadds n to the score
$03 $04 $05objecttoggles, shows, or hides it, unless it is destroyed
$06 $07 $08area, objectthe same in another area
$09 $0Avadds 1 to, or takes 1 from, variable v ($2438 + v)
$0Bv, ntests that variable v is n
$0C $0D $1Dbsets, clears, or flips flag b, one bit of $2439 onward; setting flag 31 starts the escape's tune
$0Eb, ntests that flag b is n
$0F $1Cnasks for sound effect n, at once or with the next picture
$10 $11object; area, objectdestroys it
$12area, entrancemoves the player there, paying 17,500 for a first visit
$13n, signedadds n to strength, up to 24
$14v, nsets variable v to n
$1Aredraws the view
$1Bnwaits n ticks of the game clock, 60 to the second
$1E $1Fobjecttests that it is visible, or hidden
$20 $21area, objectthe same in another area
$22nprints message n, or with the top bit set a riddle panel
$23nnothing
$2C $2Delse, end if
$2E $2Fv, ntests that variable v is above, or below, n
$30objectruns that object's script instead of the rest of this one

From EXECUTE_FCL_STREAM ($68F5-$6FBC), with the five the castle never uses: $0A, $11, $1D, $20 and $21. A test that fails skips every later token until an else or an end if, and there is no nesting. Variables and flags share their bytes: variable 29 is strength and variable 31 the keys collected, and the flags 1 to 8 are variable 1.

05 · Strength, keys and spirits

Strength drains, and the spirits keep time

Two gauges end a game: strength, kept at $2455, and the spirit meter, which fills with time.

Strength
16at the start, the database's byte $9D05 ($4E3C)
24the most a script can give ($698C)
−1every 10 seconds in an area with a sensor that is not hidden, wherever the sensor is ($7545)
−1AAAAAARRRGH!, shared object 206, from the Smithy, the Carpenter's, and shared object 208
−5a fall of the area's scale times 2 ($7758): at least that when the world changes under the player (DROP_PLAYER_TO_SUPPORT, $81F4), more than that in the collision response to a move ($53BC); both call $8142
−128GLUG GLUG GLUG, the Wilderness's object 3 and the Hot Baths' object 17
+1every 10 seconds in the Hospital while strength is below 12, the area's own script
+1each drink of the potion of strength in the Stores, up to 64 (variable 25)
+1every 10 seconds, 64 times, after the potion of revitalisation (global script 4)
+4each of 13 objects in nine areas, six of them in the Kitchen and the Larder, which hand over to shared object 214

Strength at 0 ends the game with YOU COLLAPSE ($699D, $71E8), and a fall with less than 5 left with FATAL FALL ($8152). Live: in the Magister, with its one sensor, strength fell from 16 to 13 in 30 seconds.

Score
6,250each drink of the potion of strength
17,500the first visit to each area, paid by script opcode $12 ($6D1B-$6D2D)
22,500each of the 13 objects that give strength (shared object 214)
37,500treasure found (shared object 216, from six places)
75,000each spirit destroyed (shared object 215)
125,000each key collected ($70EE)
400,000the potion of revitalisation, and the potion of rock travel
3,000,000the escape (the Magister's object 5)

The ten-key door is the Magister's object 11. Its action script tests variable 31, the keys collected, for 10: then it prints THE DOOR OPENS, hides the door, objects 10 and 11, and shows object 5, the panel whose move script is the escape. Otherwise it prints NEED TEN KEYS.

The spirit meter is a clock. $246A starts at 32 and goes up one step every two minutes; the meter shown is that clock times (21 − spirits destroyed) / 21, and at 64 the spirits win: OVERPOWERED. With no spirit destroyed that is 64 minutes after the start, and every spirit destroyed buys time.

19 of the castle's 21 sensors have the id 125, 126 or 127, and global scripts 1 to 3 put up one of three shared spirits in any area where such a sensor still stands. Shooting the spirit destroys the sensor, which stops the drain, and runs shared object 215's script, which adds 1 to variable 28, the spirits destroyed, and 75,000 to the score. The meter's arithmetic goes wrong after 127, which Discoveries plays out.

06 · Controls

Twenty-two keys, read from one table

READ_CONTROL_INPUT ($75C3) keeps up to six codes a frame ($137A-$137F), and $48C1-$48E2 looks each one up in the 22 pairs at $1382, the joystick's included.

Built from the 22 code and action pairs at $1382-$13AD; the count, 22, is $1381. Actions 1 to 20 go to DISPATCH_PLAYER_MOVEMENT ($5DD8) and 21 to 30 to DISPATCH_AIM_FIRE_ACTIVATE ($62E8). A turn is three steps of 5° ($9D4C), or 18 with the Commodore key held ($6072-$6091); live, a press of X took the heading from 28 to 31 and swung the castle to the left of the view. With the pointer on, the four direction keys move the pointer instead ($4901-$490C).