How it works#
This page is for readers who want the internals: how the cartridge is built, where things are in the ROM and the save, and how the program runs a game. Everything here was read from the program and checked in emulators (the last section says how). Addresses are bank and offset: 0D:4000 is bank $0D at $4000, bank 0 being 00:0000–3FFF and every other bank appearing at $4000–$7FFF. The save's four banks are S0–S3, each at $A000–$BFFF; the banks of work RAM are W1–W7, at $D000. Where a point was read from the code but not seen running, it says so (read); where it is a reading not traced, inferred. Maps, blocks and records are counted from 0 here, as the program stores them (the editor's map 1 is map 0), but spells, items and monsters keep the editor's numbers, from 1. Each section ends with the project's notes and tools that hold the full detail; they are files in the project that made this guide, not pages of the site.
RPG Tsukuru GB is a new program. Its developer made Super Dante, RPG Tsukuru 2 and RPG Tsukuru 3, and their guides' pages on the internals (Super Dante, RT2) describe machines this one resembles in design. But a Game Boy can't run their code, and the program shares none of it but one routine, the random number generator. Compared with the titles before it sets them side by side.
The cartridge#
CGB-A2QJ, header title RPGTCOOLGB, game code A2QJ, maker code B1 (ASCII). Inside:
- 2 MB of ROM, 128 banks of 16 KB, on an MBC5 mapper (cartridge type
$1B: ROM, RAM and a battery). - 32 KB of battery RAM, four banks of 8 KB, one mapped at a time at
$A000–$BFFF. - The header marks it Game Boy Color only (
$C0), and both of its sums are right.
There is no development tag: Super Dante's and RT2's ROMs carry 「KUSOU KAGAKU DEVELOPMENT SYSTEM」 under their headers, and this ROM has no such text, nor any other ASCII but the header's RPGTCOOLGB and A2QJ: no build date, no names. The developer appears only in the staff roll's last line, 「©2000 アスキー 空想科学」 (Kuusou Kagaku). Every bank's tail past its data is $FF; bank 0 has 11 bytes free.
In a Game Boy that isn't a Color, the program reads the model byte the boot ROM leaves and, finding no Color, shows a screen of its own and halts (00:020D): 「このカートリッジは ゲームボーイカラー 専用です。」, "this cartridge is for the Game Boy Color only". It is drawn in picture tiles from bank $1E, and it holds the only kanji in the game: the text font has none.

Notes/RPG Tsukuru GB.md, Notes/Dumps.md.
The ROM map#
Code is in bank 0, banks $02–$19 and $1C–$1D (with $07, $10 and $11 mostly data); banks $01, $1A and $1B are empty; the rest, from $1E on, is data. Bank 0 is always mapped; any other is switched in at $4000. Nothing is compressed: every tile, tile map and palette is copied from the ROM as it stands, and the 1,054 rooms, each a whole screen, fill 48 banks.
| Bank | Holds |
|---|---|
$00 | The library: the start-up, the main loop, the interrupts, the bank switch, the task scheduler, the save's routines, printing, arithmetic, the random numbers |
$01, $1A, $1B | Unused: $FF throughout |
$02 | The scrollers (world map and rooms), the world map's loader, the cartridge's title screen |
$03 | The command window and its pages (Status, Magic, Use, Equip, Discard) |
$04 | The editor menu, Messages, Sample Load, Clear Data, the broken-data screen |
$05 | The kana keyboard; a message's name codes expanded |
$06 | Magic and Enemy Map; the song and sound lists |
$07 | The animation interpreter, mostly its data |
$08 | Title and Items; the number box; three-byte sums against the gold |
$09 | Monsters; the ASCII logo, the Game Over, the ending's staff roll |
$0A, $0B | Events: the floor, the page screen, the commands |
$0C | Maps |
$0D | The title menu and Settings; the error screen; a game's opening and its start; Test Play |
$0E, $0F, $16, $17 | The battle: the battle task and its menus; a round and every action; the library of numbered functions; the monsters' choice |
$10 | The program's tables: the tasks, the monster pictures' layout, the screen blocks, the room lists, the level table |
$11 | Random Message's lines, four for each character graphic |
$12 | Heroes and the start settings |
$13 | Code; what it serves is not set out in the study |
$14 | The event interpreter; the play save's writer |
$15 | The walkers: moving, vehicles and encounters on the world map, moving in a map |
$18 | Play: its set-up, the rooms and their events, the shop |
$19 | The link cable; Test Play's Select menu; each event's own task |
$1C | The Turbo File page and its driver |
$1D | The Enemy Map's troops and its battle test |
$1E, $1F | The title screen's pictures; the non-colour screen |
$20 | The 8 × 8 font, the world map's font, the text palettes |
$21–$24 | The 108 monster pictures, 27 to a bank |
$25, $26 | The 70 characters and vehicles, 42 to a bank, and their palettes |
$27 | The battle window; the blank project a format writes |
$28 | The four world maps as small pictures, for the editors |
$29–$2E | Screens and windows stored whole as tile maps; the tiles of the title menu, the editors and the world map |
$2F–$3A | The four world maps, three banks each |
$3B–$3F | The room tile sets, the block every room loads (stairs, doors, chests), the room palettes; some animation graphics in $3C, $3E and $3F |
$40–$6F | The 1,054 rooms, 743 bytes each |
$70 | The title backdrops |
$71 | The 16 × 16 title font; tile maps; the animations' palettes |
$72, $75, $76, $7B–$7D | Animation graphics |
$73 | The Enemy Map's small world |
$74 | Screen maps and tables of the Enemy Map and the event editor, and one spell animation's graphics |
$77–$7A | The sound driver, the same code in each, with each bank's songs and effects |
$7E, $7F | The sample game, as a whole 32 KB save image |
The sound driver is there four times. Banks $77–$7A begin with the same 2,175 bytes of driver code, each followed by its own tables and its share of the songs and effects. Only bank $78's table of banks is read, so each code's data can sit in any of the four. Bank $77's pointers for the codes kept in bank $78 are all $16 lower than $78's own, as if left from an older build; they are never read.
The map was made with a code/data log: Mesen marks each ROM byte as it runs or is read. Runs from 26 saved states (every editor page, play, battles), driven by scripts and random presses, logged 200,300 bytes of code in 2,034 runs, every one of which disassembles end to end. Bank $11, which looks like code, is data: Random Message's lines.
Notes/RPG Tsukuru GB/Program.md (§The data banks and their readers), Graphics.md; Tools/gb_dis.py (the disassembler), Tools/gb_cover.py.
The program#
The main loop and the modes#
The program is native SM83 code, with no script machine: where Super Dante and RT2 draw every window from bytecode, RPG Tsukuru GB's screens are routines, and its windows are tile maps stored whole in the data banks.
At power-on (00:0150) the program checks that it runs on a Color, sets up the video, the interrupts and a little routine in high RAM for the sprites' DMA, clears all work RAM (so the random numbers start from 0), clears the task slots, checks the save's signature, reads the settings and sets the mode to 7, the logo. If SELECT is held at that moment it turns the user-game mode off and writes the settings back.
The main loop (00:0EC8) resets the stack each pass, clears the frame's queues, and calls the current mode ($C413) and its step ($C414): the mode indexes a table at 00:0DE5 giving a bank and a table of steps, and the step indexes that. A step routine moves on by changing the step number, or the mode. Most modes have three steps: set up, run, leave. Then the idle wait (00:0F8F) steps the random numbers over and over until the frame's interrupt sets a flag (below).
| Mode | Bank | What |
|---|---|---|
| 0 | $0D | The title menu, with the Link and Settings pages inside it |
| 1 | $0D | The error screen |
| 2 | $18 | Play: the world map, maps, the command window, shops, battles, all as tasks |
| 3 | $0D | A game's opening: PRESENTS, its title screen, Continue and From the Start |
| 4 | $19 | Unused: nothing enters it. It sits just before the link code, perhaps the link's own mode before it became a page of the title (inferred) |
| 5 | $04 | The editor |
| 6 | $04 | The broken-data message, then the format |
| 7 | $09 | The ASCII logo after power-on |
| 8 | $09 | The Game Over |
| 9 | $09 | The ending: the staff roll |
$A | $1C | Turbo File |
Tasks#
Play is not one routine but a scheduler. Mode 2's run step calls 00:1499, which runs 32 task slots, each once a frame in turn when its run bit is set. A slot is a header at $C420 + 8n (the task's bank and the address of its table of steps), a flag byte at $C520 + n (bit 0 run, bit 1 alive), and 16 bytes of work at $C540 + 16n (byte 0 $FF for a free slot, byte 4 the step). 00:110A starts a task by its number, from an 8-byte descriptor in the table at 10:4000, in the first free slot.
On the world map four tasks run: the walker ($0E, which also holds the encounter check), the scroller ($0A), the water's shimmer ($0C, one of seven palettes every 12 frames) and the sprites ($47). In a map, the walker and scroller are others ($0D, $0B), with the event interpreter ($36) and one task for each event on screen ($35). A battle is a task too ($C3, sixteen steps from 0E:4006): it pauses the field's tasks, keeps them, and starts its own for the menu, the commands, each round, the round's end and the victory. The mode stays 2 throughout: a battle never changes it. The editor pages are tasks of mode 5 the same way, each started from the menu's table at 04:463F.
The bank switch and the library#
There is no far-call mechanism to speak of. Code that calls into another bank switches inline: ld bc,$00NN, call 00:07EB (switch to bank BC, keeping the one before), the call, then call 00:080E to switch back. Bank 0 has 75 such sites; one helper (00:3DF8) does the same for thirteen callers. A second switch (00:081A) is for code the timer interrupt must return to correctly. The save's banks are mapped by 00:083D, work RAM's by 00:084C.
Bank 0 is a library of about 200 routines, every one named in the project's notes. Landmarks:
| Address | What |
|---|---|
00:0150 | The entry: not a Game Boy Color → 00:020D, the non-colour screen, which halts |
00:02AB | Clears all work RAM at power-on, the random numbers' seed with it |
00:0EC8 | The main loop: the mode ($C413) and its step ($C414) through the table at 00:0DE5 |
00:0F8F | The idle wait: steps the random numbers until the frame's interrupt |
00:0ED4, 00:0FA0 | The soft reset: A + B + SELECT + START, then the reset itself |
00:1499 | The task scheduler: 32 slots, each run once a frame |
00:110A | Start a task by number, from its descriptor at 10:4000 |
00:07EB, 00:080E | Switch the ROM bank, and back to the one before |
00:083D, 00:084C | Map a bank of the save; a bank of work RAM |
00:0933, 00:091D | The random numbers: a step; a draw from 0 to b |
00:0893, 00:08BD, 00:08D9 | Multiply; divide (by zero: the error screen) |
00:35F2, 00:3481 | The signature check; the format |
00:3617, 00:3627 | Read a section with its sum (three tries); write one |
00:1DD8 | Read a section from the cartridge, or from the sample in the ROM |
00:33DD | Sample Load: the sample's image into the save |
00:2091, 00:2289 | Load a map's events; a block of messages |
00:2F4A | Print a run of characters into the window buffer |
00:3C3A, 00:1E6C | Load a monster picture; a character graphic |
00:1727, 00:178F | Passability in a room; on the world map (both let test play's START through) |
00:2AF6 | The battle's library: a function of bank $16 by number |
00:25E6 | Play a sound code: the program's one way into the driver |
00:0D15 | The timer interrupt: the sound driver's tick |
00:0DC0 | The serial interrupt (the link cable, the Turbo File) |
The soft reset. A + B + SELECT + START is tested in the main loop (00:0ED4) unless the Link page has set $C9FA. It sets the hardware up again, re-reads the settings and goes, by where it came from, to the editor (from test play), to the game's opening (a user's game in the user-game mode) or to the title.
The error screen#
Code that meets an internal error stores a code in $C9F3 and calls 00:0ABA, which keeps the mode, its step and the running task's slot in $C9F4–$C9F6 and enters mode 1. It draws four lines in sprites over whatever was on screen, in hex: ERROR the code, TASKNO the mode, JOBNO its step, PROCNO the task slot. It is a dead end: no button, not even the soft reset, leaves it.

| Code | Raised by |
|---|---|
| 0 | A mode's set of tasks started with a count of 0 or of 32 or more (00:10D4); also a check at 0D:4642 that was not traced |
| 1 | All 32 task slots taken when a task is started (00:11C6) |
| 2 | Ending a task that doesn't exist (00:1263, 00:127B) |
| 4 | A division by zero (00:08BD, 00:08D9) |
Nothing in normal play reaches it; it was seen only by setting its bytes by hand.
Notes/RPG Tsukuru GB/Program.md, Hidden Content.md, Play.md; Tools/gb_dis.py, Tools/gb_mesen.py.
The save#
The 32 KB are four banks of fixed regions: the database and the play saves in bank 0, the monsters, spells and the start of the messages in bank 1, more messages in bank 2, the events in bank 3. The program reads and writes the database parts by section number through 00:363D, which gives each section's bank, address and length; the messages and events it reads raw.
| Section | Where | Bytes | What |
|---|---|---|---|
| 0 | S0:A008 | 35 | The title page: the title (16), the backdrop, the author (16), the title song |
| 1 | S0:A02B | 436 | The heroes, 8 × 51; the start settings, 27 |
| 2 | S0:A1DF | 712 | The world map's number; the 25 map records |
| 11 | S0:A4A7 | 3,521 | The room plans |
| 7 | S0:B268 | 1,266 | The items, 115 × 11 |
| 9 | S0:B75A | 969 | The Enemy Map |
| 15 | S0:BB23 | 17 | The settings: the user-game mode, the last slot saved by each kind of game |
| 12, 13, 14 | S0:BB34, BCC5, BE56 | 401 each | The three play saves |
| — | S0:BFE7 | 6 | The signature, A6 95 99 94 C0 C2 |
| 8 | S1:A000 | 2,449 | The monsters, 72 × 34 |
| 6 | S1:A991 | 441 | The spells, 40 × 11 |
| 3 | S1:AB4A | 108 | The message index: 27 × (offset, length); no sum |
| — | S1:ABB6 | 929 | The messages' order; no sum |
| — | S1:AF57–S2:BFFF | 12,457 | The message heap; no sum |
| — | S3:A000–BFFF | 8,192 | The events: index, floors, places, chests, floor starts, heap; no sum |
A section of length L is L − 1 data bytes and an 8-bit sum of them in the byte after. 00:3617 reads one: it copies and sums it, compares, tries three times, and on a failure sets mode 6, the broken-data message. 00:3627 writes one with a fresh sum. Section numbers 4, 5 and 10 don't exist. Section 3, the message index, fills its 108 bytes with 27 entries and has no room for a sum: the program reads it raw, and the byte the table would take for its sum is the last entry's length.
The power-on check#
At power-on, 00:35F2 compares the six bytes at S0:BFE7 with the ROM's copy at 00:33D7, A6 95 99 94 C0 C2. That is all it checks. On a mismatch, 00:3481 formats the cartridge at once, with no message. Then it reads section 15, the settings, with the checked read; a bad sum there sets mode 6, but the start-up sets mode 7 straight after, so the title comes up as usual. Every other section is checked only when it is read: the first time a game or an editor needs it.
The format zeroes all four banks, then copies nine pieces of the blank project from bank $27 (the title page, the heroes, the maps and plans, the message index with its order table and empty messages, the event bank's head, the spells, items, monsters and Enemy Map), then writes the signature. What it writes is byte for byte what the project's tool builds from the ROM. The table of pieces (00:34D9) has twelve entries; the last three zero the three play saves, and Clear Data uses the same table piece by piece.
Sample Load (00:33DD) copies the sample's image from banks $7E–$7F into the save, all but the play saves and the settings: its 32 KB are laid out exactly as the save is (7E:4000 is S0:A000, 7E:6000 S1, 7F:4000 S2, 7F:6000 S3). Playing Sample reads the same image straight from the ROM: $CD92 holds the game's source (1 the cartridge, 2 the sample, 3 test play), and the section reader 00:1DD8, the event loader and the message loader each take the sample's copy when it is 2.
The play saves#
Sections 12–14 are the three play saves, 400 bytes and the sum. 14:7561 assembles one in W3:D9CE from the play state and writes it; numbers are big-endian:
| Offset | Bytes | What |
|---|---|---|
| +000 | 1 | The source: 1 your game, 2 the sample, 3 test play |
| +001 | 5 | The leader's name, for the slot list |
| +006 | 1 | The leader's level, for the slot list |
| +007 | 8 × 17 | Every hero's record, by hero number: level; the four stats (words); experience (3); maximum HP and MP (words); one byte not settled |
| +08F | 3 × 9 | Each party place: HP, MP (words), the four pieces of equipment, the condition |
| +0AA | 48 | The switches, 384 bits: 1–100 the maker's, 101–128 unused, 129–384 the chests' opened marks (chest c is switch 129 + c) |
| +0DA | 4 | A bit for each of the 25 places on the world map: the places visited (inferred) |
| +0DE | 1 | Not settled |
| +0DF | 1 | Battles on (0: none, test play's setting) |
| +0E0 | 3 | Gold |
| +0E3 | 3 | The party: hero numbers, $FF an empty place |
| +0E6 | 3 | The map ($19 the world map), the room, the floor |
| +0E9 | 2 | The leader's x, y |
| +0EB | 4 | The airship's x, y, then the ship's |
| +0EF | 1 | The song playing |
| +0F0 | 115 | The items: a count for each |
| +163 | 8 × 5 | Every hero's name, by number |
| +18B | 1 | The screen's tint |
| +18C | 4 | Never written |
| +190 | 1 | The sum |
The records go by hero, the places by party: a hero who leaves keeps their level and stats. A save written by the project's tool (a leader renamed ツクール, level 42, 12,345 gold, seven of an item) loads in the game with exactly those changes, and the game's own save of it into another slot is the same in all 400 bytes. The settings (section 15) keep the user-game mode and, for each kind of game, the slot it last saved to.
Notes/RPG Tsukuru GB/Save.md; Tools/gb_save.py (check, layout, play, edit, fix, rebuild, factory).
Text#
One byte a character, and the byte is the font's tile number. The 8 × 8 font is loaded to the second bank of video RAM at $8800, and the text layer uses the signed tile numbering, so codes $80–$FF are the font's first 128 tiles and $00–$7F the next 128. That is why the katakana run from ア at $E0 past $FF round to ポ at $2F: in the font they are one run. There is no second page and no kanji: kana, capitals, digits and a few marks.
| _0 | _1 | _2 | _3 | _4 | _5 | _6 | _7 | _8 | _9 | _A | _B | _C | _D | _E | _F | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0_ | ム | メ | モ | ヤ | ユ | ヨ | ラ | リ | ル | レ | ロ | ワ | ヲ | ン | ァ | ィ |
| 1_ | ゥ | ェ | ォ | ッ | ャ | ュ | ョ | ガ | ギ | グ | ゲ | ゴ | ザ | ジ | ズ | ゼ |
| 2_ | ゾ | ダ | ヂ | ヅ | デ | ド | バ | ビ | ブ | ベ | ボ | パ | ピ | プ | ペ | ポ |
| 3_ | あ | い | う | え | お | か | き | く | け | こ | さ | し | す | せ | そ | た |
| 4_ | ち | つ | て | と | な | に | ぬ | ね | の | は | ひ | ふ | へ | ほ | ま | み |
| 5_ | む | め | も | や | ゆ | よ | ら | り | る | れ | ろ | わ | を | ん | ぁ | ぃ |
| 6_ | ぅ | ぇ | ぉ | っ | ゃ | ゅ | ょ | が | ぎ | ぐ | げ | ご | ざ | じ | ず | ぜ |
| 7_ | ぞ | だ | ぢ | づ | で | ど | ば | び | ぶ | べ | ぼ | ぱ | ぴ | ぷ | ぺ | ぽ |
| 8_ | (space) | → | ← | ↑ | ↓ | ☞ | ☛ | · | ▼ | · | · | · | · | · | · | · |
| 9_ | · | · | · | A | B | C | D | E | F | G | H | I | J | K | L | M |
| A_ | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | · | · | (skull) |
| B_ | / | ○ | · | ♥ | ♪ | ♫ | (drop) | % | 「 | 」 | ! | ? | ◆ | · | · | · |
| C_ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Ⅰ | Ⅱ | Ⅲ | Ⅳ | Ⅴ | · |
| D_ | ヴ | 、 | 。 | . | , | ・ | … | : | ー | 〜 | ゔ | + | − | · | · | · |
| E_ | ア | イ | ウ | エ | オ | カ | キ | ク | ケ | コ | サ | シ | ス | セ | ソ | タ |
| F_ | チ | ツ | テ | ト | ナ | ニ | ヌ | ネ | ノ | ハ | ヒ | フ | ヘ | ホ | マ | ミ |
The · cells are the window's frame pieces and marks: the two pointing hands ($85, $86) are the cursor, $89–$92 the window's edges and corners. The order is the kana table's (the gojūon), plain kana before the voiced and the small ones, hiragana in one block and katakana in another. No character has the code it has in RT2: hiragana start at $30 where RT2's start at $5F, digits at $C0 against $30.
Messages are kept apart from the events and shown by number. Section 3 is the index: 27 entries of a big-endian offset and length into the message heap, the world map's block first, then maps 0–24, then the common messages. A block is its messages one after another, each ended by $AF: 60 messages for the world map and maps 0–14, 30 for the dungeons and the common block. The number an event uses is not the message's place in the block: a table of the messages' order (S1:ABB6, 6- or 5-bit numbers) maps each stored message to its number, so the editor's tidying can move messages without touching the events.
| Bytes | In a message |
|---|---|
BF | A new line |
AF | The message's end (the font's tile there is a skull) |
86 nn | Hero nn's name, as the player has it |
85 nn | A name from the database, by the range nn falls in: 00–27 spells 1–40, 28–9A items 1–115, 9B–B3 maps 0–24, B4–FB monsters 1–72 (in the editor's numbering) |
80 | The space; it also fills the unused places of every name |
Two fonts. The 8 × 8 font (20:4002, 256 tiles) does everything: menus, editors, messages, battle. The 16 × 16 title font in bank $71, four tiles a glyph with a drop shadow, draws only the game's title on its title screen, in an order of its own. The program's own text is mostly whole screens: tile maps of a width, a height, the tiles and their attributes, in banks $29–$2E, drawn by number through a table at 10:49E8. Strings printed one by one are few.
Notes/RPG Tsukuru GB/Text.md; Tools/gb_text.py (table, font, decode, names, messages, strings).
The database#
Fixed records, with as little as possible stored. A spell's effect is fixed by its slot and an item's kind by its number, so neither is stored; a hero has no base stats, only a gain a level; a monster's spells, abilities and type share one 56-bit number.
| Record | Bytes | Fields, in order |
|---|---|---|
| The title page | 35 | the title (2 × 8), the backdrop, the author (16), the title song as a sound code; the sum |
| A hero | 51 | the name (5), the graphic (character g − 1, 0 none), the start level, the four gains, then the level each of the 40 spells is learnt at (0 never) |
| The start settings | 27 | the party (three heroes as nibbles, hero + 1), gold (3), map, floor, room, y, x, the ship's and airship's graphics (a nibble each), the airship's y, x, the ship's y, x, the eight songs (battle, world map, ship, airship, castle, town, village, dungeon) as sound codes, four bytes the editor keeps for itself |
| A spell | 11 | the name (6), MP, power (words), the animation |
| An item | 11 | the name (6), the price, the value (words), who can equip it (bit 7 hero 1 … bit 0 hero 8; $FF for anything not worn) |
| A monster | 34 | the name (6), the graphic (picture g − 1), HP, MP, attack, defence, speed, EXP, gold (words); the options as one 56-bit number (bits 0–39 the spells it casts, bit k spell k + 1; 40–49 the ten abilities, 52–55 its type); the spells that work on it (32 bits, bit k for spell 16 + k); the treasure (the item's number, 0 none); its odds (0–3) |
| A map | 26, 14, 44 | the name (6); the top floor's number (a dungeon's look in the high nibble); how many floors below it; 6 bytes of stairs for each pair of neighbouring floors (three x, y pairs) |
| A floor's room plan | 25 or 36 | room types row by row, 0 for no room |
| The Enemy Map | 969 | a byte; the world map's 40 areas, six monster numbers each ($FF none); then every map, two bytes and six numbers a floor; 17 bytes more |
Songs are stored as sound codes, not as the editor's numbers: a table at 06:52DF turns song 0–25 into its code (song 0 is $83, a silent song). A hero's type in the editor (hero, warrior, mage …) is not stored: the S button's classes only fill in the four gains. The S presets copy the sample's record of the same number from its image in the ROM (7E:6991 + 11n a spell, 7E:5268 + 11n an item, 7E:6000 + 34n a monster, n counting from 0: spell 1 is n = 0).
A number box (task $B1, 08:4010) takes its digits, the value and a minimum and maximum from its caller, and clamps on A. So the editors' limits (Limits) are each caller's constants, not the boxes' widths.
Notes/RPG Tsukuru GB/Database.md, Limits.md; Tools/gb_db.py (show, check, dump).
Maps and rooms#
Nothing in a map is drawn tile by tile. A map is a building of floors, a floor a 5 × 5 or 6 × 6 grid of room types ($00 no room), and a room type is looked up in one of twelve room lists (10:4EB0: by the map's kind, castle, town, village or dungeon, and by whether the floor is above 1F, 1F or below). Each entry names a bank and an index: the room is the 743-byte record at that bank's $4000 + 743 × the index, 22 to a bank in banks $40–$6F, 1,054 in all.
| Bytes | What |
|---|---|
| 0–359 | The screen's 20 × 18 tile numbers |
| 360–719 | Their colour attributes: palette, VRAM bank, flips, priority |
| 720–742 | Passability: 10 × 9 squares of 16 × 16 pixels, 2 bits each, 0 open, 2 a counter, table or bed (talk across it), 1 and 3 closed |
The loader copies the tiles and attributes into the window buffer, and the screen shows the room through a scrolled window of the background. The room's tiles come from its kind's tile set (18:4589; a dungeon's from its look, one of four, 18:45D1): 4 KB into each bank of video RAM, the font over part of the second, and the block every room loads (3D:7400: stairs, doors, chests) over part of the first. Stairs are not in the rooms: each map record lists, for each pair of neighbouring floors, up to three positions across the whole floor, and the game draws the stairs' tiles over the room there, up or down.
The world maps are four, fixed (00:1ABE: nine bytes each, the banks and addresses of the tiles, the attributes and the passability). Each is 160 × 144 tiles, eight screens by eight, three banks a world ($2F–$3A), its tiles running over a bank boundary partway down. Passability is 80 × 72 squares of 2 bits: 0 open, 2 water (the ship's), 1 and 3 closed; the airship ignores it. The world wraps both ways. The 25 places on it are records of 13 bytes in the event bank: a position, an icon, three more positions beside it (where the party and the vehicles are put on coming out, inferred), and the entrance in the move command's own form.
Drawn by the project's model of the Game Boy Color's video chip from the ROM and the save, a village house, a castle's floors with their stairs, a dungeon and a screen of the world map each match the emulator's frame with no pixel different.
Notes/RPG Tsukuru GB/Maps.md; Tools/gb_maps.py (plans, room, floor, check, fieldcheck), Tools/gb_ppu.py.
Graphics#
All fixed, all uncompressed, 2 bits a pixel with the Color's palettes. The editors choose pictures by number; nothing is drawn by the user.
- Monster pictures (
$21–$24): 108 of 6 × 6 tiles (48 × 48 pixels), 27 to a bank, each with a layout byte a row choosing one of two palettes per tile. A monster's graphic g is picture g − 1; 103 can be chosen. In battle, three monsters stand in slots 0, 2 and 4 of five across the screen, two in 1 and 3, each pair of slots sharing a block of video RAM and two palettes. - Characters and vehicles (
$25–$26): 70 of 24 tiles, six 16 × 16 frames (facing right is facing left mirrored), 42 to a bank, eight shared palettes. A hero's graphic g is character g − 1; the ship is character$3E+ its graphic − 1, the airship$42+ its graphic − 1. The world map streams one pair of frames at a time. - Animations (35, the spells' and the battle's effects): their graphics in banks
$72,$75,$76,$7B–$7D,$3C,$3Eand$3F, run by bank$07's interpreter; the Magic editor plays them as a preview.
Notes/RPG Tsukuru GB/Graphics.md; Tools/gb_gfx.py (monsters, chars, tilesets, check).
Events#
All events live in save bank 3, which has no sum: a head of 156 bytes indexing 26 blocks (the world map first, then maps 0–24), each block's floors, the world map's 25 places, a bitmap of the chest numbers in use with the count left (250 less those used), and where each floor starts in its block; then the heap, 7,404 bytes, the blocks one after another.
A block is its directory, then the event bodies. The directory runs a floor at a time, five bytes an event; on entering a room, the program takes the entries of the current floor whose room is this one.
The type byte: the low nibble is the trigger (0 on touch, 1 the A button, 2 automatic; the game itself uses 3 for a place on the world map and 4 for a chest), the high nibble the movement (0 still, 1 up and down, 2 side to side, 3 random, 4 approaches, 5 flees). The graphic: 0 none, $01–$46 character g − 1, from $47 an object drawn with background tiles ($57 a closed chest, $58 an open one, $5E–$74 the places' icons).
Choosing a page (18:4B12): page 4 is tested first, then 3, then 2, and the first whose conditions all hold runs, else page 1. A switch n is bit 7 − (n − 1) mod 8 of byte (n − 1) ÷ 8 of the switches; an item is held when its count is not 0; the party mask needs every hero marked to be in; gold must be at least the amount. A page with no condition set never runs.
The commands#
A command is an opcode and a fixed number of operand bytes, and FF ends a list. Each direction and each tint is an opcode of its own, as on the SFC, rather than an operand. The names are those of Events, which gives each one's Japanese and what it does.
| Opcodes | Commands | Bytes | Operands |
|---|---|---|---|
00 | Message | 2 | its ID |
01 | Random message | 1 | |
02, 03 | Yes; No (the end of the yes branch) | 1 | |
04 | Warp | 5 | floor and map, room, x, y |
05, 06 | Switch on, Switch off | 2 | the switch |
07 | Wait | 2 | tenths of a second |
08, 09 | BGM; Sound | 2 | a sound code |
0A | Battle | 5 | three monsters (FF none), the battle's song |
0B | Enter name | 2 | the hero |
0C | Vanish | 1 | |
0D, 0E | Hero joins, Hero leaves | 2 | the hero |
0F, 10 | Item +, Item − | 2 | the item |
11, 12 | Gold +, Gold − | 4 | 24 bits |
13 | Experience + | 4 | 24 bits |
14–17 | Party HP +, HP −, MP +, MP − | 3 | 16 bits |
18–1A | Poison; Cure; Full recovery | 1 | |
1B–1E | Party faces up, down, right, left | 1 | |
1F–22 | Party steps up, down, right, left | 1 | |
23, 24 | Party spins, Party blinks | 2 | times |
25–28, 29–2C | Event faces, Event steps (up, down, right, left) | 1 | |
2D, 2E | Event spins, Event blinks | 2 | times |
2F | Inn | 3 | the price, 16 bits |
30 | Shop | 5 | four items (FF none) |
31–38 | Brighter, Darker, Red, Blue, Monochrome, Normal, Flash, Shake | 1 | |
39 | End of event | 1 | |
3A | Save point | 1 | |
3B | Game Over | 1 | |
3C | Ending | 1 | |
3D–3F | A chest's own script, never offered | — |
The interpreter (14:401E) reads the opcode through a three-byte pointer (a work RAM bank and an address, $CD53–$CD55) and jumps through the table at 14:72CF; each routine is a small state machine (start, wait, done) and advances the pointer by its length (14:734F). The question: 02 asks yes or no; yes runs on to the matching 03, which ends the event; no skips past the matching 03, counting nested 02s, and runs to the FF. The directions' routines lie in RT2's order (up, right, down, left) though the opcodes are numbered up, down, right, left: only the numbers were changed.
A message ID below $3D is one of the map's own messages; from $3D it is a common one, numbered ID − $3C. Random message (01) picks one of four built-in lines for the speaker's graphic (bank $11, eight bytes a graphic, four pointers). Warp (04) packs the map into the first byte's low 5 bits (25 the world map), the floor into its top 3 bits and the second byte's bit 7, the room into the second byte's low 6 bits, then x and y.
A chest is opened by a script of its own. Opening one writes 3D 3E item gold FF into a buffer and runs it as an event: 3D lifts the lid with sound $F1, 3E gives what was found. An empty chest gets 3F FF, 「なにもはいっていない。」 ("there's nothing inside"). The editor never offers these three, and the length table has no entry for them. A chest's opened mark is switch 129 + its number in the play save.
Loading (00:2091): a map's directory goes to W5:D97A, its bodies to one bank of work RAM, its places to W5:D804, the chests' bitmap to $D949. The bodies must fit the 4 KB bank, so the event editor keeps a map's directory and bodies to 4,000 bytes; play has no check of its own.
Notes/RPG Tsukuru GB/Events.md, Limits.md; Tools/gb_events.py (list, places, check, stats, add, commands).
The battle, in short#
The battle is task $C3 in bank $0E with its menus, set-up, escape and victory; bank $0F runs a round and every action; bank $16 is a library of 35 numbered functions, called through 00:2AF6 with the number in $CF50, and runs the round's end; bank $17 chooses each monster's action (and each hero's under Auto) by the monster's type. The battle's state is in work RAM bank 3, the party's in bank 2. Every formula and draw, and the bugs, are on How battles work; the model that replays battles draw by draw is Tools/gb_battle.py.
Encounters are the world map walker's code (15:6796): no battle in the airship or where the area has no monsters; otherwise a battle when the step counter ($CDBB) reaches 15, or when a raw random byte is below $11, 17 in 256.
Notes/RPG Tsukuru GB/Battle.md; Tools/gb_battle.py (save, record, show, check), Tools/gb_battle_ai.py.
The random numbers#
00:0933: s = s × 5 + $3711, 16 bits, the high byte in $C862, computed as s × 4 (two shifts), + s, + $3711. 00:091D returns the high byte mod (b + 1), the bounded draw every battle roll uses; 00:092A returns the raw high byte, for the field's encounter code only (the check and the troop). It is the same generator, constant for constant and step for step, as Super Dante's and RT2's (RT2's $80:8A8A), carried across a change of processor: the one routine RPG Tsukuru GB takes over exactly from the older programs.
The generator steps outside the game's own calls. The main loop's idle wait calls it over and over until the next frame, as many times as the frame leaves time for, and the animation interpreter draws pairs of rand(28) as a monster dies or a hero swings. So the numbers a battle meets depend on timing to the cycle as well as on the player's presses. The seed is 0 at every power-on, because the start-up clears all work RAM (RT2's seed is whatever the RAM held).
This is why the battle check needed care. Two emulators part by about one idle step a frame: from the same power-on, the generator stood at step 38,128 of its 65,536 in Mesen and 37,614 in SameBoy by frame 300, and they fight different battles from the first draw. With the three bytes of the idle wait's call blanked in a copy of the ROM, the generator steps only when the game asks, and nine battles came out the same in both, value for value. On a console, too, the numbers vary only with timing and input.
Notes/RPG Tsukuru GB/Battle.md (§The RNG), Second Emulator.md.
The sound driver#
One driver, the program's own, in each of banks $77–$7A ($4000–$487E, identical in the four), with three entries: initialise, tick, and queue a code. The program's one way in is 00:25E6, which keeps the current song and a jingle's timer, and puts the code in a ring of eight that the driver takes one a tick from.
It ticks once a frame. The timer is set for 64 times a second, but its handler restarts the count and waits behind the frame's own interrupt, so in the game it ticks at the frame rate, 59.73 Hz (checked: 6,026 ticks in 6,000 frames). Lengths are therefore in frames, and there is no tempo byte.
- Songs (
$81–$9Fbut$8Cand$8D, 29 with the logo's fanfare and the title's song) have four tracks, one a channel; the wave channel's is transposed up an octave in every song. Jingles ($A0–$AD, 14) are short songs: they replace the song, and when a jingle's time (a table at00:2630) is up, the song starts again from its beginning. Effects ($AE–$FE, 81) have one track each, on the second square channel or the noise. - An effect over music: the music's track goes on reading, keeping its time, but writes nothing to the channel. When the effect ends the driver gives the channel back and then silences it again at once, so the music's channel is quiet until its next note.
- Notes: a frequency table of 74 entries (a rest, then C2 to C8, equal-tempered within 5 cents up to C6); 10 wave shapes for the wave channel, of which the songs use two; 40 pitch envelopes, most a delayed vibrato.
- The editor's numbers are tables: songs 0–25 through
06:52DF, and the sound list through06:551E, every code$A0–$FEbut$E6, in an order of its own (Music and sound).
| Byte | Operands | What |
|---|---|---|
E3 | — | The track's end |
E4 | v | Volume and envelope (NRx2), kept for each note after |
E5 | address | Jump |
E6 | d | Transpose by d semitones more |
E7 | i, n, address | A counted loop: the section plays n times |
E8 | v | The first channel's sweep |
E9 | v | Pan: which sides the channel plays on |
EC, ED | address; — | Call, return |
EE | v | The duty (the square wave's shape) |
EF, F0 | — | Tie on, off: notes change pitch without striking again |
F1, F2 | e; — | A pitch envelope (vibrato, a fall, a trill) on, off |
F3 | w | Load wave w into the wave channel |
F4, F6 | — | The end of an effect on the second channel, on the noise |
F5 | v | The wave channel's note length |
FA | n | Wait n frames, the note held |
The rip is a GBS file: the four banks as they stand behind a small player, with one table renumbered and play called at the frame rate. All 124 codes played by the game and by the rip in Mesen make the same register writes tick for tick; a Python model of the driver makes the same writes again; and a synthesiser driven by the model agrees with SameBoy's audio, channel by channel, for every code.
Notes/RPG Tsukuru GB/Sound.md; Tools/gb_sound.py (show, gbs, rom, check, model, mix, audio, renders).
The link cable#
The Link page's code is all in bank $19. The giver is the master: it clocks every byte at the Color's fast serial clock (SC = $83, 262,144 Hz). The receiver is the slave (SC = $82), armed with its answer before the giver's byte arrives, so it must be waiting first: it waits without limit, while the giver gives up after eight tries. For the last byte the roles swap.
| Byte | From | Meaning |
|---|---|---|
D0 | giver | Hello, sent twice |
D4 | receiver | The answer to the first hello |
80 + k | receiver | The request, kind k (0–9): the answer to the second hello |
1x, 2x | giver | A byte's high nibble, then its low |
D2 | receiver | "Go on": the answer to each nibble and to the first 40 |
40 | giver | The end of a block, sent until answered D3 |
D3 | receiver | The end seen |
D0, D1 | receiver, now clocking | The verdict: accepted, rejected |
Every data byte goes as two, $10 | its high nibble then $20 | its low, so data never looks like a control byte. The giver sends 48 line transfers a frame, 24 bytes, so the title page's 128 bytes take about six frames and the messages' 13,568 about nine and a half seconds (inferred from the loop; the run's transfer count fits). A reply of $FF or $00 means "no one there", and the giver resends the byte, up to 255 times in a row in the data. There is no per-byte check and no resend of a block: a nibble stored twice would make the count or the sum fail.
The receiver checks only the sum and the byte count, against the size it expects for the kind it asked for (19:711D); nothing in the data is looked at. It writes only after its verdict has gone and A or B is pressed, through the section writer, which makes a fresh sum. The sizes on the wire are rounded up from the regions (Title $80, Heroes and Magic $200 each, Maps $1300, Messages $3500, Events $2080, Items $500, Monsters $A00, Enemy Map $400, Save Data $500); the padding is whatever the giver's work RAM held, summed and thrown away.
The sample's quirk: the giver reads its sections through 00:1DD8, which takes the sample's copy while $CD92 is 2, and neither the title nor the soft reset sets it back. So after playing Sample, Give Data sends the sample's title page, heroes, maps, magic, items, monsters and Enemy Map (Saving and sharing).
All ten kinds were run between two Mesens joined through files, the receiver ending with the giver's bytes in exactly the kind's regions and its own everywhere else. What a real slave answers when not yet armed, and the timing races that leaves, were not tried.
Notes/RPG Tsukuru GB/Storage.md; Tools/gb_link.py (kinds, run, check), Tools/gb_mesen.py --link.
The Turbo File GB#
The driver is bank $1C's (1C:4799–4D00). The device drives the clock: the Game Boy only arms each transfer on the external clock and waits.
A command starts by waking the device ($6C until it answers $C6), then sends a packet: $5A, the command, its parameters and a checksum that makes the packet sum to 0. The reply is fetched byte by byte: $F1 until $E7, $7E until $A5, then $F2 for each byte of the command echoed, an error byte (0 for none; else the game shows message byte + 5), the status, any data, and a checksum. A status poll goes before every command.
| Command | Parameters | Reply data | What | Used |
|---|---|---|---|---|
10 | — | the card byte, the bank (2), 0, 0 | Status | before every command |
20 | 01 | — | Begin a session | once, first |
22 | card bit, bank | — | Select the bank to write | yes |
23 | card bit, bank | — | Select the bank to read | yes |
24 | — | — | End the session | once, last |
30 | offset (2), 64 bytes | — | Write 64 bytes | yes |
40 | offset (2) | 64 bytes | Read 64 bytes | yes |
34 | offset (2), a byte | — | Fill 64 bytes | only from a format routine nothing calls |
21, 28, 50, 60 | Two unknown, a 16-byte write and read | no caller |
The storage is 256 banks of 8 KB: $00–$7F the device, $80–$FF the memory card. Each side's last bank holds 120 headers of 64 bytes, header n describing bank n: so a side has 120 blocks, and the game shows 119 free on an empty one (an off-by-one the device's public description also notes). RPG Tsukuru GB's file is the whole save in four blocks, banks 0–3 in order, in the first four free banks, named RPG TCOOL nn with the lowest nn not in use. A save is a session ($20), the headers read, then for each block a bank selected, 128 writes of 64 bytes and its header written; about 1,600 packets. A delete writes $FF over the file's four headers, last first, and leaves the data.
A copy, cut. Bank $1C keeps the strings for copying a file (「コピー しますか?」, 「コピーする ファイル」, 「コピーさき」, 「コピーごの ファイルめい」), but no code reaches three of them and the menu has only Save, Load and Delete, with a card in too. A copy between the device and the card was planned and dropped (inferred).
Every step (save, a second save, load, delete, save again, a memory card, the protect switch) was run against a model of the device behind Mesen's link port, and every image the game wrote equals what the project's tool writes for the same operation. The device's own timing, its errors and the commands the game never sends were not modelled.
Notes/RPG Tsukuru GB/Storage.md (with the public description of the device it was checked against); Tools/gb_turbo.py (blank, list, extract, insert, delete, check), Tools/gb_mesen.py --turbo.
How this was checked#
Every format on this page was written back as well as read, or drawn and compared with the emulator's own screen, so that a reading that was nearly right would show:
| What | How it was checked |
|---|---|
| The save | Every save the runs left, and the sample's image, taken apart into their regions and rebuilt byte for byte, every sum recomputed. A play save written by the project's tool, loaded and saved again by the game: the game's slot equals the tool's in all 400 bytes |
| The blank format | Built from the ROM by the tool, and byte for byte what the game writes after a power-on and after the broken-data message |
| Text | The kana keyboard's own tile map, the heroes' names in the save, and the screens |
| The database | Each editor page against the bytes behind it; saves edited by the tool, opened in the editor |
| Maps and graphics | Rooms, the world map and battle screens drawn from the ROM and the save by a model of the Game Boy Color's video chip, and compared with the emulator's own frame: no pixel differs |
| Events | The sample's events and those of every run rebuilt byte for byte; an event written by the tool run in the game, doing exactly what was predicted |
| The battle | 21 recordings, 39 battles, 743 turns and 11,238 random draws replayed through a model of the rules, every draw at its own call site with its own bound |
| Sound | All 124 codes: the rip against the game and the model against the driver, every register write the same; the synthesiser against a second emulator's audio, channel by channel |
| The link cable | All ten kinds between two emulators joined through files: the receiver holds the giver's bytes in exactly the kind's places |
| The Turbo File GB | Seven runs against a model of the device: save, a second save, load, delete, save again, a memory card, the protect switch; every image equal to what the tool writes |
| A second emulator | The save, the event and nine battles again in SameBoy beside Mesen: the same save, the same screens pixel for pixel, every battle value in the same order |
- The emulators. Mesen 2.1.1's Game Boy core, run headless by a script (savestates, scripted presses, watches, traces by bank and address, write logs, memory dumps, screenshots from the frame buffer, two runs linked through files, a modelled Turbo File GB); and SameBoy 1.0.5 through its libretro core, run from Python.
- Why replay. A battle is recorded with every random draw at its call site and every change to the combatants, then replayed through a model of the rules, which must make the same draws in the same order with the same bounds and reach the same state every turn. A model that is nearly right fails at its first slip; several of the bugs on Limits were found that way.
- The second emulator. SameBoy runs its own boot ROM, 175 frames longer than Mesen's start, and its idle steps differ (above); with those two allowed for, the save, an event and nine battles agree with Mesen, and every screenshot is the same pixel for pixel.
- Not checked: timing to the cycle (the idle wait makes every random number depend on it), a real Turbo File GB, a real link cable, and the battle's rarer paths that no recording met (a surprise round, confusion, instant death, self-destruct, flight, items, a curse's death).
Notes/RPG Tsukuru GB/Analysis Plan.md, Second Emulator.md; Tools/gb_mesen.py, Tools/gb_lr.py.
Fan-made reference material, one of the Eschaton Games Tsukuru guides. Not affiliated with the publishers of the titles it covers. Corrections and questions: contact@eschaton.games.