1985 · Mastertronic

Kane

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

A budget western in four stages. Every picture is unpacked a byte at a time, slowly enough to watch, and each ride is a strip of 400 characters built from nine obstacles, where the video chip itself reports the horse's fall.

01 · The game

The game

You are the Marshall of Kane, a town at war with the Wagari Indians. The game is four stages played in a loop. In the canyon you shoot ducks with a bow and arrow, and every few ducks you hit earn a peace token, the game's word for a life. Then you ride to Kane against the clock, jumping the bushes and rocks in your path. In the town, twelve bad guys pop up from windows, doors and wagons, and you shoot them before they shoot you. Last you ride after a train and pass its coaches until it stops.

After the train the canyon comes round again one level higher. There are three levels, and after the third train the game shows its ending. A fall from the horse or a shot from a gunman costs a token, and with none left the game is over.

The title screen: a wooden sign reading Welcome to KANE
The title screen.
The Marshall on a white horse riding through a desert with cacti
The ride to Kane, the second stage.

The game reads a joystick in port 2. On a ride, F1 starts the ride again with no token lost. The RESTORE key does nothing: the game points the address that RESTORE jumps to at an instruction that only returns (nmi_ignore, $3162).

02 · The music

Music: the William Tell Overture

The game has one tune, the finale of Rossini's William Tell Overture, its trumpet call and then the galop. The tune plays on the title screen and on the ride to Kane, and again at the end of the game, slowing down as it goes.

The page runs the game's own music player, music_step at $9492, on the kit's 6502 with its code and tables from the listing, once a frame, as the game's raster interrupt calls it. A raster interrupt is a routine the video chip starts when it reaches a chosen line of the screen. The filter is on, with the cutoff curve of one 6581 chip, since the game sets the filter for this tune ($96A8). A test beside this page runs the same calls on the game's code and compares every write to the sound chip, frame by frame.

Each voice reads two bytes an event. The first byte's top two bits pick one of three instruments and its low six bits give the note's length in steps. The second byte is the note, 0 for a rest. A step is six frames (tempo, $9640), so a note of length one lasts about an eighth of a second. The gate is turned off two frames before a note ends, which gives each note a short gap and the galop its bounce. When voice 1 reaches $9A3C the tune starts again.

At the end of the game the tune should slow at nine places, listed in tune_slowdowns ($8E5D). It slows at two: the ending's button above plays it as the game does, and Discoveries says why.

03 · One frame of the ride

One frame of the first ride, rebuilt

The ride's screen is eight bands, one above the other, each set up by its own raster interrupt as the picture is drawn. Press a band to see what its handler changes.

Drawn by the site's C64 library from one whole frame recorded in the emulator: the memory as the frame began and every write to the video chip, with the line and cycle it happened on. Every one of its 104,448 pixels matches the emulator's own picture of the same frame.

The interrupts are a chain. Each handler sets the line of the next and puts the next handler's address in the interrupt vector ($0314), and the last one, irq_ride_control on line $AF, points back at the first. The top handler shows a screen of characters at $4000 drawn from the ride's character set at $7800. Two lower down make the band of ground multicolour and change its colours. One at line $9A reuses all eight sprites, stretched to double width, as a black strip across the seam where the picture changes to the status lines. The handlers also do the ride's work, which is why the game's own loop can run without waiting for a frame: irq_ride_control reads the stick and scrolls the band, and the top handler counts the clock down.

04 · The pictures

Pictures drawn from a packed stream

Before each stage the game draws its picture a byte at a time, slowly enough to watch. The canyon takes about a second.

Drawn with the page's port of the game's three unpacking routines, from the packed bytes in the listing, at the pace the game's own routine runs on the kit's 6502. A test beside this page checks the port against the game's code byte for byte for all four pictures.

A picture is a multicolour bitmap of 8,000 bytes, 1,000 bytes of screen colours and 1,000 colours for colour memory, 9,500 bytes in all once two colours share a byte. The game keeps four, and keeps each packed in three streams. unpack_bitmap ($0D84) copies a byte as it is, unless the byte is $00, $55, $AA or $FF, the four bytes whose four pixels are all one colour; one of those is followed by a count of how many times to write it. unpack_runs ($0DFB) reads pairs of a count and a value, for the colours. After each byte of the bitmap the game waits a little (short_delay, $0E31), and that pause is what makes the drawing visible.

PictureBitmapScreen coloursColour memoryPackedUnpacked

The streams lie under the machine's ROMs and its input and output chips, where the processor cannot normally see. The routines switch them all out of the way (cpu_port, $01, set to 0) for each byte they read. Every picture is drawn in Maps / levels.

05 · The rides

A course of 400 characters

Each ride's ground is a strip 400 characters long and five high, built from nine obstacles before the ride starts. The screen shows forty characters of the strip at a time.

start0.00 miles

The strip is built by the page's port of build_ride_screen ($2D08) from the placement lists in the listing, and drawn with the ride's character set and the colours its raster handlers set. A test beside this page builds both courses on the game's own code and compares them byte for byte.

The obstacles are nine blocks of five by five characters (ride_objects, $0EC2). A placement list gives pairs of a step along the strip and an object number: ride 1's is at $0B00 and the train's at $0B70. place_object ($2F7B) copies each object's five rows into the strip, whose rows are 400 bytes apart.

While the horse moves, irq_ride_control scrolls the band by the horse's speed, and copy_map_window ($301B) copies the next forty characters when it has moved a whole one. A character is 0.01 mile, so the ride's 4.00 miles are the strip's 400 characters. Maps / levels draws both strips whole.

The horse falls when sprites 5, 6 or 7, its legs, touch the band's characters (irq_ride_sprites, $2980). The video chip reports that touch itself, in its sprite-to-background collision register.

06 · The shoot-out

How a gunman picks where to appear

The bad guys come out of sixteen fixed places, four at a time at most. Press a place to see how its gunman appears.

rises from belowslides in from the rightslides in from the left

The town is drawn from the listing as the game unpacks it, and each place from the table at $9169: its x (whose lowest bit doubles as the ninth bit of the sprite's position), its y, and its kind. Each box is where the gunman's figure is drawn inside his sprite.

Four sprites, 3 to 6, carry the gunmen. Every fifth pass of the shoot-out's loop, gunmen_appear ($3E77) counts down a delay for each free sprite, and gives it a place when the delay runs out. gunmen_appear picks the place at random by mixing CIA 1's timer with the raster line, the line the video chip is drawing. A gunman is tiny, eight pixels wide and five to eleven lines tall, and the game draws him into his sprite a row at a time as he comes out (gunman_step, $8810). He waits seven steps, fires once at the gunmen's aim, and goes back the way he came.

The check that a place is free reads the wrong byte, so two gunmen can share a place. Discoveries has the details.

07 · The effects

Sound: the effects

The canyon's drum, the arrow's whistle, the two kinds of gunshot and the train's hoofbeats are short routines that set the sound chip once a frame.

The page runs each effect's own routine from the listing on the kit's 6502 once a frame, as play_effects ($91E7) and play_music ($9475) call them, after setting the bytes the game sets when the effect starts. The test beside this page holds every write against the game's code. The drum is a low note: laptop and phone speakers play it quietly.

Each effect has a bit in effects ($23): bit 7 the Marshall's shot, bit 6 a gunman's, bit 5 the whistle, bit 4 the drum. The shots and the whistle clear their own bit when they end. The drum's bit stays set until the stage ends, so the drum beats for the whole canyon, every fifteen frames, a high note on one beat in four. The hoofbeats belong to the train. They are noise on all three voices, struck once a period that starts at 20 frames and shortens by a frame at each beat, so the train speeds up as the gallop does (hoof_sound, $96FF).

08 · The samples

Sound: a duck's cry is the Marshall's death, sped up

A hit duck, a hit gunman, the Marshall's death, the horse's whinny and a man's voice saying “Well done” at the end of the game are recordings, one bit a sample, played while the whole game stops.

The page runs the game's own sample player on the kit's 6502, with a model of the timer it waits on, and turns each bit into a level: voice 1 held high, or low, scaled by the volume. The interrupts that still run during a sample would delay a bit here and there; the page leaves them out.

The player turns voice 1 into a switch. It sets the voice to a pulse wave of width $FFF with a frequency of 0, so the oscillator never moves and the output sits low. Setting the voice's test bit forces the output high. Each bit of the sample sets or clears the test bit ($93E9, $93F0), and CIA 2's timer A times the bits. The stream comes in blocks of a volume byte and sixteen bytes of bits, so the volume can change every 128 bits.

Three of the cries are one recording, the hit sample at $F3F0, played at three speeds and three volumes: sample_rate ($9449) sets the length of a bit and sample_volume ($9448) is taken off each block's volume. A duck's cry is the same sound as the Marshall's death, played in about half the time and quieter.