Users browsing this thread: 1 Guest(s)
Casting Spells Taught by Espers - RESOLVED!

#14
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
So I found myself working on this again...and I got 40% of the way there in the menu. It was not an easy road because while the concept of the solution was easy in retrospect, there were a lot of mental roadblocks on my end.

Thanks to seibaby I was able to isolate and reproduce the code that determined whether an Esper was equipped, so I was able to get the behavior to change based on that when I wasn't able to previously. However, isolating the change to the spells taught by the Esper was tough for several reasons. Unlike in C2, there was no existing function for me to either modify or use as a pattern, and it wasn't clear to me how to convert the Esper ID to a usable index. I did see the Esper data menu, but due to not understanding the code, I was under a mistaken impression that $4216 referred to the address of an actual item or slot ("Product") and not the multiplication product of the contents of two registers.

I went down a LOT of rabbit holes and dead ends to figure out what I need to accomplish. A smart person could have figured out in a few minutes, but no, I tried everything from cannabalizing my C2 code to trying to write a new function. I laughed when I realized all I had to do was multiply the Esper ID by 11 with the registers to get the needed offset.

The good news is that since this is done, the next 40% -- getting the spell to appear when pressing Y -- should be trivial, but the last 20% is going to be a problem as I still have no idea how to get Gogo to check the Espers for the other actors.

Anyway, I present the C3 code for you below to laugh at:

Code:
C3503E:        4C91F0            JMP $F091       ;Jumps to the new code


C3F091:        48            PHA        ;Push everything to the stack, just in case
C3F092:        DA            PHX        ;Push everything to the stack, just in case
C3F093:        5A            PHY        ;Push everything to the stack, just in case
C3F094:        20DD4E            JSR $4EDD    ;Sets up the retrieval of the Actor's Esper
C3F097:        B91E00            LDA $001E,y    ;Loads the actor's Esper in A
C3F09A:        302A            BMI $F0C6    ;Value will be negative if no Esper, branch to code leading back to regular code
C3F09C:        20EC50            JSR $50EC    ;Get spell in slot
C3F09F:        C9FF            CMP #$FF    ;If there is no spell in slot, process like normal
C3F0A1:        F023            BEQ $F0C6    ;Branch to code leading back to regular code
C3F0A3:        48            PHA        ;Pushing the spell ID to the stack
C3F0A4:        20DD4E            JSR $4EDD    ;Sets up the retreival of the esper again...yes, this is likely redundant
C3F0A7:        B91E00            LDA $001E,y    ;Loads the actor's Esper in A
C3F0AA:        8D0242            STA $4202    ;Stores A in a register designated for multiplication
C3F0AD:        A90B            LDA #$0B    ;Sets A to 11
C3F0AF:        8D0342            STA $4203    ;Stores 11 in the other register designated for multiplication
C3F0B2:        AE1642            LDX $4216    ;$4216 is the register for the product of $4202 and $4203 and X is 16-bit
C3F0B5:        A00500            LDY #$0005    ;Sets Y to 5 for the loop
C3F0B8:        BF016ED8        LDA $D86E01,x     ;A is the spell taught, indexed by X, the block for the specific Esper
C3F0BC:        C301            CMP $01,s    ;Compare this the value in our stack    
C3F0BE:        F00F            BEQ $F0CF    ;If they're the same, we go to the new code
C3F0C0:        E8            INX        ;If not, we increment x by 2 to look at the next spell. Incrementing X by one
C3F0C1:        E8            INX        ;Incrementing X by another 1
C3F0C2:        88            DEY        ;Decreasing Y to advance the loop
C3F0C3:        D0F3            BNE $F0B8    ;If Y isn't 0, the loop's not done
C3F0C5:        68            PLA        ;When the loop is over and nothing is found, bring back A from the stack
C3F0C6:        7A            PLY        ;Bring Y from the stack since it was pushed next to last
C3F0C7:        FA            PLX        ;Bring X back from the stack
C3F0C8:        68            PLA        ;Bring A back from thw stack
C3F0C9:        20EC50            JSR $50EC    ;The displaced subroutine from C3/503E
C3F0CC:        4C4150            JMP $5041    ;Jump back to the regular code as though nothing happened
C3F0CF:        68            PLA        ;Bring back A from the stack as it's no longer needed
C3F0D0:        7A            PLY        ;Bring Y from the stack since it was pushed next to last
C3F0D1:        FA            PLX        ;Bring X from the stack since it was pushed next to first
C3F0D2:        68            PLA        ;Bring A from the stack since it was pushed first
C3F0D3:        20EC50            JSR $50EC       ;Let's get the spell again
C3F0D6:        206784            JSR $8467    ;Stores the name of the spell
C3F0D9:        A2929E            LDX #$9E92    ;Part of spell drawing, necessary to prevent ghosting/artifcating when a spell is taught by an Esper and already known
C3F0DC:        8E8121            STX $2181       ;Same as above
C3F0DF:        20EC50            JSR $50EC    ;Getting spell again
C3F0E2:        4C8850            JMP $5088    ;Jumping to code to allow spell


BONUS BUGGY CODE...with fixed edition!

As the text indicates this code below is bugged. I wanted to improve upon the code I edited to show the percentage of a spell learned that is available only because of an Esper. It works..,sorta. The problem is there are extra percentage marks in weird places.  I'm probably going to leave this "feature" out, though, but I'm posting it here in case anyone wants to look at what NOT to do (note, there's no commentary).
 
Code:
C3503E:        4C91F0            JMP $F091      
C3F091:        48            PHA
C3F092:        DA            PHX
C3F093:        5A            PHY
C3F094:        20DD4E            JSR $4EDD
C3F097:        B91E00            LDA $001E,y
C3F09A:        302A            BMI $F0C6
C3F09C:        20EC50            JSR $50EC
C3F09F:        C9FF            CMP #$FF
C3F0A1:        F023            BEQ $F0C6
C3F0A3:        48            PHA
C3F0A4:        20DD4E            JSR $4EDD
C3F0A7:        B91E00            LDA $001E,y
C3F0AA:        8D0242            STA $4202
C3F0AD:        A90B            LDA #$0B
C3F0AF:        8D0342            STA $4203
C3F0B2:        AE1642            LDX $4216
C3F0B5:        A00500            LDY #$0005
C3F0B8:        BF016ED8        LDA $D86E01,x
C3F0BC:        C301            CMP $01,s
C3F0BE:        F00F            BEQ $F0CF
C3F0C0:        E8            INX
C3F0C1:        E8            INX
C3F0C2:        88            DEY
C3F0C3:        D0F3            BNE $F0B8
C3F0C5:        68            PLA
C3F0C6:        7A            PLY
C3F0C7:        FA            PLX
C3F0C8:        68            PLA
C3F0C9:        20EC50            JSR $50EC
C3F0CC:        4C4150            JMP $5041
C3F0CF:        68            PLA
C3F0D0:        7A            PLY
C3F0D1:        FA            PLX
C3F0D2:        68            PLA
C3F0D3:        20EC50            JSR $50EC
C3F0D6:        206784            JSR $8467
C3F0D9:        A2929E            LDX #$9E92
C3F0DC:        8E8121            STX $2181
C3F0DF:        20EC50            JSR $50EC
C3F0E2:        20A250            JSR $50A2
C3F0E5:        C9FF            CMP #$FF
C3F0E7:        F011            BEQ $F0FA
C3F0E9:        48            PHA
C3F0EA:        A924            LDA #$24
C3F0EC:        8529            STA $29
C3F0EE:        20EC50            JSR $50EC
C3F0F1:        204D51            JSR $514D
C3F0F4:        8D8021            STA $2180
C3F0F7:        4C6A50            JMP $506A
C3F0FA:        4C8850            JMP $5088

Edit: I figured out what was wrong with this above code, so here's the code that displays the spells with percentages and that includes the pressing Y-button mode.


Code:
C34FE4:        4CFAF0            JMP $F0FA       ;Jumps to the new code
C3503E:        4C91F0            JMP $F091       ;Jumps to the new code


C3F091:        48            PHA
C3F092:        DA            PHX
C3F093:        5A            PHY
C3F094:        20DD4E            JSR $4EDD
C3F097:        B91E00            LDA $001E,y
C3F09A:        302A            BMI $F0C6
C3F09C:        20EC50            JSR $50EC
C3F09F:        C9FF            CMP #$FF
C3F0A1:        F023            BEQ $F0C6
C3F0A3:        48            PHA
C3F0A4:        20DD4E            JSR $4EDD
C3F0A7:        B91E00            LDA $001E,y
C3F0AA:        8D0242            STA $4202
C3F0AD:        A90B            LDA #$0B
C3F0AF:        8D0342            STA $4203
C3F0B2:        AE1642            LDX $4216
C3F0B5:        A00500            LDY #$0005
C3F0B8:        BF016ED8        LDA $D86E01,x
C3F0BC:        C301            CMP $01,s
C3F0BE:        F00F            BEQ $F0CF
C3F0C0:        E8            INX
C3F0C1:        E8            INX
C3F0C2:        88            DEY
C3F0C3:        D0F3            BNE $F0B8
C3F0C5:        68            PLA
C3F0C6:        7A            PLY
C3F0C7:        FA            PLX
C3F0C8:        68            PLA
C3F0C9:        20EC50            JSR $50EC
C3F0CC:        4C4150            JMP $5041
C3F0CF:        68            PLA
C3F0D0:        7A            PLY
C3F0D1:        FA            PLX
C3F0D2:        68            PLA
C3F0D3:        20EC50            JSR $50EC
C3F0D6:        206784            JSR $8467
C3F0D9:        A2929E            LDX #$9E92
C3F0DC:        8E8121            STX $2181
C3F0DF:        20EC50            JSR $50EC
C3F0E2:        20A250            JSR $50A2
C3F0E5:        C9FF            CMP #$FF
C3F0E7:        F00E            BEQ $F0F7
C3F0E9:        48            PHA
C3F0EA:        A924            LDA #$24
C3F0EC:        8529            STA $29
C3F0EE:        20EC50            JSR $50EC
C3F0F1:        204D51            JSR $514D
C3F0F4:        4C6A50            JMP $506A
C3F0F7:        4C8850            JMP $5088
C3F0FA:        48            PHA
C3F0FB:        DA            PHX
C3F0FC:        5A            PHY
C3F0FD:        20DD4E            JSR $4EDD
C3F100:        B91E00            LDA $001E,y
C3F103:        3026            BMI $F12B
C3F105:        20EC50            JSR $50EC
C3F108:        48            PHA
C3F109:        20DD4E            JSR $4EDD
C3F10C:        B91E00            LDA $001E,y
C3F10F:        8D0242            STA $4202
C3F112:        A90B            LDA #$0B
C3F114:        8D0342            STA $4203
C3F117:        AE1642            LDX $4216
C3F11A:        A00500            LDY #$0005
C3F11D:        BF016ED8        LDA $D86E01,x
C3F121:        C301            CMP $01,s
C3F123:        F00F            BEQ $F134
C3F125:        E8            INX
C3F126:        E8            INX
C3F127:        88            DEY
C3F128:        D0F3            BNE $F11D
C3F12A:        68            PLA
C3F12B:        7A            PLY
C3F12C:        FA            PLX
C3F12D:        68            PLA
C3F12E:        20A250            JSR $50A2
C3F131:        4CE74F            JMP $4FE7
C3F134:        68            PLA
C3F135:        7A            PLY
C3F136:        FA            PLX
C3F137:        68            PLA
C3F138:        4CEB4F            JMP $4FEB

I'm 80% there. I have to figure out to get Gogo access to the spells on other people's Espers.
  Find
Quote  
[-] The following 1 user says Thank You to Turbotastic for this post:
  • madsiur (03-27-2018)



Messages In This Thread
RE: Troubleshooting Code - by B-Run - 04-05-2017, 09:39 PM
RE: Troubleshooting Code - by Turbotastic - 04-13-2017, 12:07 AM
RE: Troubleshooting Code - by madsiur - 04-13-2017, 12:38 AM
RE: Troubleshooting Code - by seibaby - 04-13-2017, 04:20 AM
RE: Troubleshooting Code - by B-Run - 04-13-2017, 06:50 AM
RE: Troubleshooting Code - by Turbotastic - 08-06-2017, 10:30 PM
RE: Troubleshooting Code - by seibaby - 12-10-2017, 10:09 AM
RE: Troubleshooting Code - by seibaby - 08-09-2017, 06:44 PM
RE: Troubleshooting Code - by Turbotastic - 08-10-2017, 07:02 PM
RE: Troubleshooting Code - by seibaby - 08-27-2017, 01:05 PM
RE: Troubleshooting Code - by Turbotastic - 08-28-2017, 07:08 PM
RE: Troubleshooting Code - by Turbotastic - 12-10-2017, 01:42 PM
RE: Troubleshooting Code - by Turbotastic - 03-25-2018, 07:50 AM
RE: Troubleshooting Code - by Turbotastic - 03-29-2018, 11:43 PM
RE: Troubleshooting Code - by madsiur - 03-30-2018, 01:08 AM
RE: Troubleshooting Code - by Turbotastic - 03-30-2018, 01:36 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite