1990 · Blade Software

Lords of Chaos

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/spectrum/lords-of-chaos with me to Gold.

Lords of Chaos loads the first file on the tape that starts with the right letter, lets lava burn only the players' creatures, sends the computer's creatures into solid rock, can lock up for good when the computer's wizard stands on a big pile of objects, and still holds a breakpoint its authors could stop the game with.

01 · Loading

Bug: LOAD takes any file that starts with the same letter

The game reads the name on each file it passes on the tape and stops at the one you asked for. It only ever compares the first letter.

The scenario's file panel with FILE NAME: MERLIN1 typed under the menu
LOAD WIZARD, file name MERLIN1.
The file panel showing LOADING: MORDRED2.WIZ
The first file on the tape is MORDRED2.WIZ, and the game loads it.
The file panel's wizard list with MORDRED at level 2 in the first slot
MORDRED, level 2, takes the slot meant for MERLIN.

A tape holding four copies of MORDRED2.WIZ and then MERLIN1.WIZ. A loader that compared the whole name would have passed all four MORDREDs.

The tape, one file to a line

Each line is a file's header as the game saves it. The page follows find_file ($C675).

The name you type becomes twelve characters, eight for the name, a dot and the extension, and find_file reads the twelve-character header of each file on the tape into found_name ($C6B2). It loads B with 12 to count the characters, then compares the first pair and never counts or moves on. So the comparison passes on the first letter alone, whatever the rest of the name and whatever the extension.

A tape with one file to a letter loads as it should, which is how a player would usually keep one. Save MERLIN at level 1 and again at level 2 on the same tape, and asking for the second one loads the first.

02 · Slayer's Dungeon

Secret: everything the computer moves is immune to lava

The river of molten lava in scenario 2 costs no more to cross than a floor. A creature you move into it loses 7 points of constitution; the dungeon's own monsters and the computer's walk through unharmed.

The scenario hooks a routine of its own into every step ($E1F0, called through $D021 by select_ground for a player's step and by computer_step_move for the computer's). Its first test is computer_moving ($D063): while the computer moves, it returns before it looks at the terrain. The six lava terrains, $18 to $1D, have a step cost of 4 and nothing else in the scenario hurts a creature standing in them, so the independent creatures and the computer's wizard's take the lava as a road. A SPECTRE moved by a player loses 7 points in the lava, and one moved by the computer loses none.

03 · Slayer's Dungeon

Bug: three of the dungeon's routes lead into solid rock

The computer walks its creatures along routes, from one waypoint to the next. Three of scenario 2's routes name a waypoint the scenario never wrote down, and the square the game finds for it is rock.

Scenario 2's map round row 8, column 7, drawn the way the game draws its map window. The red square is where waypoint 28 lands. Maps draws the routes whole.

In a game against the computer, ELBO SMOGG's creatures each take one of the scenario's first seven routes, chosen at random until one suits the creature (add_to_wizard_list, $A4FA). Routes 0, 2 and 6 all pass through waypoint 28. The table of waypoints ($D4AD) holds 28 of them, numbered 0 to 27, and the independent creatures' orders come straight after it. waypoint_square ($9971) finds a waypoint by adding twice its number to the start of the table, with no check, so waypoint 28 is the first two bytes of those orders, 8 and 7: row 8, column 7.

That square is ROCK WALL, which costs 255 action points to enter, the mark of a square no creature may walk into. Only a ghost, which pays 4 for any square (classify_step, $CA2B), could stand there. computer_choose_target ($9992) moves a creature on to its next waypoint only once it stands on the one it is heading for, so a creature on one of these routes never gets past the rock: whenever it follows its route, it heads for row 8, column 7, until the portal opens and it makes for that instead. Beside the rock, the creature's target stays row 8, column 7; standing on it, the creature would move on.

04 · Potions

Bug: the strength vials lying around wear off in three turns

Every vial the game scatters at the start gets a random strength from 0 to 7, except the strength vial. Its strength stays at 255, and in the game's arithmetic that is weaker than 0.

The turns a potion from a vial lasts, by the vial's strength, for each potion consumption the creatures of scenario 1 have. The page works them out as the game's drink ($73D0) does. In a game of scenario 2, the two strength vials on the map held 255 and the other vials 4 to 7.

The start-up routine that scatters objects ($FE03) gives byte 5 of each object from $74 to $7B a random number below 8, which is a vial's strength. That range takes in the two chests at the top and leaves out $73, the strength vial at the bottom. Its byte 5 keeps the 255 the scenario's first hook filled the whole table with.

Drinking works out the potion's length as the strength times 3 plus 10, divided by the creature's potion consumption. For strengths 0 to 7 that is 10 to 31 before the division, which just fits the five bits the creature record keeps it in. For 255 the sum is 775, and in eight bits it is 7. A wizard, consumption 2, gets 3 turns of strength from a vial found on the floor and 5 to 15 from any other. A dragon, consumption 10, gets 0 turns. Strength vials filled from a cauldron (FILL) carry the cauldron's strength and are not affected.

05 · The designer

Bug: leaving the designer throws away up to three experience points

A wizard's record keeps its score, not its experience points. The designer turns one into the other and back by multiplying and dividing by four, and the remainder is lost.

The designer's CHARACTER screen: EXPERIENCE=597 after raising CONSTITUTION to 35
600 points, less 3 for a point of constitution: 597.
The design menu with EXIT highlighted
EXIT.
The CHARACTER screen again, EXPERIENCE=596
Designing the same wizard again: 596.

MERLIN at level 1.

Opening a wizard in the designer sets its experience points to four times its score ($E0C0). EXIT stores the points left divided by four, rounded down, as the score ($E17E). Every visit to the designer that ends on a total that is not a multiple of four loses the difference. A new wizard's mana, action points, stamina and magic resistance cost 8, 8, 4 and 4 a point, but constitution costs 3 and combat and defence 2, and a spell such as GOLD DRAGON 47 plus 23 a level, so it is easy to leave on 597.

06 · The computer's turn

Bug: a pile of more than ten objects can stop the game for good

The list of what lies on a square has room for ten objects. A computer creature that wants one past the tenth goes on looking beyond the end of the list, and takes whatever it finds there for the object. In one game against the computer the search ended inside the instruction that moves play on to the next wizard, and the game never came back from the next menu.

The computer's turn panel: WIZARD TORQUEMADA, TURN 23, PORTAL 4, WIZARD1 0, TORQUEMADA 24
Turn 23. TORQUEMADA, the computer's wizard, stands on fifteen objects and wants the magic mushroom.
The menu CONTINUE, SAVE GAME, ABANDON GAME on a black screen
The end of the turn: CONTINUE.
A black screen
Then a black screen, for good.

A game of scenario 1 against the computer, 52 minutes in. In the 600 frames after CONTINUE the game went round its turn loop 32 times, and SPACE, ENTER, 0, 5 to 8, Q, A, O, P and M changed nothing.

#objectentryin the list
1AMBERGRIS$0Fyes
2CLOVER$15yes
3AMBERGRIS$16yes
4CLOVER$19yes
5CLOVER$1Eyes
6CRYSTAL$1Fyes
7CLOVER$20yes
8CRYSTAL$22yes
9CLOVER$25yes
10CAULDRON$2Ayes
11CRYSTAL$2Bno
12MAGIC MUSHROOM$2Cno
13AMBERGRIS$30no
14FAIRY WING$49no
15MISTLETOE$4Cno

The objects lying on TORQUEMADA's square, row 24, column 17, in the order of the table of things on the map, read from the game's memory at the moment of the screenshot above.

list_objects_at ($67A7) goes through the table of things on the map ($5B5A, six bytes each) and writes each object lying on the square into a list at $D1D4, its entry number and then its type, and stops when the list holds ten ($6819). When a computer creature reaches the object it is after, computer_pick_up ($A0F0) looks for the object's type in that list, every second byte from $D1D5, with nothing to count how far it has gone. If the object is not among the first ten, the search runs on through memory, still every second byte, to the first that holds the type, and takes the byte before as the entry number. It marks that entry as the object in use (bit 7 of its byte 3) and writes the creature's number into its byte 4, which says who carries it.

A magic mushroom is type $82, 130. Past the list, the first byte the search reads that holds 130 was at $E8F1, and the byte before it held 3, so in turn 22 each of TORQUEMADA's four tries marked entry 3, the fourth wizard's, empty in a game of two, and the mushroom stayed on the floor. Between tries the wizard tried spells. The computer chooses its spells by priorities, one byte a spell at $D3DC, and raises a spell's priority by one each time it tries the spell. In turn 23, between one try and the next, the FLYING POTION's priority went from 128 to 130. The next search stopped there, at $D3F9, and the byte before was the SPEED POTION's priority, 255.

Entry 255 would start at $6154, so its bytes 3 and 4 are $6157 and $6158: the operand of LD HL,$5B11 at $6156, which points at the number of the player whose turn it is. It became LD HL,$0191, and the INC (HL) after it now adds one to a byte of the ROM, which cannot change. The computer finished its turn and the game showed the end-of-turn menu. A new game turn sets the player number to 0, for the creatures that belong to no one, and from then on it stays 0: it never reaches the number of players, so the turn loop goes round for ever, clearing the screen each time and never coming to a wizard's turn.

With fifteen objects on a square, computer_pick_up's list holds the first ten: the search for the twelfth runs past it and marks the entry named by the byte before the first match, and with 255 there the turn loop's operand becomes $0191.

07 · The winner

Bug: a draw with the computer counts as the computer's win

At the end, the game looks for the highest score with a test that lets an equal score take over. Of two wizards on the same points, the one later in the list wins.

game_over ($8DD3) goes through the four final scores from the first wizard to the fourth and keeps a score when it is at least the best so far. In a game against the computer, the computer's wizard is second. A draw is its win, so the player's designed wizard does not go up a level or keep its score for the designer. Run on the game's own code with 10 points to the player's wizard and 9 to the computer's, the wizard goes from level 1 to 2; with 10 each, it stays at 1.

08 · The authors' tools

Secret: the authors' breakpoint is still in the game

A routine at $96BA that nothing calls counts up, prints the count at the bottom left and waits for fire, keeping every register. Dropped into any routine with a CALL, it stopped the game there.

The play screen with a small 1 in yellow on red at the left end of the row above the message line
borderwhenwhere
yellowa square holds a creature or object the object table cannot find$9121
magentaa division by 0$94BF
reda computer creature takes 50 steps in one turn$9843
bluea computer creature is missing from its list of orders$996D
yellowthe computer wizard's list of 35 creatures is full$A50B

The routine called from a game of scenario 1: the 1 is the count, in the Spectrum ROM's own font. The table is every write to the border that is not the tape's or the start of a turn's.

It prints through the game's own number routine with the font pointer set to the ROM's character set ($3C00), so it needed nothing but the count. The five border colours are the same kind of tool: each marks a state the authors expected never to reach, and each lets the game carry on, so a tester could report the colour.

09 · Names

Secret: the tape still carries the testers' wizards

The game was saved with names left in its tables. None shows in play, because each slot is marked empty or written over before it is used.

wherenames
the four wizard records ($CEEA)ROGUE, JOE BLOGGS, WOPPER ZAP, TORQUEMADA
the designer's table of names ($D864)MERLINEEEE, JEVARRELEE
each scenario's table of player namesMERLIN, JEVARREL, THERMIDOR, GRISELDA

Read from the game's own blocks as they come off the tape. ROGUE's record has level 0, so the file panel lists the slot as NONE.

TORQUEMADA is also the name of scenario 1's own wizard, the one the computer plays there. The designer fills its table from the wizard records before it prints a name, and a scenario writes the players' names into its own table at the start of a game, so the names left over are never seen.