Under the hood

Getting started

This repository does not ship the cartridge. It ships the commented listing and the tools that generate it, check it and draw its screens.

What you need

43b23739d63b636922f0a98c33322bfdeafbefeccc01dd74fb0a45107581d0e6

The four steps

make comprueba   # that the cartridge is what it claims to be
make listado     # builds src/boxing.asm from the trace and the notes
make verify      # reassembles it and compares the sha256 with the original
make all         # all of the above, plus the checks and the 42 tests

make verify is what decides whether the disassembly is trustworthy: if the listing does not give back the ROM byte for byte, nothing it says is worth anything.

What make sanity checks

Reassembling does not catch everything. A block of data read as code comes out the same, because the bytes do not change; only what we say about them does. Hence four more checks:

check what it watches
check_trace.py that the trace never wanders into declared data
check_datos_como_codigo.py that none of the 416 data areas comes out as code
check_entradas.py that no entry point falls inside a data area
presupuesto.py that not one byte of the cartridge is left unassigned

The pictures

make imagenes    # the fourteen plates in docs/img, drawn from the ROM
make vram        # openMSX dumps its VRAM and it is compared byte for byte

Not one picture on this site is a capture. They are built by running in Python the same steps the cartridge takes, and the comparison against the emulator's VRAM comes out with zero differences on all eight screens.

The cartridge

32 KB on pages 1 and 2, from 0x4000 to 0xBFFF. The split, measured:

what bytes of the total
traced code 6,932 21.15%
identified data 25,836 78.85%
unexplained 0 0.00%

The TWO headers

At 0x4000 sits the ordinary MSX header: "AB", the INIT address (0x4091) and twelve zeros. STATEMENT, DEVICE and TEXT go unused.

At 0x4010 there is a second one: "AB" followed by 07 36. It belongs to the Konami Game Master, the cheat cartridge that plugs into the other slot and looks for this signature to know which game it has in front of it. With this one, eight cartridges in the series are known to carry it.

The hidden mark

At 0xBFF0, behind the 0xFF filler, come thirteen bytes of katakana backwards, the length, the catalogue number in BCD and 0xAA:

RC-736   コナミのボクシング

The format was worked out by Manuel Pazos (@ManuelPazosMSX). tools/marca_konami.py only reads it.

INIT and the hook

INIT (0x4091) does five things and stops:

  1. RSLREG and EXPTBL to find out which slot it is in, and ENASLT to leave the whole cartridge visible at 0x4000..0xBFFF;
  2. interrupt mode 1 and a jp to the 0x403D hook in H.KEYI (0xFD9A);
  3. the stack at 0xE7FF, just below the variables;
  4. 0x7EF bytes from 0xE000 zeroed;
  5. the PSG silenced, all 16 KB of VRAM zeroed and the eight VDP registers set.

And then a jr $ at 0x40D9. The whole game happens inside the interrupt.

VRAM, the other way round

The eight bytes at 0x4429 are 02 E2 0E 7F 07 76 03 E4. R3 = 0x7F and R4 = 0x07 put the colours below the patterns:

colour             0x0000..0x17FF   three banks of 0x800
sprite patterns    0x1800..0x1FFF
patterns           0x2000..0x37FF   three banks of 0x800
names              0x3800..0x3AFF
sprite attributes  0x3B00..0x3B7F

R7 = 0xE4 says the border is blue... but it does not last: monta_una_columna_del_fondo (0x439E) rewrites it to 0xE1 on every call, and from the intro onwards the backdrop is black.

And a trap you pay for once: the cartridge writes addresses like 0x7800 or 0x6008. SETWRT only looks at fourteen bits, so 0x7800 is 0x3800 and 0x6008 is 0x2008.

The controls

lee_el_mando (0x443C) reads one joystick through the PSG, and bit 7 of (0xE002) flips on every call between port 1 (0x8F) and port 2 (0xCF). Since the hook calls it twice a frame, the bit returns to where it was on its own.

The keyboard uses the same bit layout, and each boxer has his own set:

  up down left right punch
one cursor up cursor down cursor left cursor right SPACE
other E C S F SHIFT

The second set is the diamond around D. And there is a second button: bit 6 of keyboard row 7, which is SELECT.

The code

The cartridge shares its frame with the other Konami titles of the period: 561 bytes in common with Knightmare (RC-739) and 562 with The Goonies (RC-734), measured with tools/comun_normalizado.py. The dispatcher even falls at the same address as in Knightmare, 0x406C.

The interrupt hook

0x403D is the whole program. Every frame:

  1. it reads the VDP status, which is what lowers the interrupt request;
  2. the sound, always, even if the previous frame has not finished;
  3. a latch in (0xE005): if the previous frame is still inside, it does not re-enter;
  4. the controls of both boxers, one with HL' = 0xE300 and the other with HL' = 0xE009;
  5. avanza_el_reloj (0x40DB), which counts down the three timers and dispatches the scene;
  6. and on the way out, if the VDP says there was a collision, another pass of sound.

The eleven scenes

(0xE000) says which one we are in and (0xE001) the step within it. The table at 0x411C hands out, and nearly all of them start with chained djnz: the step arrives in B and each djnz eats one.

Scene 2 is the match. Its per-frame loop is 0x4338, and in thirteen calls it does the whole game: the bell, the sprites, the two boxers, the referee, the punches that land, the damage, the bars and the round.

The two boxers

Each one has an eleven-byte block, and the trick is that there is only one work area: 0x46F9 copies whichever one is due to 0xE221, does everything there and puts it back. That way the code carries no player index.

block who starting column
0xE232 the right-hand one 22
0xE255 the left-hand one 2

(0xE22F) alternates between 0 and 1 on every call and is what says which is which. And each one comes in knowing the other's action, which is the only thing it knows about its opponent.

The actions

(0xE228) says what he is doing. The table at 0x4C72 turns the five control bits into one of them:

pressed action  
up 3 stand up
down 1 duck
left / right 9 / 0x0A walk
punch 8  
punch + up 5  
punch + down 6  
punch + left / right 4 / 7  

The other 23 combinations give zero. When a punch starts, 0x48D6 adds four to it: actions 9 to 0x0C mean "throwing punch 5 to 8". And 0x0D to 0x10 are wait, take it, back off and go down.

The punch that lands

mira_si_entra_el_golpe (0x4C92) settles it once per boxer, and the order is decided by the parity of (0xE23E)+(0xE261). The two index registers are the split: IY to the block of the one throwing and IX to the action of the one receiving. Hence the punch lands with a ld (ix+000h),00eh, which is the action of taking it, and when the threshold is passed (ix+0) becomes 0x10, which is going down.

Damage is two bytes: the level, 0 to 8, and what has piled up inside the level. Each level's threshold comes from 0x5445, and it falls: the more battered you are, the sooner you go down.

The drawing

pinta_una_figura (0x4F66) redraws a boxer's body by redefining tiles the screen already has in place. Four pointers per figure: two to the patterns and two to the colour, which sits at the same offset with bit 13 cleared (the res 5,a at 0x4F81).

Each boxer has two sets of tiles and they take turns frame by frame: 0x30 and 0x80 for the player, 0x58 and 0xA8 for the opponent. While one is on screen, the other is being built.

And the head and the gloves are not tiles: they are 16x16 sprites that monta_los_sprites_de_una_figura (0x5178) writes in one go, four bytes each, with the spare ones parked on row 0xCF.

The sound

Three voices with a fourteen-byte block each from 0xE311. The sound number acts as state and priority at the same time: a new one only gets in if its number is not lower than the one already playing. And how many voices it takes depends on the number: below 7 only the third, from 7 to 0x12 two, and from 0x13 up all three.

In the emulator

The pictures on this site are not captures: they are built by running the cartridge's steps in Python. And to know whether that is right, looking at them is not enough —they have to be subtracted from the real VRAM.

How the dump works

make vram

It launches openMSX twice with two Tcl scripts and compares what comes out:

Each moment produces two files: the 16 KB of VRAM as they are and a .txt with the state of the game, so it can be said what the comparison is against.

What comes out

presentacion    colour 0  patterns 0  names 0   TOTAL 0
menu            colour 0  patterns 0  names 0   TOTAL 0
opponent 1      colour 0  patterns 0  names 0   TOTAL 0
  boxers        attributes 0  patterns 0  body tiles 0 (50 tiles)   TOTAL 0
  (with figures) colour 0  patterns 0  names 0   TOTAL 0
opponents 2..6  colour 0  patterns 0  names 0   TOTAL 0
  boxers        attributes 0  patterns 0  body tiles 0   TOTAL 0
---- 8 screens, 0 bytes different

The boxers are compared on their own

The interrupt hook rebuilds the sprites every frame, so comparing the whole sprite tables would only measure the delay of the dump. But at the moment of the dump both boxers are in the action and the column the .txt records, so tools/coteja_vram.py builds them with those —taking each one's starting pattern from the dump itself, because they alternate with the frame counter— and compares the twelve sprite attributes, the 32 pattern bytes of every sprite on screen and the body tiles the name table has in rows 8 to 15. That is what tells the six opponents apart, and until it was added the comparison was blind to it: the first version of this site said the second round was the first three opponents with the colour swapped, and it was not.

What is NOT compared, and why

Handles for poking around

You can start on whichever bout you like by writing (0xE207) before monta_el_combate reads it, which is exactly what the script does. And (0xE000) governs the scene: a 2 in there takes you to the attract match.

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, 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 Ping Pong 19 202 pinta_texto (0x407A) = pinta_rotulo
King's Valley 18 190 descomprime_desde_palabra (0x45DD) = dibuja_guion_con_direccion
Yie Ar Kung-Fu II 18 186 pinta_texto (0x407A) = pinta_guion
The Goonies 17 175 pinta_texto (0x407A) = pinta_guion
Hyper Sports 2 16 162 borra_la_pantalla (0x4567) = BORRA_LA_PANTALLA
Knightmare 16 163 pinta_texto (0x407A)
Hyper Sports 3 15 157 pinta_texto (0x407A) = pinta_guion_de_tiles
Road Fighter 15 143 pinta_texto (0x407A) = escribe_rotulo
Konami’s Soccer 14 141 pinta_texto (0x407A) = escribe_un_rotulo
Hyper Rally 13 126 repite_un_trozo (0x69CC) = SONIDO_CTRL

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.