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 spirit count that stops mattering after 13, a potion that can be drunk 64 times, an alarm that never gets past its first frame, and an escape that pays for a tour of the castle.

01 · The spirit meter

Bug: destroy 13 spirits and the spirits can never win

The spirits overpower the player when their meter reaches 64. 192 minutes into a game the meter's arithmetic overflows, so destroying 13 of the 21 spirits is as good as destroying them all, and 11 or 12 end the game sooner than they should.

The solid line is the meter as the game works it out, through the port of $7286-$72A9 in this page; the dashed line is the same sum done without the overflow. In the game, with 11 and with 12 destroyed the game ends as the clock goes from 127 to 128; with 13 and with 20 it does not.

The meter is a clock. $246A starts at 32 and goes up one step every two minutes, and the meter is that clock times the spirits still free, 21 minus those destroyed, divided by 21 (Strength, keys and spirits). With no spirit destroyed the meter reaches 64 at 64 minutes. Each spirit destroyed slows it down.

The multiply at $2643 treats the clock as a signed byte. From 128, which the clock reaches 192 minutes into a game, the clock reads as a negative number, and so does the product. The divide at $259F is then given the product as an unsigned 16-bit number. With 11 destroyed, 128 reads as −128, the product is −1,280, $FB00, and 64,256 divided by 21 is 3,059, $0BF3. The game compares only the low byte, $F3, and that is over 64, so the game ends at once. With 13 destroyed the product is −1,024, $FC00, and 64,512 divided by 21 is exactly 3,072, $0C00, whose low byte is 0. Below 128 the meter could never get past 48 with 13 destroyed, and above it the low byte never reaches 64 again, so those spirits can never win.

02 · The Stores

Secret: the potion of strength can be drunk 64 times

The potions of revitalisation and of rock travel vanish once drunk. The potion of strength in the Stores stays where it is, and pays 6,250 points and a point of strength every time, 64 times over: 400,000 points, as much as either of the others.

0
Score17,500
Strength16
Variable 250

From a new game, a jump to the Stores (17,500 for the first visit), then the action on the potion 70 times, 150 frames apart, reading the score ($2442), strength ($2455) and variable 25 ($2451) after each. Strength stops at 24, the cap of script opcode $13; the score and the count stop at the 64th drink.

The potion is the Stores' object 4, and its action script is the whole of the mechanism. A test on variable 25 guards everything else, and the script adds 1 to the variable each time, so the 65th drink finds the count at 64 and does nothing. None of the other script tokens reads or writes variable 25, and a new game clears it ($4E27-$4E2D). The other two potions hide themselves instead.

A shot breaks it, as it does the others: SMASH!!, and objects 4 and 5 are destroyed.

The Stores' object 4, read from the listing. The Stores on the map.

03 · The alarm

Bug: the alarm never gets past its first frame

With sound effects on, an area with a sensor sounds an alarm. The raster interrupt starts the alarm's tune again on every frame, so only the tune's first frame is ever heard, fifty times a second.

The game's own driver, as on How it works. The first button plays tune 16 from its start to its end, 49 frames. The second plays it as the game does: SID_PLAYER_INITIALIZE ($CF1B) with 16, then SID_PLAYER_TICK ($C885), every frame.

The raster interrupt does one of two things before it ticks the driver ($738E-$73B0). With music on, it restarts the theme whenever the driver has stopped. With effects on, it checks ACTIVE_SENSOR_COUNT ($109A), the sensors in the area that are not hidden, and while there are any and the game is running it calls the driver's start with tune 16. The start takes no notice of a tune that is already playing, so every frame begins tune 16 again.

In the Magister, with its one sensor, each frame the start wrote $00, $FF and $FE to the three voices' control registers, and the tick then wrote the tune's first frame, frequency $45A0 on voices 1 and 3 and $8B40 on voice 2. With music on, the theme played on and the alarm never sounded.

04 · The escape

Secret: the escape is a tour of ten areas, and it pays for them

Through the door that ten keys open, the Magister's object 5 adds 3,000,000 to the score. The same script then carries the twins through nine areas of the castle and out to the Wilderness, and each area pays 17,500 if this is the first time the player has been there.

From a new game, a jump to the Magister, then the move event on object 5. Each picture is the 3D view as the tour left that area. The score ended at 3,192,500: the escape, the Magister, and ten first visits.

The tour is ten GOTOs in one script, each followed by a redraw except the Hospital's, which the script enters and leaves before a picture is made. Every GOTO marks its area as visited and pays for a first visit ($6D1B-$6D2D). The Wilderness always pays at least once in a game: the player starts there, but the start never marks it as visited.

05 · The sensors

Secret: a sensor drains strength from anywhere in its area

Every 10 seconds the game takes a point of strength if the area holds a sensor that is not hidden. Where the sensor stands and where the player is make no difference.

The 21 objects of type 2, read from the listing. All of them stand at 0, 0, 0 with no size. The count of sensors is made each time the view is rebuilt ($27C6-$27D7) and the drain is in the interrupt ($7545-$754F). In the Magister strength falls from 16 to 13 in 1,500 frames, 30 seconds.

A sensor is stopped by destroying its spirit. 19 of the sensors have the id 125, 126 or 127, and the first three global scripts put up one of three shared spirits wherever such a sensor stands. A shot spirit destroys its sensor too, and once an area has no sensor left, its drain and its alarm stop. The other two have scripts of their own. The Courtyard's sensor appears with its spirit when the Courtyard's object 30 is shot. The Dragon's Lair's is hidden, with 13 other objects of the lair, once the lair's object 9 has taken 21 shots, which count only after 20 spirits are destroyed; that makes the 21st spirit.

06 · Left over

Secret: two sound effects and a message the game never uses

The driver has two effects that none of the code or scripts asks for, and the messages hold one line that the game never prints.

Tunes 7 and 10, effects 6 and 9, on the game's own driver.

Message 9, at $1490:

CHOMP CHOMP AHH

None of the script tokens prints message 9, and none of the instructions names it. Shared object 214's script, which 13 objects hand over to for 4 points of strength, prints nothing.

Every request for a sound passes its number straight to the driver: the code's own calls, the deferred request that a fall, a collision or a move to another area leaves for the next picture, and the scripts' two sound opcodes (the table on How it works). None of them asks for effect 6 or effect 9. The search covered every call to the driver's start, every write to the deferred request, and the castle's 809 script tokens.