Passing an array of arguments

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
za909
Posts: 193
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Passing an array of arguments

Post by za909 » Mon Jun 03, 2019 11:31 pm

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.

Code: Select all

lda objIDslot+0,x ; X = current index into the list of active entities
cmp obj_windeagleV2
php
pla
clc
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
tay
;... 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.

Post Reply