1992 · Ocean Software

Lethal Weapon

This minisite is not complete: 100 % of the program is explained. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to continue games/c64/lethal-weapon to Silver.

An eight-way scroller that redraws the whole screen one fifth at a time, a sprite multiplexer for sixteen objects, and a disk whose game-over screen asks for a file the disk does not hold.

01 · The game

Riggs or Murtaugh, against the clock

You pick one of the two detectives and work through fourteen stages of Los Angeles, starting on the docks, each a level larger than the screen that scrolls in all eight directions.

Riggs on the docks of stage 1A, with the panel below

Stage 1A in play. The panel shows the score, the lives as hearts, the clock, the energy bar, the magazines and the six rounds in the gun.

Each stage has five minutes on the clock. Doors lead to other stages; the last door ends the game. Gunmen hide, patrol and shoot; thugs walk into you; bosses hop across the screen. You shoot, jump and climb ladders. The fire button fires one round a press, six to a magazine.

The character select screen

The select screen. Hold fire and push towards the man you want: right for Riggs, left for Murtaugh. Fire alone does nothing here.

02 · Three programs

Title, game and ending are separate loads

The disk holds about a hundred files. Three of them are programs; the rest are pictures, maps, sprites and music each program loads.

ProgramWhereWhat it loads
Title (LOADER)$C000the logo sprites, the select screen and portraits, the music ($E000)
Game (GAM0, GAM1)$03C0, $E000for each stage an overlay at $3790, its map, tiles, colours, characters and sprite files
Ending (111)$0900a portrait of the man you played, and the music again

All three carry the same fast loader ($03C3 in the game). It sends 256 bytes of code into the disk drive, then takes each file two bits at a time through the serial port, flashing the border with every byte. Stage files are packed; the game unpacks them with its own decoder at $F5D5, which builds three Huffman tables for each block and alternates runs of plain bytes with copies from what it has already written.

03 · The scroller

A fifth of the screen each frame

A level is a map of 288 by 70 characters, built when the stage loads. Two screens take turns: one is shown while the other is redrawn one character over.

When the player nears an edge, $2570 picks one of eight directions. Each frame the scroll moves the fine-scroll registers one pixel and calls one routine from a table of 128 ($178F, by direction, screen and step). Most of these copy four or five rows of the shown screen into the hidden one, shifted by a character. When the fine scroll wraps, the screens swap ($1579), colour RAM is shifted to match ($2B3F and its seven siblings) and the new edge is drawn from the level map ($1593). Every object on the level moves the other way by the same amount.

The map itself is built by $0673 from 2×2-character tiles: 144 tile columns of 35 tiles. The tiles come from the stage's .BLK file and the tile map from its .MAP file, which holds 64 rows. Stage 1A uses rows 29 to 63 of it; stage 1AX, a door away, uses rows 0 to 34 of the same map. The Maps tab draws every stage.

04 · Sixteen objects

One table, eight sprites

Everything that moves is one of sixteen objects in a table in zero page. Before each frame they are sorted by line, and the raster interrupt hands them to the eight sprites from the top of the screen down.

ByteHolds
$AF+ntype: 0 a walking thug, 2 to $22 pickups and hazards, $24 and up an enemy behaviour
$BF+ncolour, with the ninth bit of x
$CF+nsprite frame
$DF+nline on screen, 0 for an empty slot
$EF+nx

Object 0 is the player and objects 1 and 2 his bullets. The sort ($F2B3) is an insertion sort, cheap because the order rarely changes. The interrupt at $E1AC places one object per sprite until the next one is too far down, then sets itself for 13 lines above it and continues there. Each behaviour is a routine named in a table ($077D) and called by rewriting the operand of one JSR ($0FA6).

05 · Two jumps

Riggs jumps as high, and more slowly

A jump is a table of line changes, one a frame. Murtaugh has one at $36A0 and Riggs one at $36E2.

The two tables, played side by side. Each dot is one frame. Both rise 40 lines; Murtaugh lands after 32 frames and Riggs after 40.

Other versions of the game describe Murtaugh as the higher jumper. On the Commodore 64 the height is the same and the difference is time in the air. Each man also has his own sprites: the stage loader swaps the file SP00 for SP0Z when Murtaugh is chosen.

06 · Clock, rounds and magazines

A magazine every five seconds

You start with 25 magazines of six rounds. The clock gives you more.

The clock routine ($F424) adds a magazine each time the seconds digit reaches 0 or 5. Pickups add more: a magazine, energy, a life, 400 points, or a bigger gun (three sizes, each doing one more point of damage, $285C). When the clock reaches 0:00 you lose a life, and the next life starts with 9:00 on the clock.

EventPoints
Hit an enemy300
Kill an enemy400
Kill a boss1000
Points pickup400

07 · The sound

Mark Cooksey's music

The title program carries a music driver and three tunes. The ending loads the same file again and plays the title tune for ever.

The game's own driver, running in your browser. This player runs the bytes of the file MUSI ($E000-$F5D5) on the site's 6502: $E000 starts a tune and $E003 plays one frame of it, as the title's raster interrupt calls it. A test beside this page checks every register the page's player writes against the same code run on the title's memory. Tune 0 plays on the title, tune 2 when you choose a man; nothing calls tune 1.

Each voice reads a stream of notes: a note number, then a byte with its length and instrument. Bytes from $60 are commands: play a pattern (with repeats and a transposition), loop, slide, pick a filter sweep. The game itself has no music: its sound effects come from a smaller engine at $F88C, eighteen effects of a few bytes each.