Here's a little something.
I made some macros to make parameter passing just a little bit easier to manage. I call it
xparam. I used this quite a lot in STREEMERZ.
Here's how you declare a function (in a header file):
Code: Select all
; Function declaration.
xdecl testFunc
; Function parameters.
foo .byte
bar .word
; Parameters/locals can be structs too (testStruct is declared elsewhere)
xxx .tag testStruct
; Local variables of the function.
xlocals
xyzzy .dword
dog .byte
endxlocals
endxdecl
Function parameters and local variables can be accessed in the function:
Code: Select all
xproc testFunc
lda param foo
sta local dog
rts
endxproc
Here's how you would call an xparam function:
Code: Select all
ldx #111
xinvoke testFunc, foo: x, bar: #$5566, xxx: structInMemory
Inputs can be registers, immediate values or memory addresses. Everything is stored on the zero page. See README.txt in ZIP for caveats/more info.
Also note that build.cmd in the ZIP file requires that the ZEROPAGE segment is at least 32 bytes big (it uses the "none" configuration, which by default for some strange reason only has $1F bytes of zero page). To fix it, modify none.cfg in your ca65 installation directory.
Here's a commented disassembly of the binary produced by the files in the ZIP:
Code: Select all
.setcpu "6502"
L0226 := $0226
L024E := $024E
ldx #$6F
; testFunc invocation (in test.s)
; x is directly stored at $00 (foo)
stx $00
; $5566 is loaded at $01 (bar)
lda #$66
sta $01
lda #$55
sta $02
; The struct (3 bytes) is loaded from memory
lda $0223
sta $03
lda $0224
sta $04
lda $0225
sta $05
; The actual function call to testFunc.
jsr L0226
; "xparam" macro demonstrations (to access parameter "bar").
lda $01
lda $02
.byte 111 ; byteInMemory
.byte 123 ; structInMemory
.word $DEA
; testFunc (test-module.s):
lda $00
lda $01
lda $02
lda $03
lda $04
lda $05
; testFunc local variable accesses:
lda #$7B
sta $10
sta $11
sta $12
sta $13
sta $14
; testFunc invokes nestedFunc:
lda #$7B
sta $06
lda #$67
sta $07
lda #$45
sta $08
jsr L024E
rts
; nestedFunc (nested-module.s):
lda $06
lda $07
rts