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

#15
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
Editor's Note: If you want the FULL commented code for C3 scroll to the bottom!

Also, anyone is more than welcome to edit, improve, or incorporate this code or any related ideas in any project, no credit needed or even wanted
(if you want to credit anyone, credit the other posters in this thread, as well as assassin, Novalia Spirit, and such, since they did all the work). You can even spread it across the Internet. No permission is needed. It is yours for the taking and reshaping.


Gogo's menu was easier than I expected.

Before understanding the code. I had presumed that Gogo was pulling directly from the known spell lists of other characters.

Instead, Gogo's menu was just using a hijacked subroutine to check other people's lists to determine if the spells were mastered or not. Basically, the game did most of the work for me.  All I had to do was trick the menu into thinking that a spell was learned. (LDA $#FF)

In fact, since I had to do fewer tests, I didn't do as many pushing and pulling of bytes, so this was going to be a breeze...right?

Not exactly. I kept having difficulty because I kept trying to use the existing "Get Spell" subroutine that I was using before to determine whether a spell is learned. This and other code errors caused an inexplicable crash that took me to the "load game" screen when scrolling to the bottom of Gogo's menu.

Then I realized since Gogo's magic generation, unlike everyone else's, is solely a fork of the spell mastery subroutine.  In other words, Gogo's code doesn't check the slot multiple times (since there is no need for him to display partially learned spells), so using the "Get Spell" subroutine was the wrong basis for a check.

It still took a few tries and a little more tinkering. The final step in getting this to work was to restore the few bytes which set the spell as known if found (I had EA-ed them out in troubleshooting and got the strange sight of partially learned spells in Gogo's menu.).

Here's the uncommented code changes (note, this assumes the percentage dispay code in the previous post is used.)

Code:
C350E2:        4C3BF1          JMP $F13B
C350E5:        EA              NOP


C3F13B:        A5E1        LDA $E1
C3F13D:        B91E00          LDA $001E,y
C3F140:        3022            BMI $F164
C3F142:        A5E0            LDA $E0
C3F144:        48              PHA
C3F145:        B91E00          LDA $001E,y
C3F148:        8D0242          STA $4202
C3F14B:        A90B            LDA #$0B
C3F14D:        8D0342          STA $4203
C3F150:        AE1642          LDX $4216
C3F153:        A00500          LDY #$05
C3F156:        BF016ED8        LDA $D86E01,x
C3F15A:        C301            CMP $01,s
C3F15C:        F00D            BEQ $F16B
C3F15E:        E8              INX
C3F15F:        E8              INX
C3F160:        88              DEY
C3F161:        D0F3            BNE $F156
C3F163:        68              PLA
C3F164:        E6E1            INC $E1
C3F166:        A5E1            LDA $E1
C3F168:        4CE650          JMP $50E6
C3F16B:        68              PLA
C3F16C:        A9FF            LDA #$FF
C3F16E:        4CEB50            JMP $50EB

I went through the code again and I noticed an obvious extraneous instruction. So consider the below the true 1.0 code. (And, yes, it's formatted a lot better than the code in the other boxes.)

FULL C3 CODE FOLKS! START HERE!


Code:
C34FE4:   4CFAF0         JMP $F0FA          ;Jumps to new code for the
                                            Y-button pressed Menu Code

C3503E:   4C91F0         JMP $F091          ;Jumps to the new code for the
                                            standard menu

C350E2:   4C3BF1         JMP $F13B          ;Jumps to the new code for
                                            Gogo's menu
C350E5:   EA             NOP                ;Blank out extra byte



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
                                            is equipped, 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 it normally
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 retrieval of the
                                            actor's Epser again
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
                                            multiplication 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 1
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 since
                                            it was pushed next to first
C3F0C8:   68             PLA                ;Bring A back from the stack since
                                            it was pushed first
C3F0C9:   20EC50         JSR $50EC          ;The displaced original 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:   20A250         JSR $50A2          ;Loading Spell mastery
C3F0E5:   C9FF           CMP #$FF           ;Determine if the spell is
                                            completely known, just in case it
                                            actually is
C3F0E7:   F00E           BEQ $F0F7          ;If known, branch to it being
                                            displayed as known fully
C3F0E9:   48             PHA                ;Push A to stack, because we need
                                            the mastery
C3F0EA:   A924           LDA #$24           ;Load the palette for an active
                                            spell
C3F0EC:   8529           STA $29            ;Stores A
C3F0EE:   20EC50         JSR $50EC          ;Gets the spell again
C3F0F1:   204D51         JSR $514D          ;Will gray the spell if it's not
                                            able to be used
C3F0F4:   4C6A50          JMP $506A          ;Jump to regular code will pull it
C3F0F7:   4C8850          JMP $5088          ;Display the spell normally

C3F0FA:   48             PHA                ;Push everything to the stack, just
                                            in case
C3F0FB:   DA             PHX                ;Push everything to the stack, just
                                            in case
C3F0FC:   5A             PHY                ;Push everything to the stack, just
                                            in case
C3F0FD:   20DD4E         JSR $4EDD          ;Sets up the retrieval of the
                                            actor's Esper
C3F100:   B91E00         LDA $001E,y        ;Loads the actor's Esper in A
C3F103:   3026           BMI $F12B          ;Value will be negative if no Esper,
                                            branch to code leading back to
                                            regular code
C3F105:   20EC50         JSR $50EC          ;Get spell in slot
C3F108:   48             PHA                ;Pushing the spell ID to the stack
C3F109:   20DD4E         JSR $4EDD          ;Sets up the retrieval of the
                                            actor's Esper again
C3F10C:   B91E00         LDA $001E,y        ;Loads the actor's Esper in A
C3F10F:   8D0242         STA $4202          ;Stores A in a register designated
                                            for multiplication
C3F112:   A90B           LDA #$0B           ;Sets A to 11
C3F114:   8D0342         STA $4203          ;Stores 11 in the other register
                                            designated for multiplication
C3F117:   AE1642         LDX $4216          ;$4216 is the register for the
                                            multiplication product of $4202 and
                                            $4203 and X is 16-bit
C3F11A:   A00500         LDY #$0005         ;Sets Y to 5 for the loop
C3F11D:   BF016ED8       LDA $D86E01,x      ;A is the spell taught, indexed by
                                            X, the block for the specific
                                            Esper
C3F121:   C301           CMP $01,s          ;Compare this the value in our
                                            stack
C3F123:   F00F           BEQ $F134          ;If they're the same, we go to the
                                            new code
C3F125:   E8             INX                ;If not, we increment x by 2 to look
                                            at the next spell.
                                            Incrementing X by 1
C3F126:   E8             INX                ;Incrementing X by another 1
C3F127:   88             DEY                ;Decreasing Y to advance the loop
C3F128:   D0F3           BNE $F11D          ;If Y isn't 0, the loop's not done
C3F12A:   68             PLA                ;When the loop is over and nothing
                                            is found, bring back A from the
                                            stack
C3F12B:   7A             PLY                ;Bring Y from the stack since it
                                            was pushed next to last
C3F12C:   FA             PLX                ;Bring X from the stack since it
                                            was pushed next to first
C3F12D:   68             PLA                ;Bring A from the stack since it
                                            was pushed first
C3F12E:   20A250         JSR $50A2          ;The displaced original subroutine
                                            from C3/4FE4
C3F131:   4CE74F         JMP $4FE7          ;Jump back to the regular code as
                                            though nothing happened
C3F134:   68             PLA                ;Bring back A from the stack as
                                            it's no longer needed
C3F135:   7A             PLY                ;Bring Y from the stack since it
                                            was pushed next to last
C3F136:   FA             PLX                ;Bring X from the stack since it
                                            was pushed next to first
C3F137:   68             PLA                ;Bring A from the stack since it
                                            was pushed first
C3F138:   4CEB4F         JMP $4FEB          ;Jump to code to draw spell and MP
                                            cost


C3F13B:   B91E00         LDA $001E,y        ;Loads the actor's Esper in A
C3F13E:   3022           BMI $F162          ;Value will be negative if no
                                            Esper equipped, branch to code
                                            leading back to regular code
C3F140:   A5E0           LDA $E0            ;Spell stored here as during
                                            preceding code
C3F142:   48             PHA                ;Pushing the spell ID to the stack
C3F143:   B91E00         LDA $001E,y        ;Loads the actor's Esper in A
C3F146:   8D0242         STA $4202          ;Stores A in a register designated
                                            for multiplication
C3F149:   A90B           LDA #$0B           ;Sets A to 11
C3F14B:   8D0342         STA $4203          ;Stores 11 in the other register
                                            designated for multiplication
C3F14E:   AE1642         LDX $4216          ;$4216 is the register for the
                                            multiplication product of $4202 and
                                            $4203 and X is 16-bit
C3F151:   A00500         LDY #$0005         ;Sets Y to 5 for the loop
C3F154:   BF016ED8       LDA $D86E01,x      ;A is the spell taught, indexed by
                                            X, the block for the specific
                                            Esper of the actor
C3F158:   C301           CMP $01,s          ;Compare this the value in the
                                            stack
C3F15A:   F00D           BEQ $F169          ;If they're the same, we go to the
                                            new code
C3F15C:   E8             INX                ;If not, we increment x by 2 to look
                                            at the next spell.
                                            Incrementing X by 1
C3F15D:   E8             INX                ;Incrementing X by another 1
C3F15E:   88             DEY                ;Decreasing Y to advance the loop
C3F15F:   D0F3           BNE $F154          ;If Y isn't 0, the loop's not done
C3F161:   68             PLA                ;When the loop is over and nothing
                                            is found, bring back A from the
                                            stack
C3F162:   E6E1           INC $E1            ;Displaced code from C3/50E2
C3F164:   A5E1           LDA $E1            ;Displaced code from C3/50E4
C3F166:   4CE650         JMP $50E6          ;Jump back to the normal code
C3F169:   68             PLA                ;Bring back A from the stack as
                                            it's no longer needed
C3F16A:   A9FF           LDA #$FF           ;Set A as the known value of a
                                            spell
C3F16C:   4CEB50         JMP $50EB          ;Jump to the end of the subroutine
  Find
Quote  
[-] The following 1 user says Thank You to Turbotastic for this post:
  • seibaby (03-30-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