Under the hood

Getting started

A commented disassembly of Hyper Rally, Konami's RC-718 for the MSX, a 16 KB cartridge that maps into page 1 (0x4000–0x7FFF). It reassembles into the exact ROM, byte for byte, and every one of its 16,384 bytes is accounted for.

The cartridge is not here

No repository ships the game. Put your own dump in the root as hyperrally.rom, 16384 bytes, sha256

eca2c0d6057b3829210b5fccd0d0005ea6ada7560f5446d9bbc2db2d06d96aae

make comprueba checks it.

What each command does

make            trace the flow, build the listing, reassemble it, run the tests
make verify     the test that decides: reassembling has to give the ROM back
make sanity     that not one byte is left unexplained, and no data reads as code
make densidad   how much is commented, routine by routine
make web        rebuild this website from the ROM and the notes

How it is put together

The listing is not hand-edited: tools/mkasm.py builds it from a flow trace and a file of notes anchored to addresses, so the comments survive a re-trace. The tracer follows the flow from the entry points; the ones it cannot deduce on its own —the interrupt hook and the inline jump tables— are declared in src/hyperrally.entries, each with its reason.

The cartridge

16 KB in page 1 (0x4000–0x7FFF), with no bank switching. The "AB" header declares only INIT (0x4010); STATEMENT, DEVICE and TEXT are zero.

What INIT does

INIT sets interrupt mode 1, writes a jp into the H.KEYI hook (0xFD9A) pointing at 0x4051, puts the stack at 0xE800, clears the work RAM 0xE000–0xE7FF, sets up the VDP and the first screen, and then falls into a jr to itself at 0x404F. From that point on the main program does nothing: the interrupt, once per frame, runs the whole game.

The screen

SCREEN 2. The name table is at 0x3800 and the sprite attribute table at 0x3B00. The cartridge does not store whole screens: it stores compressed scripts that a decompressor (0x446D, with its out (c),a core relocated to 0xE310) unpacks into VRAM.

The RAM map

Everything the game touches lives from 0xE000 up, under the stack:

The code

The state machine

The interrupt (0x4051) calls 0x4089 every frame. It reads the word at 0xE000: the low byte is the main state, 0 to 8, and with it a jump through the table at 0x40AA reaches one of nine handlers; the high byte is the sub-state, and each handler splits it with djnz chains. Changing state is a write to 0xE000; advancing a sub-state is inc (0xE001). There are no other threads: everything is this one interrupt.

Drawing from scripts

Nothing on screen is a stored bitmap. Three interpreters build the VRAM:

The font and the road tiles are one such script, at 0x4DEA; the website's pictures are drawn by running that same decompressor in Python.

The road

There is no perspective math. 0x68D0 reads the curvature at 0xE074 and indexes the table of road shapes at 0x767C to pick what to draw; 0x707A scrolls the stripes toward the player; the roadside objects are scaled by depth from the tables at 0x6CD5.

The sound

0x5FB7 is the per-frame player: three fourteen-byte channel records at 0xE010, each reading its melody with a small command interpreter and writing the PSG through the BIOS. 0x5ED9 starts a melody or effect by number, checking priority first. It is the framework Konami reused across its MSX cartridges.

In the emulator

The listing and every number on this site come from the binary and are reproducible with make. Nothing here was measured by eye.

Running it

openmsx -machine Philips_VG_8020 -cart hyperrally.rom

An MSX1 machine is enough; the cartridge maps into page 1 and drives everything from the frame interrupt.

What can be measured

To confirm a state or a timing, put a breakpoint and watch the RAM the notes name: 0xE000 is the main state, 0xE060 the stage, 0xE085 the speed. The per-frame cost of a routine is the difference of machine_info time between a breakpoint at its entry and one at its ret, times 3579545 for Z80 cycles.

Output paths in any Tcl script must be Windows paths, never /tmp.

Code shared with other Konami cartridges

This disassembly has been compared, instruction by instruction, with every other Konami one in the series. A block counts when the same instructions, at least six of them from a label to its ret or its unconditional jump, are in both cartridges; the addresses are left aside, because they change from one cartridge to the next. Of the other 57, 51 have at least one block in common with this one; these are the ones that share the most:

Cartridge Blocks Instructions For example (here = there)
The Goonies 21 266 LEE_MANDOS (0x466B) = lee_mando_y_teclado
Knightmare 20 239 LEE_MANDOS (0x466B) = lee_mando_y_teclado
Konami’s Soccer 20 262 LEE_MANDOS (0x466B) = lee_el_mando_1
Hyper Sports 3 19 191 INT (0x4051) = manejador_de_interrupcion
King's Valley 18 220 CANAL_TONO_60BA (0x60BA) = tono_con_periodo_explicito
Yie Ar Kung-Fu II 16 158 SONIDO_CTRL (0x5F67) = repite_un_trozo
Konami's Ping Pong 15 170 PSG_TONO (0x5F91) = pon_el_mezclador
Pippols 15 158 CANAL_TONO_60BA (0x60BA) = PISTA_NOTA
Yie Ar Kung-Fu 15 150 INT (0x4051) = interrupcion
Road Fighter 14 156 LEE_MANDOS (0x466B) = lee_el_mando

The whole matrix, the 58 cartridges against each other, is on The routines in the series database, along with the method and the program that measures it.