Kajar notes of ChronoRET, rebuilding Chrono Trigger one matched routine at a time

30 October 2026: the graphics and the maps, as files you can open

Five pieces of the data plan went in overnight, and none of them is code. The scene scripts and the battle's layer-effect scripts are now readable text; the game's tile graphics come out as images; and every location's map, with its metatiles, exits and treasures, is now a text file. All of it is rebuilt from those files to the exact bytes of the cartridge.

The scene and layer-effect scripts

Two more of the game's little languages are done, the same way the event and battle scripts were. The scene scripts drive the eight scenes run from bank $C2's scene engine: 27,757 bytes once unpacked, 8,235 opcodes of 70 kinds, 580 jumps and 314 calls. The battle's layer-effect scripts are a third language: 142 scripts and 15,401 bytes of script and table.

As before, the length and the exits of every opcode come from running the code that handles it with the script's bytes known and everything else unknown. A few handlers call routines the interpreter cannot follow: an indirect jump through memory, a wait on the sound chip. The first draft took those as harmless. Now each one is refused unless it is on a short list, with a written reason why it leaves the script's position alone, and a second change turned three of those reasons into checks the tools run over the real data. Bytes no known entry reaches (1,089 in the scene packs, 414 among the effects) stay as data.

Proving a format from the code that reads it

A run of bytes does not say what it is. The same 32 bytes could be one 16-colour tile, two 4-colour tiles, part of a map or a table of numbers. The only thing that settles it is the code that uses them, so every image the project makes comes with a proof: where the code sends those bytes, and what the console does with them there.

For a location's graphics, the proof goes like this. The field draws in background mode 1, and the routine that sets up its layers puts the tiles for layers 1 and 2 at one place in video memory and layer 3's at another. It is called after every location load, before the map is drawn, and no other field code moves them. The location loader copies packs 0 to 5 of a location's list into the first area: in mode 1, layers 1 and 2 use 16-colour tiles, so those packs are 4 bits per pixel. Its layer-3 pack goes to the second: 4 colours, 2 bits per pixel.

The raw tiles came first: 22 regions, 244,952 bytes, most of it the 6,848 sprite tiles of the seven characters. Then the compressed ones: 484 packs, 1.25 MB packed and 1.68 MB unpacked, location tiles, sprite sets and the scenes' backgrounds. The build turns each image back into bytes and, for a pack, compresses it again with the project's packer. An edited pack still has to compress to its original size, because every pointer to the data after it is fixed.

Why some packs stay as bytes

A pack becomes an image only when something in the data names it in a place whose reader is proved. When nothing does, there is no proof of what it is, so it stays as compressed bytes, with the reason written down. Some examples from today:

  • Location packs 3, 31 and 211 are in the table, but no location names them.
  • One scene's sprite pack is named only in sprite slot 2, and the scene loader then copies the party's sprites over that slot. Whatever that pack holds, it is never on screen, so nothing shows how it would be read.
  • Two packs are only unpacked by script routines, into memory nothing traced reads.

A guess would not be caught by the build: a pack read with the wrong format still turns back into the same bytes. Only the reader can say which format is the right one.

Grey pictures

Every image is an indexed PNG, 16 tiles wide, where each pixel stores a palette number rather than a colour. The colours themselves are not part of the tiles. On the SNES a tile is coloured when it is drawn, by a palette that the tilemap or the sprite picks, and the same tiles can be drawn with several. Which palette a region goes with is not proved, so the images use a grey ramp: index 0 is black, the highest index is white.

The pixel numbers are what gets edited, and the palette has to stay as written. Many image editors sort or trim a palette when saving and renumber the pixels to match. The picture looks the same, but the numbers, and so the bytes, are different, so the build refuses such a file and says why.

The maps

A location in Chrono Trigger is up to three background layers. Each layer is a grid of cells of 16 by 16 pixels, and each cell holds one byte: a metatile number.

The sixteen bits of a toy tilemap word, $6C25: vertical flip, horizontal flip, priority, a three-bit palette and a ten-bit tile number, written 025/3ph

The SNES itself draws backgrounds from tilemaps, one 16-bit word per 8 by 8 tile: ten bits of tile number, three of palette, a priority bit and two flip bits. The project knows the metatile tables hold these words because the routines that draw a map's rows and columns copy them into the layers' tilemaps without changing them.

A toy map grid of metatile numbers; cell 2A points to metatile 2A, four tilemap words that make one 16 by 16 cell on screen

A metatile is four of those words, for the top-left, top-right, bottom-left and bottom-right tiles of a cell. Storing a map as metatile numbers takes an eighth of the space of storing it as tilemap words. A location names one table of 512 metatiles for layers 1 and 2 and one of 256 for layer 3. In the text files each word is written like 025/3ph: tile, palette, then p, h and v for the bits that are set.

After the layers, each cell of layer 1 has three more bytes of attributes, which the field reads for things such as whether a character can step onto the cell and whether it pushes them along. Two of their bits are the ninth bit of the cell's layer-1 and layer-2 metatile numbers. Neighbouring cells often share them, so they are packed as runs.

A toy row of eight cells: five equal attribute triples become a run of four bytes, one cell a plain entry of three bytes, two equal cells another run

The useful discovery was that all 197 maps are packed by the same rule: every repeat of two or more cells is a run, up to 256 long, and runs carry on past the end of a row. So the text file only needs the grid of cells, and the assembler makes the runs again exactly. Five maps' streams stop before the last cells; the game then reads whatever happens to follow in memory, and the text marks those cells --------.

Today's figures: 197 maps (995,296 bytes unpacked) and 71 metatile tables (253,952 bytes), and the 814 exits and 249 treasure records as readable records, all rebuilt to the exact bytes. As with the graphics, four map packs and two metatile packs that no location names stay as bytes.

Where the data stands

The 4,194,304-byte ROM as one bar, split into code and each kind of data the build places

The build checks that every one of the ROM's 4,194,304 bytes comes from something it can name, and the figure above is its count tonight. Data in readable form (text and records, the four script languages, the graphics and the maps) is now 2,711,587 bytes, 64.6% of the ROM; compressed data counts at its size in the ROM. What is still placed as plain bytes, 1.1 MB, is the sprite layouts, the music and its instrument samples, most of the tables and palettes, the raw graphics no reader proves yet, and 211 KB of packs kept as they are.

One small cost: to state its proof, the packed-graphics change added two sentences to the headers of two routines, LocLoad_Unk0960 and Ppu_SetBgLayout. A routine whose source changes goes back for an independent review, even for a comment, so the verified count reads 3,734 of 3,736 routines until those two are reviewed again.

None of this is stored in the project: the tools write the images and text from the player's own ROM, and the build rebuilds the ROM from them.

Next

The music sequences, the last script language; the rest of the $C3 module's code; and the graphics still to be proved, among them the battle's uploads and the text font.

← Back to devlog