Background:
I'm adding custom code to my mod
Arcana SOR, so the status screens are more informative. Most of it is rearranging things, but to add extra data I need ASM to read from a new location and store it in the dialogue buffer 1580-16F2. Before and after:


The bottom right column of numbers (ACDM) will be Attack-Critical-Defense-Magic Defense once I add font characters like a sword and shield. Right now I'm trying to pull the weapon's critical hit power with $80/C6DC, store it to the display buffer at $16F1, then call it when drawing the dialogue box. Decided to see if it worked before adding the magic defense as well. (Good thing I checked, because it doesn't work!)
Original code:
$87/A39D A6 00 LDX $00 [$00:1E00] A:0000 X:0000 Y:0032 D:1E00 DB:80 S:1FF1 P:envmxdIZc HC:0536 VC:260 FC:31 I:00
$87/A39F A0 33 00 LDY #$0033 A:0000 X:06B5 Y:0032 D:1E00 DB:80 S:1FF1 P:envmxdIzc HC:0610 VC:260 FC:31 I:00
(Draws the ring text to display buffer)
$87/A3A2 20 C9 A3 JSR $A3C9 [$87:A3C9] A:0000 X:06B5 Y:0033 D:1E00 DB:80 S:1FF1 P:envmxdIzc HC:0634 VC:260 FC:31 I:00
$87/A3A5 FA PLX A:0000 X:06C5 Y:0043 D:1E00 DB:80 S:1FF1 P:envmxdIZC HC:1074 VC:000 FC:31 I:00
(Checks if current party member is a Spirit (value=2)
$87/A3A6 BD C3 11 LDA $11C3,x[$80:11C3] A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF3 P:envmxdIZC HC:1188 VC:000 FC:31 I:00
$87/A3A9 29 FF 00 AND #$00FF A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF3 P:envmxdIZC HC:1234 VC:000 FC:31 I:00
$87/A3AC C9 02 00 CMP #$0002 A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF3 P:envmxdIZC HC:1258 VC:000 FC:31 I:00
$87/A3AF F0 11 BEQ $11 [$A3C2] A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF3 P:eNvmxdIzc HC:1282 VC:000 FC:31 I:00
$87/A3B1 DA PHX A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF3 P:eNvmxdIzc HC:1300 VC:000 FC:31 I:00
(Calculates Attack power)
$87/A3B2 22 CA C4 80 JSL $80C4CA[$80:C4CA] A:0000 X:0000 Y:0043 D:1E00 DB:80 S:1FF1 P:eNvmxdIzc HC:1334 VC:000 FC:31 I:00
So I decided to splice it at 87/A3A5 (3A3A5)
22 30 E0 80 jsl 80E030
5A phy
DA phx
A2 00 00 ldx 0000
A0 00 00 ldy 0000
20 DC C6 jsr c6dc
09 00 20 ora #2000
8D F1 16 sta 16F1
FA plx
7A ply
FA plx
A2 00 00 ldx 0000
BD C3 11 lda 11c3,x
6B rtl
I made sure to match my pulls and pushes, but I was getting the wrong item off the stack (either the return pointer or another large number) so I just loaded zero afterwards for troubleshooting. Calling PLX PLY PLX seems to pull the return pointer, so I was playing around with skipping that last pull at $A3A5... but then after finishing that code it returned wrong! I get the feeling I'm mixing up my JSLs and RTLs somehow. I can provide more context on request. The critical hit code is at $80/C6DC, so I do have to jump from $87 somewhere. How do I know what kind of jump to use?