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 the console's, bank and offset ($80:8001); offsets into the save are written $0000–$FFFF. Each section ends with the project's note and tool that hold the full detail. They are files in the project that made this guide, not pages of the site.
The cartridge#
SHVC-ZR2J, header title RPG-TCOOL 2. Inside:
- 2 MB of ROM (16 Mbit), LoROM, run at FastROM speed (the reset switches it on), with no coprocessor.
- 64 KB of battery SRAM, seen by the console as
$70:0000–$7FFFand$71:0000–$7FFF. It holds one user game, its three play saves and the editor's settings. - A Satellaview memory-pack slot on top of the cartridge, for an 8 Mbit pack.
Through the second controller port the program also talks to a Turbo File Twin. Just under the ROM header, at $80:FF80, sits the developer's tag, KUSOU KAGAKU DEVELOPMENT SYSTEM VER 2.28 (Behind the scenes).
Notes/RPG Tsukuru 2.md, Notes/Dumps.md.
The program's banks#
In LoROM each bank shows 32 KB of ROM at $8000–$FFFF, so the 2 MB are the 64 banks $80–$BF, bank $80 + n being the file's bytes from n × $8000. Code is in 17 of them, split by use: $80 shared by everything, $81–$85 the game being played and the battle, $86–$87 the demo, the ending and the front end, $88–$8A and $8D the editors, $8E the memory pack, $AD the sound. The rest is data: graphics, the fonts, the sound's samples and songs, the editors' scripts, and in the last two banks the factory save image, the sample game.
The map was made with a code/data log: Mesen marks each ROM byte as it is run or read, and 318 runs (every menu and editor, play in three games, battles, with random presses from 158 saved states) add up to 90,300 bytes of code run. Landmarks:
| Address | What |
|---|---|
$80:8001 | Reset |
$80:802B | The main loop; the mode table at $80:F000 |
$80:8128, $80:8178 | NMI, IRQ |
$80:86B8 | Queue a VRAM DMA for the next NMI |
$80:8A8A, $80:8AA0 | The random number generator; the same, mod n |
$80:8AC6 | The decompressor (its methods at $80:F740) |
$80:9146 | Create an object |
$80:9D3A | The script VM (ops at $80:BC4C, lengths at $80:BA4C) |
$81:A393 | The event interpreter's step |
$83:BEC6, $83:BF80 | The opcodes' start and continue handlers |
$85:8000, $85:828F | The encounter check; the start of a battle |
$87:909F | The Turbo File library's one entry |
$88:9983 | The power-on save check |
$88:D390 | Load the sample data |
$AD:FF40 | The sound interface |
$AF:A9D0 | The proportional font's pointers |
$BE:8000 | The factory save image: the sample game |
Notes/RPG Tsukuru 2/Program.md; Tools/snes_dis.py (the disassembler, which takes the CPU's register widths from the log), Tools/mesen_cover.py, Tools/rt2_modes.py.
The main loop and its modes#
The reset ($80:8001) sets the stack and the FastROM bit and clears the mode word $B9. The main loop ($80:802B) then waits for each frame and runs the routine for the current mode through the table at $80:F000. A mode with several steps keeps its step in $BB, moving on by adding 4.
| Mode | Entry | What |
|---|---|---|
$00 | $80:803E | Power-on: the hardware and the RAM set up |
$3C | $80:8061 | Cold or warm boot: a copy of the development tag in RAM tells a reset from a power-on |
$40 / $44 | $82:D8D6 | Cold boot: the boot screens ($44 on a PAL console, the same code) |
$48 / $4C | $82:D943 | Warm boot, after a reset: straight to the demo |
$50 | $86:B79C | The opening demo, a Mode 7 flight |
$74 | $87:A541 | The front end: the title and its menus; its second step is the save check |
$78 | $88:8248 | Editing: the Edit menu and every editor |
$5C | $84:8000 | Playing a game: the user game, a test play or the sample |
$60 | $86:D4CC | The ending, then back to the demo |
$04–$1C, $20–$38 | Unused: a BRK or a stub, never set |
Objects. Every screen is a tree of objects: 128 records of $80 bytes at $7E:4000, each with a 32-byte direct page of its own from $7E:1000, linked to a parent, a child and siblings. Each mode starts by creating a root object ($80:8FEA); an object's routine dispatches on its state byte (+5). Video work is queued: $80:86B8 adds a DMA to a list that the NMI sends to VRAM, and eight HDMA channels are handed out by $80:826A.
Warm and cold boot. At power-on the program copies its development tag into RAM. A reset leaves RAM alone, so finding the copy there tells a reset from a power-on: a reset skips the boot screens and goes straight to the demo. Holding L R START SELECT in play does the same without a reset: back to the title menu, past the save check.
Notes/RPG Tsukuru 2/Program.md, Hidden Content.md.
The SRAM image#
The 64 KB are one uncompressed image at fixed offsets: a header, the three play saves, nine sections (the database, the maps, the heap's directory) and the event heap, which fills both halves of the SRAM. The program reads the image in place, and each editor saves only its own section.
| Offset | Bytes | Sum | What |
|---|---|---|---|
$0000 | 24 | The signature SHVC????RPG TKOUL 2, padded with spaces | |
$0018 | 2 | The total: the nine section sums and the three slot sums added | |
$001A | 1 | The save counter, +1 at every editor's save | |
$001B | 72 | yes | Section 1: the title and the credits |
$0063 | 55 | The memory-pack data choices, outside every check | |
$009A | 5 | yes | Section 0: Config |
$009F | 3 × 544 | each | The three play saves |
$06FF | 1,907 | yes | Section 2: 127 items of 15 bytes |
$0E72 | 834 | yes | Section 3: 64 spells of 13 bytes |
$11B4 | 3,850 | yes | Section 4: the land and sea masks, then 96 enemies of 40 bytes |
$20BE | 1,013 | yes | Section 5: the start (party, gold, vehicles, BGM slots, position), then 12 heroes of 81 bytes |
$24B3 | 2,617 | yes | Section 6: the enemy maps (per screen a 32-enemy mask and a rate), the battle backgrounds, the battle test's party |
$2EEC | 7,180 | yes | Section 7: the field (size, island parts, 256 screen words), the 128 maps' names, types, outside parts and screen masks, the 300 pool screens |
$4AF8 | 272 | yes | Section 8: the event heap's directory |
$4C08 | 12,248 | The event heap, part 0 | |
$7BE0 | 1,056 | Play saves 1 and 2's memory-pack records; the rest never used | |
$8000 | 31,712 | The event heap, part 1 | |
$FBE0 | 1,056 | Play save 3's pack record and the three records' checksums; the rest never used |
The database is fixed tables: an item is 15 bytes, a spell 13, an enemy 40 and a hero 81. Fields are packed where they could be: an item's kind shares a byte with who can equip it, a cursed or unsellable item is one bit of its power or price, and an enemy's six stats are stored × 4, with the two spare bits of each holding where it appears (land, sea, both), its colour, and its chest chance, two bits at a time.
In the factory image, the never-used tail of the first bank holds stale bytecode: a development test page that runs through the whole command set (Behind the scenes). The image was copied whole from a development save.
The power-on check#
Every time the game is switched on and reaches the title (the front end's second step, $88:9983), the save is checked:
- The 24-byte signature at
$0000. - The nine sections: each begins with a word holding the 16-bit sum of the section's other bytes (
$88:9B1B). - The three play saves, each with its own sum. A bad play save is cleared on its own.
- The total at
$0018, the sum of the twelve sums.
Any other failure formats the whole save at once, without a word ($88:99E9): blank sections, new sums, empty play saves. The heap's bytes stay, but its directory is reset, so they can't be reached. The result is an empty project, not the sample game. Every editor's save rewrites its section, the section's sum and the total together, so only a power cut during a save, or a failing battery or contact, can trip the check. That is why a second-hand cartridge's save should be dumped before the cartridge is switched on (Limits).
Play saves#
Three of 544 bytes, at $009F, $02BF and $04DF. Most of a save is a copy of the party's state in RAM ($7E:8000); the heroes' levels, HP, MP, experience and equipment follow, 14 bytes each.
| Offset | Bytes | What |
|---|---|---|
+$000 | 2 | The sum of the other 542 bytes |
+$002 | 1 | $80: in use |
+$003 | 1 | The kind: 0 user game, 1 test play, 2 the sample, 3 a game played from a memory pack. A test play adds bit 6 (invincible) and bit 7 (monsters on) |
+$004 | 3 | Gold |
+$007 | 4 | The party |
+$00B | 32 | The 240 switches, a bit each |
+$02B | 1 | Reserved: kept, never set |
+$02C | 254 | The bag: 127 pairs of item and count |
+$12A | 2 | Sound; cursor speed |
+$12C | 6 | Where the party is: the map ($FF the field), x, y |
+$132 | 12 | The three vehicles' positions |
+$13E | 6 | Their facings; what the party rides; the screen tint and mosaic; the battle message speed |
+$144 | 50 | The places visited, for teleport |
+$177 | 1 | The window colour |
+$178 | 12 × 14 | Each hero: level, HP, MP, experience, status, 5 pieces of equipment |
Notes/RPG Tsukuru 2/Save.md; Tools/rt2_save.py (check, dump, build: every field out to text and back, byte for byte).
Text and the fonts#
One byte a character, the same code in the save and in the program's own strings. 00 ends a line or a string; name fields are padded with 40, the space.
| Code | x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | xA | xB | xC | xD | xE | xF |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x | (end) | (page 2) | ~ | ♡ | ♪ | " | Ⅱ | Ⅲ | : | … | / | ・ | . | , | 。 | 、 |
| 1x | 剣 | 魔 | 法 | 士 | 神 | 聖 | 女 | 人 | 死 | 城 | 町 | 村 | 王 | 天 | 竜 | 術 |
| 2x | 悪 | 光 | 氷 | 炎 | 地 | 水 | 火 | 風 | 命 | 幻 | 戦 | 者 | 木 | 石 | 本 | 薬 |
| 3x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | + | ー | ○ | × | ? | ! |
| 4x | (space) | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
| 5x | P | Q | R | S | T | U | V | W | X | Y | Z | 『 | 』 | ( | ) | あ |
| 6x | い | う | え | お | か | き | く | け | こ | さ | し | す | せ | そ | た | ち |
| 7x | つ | て | と | な | に | ぬ | ね | の | は | ひ | ふ | へ | ほ | ま | み | む |
| 8x | め | も | や | ゆ | よ | ら | り | る | れ | ろ | わ | を | ん | ぁ | ぃ | ぅ |
| 9x | ぇ | ぉ | ゃ | ゅ | ょ | っ | ア | イ | ウ | エ | オ | カ | キ | ク | ケ | コ |
| Ax | サ | シ | ス | セ | ソ | タ | チ | ツ | テ | ト | ナ | ニ | ヌ | ネ | ノ | ハ |
| Bx | ヒ | フ | ヘ | ホ | マ | ミ | ム | メ | モ | ヤ | ユ | ヨ | ラ | リ | ル | レ |
| Cx | ロ | ワ | ヲ | ン | ァ | ィ | ゥ | ェ | ォ | ャ | ュ | ョ | ッ | が | ぎ | ぐ |
| Dx | げ | ご | ざ | じ | ず | ぜ | ぞ | だ | ぢ | づ | で | ど | ば | び | ぶ | べ |
| Ex | ぼ | ガ | ギ | グ | ゲ | ゴ | ザ | ジ | ズ | ゼ | ゾ | ダ | ヂ | ヅ | デ | ド |
| Fx | バ | ビ | ブ | ベ | ボ | ヴ | ぱ | ぴ | ぷ | ぺ | ぽ | パ | ピ | プ | ペ | ポ |
01 xx is a second page: 01 08–01 47 are the 64 kanji a user can type after the 32 at 10–2F (泉野原家今昔勝負, 大中小金上下左右 …), and 01 48–01 F6 are kanji for the program's own menus. The voiced kana have codes of their own (CD–FF), so a name never needs two bytes for one kana.
Three fonts, in bank $AF:
- The proportional font (512 pointers at
$AF:A9D0, one per code): a width byte (1–12 pixels) and that many columns of 16 pixels. The menus, the editors, the name keyboard and the messages use it. - Two 8 × 8 fonts of 320 tiles each, 2 bits a pixel: a shadowed one at
$AF:81D0(the battle's windows, the menus' small text) and a plain one at$AF:95D0(some editor screens). They have no voiced kana: a voiced kana is drawn as its plain form with ゛ or ゜ in the row above, so small text takes two rows. The menu kanji have no small form.
The program's strings are in the same code, almost all inside the screens' scripts (below) and in 32 tables of pointers: 1,768 strings in all. One table no script uses: the Turbo File's 20 error messages, two of which speak of a "TF3".
Notes/RPG Tsukuru 2/Text.md; Tools/rt2_text.py (table, font, names, dump).
The event heap and the bytecode#
All events live in one heap of 43,960 bytes over both SRAM banks: part 0 at $4C08–$7BDF (12,248 bytes), part 1 at $8000–$FBDF (31,712). The field's events come first, then each map's in map order with no gaps. Section 8, the directory, holds the bytes free, where map 1's events start, where the last map's end, and 128 words: each map's byte count. A map's block is found by adding up the counts before it, and no map may pass 12,288 bytes.
Commands are one opcode byte and fixed operands, but for the message and the caption, which carry their text. The editor's 40 commands become 75 opcodes because every direction, tint and step style is an opcode of its own. Text in a message is the one-byte code above, each line ended by 00.
| Op | Command | Bytes | Operands |
|---|---|---|---|
00 | End the event | 1 | |
01 | Message | 2 + text | The number of lines, then each line's characters and a 00 |
02 / 03 | Switch on / off | 2 | The switch − 1 |
04 / 05 | Item + / − | 2 | The item |
06 / 07 | Gold + / − | 4 | 24-bit amount |
08 | Experience + | 4 | 24-bit amount |
09–0C | HP + / HP − / MP + / MP − | 3 | 16-bit amount |
0D / 0E | Poison / paralyse | 1 | |
0F / 10 | A hero joins / leaves | 2 | The hero |
11–14 | The hero faces up / right / down / left | 1 | |
15–18 | The hero steps up / right / down / left | 1 | |
19–1C | The event faces up / right / down / left | 1 | |
1D–20 | The event steps up / right / down / left | 1 | |
21 | Flash | 1 | |
22–26 | Screen brighter / darker / red / blue / monochrome | 1 | |
27 | Colour and mosaic back to normal | 1 | |
28 | Shake | 1 | |
29 | Battle | 6 | The BGM, then 4 enemies of the 96 (FF none) |
2A | Warp | 4 | The map (FF the field), x, y |
2B | Inn | 3 | 16-bit price |
2C | Shop | 9 | 8 items (FF none) |
2D | Wait | 2 | Tenths of a second |
2E | The event vanishes | 1 | |
2F | BGM | 2 | The song |
30 | Sound | 2 | The effect |
31 / 32 | Yes branch / no branch | 1 | |
33 | Save point | 1 | |
34 | Ending | 2 | The BGM |
35 | Caption | 2 + text | As 01 |
36–39 | The event steps, keeping its facing | 1 | |
3A–3D | The event steps, not treading | 1 | |
3E | The event blinks | 2 | Tenths of a second |
3F / 40 | The event spins left / right | 1 | |
41–45 | Screen green / yellow / purple / light blue / sepia | 1 | |
46 | Mosaic, fast | 1 | |
47 | Cure poison and paralysis | 1 | |
48 / 49 | Screen all black / the ground black | 1 | |
4A | Mosaic, slow | 1 |
Questions. A message that asks something is followed by 31, the yes branch, 32, then the no branch. Neither branch has an end marker: the yes branch ends at its 32, the no branch at the page's end. So nothing can follow both branches, and a second question can only sit in the no branch.
The interpreter#
Each running event is an object with its pointer at [$0C] and a flag byte at $0F. The step ($81:A393) reads the opcode and calls its start handler ($83:BEC6); while a command is still running (flag bit 1) it calls the continue handler ($83:BF80) once a frame instead. A command that finishes at once costs no frame, so a run of switches, items and gold happens in one frame; a message, a step, a fade or a wait holds the event until it is done.
The interpreter doesn't run commands from the SRAM. Each is first copied into a buffer in RAM ($83:DC51) and ended with $80, and the copy rewrites some: end the event (00) becomes 57, the internal end, and a warp becomes fade out, warp, fade in. The runtime has internal opcodes of its own for this and for its own scripts:
| Op | What | Put there by |
|---|---|---|
50 | Fade in | A warp |
51 | Fade out, and the music if the new map's differs | A warp |
52 | Gather the party into the leader | Boarding a vehicle |
53, 54, 5B | Board the sea, air or land vehicle | Boarding a vehicle |
55 | Relative jump | Nothing found |
56 | Wait a frame | After an event's step |
57 | End of the page | In place of 00; the no branch's 32 jumps to it |
58 | Wait 3 frames | |
59 | End at once | Nothing found |
5A | Stop | The end of the boarding scripts |
5C | Fade out | Boarding the air vehicle |
Choosing a page ($81:A8DC when a map loads, $81:AABB after an event has run): for each event, pages 4, 3 and 2 are tried in turn ($83:A1C7), and the first whose conditions all hold is taken; page 1 needs none. A page 2–4 with no condition is never taken. An item condition is met by an item carried or equipped.
Pseudo-events. The start of play, and boarding each vehicle, are small event scripts the runtime keeps at $7F:F800: the start is a warp to the start or the saved place, then a fade in.
Notes/RPG Tsukuru 2/Events.md, Interpreter.md; Tools/rt2_events.py (check, dump, script; make_event and pack write events), Tools/rt2_interp.py.
Map packing#
Maps are built in three levels, so that the SRAM holds little more than part numbers:
- A chip is one 16-pixel cell: 4 tile words from the set's chip table (8 bytes a chip).
- A part is 4 × 4 chips, 32 bytes of the set's part table. Each of the five map types has its own set of 256 parts, tiles, palettes and chip attributes, found through tables at
$A5indexed by the type. - A screen is 4 × 4 parts: 16 part numbers in the save's pool of 300 screens (
$3838). - A map is 4 × 4 screens: in section 7, a word for its first pool screen and a 16-bit mask of the grid cells in use (
$3638). Unused cells, and any part 0 in a used screen, are drawn with the map's outside part.
The field keeps 256 screen words instead ($2F38): island part × 4 + the quarter. Each word expands through $B1:8000 into 16 field-part numbers, and each field part points ($B6:AA00) at its 16 chips, from the field's own set in bank $B0.
Layers. In BG mode 1 the ground is BG2 (tilemap at VRAM $7800); object events are BG1 ($7000), one chip a cell from a 64 × 64 byte map that the events fill; windows and text are BG3; people and the party are sprites. One attribute byte per chip says how a cell can be crossed: on maps 0 is walkable and 1 or 2 blocked; on the field it is the terrain, which decides passability by foot, ship and air, and the battle background (Maps and the field). Maps cycle a few colours every 8 frames; the field cycles its sea.
Notes/RPG Tsukuru 2/Maps.md; Tools/rt2_maps.py (render, check, sets, sheet).
The decompressors#
Every compressed block begins with a method byte, and one routine ($80:8AC6) dispatches on it. It can be told to stop after so many units, so a big load is spread over several frames.
| Method | Routine | What | Used for |
|---|---|---|---|
$00 | $80:8AF0 | Stored: a count, then the bytes | Nothing found |
$04 | $80:8B3C | LZ on bytes | One block of the boot screens |
$08 | $80:8BFD | LZ on 16-bit words | Battle-background tilemaps, enemy arrangements |
$10 | $8A:8000 | The tile packer | Every tile set: maps, the field, battle backgrounds, enemies, spell animations |
The tile packer (method $10, at $8A:8000) works a unit at a time, a unit being 16 bytes or one 32-byte tile. A header gives the unit size, two fill bytes and a code table; a stream of 1- or 2-bit codes then picks, for each unit, one of six ways to build it: copy it whole from the data, fill it from a mask (each bit a fill byte or the next data byte), or repeat the byte or word before it under a mask. A mostly empty tile costs its masks and a few bytes.
The LZ methods ($08 on words, $04 on bytes) read eight tokens to a control byte: a literal, or a copy of 3–18 units from an absolute position in a window that starts 18 zero units before the output.
Where the graphics are. The 71 character sheets are uncompressed, 48 tiles each (8 frames of 16 × 24), through a resource table at $A0:EF00; a character's resource is its editor number + 15. An enemy graphic is a header at $90:8000 + 2 × its number: size, tiles (method $10) and arrangement (method $08), with its four colourings at $90:80CE. The 17 battle backgrounds are listed at $90:8D00, and the spell animations at $90:A000 (tiles), $90:A0E0 (frames) and $90:A140 (timing), all in one 64-colour set (Graphics).
Notes/RPG Tsukuru 2/Graphics.md; Tools/rt2_gfx.py (unpack, chars, enemies, battlebgs, magic).
The object-script VM#
Almost everything RT2 shows is bytecode: the field's windows, the event commands' windows, the battle's flow and its messages, the front end, every editor screen, the boot screens, the demo and the ending. One small virtual machine in bank $80 runs it, as part of an object.
- Running (
$80:9D3A, every frame): fetch an op, dispatch through$80:BC4C, repeat until the script ends or waits. A waiting op is called again next frame through its continue handler ($80:BD4C). Lengths are in a table ($80:BA4C), and00starts a sub-op. - Bit 7 of an op turns its last operand from a constant into a variable.
- Variables are 16-bit addresses through a base: absolute RAM, the object's own record, a walk up and down the object tree, or a pointer the object holds.
- Control flow is structured, with no jump offsets: if, else, end if, loops, switch and case. A branch not taken skips forward counting the nesting.
| Kind | Ops | What |
|---|---|---|
| Control | 01–12 | If a byte, word or 24-bit variable compares, or a bit is set; else, end if; repeat, do-until, while, switch and case, break, continue. No jump offsets: an untaken branch skips forward counting nesting |
| Calls | 13–1A | Go to; call native code; call a script and return; wait a frame; end (the object is deleted); halt |
| The base | 1B–1E | Where variables are: absolute WRAM, the object's own record, a walk of the object tree, or a pointer slot |
| Values | 1F–27, 2E–4D, 70–75, 7F | Set, clear, exchange; and, or, eor, not, shifts; increment, decrement, add, subtract, multiply, divide; push and pop |
| Graphics | 2B–2D, 62, 66–6B, 7C–7E | Decompress; a VRAM DMA; tile blocks, frames and boxes; palette bits over a rectangle; colours to CGRAM |
| Text | 4E–61, 63–65, 6C–6F, 76–7B | The window and its VRAM; the cursor, speed, palette, tile base and fill; a character, a string, a string from a table, a new line; numbers |
| Sub-ops | 00 nn | 28 more: copies, lines of a character, waits for frames and buttons, the base, filling VRAM, a call through a table |
From the four tables of entry points (the event windows, the field's windows, the battle's scripts, the front end's and the editors' windows) and fifteen fixed starts, 1,634 scripts and subroutines, 202,130 bytes, are reached in banks $82–$8E; banks $8B and $8C hold nothing else. A message is run the same way: the message command compiles its lines into VM code in RAM and calls it, so it prints through the same text op as every menu, at a fixed two frames a character.
Notes/RPG Tsukuru 2/Scripts.md; Tools/rt2_vm.py (ops, scan, check, a disassembler).
The battle#
A battle has eight records of 256 bytes: the party in slots 0–3, the enemies in 4–7. A hero's is the hero's record in RAM ($7E:8200 + 256 × the hero) copied whole; an enemy's is built from its 40 bytes in the save, each stat divided by 4. The flow is a script (the table at $85:967A) calling native routines for the rules.
Each round: the escape roll, the commands, then the turn order, by speed and nothing else (a bubble sort, ties to the party and the lower slot), then each turn: status first, then the choice and the action. There is no hit roll and no variance: an attack does (attack − defence) ÷ 2, at least 1, and a critical hit (1 in 16) attack − defence. An enemy picks one of its battle methods and spells with equal odds. Auto is a fixed list of tests with no random numbers. All the rules, with their formulas: How battles work.
Encounters. Each step on foot or by ship counts up to 17 since the last battle; a battle starts when a random byte falls below the table at $85:805A, by the screen's rate and the steps. The group is drawn from the screen's enemy mask, shuffled by 331 random swaps.
The random number generator#
$80:8A8A: s = s × 5 + $3711, 16 bits at $00A7, returning the high byte. $80:8AA0 takes a step and returns the high byte mod n, by the hardware divider.
- The period is full: the generator visits all 65,536 states before repeating, so over a cycle each high byte comes up exactly 256 times.
- Mod n is uneven where n doesn't divide 256. For the item break chance and the chest, tested against mod 101, the values 0–53 come up 3 times in 256 and 54–100 twice, so every chance between 1 % and 99 % is a little higher than it says (Limits).
- The seed is power-on RAM. The start-up clears all of RAM but the stack page, and keeps
$00A7aside while it does; nothing else ever sets it. A console starts somewhere new at each power-on. - The idle loop draws numbers: while a frame waits for the NMI, the main loop calls the generator about 350 times. So the number any decision gets depends on timing to the cycle, and a battle can't be predicted from the inputs, only replayed from the numbers it drew.
Notes/RPG Tsukuru 2/Battle.md; Tools/rt2_battle.py (record, check, show: a battle recorded in the emulator and replayed through a model of the rules).
The sound driver#
RT2 has its own SPC700 driver, a sibling of the one in the SFC Kanadeeru. At power-on the program sends the sound chip a loader, then everything but the song:
| From | Bytes | To (SPC RAM) | What |
|---|---|---|---|
$AD:D1B9 | 5,770 | $05E0 | The driver |
$AA:8000 | 37,629 | $2000 | 44 samples (BRR) |
$AB:92FD | 176 | $1F00 | The sample directory |
$AB:93AD | 88 | $1EA0 | Each sample's tuning |
$AD:E843 | 64 | $1FC0 | 16 vibrato presets |
$AD:E883 | 192 | $1CC0 | 48 instruments |
$AD:E943 | 288 | $1D80 | A 36-drum kit |
$AD:EA63 | 3,063 | $B300 | The 65 sound effects |
$AB:B000 | 617–3,645 | $D000 | The song playing, sent at each change of song |
- The interface. The game calls a jump table at
$AD:FF40(play song n, fade out, play effect n). Calls only put two bytes in a queue of 16; once a frame, from the NMI, the queue goes to the sound chip through its ports, followed by the tick commandED. - No clock of its own. The driver ticks once each time it gets
ED: once a frame, 60 times a second. - Songs. A song is only its sequences, 0.6–3.6 KB, sent to
$D000at each change. It has eight tracks, one to each voice, and a conductor track that may change the tempo. There are 24 units to a quarter note, so the tempo byte is the beats per minute (72–168). Every song loops. - Instruments. All 30 songs play on one set: 44 samples, 48 instruments, a 36-drum kit and 16 vibrato presets.
- Effects are sequences in the same format, run at one unit a tick. An effect takes its voice from the music, voice 6 or 7 for most; a newer effect on a voice replaces the older.
- Echo. The echo buffer is 4 KB at
$C000, set up by the loader. - Song numbers. 0 stops the music, 1–30 are the ROM's songs, and 31 on would be a memory pack's, played on the ROM's instruments.
Notes/RPG Tsukuru 2/Sound.md; Tools/rt2_sound.py (check, song, instruments, samples, rip), Tools/snes_spc.py. Every song and effect is ripped as an .spc (Music and sound).
The Turbo File and the memory pack#
The Turbo File Twin#
Bank $87 from $87:8000 holds a general Turbo File library, the same in all four SFC Tsukuru titles, with one entry (JSL $87:909F, a function number in A: mount, format, find, open, read, write, close, delete …). It speaks the Twin's STF mode: 124 blocks of 1 KB after a 4 KB table, each block's chain and 8-bit sum in the table. Every block is read twice and compared, and a write is read back, nine tries in all. The NMI is off for the whole access.
RT2's file is 62 blocks, so two games fill a Twin exactly:
| File offset | Bytes | What |
|---|---|---|
$0000 | 24 | SHVC, ZR2J, RPG-TCOOL2-nn |
$0018 | 31,720 | SRAM $0018–$7BFF |
$7C00 | 31,744 | SRAM $8000–$FBFF |
The file is the whole user game, play saves included: only the save's signature and the never-used tails are left out. A load reads the whole file into RAM first and copies it to the SRAM only if every block was good; a block with a bad sum makes RT2 delete the file and leave the cartridge alone. An unformatted Twin is formatted without a question.
The memory pack#
An 8 Mbit Satellaview pack is 8 blocks of 128 KB, block b at banks $C0 + 4b onward (bank $8E holds the code). A block counts if it carries a valid Satellaview header (maker B1, a checksum and its complement), and its first four bytes say what it is:
| First bytes | Kind | What |
|---|---|---|
RPSV | 1 | An RT2 game, as RT2 writes it |
RPSM, RPSX | 2, 3 | Game files RT2 didn't write (broadcast ones, presumably); read exactly as kind 1 |
RPGR | 4 | Graphics data: extra part sets, enemy graphics, palettes |
MTTC | 5 | Sound data: songs, effects and streamed samples. The SFC Kanadeeru's export file |
RT2 writes one game to a block, the first erased one, and a delete erases the whole block:
| Block offset | Bytes | What |
|---|---|---|
$0000 | 24 | RPSV, 4 zeros, ASCII TCOOL MEMP |
$0018 | 31,720 | SRAM $0018–$7BFF |
$7E00 | 432 | A stub, for a Satellaview that tries to run the file: it says it can't be used on the BS-X cartridge |
$7FB0 | 48 | The BS header: maker B1, the title RPGツクール2 ファイル0n, the block mask, a checksum |
$7FE0 | 32 | The stub's vectors |
$8000 | 31,744 | SRAM $8000–$FBFF |
A game on a pack can also be played without loading it: the play save then records the file's title and checksum, and at power-on RT2 looks for the file again wherever it now sits. The sound and graphics files the Data page chooses are found the same way, by a title and checksum kept in the save at $0063–$0099. The graphics file (RPGR) would have supplied map types 5–7, further enemy graphics and more palettes; no such file is known to survive (Behind the scenes).
Notes/RPG Tsukuru 2/Storage.md, Notes/Turbo File.md; Tools/snes_turbofile.py, Tools/snes_mempack.py.
How this was checked#
Every format on this page was written back as well as read, and run in an emulator, so that a reading that was nearly right would show:
| What | How | Result |
|---|---|---|
| The save | Every field dumped and the image rebuilt, for the factory image, both cartridges' saves and a played copy | Byte for byte; an edited save passed the game's own check |
| The events | Every event and page of the three saves parsed | Factory 456 events and 651 pages, cart 1 the same, cart 2 436 and 436; not a byte left over |
| The interpreter | Test events using every opcode, run in Mesen | Every opcode's start handler ran but 00's, which the copy turns into 57 |
| The maps | Eight places drawn from the save and the ROM, against Mesen's screen | Pixel for pixel |
| The battle | 31 recorded runs replayed turn by turn through a model of the rules | 1,327 turns, 153 escape rolls and chests, none wrong |
| Two emulators | Ten battle saves recorded in Mesen and in bsnes, from cleared RAM | 672 and 670 turns, 101 rolls and chests each, none wrong |
| The screens | Six places compared between the two emulators | The same wherever both stand at the same moment |
| The sound | Every song and effect ripped and played back | All 30 songs and 65 effects run as in the game |
| The scripts | The VM's length tables against its operands; every reachable script walked | No mismatch in 196 ops and 46 sub-ops; 1,634 scripts |
| Turbo File, memory pack | Save, load and delete, in MesenCE with a Twin and in Mesen with a pack | Both cartridges' games out and back byte for byte |
- The emulators. Mesen 2.1.1, run headless by a script (savestates, scripted presses, watches, traces, memory dumps, screenshots from the frame buffer); MesenCE 2.2.1, a fork of it that emulates the Turbo File Twin; and bsnes 115.1 through its libretro core, run from Python with its memory read out of savestates.
- Why replay. Because the random numbers depend on timing within a frame, the two emulators draw different numbers and their battles go differently. So each battle is recorded with every random number at its call site and every change to the combatants, then replayed through a model of the rules; the model must give the same action, HP and status every turn.
- The second emulator. In bsnes, which has no hooks, the ROM copy was patched to log the same things to a ring in RAM. Both emulators were started from cleared RAM, which fixes the seed.
- What turned up. Where the two stood at the same moment, their screens agreed pixel for pixel, and every difference was one of timing. The cross-check also found a bug in RT2's escape roll (Limits).
Notes/RPG Tsukuru 2/Second Emulator.md, Analysis Plan.md; Tools/mesen.py, Tools/lr.py, Tools/rt2_xcheck.py.
Fan-made reference material, one of the Eschaton Games Tsukuru guides. Not affiliated with the publishers of the titles it covers.