Pseudo Static Heap for ca65
or
Parisoft Allocator for ca65
- Download the latest version at releases page.
- Declare all functions and variables using pa65 directives.
- Choose a file name like
pa65.inc
and include it in all your source files:-
.include "pa65.inc"
-
- Call pa65 with your source files to generate the
.inc
file above:-
java -jar pa65-xy.jar -o pa65.inc file1.s ... fileN.s
-
- Just assembly/link your project as you've used to do
Declare a function with the given name.
The function must terminate with .endfunc
.
- name - The name of the function
.func foo
rts
.endfunc
Allocate some bytes of a variable into a segment.
- seg - The name of a segment to allocate into. The directives
.zeropage
and.bss
can also be used. - var - The name of the variable
- size - The number of bytes to allocate
.func foo
.palloc .zeropage, acme, 1 ; allocate 1 byte in zp for acme
; some code here
.endfunc
.palloc bar
; call foo passing the value 1 to the acme parameter
lda #1
sta foo::acme
jmp foo
.endfunc
Free the memory space allocated by some variables.
- var1...varN - The name of the variable(s) to free
.func foo
.palloc "SEG1", tmp1, 1
.palloc "SEG2", tmp2, 1
; some code here
.pfree tmp1, tmp2 ; free the space allocated by tmp1 and tmp2
.palloc "SEG1", acme, 1 ; reuse the space freed by tmp1
; some code here
.endfunc
Create a reference of a variable defined on another function.
Useful to preset the parameters of a function.
- v1 - The name of the referer variable
- v2 - The name of the referee variable
.func foo
.palloc .zeropage, acme, 1
; some code here
.enfunc
.func bar
.pref acme, foo::acme ; make a reference of foo.acme
jsr foo ; just call foo as the parameter is alread set by the callee (baz)
; some code here
.endfunc
.func baz
; call bar passing 1 to the acme parameter
lda #1
sta bar::acme
jmp bar
.endfunc
Declare a table of functions. See jtx and jty.
- name - The name of the table
- funcs - Array of functions
.linecont+
.func foo
; some code here
.endfunc
.func bar
; some code here
.endfunc
.ftable choose_foo_or_bar, {\
foo-1,\
bar-1\
}
Jump to a function referenced by a .ftable
at index X
using RTS trick.
- table - The name of a function table declared as .ftable
.linecont+
.func switch
.palloc .zeropage, idx, 1
ldx idx
jtx choose_foo_or_bar ; jump to foo if idx is 0; jump to bar if idx is 1
.endfunc
.func foo
; some code here
.endfunc
.func bar
; some code here
.endfunc
.ftable choose_foo_or_bar, {\
foo-1,\
bar-1\
}
Jump to a function referenced by a .ftable
at index Y
using RTS trick.
- table - The name of a function table declared as .ftable
.linecont+
.func switch
.palloc .zeropage, idx, 1
ldy idx
jty choose_foo_or_bar ; jump to foo if idx is 0; jump to bar if idx is 1
.endfunc
.func foo
; some code here
.endfunc
.func bar
; some code here
.endfunc
.ftable choose_foo_or_bar, {\
foo-1,\
bar-1\
}