Battlescript

General Information[edit]

Chrono Cross[edit]

(As with the fieldscript details, some parameters are probably reversed or otherwise messed up)

The first 0x10 bytes of a battlescript file appear to be mostly offsets within the file, perhaps the header, dialog, and the end of the file.

At 0x90 (counting those first 0x10 bytes), there's the 4-byte number of entities(?). Then there's the pointers to the scripts, 0x40 bytes per entity.

Entity 0 is a global script entity.
Entity 1-3 are for PC 1-3, Entity 4-(max-1) are for monsters (there can't be more than 6 monsters).
Entity max is unknown.

Script 0 of each entity is used for initializing purpose.
Script 1 is called frequently.
Script 2 is used when an entity is about to take an action, for ~PCs, maybe when they are confused.
Script 3 is used when the entity is killed.
Script 4 is called when the entity is attacked.

Reserved variables:
Pip evolution points
var[0x0004] green element points
var[0x0006] white element points
var[0x0008] black element points
var[0x000a] red element points
var[0x000c] yellow element points
var[0x000e] blue element points
These are stored at 0x712ac after the battle.

var[0x0020] - Global Last Attack. 00 - Physical. 01 - Element.
var[0x0022] - Global Last Attack / Element.
var[0x0024] - Global Last Target.

var[0x0026] - PC1 Last Attack.
var[0x0028] - PC1 Last Attack / Element.
var[0x002A] - PC1 Last Target.

var[0x002C] - PC2 Last Attack.
var[0x002E] - PC2 Last Attack / Element.
var[0x0030] - PC2 Last Target.

var[0x0032] - PC3 Last Attack.
var[0x0034] - PC3 Last Attack / Element.
var[0x0036] - PC3 Last Target.

var[0x0038] - 1st field color.
var[0x003A] - 2nd field color.
var[0x003C] - 3rd field color.

var[0x003E] - PC1 ID.
var[0x0040] - PC2 ID.
var[0x0042] - PC3 ID.

var[0x0044] - Monster1 ID.
var[0x0046] - Monster2 ID.
var[0x0048] - Monster3 ID.
var[0x004A] - Monster4 ID.
var[0x004C] - Monster5 ID.
var[0x004E] - Monster6 ID.

var[0x0052] is used to store last element color you used.
var[0x0054] - Battle Timer (int32)


(I have made the assumption below that battlescript and fieldscript commands with the same OP byte mean the same thing when this seems reasonable—frex, when they deal with simple variable arithmetic and have the same number of parameter bytes. I have not made that assumption for more complex commands such as model loading.)

  • 00 - Halt
  • 01 XX YY - Goto: Jump to offset YYXX in the fieldscript
  • 02 TT UU VV WW XX YY ZZ - Conditional jump (parameter functions not noted, but they are UUTT, WWVV, XX, ZZYY, and one of them controls the type of condition, e.g. >, ==, !=) Probably the same as Xenogears.
  • 05 XX YY - Call subroutine YYXX. Max stack depth is 4
  • 0A
  • 0B
  • 0D - Return from subroutine
  • 0E XX YY
  • 0F XX YY
  • 10 VV WW XX YY ZZ - Set variable WWVV to signed value YYXX (ZZ contains sign bits). If used for targeting purpose instead of 2B-byte, then 0x0001 - PC 1, 0x0002 - PC 2, 0x0003 - PC 3, 0x0008 - Enemy 1 Cast (defined in Monster.Init), 0x0016 - Enemy 2 Cast, etc.
  • 11 XX YY - Set variable YYXX to 1
  • 12 XX YY - Set variable YYXX to 0
  • 13 VV WW XX YY ZZ - Add signed value YYXX to variable WWVV (ZZ contains sign bits)
  • 14 VV WW XX YY ZZ - Subtract signed value YYXX from variable WWVV (ZZ contains sign bits)
  • 15 VV WW XX YY ZZ - OR nth bit of variable WWVV with value YYXX?
  • 16 VV WW XX YY ZZ - XOR nth bit of variable WWVV with value YYXX?
  • 17 XX YY - Increment variable YYXX by 1
  • 18 XX YY - Decrement variable YYXX by 1
  • 19 VV WW XX YY ZZ - AND variable WWVV with value YYXX (ZZ contains sign bits)
  • 1A VV WW XX YY ZZ - OR variable WWVV with value YYXX (ZZ contains sign bits)
  • 1B VV WW XX YY ZZ - XOR variable WWVV with value YYXX (ZZ contains sign bits)
  • 1C WW XX YY ZZ - Shift variable WWVV left by value YYXX (ZZ contains sign bits)
  • 1D WW XX YY ZZ - Shift variable WWVV right by value YYXX (ZZ contains sign bits)
  • 1E XX YY - Set variable YYXX to random value
  • 1F WW XX YY ZZ - Set variable XXWW to random multiple of ZZYY
  • 20 VV WW XX YY ZZ - Multiply variable WWVV by value YYXX (ZZ contains sign bits)
  • 21 VV WW XX YY ZZ - Divide variable WWVV by value YYXX (ZZ contains sign bits)[Not attested, but given that opcode 20 appears to match...]
  • 26
  • 2A - Present in every "Attacked" section. Deleting causes a freeze or stops enemy turns completely.
  • 2B VV WW XX YY ZZ - Select target YYXX (0x0000 - 1 Random PC, 0x0001 - All PC's, 0x0128 - Serge (used as target for TurnBlack by Solt&Peppor)) and set to variable WWVV. Don't know much about ZZ.
  • 2C - Hide battle interface
  • 2D XX YY - Set delay for YYXX (YY contains sign bits)
  • 2F WW XX YY ZZ - Sets variable XXWW to quantity of ZZYY color on field; 0x0 - Green, 0x1 - White, 0x2 - Black, 0x3 - Red, 0x4 - Yellow, 0x5 - Blue (ZZ contains sign bits)
  • 34 XX
  • 35 XX YY
  • 38
  • 39 XX
  • 3C XX YY
  • 3D XX YY - Set animation for "this" entity: YYXX is the animation index.
  • 55 WW XX YY ZZ - Pick a random Element: XXWW is the Element index, ZZYY is the target.
  • 56 WW XX YY ZZ
  • 57 XX YY - Store current enemy numbers in variable YYXX
  • 58 XX YY
  • 59
  • 5A XX YY ZZ
  • 5B XX YY ZZ
  • 5C XX YY ZZ
  • 62 WW XX YY ZZ - Dialog box position
  • 65
  • 66
  • 67 TT UU VV WW XX YY ZZ - Queue attack (attack type UUTT (0=physical, 1=Element, 3=Time Devourer good ending), WWVV - Attack Power (Probably, 0x0001 - Weak Attack, 0x0002 - Strong Attack, 0x0003 - Fierce Attack) for physical attacks, Element index for element attacks, target YYXX). Bit 0x20 on ZZ makes the targeting parameter an immediate; Bit 0x40 makes the attack type parameter an immediate.
  • 75 TT UU VV WW XX YY ZZ - Set variable UUTT to the (2-byte) content of address (WWVV + YYXX). The details are quite complex (see [1])
  • 76 TT UU VV WW XX YY ZZ - Inverse of 75 (set contents of address (WWVV + YYXX) to match variable UUTT)
  • 7A
  • 7B XX YY
  • 7C
  • 7D XX
  • 80 XX YY - Copy current number of ~PCs into variable YYXX
  • 82
  • 83 XX YY
  • 84 XX YY
  • 85 WW XX YY ZZ
  • 86 XX YY - Relates to camera targeting
  • 87
  • 89 UU VV WW XX YY ZZ
  • 8C XX YY
  • 8D NN PP QQ RR SS TT UU VV WW XX YY ZZ
  • 8E XX YY
  • 8F UU VV WW XX YY ZZ
  • 90 WW XX YY ZZ
  • 93
  • 96 XX YY - Makes target unvulnerable for all attacks except YYXX. Don't know much about YY, but 0xFF01 - Green, 0xFF02 - White, 0xFF03 - Black, 0xFF04 - Red, 0xFF05 - Yellow, 0xFF06 - Blue. For RoyalJelly it was 0x8004.
  • 97
  • A4
  • A6
  • A7 WW XX YY ZZ - Possibly a check for Pip's evolution
  • A9 XX YY ZZ
  • AB WW XX YY ZZ
  • AE WW XX YY ZZ
  • AF XX
  • B0 XX YY ZZ
  • B4
  • B2 XX
  • B3 XX YY ZZ
  • B5 XX YY
  • C0 WW XX YY ZZ
  • C5
  • C2 WW XX YY ZZ
  • C3 WW XX YY ZZ
  • C4 WW XX YY ZZ
  • C5 WW XX YY ZZ
  • E0 XX YY ZZ - Display dialogue (one of the parameters should be an offset into the script file)
  • E2 - Wait for dialogue

[1] Additional stuff about opcode 75: It's used for things like copying parameters for the enemy whose information starts at WWVV to a "current enemy" set. Interesting values for XX include 0x16 (HP) and 0xa2 (gold dropped)

The 3rd parameter seems to have 2 parts, the lower 9 bits are offset value for sure(0-511), the high bits are some sort of flags which I'm not sure currently (for example, different base address).

Values of the second parameter:

E0 ~ E2 read data from PC 1-3
E3 ~ E8 read data from an enemy
E9 read data from an slot determined by certain address

How to get the address for E9:

Check the address at 0xDDB30, go to that address + 0x10
There is another address there, go that that address + 0x83
The byte is the index you need, for example, if it is 3, then it stands for the first enemy, and so on.

From: Modification