°Aslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2232.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index318d-2.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&board=17.40e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index318d-2.html.zxR9h^                    ╚рХддрOKtext/htmlISO-8859-1gzip0|╓др        Wed, 11 Mar 2020 01:21:47 GMT0є░░ о0оPоАз▓ЁоR9h^        ▄#др Quick Confirmation Question Re: AI Scripts

Author Topic: Quick Confirmation Question Re: AI Scripts  (Read 1541 times)

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Quick Confirmation Question Re: AI Scripts
« on: May 21, 2016, 09:38:10 PM »
I have a (hopefully) easy question for the community that I'd like some confirmation on regarding AI scripts.

FF5 allocates 0x654 bytes in RAM for each monster's AI script.  This seems a bit like overkill, since by my calculations the longest AI script is 0x12D bytes.  Is this calculation correct?  Are there any known exceptions?  If so, significant amounts of RAM in the game could be freed up by reducing the amount of RAM allocated.  For reference, AI scripts are loaded at approximated C2/404D, and the amount of RAM is at 4056.

samurai goroh

  • FF5 Hacker
  • *
  • Posts: 221
  • Gender: Male
    • View Profile
    • My page
Re: Quick Confirmation Question Re: AI Scripts
« Reply #1 on: May 21, 2016, 10:40:40 PM »
I  remember that Apocalypse (Azulmagia) had one of if the not the longest AI script in the game (which I guess is the one you mention). Necrophobia's battle script was also long IIRC.

Looking at my editor, the calculation seems to concur.
I'm the best in the universe! Just remember! [F-zero X]

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #2 on: May 22, 2016, 01:15:17 PM »
Yep, the two longest in my list are those two.  Talk about a waste of RAM!  I'll be working on a patch for this today.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Quick Confirmation Question Re: AI Scripts
« Reply #3 on: May 22, 2016, 01:49:28 PM »
curious how games differ..  FF6 just keeps the last four read bytes (the largest possible command size) of a script in RAM, digesting from ROM as needed.  plus, RAM is used for some helper values:
- four pointers (main script entry point, counterattack script entry, and a bookmark pointer for each).
- two bytes (bookmark sub-block index for main script and for counterattack script).

is there any reason FF5 copies the whole thing to RAM in the first place?  e.g. is there unpacking to be done?

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #4 on: May 22, 2016, 02:18:10 PM »
There doesn't appear to be any unpacking involved, but I'm still looking into it so I could be wrong.  It does save different parts to different offsets; the non-reaction block is saved to 4759, and the reaction block to 4A83, and separates out the different condition blocks.

[EDIT] Ugh, it looks like it does do some unpacking.  Looks like it's back to the drawing board for my timer hack.
« Last Edit: May 22, 2016, 03:38:20 PM by LightPhoenix »

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #5 on: May 24, 2016, 01:11:01 PM »
I dont know about other FF, but FFV is quite generous to RAM :D

As far as I know there is no unpacking. If you check my 'FFV Viewer'  I do all AI parsing directly from the ROM without any unpacking.

P.S. if you guys have accumulated knowledge about AI script that is not in Jorgur's doc please share, I hope at one point to have full AI parsing :D
« Last Edit: May 24, 2016, 01:47:16 PM by Squall »

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #6 on: May 28, 2016, 06:25:37 PM »
Sorry, I was a bit bummed out when I last posted. 

It's not unpacking per se, in that there's additional information extracted.  The AI script is read into memory in a specific way, and I suspect that changing this would be quite a bit of effort. 

In general (as I'm sure people know), the AI data is organized into two blocks - the nonreact block and the reaction block.  Within each block is a set of zero to ten condition/action (cnd-act) sets.  The game loads the AI script into memory in the following way:  First, the non-react block is loaded.  The four-byte conditions are stored at 4759,X (17 bytes/cnd).  The corresponding actions are stored at 4803,X (64 bytes/act).  X in this case is the index for each cnd-act set, starting at zero and incremented for each set, up to ten.  Next, the react block is loaded in a similar way to 4A83/4B2D.

Without going through each AI script and looking it over, I couldn't say if these offsets can be compressed at all.  I am particularly suspicious of the condition block saving - why does the game need 17 bytes to hold 4 bytes?  I'm a little skeptical that the action block really needs 64 bytes as well.  On first glance, I can't see any code that saves additional data to those structures.  Perhaps this is simply a relic of changing code, where there was more to the condition block and it got pared down to the four byte structure without getting the memory allocation changed.  It would be a big undertaking to check all of this, and while I might work on it as a side project, for now I'm willing to simply let it be and find other, smaller regions of free RAM to use.

As an aside, I believe I found a rare bug in the "If Target Status Set" condition.  At C2/287A, as part of checking the Dead status (201A bit 7) it also checks the target's HP.  However, instead of an ORA for both bytes of the word as is normally done, it ORAs the low bytes together.  Oops.  This results in a case where targets that have a HP multiple of #100 will be counted as dead for this check, even if they are not.  It's a one byte fix.

Jorgur

  • Moderator
  • *
  • Posts: 437
  • Gender: Male
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #7 on: May 29, 2016, 04:41:16 AM »
Quote
the AI data is organized into two blocks
I just want to point out that by my definition there can be more than two blocks per AI script. There can be several conditional non-react blocks and several different react blocks.

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #8 on: May 29, 2016, 06:08:43 AM »
Quote
the AI data is organized into two blocks
I just want to point out that by my definition there can be more than two blocks per AI script. There can be several conditional non-react blocks and several different react blocks.
Technically Jorgur is right - its possibly to have more then 2 block (I accept his definition of block: condition, separators, action part, End of Block - FE or FF). Logically LightPhoenix is right - there are 2 type of blocks - conditional and non-conditional (as others may call them react and non-react).
Although technically we may have more then 1 non-conditional, I have never seen more then one. It ends with FF regardless where it stands. Maybe that is why in some people's parsing they call it: default.
Since the game allocates space for 10 blocks non-conditional, LightPhoenix you may use the 9 of them for whatever you need (that is 9x17 + 9x64 bytes) :)

Quote
why does the game need 17 bytes to hold 4 bytes?
Because you may have up to 4 conditions and FE in the end. Each of this conditions are connected with logical AND. Personally I havent seen more then 2 in one block.

Quote
Perhaps this is simply a relic of changing code
I have the same feeling ... or changing of the idea :)

Jorgur

  • Moderator
  • *
  • Posts: 437
  • Gender: Male
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #9 on: May 30, 2016, 02:44:06 AM »
Quote
conditional and non-conditional (as others may call them react and non-react)
They are not actually the same things. A non-react block can be conditional or non-conditional.

Here is one example. The first block has a condition, the second block does not have a condition, but they are both non-react blocks.
Quote
Sucker 9FA0

12 if no females are alive
00
00
00
FE
AA Nothing
FE

00
00
00
00
FE
FD ---
F3  Set target:
18   single female
F0
FD ---
80  Fight
80  Fight
81  Specialty
FF
FF

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #10 on: May 30, 2016, 07:23:05 AM »
Squall stands corrected :D

Well it seems you are right, react & condition is not the same ... I always wonder why FF appear in a such illogical way. Now I understand its well placed. Ohh forget what I said in my previous comment!

Then my question is what is the difference between condition and react? Why some conditions are called simply condition while other are called react?
For example:
  01 if status of Target (Self) is :[Status] (Dead)
  0F react death
logically they are the same. Then why 01 is simply condition, while OF is reaction?

Jorgur

  • Moderator
  • *
  • Posts: 437
  • Gender: Male
    • View Profile
Re: Quick Confirmation Question Re: AI Scripts
« Reply #11 on: June 01, 2016, 02:50:17 PM »
Conditional blocks require the ATB counter of the monster to reach full before it is executed. React blocks are basically counter-attacks to certain actions.

Quote
01 if status of Target (Self) is :[Status] (Dead)
Once the ATB of the monster is full, it will check for death status and exectute the block.
Quote
0F react death
When death status is inflicted, the block will immediately execute.