Author Topic: Info about the field scripting language goes here.  (Read 28727 times)

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #25 on: 2004-07-16 21:47:37 »
First bit of info from FF7.exe mainly confirms Terence's findings about memory variable banks. The complete mapping is:

Code: [Select]
Code  Bank  Size
-------------------------------------------------------------------
0     -     -        (16-bit constant fetched from argument list)
1     1     8 bits
2     1     16 bits
3     2     8 bits
4     2     16 bits
5     temp  8 bits   (temporary variables)
6     temp  16 bits  (...)
7     5     16 bits
8     -     -        (unused, always returns zero when read)
9     -     -        (...)
A     -     -        (...)
B     3     8 bits
C     3     16 bits
D     4     8 bits
E     4     16 bits
F     5     8 bits

Any of these banks can be accessed by script commands, as long as the code nibble used to select the variable type is in one of the first three arguments. (e.g. the MINUS2 command uses two variable references, and uses the first argument to contain the two type codes)

Naturally, since variable references are 8-bit (the offset from the start of the bank, that is) while constants are 16-bit, script commands must take special care to support constant arguments (usually as the last argument where the final byte is either part of the constant or unused). It is thus not guaranteed that all commands support constant arguments.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #26 on: 2004-07-16 23:36:45 »
Quote from: Qhimm
First bit of info from FF7.exe mainly confirms Terence's findings about memory variable banks. The complete mapping is:

 [MAP SNIPPED]



I'm going to bed and I'm going to attempt to look at that with fresh eyes when I wake up. I'm not getting this whole code <-> bank thing at all.

I'm going to talk out loud, then go to bed. Let's take the following command.

set byte(50)[07]=14

In this case the [07] means code 7, which selects bank 5 at a "depth" of 16 bits.

It then writes 0x14 at +0x50 within bank 5.

So what's the difference than doing this?

set byte(50)[0F]=14

....

Wait, I have the sentax wrong. I guess I simply don't know how to read the opcodes... I've been playing with the ones that don't deal with memory at all, like BATTLE, PRTYP, GOLD+ and others like that. I think you tried to explain it above, but you started tossing around terms like "nybbles" (I honestly thought this term was made up hacker speak for the 4 bit upper/lower half of a byte. Even on an 8 bit 6502 you can't split a register in half, everything aligns on a 8 bit byte or 16 bit word.) The script dumps also align on 8 bit bytes and 16 bit words.

I guess the script dumper is displaying memory locations in a pretty unintuitive way. I'm used to seeing explicit memory address ($0000-$FFFF), "zero-page" offsets ($00-$FF), or immidatle accessors (LDA #10)

Could you use give me some examples on how I'm supposed to properly parse these things? Thanks....

Terence Fergusson

  • *
  • Posts: 262
    • View Profile
Info about the field scripting language goes here.
« Reply #27 on: 2004-07-17 00:53:50 »
Quote from: halkun
I'm going to talk out loud, then go to bed. Let's take the following command.

set byte(50)[07]=14

In this case the [07] means code 7, which selects bank 5 at a "depth" of 16 bits.

Don't look at the disassembled script for this.  Look at the *Op Codes* and associated data.  So what you really wanted to say was:

80 50 07 14, which becomes, properly:
set byte (5)[07] = (0)14

This means: Put the Constant 0x14 into the Byte at Offset 0x07 using ID 5 (which refers to the Temporary Bank and only dealing with bytes).

Quote from: halkun
So what's the difference than doing this?

set byte(50)[0F]=14

I believe you want for your example:
set byte (6)[07] = (0)14

This means: Put the Constant 0x14 into the Byte at Offset 0x07 using ID 5 (which refers to the Temporary Bank and only dealing with words).  Which... isn't exactly the most sensible of code... you don't *really* want to mix opcodes dealing with bytes and telling the script engines variable handling subroutine that you want to store it in a word.  Who knows what might be put into that spare byte?

Quote from: halkun
Wait, I have the sentax wrong. I guess I simply don't know how to read the opcodes... I've been playing with the ones that don't deal with memory at all, like BATTLE, PRTYP, GOLD+ and others like that. I think you tried to explain it above, but you started tossing around terms like "nybbles" (I honestly thought this term was made up hacker speak for the 4 bit upper/lower half of a byte. Even on an 8 bit 6502 you can't split a register in half, everything aligns on a 8 bit byte or 16 bit word.) The script dumps also align on 8 bit bytes and 16 bit words.

You're thinking about this too much.  If I want to check a single bit, do I use a command to *only* get that bit?  (Assume we're working in Assembler; the script engine has comparisons to check single bits)  No: I grab the whole byte and store it in one of the 4-byte registers, then I'll AND it with the bit I want to check, and then test it against 0.  It's the same with nibbles (which, yes, is another term for a half-byte, and is reasonably old in terms of when it was defined); I used it at the time because I thought it strange that, say: Random (05, 6D) and And (50, 6D, 01) would be associated with the same address.  It was only later that I was able to parse them as:
99 05 6D: Random (5)[6D]
8F 50 6D 01: And (5)[6D], (0)01

Quote from: halkun
I guess the script dumper is displaying memory locations in a pretty unintuitive way. I'm used to seeing explicit memory address ($0000-$FFFF), "zero-page" offsets ($00-$FF), or immidatle accessors (LDA #10)

Could you use give me some examples on how I'm supposed to properly parse these things? Thanks....

They're not that unintuitive.  See, the script doesn't *know* all the addresses.  It doesn't have nearly as much control you give it credit for.  It has, as we've stated, access to 5 main banks of permenant variables, and 1 bank of temporary variables.  (Please note: VARIABLES.  We are currently ignoring stuff like XYZI which are specific commands that FF7 will go and do its own business with.)  The permenant variables contain stuff that will be saved out in FF7's save file.  Stuff like the number of Chocobos you have, or the last time you fought at Fort Condor, or how many battles you've been in since the start of the game.  Temporary variables change and are reset from scene to scene and are used and thrown away as and when they're needed.

All you really have to know about the addresses is the following:

 B/W
(1/2)[xx]: Bank 1
(3/4)[xx]: Bank 2
(B/C)[xx]: Bank 3
(D/E)[xx]: Bank 4
(F/7)[xx]: Bank 5
(5/6)[xx]: Temporary Bank

The 5 Banks are sequential sets of 256 addresses, and in v1.0, they start at 00DB1EC4 in memory, which starts with the Plot Progression Variable I've made note of several times.

The Temporary Bank is a set of 256 addresses that start at 00CB2B80 in v1.0, and are reserved for the script engine's use alone.

To put it simply: the scripts are interpreted by FF7, and FF7 itself will eventually convert (2)[00] to Word(0x00DB1EC4) when it's asked by the script engine to grab that particular address.  Script writers are not expected to know exactly where in memory all this is going to eventually be placed... all they need to know is their offset from the start of the Global or Temporary areas.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #28 on: 2004-07-17 13:45:53 »
I've updated Gears with the FF7 save map, it's on page 12 under "menu" You can use it to help map out variables. It me know if I missed anything and if I need any corrections.

You know, I wonder of those banks arn't object conatiners.

For example the original code was something like Chocobo::slot_1::Intelligence==100

or If Character::Cloud::Vitality==21 then jump :label3

The bank is "Character" and the offset is handeled by the script compiler, (or even a hand ful of #define)

It would be easier when the save map is mapped to the banks...

Cyberman

  • *
  • Posts: 1572
    • View Profile
Info about the field scripting language goes here.
« Reply #29 on: 2004-07-18 16:59:59 »
Quote from: halkun
I've updated Gears with the FF7 save map, it's on page 12 under "menu" You can use it to help map out variables. It me know if I missed anything and if I need any corrections.

You know, I wonder of those banks arn't object conatiners.

For example the original code was something like Chocobo::slot_1::Intelligence==100

or If Character::Cloud::Vitality==21 then jump :label3

The bank is "Character" and the offset is handeled by the script compiler, (or even a hand ful of #define)

It would be easier when the save map is mapped to the banks...

Judging from the way things are being handled in terms of 'functions' within the script I would say you might be closer to the truth.  Perhaps the 'global' values are really values within the game object and each character object has a set of associated variables, such as the 'love points' for example. I wonder if these are less global and more object oriented.  Or I could be completely wrong (wouldn't be the first time).

Cyb

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #30 on: 2004-07-18 19:13:58 »
Script values are definitely not object-oriented, at least not on any visible level. As for the rest of the save block (and probably most of the game), a certain level of object-oriented thinking exists, but mostly its just POD (plain-old-data) structs.

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #31 on: 2004-07-22 00:41:28 »
Right it's a double-post, but they're completely unrelated and separated by a lot of time so it's warranted.

A question for people who have actually been looking at the FF7 scripts... are there any scripts that use the DM_TRA or CM_TRA commands? (delete materia and check materia, respectively)

The reason being that in the PC version, these commands are not implemented. But since no one has complained about any materia bugs, I'm speculating that the commands aren't actually used anywhere in the game... I'd like to confirm it though.

sfx1999

  • *
  • Posts: 1142
    • View Profile
Info about the field scripting language goes here.
« Reply #32 on: 2004-07-22 04:31:53 »
CM_TRA might be used for that one timer for that underwater battle.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #33 on: 2004-07-22 11:39:57 »
I don't think the game ever removes materia. I've been diggin with MNU files as of late but I think all yuffie does is move the materia to an unaccessable part of memory.

When I finaly figure out the menu thing, I'll have to play with that.

Heck. I haven even started on the REQ opcodes, I'm kinda hoping because they are first, someone will beet me to it.... :P

Cyberman

  • *
  • Posts: 1572
    • View Profile
Info about the field scripting language goes here.
« Reply #34 on: 2004-07-23 03:08:28 »
Quote from: Qhimm
Right it's a double-post, but they're completely unrelated and separated by a lot of time so it's warranted.

A question for people who have actually been looking at the FF7 scripts... are there any scripts that use the DM_TRA or CM_TRA commands? (delete materia and check materia, respectively)

The reason being that in the PC version, these commands are not implemented. But since no one has complained about any materia bugs, I'm speculating that the commands aren't actually used anywhere in the game... I'd like to confirm it though.


DM_TRA and CM_TRA are those for removing/deleting materia?
Do we know exactly what these do?
They may have been for things that were never implemented in the game.  I know FF7 is incomplete and unused opcodes might be a good indicator of this.

Cyb

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #35 on: 2004-07-23 11:08:48 »
Quote from: Cyberman
DM_TRA and CM_TRA are those for removing/deleting materia?
Do we know exactly what these do?

I'm fairly sure they are the delete-materia-from-inventory and check-if-materia-exists-in-inventory commands. Even if the actual command is unimplemented, the forms are very similar to the ST-ITM, DL-ITM and CK-ITM commands (which add, remove and check for items in the inventory, respectively). Also, the SM-TRA commans is fully implemented, which adds materia to the inventory. DM-TRA and CM-TRA use the same type of arguments as SM-TRA, with small differences equal to those between ST-ITM and DL-ITM/CK-ITM.

All I can't figure out is what TRA stands for... :P

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #36 on: 2004-07-23 11:26:15 »
You *are* jotting down all these arguments..... right ^_^

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #37 on: 2004-07-23 12:08:04 »
Yes I am, dear. ^_~
I'm dumping all info on the commands I find into C++ header files for now, the plan is to incorporate them into a complete script viewer capable of presenting (and later editing) the script in an easily comprehensible manner. For example, replacing variable references like "14 56 1F 00" with "(1)[56], <2>[1F]" and replacing some command names to more descriptive versions, with (simplified) syntax and description denoted. The actual "hardcode" syntax can then still be easily retrieved from reading the C++ header files, even if you don't read C++ too well.

Terence Fergusson

  • *
  • Posts: 262
    • View Profile
Info about the field scripting language goes here.
« Reply #38 on: 2004-07-23 13:06:05 »
Quote from: Qhimm
All I can't figure out is what TRA stands for... :P


SM-TRA most likely stands for:

Set MaTeRiA.

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #39 on: 2004-07-23 13:17:13 »
Quote from: Terence Fergusson
SM-TRA most likely stands for:

Set MaTeRiA.

Ooh, that's clever that.  :D  I would've thought Store or Stock though, from the ST-ITM variant, but SeT is equally likely I guess. ^_^

Cyberman

  • *
  • Posts: 1572
    • View Profile
Materia.. versus items
« Reply #40 on: 2004-07-23 13:57:09 »
Since Items and materia aren't stored in the same data space, it might be a hold over.

That is they may have originally had SET REMOVE and GET Materia commands (obligatory nuisances), then removed them and rolled them into the ITEM code.  Now this brings up a bit of a problem, if materia is fetched using the item code how do the specify what the item is? Since Materia and item codes are completely different?

Cyb

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #41 on: 2004-07-23 14:25:34 »
Nonono, materia and items are still handled completely separately. Sorry for any confusion. All I'm saying is that the commands for the two share certain similarities. Now DM-TRA and CM-TRA are non-functional in the PC version. It's possible there's another command replacing them, but I haven't found one; probably the commands are just never used, and the developers didn't bother implementing them. That, or they just forgot :P

One point I figured the DM-TRA and CM-TRA commands would be used is when you touch the huge materia to replace your mastered materia with a Master Magic (or similar) materia. Probably there's a special command for that though, or it would have to rely on the dysfunctional ones...

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #42 on: 2004-07-23 18:03:54 »
Yea it's probably a SPECIAL() command that talks directly with the kernel.

That bad boy has 256 sub commands and it seems to be a bunch of hard-coded last minute commands that were put in because the opcode matrix was full.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Info about the field scripting language goes here.
« Reply #43 on: 2004-07-25 18:27:29 »
Quote from: halkun
Yea it's probably a SPECIAL() command that talks directly with the kernel.

That bad boy has 256 sub commands and it seems to be a bunch of hard-coded last minute commands that were put in because the opcode matrix was full.

Argh.. I hate when they do that, it reminds me of programing for microcontrollers the idiot designers didn't design with enough for thought.  I should shut up on that, I really want to strangle some engineers on ocassion, but then I am probably as guilty as they are!

So I suppose the big thing would be to document the SPECIAL matrix next then?

Cyb

Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Info about the field scripting language goes here.
« Reply #44 on: 2004-07-25 18:48:34 »
Quote from: Cyberman
So I suppose the big thing would be to document the SPECIAL matrix next then?

Yeah, I'll get on it right after I finish documenting those pesky REQ instructions...

Cyberman

  • *
  • Posts: 1572
    • View Profile
Info about the field scripting language goes here.
« Reply #45 on: 2004-07-25 19:09:26 »
Quote from: Qhimm
Quote from: Cyberman
So I suppose the big thing would be to document the SPECIAL matrix next then?

Yeah, I'll get on it right after I finish documenting those pesky REQ instructions...

Well I suppose I ought to start working on the script viewing stuff as well.  I have to rewrite my software almost completely (sigh) in some section.

The 'dumb' question where are the NAMEs you are giving this OPCODES coming from? Laysan3's script dumper? or are they listed someplace in FF7's various data files?

Cyb

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #46 on: 2004-07-25 20:24:07 »
They are coming from Lasyan3's script dumper, but Qhimm is renaming them.

I'm going to hold off on the field scripting bit till Qhimm's done with his side. However, I'm done with the MENU section of Gears, and I'm going to finish KERNEL tonight, after that, I'm going to move on to the FIELD section and flesh out the mechanics of that.

I'l also re-vamping the way I have my sections set up to improve readability. However, Openoffice can't export it's bookmarks into PDF format so I'm still looking for a soultion.

Maybe, when gears is done, some soul with Acrobat can put in the bookmarks for me.

lasyan3

  • *
  • Posts: 76
    • View Profile
Info about the field scripting language goes here.
« Reply #47 on: 2004-07-26 08:11:56 »
The names I've given to the opcodes are listed in the field.bin file of ff7 PSX. Here is the file, I think it will be useful :

[MOD: LINK REMOVED][/i]

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Info about the field scripting language goes here.
« Reply #48 on: 2004-07-26 12:07:42 »
Quote from: lasyan3
The names I've given to the opcodes are listed in the field.bin file of ff7 PSX. Here is the file, I think it will be useful :


Please don't post files from the game disk here. I'm pretty sure most everyone has a copy of FF7 for PSX. Saying that it's in Field.bin is enough for us to take a look for ourselves.

lasyan3

  • *
  • Posts: 76
    • View Profile
Info about the field scripting language goes here.
« Reply #49 on: 2004-07-26 20:17:11 »
I see. Sorry for the trouble.