1990 · Blade Software

Lords of Chaos: play

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.

The whole game, playable in the browser from where its loader hands over: SELECT CONTROLS, the wizard designer, the three scenarios loaded from the cassette, one to four wizards, the computer's own wizard and creatures, every spell, battle and treasure, the portal and the end of turn menu, with saving and loading to a tape file. Every routine is ported from the game's own Z80 code and was run beside it until the two agreed.

Loading the game's data…
  • Tap a key in this list to press it in the game.
  • To start a game: choose KEYBOARD at SELECT CONTROLS, then LOAD SCENARIO, type 1, 2 or 3 for the scenario and press Enter. When it has loaded, choose PLAY GAME.
  • HOW MANY PLAYERS? takes 1 2 3 or 4; scenario 3 is for one player and does not ask
  • A file name or a wizard's name: type it
    here
    , 0 rubs out, Enter ends it
  • Loading: the cassette holds DESIGNER., 1.GAM, 2.GAM and 3.GAM, then whatever is saved or added, and the game loads the first file whose name starts with the letter typed. It winds back to the start after the last file; a search that finds nothing stops at the end of the tape. Hold Space to stop a search
  • Saving (SAVE GAME at the end of a turn, SAVE WIZARD in the designer) puts the files on the cassette and offers them as a .tap file to keep
  • SELECT CONTROLS, and every menu: Q A move the bar, Space chooses
  • In play: Q A O P move the cursor, Space opens the menu for the square under it
  • The arrow keys and Ctrl are the controls chosen at the start: the keys above, a Kempston joystick or a Sinclair one

The game's own screen, drawn from the port's memory each frame as the Spectrum would show it, at the Spectrum's own pace: the interrupt animates the creatures and slides the bars every frame, and the computer's wizard takes as long to think as it does on the machine. The sound is the port's writes to the beeper, each edge at the T-state the game's delay loops make it.

01 · The port

Every routine of the game, written again in JavaScript

The game is a Z80 program in five parts: the engine, always in memory, and above it the wizard designer or one of the three scenarios, about 29,800 bytes of code in all. The port is the same program written again in JavaScript, one function for each of the game's 412 routines, reading and writing the game's variables at the game's own addresses. The page runs only the port.

The game can stop for good. In a game against the computer, a computer creature standing on more than ten objects sends its search for the one it wants on through memory, and the mark it leaves can land on the turn loop's own instruction: the loop then counts up a byte of the ROM instead of the player, and the screen stays blank for ever (Discoveries tells the whole story). The port reads that instruction's operand from memory, as the Z80 does, so it hangs in the same place.

The game prints in the ROM's font and turns KEY-SCAN's codes into characters with a copy of the ROM's key table. The page carries those two pieces of the 48K ROM ($3D00-$3FFF and $0205-$022B) and nothing else of it; KEY-SCAN, LD-BYTES and SA-BYTES, as far as the game uses them, are ported with the game's own routines.

02 · Differences

What differs from a Spectrum

The game plays as it does on a 48K Spectrum, at the 48K's pace. These are the places where the page cannot be the machine, and what it does instead.

On a SpectrumOn this page
The interrupt can fall between any two instructions of the main program.The interrupt runs between two of the port's routines, at the clock's time for it. The bytes the interrupt changes and the main program reads in the middle of a routine (the animated things' pictures and colours, the frame of the summoning animation, the cursor's blink, the flashing colour and the sound the map's drawing plays a step of) are read after the interrupts due by then have run.
Each instruction takes its T-states, and a computer player's turn takes as long as its thinking does.The port executes no instructions. Each stretch between two reads of the controls, each routine and each square looked at, word printed and number drawn costs what it cost the game, measured or fitted on the game's own timings (01, The port), so a turn takes about as long as on the Spectrum: within 4 % over a minute of play, and each wait of more than a second within 6 %.
A long stretch of work with no read of the controls (the start of a game, some nine seconds) draws on the screen as it goes.The port runs such a stretch at once, and the page shows the frames it took as the clock went through them, so the screen changes as it would; the controls are read again when the screen has caught up.
The beeper is toggled from the sounds' delay loops, with the interrupts on, so an interrupt can fall inside a note.The site's model of the beeper plays the port's writes to it, each at the T-state the game's loops make it, and an interrupt due inside a note runs before the note's edge, as on the machine.
The ULA draws the screen a line at a time as the beam crosses it.The page takes the screen whole at the moment the beam would reach its first line, so a change made while the beam is drawing shows a frame later, all at once.
random_below mixes the refresh register, which counts the instructions the processor has run, with bytes of memory it walks through, the game's code among them.No port can know the refresh register: the page draws a byte at random in its place, and where the walk passes over the game's code, which the page does not carry, it reads 0.
A scenario takes over a minute to load from the cassette; SAVE GAME and SAVE WIZARD write to it; at the end of the tape a search waits until SPACE is held.The page's cassette holds DESIGNER., 1.GAM, 2.GAM and 3.GAM and plays each file at once. It winds back to the start after its last file, as a player would to look for a file. A search that has been all the way round without finding its file stops at the end of the tape, as it would on a Spectrum, and the game waits until SPACE is held. A save puts its files at the end and offers them as a .tap file to keep; Add a tape file puts one back.
The controls are the keyboard (Q, A, O, P and SPACE), a Kempston interface or a Sinclair stick (6 to 0), as SELECT CONTROLS chose.The arrow keys, and the pad under the screen, are whichever was chosen, with Left Ctrl for fire; every other key is the Spectrum's own.
Two loops have no way out: random_below given a limit of 0 draws for ever, and computer_pick_up, looking for an object past the tenth on a square, searches on through memory, the game's code among it, to the first byte of that type, for ever when there is none. The main program stops there and the interrupt goes on.The port's search reads the page's memory, where the game's code is zero, so it can stop at another byte than on the Spectrum and mark another entry. In a loop for ever the port's program stops and the clock and the interrupt go on.
The game reads the keyboard through the ROM's KEY-SCAN, loads and saves through LD-BYTES and SA-BYTES, and prints in the ROM's font.The routines the game calls in the ROM are ported with the rest. The page carries two pieces of the 48K ROM and nothing else of it: the font ($3D00-$3FFF) and the key table KEY-SCAN's codes are looked up in ($0205-$022B).