<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 26 Dec 2008 17:03:16 +0000
From   : jgh@... (Jonathan Graham Harston)
Subject: Using stack page for temp vars

Phill Harvey-Smith wrote:
> without taking up extra ram. I have been using the area from &A8-&AF for
> tempory storage during execution of the commands, however I find that I
> need some more storage, perhaps another 5-10 bytes just for tempory byte
> counts end addresses etc.
 
Didn't we cover this a couple of months ago?
 
&A8-&AF is reserved for *commands to use as temporary workspace. If
you need more space you should allocate it on the stack itself,
not in the memory used by the stack.
 
For instance:
 
TSX:TXA:SEC:SBC #32:TAX:TXS  :\ Reserve 32 bytes on the stack
 
\ &100,X to &11F,X accesses space on the stack
 
TSX:TXA:CLC:ADC #32:TAX:TXS  :\ Release 32 bytes on the stack
 
You mustn't trample on any MOS workspace, as you will interfere
with the MOS's working. However, there is a way of being able to
use some more zero-page space.
 
&00-&7F is reserved for the current language. A transient command
can use some of this *IF* *AND* *ONLY* *IF* you ensure it is
preserved across the call. Languages are foreground applications,
and so language workspace therefore will only change in the
foreground when the language code is executing. For instance:
 
\ On entry to your code
LDX #31
.savelp
LDA &70,X:PHA:DEX:BPL savelp  :\ Preserve bytes &60-&8F
 
\ ... code ...
 
LDX #0
.restorelp
PLA:STA &70,X:INX:CPX #32:BNE restorelp :\ Restore &60-&8F
 
Note that you *MUST* restore the memory before exiting, even if
exiting on an error condition.
 
> Final point, is there anywhere I could make the source available, as
> these utils are getting to the point where they may actually be usefull
> to someone other than me :)
 
If you don't want to get some of your own webspace, I suppose I
could make some space available on my website. You'd have to email
me the files for me to upload for you.
 
-- 
J.G.Harston - jgh@...                - mdfs.net/User/JGH
BBC BASIC for 30+ platforms - http://mdfs.net/Software/BBCBasic
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>