Re: How do I do in CA65 things I do in ASM6?
Posted: Mon Nov 09, 2015 8:57 pm
I just put all my RAM allocations in a single file, and import everything from there. Everything includes this file. When I assemble the file, I define RAM_EXPORT which causes all the allocations and exports to be made, but elsewhere it is included and just creates the necessary imports.
If I am using temporary variables in functions, and I wanted a "helpful" name for them, I'd just alias them there:
Your problem seems to stem specifically from wanting to use aliased zeropage variables before the definition of the function. I think you I'd just do a "forward declaration" for that variable if it ever came up, but really it hasn't for me. (Forward declarations are a common necessity in C/C++, so I'm used to doing that already.) The stuff I tend to alias is always in BSS, and I'm used to using the common temporaries for ZP, they're all named like i, j, k, l, etc. and usually I document which ones a function uses or which ones it doesn't because there's a lot of overlap-- so I'd rather know a common name for them than hide it from myself with an alias.
The BSS stuff that I do alias is usually to do with different types of object, all of which use the same memory areas to store their state, but each of them has different data needs, so I alias the various bytes to document their usage. A struct might have done the job well, if I wasn't using striped arrays. At any rate, not really an issue because it's not on the zeropage, so it's not subject to the one-pass problem.
Code: Select all
.macro RESZP label, size
.ifdef RAM_EXPORT
label: .res size
.exportzp label
.else
.importzp label
.endif
.endmacro
.macro RES label, size
.ifdef RAM_EXPORT
label: .res size
.export label
.else
.import label
.endif
.endmacro
.segment "ZEROPAGE"
RESZP i, 1
RESZP j, 1
RESZP k, 1
.segment "OAM"
RES oam, 256
.segment "RAM"
RES collision, 256
RES dog_data0, 16
RES dog_data1, 16
RES dog_data2, 16
Code: Select all
.proc my_func
param_a = i
param_b = j
param_c = k
lda param_a
eor param_b
clc
adc param_c
rts
.endproc
The BSS stuff that I do alias is usually to do with different types of object, all of which use the same memory areas to store their state, but each of them has different data needs, so I alias the various bytes to document their usage. A struct might have done the job well, if I wasn't using striped arrays. At any rate, not really an issue because it's not on the zeropage, so it's not subject to the one-pass problem.