This repository holds a commented disassembly of Frogger for MSX (Konami, 1983, cartridge RC-704). Everything here is generated from the binary and can be reproduced from it.
Put the ROM in the root as frogger.rom. It is 8192 bytes exactly:
sha256 0d60ff78e1ab466bce6e888193ca62d6df71fa07344c8ea31f7a8b486323c5f5
make comprueba checks it for you.
make # trace, listing, reassembly, checks and tests
make listado # rebuild src/frogger.asm from the notes
make verify # reassemble and compare against the ROM, byte for byte
make sanity # nothing declared as data may come out as code,
# and not one byte may be left unassigned
make test # the test suite
make imagenes # rebuild the pictures from the ROM
make web # rebuild this site
src/frogger.entries |
the entry points, each with its justification |
src/frogger.nocode |
the four tables the tracer must not read as code |
src/frogger.notes |
the only file edited by hand: every annotation |
src/frogger.asm |
the listing, generated by tools/mkasm.py |
tools/ |
the tracer, the listing generator and the measuring tools |
tests/ |
23 checks over the listing and the notes |
docs/ |
this site |
Annotations are anchored to an address, so they survive a retrace. The directives follow theNestruo's conventions:
L |
a label and what the routine does |
C |
a comment on that one line |
B |
a block header before that address |
D |
a range of data, with a name and an explanation |
F |
how wide the rows of a data block are |
The tracer follows the real flow from the entry points. Whatever cannot be
worked out statically — the interrupt hook, the four tables embedded behind a
call — is declared by hand in the .entries file, each with the reason
written next to it.
Nothing here is a guess dressed up as a fact. Where something is not known, it is in Open questions and it says so.
make verify reassembles the listing and compares the result against the
original ROM. It has to come out identical, byte for byte. make sanity
then checks what reassembly cannot catch: that no range declared as data is
being read as code, and that not one of the 8192 bytes is left unassigned.
An 8 KB cartridge in page 1, from 0x4000 to 0x5FFF. It is the smallest Konami cartridge in this series — half of any of the others.
4000 41 42 b4 41 00 00 00 00 ... "AB", then INIT = 0x41B4
Only INIT is declared; the other three vectors are zero. INIT hooks the
interrupt by writing jp 0x4012 into H.KEYI (0xFD9A) one byte at a time, wipes
the 2 KB of game RAM with a single LDIR, puts the stack at 0xE7FF and loads
the title screen.
SCREEN 2, with the eight registers coming from 0x49A3:
| name table | 0x3800 |
| pattern table | 0x2000 |
| colour table | 0x0000 |
| sprite attributes | 0x3B00 |
| sprite patterns | 0x1800, 16×16 |
SCREEN 2 splits patterns and colours into three 2 KB thirds and the game wants them identical. It gets that with one copy of 4095 bytes whose destination runs 2 KB ahead of the source (0x471A): past the first third it is already reading what it just wrote, so the second propagates into the third by itself.
Twelve blocks with a header — destination, size, data — go up from 0x4B36 (0x4956 reads them). Then the same bytes go up a second time, at characters 0x98 and 0xB7, because in SCREEN 2 colour goes per pattern line and the same character cannot be two colours. The colour table gives cyan to one copy and white to the other.
The digits of the scoreboard are patterns 0xE0 to 0xE9, which is why printing a BCD number is just adding 0xE0 to the digit (0x4651).
Logs, turtles and cars are not sprites. They are characters, and to move them two pixels at a time the cartridge keeps four versions of every drawing in video memory, shifted 0, 2, 4 and 6 pixels (0x473C).
Each object's position is stored in quarters of a character: the low two bits pick the version and the rest is the column. Each row is assembled in a RAM buffer of two rows of 40 columns (0xE600) and 22 columns of it are then pushed to video memory.
Only four things use sprites: the frog (two), the crocodile (four), the creature that crosses the river and the frog you rescue. That is what the MSX1's limit of four sprites per line is being saved for.
Three channels, each with an 8-byte record (0xE020, 0xE028, 0xE030). A tune is a string of three-byte notes: fine period, coarse period with the volume in the top nibble and bit 3 for noise, and duration. A negative duration makes the note fade on its own. 0xFF ends the tune.
Priority is by address: 0x50E7 only takes a new effect if the channel is quiet or if the tune being asked for sits at a lower address than the one playing.
These 163 bytes are the same code as Time Pilot's — see Findings.
| bytes | ||
|---|---|---|
| traced code | 4,880 | 59.57 % |
| identified data | 3,312 | 40.43 % |
| unexplained | 0 | 0.00 % |
The BIOS enters at 0x4012 on every retrace. The first thing it decides is what this frame is for, by reading 0xE043: bit 0 means only the demo and the sound, bit 6 only the sound. With no game running, all it does is bump the frame counter.
Then it decides which scene, by reading 0xE040 one bit at a time with
rrca:
| bit | |
|---|---|
| 0 | the death |
| 1 | the time bonus (inside the game) |
| 2 | stage cleared |
| 3 | the game is over |
| 4 | build the stage |
With none of them set, the normal game runs: the lanes, the frog, the river creature, the frog to be rescued and the collisions, in that order.
0x57FF is not a dispatcher that jumps. It takes the return address as the
base of a table embedded right behind the call, returns the Ath word in BC,
walks forward to the 0xFF that closes the table and rets to the byte after
it.
Four places use it, and it is the one thing a tracer cannot follow on its own: those four tables have to be declared by hand, or 700 bytes of label lists get read as instructions.
Eight rows move — four of river and four of road — and they do not fit in one frame, so they are spread over three (0x55E5). Each row also has its own clock in a single byte: the low nibble counts down and the high one says how often (0x5682).
Every object is a four-byte record: type and flags, position in quarters of a character, signed speed, and the diving counter.
Types 7 to 12 animate, but only if bit 7 of the fourth byte is set — and that bit is written by hand, at two addresses when the stage is built. The counter runs from 0x80 to 0xC0 and on the way the type goes up one at 0x90 and another at 0xA0, then back down at 0xB0 and 0xC0. Since the type is what picks the drawing, the turtle sinks and comes back up on its own.
Types 9 and 12 have all four collision margins at zero (0x49C7): those are the fully submerged ones, which is why they do not hold the frog up.
The only thing in the river drawn with sprites — four of them. It opens and closes its mouth on a 32-step cycle: 22 steps with drawing 0x40 and 10 with 0x3C. With the mouth open, 0x524F checks the head separately and it kills instead of carrying.
Everything is checked against the frog in one place (0x5185): the river creature, the frog to be rescued, the screen edges and, if the frog is in the water, whichever row of logs it is standing on. Which row that is comes from how far up it has got (0xE28A).
In the water, touching something is what saves you. On the road it is what kills you.
No random generator. The frog is driven by a list of fifteen bytes at 0x584F, one per move, in the same format as the controls. The pointer at 0xE049 is reset to the start whenever a stage is built, and only its low byte is incremented — so the list cannot cross a page boundary.
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, 6 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) |
|---|---|---|---|
| Time Pilot | 16 | 236 | CANAL_PON_VOLUMEN (0x4167) |
| Hyper Olympic 1 | 4 | 35 | PARPADEA_LA_ELECCION (0x4328) = TITULO_PARPADEA |
| Hyper Olympic 2 | 4 | 35 | PARPADEA_LA_ELECCION (0x4328) = TITULO_PARPADEA |
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.