Users browsing this thread: 1 Guest(s)
Casting Spells Taught by Espers - RESOLVED!
08-28-2017, 07:08 PM
Sometimes I can be kind of slow, like Turbo the snail instead of my Wreck-It Ralph namesake. Thanks for the patience. Now I get it and that is a good idea.
(08-06-2017, 10:30 PM)Turbotastic Wrote: code
So, I finally got around to testing this and it indeed works fine. Nice work!
For menu stuff, you could hook the equip/unequip Esper function at C3/2929. That's what I did when I recently tackled this. GrayShadows suggested I use the top bit of the learn% byte as a signifier for whether a spell should be available, and to modify the relevant branches in C2 and C3, which works like a charm. I had a look at your code beforehand to help me figure some stuff out, so thanks!
I stilll haven't figured out how to cast a spell from the Esper data menu though... I can call the spell casting function but I'm not sure how to pass the spell ID to it. It's a minor detail though.
EDIT: also, you *definitely* need to start making your topic headers more descriptive.
The following 2 users say Thank You to seibaby for this post:
• Robo Jesus (03-25-2018), Turbotastic (12-11-2017)
• Robo Jesus (03-25-2018), Turbotastic (12-11-2017)
12-10-2017, 01:42 PM
(This post was last modified: 12-12-2017, 11:15 AM by Turbotastic.
Edit Reason: Grammar. Ugh. Grammar.
)
Any praise is appreciated, but I wouldn't have gotten even half that far if it weren't for B-Run. I can't program for beans.
In all honesty, I put this project on the backburner because while I did figure out what I needed to do conceptually to make this work for the menu outside of battle, I hit a different roadblock for each approach I tried.
With the "cast from the magic menu" option, I couldn't get the magic percentage subroutine to recognize when an Esper was equipped on a character. That and having to redo Gogo's spell menu to incorporate the "Esper equipped" spells of the other characters would be a hassle as I'd have to get the code for his menu to look at the Espers equipped by the other characters. Gogo's magic menu outside of battle just pulls the spells everyone already knows, so either I'd have to write custom code to check for spells from equipped Espers of other characters or I'd have to add more code to C2 to check for the actual spell lists themselves of the other characters in Gogo's case (in battle) just to be consistent. More succinctly, either I would have to allow Gogo to access those "equipped" spells both in and out of battle or I'd have to disallow Gogo's access both in and out of battle for balance reasons. That I couldn't get the other part to work, though, renders this point moot.
With the "cast from the Esper menu" option, I realize I would have to examine the spell that is listed when putting the cursor on it (the spell list menu only reads for display purposes at startup), subject it to the same tests as regular spells, then if and only if it is able to be cast, change the color so that it is enabled (since that's how this menu handles it) connect the eligible spells to the cast menu. As you've noted, getting that spell ID alone is kind of hard (there's a reason why you can only cast spells from the magic menu), and I'd have to either clone or hijack the casting subroutines after figuring out how to get the spell ID to load.
Because I got stuck, I followed auraplatonic's suggestion in another thread and opened up the "Imbued Magic" patch to see what was done there, but when I saw it rewrote the magic function entirely instead of just working with the existing code, I realized I was too dumb to hack and settled for lurking around these parts.
So because of that and because the spare time on my hands evaporated...I called it quits.
You have a good solution as I would have never thought of hijacking the Esper equip function. So if you want to take over, be my guest. Again, I'm no coder and I have neither the aptitude nor intelligence to get this working the way I want in a timely manner.
As for the title, when I first created this thread I was naive and thought that if I got over that one little hurdle in my initial post, it would be an easy ride from there. I didn't bother about being descriptive because I just wanted help with one little thing. Now, I realize I need help with too many things as I know nothing.
In all honesty, I put this project on the backburner because while I did figure out what I needed to do conceptually to make this work for the menu outside of battle, I hit a different roadblock for each approach I tried.
With the "cast from the magic menu" option, I couldn't get the magic percentage subroutine to recognize when an Esper was equipped on a character. That and having to redo Gogo's spell menu to incorporate the "Esper equipped" spells of the other characters would be a hassle as I'd have to get the code for his menu to look at the Espers equipped by the other characters. Gogo's magic menu outside of battle just pulls the spells everyone already knows, so either I'd have to write custom code to check for spells from equipped Espers of other characters or I'd have to add more code to C2 to check for the actual spell lists themselves of the other characters in Gogo's case (in battle) just to be consistent. More succinctly, either I would have to allow Gogo to access those "equipped" spells both in and out of battle or I'd have to disallow Gogo's access both in and out of battle for balance reasons. That I couldn't get the other part to work, though, renders this point moot.
With the "cast from the Esper menu" option, I realize I would have to examine the spell that is listed when putting the cursor on it (the spell list menu only reads for display purposes at startup), subject it to the same tests as regular spells, then if and only if it is able to be cast, change the color so that it is enabled (since that's how this menu handles it) connect the eligible spells to the cast menu. As you've noted, getting that spell ID alone is kind of hard (there's a reason why you can only cast spells from the magic menu), and I'd have to either clone or hijack the casting subroutines after figuring out how to get the spell ID to load.
Because I got stuck, I followed auraplatonic's suggestion in another thread and opened up the "Imbued Magic" patch to see what was done there, but when I saw it rewrote the magic function entirely instead of just working with the existing code, I realized I was too dumb to hack and settled for lurking around these parts.
So because of that and because the spare time on my hands evaporated...I called it quits.
You have a good solution as I would have never thought of hijacking the Esper equip function. So if you want to take over, be my guest. Again, I'm no coder and I have neither the aptitude nor intelligence to get this working the way I want in a timely manner.
As for the title, when I first created this thread I was naive and thought that if I got over that one little hurdle in my initial post, it would be an easy ride from there. I didn't bother about being descriptive because I just wanted help with one little thing. Now, I realize I need help with too many things as I know nothing.
03-25-2018, 07:50 AM
(This post was last modified: 03-30-2018, 12:27 AM by Turbotastic.)
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:
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).
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.
I'm 80% there. I have to figure out to get Gogo access to the spells on other people's Espers.
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.
03-29-2018, 11:43 PM
(This post was last modified: 05-27-2018, 09:50 PM by Turbotastic.)
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.)
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!
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
03-30-2018, 01:08 AM
good job! you know you can indent your code correctly in notepad++ but doing Edit -> Blank Operations -> Tab to spaces, and it will look good in forum codeblocks. Next step will be to make an assembler version (bass or xkas), that's another good learning project!
03-30-2018, 01:36 PM
(This post was last modified: 03-30-2018, 07:29 PM by Turbotastic.)
Thanks for the tip. There was a similar feature in another text editor, so I tried to implement it. I messed up.
As for making an assembler version, while that would be extremely useful so the code could be moved around and used in conjunction with other projects...my skills and understanding aren't strong enough to begin to approach that. I only barely understand asm file notation. This topic is almost a year old (and I had been working on this a lot longer), and this was with me having access to a complete disassembly, an opcode reference, and endless requests for help. I might attempt it in the future, but right now I'm going to take a break.
Also, I put the altered code for each bank together and there were no conflicts in my limited testing, so I was able to make a patch, but I haven't tested it thoroughly.
As for making an assembler version, while that would be extremely useful so the code could be moved around and used in conjunction with other projects...my skills and understanding aren't strong enough to begin to approach that. I only barely understand asm file notation. This topic is almost a year old (and I had been working on this a lot longer), and this was with me having access to a complete disassembly, an opcode reference, and endless requests for help. I might attempt it in the future, but right now I'm going to take a break.
Also, I put the altered code for each bank together and there were no conflicts in my limited testing, so I was able to make a patch, but I haven't tested it thoroughly.
« Next Oldest | Next Newest »
Users browsing this thread: 1 Guest(s)