Under the hood

Getting started

This repository holds the commented disassembly of Konami's Circus Charlie for the MSX (RC-712, 1984). It does not hold the cartridge: the ROM image is not distributed.

What you need

It is exactly 16,384 bytes and its fingerprint is:

sha256  89e1badac10e65886590d55e735ed794e5ca3c41142e6637b3e7ac6b25d042c0

To check it:

make comprueba

Rebuilding all of it

command what it does what it proves
make listado traces the flow and generates src/circus.asm with the notes that the listing comes from the cartridge and src/circus.notes, not hand edits
make verify reassembles with pasmo and compares that the listing IS the ROM, byte for byte
make sanity splits the 16,384 bytes into code and data that not one byte is left unassigned
make test 49 tests that the numbers on this site are the listing's
make imagenes draws everything in docs/imagenes/ from the ROM that the formats are read right
make coteja_montaje / make coteja_arranque / make coteja_pista compare against openMSX dumps zero bytes different

All three comparisons need the emulator dumps first: tools/omsx_montaje.tcl and tools/omsx_arranque.tcl (the ring one uses the same dumps as the start), each with its usage line in the header. See In the emulator.

The cartridge

16 KB in page 1 (0x4000-0x7FFF), an AB header with INIT at 0x407B and no BASIC. The screen is SCREEN 2.

The RAM

The game's whole RAM is 1 KB: 0xE000-0xE3FF, cleared by INIT with the ldir over itself. The stack sits at 0xE500.

area what is there
0xE000 the current scene
0xE003 the frame counter
0xE005 the interrupt re-entry lock
0xE052 the act type, 0 to 4
0xE0B0 the buffer for the 32 sprites, copied whole to 0x3B00 every frame
0xE130 the player: position, position and pose
0xE150 / 0xE170 / 0xE1B0 the moving objects, the pick-ups and the loose one
0xE280 the second decompressor's buffer

The BIOS

It uses seven routines: RDVDP, SETRD, SETWRT, WRTVDP, WRTPSG, RDPSG and SNSMAT. And it reads two bytes of its table, (0x0006) and (0x0007), which are the VDP ports.

The two menu screens

They are not the same one: the company screen (the KONAMI logo and "- VIDEO CARTRIDGE -") and the title screen. They share their scenery byte for byte; only the name table changes. Both are drawn from the ROM and checked down to zero bytes.

The company screen

The title screen

The code

The whole game lives inside the interrupt

INIT sets mode 1, hooks H.KEYI (0xFD9A) with a jp 0x402C, clears the RAM and then sits forever on the jr $ at 0x40A9. Everything else happens in the hook, once per frame: sound first, then the controls, then the scene. The lock at 0xE005 counts overlapping interrupts: if a frame runs long, the next one is served on the way out, without going back through the stack.

Tables sit right behind the call

despacha_por_tabla (0x404E) takes its own return address with pop hl, and that is where the table starts. That is how the scenes are dispatched, and the five set-ups (0x5FEF), the five starts (0x60B6) and the five frames (0x4C93).

Three data machines

Rewritten in Python in tools/:

And the ring, from the tables

tools/pista.py is the game frame routine by routine: it starts from the state left by 0x604C and each act's start-up (0x60B6), and every frame it moves and draws what the game moves and draws. Against 43 openMSX dumps: 0 bytes different (make coteja_pista). tools/corre_circus.py, which runs the cartridge on the Z80 in tools/z80run.py, stays as a second check (make coteja_arranque), not as the source of the pictures.

In the emulator

With openMSX and the Philips_VG_8020 machine:

openmsx -machine Philips_VG_8020 -cart circus.rom -script tools/omsx_montaje.tcl

There are three scripts:

The whole game happens in the hook at 0x402C: a breakpoint there stops once per frame.

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, 46 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 41 565 atiende_el_menu (0x477D)
Comic Bakery 27 392 atiende_el_menu (0x477D)
Cabbage Patch Kids 23 255 lee_el_teclado (0x4758) = LEE_EL_TECLADO
Hyper Sports 1 21 276 atiende_el_menu (0x477D) = MANEJADOR_DEMO
Konami’s Mahjong Dojo 19 183 limpia_la_pantalla (0x4558) = limpia_la_pantalla_entera
Super Cobra 18 242 mira_la_vida_extra (0x4416) = MIRA_VIDA_EXTRA
Athletic Land 10 87 copia_vram_a_vram (0x458F) = COPIA_VRAM_A_VRAM
Konami's Ping Pong 8 102 lee_el_teclado (0x4758) = lee_teclado_1
Yie Ar Kung-Fu 8 120 lee_el_teclado (0x4758)
Konami’s Billiards 7 67 pinta_rotulo (0x4066) = pinta_lista_formato_a

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.