1985 · Mastertronic (M.A.D.)

Master of Magic

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

Master of Magic settles every spell without rolling a die, gives the second vampire your own to-hit score for a defence, and sends its monsters wandering north from homes the game wiped. The instructions mention none of it.

01 · Magic

Secret: spells never roll the dice

The instructions promise that Magic Missile has a high chance of missing. The code fetches a random number for it and throws it away.

; $3AD3 spell_hit_creature jsr $2B9E ; a random number into A lda #$1F ; ...overwritten with 31 clc adc $57D4 ; + the spell's power ldx $03A7 cmp $4DC7,x ; against the target's defence bpl hit

MAGIC MISSILE has power 20, FIREBALL and ENERGY DRAIN 60. Cast from six different random states, each gives the same result every time.

So a spell either always hits a creature or always misses it. MAGIC MISSILE always hits everything but the first vampire and the minotaur, which it always misses; FIREBALL and ENERGY DRAIN miss only the minotaur. The cost in mind is paid before you pick a target, so choosing -NOTHING- still spends it. The Magical Shield takes 8 off every creature's roll and a point of mind every 100 passes, and while it is up the menu offers UNCAST instead of CAST, so no other spell can be cast.

02 · Fighting

Bug: the second vampire's defence is your to-hit score

Strength, defence and to-hit are three tables of 64 entries, indexed by entry number. They were placed only 62 bytes apart, so the last two entries of each, the second vampire and the minotaur, are the first two of the next. The second vampire's defence is the player's to-hit score, 25, where the first vampire's is 60, and the minotaur's defence is to-hit entry 1, an unused object slot that holds 133. Every blow is a roll against one of them, the defender's defence (Fighting).

With a defence of 133, no roll reaches the minotaur, and the Dagger of Death is the only way through: $2B93 replaces the roll with the minotaur's own defence, a certain hit, and $2B26 makes the damage 30. The first vampire, at 60, is out of reach of a roll that tops out at 56, unless you wear the Ring of Dexterity, which adds 8.

03 · Weapons and armour

Bug: the mace and the dagger of wood never get their bonus

The routine that adjusts a roll for special weapons has two tests that cannot pass. Each asks whether one register equals two different values in turn:

; $2B60: the weapon ($03A8) is a mace, and the target a skeleton or hellhound? lda $03A8 cmp #$16 ; mace 1? bne $2B78 ; if not, skip cmp #$17 ; ...and mace 2? A is still $16, so no bne $2B78 ; always taken: the +8 below is never reached cpx #$28 ... adc #$08 ; $2B7B: the dagger of wood against either vampire cmp #$05 bne $2B8C cpx #$3D ; target vampire 1? bne $2B8C ; if not, skip cpx #$3E ; ...and vampire 2? X is still $3D, so no bne $2B8C lda $4E04 ; the roll = vampire 1's defence: a certain hit

The protection routine $24F1 has the same shape for the shield, three compares in a row against $1E, $1F and $20, so a shield never protects. Its other tests read the wrong table: the object's "can be worn" flag, which is always set for armour, helmet and rings, instead of its state in $4AC1, which says whether it is worn. So armour protects you while you only hold it in a hand, and the ring with the blue stone, the one the scrolls call cursed, makes monsters hit more often whenever you hold it.

04 · The monsters

Bug: the monsters' homes are wiped, so they wander north

The instructions say most monsters patrol round their lair. The code gives every creature a home to walk back to when it is not hunting you, and the new-game routine wipes half of each address.

A port of the creature clock $2205, the decisions $2308 and the move chooser $2566.

The home addresses live in two 31-byte tables at $4CAE and $4CCD. The set-up at $0924 clears two flag tables next to them with a loop that runs for 64 entries, so the first store runs on through every home's high byte. A home of $00ll is a page-0 address above the top of the map, and an idle creature heads for it: first towards its start column, then due north, and then back and forth under the northernmost wall it can reach. The file was saved after the game had already run once, so the loaded homes are already wiped. Seven creatures ignore their homes and get a random destination every 50 passes. In the game, 53 seconds in, 17 of the 24 that do not wander were north of their starting row; the port above reaches the same 17 at the same moment.

A creature that sees you re-arms a pursuit counter: bats give up at once, orcs after 6 decisions, skeletons 20, vampires 30, the wizard and the minotaur 60. Chasing, it walks to where it last saw you and carries straight on. Orcs, skeletons, vampires, the wizard and the minotaur open a shut door in their way and close it behind them; hellhounds, bats, spiders and snakes treat it as a wall. One snake is timid: it runs from you and never attacks.

05 · The demonstration

Secret: the demo recorder is still in the game

After one pass of the title's story the game plays itself. It does it by replaying a recording of joystick input from $A543, with the random numbers reset to where they were when it was recorded.

The recording, one byte per run of identical input: the stick in the high four bits, the number of polls less one in the low four. . It ends with an idle stretch and the end mark the recorder writes when its buffer runs out.

CTRL with R on the title screen starts a recording. $5BBA saves the random state and starts a game in which every input is written over the demonstration, and F ends it. The next time the title's story runs out, the demonstration plays the new recording, through the same cells to the same pixel.

The recording is also the best test there is of a port. The Play tab runs the whole game in JavaScript; fed this recording poll by poll, it reproduces the real game's run through the demonstration, every one of its 2,371 world passes, byte for byte.

06 · Doors

Secret: the edge of a pool is a door

The menu decides whether you stand on a door with a signed compare ($11E5: CMP #$F0, BMI), so any character below $70 passes too. On level 2 the top edge of the big pool is two such cells, floor except for a line of water, and standing on one offers OPEN. Choosing it prints "OPEN DOOR." and spends eight passes; the door routine checks for real door characters and changes nothing.

The menu offering OPEN at the edge of the pool, and OPEN DOOR. in the messages

07 · Secrets, quirks and bugs

Things the manual never told you

A reset leaves BASIC switched in live

The game catches RESTORE and the reset button with the CBM80 signature at $8004, and both restart it. After a reset, though, the processor's data direction register is zero, and the restart never sets it again, so switching BASIC out has no effect. The game's tables at $A000 read as BASIC ROM: the title comes up in the wrong colours and the view window stays empty.

The title after a reset, colours scrambledA game after a reset, the view window empty

The first game after loading rolls different dice

The random numbers depend on two indices that step by +1 and −3, so the sequence repeats every 256 numbers, on one of 256 separate cycles. The demonstration resets them to its own starting point, and every game after it continues on that cycle. A game started straight after loading, before the demonstration has ever run, starts from the indices saved in the file and runs on a different cycle, with different odds: the wizard is hit 45 % of the time instead of 47 %.

Two descriptions nobody can read

EXAMINE picks one of 28 descriptions through a table at $571E. No entry points at text 3, "THE WRITING ON IT SAYS -THE SAPPHIRE IS CURSED, IT BRINGS BAD LUCK-", or at text 5, "IT HAS A SHARP EDGE AND A LONG BLADE". The warning about the cursed ring is in the game and can never be shown.

The wizard who will heal your wounds

A scroll says "THE KIND OLD WIZARD LEGGOLESS WILL HEAL YOUR WOUNDS", and EXAMINE calls him "A SHORT HARMLESS LOOKING WIZARD". Nothing in the game raises your body strength except the two healing potions, and the wizard's FIREBALL SPELL does 3 to 18 damage, the hardest blow of any creature. Two other scrolls say the Dagger of Death "WEAKENS HIS MIND"; in the code it takes 30 from the minotaur's body.

The title screen re-enters its interrupt 126 times a frame live

The title's interrupt handler $5D08 acknowledges the video chip and leaves at once when the interrupt came from somewhere else, without acknowledging the CIA timer that sent it. The timer keeps asking, so the processor enters the handler again and again until the KERNAL's exit, later in the frame, finally acknowledges it. Over 100 frames of the title the handler ran 12,685 times, 12,586 of them for nothing.

A timed action cannot be cut short live

After every action the pass loop tests the fire button, as if pressing it could end the action early. It can only end RUN: nothing reads the joystick during the other actions' passes, so the test never sees fire. INVENTORY took its 12 passes with fire held all the way through.

A machine-code monitor left in the middle

Between the menu verbs and the nouns, $41D9–$4587 holds 943 bytes of a machine-code monitor, the kind with commands for memory, assembly and disk: nothing calls it, and its own jumps land in the game's tables. Its remains also fill the unused object slots of several creature tables, among them its disassembler's table of addressing modes at $4F06.