This repository holds a commented disassembly of Konami's Billiards for the MSX (Konami, 1984, cartridge RC-706). Everything here comes out of the binary and can be generated from it again.
The ROM goes in the root, named billiards.rom. It is exactly 16384 bytes:
sha256 38741612e0b20e39dfd834106a3d5ef5a24c06fb947a104c044f1cdd269c46d9
make comprueba verifies it.
make verify
This reassembles the listing with pasmo and compares the result against the
original ROM, byte for byte. If it prints OK: reproducible byte a byte, the
disassembly has invented nothing: it is the same cartridge written differently.
make # the whole cycle: listing, notes, verify, sanity and tests
make listado # regenerates src/billiards.asm from the trace and the notes
make sanity # the checks reassembly does NOT cover
make test # the tests
make densidad # how many comments each routine carries
make imagenes # rebuilds the pictures in docs/imagenes from the ROM
make web # regenerates the site
make sanity is the one that watches for what a correct reassembly can hide:
data being read as code. The bytes come out the same either way, because they do
not change; the only thing that changes is what we say about them.
src/billiards.asm the listing, GENERATED — not edited by hand
src/billiards.notes the annotations, anchored to addresses
src/billiards.entries the entry points that cannot be deduced
src/billiards.nocode the stretches that are not code
tools/ the tracer, the generator and the checks
docs/ this site
The listing is never edited: you edit the .notes and regenerate. Every
annotation is anchored to an address, so it survives a retrace and does not slide
out of place if something moves.
The .notes directives are five: L names and describes a label, C hangs a
comment off an instruction, B inserts a block header, D declares a data range
with its name, and F says how many bytes a table's rows are.
make imagenes
There is not a single screenshot on this site. tools/graficos.py replays the
cartridge's loading routines and its two drawing interpreters, instruction by
instruction, onto an empty video memory, and then develops that VRAM the way the
VDP would. No emulator is needed, and the table coming out right is the best
proof that the routines have been read correctly.
Sixteen kilobytes in the MSX's page 1, from 0x4000 to 0x7FFF. The game takes up 8,115 bytes: from 0x5FB3 onwards there are 8,269 bytes of 0xFF in a row, chip padding that no instruction ever reads.
41 42 5F 40 00 00 00 00 00 00 00 00 00 00 00 00
A B INIT=0x405F
AB is the signature the BIOS looks for at boot, and behind it come four
pointers. This cartridge declares only the first one, INIT; the other three —
STATEMENT, DEVICE and TEXT — are zero.
0x405F does this, in order:
jp 0x4034 in the H.KEYI hook (0xFD9A), the one the BIOS calls
on every interrupt.jr $ (0x409E) and never comes out.From then on the main thread does nothing. The whole game runs inside the interrupt, which is the usual arrangement in Konami cartridges of this period.
SCREEN 2, with the register table at 0x46BE:
| table | address |
|---|---|
| names | 0x3800 |
| patterns | 0x2000, in three thirds of 0x800 |
| colours | 0x0000, in three thirds as well |
| sprite attributes | 0x3B00 |
| sprite patterns | 0x1800, 16×16 |
In SCREEN 2 the character generator is three independent tables, one per third of the screen, which is why nearly every load in the cartridge repeats the same copy three times adding 0x800. The exception is the big title lettering (0x5766), loaded into the first third only: that is where its two rows fall.
Almost nothing is copied raw. There are two formats, and both turn up all over the cartridge.
Format A, read by 0x472E: two destination bytes in VRAM and then the tile numbers, with 0xFE to change destination and 0xFF to finish. Every text label uses it.
It has a nice touch: the same list serves to draw and to erase. Entering at
0x472A instead of 0x472E, the only difference is that C holds 0x00 rather than
0xFF, and down in the loop there is an and c that turns every tile into a zero.
The menu's blinking is the two entry points of one routine over one list.
Format B, read by 0x4969: a stream of commands where bit 7 separates the two cases. With the bit set, the low seven say how many literal bytes follow; without it, how many times the next byte repeats. 0x00 closes the block and 0xFF means another destination follows. The Konami logo, the table colours and the whole table plan are compressed with it.
The 48 glyphs at 0x4136 are loaded into tiles 0x30 to 0x5F, and those numbers are exactly the ASCII codes of the characters they draw: the digits, a few symbols and the capitals.

That is why the cartridge's text lists spell the words out literally, in ASCII, with no conversion table in between. In the slot where ASCII has the backslash, the bracket and the underscores (0x5C to 0x5F) sit four drawings of its own: the two menu cursor tiles, a diamond and a filled ball, which are the ones that draw the goes and the spare balls on the scoreboard.

The 59 table tiles are copied verbatim from 0x4A70, but their colours come compressed separately at 0x4C40. And there is a deliberate overlap there: the first eight bytes of the colour block are also the last eight of the pattern copy. Konami spliced the two tables to save eight bytes.
There is a second overlap, and a stranger one. The sprite patterns are copied from 0x4B30, which sits inside the table tiles: the balls and the cloth drawings are the same bytes read two ways.
![]()
288 bytes are copied, enough for nine 16×16 sprites, but only eight are real drawings: the cue ball, the six numbered ones and the aiming dot. The ninth overruns the end and lands on the table's compressed colours. Nothing uses it.

Measuring the patterns themselves, a ball's drawing takes ten pixels across by twelve down. With the square pixel of a modern monitor —the top row— that is an oval, and it shows.
Ten and twelve are screen pixels. The VDP's register 1 comes from 0x46BE and holds 0xE2: bit 1 set asks for 16×16 sprites, and bit 0 clear leaves MAG = 0, no magnification. Magnified, every pattern pixel would cover two on screen and the figures above would have to be doubled.
The bottom row is the same drawing with each pixel painted five across by four down, which is the ratio usually attributed to an MSX pixel on a television of the period. The 10×12 becomes 50×48: round, to within 4 %.
The ratio that would make the balls exactly circular is 12/10, that is 6:5, which falls between the two figures usually quoted for the MSX pixel. That one does come from the cartridge; what an MSX pixel is really worth depends on the television, and the binary does not say.
The picture is drawn by tools/graficos.py from the bytes of the ROM.
No. The physics works 1:1, and you can point at it:
busca_choques (0x4F25) does its first sieve with cp 00Ch on the Y
difference and the very same cp 00Ch on the X one: twelve pixels on both
axes;resuelve_el_choque (0x4F63) confirms with Pythagoras, and treats both
components with the same instructions —the same four-bit shift, the same
squaring— before adding them;calcula_el_tiro (0x4CA8) gets the distance to the aiming point the same way,
dY and dX squared and the root;saca_la_pendiente_del_vector (0x5430) divides both components by 32 and
compares, favouring neither;So the balls look round and behave as if the space were square. In practice that means a ball covers more real distance per pixel vertically than horizontally, and a 45° angle in the code does not look like 45° on screen. It is the solution of the period, and it is the cheap one: correcting the ratio would cost a multiplication per axis on every collision.
It was pointed out by theNestruo in this repository's first issue.
The TMS9918 has thirty-two sprites in its attribute table —here at VRAM 0x3B00, which is what R5 = 0x76 asks for— but it only draws four per scanline. From the fifth on it drops them on that line and raises its fifth-sprite flag. X plays no part: a sprite counts on a line if that line falls inside its box, and with 16×16 and MAG = 0 the box is sixteen lines, Y+1 to Y+16. Sixteen, not the twelve a ball's drawing measures.
Billiards uses eight of the thirty-two entries: the cue ball, the six numbered ones and the sight.
![]()
The eight starting positions are at 0x461F, four bytes each (Y, X, pattern, colour). Counting whole boxes:
| lines | sprites | which |
|---|---|---|
| 97-104 | 1 | the 4 |
| 105-112 | 2 | the 2 and the 4 |
| 113-120 | 4 | the cue ball, the 1, the 2 and the 5 |
| 121-128 | 4 | the cue ball, the 1, the 3 and the 5 |
| 129-136 | 3 | the 3, the 6 and the sight |
| 137-144 | 2 | the 6 and the sight |
Four at most, never five. And by a hair: the box of the 4, which starts at Y=0x60, ends on line 112, exactly where the boxes of the three that start at Y=0x70 begin. One pixel breaks the arrangement: the 3, which starts at Y=0x78, moved a single line up already puts five sprites on line 120.
In the picture each ball carries its 16×16 box —the dashed square, which is what
the VDP looks at— and the column on the right counts, line by line, how many
sprites touch it, with the figure beside it; the lines where the count reaches
four come out in red. It
is drawn by tools/sprites_por_linea.py from the bytes of the ROM, and the same
program hangs off make sanity: if any of these figures stopped coming out of
the binary, the make would go red.
A ball's centre can only sit between Y=0x3E and Y=0xA1 —the two sub in
mueve_una_bola, the sub 03Eh at 0x4ED4 and the sub 064h at 0x4ED6— so the
boxes of the seven balls live in 115 lines, from 63 to 177. And between the seven
they measure 7 × 16 = 112. Three lines to spare: two boxes overlapping is not the
exception, it is what happens all the time. With five overlapping, the VDP draws
four and swallows the fifth.
The cartridge does not avoid it. What it does is make sure the one that is lost
is not always the same one. refresca_los_sprites (0x463F) dumps the eight
entries to VRAM in two groups of four, and bit 0 of the frame counter decides
which group goes first:
avanza_el_juego bumps it with the inc (hl) at
0x433A, once per interrupt;rra at 0x4651 carries that bit 0 into the carry flag and picks the half
it starts with;rr c at 0x465E pulls it out again for the second half, which is the other
one.On an even frame the order in the attribute table is cue-1-2-3-4-5-6-sight; on an odd one, 4-5-6-sight-cue-1-2-3. Since the VDP keeps the first four on the list that touch the line, the one that is lost changes every frame.
An example. If the cue ball, the 1 and the 2 —first group— share a line with the 4 and the 5 —second group—, the even frame draws cue, 1, 2 and 4, and swallows the 5; the odd one draws 4, 5, cue and 1, and swallows the 2. Neither disappears outright: both flicker, at 25 Hz on a PAL MSX and 30 Hz on an NTSC one.
The cartridge never looks at the fifth-sprite flag. It reads the VDP status register three times —at 0x4035, 0x405A and 0x409A— and throws the value away all three: it is there to acknowledge the interrupt, not to find out what was lost.
The table is not stored as a screen of 768 tiles. At 0x4C59 there is a strip of groups, and each group is a number followed by a format B block: the number says how many consecutive rows carry that same drawing. The routine that unrolls it (0x4A39) draws the block and steps down 32 bytes at a time from row 7, reloading the pointer on each pass because the interpreter leaves it at the end. A zero closes the plan.
Seven groups covering sixteen rows, from 7 to 22, in 79 bytes.
Manuel Pazos found that Konami cartridges of this period hide their RC-7xx
catalogue number and the game's title in katakana at the end of the ROM. This one
does not: there is not a single RC-7 in ASCII in the 16 KB, and the end of the
chip is 0xFF all the way.
The RC-706 this cartridge is known by comes from the catalogue, not from the binary.
5,343 bytes of code and 11,041 of data. The main thread has been stuck in a
jr $ since boot, so everything that follows happens inside the VDP interrupt,
fifty times a second.
0x4034 does four things in this order: acknowledges the VDP — which is what lowers the signal — steps the sound player, checks the latch at 0xE005 and, if it is free, reads the controls and runs one step of the game.
The latch matters. Just before entering the game step, the routine does ei: it
opens interrupts while it works. If the step overruns a frame — and the
physics of seven balls does overrun — the next interrupt comes in, sees the latch
closed and leaves without doing anything but servicing the sound. The music does
not stutter even when the game is running tight.
The game step (0x4337) increments the frame counter and dispatches on 0xE000, the state, which runs from 0 to 15.
The dispatcher (0x40A0) is not given the table's address. It does pop hl to
take its own return address and use it as the base, so the table of sixteen
words sits immediately behind the call that invoked it, and control never
returns there. It ends in jp (hl).
There are three such tables in the cartridge: the sixteen states behind the
call at 0x434D, the three tally phases behind the one at 0x5ACA, and the four
demonstration steps behind the one at 0x5EB6.
The states do what you would expect: 0 to 7 are the title screen and menu, 8 confirms the selection, 9 racks a ball, 10 sets the table, 11 is the shot, 12 decides it, 13 changes player, 14 waits after GAME OVER and 15 celebrates a cleared table. State 3 is a dead step: its table entry points at the instruction that only increments the state.
The table is eight sixteen-byte records from 0xE100:
| byte | what it is |
|---|---|
| +0 | 0xFF while the ball is still on the cloth |
| +1 | the energy it has left; at zero, it has stopped |
| +2 | the angle it is travelling at |
| +3 and +4 | Y in 16 bits, with the integer part in +4 |
| +5 and +6 | X in 16 bits, with the integer part in +6 |
| +7 and +8 | the Y velocity, signed |
| +9 and +10 | the X velocity |
| +11 and +12 | sprite pattern number and colour |
| +13 and +14 | the friction, split by component |
| +15 | which ball it last collided with |
The position is fixed point 8.8, and the integer byte lands exactly where the sprite dump will read it: moving a ball is adding two 16-bit words to two others, and the sprite finds out by itself.
The four bytes the VDP needs — +4, +6, +11 and +12 — are dumped by 0x466D in one go through the data port, riding the VDP's auto-increment. And the order of the two groups of four balls alternates with bit 0 of the frame counter, the usual trick against the TMS9918's sprites-per-line limit.
Moving (0x4E6B) adds the velocity to the position and checks whether the ball has left: the table runs from X=0x14 to X=0xD8 and from Y=0x3E to Y=0xA1. If it has left where there is a cushion, it reflects it — position minus twice the overshoot — and negates that velocity component. If it has left where there is a pocket, it goes to the routine that sinks it.
Colliding (0x4F25) walks the other six balls with a cheap sieve: if the two coordinates differ by less than twelve pixels, contact is possible. Then 0x4F63 measures the real distance, with the two squares summed and compared against 0x9000, which at that scale is the same twelve pixels.
Friction (0x53DD) comes in one frame in every eight: it takes 3 off the energy and adds to each velocity component the friction held in +13 and +14, always with the opposite sign to the motion. Since those two bytes are the unit vector components scaled to 24/256, the ball slows down along its own line and does not veer as it stops.
If both balls are rolling, the cartridge swaps their velocities and that is that (0x5192): the head-on collision between equal masses, solved without a single multiplication.
If one was at rest, then there is a calculation. It measures the angle of the line joining the two centres, compares it with the angle the ball was travelling at, and that difference — saturated at 0x3C, nearly a right angle — goes into the cosine table: the part of the motion falling along the line of centres is handed over, the perpendicular part stays. The striking ball leaves along the perpendicular, and for that the two components are crossed as they are written, which is turning the vector ninety degrees without touching it.
A direction is not kept as an angle, but as a slope within an octant plus two mirror bits. The routine at 0x5430 takes the two velocity components, keeps their absolute values, notes in 0xE1A2 which way each was heading, divides both by 32 and compares: the larger becomes the divisor and the smaller the dividend, so the quotient always lands between 0 and 255 and tables of 256 entries are enough.
There are four, all checked against their formula with a maximum error of 1:
| table | what it holds |
|---|---|
| 0x539C | 65 values of 255·cos, for sharing out the collision |
| 0x54E6 | 256 values of 255·sin(atan(p)) |
| 0x55E6 | 256 values of 255·cos(atan(p)) |
| 0x56E6 | 64 values of atan, in 1/256 of a turn |
The one at 0x539C is read twice, with the index and with its complement to 0x40,
and out come the sine and the cosine from a single table. And when the final
angle is assembled, the two mirror bits are combined using parity: an and a
over 0xE1A2 and a jp pe, because negating the angle is needed when exactly one
of the two axes is mirrored.
0x5376 takes the root of HL by subtracting odd numbers: 1, then 0, then 2 and 2,
then 4 and 4… and returns how many rounds it survived. Run over all 65,536
possible values, it returns exactly round(sqrt(n)), the root rounded to the
nearest integer rather than truncated.
It is used for the distance between the cue ball and the aiming point, which is what divides the two shot components to leave them as a unit vector. Half a pixel there shows up in the direction.
Three nine-byte channels from 0xE010, each with its counter, its pointer into the score and the sound number it is playing, which doubles as its priority: a new sound only gets in if its number is greater than or equal to the one playing.
What you request is not a channel but a sound, and depending on its number one, two or three channels start at once with consecutive pointers from the table at 0x5D1C. Below 0x87 it is a one-channel effect; from 0x8A up, three-channel music.
Notes carry the duration in the high nibble and the semitone in the low one, and semitone 12 is a rest. The frequency divisor comes from the table of twelve at 0x5D08 and is doubled once per octave to be dropped. The volume decays on its own, in software, by comparing two counters.
And a detail of the kind that pleases: the channel's volume register comes from rotating C — which holds 1, 3 or 5 — and adding 0x88. That gives 8, 9 and 10, which are exactly the PSG's three volume registers.
(ix+002h) twice in a row with the same value. Three bytes
that change nothing.push hl followed by pop hl turns up several times in the routines that write
sprites and cards (0x59E8, 0x5A01, 0x5B66). They move nothing: they are
twenty-one clock cycles of waiting so the VDP has time between two consecutive
writes.
And at 0x5488 there is an ld a,r. The R register is the dynamic memory refresh
counter, which changes on its own, so it serves as a random number for free. The
cartridge keeps its low bit and uses it to flip bit 0 of the slope it has just
computed: every direction comes out with one unit of noise on it.
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, 45 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) |
|---|---|---|---|
| Magical Tree | 9 | 116 | refresca_el_marcador (0x47F1) = pinta_el_marcador |
| Cabbage Patch Kids | 8 | 97 | pinta_el_numero_de_fase (0x4833) = PINTA_FASE |
| Circus Charlie | 7 | 67 | pinta_lista_formato_a (0x472E) = pinta_rotulo |
| Athletic Land | 6 | 111 | paso_de_un_canal (0x5C2B) = SUENA_PASO |
| Hyper Sports 1 | 6 | 76 | pinta_el_numero_de_fase (0x4833) = PREPARA_TABLERO_42E5 |
| Monkey Academy | 6 | 105 | paso_de_un_canal (0x5C2B) = SUENA_PASO |
| Konami’s Mahjong Dojo | 5 | 55 | despachador (0x40A0) = despacha_por_tabla |
| Konami's Ping Pong | 5 | 43 | programa_los_registros_del_vdp (0x46AD) = carga_los_registros |
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.