07-01-2012, 08:24 AM
(06-30-2012, 10:49 PM)Edrin Wrote: Ok, so what about editing the current code to reuse the same 12 lists by using the remainder of the actor number devided by twelve to choose what address to look for? Shared magic is better than none. All I need is the location of the code for both read and write for battle and menu. I think I can figure out the rest.
I think you will have to change code in 3 places. First, you will ne to change when the magic list is populated for battle (bank C2). Second you will need to change when the magic is saved after a battle (bank C2) and third, when magic is read for the menu outside battle (bank C3).
Here is your entrance door for saving magic. Routines $6283 and$ 602A are where those changes need to be I think but I haven't found explicitly where is it read and save to the RAM:
Code:
C2/5E60: 20 83 62 JSR $6283 (Stores address for spells known by character in $F4)
C2/5E63: BE 10 30 LDX $3010,Y (get offset to character info block)
C2/5E66: 5A PHY
C2/5E67: 20 EF 5F JSR $5FEF (Cursed Shield check)
C2/5E6A: BD 1E 16 LDA $161E,X (Esper equipped)
C2/5E6D: 30 03 BMI $5E72 (Branch if no esper equipped)
C2/5E6F: 20 2A 60 JSR $602A (Learn spells taught by esper)
I'm still not sure but this is partially where the magic menu might be populated:
Code:
C2/56DC: C2 21 REP #$21 (Set 16-bit A, clear Carry)
C2/56DE: 69 6E 1A ADC #$1A6E
C2/56E1: 85 F0 STA $F0
As for bank C3 I found not 1 but 2 places where magic spell list is read:
Code:
Get spell's learned amount, or, if it's Gogo, branch below to check everybody
else in the party.
C3/50A2: 85E0 STA $E0
C3/50A4: 20DD4E JSR $4EDD
C3/50A7: B90000 LDA $0000,Y
C3/50AA: C90C CMP #$0C
C3/50AC: F017 BEQ $50C5 (Branch if it's Gogo)
C3/50AE: 8D0242 STA $4202
C3/50B1: A936 LDA #$36
C3/50B3: 8D0342 STA $4203
C3/50B6: 7B TDC
C3/50B7: A5E0 LDA $E0
C3/50B9: C220 REP #$20 (16 bit memory/accum.)
C3/50BB: 6D1642 ADC $4216
C3/50BE: AA TAX
C3/50BF: E220 SEP #$20 (8 bit memory/accum.)
C3/50C1: BD6E1A LDA $1A6E,X
C3/50C4: 60 RTS
Code:
Determine if a character actually knows magic
C3/0D2B: AD691A LDA $1A69 (from C3/0CB7)
C3/0D2E: 0D6A1A ORA $1A6A
C3/0D31: 0D6B1A ORA $1A6B
C3/0D34: 0D6C1A ORA $1A6C
C3/0D37: D02A BNE $0D63 (branch if you have at least one esper)
C3/0D39: A667 LDX $67
C3/0D3B: 7B TDC
C3/0D3C: BD0000 LDA $0000,X (character ID)
C3/0D3F: C90C CMP #$0C
C3/0D41: F020 BEQ $0D63 (Branch if it's Gogo)
C3/0D43: B01C BCS $0D61 (Branch if it's Umaro or higher)
C3/0D45: 8D0242 STA $4202 (we're here if character is below Gogo, and you have no espers)
C3/0D48: A936 LDA #$36
C3/0D4A: 8D0342 STA $4203 (#$36 as multiplier)
C3/0D4D: EA NOP
C3/0D4E: EA NOP
C3/0D4F: EA NOP
C3/0D50: A03600 LDY #$0036 (TAY?)
C3/0D53: AE1642 LDX $4216 (load character * spell total)
C3/0D56: BD6E1A LDA $1A6E,X (load spell at X)
C3/0D59: C9FF CMP #$FF (learned it?)
C3/0D5B: F006 BEQ $0D63 (branch if so)
C3/0D5D: E8 INX
C3/0D5E: 88 DEY
C3/0D5F: D0F5 BNE $0D56 (branch if we haven't checked every spell)
C3/0D61: 18 CLC (used by C3/0C6C, says that this character doesn't know magic)
C3/0D62: 60 RTS
I found all that code by doing a search for "1A6E" in bank C2 and C3, which is the starting offset of the magic list for character 00. I can't really help you more than this, as I am a bit unfamiliar with all that code.