Under the hood

Getting started

The repository ships the listing already generated, but what really matters is that it can be rebuilt from the cartridge and that the result is the ROM byte for byte. That is what makes the notes worth believing.

What you need

The cartridge

It does not travel with the repository. Put it in the root as hypersports3.rom, exactly 32,768 bytes:

247a14766d3c64c88707ee0bfd1a0255182acab98006d2c2646085e00db29936

To check it is the same one:

make comprueba

Rebuilding everything

make

That chains the four things that matter:

  1. make listado traces the flow from the declared entry points and writes src/hypersports3.asm.
  2. make verify reassembles it with pasmo and compares the binary against the ROM. If it is not 32,768 identical bytes, it fails.
  3. make sanity checks what reassembly cannot see: that no byte declared as data is being read as code, that no entry point falls inside a data region, and that not one byte is left unassigned.
  4. make test runs the 33 tests over the listing and the site.

The numbers

make densidad

Gives the two used across the series: how many routines are below 10 % of commented instructions, and the overall density. Here they are 0 out of 931 and 34.5 %.

The pictures

make imagenes

Draws the screens from the bytes of the ROM, running in Python the same decompressor, the same figure engine and the same label interpreter the Z80 runs. There is not one screen capture in this repository.

And to check those drawings are the real thing:

make vram

runs the cartridge in openMSX, dumps the 16 KB of VRAM at several instants, and tools/coteja_vram.py compares them byte for byte against what Python builds. Looking at the picture is not enough; that already cost four errors that had passed the eye test.

The cartridge

Hyper Sports 3, Konami, 1985. Catalogue number RC-733. 32 KB of ROM in an MSX1 cartridge, no mapper, no SCC and no RAM of its own.

The map

0x4000 .. 0xBFFF   the cartridge's 32 KB, pages 1 and 2
0xE000 .. 0xE7FF   the 2 KB of work RAM, and it uses no more

The header is the sixteen bytes at 0x4000: the AB signature, the INIT address (0x405A) and everything else at zero —STATEMENT, DEVICE, TEXT and the six reserved bytes—.

The eight VDP registers

The loop at 0x4488 writes them in order, 0 to 7, taking each value from a table. For the game they are:

02 E2 0E 7F 07 76 03 E4

R2 = 0x0E -> name table       0x3800
R3 = 0x7F -> colour           base 0x0000, mask 0x3FF
R4 = 0x07 -> patterns         base 0x2000
R5 = 0x76 -> sprite attrs     0x3B00
R6 = 0x03 -> sprite patterns  0x1800

In SCREEN 2 R3 and R4 are not an address, they are a base and a mask. With these values the screen is split into the usual three thirds, each with its own 256 patterns and 256 rows of colour. Which is why the cartridge has a routine (L_4405) that decompresses the same block into all three at once, skipping 0x0800 each time.

What INIT copies to RAM

Of the 2 KB of work RAM, twelve bytes are the only ones that do not start at zero. INIT copies them from 0x40CF to 0xE053, and they are the world records for the four events, in BCD. They sit in RAM rather than ROM because the game overwrites them as soon as they are beaten.

The scene dispatch

The whole game is one counter and eleven tables, and all eleven sit glued right behind their call L_4050:

pop hl / add a,a / call L_4046 / ld e,(hl) / inc hl / ld d,(hl)
ex de,hl / jp (hl)

The pop hl recovers its own return address, which is the start of the table. It is the dispatcher shared across this family of Konami cartridges.

The entry count of each table is not estimated: it is fixed by the constraint that no entry can point inside the table itself. All eleven are in src/hypersports3.entries with their arithmetic down to the byte. The longest is the one at 0xA934, with thirteen entries; the topmost is 0x4109, with nine, which dispatches the logo, the title, the events and the ending.

Sound

The whole player lives between 0x4AD2 and 0x4DA2, with its data right behind. The door is L_4ADD: you pass it the sound number in A. The track table ends exactly at its own lowest entry, 0x4E1C, which is what fixes its length without having to guess.

The period table has twelve values, not ten, and the last two are hidden inside the pointer table that follows. All twelve land within one unit of the exact semitone: it is a chromatic octave.

Konami's hidden mark

The last sixteen bytes —0xBFF0 to 0xBFFF— carry the game's title in katakana, backwards: ハイパースポーツ3, its length (0x0D), the 0x33 of RC-733 and an 0xAA to close. Nothing reads it: not one instruction in the cartridge points there.

The mark was discovered by Manuel Pazos, and it is in many of Konami's cartridges from these years.

Credits

There are none. No initials, no names, no build dates anywhere in the 32 KB. The only thing that signs is the hidden mark, and it signs for the company, not for the people.

The code

14,410 bytes of code and 18,358 of data, adding up to the cartridge's 32,768. Not one unassigned. 931 named routines and 34.5 % of the listing commented, with zero routines below 10 %.

That there is more data than code says a fair amount: this is a cartridge of compressed graphics with a small engine on top.

The scene machine

The whole game is a counter and eleven tables. (0xE003) picks the big scene —logo, title, event, ending— and each event keeps its own sub-scene in its own variable: the jumps in 0xE09E, cycling in 0xE120 and curling in 0xE230.

(0xE06A) holds the event in its bottom two bits and the lap in the top ones, that is how many times the four have been played through. With that the cartridge raises the difficulty without keeping a table per event: L_5443 pulls out the lap, clamps it to seven and indexes whatever table it is handed.

Four decompressors, not one

The RLE format is always the same —one command byte, bit 7 tells copy from repeat, 0 closes— but the cartridge has four different doors depending on where the output goes:

Two label interpreters

L_4415 is the usual one: 0xFE changes destination with a full address, 0xFF closes. L_676E is the other, and it takes its jumps as a single byte relative to where it is. With it a drawing several rows tall fits in very few bytes; the pole the athlete carries is twelve tiles in a fifteen-byte block.

The figure engine

L_6992. An athlete is not a sprite: he is two to seven 16x16 sprites, and each piece is five bytes —relative row and column, pointer to the pattern block, and colour— closed by an 0x80.

The interesting part is that the pattern is not sitting there beforehand: the block is decompressed into VRAM right then, on the spot, and the sprites pick it up in order. The 2 KB of sprite patterns are rebuilt in full on every frame, and that is how the cartridge can hold hundreds of poses.

The figures come out of five tables, and each one ends exactly at its own lowest entry: that is what fixes how many figures each holds without guessing it. The 127 pattern blocks they all point at run consecutively.

And the engine has two doors: L_65FC, which takes one figure from one table, and L_64E3, which composes the figure from two consecutive blocks sharing the pattern counter. The second one is what draws the athlete with the pole in his hand.

The table of ninety

0x7346 is ninety degrees of sine, one byte per degree. That it is ninety and not something else is what its two readers say: the second enters with 0x5A, which is 90, and 0x7346 + 90 = 0x73A0, exactly where it ends.

Clipped rectangles

L_AF7C draws a rectangle into the name table taking the screen's scroll into account, which it reads from (0xE20D) divided by eight. With the curling sheet at its starting position, the house falls to the right of the edge and the cp 020h / ret nc does not paint a single tile: that is why the opening screen is plain ice.

Ten bytes that are not data

Between the figures and the relative scripts there are ten bytes no instruction in the cartridge ever calls, and that are not data: they are a routine. It divides HL by 32 without losing anything off the top, taking into A the three bits that fall off. Which is exactly what the curling stone's address arithmetic does by hand a few lines below. It is there, complete, and nobody uses it.

In the emulator

The pictures on this site are drawn from the ROM, not captured. What the emulator does here is something else: decide whether those drawings are the real thing.

Checking against VRAM

make vram

launches openMSX with the cartridge and tools/omsx_vram.tcl, which at several instants dumps the whole 16 KB of VRAM, the eight VDP registers and the 2 KB of work RAM. Then:

python3 tools/coteja_vram.py hypersports3.rom 0x4000 work/omsx

compares byte for byte what Python builds against what the VDP actually holds, and it does it per table, because they do not all mean the same thing:

table address what it is
colour 0x0000–0x17FF the eight colour bytes of each tile
sprite patterns 0x1800–0x1FFF the sprite drawings
patterns 0x2000–0x37FF the tile drawings
names 0x3800–0x3AFF which tile goes in each cell

The first three are static: built once and untouched until the screen changes, so they have to come out at zero. The name table does move —the athlete, the scoreboards, the labels that blink— and there what you look at is how many cells wobble and whether they are the ones that should.

Where it stands

screen colour spr. patterns patterns names
title 0 0 0 14
cycling 0 0 0 0
triple jump 0 77 0 0
curling 0 0 0 34
pole vault 0 0 0 0

Cycling closes at zero across all four tables and on the 128 sprite attribute bytes as well: 15,104 bytes of VRAM identical to the emulator's.

The 14 on the title are the blinking cursor and the 34 on curling are the TEMP readout and the scoreboard, both written after the screen is built. The 77 on the triple jump and the pole vault's sprite patterns are the athlete's pose: the build-time dump does not have him drawn yet, and the frame that does has the runway already scrolled. Against that frame the pole vault comes out at zero of 2,048 pattern bytes with all six sprites identical.

No need to play it

The demo walks through all four events on its own, but you have to wait. There is a faster trick: scene 4 is call limpia_la_pantalla / call monta_la_prueba, and monta_la_prueba reads the event from (0xE06A) at 0x53CB. A breakpoint between the two that writes the event number there leaves the cartridge building and playing that event. It is not a frozen screen.

echo 2 > work/prueba.txt      # 0 cycling, 1 triple jump, 2 curling, 3 pole vault
make vram

And it comes out better than playing: this way the event inherits the title screen's VRAM, which is exactly what it inherits on the real machine. Between screens the cartridge does not clear the patterns or the colour —it only hides the sprites and clears the name table—, so what was underneath is still there. Building an event from scratch introduces hundreds of differing bytes that are not a misreading but the missing inheritance.

And tracing the drawing calls

"openmsx" -machine Philips_VG_8020 -cart hypersports3.rom -script tools/omsx_montaje.tcl

puts a breakpoint on every drawing routine in the cartridge and logs, in order and with their arguments, every call that falls inside the build window. Replaying that list in Python over the dumped inheritance gives a screen identical to the emulator's. It is what separates "a block is missing" from "the format is being read wrong" without eyeballing a single byte.

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, 54 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)
Yie Ar Kung-Fu II 25 284 teclado_del_jugador_1 (0x44D4) = lee_las_filas_7_y_8_del_teclado
The Goonies 24 294 descomprime_a_vram (0x4442) = guion_rle
Knightmare 24 256 manejador_de_interrupcion (0x4019) = cada_cuadro
Konami’s Soccer 23 232 pinta_guion_de_tiles (0x4415) = escribe_un_rotulo
Konami's Ping Pong 21 243 teclado_del_jugador_1 (0x44D4) = lee_teclado_1
Pippols 20 229 mandato_de_pista_larga (0x4D13) = PISTA_MANDOS
Hyper Rally 19 191 manejador_de_interrupcion (0x4019) = INT
Nemesis / Gradius 19 207 descomprime_a_vram (0x4442) = descomprime_con_destino
Road Fighter 19 215 descomprime_a_vram (0x4442) = descomprime_con_destino_dentro
King's Valley 17 237 mandato_de_pista_larga (0x4D13) = procesa_comando_de_control

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.