Under the hood

Getting started

What you need

pasmo and z80dasm to assemble and disassemble, and Python 3 for the tools.

The cartridge isn't distributed with this repository, only the documentation work, so you'll need your own copy named antarctic.rom in the project root. It's exactly 16384 bytes and has to give this sha256:

a33f9298bf6f740ebe8d88bdc8ed75c855404d804e07679d6c2f2ad00dc3c452

If yours doesn't, it's a different version and the listing won't reassemble. make comprueba tells you in one line.

The commands

make          # trace, build the listing and check everything
make verify   # just the acid test: does the cartridge come back out?
make graficos # decompress the artwork and dump it to PNG

Plain make runs the whole cycle and fails if anything doesn't add up: if the listing stops reproducing the cartridge byte for byte, if the tracer has walked into a range declared as data, or if an entry point falls inside one.

The test that settles it

The only thing that makes a disassembly trustworthy is that it gives the original back. Here that's make verify, which assembles the published listing and compares the sha256 against the cartridge:

ensamblado : 16384 bytes  a33f9298...dc3c452
original   : 16384 bytes  a33f9298...dc3c452
OK: reproducible byte a byte

As long as that line shows up, no comment in this repository can have eaten a byte along the way.

Without the cartridge

You can still read src/jap2/antarctic.asm and the notes, which is where the work actually lives: 394 named routines, 713 comments anchored to their address, and 63 data ranges with an explanation beside each one.

How it's laid out

The listing is never edited by hand. It's generated, and three files govern it:

   
src/jap2/antarctic.entries the entry points: where tracing starts
src/jap2/antarctic.nocode the ranges that are NOT code, and how we know
src/jap2/antarctic.notes the names, the comments and the data ranges

Out of those comes src/jap2/antarctic.asm. If you want to change a comment or name a routine, it goes in the .notes, anchored to its address; that way the comment survives a re-trace and never drifts away from the instruction it explains.

That separation is exactly what stops the listing and its verification from diverging over time, because the file that gets published is the same one that gets checked.

How the data blocks are laid out

Every data range declared in the .notes comes out as a block of its own: its own heading saying what it is for, its own label, and the dump aligned to its first byte, so where one table ends and the next begins is visible at a glance. An optional line gives the block the row width of its real structure -two bytes per stage, eight per list, defw for a table of pointers- and where a pointer lands on a block that has a name, that name is written next to it.

The tools

Everything you need is in tools/, and each one carries in its header what it does and why it was built that way:

   
z80trace.py follows the flow from the entry points
mkasm.py assembles the listing with the anchored notes
descomprime.py the game's decompressor, reimplemented
refs.py what instructions point into a range, without inventing pointers
render_tiles.py draws the tiles and sprites from video memory
render_banderas.py the flags of the ten stops
render_decorados.py the scenery, using the game's own interpreter
render_pista.py the seven obstacles, built up step by step
render_foca.py the seal that comes out of the holes, frame by frame
render_pinguino.py the penguin's ten poses, in its own colour

The cartridge

It's 16384 bytes, and that's it. No loader, no blocks, nothing to wait for: the MSX maps the cartridge at 0x4000-0x7FFF and what's there is what's there, permanently. That makes the byte budget far cleaner than it usually is, because there aren't two different things living at the same address at different moments: one single snapshot of memory, no overlaps.

Where it comes in

The first sixteen bytes are the header the BIOS reads:

41 42 10 40 00 00 00 00 00 00 00 00 00 00 00 00
'A' 'B'  \_ INIT = 0x4010

The two letters are the signature telling the machine there's an executable cartridge here, followed by four two-byte vectors. Only the first is filled in: the other three —the ones that would add statements to BASIC or declare a device— are zero. This cartridge is a game and nothing else.

So the BIOS finishes bringing the machine up and calls 0x4010. And from there it never comes back.

What the startup does

Not much, and all of it deliberate:

That empty loop is the main program. From then on the entire game runs inside the interrupt, fifty or sixty times a second, and the thread that started the machine never does anything again.

Where the state lives

There isn't a single variable in the cartridge, because it's ROM. Everything the game keeps track of lives in the MSX's RAM from 0xE000 upwards, which is why the listing is full of addresses starting 0xE0: they aren't cartridge data, they're variables.

The ones read most:

   
0xE000 the game state, 0 to 15
0xE001 the step within that state
0xE003 the frame counter, which serves as a clock for everything
0xE005 the latch stopping the interrupt from treading on itself
0xE009 what's being pressed, with the previous frame's at 0xE008
0xE040 the high score, with the score at 0xE043
0xE078 the penguin's four sprites
0xE100 the speed
0xE112 the obstacle slots

The screen, laid out backwards

The game doesn't settle for what the BIOS leaves behind: it writes the graphics chip's eight registers itself, from an eight-byte table it carries. And the layout it ends up with is the opposite of the usual one.

   
0x0000 the colours
0x1800 the sprite patterns
0x2000 the patterns
0x3800 the name table
0x3B00 the sprite attributes

The normal arrangement has patterns low and colours high; here it's the other way round, and that matters more than it sounds, because drawing the cartridge with the bases swapped doesn't produce an error: it produces a picture, and a convincing one at that, since a colour table read as artwork looks a lot like artwork. That's why this repository's tools take the bases from the registers the game writes, and not from a constant typed in by hand.

The mode is the 256x192 graphics one with unmagnified 16x16 sprites, and the border ends up dark blue.

Three banks, and sixteen flat-colour tiles

In this mode the screen splits into three thirds, each with its own set of 256 tiles. The cartridge sets all three up identically to begin with: the same typeface and the same graphics written three times over, 1792 bytes of pattern and another 1792 of colour in each third.

And there's one detail that pays for itself: the first sixteen tiles of each third are flat colour squares, one per palette entry. They're built by hand, uncompressed, by writing the colour number eight times over. With those, painting the sky or the ice costs no artwork at all: you fill the row with the tile of whatever colour you want.

And everything else is compressed

Not a single graphic sits there raw. There's a 61-byte decompressor reading a format you can follow at a glance —one byte says whether what follows repeats so many times or is so many bytes taken as they come— and four separate doors into it depending on where the destination has to come from, or on whether the picture needs mirroring on the way in.

Of the cartridge's 16 KB, 10437 bytes are data and 5947 are code.

The full layout

Not one byte without an owner. Here's what's there, top to bottom:

   
0x4000-0x4010 the header
0x4010-0x44DF startup, interrupt, controls and the state machine
0x44DF-0x4787 video, strings, decompressor and the panel
0x4787-0x4843 the per-stage scenery tables
0x4843-0x4A01 the title banner, video memory access and the map
0x4A01-0x4B01 the map artwork, the route and the ten stages
0x4B01-0x53E1 the penguin, collisions, the track and the obstacles
0x53E1-0x55D9 the bends and the seven horizons
0x55D9-0x5839 the base names, the flags and the on-screen labels
0x5839-0x588A the title screen and the demo recording
0x588A-0x6BE9 the typeface and all the artwork, compressed
0x6BE9-0x7241 the 92 pieces the obstacles are built from
0x7241-0x7519 the scenery tree
0x7519-0x78C1 the finish, the fish, the speed and the background sprites
0x78C1-0x79C9 the frames of the creature from the holes
0x79C9-0x7B37 the sound player
0x7B37-0x7EB7 the notes, the durations and the sound streams
0x7EB7-0x8000 the padding up to 16 KB

The code

Everything happens inside the interrupt

This game's main program is two bytes: a jump to itself. The real work happens in the timer hook, which the BIOS calls on every screen refresh, and which does three things in this order: services the sound, moves the penguin and the clock, and takes one step of the state machine.

That third step can take longer than a frame, so it's protected by a latch. If the previous pass is still working, this one skips the step entirely and leaves by the side door instead of re-entering. The frame is lost and nothing breaks.

The state machine

One byte says what state the game is in —0 to 15— and another says which step within that state. Each frame runs whichever step is due and that's that. The sixteen destinations are:

       
0 idle 8 the control menu
1 start the intro 9 set up the stage
2 raise the logo 10 enter the stage
3 wait 11 the game
4 draw the banner 12 time up
5 wait 13 end of game
6 wipe 14 the finish
7 the demo 15 the map of Antarctica

And the normal path is: intro, demo, menu, set up, map, enter, play, finish, and back to setting up the next one. Run out of clock instead and you leave via 12 and 13 and land back in the demo.

What makes this readable are six chained routines that serve as exits. Each does its bit and falls into the next, most to least: the top three move to the next state and zero the step, the bottom three only move to the next step, and the ones with a wait leave a counter set before they fall. With those, nearly every step in the game ends in a three-letter jump.

The dispatcher, with the table tucked behind the CALL

The heart of all this is ten bytes:

DESPACHA:
    add a,a           ; the index, doubled
    pop hl            ; ...and this is NOT something off the stack
    call SUMA_A_HL
    ld e,(hl)
    inc hl
    ld d,(hl)
    ex de,hl
    jp (hl)

The pop hl isn't picking up anything anybody pushed: it picks up the return address, which is precisely the byte after the call. And that's where the table is. So the caller writes the table right behind the call, and the dispatcher finds it without anyone passing it along.

It's elegant, and it has an awkward side effect: a tracer following the flow walks straight into the table and reads pointers as if they were instructions. Which is why this cartridge's six tables are declared by hand.

The good news is they bound themselves. Each table's last word ends exactly on the byte where its own first destination begins, so only one size is possible: try N entries and only one N closes. All six close, and between them they give 42 destinations.

There's also a second dispatcher that works differently. Instead of indexing addresses it indexes code: four chunks of exactly four bytes, laid out so the index lands squarely on one of them. It drives the four moves that trace the route across the map.

The controls, and three places they come from

Whatever's being pressed always ends up in the same byte, in the same format: four directions and two buttons. But it can come from three different places, and a single flag byte decides which: from the joystick via the sound chip, from the keyboard by reading two rows of the matrix and shuffling the bits, or from a recording carried inside the cartridge, which is what drives the demo.

Since all three end up in the same place with the same shape, the rest of the game has no idea which one it's using.

The penguin is four sprites

A sprite on this MSX is 16x16, so the penguin is built from four of them in a square: 32x32 pixels. Only the first one's position is tracked, and the other three come from adding sixteen across, down, or both.

The poses live in a table of ten, four bytes each, being the four pictures each sprite gets. Changing pose is copying four bytes at a stride.

Walking is three poses rotating every eight frames. Jumping is eleven steps, one every four, with a twelve-entry curve that lifts the penguin four pixels and puts him back down; and if the button was pressed with a direction held, he also moves sideways at double speed. Falling is twenty-one steps with its own curve and its own table of rolls.

Obstacles are six-byte slots

There's room for four obstacles at once, and five from the fifth stage on. Each takes a slot:

   
+0 which step it's on, 1 to 15; 0 means the slot is free
+1 the type, 0 to 6
+2 pointer to the piece of artwork due now
+4 pointer to the four bytes the collision is checked against

The interesting one is that artwork pointer, because it advances by itself. The 92 pieces between 0x6BE9 and 0x7241 aren't screens: each one places between one and six tiles, which makes them increments. The slot runs the piece it's due, saves where it stopped, and carries on from there next step. Accumulated, what you see is the obstacle coming closer.

That this is the right reading checks itself: chain the fifteen steps of all seven types and the seven chains tile the whole region without a single byte left over, each one ending exactly where the next begins.

Drawing is executing

The scenery down the sides and the pieces of track are written in a small language, and there's a 45-byte interpreter that runs it. One byte says which column and which third to start in, and then, per row, an offset followed by the tiles written consecutively; a high byte closes the row and opens the next, and a zero closes the block.

With that, the side scenery comes out of a two-level tree —four groups of four— and the sixteen blocks hanging off it tile their region without a gap.

The track turns without moving a single pixel

The horizon row isn't drawn straight onto the screen. It's composed in memory: 32 tiles, with two bytes in front saying where on screen they go and one byte behind closing it off. When the track has to bend, what happens is that this row gets rotated with a single block-copy instruction, one way or the other, and sent again.

Which bend is due at any moment comes out of a table of nibbles, two bends to a byte, and there are seven different horizon pictures —straight, bending one way, bending the other, and the four for arriving at a base— picked by index.

The sound: the number is the priority

Three channels, one per chip voice, with ten bytes of state each. To ask for a sound you pass a number, and that number does two things at once: it says which stream plays and how much authority it has. If what's already playing has a higher number, the request dies right there.

The number also says how many channels it takes: below 0x8A just one, up to 0x8C two, and above that all three. Effects take one channel and music takes three, so an effect never cuts a tune in half.

Each note is one byte: the low nibble is the note within a twelve-note chromatic octave, and the high nibble is the duration, looked up in another table of twelve sitting right next to the first. Both have twelve entries and they're side by side, which rather invites reading them as the same thing; they aren't. Going up an octave is doubling the period as many times as needed, and there's a control byte to change it, another to repeat a section and another to finish.

Of the twenty-four stream pointers, one points outside the cartridge —sound zero, which is never asked for— and three point at the same place: an end-of-stream byte. That's the silence, and it's what the startup asks for to leave the chip quiet before it begins.

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, 48 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)
Athletic Land 14 222 CANAL_SIGUE (0x79F4) = SUENA_PASO
Monkey Academy 9 184 VOLUMEN_MIRA_FD (0x7A76) = MUSICA_EVENTO
Super Cobra 6 98 VOLUMEN_MIRA_FD (0x7A76) = MUSICA_EVENTO
Circus Charlie 5 51 PINTA_FASE (0x4709) = pinta_el_numero_de_fase

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.