FF7/Field
Contents
Important Files
PSX Version | PC Version |
---|---|
/FIELD/*.DAT | /DATA/FIELD/FLEVEL.LGP |
/FIELD/*.MIM | /DATA/FIELD/FLEVEL.LGP |
/FIELD/*.BSX | |
/FIELD/*.BCX | /DATA/FIELD/CHAR.LGP |
Field Overview
The field module is the core of the game to which everything else is spawned. It is tied very closely with the kernel and contains many low-level calls to it. The field system also contains a self-contained bytecode language called commonly called "Field Script". The field module is responsible for the following:
- The loading and parsing of the field files
- The display of the 2D background ands related special effects
- The display of 3D elements in the field such as the camera, perspective and and entities
- The running of the Field Script to display events and to get user input
- The on-demand loading of other modules when needed
The Field module loads modular "Field Files". In the PC version, the Field File is a single file with nine sections. In the PSX version, there are three files with the same name but with different extensions that do the same thing. The three files are MIM (Mutiple Image Maps, or the backgrounds), DAT (Field Script Data), and BSX (3D data).
The backgrounds are actually 16x16 blocks that are loaded into VRAM and then assembled into the video buffer every frame. The system allows for layers to obscure the 3D entities using a simple painter's algorithm.
In this particular field file, there are six cached sections of background data. Also notice the bright green patches that don't show up in in the video buffer. This was to show where a lower layer of 2D data was to be covered by a higher layer. The bright green is for debug purposes. During development, if any bright green showed up, it meant that your upper layer had a "hole" in it that a 3D entity could be seen through.
When the PSX version of FF7 is ran in higher resolutions via emulation with texture filtering on, often the lower layers will "bleed" outside the upper layer and make artifacts. This was also the reason why the field files were not re-rendered for the PC version of the game. It would of required "re-cutting" the layers again in the higher resolution.
Another last thing to note is in the middle of the bottom texture cache there are a sea of eyes. These blink at random times and reflect the random blinking of the characters in the game.
Field Format (PC)
General PC Field File Format
Field files are always found in FLEVEL.LGP. They are always LZS compressed.
The first two bytes of each (decompressed) field file are blank (zero). The next four bytes is an integer indicating how many sections are present in the file. Then a number of 4-byte integers follow, giving the starting offset for each section.
All field files should contain 9 sections; it's what FF7 expects.
PC Field File Header
Offset | Size | Description | Section Data |
---|---|---|---|
0x00 | 2 bytes | Blank | Always 0x00 |
0x02 | 4 bytes | Number of Sections | Always 0x0009 |
0x06 | 4 bytes | Pointer to Section 1 | Field Script & Dialog |
0x0A | 4 bytes | Pointer to Section 2 | Camera Matrix |
0x0E | 4 bytes | Pointer to Section 3 | Model Loader |
0x12 | 4 bytes | Pointer to Section 4 | Palette |
0x16 | 4 bytes | Pointer to Section 5 | Walkmesh |
0x1A | 4 bytes | Pointer to Section 6 | Unknown |
0x1E | 4 bytes | Pointer to Section 7 | Encounter |
0x22 | 4 bytes | Pointer to Section 8 | 3D & Walkmesh-related |
0x26 | 4 bytes | Pointer to Section 9 | Background |
0x2A | 4 bytes | Where Pointer to Section 1 points to | Length of Section 1 |
0x2E | Varies | Start of Section 1 data. Continues for the number of bytes specified in Section Length |
See links above |
Each section generally starts with a four byte integer indicating the length of the section. You could just work this out by comparing offsets (how much space until the next section/end of file, etc) but FF7 stores the length at the start of the section anyway. After that the actual data follows. So the first bit of data for a section is actually 4 bytes after the point given in the section header (since the first four bytes are actually the length marker).
To examine each section, please navigate using the links in the table above.
Field Format (PS1)
PSX DAT Format
The PSX script is contained in the DAT file, it is compressed with LZS compression.
The header for the DAT file (after it is decompressed), is 28 bytes in size (they are used in the PSX, it's a list of 7 long word values which point to locations in PSX RAM). So for each of these sections are addressable by taking the first memory location subtracting it and adding 28.
There are 7 sections each coresponding to the first 7 memory locations at the begining of the file.
Section Name | Section Information |
---|---|
Script | Contains conversations, save point interaction etc. |
Walkmesh | Contains walkmesh triangles and access info. |
TileMap | Contains the information for the background, animation, and static scene objects. |
Camera_Matrix | Contains camera info. |
Triggers | Contains triggers, singles, gateways and so on. |
Encounters | Battle Encounter information for location. |
PSX MIM Format
Part of the PSX background data is contained in the MIM file, it is compressed with LZS compression. It consists of palettes (256 color ones) and screen blocks. No data for locating the blocks on the screen is in this file. The MIM file is a truncated TIM file and contains the normal clut location height and width information. This information is directly loaded into the PSX video ram to be decoded by the field module. The structure begins with the
MIM Header
typedef struct { UINT32 Header_Palette; UINT16 PalX, PalY; UINT16 PalWidth; UINT16 PalHeight; } MIMHeader;
which is followed by PalHeight number of
MIM Palette
typedef struct { UINT16 Palette[256]; } BGRPal256;
After the palettes comes the
MIM Block Header
typedef struct { UINT32 WordCount; // # words of data in image UINT16 ImageX, ImageY; // location of blocks on 1024x512 display area UINT16 Width, Height; // Width is the # of Word units (UINT16) the blocks are wide } MIMBaseImage;
lastly the actual block data for display follows. The palettes are selected from information in the DAT section 3 data.
PSX BSX Format
The Field models are contained within this file, it is compressed with LZS compression. FIELD.TDB contains the textures for these models. The format is similiar to the Playstation Battle Model.
PSX BCX Format
The individual characters field models are stored in BCX files, there textures are also in FIELD.TDB, they are compressed with LZS compression.
Event Scripting
Script commands
The event scripting language for FF7 has 246 commands that have a wide array of functions. For a complete listing of the commands, opcodes, arguments and descriptions, please refer to the opcodes section.
Movies
The 3D Overlay
Data Organization
"A" Field Animation Files for PC by Mirex
Each animation file holds one character animation ( run, walk or some other). Some characters have more animation files. Animation is set of frames, in each frame are stored bone rotations.
-- animation file contents --
Name | Size in bytes |
---|---|
header | 24 |
unknown | 12 |
frames | frames_count * frame |
-- one frame, size is (bones * 12 + 24) --
unknown 24 bytes = 6 floats rotations bones * 12 bytes = bones * 3 floats
Name | Size |
---|---|
unknown | 24 = 6 floats |
rotations | bones * 12 bytes = bones * 3 floats |
header structure, 24 bytes
struct { unsigned long x1; unsigned long frames_count; unsigned long bones_count; unsigned long x2, x3, x4; } anim_head;
I understand only two values from the header, 'frames_count' which is number of animation frames and 'bones_count' which is suprisingly number of animated bones.
If you want to load all possible animations for the model (even animations of different models) then check if animation file has same number of bones as current model.
After header there is 12 bytes of data that are unknown to me. It could be some center of the coordinate system or anything.
Frame starts with 6 floats (unknown), followed by rotations for each bone. Rotations are stored as 3 floats (float is 4byte floating-point number).