Users browsing this thread: 1 Guest(s)
Condensing Spell List in Battle
09-17-2017, 05:34 PM
(09-17-2017, 04:58 AM)GrayShadows Wrote: I'd be curious to see yours, just to compare -- I learn more from seeing everyone else's coding than I do just by coding myself, half the time.
untested, hasn't been assembled:
Code:
phx
ldy #$04 ; full list index. start at 1st Magic slot.
tyx ; index of next spot to write in shortened list. start at 1st
; Magic slot.
mainLoop:
LDA ($F2),Y
CMP #$FF
BEQ checkNextSpell ; branch if current entry null
stx $f0
cpy $f0 ; does full list index == output index? yes, i use
; this variable in a single place, because no other
; easy way to compare X and Y. :/
beq noCopy ; skip copying if so, but still advance
clc
rep #$20
copyLoop:
lda ($F2),Y ; read two spell menu bytes from original position
phy
txy
sta ($F2),Y ; save to new position
ply
iny
iny
inx
inx
bcs done ; exit loop if we've iterated twice. this
; way lets us avoid using decrementor.
sec
bra copyLoop ; otherwise, iterate that second time
done:
sep #$20
bra alreadyInced
noCopy:
inx
inx
inx
inx ; advance index of next place to write in shortened list
checkNextSpell:
iny
iny
iny
iny ; advance full list index
alreadyInced:
cpy #$D8 ; have we processed end of Magic list?
bcc mainLoop ; loop if not
; now blank out unused remainder of shortened list
txy
blankLoop:
cpy #$D8 ; have we reached Lore Land yet?
bcs nothingLeft ; branch if so
LDA #$FF
STA ($F2),Y ; this blanks out a spell
LDA #$00
STA ($F4),Y ; and zeroes out the MP cost
iny
iny
iny
iny
bra blankLoop
nothingLeft:
plx
one strong point is i'm able to mostly keep the second index in a register. but i do resort to using $F0 briefly to avoid stack jackassery. that could pose problems if i wanted to use the variable for bounds or other parameters in a unified version.
for the zeroing+FF'ing of spell data, it'd be a little smaller (and maybe faster) to have a "TDC ... DEC", with the ($F4) write first.
« Next Oldest | Next Newest »
Users browsing this thread: 1 Guest(s)