A commented disassembly of Hyper Sports 2, Konami's RC-717 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.
No repository ships the game. Put your own dump in the root as
hypersports2.rom, 16384 bytes, sha256
f4273f5290edb8b55a319bdfc40d99c0f7863a4cbd93b75519508cb129d288f6
make comprueba checks it.
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 textos read the cartridge's texts, which are tile lists and not ASCII
make web rebuild this website from the ROM and the notes
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:
src/hypersports2.entries — the entry points the tracer cannot deduce on its
own: the interrupt hook, the ten inline dispatch tables, and the four return
addresses this cartridge pushes on the stack instead of calling. Each one has
its reason written next to it.src/hypersports2.nocode — the ten word tables glued right behind their
call. A tracer that walks straight through them eats them as instructions
and reports coverage it has not earned.src/hypersports2.notes — one line per annotation: L names a routine, C
comments an instruction, B a block, D a data range and F the width of a
record inside it.make sanity prints the budget: 6,956 bytes of traced code and 9,428 bytes of
data in named ranges, 0 unexplained, 16,384 in total. make densidad prints the
comment density: 3,680 instructions, 837 line comments, 22.7%, and not one
routine below 10%.
Every figure on this site comes from those two commands, not from an estimate.
16,384 bytes that map into page 1 of the MSX, 0x4000-0x7FFF. The header at
0x4000 is the usual one: the AB mark and, of the four vectors, only INIT is
filled in, pointing at 0x4064.
| bytes | share | |
|---|---|---|
| traced code | 6,956 | 42.46% |
| identified data | 9,428 | 57.54% |
| unexplained | 0 | 0.00% |
The data is not one lump: it is 151 named ranges, each closed against what
reads it. make sanity is what prints this table, and it fails if a single byte
is left over.
MANDA_LOS_REGISTROS_DEL_VDP (0x4476) writes the eight bytes at 0x4487 one by
one through the BIOS. They put the machine in SCREEN 2 with 16x16 sprites and
lay the memory out like this:
| table | address |
|---|---|
| names | 0x3800 |
| colours | 0x0000 |
| patterns | 0x2000 |
| sprite attributes | 0x3B00 |
| sprite patterns | 0x1800 |
The border is black. Patterns and colours have their three thirds independent, and the cartridge uses that: the font goes into all three, and each event only replaces the two lower ones.
Nothing is stored as a screen. There are three interpreters:
n & 0x7F literal bytes, and without it, it repeats the next byte n
times. Entering at 0x43F5 the stream carries its own destination in front.Every picture on this site is drawn by running those three in Python, in
tools/graficos.py. If a range or a format were wrong, what would come out is
noise.
The table at 0x6C3A holds four records of three pointers: patterns to VRAM 0x2A00, colours to 0x0A00 and sprites to 0x1800, indexed by (0xE080) & 3 times six. The fourth record is the records screen, which shares its sprites with the archery. The backgrounds are somewhere else: three words at 0x42A0, straight into the name table from row 8.
Three channels of twelve bytes each from 0xE010: the note counter, how long it lasts, the state — which is the number of the effect playing, with bit 7 for the long commands and bit 6 for noise —, the pointer into the stream, the octave, the background volume, the volume sounding, the fade count, the pitch and the detune.
CORRE_EL_SONIDO (0x7696) steps the three every frame and leaves in 0xE036 the
OR of the three states: that is the "something is playing" flag half the
cartridge waits on. There are 48 effects and short tunes in the table at 0x78AC,
and the tone table is one octave of twelve periods — the rest come from doubling.
0xE000 is the state and 0xE001 the sub-state; 0xE003 the frame counter, 0xE004 the general wait. 0xE043-0xE048 hold the joystick as read and as it was. 0xE063 keeps the points in BCD, 0xE080 the event and 0xE0C0 the sprite records that go up to the VDP in one block. The stack starts at 0xE400.
INIT (0x4064) sets the stack at 0xE400, zeroes the game's RAM, writes a
jp 0x4022 into the H.KEYI hook, sets up the VDP and the PSG, loads twelve
starting values into 0xE053 — and then falls into a jr to itself at 0x40A0 and
stays there for ever.
Everything happens inside the interrupt. Each frame it steps the sound (0x7696), reads the controls (0x44AD) and gives the game one step (0x40AB). 0xE005 is the latch: if the previous step has not finished, the interrupt only moves the sound and leaves.
0xE000 is the state and 0xE001 the sub-state. The state indexes an eleven-word
table and the sub-state splits each handler with a djnz chain, so a handler
reads like a list of numbered sub-states.
0 title, curtain and labels 6 the event's frame
1 wait 7 end of attempt
2 change of event 8 end of the event
3 prepare the game 9 change of event
4 set the event up 10 the table of records
5 prepare the attempt
Every jump by index goes through the same seven instructions at 0x4046:
add a,a
pop hl ; the return address is the table
call HL_MAS_A
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
jp (hl)
The word table is glued right behind the call, and the dispatcher pops it
off the stack. There are ten of them (0x40C8, 0x4B80, 0x4BB1, 0x4CD0, 0x4DFE,
0x4EC4, 0x5054, 0x5151, 0x5297, 0x547C), and each one is declared in
src/hypersports2.nocode. A tracer that walks past a call DESPACHA eats the
table as instructions and reports coverage it has not earned: the size of each
table is fixed by its lowest forward destination, and every one of them closes
exactly against it.
Because the dispatcher jumps and never comes back, whatever has to run afterwards is pushed on the stack beforehand:
ld hl,04cc8h
push hl
ld a,(0e080h)
call DESPACHA
Four addresses reach the listing that way and no other: 0x4CC8, 0x521C, 0x44E6
and 0x4F87. Two of them were sitting in the notes as data until the pattern was
searched for on purpose — a ld hl,NN and a push hl with up to three
instructions in between.
Each event has its own step table — seven words for the archery (0x5297), eleven for the weight lifting (0x5151) — and both of them reuse the skeet's steps for what does not change: saving the mark (0x4FD6), checking against the qualifying score (0x4FEA), the end (0x501A) and finishing the event (0x50DC). Four of the eleven weight lifting steps and four of the archery's seven are the skeet's, pointed at from another table and untouched.
tools/mkasm.py builds it from the trace and the notes. Two guards run on every
build:
check_trace.py and check_datos_como_codigo.py: no byte declared as data
may come out as an instruction. Reassembling cannot catch this — the bytes are
the same either way, only what we say about them changes.check_entradas.py: no entry point may fall inside a data range.And presupuesto.py refuses to pass if a single byte of the 16,384 is left
unassigned.
The listing and every number on this site come from the binary and are
reproducible with make. Nothing here was measured by eye. The emulator is for
checking that what the listing says is what the cartridge does.
openmsx -machine Philips_VG_8020 -cart hypersports2.rom
An MSX1 machine is enough: the cartridge maps into page 1 and drives everything from the frame interrupt.
| address | what it holds |
|---|---|
| 0xE000 | the state; 0xE001 the sub-state |
| 0xE005 | the latch that keeps the interrupt from re-entering |
| 0xE036 | non-zero while any of the three channels is playing |
| 0xE080 | the event: 0 skeet, 1 archery, 2 weight lifting, 3 records |
| 0xE1A1 | the step inside the event |
| 0xE1A3 | in the weight lifting, the lift given as good |
| 0xE063 | the points, three bytes of BCD |
To confirm a timing, put a breakpoint at a routine's entry and another at its
ret, and take the difference of machine_info time — times 3579545 for Z80
cycles.
tools/omsx_capturas.tcl boots the cartridge, presses keys through the key
matrix and takes screenshots. Its log writes the time, the PC and the state next
to each shot, so a capture can be tied to the listing:
t= 21.91 foto tiro_03.png PC=0x58F3 estado=2
t= 44.92 foto tiro_05.png PC=0x445A estado=2
The first PC falls inside MIRA_LOS_IMPACTOS (0x58E3), the skeet's; the second
inside the VDP write helper, with the archery on screen. That is what settles
the order of 0xE080: skeet first, archery second — and the ANGLE 0.00 and
WIND readouts confirm which event is which without having to reason about it.
-script, the emulator starts with the renderer
uninitialized, and screenshot returns a black PNG with a return code of
zero. It has to be turned on by hand with set renderer SDLGL-PP.set throttle off the machine runs flat out and the renderer skips
frames: ask for the capture with the throttle on and with
after realtime, which is wall clock.type space types the word "space". The trigger is row 8 of the key matrix:
keymatrixdown 8 0x01 for the bar, 0x10, 0x20, 0x40 and 0x80 for the four
arrows./tmp.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, 53 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) |
|---|---|---|---|
| Konami's Boxing | 16 | 162 | BORRA_LA_PANTALLA (0x43A8) = borra_la_pantalla |
| Sky Jaguar | 16 | 224 | SOLO_SI_PESA_MAS (0x7884) = REPARTE_CANALES |
| Yie Ar Kung-Fu | 16 | 217 | PINTA_CIFRAS_SIN_CEROS (0x4320) = empieza_tapando |
| King's Valley | 14 | 155 | PERIODO_DE_LA_NOTA (0x77FE) = arranca_con_forma_elegida |
| Konami's Ping Pong | 14 | 140 | LEE_EL_TECLADO (0x44C1) = lee_teclado_1 |
| The Goonies | 12 | 126 | ABRE_O_CIERRA_EL_CANAL (0x7670) = enciende_o_apaga_el_ruido |
| Road Fighter | 12 | 108 | ABRE_O_CIERRA_EL_CANAL (0x7670) = enciende_o_apaga_canales |
| Yie Ar Kung-Fu II | 12 | 128 | LEE_EL_TECLADO (0x44C1) = lee_las_filas_7_y_8_del_teclado |
| Hyper Sports 3 | 11 | 137 | LEE_EL_TECLADO (0x44C1) = teclado_del_jugador_1 |
| Knightmare | 11 | 105 | ABRE_O_CIERRA_EL_CANAL (0x7670) = enciende_o_apaga_el_ruido |
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.