I did a bit of research, did some experimentation.. and ended up with a pretty decent collection of macros for function calls in ASM6! It seems to work pretty well, but any optimizations or bug fixes are appreciated
The values being passed are kept in a stack at $0500 - $05FF which is separate from the internal stack. This stack does not contain program pointers, just data and pointers to data. Program pointers are still handled using the internal stack. The separation of data and internal stacks make code less error prone and also increases the level of nesting possible.
In addition to passing parameters, you can allocate space in the stack for temporary local variables. This is much more flexible than trying to reuse a handful of global variables as reusable temporary variables.
http://supermariounlimited.com/wiki/C_Style_Functions
and here's a test case.. nothing exciting, just writes some values to memory. You can check out the contents of the stack at $0500 as well to see that everything is working as expected
Code: Select all
resetStack
loop: ; call functions over and over to test stack
call foo, #$FF
jmp loop:
foo:
foo_x equ #1 ; name the first parameter using equ
foo_y equ #2 ; name local variable
alloca #1 ; allocate anoter byte of memory for temporary local variable
lda #$EE
staLocal foo_y ; assign foo_y a value
call bar, #$AA, #$BB ; call another function
ldaLocal foo_x
sta #$10 ; write foo_x to $10
ldaLocal foo_y
sta #$11 ; write foo_y to $11
rts
bar:
bar_a = #1 ; name the parameters
bar_b = #2
bar_c = #3 ; and local vars
bar_d = #4
alloca #2 ; allocate 2 bytes for local variables
; Must prepend # onto var names since vars were named with =
ldaLocal #bar_a ; copy bar_a
staLocal #bar_c ; to bar_c
sta #$20 ; and to $20
ldaLocal #bar_b ; copy bar_b
staLocal #bar_d ; to bar_d
sta #$21 ; and to $21
ldaLocal #bar_c ; copy bar_c
sta #$22 ; to $22
ldaLocal #bar_d ; copy bar_d
sta #$23 ; to $23
rts