[FYI] variable count parameter retrieval
kuroneko
Posts: 3,623
This is one more result of getting the [thread=134987]PASM-Gameduino-drivers[/thread] down in size (more a side effect actually). It's more concerned about speed than size so re-introduction may not be feasible. The parameter loop always fetches 8 parameters from hub (2 hub windows/long) regardless of whether they are needed or not.
movd :arg, #arg0 ' get 8 arguments ; arg0 to arg7
mov t1, retaddr
mov t2, #8
:arg rdlong 0-0, t1
add :arg, d0
add t1, #4
djnz t2, #:arg
arg0 res 8
So I thought it should be possible to let each subroutine decide how many parameters are fetched. While this can be done in a loop it wouldn't get around the hub window issue (unless you go to more trouble than it's usually worth). The hub address of the first parameter is stored in retaddr, the address after the input array can be used for results. If no parameters are required then don't call the function. Otherwise simply use:
movi retaddr, #%nnn_1 ' nnn: number of parameters -1 (0..7) call #argsThe actual subroutine then uses cmpsub to increment the source address and generate an exit condition for us. Exit is done with an early (indirect) ret.
args rdlong arg0, retaddr ' read 1st argument
cmpsub retaddr, delta wc ' [increment address and] check exit
if_nc jmp args_ret ' cond: early return
rdlong arg1, retaddr ' read 2nd argument
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg2, retaddr
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg3, retaddr
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg4, retaddr
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg5, retaddr
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg6, retaddr
cmpsub retaddr, delta wc
if_nc jmp args_ret
rdlong arg7, retaddr
' cmpsub retaddr, delta wc
' if_nc jmp args_ret
args_ret ret
delta long %10 << 23 | $FFFC ' %10 deal with movi setup
' -(-4) address increment

