recursal/Fanatic-Fandom huggingface dataset:
FF7/Technical/Chocobo races

### Symptoms

In Gold Saucer, whenever I go to Chocobo Races my game crashes to Windows. I'm using Windows 2000 or XP.

### Causes

This is a very known problem caused by bad memory allocation. Game refers to pointer that doesn't exist in memory and Windows XP doesn't allow such operations.

### Solution

Eidos has no solution to this problem besides giving you Save so you can play further in-game. This can be fixed using Aali's OpenGL driver.

Back to Technical Problems page
FF7/Field/Script/Opcodes/AA MOVA

* Opcode: **0xAA**
* Short name: **MOVA**
* Long name: Move to Entity

#### Description

Moves the field object towards the entity with the given ID. Note that this is *not* a field object ID, in that the entity ID includes non-visible entities; in other words, this is an offset to an entity in the entire entity list, not just the visible entity list. However, attempting to move the field object to an entity that is not visible will fail, in that the MOVA opcode is ignored.
FF7/Field/Script/Opcodes/30 IFKEY

* Opcode: **0x30**
* Short name: **IFKEY**
* Long name: If Key Pressed

#### Description

Checks the status of a button being pressed; if pressed, regardless of the previous condition of the button press state (see IFKEYON / IFKEYOFF), the "if" body executes (that is, the script pointer is moved to the opcode after the current IFKEY). If the checked button fails the condition check, then the script pointer moves ahead *A* bytes.

The highlighted keys in the button ID table below do not quite act as the rest when used with this particular opcode. For these keys, IFKEY acts in the same manner as IFKEYON; these keys cannot be checked repeatedly, and the if statement body will only execute once, regardless of whether the key is being held down.

Button IDs can be ORd with each other to produce a combination of keys to check in one statement. For example, IFKEY with a key ID of 0x00F0 will check if any of the directional buttons are being pressed.
FF7/Field/Script/Opcodes/B6 DIRA

* Opcode: **0xB6**
* Short name: **DIRA**
* Long name: Direction to Entity

#### Description

Instantaneously directs the field object towards the entity with the given ID. As with MOVA, the entity ID is an offset in the entire entity list, and not into the visible object/entities list, and will also have no effect if a non-visible entity is given.
FF7/Field/Script/Opcodes/3B CHGLD

* Opcode: **0x3B**
* Short name: **CHGLD**
* Long name: Check Gil

#### Description

Copies the amount of gil the party has into the destination addresses. As the gil amount is a four-byte value, the arguments require two destination addresses to place two two-byte values into. Address 1 takes the lower two bytes of the gil amount, while address 2 takes the higher two bytes.
FF8/FileFormat MCH

Authors: Koral, JWP and Vehek

# MCH Field Character Models

Each MCH file contains a skinned-animated model representing a character on the field or world Maps. There appear to be multiple files of the same character representing differnt Level of Details.

They usually contain multiple TIM textures (standard PSX textures), mesh geometry, bones, skeleton heirarchy information and skinning information. The whereabouts of the Bone Animation data is currently unknown.

# MCH File Structure

## Header

```
0x100 bytes [256 bytes]

    DWORD: Offsets to multiple Texture-Data
        Start: 0x00
        Parse DWORDS until read value: 0xFFFFFFFF

    DWORD: Offset to Model Data

```

## Texture-Data

TIM format

```
(for each Texture)

    Standard [TIM] format textures

```

## Model-Data

```
    Skeleton Data: 0x40 bytes per bone, recurse through number of bones dictated in Header
    (for each bone)

        SHORT: parent bone (1-based)
        SHORT:   (unknown)
        DWORD:   (unknown)
        SHORT: bone length
        DWORD * 15:   (unknown)

```

```
    Vertex Data:
    (for each vertex)

        SHORT * 3: Vertex XYZ Position
        SHORT:   (unknown)
        DWORD * 4:   (unknown)

```

```
    Texture-animations Data:
struct
{
	byte unknown
	byte total_textures?
	byte unknown
	byte uSize
	byte vSize
	byte replacement_section_count
	UV_pair original_area_coords
	byte unknown[2]
	UV_pair replacement_coords[replacement_section_count]
};

```

```
struct face {
	u32 opcode; 0x07060125 = triangle, 0907012d = Quad
	BYTE unk[4];
	SHORT unknown; //When bit 0x04 is set, sets semitransparency
	BYTE unk[2];
	u16 verticies[4]; //vertex id's
	u16 verticies1[4]; //Edge data???
	u32 Vertex_Colours[4];
	TextureMap TextureData[4]; // TextureMap = u16 with the first byte = u and the second byte = v
	u16 Padding;
	u16 textureIndex;
	u32 padding[2];
	//64 bytes
};

```

```
    Unknown Data, Seems to split up the skin-objects, triangles, and quads:
struct
{
	uint16 start_skinobject_index
	uint16 skinobject_count
	byte unknown[12]
	uint16 start_triangle_index
	uint16 triangle_count
	uint16 start_quad_index
	uint16 quad_count
	byte unknown2[8]
};

```

```
    Skin-Object Data:
    (for each skin-object)

        SHORT: index of first vertex
        SHORT: number of vertices
        SHORT: Bone ID (1-based)
        SHORT:   (unknown)

```

todo: notes on skinning, animation data
FF7/Field/Script/Opcodes/97 DEC

* Opcode: **0x97**
* Short name: **DEC**
* Long name: Decrement (8-bit)

#### Description

Decrements the 8-bit value found at bank **B**, address **A**. If the value is 0x00, it will roll over to 0xFF. If you specify a 16-bit bank, only the lower byte will be decremented, and if the lower byte is 0x00, the higher byte will be unaffected whilst the lower byte will return to 0xFF.
FF7/Field/Script/Opcodes/36 WSPCL

* Opcode: **0x36**
* Short name: **WSPCL**
* Long name: Window Special (Numerical Display)

* **const UByte** *X*: X-coordinate of the numerical display, relative to the top-left of the window.
* **const UByte** *Y*: Y-coordinate of the numerical display, relative to the top-left of the window.

#### Description

Creates a numerical display inside the given window. The display can be either in the form of a clock, or a scoreboard with six digits. This only creates the numerical display; to actually show it, a MESSAGE or ASK command needs to be issued. Using a blank line of dialog will allow you to create a numerical display in the top-left of the window without field dialog hidden behind it. Alternatively, dialog can be shown along with the display by placing the display in an appropriate area of the window.

To set the time for the clock variant, STTIM is used. To set the number for the numerical display, WNUMB is used.

#### Display types

 1
 2
FF7/Field/Script/Opcodes/89 MUL

* Opcode: **0x89**
* Short name: **MUL**
* Long name: Multiplication (8-bit)

* **const UByte** *Dest*: The destination variable, to which the operand is multiplied.
* **const UByte** *Oper*: The operand, which is multiplied with the destination.

#### Description

Multiplies two numbers together and stores the result back into â€œDestâ€. The result of the Multiplication is capped at 255.
If the Source Bank is 0 then the the value â€œOperâ€ is multiplied with the destination value.
If the Source Bank is an 8 bit bank, then the â€œOperâ€ is the address in that bank where the operand is.
FF8/Variables

By Shard.

Game variables can be accessed using the PSHM family of script functions, and can be written to by using the POPM family of functions. Which one you use depends on the size of the variable.
The variables are all stored in save files, with the save block starting at address 0xD10 on uncompressed PC saves. The parameter to access a variable in the game scripts is basically the offset from this point in the variable block. For example, getting main story progress (word 256, which is word 0x100 in hex) just gets the two bytes starting at address 0xD10 + 0x100 = 0xE10. The varmap is continuous in memory while the game is running as well. In the en-US version of the original and SE releases (and likely most other versions), the varblock begins at 0x18fe9b8. You can use Cheat Engine table to track them as you play.

Items in grey are unused by field scripts (some of them may be used in battle scripts).

# Notes

1. 1. When the party splits in disc 2, each party member in the inactive party except Selphie has one of the eight bits changed for this variable. One member has a flag in the 4 most significant bits, and the other has a flag in the 4 least significant bits. It's done this way so that when the characters appear, they animate towards different locations in the field, rather than stacking on top of each other.
2. 2. This byte contains flags for which characters are in Squall's party when the party splits in disc 2.
3. 3. List of everything that 728 holds throughout the game:

* SeeD field exam "Conduct" score (lose points when you do something wrong at Dollet).
* Train job attempts (Timber)
* Tomb of the Unknown King student ID.
* Who you took to space in disc 3.

1. 4. The field controlling restriction unlocking in Ultimecia's Castle uses this to figure out where to jump the party after they've broken a seal. It's unknown how SETPLACE actually sets this, it's not always related to the field ID or the SETPLACE parameter. This variable is also set at Balamb Garden's front gate manually.:5. List of everything that 341 holds throughout the game:

* First flashback team
* Selphie's current action when escaping from Deling's mansion (changes the dialogue)
* FH Concert Crappiness
* Something in B-Garden classroom during the paratrooper attack.
FF7/TEX format

## TEX Texture Data Format for PC by Mirex (Edits by Aali)

FF7 PC texture consists of header, an optional palette and bitmap data. Usually data are stored like palletized picture, with bitmap pixels referencing to palette. Color 0 (in palette its usually black) is usually used as transparent color.

*Pixel values of 0 may or may not be transparent, depending on the color key status, more on that later. This also applies to non-paletted formats.*

When bit depth is 16 then data are stored as packed RGB in style RGB555, which means 5 bits per color in one 2 byte entry. I'm not sure if it is used in FF7 at all, its probably used in FF8.

*The tex format is actually very flexible and can take almost any non-paletted format as long as you describe it properly in the header.*

*Color keying: If the color key flag is zero, no color keying is performed and the color key array is ignored. Otherwise, the current palette index is used to retrieve a single byte from the color key array, this is the new color key flag, zero means don't do color keying.* If there is no color key array (and the color key flag is not zero), you should always color key.

*Reference alpha: Only applies to paletted images, if the alpha value sampled from the palette is 0xFE, this value should be replaced with the reference alpha.*
FF7/Field/Script/Opcodes/DA AKAO2

* Opcode: **0xDA**
* Short name: **AKAO2**
* Long name: Sound Operation (word param1)

#### Arguments

* **const Bit[4]** *B1*: Bank to retrieve *Param1*, or zero if *Param1* is specified as a literal value.
* **const Bit[4]** *B2*: Bank to retrieve *Param2*, or zero if *Param2* is specified as a literal value.
* **const Bit[4]** *B3*: Bank to retrieve *Param3*, or zero if *Param3* is specified as a literal value.
* **const Bit[4]** *B4*: Bank to retrieve *Param4*, or zero if *Param4* is specified as a literal value.
* **const Bit[4]** *0*: Zero.
* **const Bit[4]** *B6*: Bank to retrieve *Param5*, or zero if *Param5* is specified as a literal value.
* **const UByte** *Op*: Operation to perform.
* **const UShort** *Param1*: Parameter 1.
* **const UShort** *Param2*: Parameter 2.
* **const UShort** *Param3*: Parameter 3.
* **const UShort** *Param4*: Parameter 4.
* **const UShort** *Param5*: Parameter 5.

#### Description

Perform an operation described by *Op*, and uses the parameters depending on the operation.

Opcode list
FF7/Field/Script/Opcodes/E0 BGON

* Opcode: **0xE0**
* Short name: **BGON**
* Long name: Background On

#### Arguments

* **const Bit[4]** *B1*: Bank to retrieve *A*, or zero if *A* is specified as a literal.
* **const Bit[4]** *B2*: Bank to retrieve *L*, or zero if *L* is specified as a literal.
* **const UByte** *A*: The ID of the background area to manipulate, as specified in the background's sprite.
* **const UByte** *L*: The ID of the layer of *L* to display (turn on), as specified in the background's sprite.

#### Description

Turns on the portion of background whose background sprite belongs to the scripted area and state specified.

Parts of the background image (or more accurately, specific sprites) may be assigned a "scripted area" that allows control over that portion of the background by the scripting system. Within each scripted area, backgrounds are drawn on top of each other in layers, on the same location; these can represent a door in both open and closed states, for example, allowing the script to switch between an open door when a trigger is crossed and a closed door otherwise by simply turning off the "closed door" background and turning on the "open door" background.
FF7/Field/Script/Opcodes/52 WMODE

* Opcode: **0x52**
* Short name: **WMODE**
* Long name: Window Mode

#### Description

Changes properties associated with the WINDOW whose ID is specified. The mode byte sets the style of the window, as detailed below. If the final byte is set to 1, the window cannot be closed by the player pushing [OK].

The mode of the window should be changed before it is displayed with MESSAGE or ASK, or the changes will not be visible unless the window is closed and reopened.

#### Mode Table

 1
 2
FF7/Field/Script/Opcodes/CC IFMEMBQ

* Opcode: **0xCC**
* Short name: **IFMEMBQ**
* Long name: If Party Member Available

#### Description

Checks whether the character, given as the first argument, is globally enabled; that is, the character has been enabled using MMBud. If so, the script immediately following this opcode and argument list will execute; otherwise, the script pointer is advanced by the second argument and execution continues.
FF7/Field/Script/Opcodes/24 WAIT

* Opcode: **0x24**
* Short name: **WAIT**
* Long name: Wait

#### Description

Pauses current script execution for a specific amount of time. Rather than a specific time value in milliseconds/seconds, the amount specifies the number of frames that must be drawn before execution resumes. Since the game runs at 30fps, WAIT(0x1E) (or WAIT(30) in decimal) will pause script execution for 1 second, WAIT(0x96) will pause for 5 seconds, and so on.
FF7/Field/Script/Opcodes/68 SCR2DL

* Opcode: **0x68**
* Short name: **SCR2DC**
* Long name: Scroll to Coordinates (Linear)

#### Arguments

* **const Bit[4]** *B1*: Source bank 1, or zero if *X* is set as a constant value.
* **const Bit[4]** *B2*: Source bank 2, or zero if *Y* is set as a constant value.
* **const Bit[4]** *0*: Zero.
* **const Bit[4]** *B4*: Source bank 3, or zero if *S* is set as a constant value.
* **const Short** *X*: X-coordinate to scroll to.
* **const Short** *Y*: Y-coordinate to scroll to.
* **const UShort** *S*: Speed to scroll; higher values scroll more slowly.

#### Description

Similar to SCR2D, except the scroll to the coordinates is linear; that is, the speed is constant throughout the duration of the screen scroll.
FF7/Field/Script/Opcodes/00 RET

* Opcode: **0x00**
* Short name: **RET**
* Long name: Return from request / Halt

#### Description

When an entity's script is being executed as part of a request (function call), the return opcode will cause current execution to halt and return to whatever the entity was previously executing (at some lower priority). If the execution was requested via a synchronous call (REQEW or PRQEW), the completion of execution is also signalled to the calling entity which can resume execution.

If *return* is used when executing at base priority, execution will simply halt. This is what happens in the entry scripts.
FF7/Field/Script/Opcodes/8B DIV

* Opcode: **0x8B**
* Short name: **DIV**
* Long name: Division (8-bit)

#### Description

Divides â€œDestâ€ by â€œDenâ€ and stores the result back into â€œDestâ€. The result of the division is rounded towards zero to the nearest integer.
If the Source Bank is 0 then the â€œDenâ€ is the denominator.
If the Source Bank is an 8 bit bank, then the â€œDenâ€ is the address in that bank where the denominator is.
FF7/Field/Script/Opcodes/0F SPECIAL/F5 POINT

* Opcode: **0x0FF5**
* Short name: **SPECIAL: ARROW**
* Long name: Special: Arrow Switch

#### Description

Turns on or off the *availability* of the hand pointer that hovers above the playable character's head; this does not do the same as pressing the Assist button, but rather toggles whether the hand will appear when the user has the hand and arrows set to display. Other indicators that are available, such as the red/green arrows that are turned on or off along with the hand pointer, are not affected by this sub-opcode.
FF7/Field/Script/Opcodes/A1 CHAR

* Opcode: **0xA1**
* Short name: **CHAR**
* Long name: Character definition

#### Description

Defines a character, or rather, a visible entity. This means that the entity executing this opcode can be associated with a field object, and thus displayed on the walkmesh, as defined in Section 3.

#### Notes

Note that the character ID does *not* provide an index into the field object array as you might expect. Infact, the field object that this CHARacter will use is related solely to the position of this entity amongst the other visible entities in the set. For example, if you have the following entities and objects loaded:

* Ent1 (Visible, CHAR (00))
* Ent2 (Visible, CHAR (01))
* Ent3 (Visible, CHAR (02))
* Ent4
* FObject1
* FObject2
* FObject3

Ent1 will be associated with FObject 1, Ent2 with FObject 2, and Ent3 with FObject3. If you were to edit as such:

* Ent1 (Visible, CHAR (60))
* Ent2 (Visible, CHAR (12))
* Ent3
* Ent4 (Visible, CHAR (FF))
* FObject1
* FObject2
* FObject3

Ent1 will be associated with FObject 1, Ent2 with FObject 2, and Ent4 with FObject3. As you can see, the argument provides no information as to which object to use. Simply put, as each CHAR entity is read, the next sequential field object in the loader is assigned to it.
FF7/Field/Script/Opcodes/07 RETTO

* Opcode: **0x07**
* Short name: **RETTO**
* Long name: Return To

#### Arguments

* **const Bit[3]** *P*: The priority at which we want to execute the remote script (high 3 bits of byte).
* **const Bit[5]** *F*: The ID of the specific member function of the currententity to be executed to (low 5 bits of byte).

#### Description

Gives script control to another script within the current entity, selected by *F*.
FF7/Field/Script/Opcodes/9B HBYTE

* Opcode: **0x9B**
* Short name: **HBYTE**
* Long name: High Byte

* **const UShort** *SA*: Source address, *or* the word given as a literal, if source bank is zero.

#### Description

Retrieves the high byte of a two-byte word from the source bank and address, and places the byte value into the destination bank and address. If the source bank is zero, then the final two arguments are actually a given two-byte word value, and the high byte value is retrieved from this word instead of from a memory address.
FF7/Field/Script/Opcodes/8D MOD

* Opcode: **0x8D**
* Short name: **MOD**
* Long name: Modulus (8-bit)

* **const UByte** *Dest*: Contains the nominator of the division and receives the remainder.
* **const UByte** *Den*: The denominator of the division.

#### Description

Divides â€œDestâ€ by â€œDenâ€ and stores the remainder back into â€œDestâ€.
If the Source Bank is 0 then the â€œDenâ€ is the denominator.
If the Source Bank is an 8 bit bank, then the â€œDenâ€ is the address in that bank where the denominator is.
FF7/Field/Script/Opcodes/A6 XYI

* Opcode: **0xA6**
* Short name: **XYI**
* Long name: Place Object (No Z)

#### Arguments

* **const Bit[4]** *B1*: Bank to retrieve *X*, or zero if *X* is specified as a literal value.
* **const Bit[4]** *B2*: Bank to retrieve *Y*, or zero if *Y* is specified as a literal value.
* **const Bit[4]** *B3*: Bank to retrieve *I*, or zero if *I* is specified as a literal value.
* **const Bit[4]** *0*: Zero.
* **const Short** *X*: X-coordinate of the field object, or address of X-coordinate if *B1* is non-zero.
* **const Short** *Y*: Y-coordinate of the field object, or address of Y-coordinate if *B2* is non-zero.
* **const UShort** *Z*: Triangle ID, or address of ID if *B3* is non-zero.

#### Description

Similar to XYZI, but does not specify a Z-coordinate. This lack of Z-coordinate may be a problem when placing the object on a mesh that has multiple Z-levels on the same X- and Y-coordinates.
FF7/Field/Script/Opcodes/C7 SOLID

* Opcode: **0xC7**
* Short name: **SOLID**
* Long name: Solid object

#### Description

Switches the solidity of the field object associated with this entity; that is, turns collision detection on or off. When off, the playable character will be able to walk through the entity's object, as if it were not there. This may be used for such objects as save points, where the character must be able to walk through the object to be able to access the save menu item.
FF7/Field/Script/Opcodes/E5 STPAL

* Opcode: **0xE5**
* Short name: **STPAL**
* Long name: Store Palette

* **const UByte** *Vram palette id*: Id of palette. All palettes stored starting from vram\_x = 0, vram\_y = 0x1e0, so this index is starting from vram\_y.
* **const UByte** *Palette array id*: All palette stored from in special array 0x20 size of each item. But it just index and can be used lo load full 256 colours (it just takes 0x10 slots of array).
* **const UByte** *Size*: Size of palette to copy + 1.

#### Description

Stores palette data to special array (0x80095de0 in english psx version).
FF7/Field/Script/Opcodes/04 PREQ

* Opcode: **0x04**
* Short name: **PREQ**
* Long name: Request party entity execution (asynchronous, non-guaranteed)

* **const Bit[3]** *P*: The priority at which we want to execute the remote script (high 3 bits of byte).
* **const Bit[5]** *F*: The ID of the specific member function of *PM* 's entity to be executed (low 5 bits of byte).

#### Description

Requests that the entity associated with a character in the current party executes one of its member functions at a specified priority. The request is asynchronous and returns immediately without waiting for the remote execution to start or finish. If the specified priority is already busy executing, the request will fail silently.
FF7/Field/Script/Opcodes/A9 CMOVE

* Opcode: **0xA9**
* Short name: **CMOVE**
* Long name: Move Object (No Animation)

#### Arguments

* **const Bit[4]** *B1*: Bank to retrieve X-coordinate, or zero if it is specified as a literal value.
* **const Bit[4]** *B2*: Bank to retrieve Y-coordinate, or zero if it is specified as a literal value.
* **const Short** *X*: X-coordinate, or lower byte specifying an address for the value if *B1* is non-zero.
* **const Short** *Y*: Y-coordinate, or lower byte specifying an address for the value if *B2* is non-zero.

#### Description

Similar to MOVE, but the field object won't play its animation whilst it moves. Field object will not be rotated according to movement (it will move without changing direction).
FF7/Field/Script/Opcodes/6C FADEW

* Opcode: **0x6C**
* Short name: **FADEW**
* Long name: Wait for fade

#### Description

Halts execution of the current script for a preceding FADE command, issued by any entity, to fully complete before continuing execution. If no FADE has been issued by any entity, or previous FADE calls have already completed, the FADEW call is ignored.
FF7/Field/Script/Opcodes/E2 BGROL

* Opcode: **0xE2**
* Short name: **BGROL**
* Long name: Background Roll

#### Arguments

* **const UByte** *B*: Bank to retrieve *A*, or zero if *A* is specified as a literal.
* **const UByte** *A*: The ID of the background area to roll, as specified in the background's sprite.

#### Description

Turns on the next numerical layer in the background area specified by *A*. For example, if background area 3 is currently set to display layer 1 for that particular area, a call to BGROL(0,3) will display layer 2 for that area. If an invalid layer is given, or the background rolls past the last layer for this area, no background is displayed by this opcode.
FF7/Field/Script/Opcodes/0F SPECIAL

* Opcode: **0x0F**
* Short name: **SPECIAL**
* Long name: Special Opcode (Multibyte sequence)

#### Description

Special is a multibyte opcode extension, mostly for game specific opcodes to FF7. The first argument specifies the type of operation and must be from the values listed below; the number of arguments after this must also match the number of arguments for the operation type.

#### Subcodes by Category

##### Kernel

```
F5 ARROW
F6 PNAME
F7 GMSPD
F8 SMSPD
FB BTLCK
FC MVLCK
FD SPCNM
FE RSGLB

```

##### Inventory

```
F9 FLMAT
FA FLITM
FF CLITM

```

#### Subcodes by Opcode

```
F5 ARROW
F6 PNAME
F7 GMSPD
F8 SMSPD
F9 FLMAT
FA FLITM
FB BTLCK
FC MVLCK
FD SPCNM
FE RSGLB
FF CLITM

```
FF7/Field/Script/Opcodes/70 BATTLE

* Opcode: **0x70**
* Short name: **BATTLE**
* Long name: Start Battle

#### Arguments

* **const UByte** *B*: Bank (16-bit) to retrieve the address of the battle ID, or zero if it is given as a literal value.
* **const UWord** *N*: Battle ID, or address to find ID if *B* is non-zero.

#### Description

This launches the battle module with whatever battle number is used in the argument, or the value retrieved from memory location *N* if *B* is non-zero. Battle 1, 2, and 999 (0x03E7) are debug battles.
FF7/Field/MIMfile

The MIM filestructure begins with the

```

which is followed by PalHeight number of

```

After the palettes comes the

   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.

Sometimes there is a second MIM Block:
FF8

# Contents

### History

Final Fantasy VIII came after the mega hit Final Fantasy VII, it in itself was a very successful game release for Square. For more on the history of Final Fantasy VIII read here. The Game Engine

* Final Fantasy VIII's Engine

### Details of the Game

* Final Fantasy VIII's Kernel
* Game variables used in scripting
* World map camera
* Battle encounters list
* String Encoding

### Media Formats

* Final Fantasy VIII PS1 media information.
* Final Fantasy VIII PC media information.
* Final Fantasy VIII Save data

# File Formats

### Battle files

* [X] Battle Fields
* [DAT] Battle Models
* Scene.out Battle encounter data
* r0win.dat Winning sequence
* b0wave.dat Core battle data (Textures+Music+Font)
* a9btlfnt.bft Battle Font (Redirect to TDW)
* .mag files - MAG files

### Field files

* Opcodes Field script opcodes
* [MCH] Field Character Models
* [ONE] Field Character Models Container
* [MIM] Field Background Image Data
* [MAP] Field Background Tile Data
* [JSM] Field Scripts
* [SYM] Field Script names (unused)
* [MSD] Field Dialogs
* [INF] Field Gateways
* [ID] Field Walkmesh (same format as FF7)
* [CA] Field Camera
* [TDW] Extra font
* [MSK] Movie cam (?)
* [RAT & [MRT]] Battle related
* [PMD] Particle Info
* [PMP] Particle Image Data
* [PVP] Unknown (often 0x0c000000, sometimes 0x0a000000 or 0x0b000000)
* [SFX] Indexes to Sound Effects (?)

### World map files

* music0.obj
* music1.obj
* music2.obj
* music3.obj
* music4.obj
* music5.obj
* rail.obj
* texl.obj
* wmset.obj
* wmsetXX.obj
* wmx.obj
* chara.one

### Main

* wm2field.tbl
* kernel.bin
* harata.cnf
* init.out
* namedic.bin

### Menu

* \*.sp1/\*.sp2
* mngrphd.bin
* mngrp.bin
* tkmnmes\*.bin
* mag\*.tex
* mngrp strings
* mngrp complex strings
* m00\*.bin and m00\*.msg
* areames.dc1
FF7/Field/Script/Opcodes/5D CMTRA

* Opcode: **0x5D**
* Short name: **CMTRA**
* Long name: Check Materia

#### Arguments

* **const Bit[4]** *B1*: Source bank 1, or zero if *T* is set as a constant value.
* **const Bit[4]** *B2*: Source bank 2, or zero if this unit of *AP* is set as a constant value.
* **const Bit[4]** *B3*: Source bank 3, or zero if this unit of *AP* is set as a constant value.
* **const Bit[4]** *B4*: Source bank 4, or zero if this unit of *AP* is set as a constant value.
* **const UByte** *B5*: Bank to store *A*.
* **const UByte** *T*: Type of materia to check, or source address 1.
* **const UByte[3]** *AP*: Amount of AP the checked materia must have, or source addresses 2, 3 and 4.
* **const UByte** *U*: Unknown.
* **const UByte** *A*: Address to store amount of materia found.

#### Description

Places the amount of materia with specified type and AP into the bank and address specified.

#### Important Note

This opcode is **not** implemented in the PC version of the game, nor used in the PlayStation version.
FF7

This is a Stub article. A Wiki version of Gears should go here. For more information, select the "discussion" tab above so we can best architecture the data. For those who want to start converting, download the Gears pdf Halkun 20:18, 5 Mar 2005 (CST)

## Contents

* History
* Engine Basics
	+ Parts of the Engine
	+ Generic Program Flow
* The Kernel
	+ Kernel Overview
		- History
		- Kernel Functionality
	+ Memory Management
		- RAM Management
		- VRAM Management
		- PSX CD-ROM management
	+ Kernel.bin
		- The KERNEL.BIN Archive
		- The KERNEL2.BIN Archive
	+ Low Level Libraries
		- PC to PSX comparison
		- Data Archives
			* BIN Archive data format
			* LZSS Archives
			* LGP Archives
		- Textures
			* TIM texture data format for PSX
			* TEX texture data format for the PC
		- File formats for 3D models
			* Model Formats for PSX
			* Model Formats for PC
* The Menu Module
	+ Menu Overview
	+ Menu Initialization
	+ Menu Modules
	+ Calling the various menus
	+ Menu dependencies
	+ The Save Game format
* The Field Module
	+ Field Overview
	+ Field Format (PC)
		- General PC Field File Format
		- PC Field File Header
		- File Section Details
	+ Field Format (PSX)
		- PSX DAT Format
		- PSX MIM Format
		- PSX BSX Format
		- PSX BCX Format
* The Battle Module
	+ Battle Overview
	+ Battle Mechanics
	+ Battle Field
	+ Battle Scenes (scene.bin)
		- Battle Scripts
	+ Battle Models (PSX)
	+ Battle Animation (PC)
* The World Map Module
	+ World Map BSZ model file format (PSX)
	+ World Map TXZ file format (PSX)
	+ World Map Script Engine
* Sound
	+ PSX Sound
		- Overview
		- INSTRx.DAT
		- INSTRx.ALL
		- AKAO frames
	+ PC Sound
* Technical Help
* Tools and patches
* Source Code Forensics
FF7/Field/Script/Opcodes/76 PLUS!

* Opcode: **0x76**
* Short name: **PLUS!**
* Long name: Saturated Addition (8-bit)

* **const UByte** *Dest*: The destination variable, to which the operand is added.
* **const UByte** *Oper*: The operand, added to the destination.

#### Description

Adds two numbers together and stores the result back into "Dest". The result of the addition is capped at 255.
If the Source Bank is 0 then the â€œOperâ€ is added to the destination value.
If the Source Bank is an 8 bit bank, then the â€œOperâ€ is the address in that bank where the operand is.
FF7/Field/Script/Opcodes/F9 MOVIE

* Opcode: **0xF9**
* Short name: **MOVIE**
* Long name: Play Movie

#### Description

Plays the movie previously defined by PMVIE. Note that further execution of the current script is halted until the movie has finished playing, and a playable character is still able to move whilst the movie is being played, so player movements may be frozen first. In addition, field music currently playing will continue to do so unless explicitly instructed otherwise.

Note that MOVIE removes the availability of the hand pointer above the player's head, even after the movie has finished playing. To re-enable it, use SPECIAL: POINT.
FF8/FileFormat JSM

By myst6re.

```
  scriptCount = entryPointEntity & 0x7F;
  label = entryPointEntity >> 7;

```

The entry points are sorted in order of execution (I guess), not in the order in which entities appear in the file.

When sorting entities, it will be always in that order:

1. Lines
2. Doors
3. Backgrounds
4. Other

To know what type of an entity, so we were just use their count.

### Entry point of each script

Each entry is 2 bytes with:

```
  position = (entryPointScript & 0x7FFF)*4;
  flag = entryPointScript >> 15;

```

The position is relative to *offsetScriptData*. The meaning of the flag is unknown, it appear always and only with door, location and background entities.
Last entry point is relative EOF

### Script Data

Each opcode is 4 bytes.

Opcode List
FF7/Field/Script/Opcodes/0A SPTYE

* Opcode: **0x0A**
* Short name: **SPTYE**
* Long name: Set Party From Memory

#### Description

Sets the current party, using the Character ID values found at the banks and addresses specified by the arguments. It is possible to retrieve from three different banks.

This is used to set a party back to the player's configuration after a certain event, that requires specific characters that have been set using PRTYE, has completed. An example would be the party being set to Barret only for the Dyne event/battle, and then returning the party back to the player's configuration before the Dyne event occurs.
FF8/String Encoding

# String Encoding

FF8 strings are converted to byte arrays.Char Table Some of which aligns to the grid of text in the texture if you -32 from the value. Some values are 1 byte = 2 characters, most are 1 byte = 1 character. There are also special bytes that use up 1-3 bytes.

## Special Bytes

These bytes are points where things are inserted or a change in formatting. Some just say to ignore this string unless the player unlocked something.
FF7/Field/Script/Opcodes/60 MAPJUMP

* Opcode: **0x60**
* Short name: **MAPJUMP**
* Long name: Change Field

* **const UByte** *D*: Direction the character will be facing on the next field, in the standard game format.

#### Description

Switches fields to the one indicated by *I*, and places the character at the coordinates and direction specified. This is an alternative to using a gateway, and can complement their usage as it allows for more than 12 gateways by simulating their behaviour through a LINE which, when crossed, executes a MAPJUMP.
FF7/Field/Script/Opcodes/19 IFUWL

* Opcode: **0x19**
* Short name: **IFUWL**
* Long name: If (Unsigned Word, Long Jump)

* **const UShort** *V*: Unsigned value to compare the retrieved value to, or address from the second bank of the value to retrieve, if *B2* is non-zero.
* **const UByte** *C*: Type of comparison to perform.
* **const UShort** *E*: Amount to jump if the comparison does not hold.

#### Description

This is similar to the IFUW opcode, but allows for a jump on comparison failure of more than 0xFF bytes.
FF7/Field/Script/Opcodes/57 SWCOL

* Opcode: **0x57**
* Short name: **SWCOL**
* Long name: Set Window Colour

#### Arguments

* **const Bit[4]** *B1*: Bank to retrieve *C*, or zero if it specified as a literal value.
* **const Bit[4]** *B2*: Bank to retrieve *R*, or zero if it specified as a literal value.
* **const Bit[4]** *B3*: Bank to retrieve *G*, or zero if it specified as a literal value.
* **const Bit[4]** *B4*: Bank to retrieve *B*, or zero if it specified as a literal value.
* **const UByte** *C*: Corner to set colour, or address to retrieve value if *B1* is non-zero.
* **const UByte** *R*: Red value of the corner, or address to retrieve red component if *B2* is non-zero.
* **const UByte** *G*: Green value of the corner, or address to retrieve green component if *B3* is non-zero.
* **const UByte** *B*: Blue value of the corner, or address to retrieve blue component if *B4* is non-zero.

#### Description

Sets the colour for a particular corner of the gradient used in windows for displaying text.

#### Corner ID

 1
 2
 3
FF7/Battle/Special Attack Flags

Attacks and Items can have additional Special Properties that Damage Calculation takes into account when applying damage. The storage of these bits is reversed from the standard way by having "0" if the effect is active and "1" if it is not.

The 0004 bit here causes darkness to halve the accuracy byte when the ability data is loaded. The fact that this bit is unset for all enemy attacks is the true cause of the infamous "darkness bug", likely the design intent
was to make this interaction configurable on a per-action basis, but then enemy actions were just never flagged. The other Unused ones don't seem to have any immediately obvious effect on damage calculation and they aren't used in any attack available to player or enemy. They are probably place-holders for temporary variables set during damage calculation.

## Attacks with Property 0002h

After testing this significantly, it cannot be determined what this effect is based on a visual inspection. Here is a complete list of attacks that have this property. No enemy exclusive attacks have it.

* Life
* Life2
* Confu
* Haste
* Slow
* Death
* Escape
* Remove
* Fire3
* Ice3
* Bolt3
* Quake2
* Quake3
* Bio3
* Demi3
* FullCure
* Ultima
* Choco/Mog
* Shiva
* Ifrit
* Ramuh
* Titan
* Odin
* Leviathan
* Bahamut
* Kjata
* Alexander
* Phoenix
* Neo Bahamut
* Hades
* Typoon
* Bahamut ZERO
* Knights of Round
* White Wind
* Big Guard
* Bad Breath
* Beta
* Aqualung
* Trine
* Magic Breath
* Pandora's Box
* Fat-Chocobo
* Gunge Lance

Things it doesn't do:

-Alter Camera Movement (this info seems to be in the animation)

-Affect Animations between single/multiple targets (although it looks like it should)

-Change damage infliction timing (individually or all at once)

-Alter Battle Timer for any character (this info seems to be in the animation)

NOTE: After going through and decompiling the executable for FFVIIPC, it does not look like this property is checked for. Neither does it check for the Blade Beam property. At one time this may have been the "use multi-target animation on multiple targets" flag, but the animation handles that now. Likewise, removing the Blade Beam property does nothing to the Blade Beam attack itself. It was likely replaced by Additional Effect 1Ah.
FF7/Field/Script/Opcodes/8A MUL2

* Opcode: **0x8A**
* Short name: **MUL2**
* Long name: Multiplication (16-bit)

* **const UByte** *Dest*: The destination variable, to which the operand is multiplied.
* **const SWord** *Oper*: The operand, which is multiplied with the destination.

#### Description

Multiplies two numbers together and stores the result back into â€œDestâ€. The result of the Multiplication is capped at 32767.
If the Source Bank is 0 then the the value â€œOperâ€ is multiplied with the destination value.
If the Source Bank is an 8 bit bank, then the â€œOperâ€ is the address in that bank where the operand is.
FF7/Field/Script/Opcodes/53 WREST

* Opcode: **0x53**
* Short name: **WREST**
* Long name: Window Reset

* Position and size, set by WMOVE, WSIZW, WROW or even the initial values set by WINDOW;
* Background type, set by WMODE;
* Numerical displays, set by WSPCL;
* Message parameters, set by MPARA and MPRA2.

The reset window has a position of approximately (5,5), with a width and height of approximately (0x130, 0x45).
FF7/Field/Script/Opcodes/0B GTPYE

* Opcode: **0x0A**
* Short name: **GTPYE**
* Long name: Get Party To Memory

#### Description

Retrieves the current party's Character IDs into the banks and addresses specified for each party member. It is possible to retrieve values into three different banks, one for each member.

This is used to store the player's party configuration before they are overridden for a special event that requires a specific character setup. The player's original party configuration can then be set back to its original setup using SPTYE.
FF8/FileFormat MAP

By Aali.

# MAP Files

MAP files contain data about the tiles used to draw the field background. There is no header, every 16 bytes of the file is one 16x16 tile from the MIM data, ending with the special signature 0x7FFF followed by 12 zero bytes.
To determine whether you're dealing with a type 1 or type 2 file, look at the MIM filesize, there is no obvious marker for type 2 in the MAP file.

## Tile format

### Type 1

Two signed 16-bit integers, X and Y relative to center (0, 0)

Another 16-bit value, probably a fixed-point representation of the Z coordinate (divide by 4096 to get a floating point value)

4 bits, which 128x256 texture to use, if you consider the MIM to be one big image, just multiply this value by 128 and add it to the source X coordinate

1 unknown bit, always 1 (except in ending.map)

3 bits, related to image deph. If < 4 there is two color indexes per byte (4-bit indexed), else there is one color index per byte (8-bit indexed)

1 Unknown byte, always 0 (except in ending.map)

6 unknown bits, always 0

4 bits specifying which palette to use, add 8 to this number to get the right palette from the MIM

6 unknown bits, always 15

2 bytes, source X and Y coordinates to sample the tile from

1 bit, always 0

7 bits, layer id

1 byte specifying which blend mode to use for this tile, 1 is additive blending, 2 is subtractive blending, 3 seems to be +25%, 4 seems to be the default (no blending) and 0 is unknown (elview1)

1 byte, background animation id

1 byte, animation state

### Type 2

X and Y, same as above

Source coordinates, both 16-bit this time

Possible Z coordinate

4 bits, which 128x256 texture to use, same as above

4 unknown bits (maybe same as above)

1 unknown byte, always 0

6 unknown bits, always 0

4 bits specifying which palette to use, add 8 to this number to get the right palette from the MIM

6 unknown bits, always 15

1 byte, background animation id

1 byte, animation state
FF7/Battle/Battle Field

Battle fields are simple 3d models drawed in 3d space.

They stored in directories STAGE1 and STAGE2. There are lzs archives that unpacked and loaded in PSX space 0x801590e4. Size of unpacked field must be less than 0x8d04. It consist from few concatenated files. First one is settings for field. Last one is texture. All others are meshes.

### Settings (first file)

0 - mesh with horisontal scrolling parts (field 47 - Corel Train Battle).
1 - normal static mesh.
2 - mesh with vertical scrolling parts (field 12 - Shinra Elevators).
3 - mesh with lifestream (field 4e - Final Battle - Sephiroth).
4 - mesh with rotating parts (field 39 - Safer Battle)
 1
FF7/Field/Script/Opcodes/8F AND

* Opcode: **0x8F**
* Short name: **AND**
* Long name: Bitwise AND (8-bit)

* **const UByte** *Dest*: Contains an operand of the bitwise AND and receives the result.
* **const UByte** *Oper*: The second operand of the bitwise AND.

#### Description

Performs a bitwise AND operation between "Dest" and "Oper" and stores the result back into "Dest".
If the Source Bank is 0 then the â€œOperâ€ is the operand to AND with.
If the Source Bank is an 8 bit bank, then the â€œOperâ€ is the address in that bank where the operand is.
FF7/Field/Script/Opcodes/A2 DFANM

* Opcode: **0xA2**
* Short name: **DFANM**
* Long name: Animate, Loop

* **const UByte** *S*: Speed the animation is played at. Higher numbers indicate slower animations.

#### Description

Plays the animation given by *A* at the speed *S*. The animation loops (plays, completes, then rewinds and plays again) until another animation is played, either using any animation opcode, or an opcode indirectly changes the animation being played, such as MOVE.
FF7/Field/Script/Opcodes/78 MINUS!

* Opcode: **0x78**
* Short name: **MINUS!**
* Long name: Saturated Subtraction (8-bit)

* **const UByte** *Dest*: The destination variable, to which the operand is subtracted.
* **const UByte** *Oper*: The operand to be subtracted from the destination.

#### Description

Subtracts "Oper" from "Dest" and stores the result back into "Dest". The result of the subtraction is capped at 0.
If the Source Bank is 0 then the â€œOperâ€ is subtracted from the destination value.
If the Source Bank is an 8 bit bank, then the â€œOperâ€ is the address in that bank where the operand is.
FF7/Savemap

### The Savemap

The following is the general save format for the game. This data excludes the header data that differs between the PSX and PC version. (PSX header is 512 Bytes, checksum @ 0x200) (PC header is 9 bytes, checksum @ 0x11) Note: For the *preview* descriptions below, changing these values does not change any in-game values. These are only used so a player can preview the data within the save file when viewing the Save menu.

## Save Item List

Each item in the item list is stored as a word value with the quantity, expressed as a 7-bit value, concatenated with the item's index, expressed as a 9-bit value between the range of 0-320. In Binary: QQQQQQQXXXXXXXXX Where X is the index and Q is the quantity. There are a total of 320 item slots in the save map and a total of 320 objects that are stored there, some of which are dummy items. The objects are indexed like this:
 Indexes 0 - 127: Items
 Indexes 128 - 255: Weapons
 Indexes 256 - 287: Armors
 Indexes 288 - 319: Accessories
 Quantity is limited (by the menu mechanics) to 99 since there are only two characters available in the item menu to show quantity. A Graphical "glitch" occurs in the ten's digit when quantity exceeds that number. The menu only checks the current quantity to determine if the value can increase and the quantity will not decrease unless an item is used or sold. Forcing the quantity to exceed 99 does not have any side effect with most versions of the game. The Japanese PSX version(BISLPS-00700) is the only version with a problem when you exceed a quantity of 99 for an item. This version will experience an error during battles when you have more then 99 of an item.

## Save Materia List

Materia is stored as a single-byte ID followed by the amount of AP on that instance of Materia stored as an unsigned 24-bit integer.eskill materia does not use the ap value, but instead the 24 bits as switches for each skill that can be learned. For every materia ap =0xFFFFFF when mastered

## KERNEL.BIN Section 4 Entry

During game initialization, section 4 from KERNEL.BIN is decompressed and copied into RAM. This is all the initial values and structure for most of the Save, excluding the header data and the tail of the last bank (0x0054 to 0x0B93).

## Documentation Notes & Format

Format: Bit mask: Bit description [Hex byte value] {Field Keyword}
 Example: 0x04: Set to 1 if we choose no drink when talking to tifa. [0x0F] {MDS7PB\_1}

Note: We use LBS 0 bit numbering.

Bit description: What bit does.

Hex byte value: The Byte's value in hex when the bit change.(optional)

Field Keyword: Field name code.