This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Passing an array of arguments

Passing an array of arguments
by on (#239573)
Yesterday as I was trying to figure out a way to efficiently create multiple "forks" of the same enemies that would behave differently based on their ID, I've come across the need to pass one of multiple sets of arguments to my function that handles sine-wave motion. Since the enemy needs to find its own ID and figure out which of the three possible versions it is, I decided to use a copy of the CPU flags after comparison, because the Z and C flags are conveniently placed in the low two bits.

lda objIDslot+0,x ; X = current index into the list of active entities
cmp obj_windeagleV2
adc #$01 ; correction to 01/00/10, as ZC after the comparison would result in either 00, 11 ,or 01, but not 10
and #$03
;... read the arguments from arrays for each argument

Is there perhaps a more efficient way to do this sort of thing? Most places I've read about this tell you to pass the address of the right array, but one array per argument seems better suited for the 6502.