Users browsing this thread: 1 Guest(s)
Condensing Spell List in Battle
09-17-2017, 08:48 PM
I've got the first function down to 90 bytes.
I'm open to suggestions on reducing the size of the MP Deduction function, too.
Code:
condenseSpellLists:
PHX ; This is our character ID coming in
PHP
REP #$10
LDY #$0004 ; this is the index of the first Spell slot in the character's spell list
TYX ; X is going to be our 'write-space' index
.checkLoreLoop ; don't need to actually check the last slot of either list
LDA ($F2),Y
CMP #$FF
BNE .checkNextLore
.findNextLore
INY #4
CPY #$00DC ; if we've hit the first Lore slot, there are no more spells to copy back
BEQ .noMoreSpells ; so jump out, reset $F0 to start our lores
CPY #$013C ; this is after the last Lore slot, so if we've gone that far, there are no more spells to copy back
BEQ .noMoreLores
LDA ($F2),Y
CMP #$FF
BEQ .findNextLore
PHY ; we'll be pushing and pulling within the loop, but we need to know
; where it started so we can blank out the slot we copied from
CLC
REP #$20
.copyNextLore
LDA ($F2),Y ; Yes, we just did this, but we need to do it within this loop, too
PHY ; this stores our Y location, i.e. the next slot with a spell learned
TXY
STA ($F2),Y
PLY ; back to our 'write from' location
INY #2 ; and gets the next byte
INX #2
BCS .doneCopy
SEC
BPL .copyNextLore ; if we haven't done four bytes, loop back and grab the next
.doneCopy
SEP #$20
PLY ; this is the first byte of the slot we copied from
TDC
STA ($F4),Y ; this zeroes out the MP cost
DEC
STA ($F2),Y ; and blanks out the spell we copied from
BRA .weCopiedALore
.checkNextLore
INX #4
.weCopiedALore
TXY ; and then copy it over to Y for our next loop through
CPY #$00D8 ; if this is the last spell slot
BEQ .checkNextLore ;loop back up and INX again so we skip over it and point at our first Lore slot
CPY #$0138
BEQ .noMoreLores
BRA .checkLoreLoop
.noMoreLores
PLP
PLX
JMP $532C
.noMoreSpells
TYX ; reset our write-space index for the first Lore slot
BRA .checkLoreLoop
« Next Oldest | Next Newest »
Users browsing this thread: 1 Guest(s)