Re: [stella] ... [overlays]

Subject: Re: [stella] ... [overlays]
From: "Andrew Davie" <adavie@xxxxxxxxxxx>
Date: Thu, 27 Jun 2002 00:29:36 +1000
> Next general there a document that talks about
> sensible variable placement with the 6502?  I can make some
> guesses based on what variable locations people use in their
> own programs, and I know you want to keep it on the opposite
> end from the stack (and probably not use the stack that much
> anyway it seems)

Have a very close look at the variable overlay method in Qb.

This method gives you many more RAM locations to play with than you might
otherwise think you have.  The essential methodology is to define a buffer
for overlays (say, 16 bytes), then reallocate those bytes to different
variables by re-orging the assembler location during variable definition.
As long as you don't use different overlays' vars at the same time, you have
very nicely named vars through your whole program.  Again, Qb is a good

Here's a basic example...

    SEG.U vars
    org $80            ; start of vars

nonoverlayvars        ds 64                ; assume there's lots of 'normal'
vars here
Overlay               ds 16                ; and 16 bytes reserved for

    ; now we define multiple overlays...
       ; each can use up to 16 bytes (the size of the Overlay buffer) in any
way required...

    org Overlay
ovar1                 ds 3
ovar1b                ds 6
ovar1c                ds 2                 ; so overlay section 1 uses a
total of 11 bytes
                                           ; there are 5 free variable
locations in this overlay

    org Overlay       ; another overlay!
overlay2buffer        ds 16                ; just a single 16-byte buffer

    org Overlay       ; yet another overlay
overlay3              ds 2
blah3                 ds 4
hardtothinkofnames    ds 2

So, as long as you never use "overlay3" variable when you're also using ANY
variables from the other overlays, you're fine.  This isn't as much of a
limitation as it sounds.  And there's no reason one can't have multiple
overlays - or even nested overlays.  Once setup, it's easy to use, and gives
a lot more leeway in variable usage.  AND leads to nicer code - as variables
are named with meaningful names, not "temp1", "temp2", etc.


Archives (includes files) at
Unsub & more at

Current Thread