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:
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.
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
RTSTBH, 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.