Eschaton GamesRPG Tsukuru GB an English guide

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:

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.

The screen a non-colour Game Boy shows, drawn from the ROM.
The screen a non-colour Game Boy shows, drawn from the ROM.

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.

$00core$01$02scroll$03menu$04editor$05keys$06editor$07anim$08editor$09editor$0Aevents$0Bevents$0Cmaps$0Dfront$0Ebattle$0Fround$10tables$11lines$12heroes$13code$14events$15walker$16battle$17choice$18play$19link$1A$1B$1CTurbo$1Denemy$1E–$1Ftitle$20fonts$21–$24monster pictures$25–$26characters$27blank$28minis$29–$2Escreens and editor tiles$2Fmaps$30–$3Athe four world maps$3B–$3Froom tile sets$40$6Fthe 1,054 room records: whole screens with their passability, 22 to a bank$70title$71font$72anim$73mini$74editor$75–$76animations$77–$7Asound driver, music$7B–$7Danimations$7E–$7Fthe samplecodethe program's tablesgraphics and fontsmaps and roomssoundsave images: the blank project, the sampleunused ($FF)
The 2 MB ROM, bank by bank: code, data and the empty banks.
BankHolds
$00The 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, $1BUnused: $FF throughout
$02The scrollers (world map and rooms), the world map's loader, the cartridge's title screen
$03The command window and its pages (Status, Magic, Use, Equip, Discard)
$04The editor menu, Messages, Sample Load, Clear Data, the broken-data screen
$05The kana keyboard; a message's name codes expanded
$06Magic and Enemy Map; the song and sound lists
$07The animation interpreter, mostly its data
$08Title and Items; the number box; three-byte sums against the gold
$09Monsters; the ASCII logo, the Game Over, the ending's staff roll
$0A, $0BEvents: the floor, the page screen, the commands
$0CMaps
$0DThe title menu and Settings; the error screen; a game's opening and its start; Test Play
$0E, $0F, $16, $17The battle: the battle task and its menus; a round and every action; the library of numbered functions; the monsters' choice
$10The program's tables: the tasks, the monster pictures' layout, the screen blocks, the room lists, the level table
$11Random Message's lines, four for each character graphic
$12Heroes and the start settings
$13Code; what it serves is not set out in the study
$14The event interpreter; the play save's writer
$15The walkers: moving, vehicles and encounters on the world map, moving in a map
$18Play: its set-up, the rooms and their events, the shop
$19The link cable; Test Play's Select menu; each event's own task
$1CThe Turbo File page and its driver
$1DThe Enemy Map's troops and its battle test
$1E, $1FThe title screen's pictures; the non-colour screen
$20The 8 × 8 font, the world map's font, the text palettes
$21–$24The 108 monster pictures, 27 to a bank
$25, $26The 70 characters and vehicles, 42 to a bank, and their palettes
$27The battle window; the blank project a format writes
$28The four world maps as small pictures, for the editors
$29–$2EScreens and windows stored whole as tile maps; the tiles of the title menu, the editors and the world map
$2F–$3AThe four world maps, three banks each
$3B–$3FThe room tile sets, the block every room loads (stairs, doors, chests), the room palettes; some animation graphics in $3C, $3E and $3F
$40–$6FThe 1,054 rooms, 743 bytes each
$70The title backdrops
$71The 16 × 16 title font; tile maps; the animations' palettes
$72, $75, $76, $7B–$7DAnimation graphics
$73The Enemy Map's small world
$74Screen maps and tables of the Enemy Map and the event editor, and one spell animation's graphics
$77–$7AThe sound driver, the same code in each, with each bank's songs and effects
$7E, $7FThe 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).

The modes ($C413)power-onsignature check7 the logo0 the titleLink, Settings$A Turbo File5 the editor3 the openingGame, Sample2 playtasks, below8 Game Over9 the endingstaff roll6 broken datathen a format1 error screena dead end4 unusedTest Playboth back to 0 or 3A frame: the main loop clears the frame's state, runs the mode's current step, then waits forV-blank, stepping the random numbers all the while.Play: 32 task slots, each run once a frame in turnOn the world map$0Ethe walker$0Ascroller$0Cwater$47spritesIn a battle: task $C3; the field's four are paused$C4menu$C6commands$CEa round$CCround's end$CAvictoryIn a map: $0D the walker, $0B the room scroller, $36 the event interpreter, one $35 per event, $47, $06.A task is a bank, a table of steps and 16 bytes of work; it moves on by changing its own step number.
The eleven modes, a frame of the main loop, and play's task slots.
ModeBankWhat
0$0DThe title menu, with the Link and Settings pages inside it
1$0DThe error screen
2$18Play: the world map, maps, the command window, shops, battles, all as tasks
3$0DA game's opening: PRESENTS, its title screen, Continue and From the Start
4$19Unused: 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$04The editor
6$04The broken-data message, then the format
7$09The ASCII logo after power-on
8$09The Game Over
9$09The ending: the staff roll
$A$1CTurbo 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:

AddressWhat
00:0150The entry: not a Game Boy Color → 00:020D, the non-colour screen, which halts
00:02ABClears all work RAM at power-on, the random numbers' seed with it
00:0EC8The main loop: the mode ($C413) and its step ($C414) through the table at 00:0DE5
00:0F8FThe idle wait: steps the random numbers until the frame's interrupt
00:0ED4, 00:0FA0The soft reset: A + B + SELECT + START, then the reset itself
00:1499The task scheduler: 32 slots, each run once a frame
00:110AStart a task by number, from its descriptor at 10:4000
00:07EB, 00:080ESwitch the ROM bank, and back to the one before
00:083D, 00:084CMap a bank of the save; a bank of work RAM
00:0933, 00:091DThe random numbers: a step; a draw from 0 to b
00:0893, 00:08BD, 00:08D9Multiply; divide (by zero: the error screen)
00:35F2, 00:3481The signature check; the format
00:3617, 00:3627Read a section with its sum (three tries); write one
00:1DD8Read a section from the cartridge, or from the sample in the ROM
00:33DDSample Load: the sample's image into the save
00:2091, 00:2289Load a map's events; a block of messages
00:2F4APrint a run of characters into the window buffer
00:3C3A, 00:1E6CLoad a monster picture; a character graphic
00:1727, 00:178FPassability in a room; on the world map (both let test play's START through)
00:2AF6The battle's library: a function of bank $16 by number
00:25E6Play a sound code: the program's one way into the driver
00:0D15The timer interrupt: the sound driver's tick
00:0DC0The 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.

The error screen, reached by setting its bytes by hand from the title.
The error screen, reached by setting its bytes by hand from the title.
CodeRaised by
0A 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
1All 32 task slots taken when a task is started (00:11C6)
2Ending a task that doesn't exist (00:1263, 00:127B)
4A 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.

S0mapsroom plansitemsenemy maptitleheroesthree play savessettingssignatureS1monstersorderthe message heapspellsmessage indexS2the message heap, continuedS3the event heap, 7,404 bytesindex, floors, places, chests, floor starts$A000$A800$B000$B800$C000parts with a sumplay saves (a sum each)settings, signaturemessages and events: no sumEach bank is 8 KB at $A000–$BFFF, one mapped at a time. Bank 2 holds nothing but messages.
The 32 KB save: four banks of fixed regions, with the signature at the end of bank 0.
SectionWhereBytesWhat
0S0:A00835The title page: the title (16), the backdrop, the author (16), the title song
1S0:A02B436The heroes, 8 × 51; the start settings, 27
2S0:A1DF712The world map's number; the 25 map records
11S0:A4A73,521The room plans
7S0:B2681,266The items, 115 × 11
9S0:B75A969The Enemy Map
15S0:BB2317The settings: the user-game mode, the last slot saved by each kind of game
12, 13, 14S0:BB34, BCC5, BE56401 eachThe three play saves
—S0:BFE76The signature, A6 95 99 94 C0 C2
8S1:A0002,449The monsters, 72 × 34
6S1:A991441The spells, 40 × 11
3S1:AB4A108The message index: 27 × (offset, length); no sum
—S1:ABB6929The messages' order; no sum
—S1:AF57–S2:BFFF12,457The message heap; no sum
—S3:A000–BFFF8,192The 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:

OffsetBytesWhat
+0001The source: 1 your game, 2 the sample, 3 test play
+0015The leader's name, for the slot list
+0061The leader's level, for the slot list
+0078 × 17Every hero's record, by hero number: level; the four stats (words); experience (3); maximum HP and MP (words); one byte not settled
+08F3 × 9Each party place: HP, MP (words), the four pieces of equipment, the condition
+0AA48The switches, 384 bits: 1–100 the maker's, 101–128 unused, 129–384 the chests' opened marks (chest c is switch 129 + c)
+0DA4A bit for each of the 25 places on the world map: the places visited (inferred)
+0DE1Not settled
+0DF1Battles on (0: none, test play's setting)
+0E03Gold
+0E33The party: hero numbers, $FF an empty place
+0E63The map ($19 the world map), the room, the floor
+0E92The leader's x, y
+0EB4The airship's x, y, then the ship's
+0EF1The song playing
+0F0115The items: a count for each
+1638 × 5Every hero's name, by number
+18B1The screen's tint
+18C4Never written
+1901The 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_···ABCDEFGHIJKLM
A_NOPQRSTUVWXYZ··(skull)
B_/○·♥♪♫(drop)%「」!?◆···
C_0123456789ⅠⅡⅢⅣⅤ·
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.

BytesIn a message
BFA new line
AFThe message's end (the font's tile there is a skull)
86 nnHero nn's name, as the player has it
85 nnA 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)
80The 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.

RecordBytesFields, in order
The title page35the title (2 × 8), the backdrop, the author (16), the title song as a sound code; the sum
A hero51the 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 settings27the 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 spell11the name (6), MP, power (words), the animation
An item11the 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 monster34the 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 map26, 14, 44the 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 plan25 or 36room types row by row, 0 for no room
The Enemy Map969a 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.

BytesWhat
0–359The screen's 20 × 18 tile numbers
360–719Their colour attributes: palette, VRAM bank, flips, priority
720–742Passability: 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.

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.

One event (its body)flags1length1page 1graphic, typepage 210page 310page 4absentlist 1… FFlist 2… FFlist 3… FFlist 4FFOnly the pages present have a header; all four command lists are always there, each ended by FF.The flags bytechestpage 2page 3page 4length, highbit 7bit 0The type bytemovement 0–5trigger 0–2still, up-down, side to side, random,approaches, flees | touch, A, automaticA page 2–4 header (10 bytes)switch1item1partymaskgold at least3graphic1type1its listoffset, 2Conditions are 0 for none; every one set must hold. Amounts are big-endian. Page 4 is tested first.A directory entry (5 bytes)room1x1y1the bodyoffset, 2A floor's entries end with FF FF FF 00 00.x, y in a room's 16 × 16 squares; on the world map, tiles.A chest (12 bytes)80 0Cnnchestiiitem11 gg gg gggold, as command 11FF FF FF FFfour listsThe item is FF for none; the gold is the gold command's own form.
An event's body, its flags byte, a header for pages 2 to 4, and its five-byte directory entry.

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.

OpcodesCommandsBytesOperands
00Message2its ID
01Random message1
02, 03Yes; No (the end of the yes branch)1
04Warp5floor and map, room, x, y
05, 06Switch on, Switch off2the switch
07Wait2tenths of a second
08, 09BGM; Sound2a sound code
0ABattle5three monsters (FF none), the battle's song
0BEnter name2the hero
0CVanish1
0D, 0EHero joins, Hero leaves2the hero
0F, 10Item +, Item −2the item
11, 12Gold +, Gold −424 bits
13Experience +424 bits
14–17Party HP +, HP −, MP +, MP −316 bits
18–1APoison; Cure; Full recovery1
1B–1EParty faces up, down, right, left1
1F–22Party steps up, down, right, left1
23, 24Party spins, Party blinks2times
25–28, 29–2CEvent faces, Event steps (up, down, right, left)1
2D, 2EEvent spins, Event blinks2times
2FInn3the price, 16 bits
30Shop5four items (FF none)
31–38Brighter, Darker, Red, Blue, Monochrome, Normal, Flash, Shake1
39End of event1
3ASave point1
3BGame Over1
3CEnding1
3D–3FA 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.

s, 16 bits$C862 (high), $C863× 4shift twice+ s+ $3711new sthe high byte outone step: s = s × 5 + $3711, the same constant and steps as Super Dante's and RT2'sWho draws00:0F94the idle waitover and over until the next frame: as many steps as the frame leaves time for00:091Drand(b)the high byte mod (b + 1): every draw of the battle00:092Athe raw bytethe encounter check on the world map, and the troop's size and membersbank $07animationspairs of rand(28) as a monster dies or a hero swingsThe seed is 0 at every power-on (all work RAM is cleared); the cycle is 65,536 steps long.
The random number generator, and the four places that draw from it.

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.

One byte for every sound: the code spacebelow $80: stop everythingsongseffects (81)$00$80$A0$AE$FFjingles (14)$80 does nothing; $8C, $8D (pause, resume) are never played; $FF stops everything.A header: a count, then 6 bytes a track (a song 4, one a channel; an effect 1)count1flags$80 song, $88 effectchannelNRx3trackpointer, 2transposesemitonespitch envelopeunusedA track: read when the last note runs out, until a note or a waitE9 22panEE 80dutyE4 A3volume9C 18note, 24 frames9Enote, same80restE7 0 2 aa aaloop twiceE3endA note is $80 + n: the frequency is the table's entry n + the transpose. A byte below $80 after a note is its lengthin frames, kept for the notes after it. On the noise channel the byte is the noise's setting instead.Commands are $E0–$FF: volume, jump, call and return, a counted loop, transpose, duty, tie, pan, the wave, a wait.The driver ticks once a frame (59.73 Hz): lengths are in frames, and there is no tempo byte.
The sound driver's one-byte code space, a header and a track.
ByteOperandsWhat
E3—The track's end
E4vVolume and envelope (NRx2), kept for each note after
E5addressJump
E6dTranspose by d semitones more
E7i, n, addressA counted loop: the section plays n times
E8vThe first channel's sweep
E9vPan: which sides the channel plays on
EC, EDaddress; —Call, return
EEvThe duty (the square wave's shape)
EF, F0—Tie on, off: notes change pitch without striking again
F1, F2e; —A pitch envelope (vibrato, a fall, a trill) on, off
F3wLoad wave w into the wave channel
F4, F6—The end of an effect on the second channel, on the noise
F5vThe wave channel's note length
FAnWait 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 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.

the giverclocks every bytethe receiverwaits, armedD0← D4helloD0← 80 + kthe kind wanted, 0–932 frames' pause on both sides1h← D2a byte's high nibble2l← D2its low nibble… every byte of the part, 24 a frame …40 40← D2 D3end of the block1h 2l ×2← D2the 16-bit sum, 4 nibbles40 40← D2 D3end of the sumthe roles swap: the receiver now clocksD0 accepted, D1 rejectedthe verdictEach answer is the byte the other side had ready when the clock ran. $FF or $00 means "no one there": the giversends the same byte again. Data never looks like a control byte, as each nibble is sent with $10 or $20 on top.
One link-cable session: who clocks each byte, and the roles swapping for the verdict.
ByteFromMeaning
D0giverHello, sent twice
D4receiverThe answer to the first hello
80 + kreceiverThe request, kind k (0–9): the answer to the second hello
1x, 2xgiverA byte's high nibble, then its low
D2receiver"Go on": the answer to each nibble and to the first 40
40giverThe end of a block, sent until answered D3
D3receiverThe end seen
D0, D1receiver, now clockingThe 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 (the device drives the clock)6C … C6wake5Astartcmd1parametersa bank, an offset, 64 bytes …sumto 0Its replyF1 … E77E … A5cmdechoerror0: nonestatusbitsdata64 bytes on a readsumto 0Each reply byte is fetched by sending F2. Status bits: 0 ready, 1 batteries good, 3 a bank selected, 7 write-protect on.The storage: 256 banks of 8 KB$00–$7E: the device, 120 blocks used$80–$FE: the memory card$7F and $FF: each side's 120 headers of 64 bytes, header n for bank nA header (64 bytes)5AusedA2QJthe gameRPG TCOOL 00the name, 17place0–3blocks4zeros40A file is four banks: the cartridge's four save banks in order, in the first four free banks of the side.The lists show a header only when it is used, its place is 0 and its game is A2QJ: other games' files are invisible.Deleting writes FF over the file's four headers and leaves the data.
A Turbo File GB command and its reply, the device's 256 banks, and a file's header.

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.

CommandParametersReply dataWhatUsed
10—the card byte, the bank (2), 0, 0Statusbefore every command
2001—Begin a sessiononce, first
22card bit, bank—Select the bank to writeyes
23card bit, bank—Select the bank to readyes
24——End the sessiononce, last
30offset (2), 64 bytes—Write 64 bytesyes
40offset (2)64 bytesRead 64 bytesyes
34offset (2), a byte—Fill 64 bytesonly from a format routine nothing calls
21, 28, 50, 60Two unknown, a 16-byte write and readno 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:

WhatHow it was checked
The saveEvery 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 formatBuilt from the ROM by the tool, and byte for byte what the game writes after a power-on and after the broken-data message
TextThe kana keyboard's own tile map, the heroes' names in the save, and the screens
The databaseEach editor page against the bytes behind it; saves edited by the tool, opened in the editor
Maps and graphicsRooms, 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
EventsThe 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 battle21 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
SoundAll 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 cableAll ten kinds between two emulators joined through files: the receiver holds the giver's bytes in exactly the kind's places
The Turbo File GBSeven 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 emulatorThe 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

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.