1988 · Blade Software

Laser Squad: 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/laser-squad with me to Gold.

The whole game, playable in the browser: the five scenarios, the shop, placing the squad, and the turns, against a friend at the same keyboard or against the computer at any of its levels, with saving and loading a game. 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.
  • 1 2 3 4 5 6 7 answer the menus: the scenario, the controls, one player or two, the level
  • Between turns, fire plays on; 2 saves the game, 3 leaves for the first menu
  • The arrow keys move the cursor; Space, Enter or Ctrl is fire, which picks what is under it

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 sound is the port's writes to the beeper, each edge at the T-state the game's loops make it.

01 · The port

Every routine of the game, written again in JavaScript

The game is a Z80 program of 22,521 bytes, the engine, and five scenarios of 18,911 bytes each, loaded from tape over the top of memory, each with routines of its own and its own copy of the computer player. The port is the same program written again in JavaScript: one function for each of the engine's 289 routines and for the 40 routines the scenarios carry, in 144 copies, each reading and writing the game's variables at the game's own addresses. The page runs only the port.

The game's dice add the Z80's refresh register, a byte read from a pointer that walks the whole of memory, and the time spent waiting for keys. No port can keep the refresh register, so on this page it is noise.

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
Each instruction takes its T-states, and a turn of the computer's takes as long as its thinking does.The port executes no instructions. Each stretch of the program between two reads of the controls, each routine it calls and each piece of work inside them (a view drawn, a line of sight walked, a word printed) costs what it cost the game, fitted on the game's own timings (The pace, under How the port was checked), so a turn takes about as long as on the Spectrum.
The random numbers add the refresh register, which counts every instruction the processor fetches, to a byte from a pointer that walks through the whole of memory: the ROM, the game's code, the stack.No port can keep the refresh register, so it is noise, between 0 and 127. The page does not carry the ROM or the game's code, so a byte the walk reads there is noise too. The shots, the morale tests and the computer's choices are drawn the way the game draws them, from numbers just as unpredictable.
The menus read the keyboard through the ROM's KEY-SCAN routine.The port reads the keys the way KEY-SCAN does, and charges the time it took the game.
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.
The beeper is toggled from the effects' timing loops, with the game stopped while each plays.The site's model of the beeper plays the port's writes to it, each at the T-state the game's loops give it, and the game waits for the effect as it does on the Spectrum.
Choosing a scenario plays its block of 18,913 bytes from the cassette at the ROM's speed, which takes nearly two minutes.The page carries the five scenarios' blocks, and a scenario loads at once.
Save Game, in the menu between turns, saves the game to tape; Load Saved Game, at the first menu, loads it back.A saved game is kept in the browser, and offered as a .tap file to download. Load Saved Game loads the one kept, or a .tap file given to the page.
A key stays down as long as a finger holds it, and the game reads it as often as its loops come round.A tapped key stays down until the game has read it and the screen has shown what it did, however short the tap, so a tap moves the cursor one square. A key held down repeats as it does on the Spectrum.
The controls are the keys, a Kempston joystick, a Sinclair stick or the cursor keys, as the first menus choose.The arrow keys, and the pad under the screen, are whichever the menus chose, with Space, Enter or Ctrl for fire; every other key is the Spectrum's own.