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 flash, and how the program runs a game. Addresses are the GBA's own: the ROM appears at 0x0800_0000, the two work RAMs at 0x0200_0000 (256 KiB) and 0x0300_0000 (32 KiB), the flash at 0x0E00_0000. Offsets inside the flash and inside a record are written $90, +$1A. Everything here was read from the program and checked in emulators (the last section says how); where a point was read from the code but not seen running, it says so (read), and where it is a reading not traced to the end, inferred. 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 Advance is a new program. It is written in C, by RPG Tsukuru GB's team, and shares no code with GB (hand-written Game Boy code) or with RT3 and RT4 (C on the PlayStation). What it keeps from GB is the design: numbered kinds of task, each a table of steps run once a frame; GB's battle rules; and GB's Turbo File driver, written again byte for byte. Compared with the titles around it sets them side by side.
The cartridge#
The ROM's header names it RPGTCOOLGBA, game code A8TJ, maker CP. Inside:
- 8 MiB of ROM, the last 24,656 bytes of it padding.
- 64 KiB of flash, a Panasonic 512 Kbit part (it answers the ID command with
32 1B), driven through Nintendo'sFLASH512_V130library. Flash needs no battery.
There is no development tag: no company string, no build date, no developer's name. The only version in the ROM is 「VERSION 0214A」 on the DEBUG TASK, a developers' boot screen nothing reaches (Behind the scenes). The program was compiled with GCC (libgcc's helpers are linked in), with Nintendo's MusicPlayer2000 for sound and AGBAssert for its checks; 33 source paths survive in the asserts (below).
Notes/RPG Tsukuru Advance.md, Notes/RPG Tsukuru Advance/Program.md.
The ROM map#
| ROM | What |
|---|---|
0x0800_0000–0x080E_EDBB | Code, 0.93 MiB: the ARM start-up, then the program in Thumb, then the libraries; the ARM interrupt dispatcher at 0x080E_ED00 |
0x080E_EDBC | The scene table: 13 scene functions |
0x080E_EE90 | The process table: 299 kinds × 16 bytes |
0x080F_0140 | The signature RPGTCOOL GBA; at 0x080F_0154 the empty game's header |
0x080F_0154–0x0813_70FF | The program's data: each kind's state table, strings, the windows and screens, the database's defaults |
0x0813_7100 | MusicPlayer2000's players; 0x0813_7118 the song table (307 entries) |
to 0x087F_9FAF | Sound samples and songs; graphics from 0x081B_A2A0, 58 regions, every one with code that loads it; the font (0x0872_B184, 0x0873_A184), and the three project images: the default library at 0x0871_B2B4 (raw), Jewel Keeper at 0x0871_EE14 and the Tutorial at 0x0879_ED28 (both LZ77) |
0x087F_9FB0–end | $FF: 24,656 bytes of padding |
The code is 0.93 MiB, and analysis found none past it: 5,557 functions in a Ghidra project made from a copy of the ROM. Two pieces run from RAM: the flash library's read loop, which it copies onto the stack, and MusicPlayer2000's mixer, copied to the fast RAM at start-up. The libraries are Nintendo's and the compiler's:
| Address | Library |
|---|---|
0x080E_6E1C– | Nintendo's MusicPlayer2000 (m4aSongNumStart; SoundMain 0x080E_60E8, whose mixer runs from IWRAM at 0x0300_1268) |
0x080E_8300– | Nintendo's FLASH512_V130: ReadFlash 0x080E_8548, which copies its inner loop onto the stack and runs it there; the sector writer 0x080E_89A6 |
0x080E_8C40–0x080E_8FC0 | Nintendo's AGBPrint and AGBAssert (assert_fail 0x080E_8F9C) |
0x080E_8FE4, 0x080E_8FE8 | libgcc's _call_via_r1, _call_via_r2: every call through a pointer |
0x080E_AFC0–0x080E_B27C | The C library: memcpy 0x080E_B008, memset 0x080E_B0F0, memcmp 0x080E_B27C; newlib's rand at 0x080E_B158 |
Notes/RPG Tsukuru Advance/Program.md; Tools/adv_ghidra.py (the Ghidra project, built headless), Tools/adv_dis.py (a Thumb listing).
The program#
Scenes#
The main loop (0x0800_0108) runs one of 13 scene functions from the table at 0x080E_EDBC, chosen by the byte at 0x0201_0710. Each scene creates one root process, and the rest of the scene is that process's tree. The boot stores 4, the title, or 10 in the user-game mode; the top menu chooses the next by tab × 3 + item through the table at 0x0813_5A28.
| Scene | Root kind | What |
|---|---|---|
| 0 | 0 | The boot and the power-on check |
| 1 | 1 | The DEBUG TASK: nothing sets this scene (Behind the scenes) |
| 2 | 2 | A play session |
| 3 | 11 | Make the Data |
| 4 | 272 | The title |
| 5 | 273 | The top menu (with 261, its tabs) |
| 6 | 276 | Data Exchange |
| 7 | 277 | Options |
| 8 | 278, play mode 2 | Jewel Keeper's title |
| 9 | 278, play mode 3 | Make the Game: your game's title, for test play |
| 10 | 278, play mode 1 | Your game's title, in the user-game mode |
| 11 | 281 | Turbo File |
| 12 | 298 | Loading the Tutorial |
Processes#
The whole program, the editors, the game player and the system's windows alike, is a tree of processes. Each process is one of 299 kinds, defined by the table at 0x080E_EE90: 16 bytes a kind, the enter function (called once, when the process is made), the leave function (when it ends), its state table (one function a state), and flags. Every frame, each live process runs the function its state byte names; a state moves on by changing that byte. A screen's code is found from its kind: its enter sets it up, its states are its loop, and the kinds it creates are its windows and pages.
proc_create(parent, kind, priority, flags, param) (0x0800_1290) takes a process from a free list, joins it to a run list and to its parent's children, and calls the kind's enter. The root is at 0x0300_1220, the run lists after it at 0x0300_1244, one list a priority at 0x0300_1258; each frame 0x0800_172C walks them. Ending a process (0x0800_13A8) calls its leave at once; a process with children stays, inactive, until the last of them ends, and is freed then.
| Offset | What |
|---|---|
+$0 | Flags: bits 0–1 active, bit 2 flipped as the frame's walk passes it, bits 3–5 from the creator's flags |
+$2 | The kind |
+$4 | The priority (a run list for each) |
+$5 | The state: the index into the kind's state table |
+$10 | The parent; +$14, +$18 the first and last child; +$1C, +$20 the previous and next sibling |
+$28– | The links in the run lists |
The kinds sit in the ROM in the source tree's order, so a range of kinds is a part of the program:
| Kinds | Code from | What |
|---|---|---|
| 0–10, 12–23 | 0x0801_905C | The boot and the game player: 0 the boot, 1 the DEBUG TASK, 2 a play session, 3 the field on the world map, 4 on a local map, 5–10 and 17 the field's parts (10 one per thing on the map), 9 the event runner, 12 the message window, 13–20 the runner's windows (Yes/No, Choice, Password, telops, the church, the inn, the shop), 21–23 the egg palette |
| 11, 237–239, 254–260, 262–271, 274–279, 287–298 | 0x0805_70EC | The top level: 11 Make the Data, 238 Clear Data, 254 the first-time setup, 262 the level-up window, 263 the staff roll, 264 the end mark, 265 the Game Over, 266 "save the game's data?", 267 the save point, 276 Data Exchange, 277 Options, 278 a game's title, 279 its Continue, 287 its Options, 298 the Tutorial's load |
| 72–236 | 0x0806_8124 | The editors' pages, in the source's order: the title 72–75, the system 77–80, characters 82–86, jobs 92–95, items 98–101, skills 106–109, monsters 112–116, units 121–124, maps 130–151, create mode 160 and its placement editors 161–180, an event's contents 187, the command catalogue 188 and its parameter pages 190–220, Save 228, messages 230–234, keywords 236 |
| 240–252 | 0x080A_77FC | The services: 240 the window controller under every screen, 242–244 the number boxes, 246 the Yes/No box, 250 and 251 the animated cells of the title and menus |
| 61–71 | 0x080A_BCC0 | The battle: 61 and its parts |
| 34–60, 280 | 0x080C_B0EC | The field menu (34) and its pages: Items 35, Status 42, Skills 45, Equip 50, Order 56, Save 57 (58 in test play); 280 the map view |
| 24–33, 253, 261, 272, 273, 281–286 | 0x080D_B97C | 24 the name keyboard, 27–33 its lists of names; 261 the top menu's tabs, 272 the title, 273 the top menu; 281–286 the Turbo File |
Four kinds are never created: 49 (an equipment menu), 189 (an event-editor page), 224 (a developer's shortcut into create mode) and 237 (a menu in Make the Data); and kind 1, the DEBUG TASK, is created only by scene 1, which nothing sets (Behind the scenes).
The pad#
One routine reads the buttons (0x0800_F348, once a frame, the only reader of the GBA's key register), into 0x0201_0730: the buttons held, those new this frame, and a repeat (12 frames, then every 6). Up with down reads as up, left with right as left. Nothing reads the buttons at power-on or compares a sequence of them: there is no soft reset and no button code (read).
The asserts#
The program links Nintendo's AGBPrint and AGBAssert: 58 checks in the code call assert_fail(file, line, expression, halt) (0x080E_8F9C), every one with halt set. On the developers' IS-AGB debugger that prints 「ASSERTION FAILED FILE=[…] LINE=[…] EXP=[…]」 and stops. On a cartridge it shows nothing: the debugger's registers at 0x09FE_xxxx are then a mirror of the ROM, so the print loop reads game data, calls into it and ends on a swi 0xFF that is no BIOS call. A failed assert hangs the game with no message: one set off on purpose in Mesen (an event record of a kind the field doesn't expect) left a black screen and the program stopped where it was.
The checks keep their source file, line and expression, which give the developers' own tree: service/sv_buram/ (the flash and the project image, a file for each kind of data: sv_udjob.c, sv_udmap.c, sv_udevt.c …), service/sv_win/, edit/ (a file for each editor page: p_editchr08.c, p_editevt201a.c …), srv_proc/ (the services), and tf/ (the Turbo File). Some of the expressions say what they guard: !chk_size (sv_buram.c, line 932: the game fits the flash), objno < 128 (at most 128 things on a map), gSysWork.trs_flag_resv_buffp (the chest marks' buffer). The full list is in the notes.
Notes/RPG Tsukuru Advance/Program.md, Hidden Content.md, Play.md; Tools/adv_mesen.py --exec 08001290 (logs every process made, with its kind).
The flash#
Sixteen sectors of 4 KiB. Sectors 0–14 hold the project image, your game, 61,440 bytes; sector 15 holds the play saves. The program reads the image whole into RAM at 0x0200_0000 at power-on, keeps it packed there, unpacks one record at a time when an editor or play needs it, and writes the image back whole.
The power-on check#
The boot (kind 0, from 0x0801_9104, a step a frame):
- An empty game is built in RAM (
0x0800_19E4): the 60 KiB buffer zero-filled, the header from the template at0x080F_0154, every section emptied, the bytes free set to$EF6C, the sections' first records made, the sum written. - The flash is identified and read over it (
ReadFlash(0, 0, buffer, $F000)), at about frame 283. - Each of the 15 sectors is looked at (
0x0800_1958). One whose first 8 bytes readBURAM NG(the program's mark for a bad sector) fills the buffer with that mark, so the next step fails. One whose first 16 bytes are all$FFstops the check as erased: the program shows 「チュートリアルデータを ロードしています…」, unpacks the Tutorial from0x0879_ED28, writes it, and writes sector 15's fresh record. - The image is checked (
0x0801_92A8): the signature (0x0800_1AE4), the sum (0x0800_1C80, which first refuses an image that would end past$EFFF) and the version (0x0800_20C8, at least 10). Any of them wrong: an empty game replaces it, 「バックアップデータの内容が壊れています。」 shows, and the empty game is written.
The writes begin at frames 297–312, long before a button could stop them. Each case was run from a copy of the flash, in both emulators, with the same result to the byte (Saving and sharing has the table). The DEBUG TASK has two keys for the same machinery: R+SELECT writes an empty game, L+SELECT erases sectors 0–14 and leaves sector 15 (run from a patched copy).
The project image#
| Offset | Size | What | The cartridge's game |
|---|---|---|---|
$00 | 12 | The signature RPGTCOOL GBA (checked at power-on) | |
$0C | 1 | Bits 2–7 the format version, at least 10 (checked); bit 1 a flag the program sets and clears; bit 0 not understood | $29: version 10 |
$0D | 1 | The editor BGM (a song) | $25: song 37, データをツクル |
$0E | 1 | Bits 0–1 the cursor speed, bit 2 the user-game mode, bit 3 not understood, bits 4–6 the message speed | $38: message speed 3 |
$0F–$11 | 3 | Not understood | zeros |
$12 | 2 | The bytes free: $EF6C less the sixteen sections' lengths | $B615, 46,613 |
$14–$47 | 52 | Not understood | FF FF 7F 00, then zeros |
$48 | 64 | The section table: an offset and a length (halfwords) for each of the 16 | |
$88 | 8 | The next free id of sections 3–9 and 11 | 09 19 1A 36 8A 13 02 0C |
$90– | The sections, end to end | ||
| After the last | 4 | The sum: the 32-bit sum of every byte before it | $000A_8511, at $39E7 |
$EF6C is $F000 less the header and the sum: 61,292 bytes of data. The sum is a plain 32-bit sum of every byte from $0000 to the end of the last section, written just after it (0x0800_1BFC, which also zeroes the rest up to $F000). The settings in $0D–$0E are inside it: a header changed by hand without fixing the sum is rejected at power-on (seen).
The sections#
| 0 | The system: the element names, the church, the special screens' BGM | 1 | 25 bytes |
|---|---|---|---|
| 1 | The title and the staff | 1 | 26 bytes |
| 2 | The start; the three vehicles (records 2–4) | 4 | the start only, 13 bytes |
| 3 | Characters | 8 | 8, 230 bytes |
| 4 | Jobs | 100 | 15, 205 bytes |
| 5 | Monsters | 99 | 21, 513 bytes |
| 6 | Skills | 99 | 51, 740 bytes |
| 7 | Items | 99 | 30, 484 bytes |
| 8 | Units | 99 | 18, 189 bytes |
| 9 | Keywords | 30 | none |
| 10 | The variables ?A–?Z, fixed 9-byte entries | 26 | none |
| 11 | Maps | 30 | 9, 920 bytes |
| 12 | Messages, a block a list | 99 a list | 10 lists, 119 messages, 5,032 bytes |
| 13 | Encounters (the units placed on a map), a block a list | 64 a list | 13 lists, 130 bytes |
| 14 | Stairs (inferred), 9-byte records, a block a list | 20 a list | 32 lists, 12 records, 300 bytes |
| 15 | Events, a block a list | 224 a list | 97 lists, 269 events, 5,872 bytes |
Every section lies end to end from $90, each at the offset and length the table at $48 gives. A store (0x0800_2490) packs one record into the section in RAM; a commit (0x0800_2718) moves every later section along and puts right the table, the bytes free and the sum. Each section has a 16-byte descriptor in RAM (0x0800_2F58 returns it) with its count and its maximum, the maxima from the byte table at 0x080F_132C. An editor's refusals come from these: the count at the maximum, or the bytes free short of a default record (Limits).
The ROM's three images are laid out the same way. The default at 0x0871_B2B4, stored raw, is not a game but a library the editors copy records from: 50 jobs, 99 monsters, 98 skills, 99 items, 25 maps, no events or messages, its monsters named with size letters (Sスライム, LLオーディン). Jewel Keeper and the Tutorial, both version 63, are packed with LZ77; Jewel Keeper's sum sits at $EFFC, the last place it can.
Records#
Each record is packed by its kind's own routine, storing only what differs from the default. Byte 0 is the record's id and byte 1 its length (halfwords in the maps, messages and events); then flag bits, one for each optional field; then a few bytes always stored; then each field whose flag is set, in the routine's order. A text field is 8-bit text to its 0, and a text field left empty is not stored at all.
$484).Sections 2, 10, 13 and 14 hold fixed records, stored whole. A map's record depends on its type: the world map's is 12 bytes; a dungeon's is an 11-byte head and a sub-record for each floor; a town's a 12-byte head and 15 bytes for each building. A reader of names has to step over the two-byte codes, not stop at the first 0: a kanji such as 06 00 has a 0 inside it.
Blocks#
Sections 12–15 are runs of blocks, one for each list: a head (a key, the block's size counting the head, and the list's next free id), then the list's records. The heads of sections 12 and 13 are 4 bytes (key 1, size 2, counter 1), those of 14 and 15 are 6 (each 2). The keys rise with gaps, an empty list keeping its block. The map records hold their lists' keys; 0x0800_3A60 checks a key's range by kind: a message list at most 30, an encounter list below 180, a stairs list at most 479, an event list at most 1,469.
Sector 15#
| Where | Size | What |
|---|---|---|
Sector 15 $000–$002 | 3 | Which play wrote each slot: 1 your game published, 2 Jewel Keeper, 3 Make the Game |
$00F + 4 × slot | 4 a slot | The party's members, for the save list |
$01C + $52C × slot | 1,324 a slot | The three slots, to $F9F |
$FA0–$FFB | 92 | Unused: $FF |
$FFC | 4 | The plain byte sum of $000–$FFB |
A slot +$000 | $300 | The eight characters, $60 each |
+$300 | $20 | The members' states, 8 bytes each (HP, poison, paralysis …) |
+$320 | $20C | The play state from the gold on: the gold, the map and square (+$340–+$343), the switches, the timer, the bag, the vehicles |
A fresh sector 15 is zeros but byte $1B ($FF, not understood), $FF from $FA0, and the sum A3 5C 00 00; the cartridge's is exactly that, so no game was ever saved on it. A save (kind 59) reads the sector whole, packs the slot from the play state, sums it again and writes it (0x080A_BC74(proc, 1, buffer); the project's write is the same routine with 0 and the image). Continue (kind 279) reads it up to 16 times while the sum fails (0x0804_BEC0), and lists only the slots whose first byte matches the title it came from.
Notes/RPG Tsukuru Advance/Save.md, Play.md (§Saving and loading); Tools/adv_save.py (check, sections, dump, rebuild, roundtrip, settext, diff): it parses each of the four images down to its fields and builds it again, byte for byte, and an image it edited was taken by the game, which then wrote back the same 61,440 bytes.
Text#
One table of 2,560 codes, the font's own order, serves everything the program writes in a window: its own strings, your names and messages. It is not Shift-JIS. The program's strings are 16-bit (little-endian; $000A a new line, $0000 the end); your game's text is 8-bit: a byte $01–$09 starts a two-byte code (byte × 256 + the next), $0A is a new line, $00 the end, and any other byte is its own code. So kana, Latin and marks take one byte in your game, kanji two. The cartridge game's first message, 「隊長!おきてください!」, is 04 FE 05 53 21 7F 81 8D 82 3E 85 7C 21: 隊 $4FE, 長 $553, then a byte each.
| Codes | What |
|---|---|
$000–$0FF | Kana, Latin letters, digits and marks: the katakana at their JIS X0201 places, the hiragana in no kana order around them |
$100–$7A2 | 1,699 kanji of JIS level 1, in Shift-JIS order (亜 … 腕): the rarer 1,266 left out |
$7B0–$831 | 130 kanji more, the ones an RPG wants (鎧 兜 斧 闇 呪 祠 罠 …) and the staff's name kanji |
$832–$85D | Marks (「 」, arrows, ○ △ □, ♪, Ⅰ–Ⅹ, ©) and two kanji |
| The rest | Blank |
Six name codes, $0B–$10, each followed by a record's number, draw a character's, job's, item's, skill's, monster's or map's current name in a message: the cartridge's game greets its hero by the name the player gave him with $0B 01. The message copier (0x0800_FFE8) takes every byte from $01 to $10, $0A aside, together with the next.
The font is 8 × 12 pixels, drawn into the window's tiles by 0x0801_02A0 from two planes: a 1-bit mask (0x0873_A184, stored inverted, four glyphs a row) and a 2-bit colour plane (0x0872_B184), whose ink is colour 2, the body, or 3, a lighter edge that softens corners. The big outlined headings (オプション, 消費MP …) are pictures, not text. The kanji were identified by likeness, each glyph against JIS level 1 drawn small, then checked against the keyboard's lists of kanji by reading; six stay doubtful (Messages and text).
Notes/RPG Tsukuru Advance/Text.md; Tools/adv_text.py (table, font, dec8, enc8, strings).
The database records#
Each kind's unpacker starts from its default struct in ROM (0x080F_01E4 the system … 0x080F_048C the unit), puts the fixed bytes in place and reads in the flagged fields. The structs, as the program holds them in RAM:
| Section | Struct | Fields (offset: field) |
|---|---|---|
| 0 System | $3C | +$02 … +$2A the five element names (4 characters); +$34 the church's two prices (14 bits each, and a bit for "× LV"); +$38, +$39 the shop's and the church's BGM |
| 1 Title | $128 | +$01 the BGM; +$02 the title picture (0–36); +$03 the frame (bits 0–3) and "shown by an event" (bit 4); +$04 the title (24); +$36 the author (12); +$50 and +$BC the six staff roles and names (8 each) |
| 3 Characters | $88 | +$00 the job; +$02 LV; +$04 thirty skills and +$40 their levels; +$5E–+$66 the five starting pieces of equipment; +$68 the id; +$6A the name (6); +$78 the graphic; +$7C the resistances; +$84 the growth speed (bits 0–1), in use (bit 2, inferred) |
| 4 Jobs | $20 | +$00–+$05 the six growths; +$06 the id; +$08 the name; +$1A–+$1C the attack, defence and turn skills (6 bits each) |
| 5 Monsters | $44 | +$00 gold; +$02 EXP; +$04 the job; +$06 LV; +$08 seven skills and +$30 their conditions; +$18 extra HP (32 bits); +$1C the id; +$1D the graphic; +$1E the name; +$38 the resistances; +$40 the graphic's variant and the personality |
| 6 Skills | $1C | +$00 the MP cost; +$02 the power; +$04 the effect; +$06 the name; +$18 the id; +$19 the kind (bits 0–5), technique (bit 6), all (bit 7); +$1A the statuses cured and the help display |
| 7 Items | $20 | +$00 the price; +$02 the power (or +$19 the statuses cured, or +$1A the skill cast: one of the three, by kind); +$04 the id; +$06 the name; +$18 the kind and all; +$1B who can equip it (a bit a character); +$1C the extra effect; +$1D the icon; +$1E the help display |
| 8 Units | $10 | +$00 the id; +$01–+$06 six members; +$07–+$0A four treasures; +$0B the formation and the type; +$0C the unit effect; +$0E its condition |
| 9 Keywords | $14 | +$00 the id; +$02 the word (8) |
- Resistances are 20 two-bit entries (entry i in bits 2(i mod 4) of byte i/4): the ten statuses, four specials (補無効, HP吸, MP吸, 即死), the five elements and one unused. 0 never works, 1 normal (the default,
55 55 55 55 15), 2 always works. - HP, MP and the other stats are not stored: they are the level × the job's growth, plus the equipment (The database).
- A job id from 201 is a place in the list, 201 the first job; past the game's own list it reads the default library's job at that place.
- A linkable field holding −1 to −26 reads variable ?A–?Z instead (
0x0800_807Cafter unpacking; in play0x0804_FBA4, which holds the value to the field's range from the table at0x080F_0DF4). - The start is section 2's first record: the gold (bytes 2–3 and 7 bits of byte 4: 23 bits written, 22 read back), the four members, and the position.
Notes/RPG Tsukuru Advance/Database.md; Tools/adv_db.py (dump, raw, check).
Maps#
A map is picked, never drawn: each of the three types is built from pieces in the ROM into a grid of cells, 4 bytes each (a flag byte, a byte, the block's number). A block is 16 × 16 pixels, four entries of a tile map.
- The world map: one of 6 presets, 100, 120 or 144 cells square (the resources at
0x080F_2230; the record's byte 10 is the preset × 2). It wraps both ways. The towns and dungeons stand on it as events. - A town: one of 33 grounds (
0x080F_2664) with up to 16 buildings, 15 bytes each: its look, its place, a stairs-list key, an event list for each of its three storeys, and three of the 209 templates at0x080F_55D4. Outdoors is a 48 × 49 grid; inside, a template centred in a 62 × 62 grid, the middle storey with an overlay, the doorway. - A dungeon: up to 6 floors, each 6 × 6 squares of room shapes (8 × 8 cells each) and 84 bits of joins, in one of 6 styles (
0x080F_AF78), stamped into a 48 × 49 grid.
A position is a word: x, y, the map, and a byte whose bits 0–5 are the building or the floor and bits 6–7 the storey (0 outdoors, 1–3 inside). A floor is given as a number with 5 for the entrance floor, the others counted from it; a dungeon is left by walking off its outer edge, and only on its entrance floor.
The field's screen is mode 0, four text backgrounds of 512 × 256:
| Screen block | Priority | Holds |
|---|---|---|
$19 | 3 | The ground (on the world map, shown on BG2) |
$1B | 1 (2 on the world map) | The layer over it: walls, roofs, trees |
$1D | 2 | A third layer, with tiles of its own |
$1F | 0 | The window and test play's bar |
The camera keeps the hero at (112, 56) on screen. Every map of the four images was drawn by the project's tools, 652 pictures, and each of the 122 screens that showed one matched its drawing with 0 pixels different.
Notes/RPG Tsukuru Advance/Maps.md, Graphics.md; Tools/adv_maps.py, adv_ppu.py (a GBA screen from a RAM dump, matching the emulator's frame buffer exactly), adv_gfx.py.
Events#
The lists and the records#
Section 15 holds one list for each place events can stand: the world map, a town's outdoors, each storey of each building, each dungeon floor. An event's record is its id (2 bytes) and length (2), a byte whose bits 0–3 are its kind and bits 4–6 its page count, its x and y, then what its kind needs:
| Kind | What | After x and y (bytes 5, 6) |
|---|---|---|
| 0 | Object | The pages' heads, then all their commands |
| 1 | Person | The same (a person's head adds facing, movement and speed) |
| 2 | Map entrance, on the world map | Where the party stands on leaving the map; three more cells if byte 4 bit 7 is set; then the pages (each with its destination) and commands |
| 3 | Chest | Its chest mark, its graphic, four 2-bit content kinds (nothing, item, gold, unit), then 4 bytes for each content |
| 4 | Door | Its number (0–149), its graphic, the key item (no image has a door) |
| 5 | Event egg | The egg; in byte 4, bits 4–5, a thing (0) or a person (1); its collision is fixed in the cartridge |
| 6 | — | Not stored: the field's own entries for the vehicles (its store routine asserts) |
Pages. Page 1 has a short head (the graphic, the start type and its parameter; a person's facing, movement and speed; an entrance's destination) and no conditions. Each later page's head starts with its own length and holds its two conditions, its start type, its graphic and the offset of its commands. All the pages' commands follow the last head as one run, each page's ending with opcode 0. The page in force is, as the games are written, the last whose conditions hold; Enterbrain's published FAQ says the higher page wins; the field's choosing code was not read.
The commands#
A command is its opcode byte and fixed arguments, little-endian, the size per opcode from the table at 0x080F_1748. Bits 0–6 are the opcode, 0–110: 1–80 the catalogue's commands, 81–106 Set ?A to Set ?Z, 107–110 the second-branch labels of Yes/No, Choice, Battle (Win/Lose) and Password; 0 ends the page. Bit 7 is an option the command's page sets: a message from the common list, a sound played without waiting, and the like. A page is unpacked into 16-byte commands (0x0800_B688; packed again by 0x0800_B81C).
The interpreter is kind 9, the event runner: its state 1 (0x0802_DDD0) takes the next command and calls the routine for its opcode from the table at 0x0810_3F54; the routine is called again every frame until it says it has finished (0x0803_F960). Windows, shops, inns and battles are processes the routine creates and waits on.
Branches. A branching command whose first answer comes (はい, the first choice, the right password, a won battle) simply goes on to the next command. Otherwise it scans forward for its own label, counting the same pair's openers and labels for depth, and goes on after it; with none, it clears its own opcode and the page ends. A label reached by running ends the page, as opcode 0 does: there is no rejoining. The Yes/No scan is GB's, step for step.
Variables. Section 10's 26 fixed entries are the variables ?A–?Z. Each declares the field it stands for (an owner kind, a field, a record, an opcode), from which the program works out a field code; the values are 32-bit, in the play state. Set ?X stores its value only if the variable's field code is still the one recorded when the command was written. No image uses a variable.
Checked: every page of the four images (1,605) splits exactly by the size table; the events go to a script and back to the same bytes; and script-written events ran in the game as predicted, branches included.
Notes/RPG Tsukuru Advance/Events.md; Tools/adv_events.py (list, script, build, roundtrip).
The battle, in short#
A battle is kind 61 (39 states) with its parts as kinds 62–71, started by 0x080C_4788 from the field (a step's encounter, or test play's SELECT) or from an event's battle command. Its work (pointer at 0x0300_072C, zeroed at each start) holds ten combatants, the party's four and the unit's six places: their HP and MP, their four stats as set up and as randomised each round (±⅛), the modifiers that skills set, their statuses and commands, and copies of the monsters' and the unit's records. The rules are on How battles work.
The random numbers are the Mersenne Twister, MT19937 (0x0800_F1BC, its state at 0x0200_F760), in its 1998 reference form, seeding with Knuth's 69069 and a default seed of 4357. It is seeded once, from the frame counter (0x0300_0724), when Make the Game is chosen on the top menu: 612 at frame 890 of a cold boot. rand(lo, hi, n) (0x0800_FC94) sums n draws, so n > 1 gives a bell-shaped spread. The field's code uses the C library's rand instead.
Checked: 53 battles recorded with every draw logged were replayed by the project's model of the battle, draw for draw, 19,117 draws with every combatant's HP through every value; the first 31 were replayed again in the second emulator, each taking the same seed and ending with the same twister state.
Notes/RPG Tsukuru Advance/Battle.md; Tools/adv_battle.py (make, record, check, mt).
The sound#
Nintendo's MusicPlayer2000, linked whole, plays everything. SoundMain runs once a frame from the VBlank handler: the effects' player first runs the music's (so the music always ticks first), then the four PSG channels are updated, then the mixer, in ARM code in the fast RAM, mixes 8 DirectSound channels at 10,512 Hz (176 samples a frame) with a reverb pass. Two players: music, and effects.
- The song table (
0x0813_7118) has 307 entries, of which 167 are songs: 38 BGMs and 129 sound effects; the rest point at empty headers. BGM n is song n; sound effect n is song 100 + n up to 113, the rest through a table (0x080F_B0A4). - Two voice groups of 128 voices, music and effects; 70 samples, 452,207 bytes, every one recorded at the mixer's own 10,512 Hz.
- A song's header sets the reverb for everything. The interface effects set 10 and the songs 30, so a cursor click drops the music's reverb until the next song or effect sets it back (read).
- A message beeps every second character, the effect chosen by the speaker's graphic: a man's, a woman's, a child's, a monster's or an animal's voice (
0x080F_B3B0).
Checked: the project's model of the engine, ported routine by routine, matched the game's own mixer output byte for byte over every song (277,080 calls compared); the guide's clips are its renders (Music and sound).
Notes/RPG Tsukuru Advance/Sound.md; Tools/adv_m4a.py (the engine's model), adv_sound.py.
The link cable and the Turbo File#
Data Exchange (kind 276) uses the GBA's multi-player link mode at 115,200 bits a second, in 72-byte frames. The ROM also holds the version tag of Nintendo's multi-player serial library, MultiSio010918 (18 September 2001), which nothing points to. The exchange itself was not run or read further.
The Turbo File (kinds 281–286, the source's tf/, code from 0x080E_3930) speaks RPG Tsukuru GB's protocol byte for byte, over the GBA's 8-bit serial mode with the device's clock:
- the wake-up
$6C, answered$C6; - packets of
$5A, a command, its data and a negated sum, answered$F1then$E7,$7Ethen$A5, or$F2and a byte; - the same twelve commands as GB's (templates at
0x0813_5CE8), the same five never sent ($21,$28,$34,$50,$60); one sender of another form (0x080E_3E90) is never called; - the same 120 file headers of 64 bytes in each side's last bank, and the same error numbers.
A file is the whole flash, 8 blocks of the device's 8 KiB, marked A8TJ and named RPG TCOOL GBA and two characters (an assert in p_tf04.c refuses one outside 0–9 and A–Z): 15 games to a side, where GB's 4-block files fit 30. No device or model of one was run (GB's Turbo File, as it ran).
Notes/Turbo File.md, Notes/RPG Tsukuru Advance.md (§Lineage).
How this was checked#
Mesen 2.1.1 ran the cartridge headless, scripted from Lua: from power-on with a pad script, it took frame-buffer shots, RAM dumps, read, write and execution traces with the program counter, the live process tree and savestates. Every run started from a copy of the cartridge's flash; the original was never written. mGBA 0.11, through a libretro frontend in Python, was the second emulator, and the findings that rested on Mesen alone were run again there:
| What | In both emulators |
|---|---|
| The boot and the menus | Frame for frame to frame 1,300: the scene byte, the random-number state and the frame counter change on the same frames |
| Power-on, eight flash images | The same 65,536 bytes left in each (the power-on check) |
| 31 recorded battles | The same seed, the same random-number state at the end, and no word of the battle's work with a different history |
| Two play tests (the caps, the inn) | The same settled screens, pixel for pixel |
Where the two differ is timing, not logic: a long load can take a frame more in Mesen, so a fixed-frame shot of a moving screen can differ; a value being written as a frame ends can be caught at different points; and Mesen's shots of a fast-changing screen blend two frames. Which is nearer the hardware was not tested. The screenshots of this guide come from both: the editors' from Mesen, the cartridge game's from mGBA.
Notes/RPG Tsukuru Advance/Second Emulator.md; Tools/adv_mesen.py, Tools/adv_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.