EMI container
An EMI archive is a 16-byte header, a table of contents (TOC) and payloads that each start on a CD sector boundary (2,048 bytes). Each TOC row gives a payload size, a type and a load argument; the type tells the loader to copy the payload to RAM, decompress it, upload it to VRAM or hand it to the sound system. The 880 archives on the US disc hold almost all game data, in 6,344 entries. What a payload means depends on the archive family and slot; payload formats have their own pages.
Header
Section titled “Header”| Offset | Size | Type | Meaning |
|---|---|---|---|
0x00 |
4 | u32 |
entry count |
0x04 |
4 | u32 |
format version (1 on the US disc) |
0x08 |
8 | char[8] |
MATH_TBL |
typedef struct EMIArchiveHeader { u32 entry_count; /* 0x00 */ u32 version; /* 0x04 */ u8 magic[EMI_MAGIC_SIZE]; /* 0x08 */} EMIArchiveHeader;Source: include/sys/emi.h
TOC entry
Section titled “TOC entry”One 16-byte row per entry follows the header from 0x10.
| Offset | Size | Type | Meaning |
|---|---|---|---|
0x00 |
4 | u32 |
payload size in bytes |
0x04 |
4 | u32 |
load argument (see Load argument) |
0x08 |
4 | u32 |
copy of the first payload word (the loader compares it with the payload) |
0x0C |
2 | u16 |
entry type |
0x0E |
2 | u16 |
padding, always 0x2E2E |
typedef struct EMITocEntry { u32 size; /* 0x00 */ u32 load_arg; /* 0x04 */ u32 first_word; /* 0x08 */ u16 type; /* 0x0C */ u16 padding; /* 0x0E */} EMITocEntry;Source: include/sys/emi.h
The first payload starts at 0x800; each later one at the next sector boundary after the previous:
next payload offset = current offset + size rounded up to a multiple of 0x800The last payload ends exactly at the end of the file.
Example: a row with size 1,160, load argument 0x800E4000 and type 0 is a 1,160-byte block copied to RAM 0x800E4000. It takes one sector, so the next payload starts 2,048 bytes later.
Padding
Section titled “Padding”Fixed fill values let a rebuilt archive match the original byte for byte.
| Region | Fill |
|---|---|
TOC row bytes 0x0E-0x0F |
0x2E2E |
0x10 + count * 0x10 up to 0x800 |
0x2E |
payload end up to the next 0x800 boundary |
0x5F |
Over the whole disc this is 1,686,656 bytes of 0x2E TOC fill and 7,440,017 bytes of 0x5F payload fill, with no exception.
Entry types
Section titled “Entry types”The type is a loader command. Types 4 and 5 never appear in a TOC (0 of 6,344 rows); they are internal loader states, and g_EmiEntryHandlers points both at EMI_ReadToc. Types 2 and 9 have a handler, but no entry uses them.
| Type | Loader treatment | Entries | Payload bytes | Note |
|---|---|---|---|---|
0 |
copy to RAM at the load argument; code or data | 2,623 | 39,534,564 | 429 code, 98 mixed, 945 data, 1,098 asset, 53 empty |
1 |
queue for decompression, then copy to RAM | 65 | 12,723,580 | all LZ77; 21,753,944 bytes decoded |
2 |
same handler as type 1 (EMI_LoadCompressed) |
0 | - | |
3 |
raw graphics upload to VRAM | 593 | 112,312,320 | every payload is a multiple of 2,048 bytes |
6 |
VAB header (VH) | 1,020 | 4,904,832 | every header starts pBAV |
7 |
VAB body (VB) | 1,020 | 79,157,504 | header size equals the VH fsize field in all 1,020 |
8 |
cue table of one bank | 904 | 34,432 | see audio |
9 |
sequence copy | 0 | - | |
10 |
sequence copy (SEP package) | 119 | 1,836,303 | every package starts pQES |
The type-0 Note classes are estimates. An entry counts as code only when its archive, slot, bytes, load address and disassembly agree. The 527 code-bearing entries resolve to 405 distinct images.
Load argument
Section titled “Load argument”TOC +0x04 is not always a CPU address.
| Type | Interpretation |
|---|---|
0, 1 |
CPU destination address (for type 1, the address of the decoded output) |
3 |
packed VRAM upload descriptor (graphics) |
6-8 |
audio bank selector, 0 to 6 |
9, 10 |
sequence copy; the destination comes from the bank record |
A bank’s type-6 and type-7 entries share one selector. A type-8 selector is one of its container’s type-6 selectors. The 1,020 type-6 entries use the selectors like this:
| Selector | Archives (type-6 entry counts) |
|---|---|
0 |
BGM (81), BOSS music (35), BATTLE (2), ETC (1) |
1 |
BMAGIC (128), PLCHAR (19), BOSS (40), BATTLE (6), ETC (14), WORLD second bank (3) |
2 |
WORLD areas (200), BOSS (40), BATTLE (2), ETC (2) |
3-5 |
BPLCHAR character forms (63, 74, 70) |
6 |
BENEMY (200), BOSS (40) |
A BOSS archive loads banks 0, 1, 2 and 6 together. Audio explains what a bank is.
Disc slot ids
Section titled “Disc slot ids”The game names an archive by its slot id, its index in the disc file list. EMI_LoadArchive (exe/slus_004_22@0x80161FDC) reads the start sector from g_EmiSlotLbas[slot_id]. For example, 0x261 is FIRST.EMI and 0x262 is GAME.EMI. The list is in ascending sector order, so each directory is one contiguous run of slots (Disc and files gives the ranges; the executable page describes the table).
The slot id is not the entry slot, the TOC index inside one archive. The caller that picks the slot, by directory:
| Directory | Caller that picks the slot |
|---|---|
BATTLE/* |
fixed ids 0-8 in emi/battle/battle/03 and emi/battle/battle/15 |
BENEMY |
func_801D1228 (emi/battle/battle/03@0x801D1228): g_GameAreaId + 9 |
BGM |
SND_RequestBGM (exe/slus_004_22@0x80161BBC): the table g_BGMTracks[id] holds the slot (0xD1-0x121) |
BMAGIC |
Battle_LoadSelectionEffect (emi/battle/battle/15@0x800AE1F8) and func_800AE2D4 (emi/battle/battle/15@0x800AE2D4): BattleSelection.id from the table at 0x800B65F8 (0x122-0x1B1) |
BMAG_XA |
SND_StartXAStream, key 0x1000 + n |
BOSS |
Battle_LoadBattleArchive (emi/etc/game/00@0x80197C94): the slot comes from g_BossArchiveSlots, indexed by the encounter record (0x1B3-0x1DA) |
BPLCHAR |
EMI_GetArchiveId families 1 and 2 (BPLD, BPLU, party combination 0-18); func_801E7948 (emi/battle/battle/03@0x801E7948) (BRTD/BRTU 0x201-0x208 for combinations 7, 13, 14, 15; tables D_800B4A64, D_800B4A68); func_801E75B0 (REI, 0x23C-0x23F); BMagic_Effect (RT, 0x240-0x243) |
ETC/* |
fixed ids (0x256-0x25F, 0x260 in scena17, 0x262, 0x265-0x269) in emi/etc/game/00, emi/etc/game/01, emi/etc/commu00/00, emi/battle/battle/03 and emi/scenario/scena17/00 |
PLCHAR |
EMI_GetArchiveId families 0 and 3 (PL, PLP, party combination 0-18) |
SCENARIO |
Scene_LoadOverlay (emi/etc/game/00@0x801A7804): scenario_id + 661 (0x295 is SCENA00) |
SCE_XA |
SND_StartXAStream, key kinds 0 and 2 |
WORLD00-04 |
func_8019FAA0 (emi/etc/game/00@0x8019FAA0) and Battle_ReloadAreaAudio (emi/battle/battle/03@0x801D7108): area + 0x2AB |
EMI_GetArchiveId (exe/slus_004_22@0x8016728C) adds a family bias to the character index:
| Family | Bias | Archives |
|---|---|---|
0 |
0x26A |
PLxxx bank |
1 |
0x1DB |
BPLDxxx |
2 |
0x1EE |
BPLUxxx |
3 |
0x27D |
PLPxxx code |
The index is the party combination, a row of the 19-row table D_80181B34 listing the three characters the archive set holds (party combinations). Combination 0 is 012 (young Ryu, young Nina, Garr): family 0 gives slot 0x26A (618, PL012), and slots 475, 494 and 637 are BPLD012, BPLU012 and PLP012. Combination 12 is 349: PL349 is slot 630.
SND_StartXAStream (exe/slus_004_22@0x801636A0) is not an EMI loader; it streams the three XA files with its own state machine (STR and XA; slot ids in the executable data).
Loader chain
Section titled “Loader chain”Every archive read runs EMI_LoadArchive, EMI_GetArchiveSector, EMI_StartArchive and EMI_CdOnReady. Then EMI_NextEntry starts each TOC row. Loader states 0, 4, 6, 8, 9 and 10 run inside the CD callback. States 1, 2, 3, 5 and 7 go through a 23-slot ring that EMI_Update drains each frame.
| Type | Handler chain |
|---|---|
| header | EMI_ReadToc checks MATH_TBL and builds the cumulative sector offsets in g_EmiSlotSectors[] |
0 |
EMI_LoadToRam, then EMI_CopySectorData (each sector goes straight to the load argument) |
1 |
EMI_LoadCompressed, then EMI_DecompressSector (@0x80163238, starts the decoder with LZ77_DecodeBegin), then EMI_CopySectorToScratchpad (@0x8016327C, copies two 1,024-byte halves to the scratchpad and runs LZ77_DecodeStep) |
3 |
EMI_LoadToVram (descriptor col:row:count), then EMI_UploadSectorImage (@0x80163378, one LoadImage of a 32x32-word rectangle) |
6 |
EMI_LoadVabHeader copies the VH and closes the bank’s previous owner |
7 |
EMI_LoadVabBody (SsVabOpenHeadSticky), then EMI_UploadVabBody (SsVabTransBodyPartly) |
8 |
EMI_LoadSoundCues copies the table to 0x801486A0 + 124 * bank |
9, 10 |
EMI_LoadSequence copies the payload to the bank record’s alternate destination |
All handlers sit in exe/slus_004_22.
Archive shapes
Section titled “Archive shapes”Archives of one family share a shape: the same entry types in the same slots. Slot numbers here are TOC indexes.
| Family | Archives | Shape | Entries by type |
|---|---|---|---|
| BENEMY | 200 | slot 0 VH (6,688 B), slot 1 cue table (64 B), slot 2 VB (2,816-35,632 B); selector 6 | 6:200 7:200 8:200 |
| BGM | 81 | VH, SEP, VB (78 archives); VH, SEP, cue (4-20 B), VB (BGM004, BGM108, BGM117); selector 0 | 6:81 7:81 8:3 10:81 |
| BPLCHAR | 121 | 44 whole banks, 75 one-section banks, 2 container archives (BPLD349, BPLU349) |
0:120 1:45 6:207 7:207 8:207 |
| PLCHAR | 38 | 19 PLxxx (VAB triple + LZ77 bank), 19 PLPxxx (code) |
0:19 1:19 6:19 7:19 8:19 |
| WORLD00-04 | 200 | seven shapes (below) | 0:1,832 3:408 6:203 7:203 8:203 |
| BMAGIC, BOSS, BATTLE, SCENARIO, ETC | 240 | code-overlay shapes (below) | mixed |
BENEMY, BGM and WORLD put the sound bank first (VH, cue table or sequence, VB) at slots 0-2. In BENEMY the 200 cue tables are byte-identical; the VH has 67 distinct bodies and the VB 58. In BGM, slot 1 is the SEP package.
Character archives
Section titled “Character archives”A BPLCHAR archive has one of three shapes:
| Shape | Archives | Slots |
|---|---|---|
| whole bank | 44 | three VAB triples (selectors 3, 4, 5, one per character form), 16 KiB zero filler at slot 3, LZ77 container at slot 7 |
| one-section bank | 75 | VAB triple and one type-0 section at one of five fixed addresses (load arguments) |
| container only | 2 | BPLD349, BPLU349: raw or LZ77 container |
The filler loads at 0x8003B800 and the LZ77 container overwrites it. Nothing reads it (character classes it reserve).
A PLCHAR archive pair has two shapes. PLxxx is a VAB triple plus an LZ77 bank at 0x8003B800 (slot 3). PLPxxx is one type-0 code entry at 0x801CE400 (slot 0).
Code overlays
Section titled “Code overlays”The first u32 of every code payload is a module id, which the type-0 loader compares with the TOC’s cached first word. Ids form one namespace across all archives:
| Range | Bodies | Content |
|---|---|---|
0x12-0x20 |
15 | ETC programs (0x12 START/STATUS, 0x13 SHOP, 0x14 BATE, 0x15 SHISU, 0x18 COMMU00, 0x19-0x1D COMMU01-05, 0x1E GAME00, 0x1F SISYOU, 0x20 GAME01) |
0x21-0x33 |
19 | PLCHAR programs (33 + name-order ordinal) |
0x34-0x104 |
181 | WORLD area programs (52 + area; 200 archives, 19 are data-only) |
0x105-0x118 |
20 | SCENA00-19 controllers |
0x119-0x11D |
5 | SCE10EFF, SCE15EF0-3 effect controllers |
0x11E-0x140 |
35 | BOSS modules |
0x141 |
1 | shared START#9 / SHOP#8 overlay |
0x142, 0x143 |
2 | BATL_END, BATL_OVR battle-effect modules |
0x144-0x1BF |
124 | BMAGIC effect modules |
A few companion world modules use the same word: 0x16 at 0x801D0C00, 0x17 at 0x800F5000, 0x18 at 0x801EEC00, and 0xFC-0x104 at 0x80117000. A payload that the game copies from another overlay keeps its source’s id.
Where the code entry sits depends on the family:
| Family | Load address | Slot of the code entry |
|---|---|---|
| WORLD | 0x801F2C00 |
varies by shape (below) |
| PLCHAR | 0x801CE400 |
0 (PLPxxx) |
| SCENARIO | 0x801F6C00 (SCENA), 0x801D0C00 (SCE*) |
0 only (the controller) |
| BMAGIC | 0x801EEC00 |
3 (128 archives with a VAB triple), 0 (13 archives without); the other slots are type-3 uploads, CLUT blocks (0x80033800..0x80036E00) and data blocks (0x800C3800, 0x80036C00) |
| BOSS | 0x800C1800 |
17-entry shape (BOSS001, 004, 022, 025, 031): slots 0, 12, 13; 20-entry shape (35 archives): slots 3, 15, 16. The three programs are the boss module and the two copied battle programs |
| BATTLE | none (per archive) | BATTLE and BATTLE2: programs at slots 3 and 15 (16 entries, byte-identical across the two); BATL_END and BATL_OVR: module at slot 0; BATL_RE2: CLUT bundle; BATL_DRA, BATL_RET, BATL_SE, COMN_SE: no code |
| ETC | 0x801D0C00 (menus), 0x80195800 (game/00) |
slot 0 for bate, game/00, shisu, shop, sisyou; 6 for commu03 and commu04; 7 for commu01, commu05 and commu02b; 8 for commu02 and start/08; 9 for start/09 |
WORLD shapes
Section titled “WORLD shapes”A WORLD archive holds one sound bank, its type-3 uploads and the type-0 area working set. An entry’s role follows its load address, not its slot. Seven shapes cover the 200 archives:
| Shape | Archives | Entries | Layout |
|---|---|---|---|
| A | 174 | 14 | audio 0-2, 0x800E3800 at 3, 0x800D3800 at 4, area program at 13 |
| B | 11 | 15 | A plus a 0x801EEC00 module at 14 (WORLD04 AREA175-185) |
| C | 9 | 15 | 0x80117000 module at 13, area program at 14 |
| D | 3 | 23 | AREA030, 089, 129: second audio bank, area program at 3, modules at 0x801D0C00 and 0x800F5000, extra CLUTs and uploads |
| E | 1 | 14 | AREA002: area program at 9 |
| F | 1 | 15 | AREA004: area program at 9, extra type-3 upload 0x1A080400 at 14 |
| G | 1 | 15 | AREA024: extra type-3 upload 0x1A080400 at 9, area program at 14 |
The area program is code in 181 archives. The other 19 payloads at 0x801F2C00 have no stack prologue and no jr $ra, so they are data (area). Which overlay is resident in which window is in runtime.
Data-only code-window payloads
Section titled “Data-only code-window payloads”Two type-0 images with code-style addresses are 512-byte CLUT blocks, not code: one segment ending at 0x200, one CLUT, no jr $ra and no addiu sp,sp prologue.
| Target | Load | Payload |
|---|---|---|
emi/etc/bate/03 |
0x80033A00 |
256 colors (512 B), arena +0x200, VRAM row 481 (area) |
emi/battle/batl_re2/01 |
0x80036E00 |
256 colors (512 B), arena +0x3600, VRAM row 507; colors 96-255 0x8000 (STP black) |
Open questions
Section titled “Open questions”| Question | What would settle it |
|---|---|
BOSS slot ids 0x1B3-0x1DA: no caller found; the one boss-overlay site read requests slot 4 (BATL_RET) |
a runtime trace of a boss battle load |
BMAGIC loading is table-driven (BattleSelection at 0x800B65F8); no caller maps a spell id to a table row |
the code that fills BattleSelection.id |
BPLCHAR filler (16 KiB zero entry at 0x8003B800, 44 archives): purpose |
a reader of the entry |
| BGM cue tables in BGM004, BGM108 and BGM117 (4-20 B): consumer | the sound-request code that indexes bank cue tables |
| Type-8 cue byte 2, low nibble | a consumer of the cue byte |
Type-0 slots with no named reader: BATTLE script table at 0x800F0800 beyond Actor_BeginScript; BMAGIC data blocks at 0x80036C00 and 0x800C3800; modules at 0x80117000 |
readers of those addresses |
Sources and confidence
Section titled “Sources and confidence”- Confidence: high. Header, TOC, padding, types and shapes are measured on all 880 archives; a few readers of type-0 data blocks are not found.
- Evidence: every archive’s header and TOC, the loader functions and slot callers named above. The community BoF3-Data-Doc only confirms (sources).
Related
Section titled “Related”- Disc and files: which archive is in which directory and slot.
- Type-1 LZ77 payload: the compressed form of type 1.
- Graphics formats: the type-3 VRAM upload and the type-0 CLUT blocks.
- Audio formats: the VAB, cue and SEP payloads of types 6 to 10.
- Area formats: the blocks of a WORLD archive.