[stella] Macros to manage memory allocation.

Lee Fastenau stella at leefastenau.com
Tue Jun 12 12:44:37 CDT 2007


> I should note that you  
> don't need to put all you ALLOCATE macros together.  They can be  
> scattered throughout your source files as long as INIT_ALLOC appears  
> before any instance of ALLOCATE at compile time.  I want to be able  
> to build up a library of subroutines in include files, then include  
> as many as I like in a project and have DASM figure out all the  
> allocations for me.

I noticed that about the macro, it's a neat idea to be able to declare globals anywhere, but I don't think that's a great practice, and it's the reason it takes so many passes for DASM to resolve all the addresses.

Another solution could be to make the user reserve n bytes for stack, then initialize two counters: One that counts up from $80 for global vars and one that counts down from ($FF - STACK_SIZE) for locals.  This way the assembler doesn't have to go back and resolve any values.  You'd also be able to easily check for memory overruns by comparing the two counters (if local_counter<=global_counter then out of memory).  Actually, with this solution you'd be able to continue to define globals throughout the program without the compiler balking at it.

I also recommend reducing the number of "public" macros by embedding init code in the allocation macros and setting an init flag.

; Setup stack
SET_STACK_SIZE 6

; Setup globals
VAR_GLOBAL "globalVarA",1
VAR_GLOBAL "globalVarB",1
VAR_GLOBAL "globalSet",10

...

; Some subroutine
someSub subroutine
INIT_LOCAL
VAR_LOCAL ".counter",1
VAR_LOCAL ".somePointer",2

...

; Other subroutine
otherSub su broutine
INIT_LOCAL
VAR_LOCAL ".otherSet",5
VAR_LOCAL ".counter",1

The dot var syntax should allow us to reuse var names in subroutine scope.  A potential solution to the "mostly global" use case might be:

VAR_SHARE ".localVar","globalVarA"

I'll have to try these ideas on a new project! :)

-Lee






More information about the Stella mailing list