øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1943.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexfb1b-2.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&board=8.140e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexfb1b-2.html.zxÄ%h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈà•¤^úOKtext/htmlISO-8859-1gzip@øÕ^úÿÿÿÿÿÿÿÿTue, 10 Mar 2020 23:58:20 GMT0ó°° ®0®P®€§²ð®Ã%h^ÿÿÿÿÿÿÿÿÍ*^ú FF6: AI Upgrade bug help

Author Topic: FF6: AI Upgrade bug help  (Read 2075 times)

Edrin

  • Ymir
  • *
  • Posts: 12
    • View Profile
FF6: AI Upgrade bug help
« on: July 07, 2014, 08:42:44 AM »
I'm in the process of creating a Monster AI Upgrade patch which will expand the script AI functionality and fully integrate 24-bit monster HP.

I have a couple potentially related problems I'm having trouble tracking down and I was hoping for a little insight.

Firstly, I have a problem where sometimes when my demo boss attacks (only when he attacks, never my own characters), occasionally, if I am in the middle of a menu, the menu borders remain correct, but the displayed text gets mixed up with other views:

The first image is the main menu, the second is the item screen, the third is the magic menu.

As far as I'm aware, there should only be a couple changes to the ROM running at this point. The first being the 24-bit monster HP patch, which I can't see anything that would cause a problem... secondly is this code:

Code: [Select]
PHX
LDA $11A7
PHA
PHP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
STZ $1E70,x
LSR A
ASL $11A7
BCC 02
STA $1E70,x
DEX
BPL F1
PLP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
SEC
SBC $1E70,x
DEX
BPL FA
PLX
STX $11A7
PLX
RTS

...which essentially allows for independent selection for moves to ignore 50%,25%,12.5%,6.25% defense. I can't find a problem with this either...

There are a couple custom targeting functions I created as well that I'm 99% sure have nothing to do with the glitch (since it stays within the parameters and RAM space of the current targeting functions), but I could be wrong.

The last, is the fact that I wrote code to allow the scripts to run both inside and after conditionals optionally allowing me to queue up a bunch of attacks per turn. I'm worried that maybe I'm getting an overflow problem that is crossing over into graphical data. In my testing it appears that the whole script runs before attacks actually start leading me to this hypothesis. Does anyone know more about how the script queues attacks and if this could cause any potential issues?

Come to think of it, I could probably test this by making a script that just does a ton of attacks every turn and see what kind of limits I can find. But there really doesn't seem to be any consistency to the problem happening. Also, the script normally only calls 2-4 attacks per turn with a few exceptions that I don't believe were the case when the glitch occured. It only happens with I'm navigating menus and only during the boss' attacks but I can't make it happen with any consistency...

...thoughts?


And my other problem happens when I use a custom script to change the music from the monster script. I have narrowed it down to this specific command, but not sure why it's happening. This is another glitch that happens when navigating menues... in particular, when I am moving from the menu to target selection via cursor. It essentially sets up the RAM variables then runs the same code that runs at the beginning of battle and when the theme changes to fanfare after battle. This glitch causes the game to essentially freeze. The music stops and before the new music starts I lose the ability to move the cursor and everyone just sits there.

Code: [Select]
LDA #$10 (16 = instrument set?)
STA $1300
LDA $B8 (load song ID from parameter byte)
STA $1301
LDA #$FF (Volume: FF = normal)
STA $1302
JSL $C50004 (Changes the music)
STZ $E9ED
RTS

TBH, I have not dug through the music code before and am not very familiar with it. Any help would be appreciated. Hopefully its as simple as pushing a few variables before the code and restoring them at the end.

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6: AI Upgrade bug help
« Reply #1 on: July 07, 2014, 10:09:46 AM »
Whoo boy, where do I begin...

Firstly, I have a problem where sometimes when my demo boss attacks (only when he attacks, never my own characters), occasionally, if I am in the middle of a menu, the menu borders remain correct, but the displayed text gets mixed up with other views:

The first image is the main menu, the second is the item screen, the third is the magic menu.
Other than "there is something wrong," there really isn't anything I could narrow down based on these screenshots. Any number of routines that execute could be an issue.

Quote
As far as I'm aware, there should only be a couple changes to the ROM running at this point. The first being the 24-bit monster HP patch, which I can't see anything that would cause a problem...
Quote
There are a couple custom targeting functions I created as well that I'm 99% sure have nothing to do with the glitch (since it stays within the parameters and RAM space of the current targeting functions), but I could be wrong.

The last, is the fact that I wrote code to allow the scripts to run both inside and after conditionals optionally allowing me to queue up a bunch of attacks per turn. I'm worried that maybe I'm getting an overflow problem that is crossing over into graphical data. In my testing it appears that the whole script runs before attacks actually start leading me to this hypothesis. Does anyone know more about how the script queues attacks and if this could cause any potential issues?
These statements seem to be conflicting with each other. First let's examine the code you did provide:

Code: [Select]
PHX
LDA $11A7
PHA
PHP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
STZ $1E70,x
LSR A
ASL $11A7
BCC 02
STA $1E70,x
DEX
BPL F1
PLP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
SEC
SBC $1E70,x
DEX
BPL FA
PLX
STX $11A7
PLX
RTS
Doing STX $11A7 is an issue. If you are storing damage, you want to store to $11B0 or $F0, preferably $11B0. It's also an issue because a bit of this is used to call displaying text when a spell hits. That code is at C2/3262. If you're shifting $11A7, this bit may be misread. You'll also want to make sure that $1E70-$1E73 are actually free in ram. I'm not sure they are, but I do know that there's a big range of free ram in the $1440-$14FF range.

Of course, this may not be the issue at all.

Quote
Come to think of it, I could probably test this by making a script that just does a ton of attacks every turn and see what kind of limits I can find. But there really doesn't seem to be any consistency to the problem happening. Also, the script normally only calls 2-4 attacks per turn with a few exceptions that I don't believe were the case when the glitch occured. It only happens with I'm navigating menus and only during the boss' attacks but I can't make it happen with any consistency...

...thoughts?
I have nothing I can provide here.

Quote
And my other problem happens when I use a custom script to change the music from the monster script. I have narrowed it down to this specific command, but not sure why it's happening. This is another glitch that happens when navigating menues... in particular, when I am moving from the menu to target selection via cursor. It essentially sets up the RAM variables then runs the same code that runs at the beginning of battle and when the theme changes to fanfare after battle. This glitch causes the game to essentially freeze. The music stops and before the new music starts I lose the ability to move the cursor and everyone just sits there.

Code: [Select]
LDA #$10 (16 = instrument set?)
STA $1300
LDA $B8 (load song ID from parameter byte)
STA $1301
LDA #$FF (Volume: FF = normal)
STA $1302
JSL $C50004 (Changes the music)
STZ $E9ED
RTS
This code specifically looks fine. Let's see the rest of this command to possibly narrow this one down.

Quote
TBH, I have not dug through the music code before and am not very familiar with it. Any help would be appreciated. Hopefully its as simple as pushing a few variables before the code and restoring them at the end.
I can safely tell you that there isn't much to bank C5, but what is there is a mess that is difficult to figure out. Nothing in there is going to be wrong, it's the setup leading to the call.

119 bugs fixed and counting.

Edrin

  • Ymir
  • *
  • Posts: 12
    • View Profile
Re: FF6: AI Upgrade bug help
« Reply #2 on: July 07, 2014, 12:26:51 PM »
Other than "there is something wrong," there really isn't anything I could narrow down based on these screenshots. Any number of routines that execute could be an issue.

Doing STX $11A7 is an issue. If you are storing damage, you want to store to $11B0 or $F0, preferably $11B0. It's also an issue because a bit of this is used to call displaying text when a spell hits. That code is at C2/3262. If you're shifting $11A7, this bit may be misread. You'll also want to make sure that $1E70-$1E73 are actually free in ram. I'm not sure they are, but I do know that there's a big range of free ram in the $1440-$14FF range.

Of course, this may not be the issue at all.

I probably should have commented on my code a little better...
Code: [Select]
PHX
LDA $11A7
PHA               (Backup special byte 3)
PHP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
STZ $1E70,x
LSR A            (half M/Def stat)
ASL $11A7    (shift Special 3 bit (4-7) into Carry)
BCC 02         
STA $1E70,x (Store current value)
DEX
BPL F1          (branch if all 4 bits haven't been checked)
PLP
LDA $3BB9,Y (Magic Defense)
BCC $0CD4   (Branch if concern MP or Magical damage)    
LDA $3BB8,Y (Defense)
LDX #$03
SEC
SBC $1E70,x (subtract stored values based on m/def percentages (0 for values when bit wasn't set))
DEX
BPL FA
PLX
STX $11A7    (restore Special byte 3)
PLX
RTS

This runs when the game would normally load defense. It exits the function with X intact and A set to a modified defense value. I backup special byte 3 since it gets used elsewhere and restore it at the end of the function. Special byte 3 is used to set how much defense to ignore.



I can safely tell you that there isn't much to bank C5, but what is there is a mess that is difficult to figure out. Nothing in there is going to be wrong, it's the setup leading to the call.

Yea, i figured out what I was missing. I'm not entirely certain exactly what it does, but it appears to stop the music and menu temporarily to make sure everything is clear for the C5 function.

Code: [Select]
INC $E9ED
INC $6284
LDA #$10 (16 = instrument set?)
STA $1300
LDA $B8 (load song ID from parameter byte)
STA $1301
LDA #$FF (Volume: FF = normal)
STA $1302
JSL $C50004 (Changes the music)
STZ $E9ED
RTS

I should have looked a bit more before posting this one.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FF6: AI Upgrade bug help
« Reply #3 on: July 08, 2014, 12:41:05 AM »
that's a lot of different changes to your ROM.  try making a separate patch for each one, and applying them one at a time to figure out the culprit.

The last, is the fact that I wrote code to allow the scripts to run both inside and after conditionals optionally allowing me to queue up a bunch of attacks per turn. I'm worried that maybe I'm getting an overflow problem that is crossing over into graphical data.

yeah, this sounds like quite a significant change.  can you elaborate on what you're doing, and why you're doing it?  why not just have the script issue a bunch of commands per turn, like you mentioned for your test scenario below?

Edrin

  • Ymir
  • *
  • Posts: 12
    • View Profile
Re: FF6: AI Upgrade bug help
« Reply #4 on: July 08, 2014, 06:30:40 AM »
that's a lot of different changes to your ROM.  try making a separate patch for each one, and applying them one at a time to figure out the culprit.

That's probably what I will end up having to do.

yeah, this sounds like quite a significant change.  can you elaborate on what you're doing, and why you're doing it?  why not just have the script issue a bunch of commands per turn, like you mentioned for your test scenario below?

Its implemented as a branching function to jump forward or backward in the script, by jumping over the "End if and reset targetting" you can continue running code after the conditional is closed. This helps me emulate "end if and continue", "else", and nested-ifs.

For example, in my demo boss, he has a few actions he takes when the party has such-and-such statuses, but I don't want him to ONLY respond to the party statuses, so I can have him perform those actions and continue with his normal script. Also, the boss is based on his FFXIV counterpart and uses phases and skill rotations, but because of the nature of FF6, I thought it would be too easy with a single set and thus he has a primary and secondary skill rotation which independently cycle (as they have a different number of moves in them). The move he performs each turn is based on a variable value that gets changed at the end of the script based on which phase he's in... so the moves and any other specifics are only scripted once and the variable changes (which are much shorter) can be scripted for each phase.

Here's a quick example from my boss script:

Code: [Select]
FC 0C 01 02    ; If variable VAR001 is less than to 2
FC 0D 01 01    ; If variable VAR001 is greater than or equal to 1
FB 11 04       ; Branch forward in script 4 bytes
FE             ; End If and reset targeting
FB 11 21       ; Branch forward in script 33 bytes
FC 15 03 00    ; If VAR003 has all the following bit cleared: 0
FC 17 4F 00    ; If target Back Row is valid, set it, and
E8             ; Landslide
FB 11 11       ; Branch forward in script 17 bytes
FE             ; End If and reset targeting
FC 14 03 00    ; If VAR003 has all the following bit set: 0
FC 17 4E 00    ; If target Front Row is valid, set it, and
E8             ; Landslide
FB 11 04       ; Branch forward in script 4 bytes
FE             ; End If and reset targeting
F1 52          ; Targeting: none
E8             ; Landslide
F9 00 03 00    ; VAR003 toggle bit: 0

This script is far from optimized, but it helps show what can be done with the code... The boss alternates hitting the front row and back row with Landslide every time the move counter equals 1, but since the fight is rotation based and we need to see if the skill has missed, I need to be able to get the skill text to appear and hit no one. The first set of conditionals checks to see if its time to use Landslide. If it is we run the code right after the conditionals which branches past the end-if and the branch that skips to the end of the code if VAR001 doesn't equal 1, essentially ending up being able to run more conditionals without having to close them all the first time one of them fails. There's also an example of using it to emulate an "else-if" statement if VAR003 bit 0 is cleared and the back row is valid... it sets up Landslide then skips past the script which checks for the bit being set and if the front row is valid.

...this is just a small example. The more nested if-statements you want, the more helpful the code becomes.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FF6: AI Upgrade bug help
« Reply #5 on: July 08, 2014, 12:14:47 PM »
ooh, very ambitious stuff.  i've thought for awhile that Nested IFs would be cool, but hell if i was gonna attempt it. :/  a computer science instructor would probably give you grief for "spaghetti code", but that beats writing some big parser/interpreter that has to do something like store states recursively.

Quote
For example, in my demo boss, he has a few actions he takes when the party has such-and-such statuses, but I don't want him to ONLY respond to the party statuses, so I can have him perform those actions and continue with his normal script.

something you can take advantage of in the normal game is that the failure of *any* If Test in an IF Block is enough to make things proceed afterwards like the whole block had been skipped.  take this pseudocode example:

-----
If real condition test
Fire
Ice
If BS-always-false condition test
End If

Bolt
-----

the "End If" isn't executed, per se, but found and branched past by the last failed IF, which means we don't exit the script.  anyway, thanks to Master ZED for this insight on script function.

Edrin

  • Ymir
  • *
  • Posts: 12
    • View Profile
Re: FF6: AI Upgrade bug help
« Reply #6 on: July 08, 2014, 01:45:54 PM »
I went ahead and released the Titan boss without having figured out the last graphic glitch. I'm hoping a myriad of testers will help me narrow down the source. It seems to pop up out of nowhere... But I've done a couple runs now without incident so I'm not worried about it messing up the experience too much. The real goal is to make the patch sans Titan for hackers to use.

Here's the link if you're interested in trying it out:
http://www.ff6hacking.com/forums/showthread.php?tid=2628
http://www.mediafire.com/download/uv40qztx8qtnykt/TitanEX.ips
*it uses a headered, expanded ROM.

Edrin

  • Ymir
  • *
  • Posts: 12
    • View Profile
Re: FF6: AI Upgrade bug help
« Reply #7 on: July 12, 2014, 07:04:15 AM »
It appears the glitch may have just been a bad special animation. I used one of the ones later on the list, not really thinking about it and got wrapped up thinking it was my code (who was I kidding? my code is awesome). The boss is pretty challenging if you've got time to try it out. Still would like it confirmed from a couple other testers that the glitch is gone. Thanks for the help.

Happy Hacking!