Date : Sun, 05 Oct 2008 00:39:37 +0100
From : jgh@... (Jonathan Graham Harston)
Subject: Save location for temp variables.
Phill Harvey-Smith wrote:
> Ok, so next question is this, the ROM code I'm working on will need to
> store a couple of temp variables, I could request a page of private
[snip]
> So is there a convenient place I can save a few bytes whilst in my ROM
> code ? This is mainly for parsing the command line passed to my
> commands, and the binary parameters for my code, e.g. I'm working on a
> command thus
>
> *SRZAP <id> (<id>)
The area at &A8 to &AF is specified as for use by *commands. Eg,
something like, for transient code:
lptr=&A8:rom=&AA
LDX #lptr:LDY #0:LDA #1:JSR OSARGS
LDA (lptr),Y
CMP #ASC"0":BCC errSyntax
CMP #ASC"F"+1:BCS errSyntax
CMP #ASC"9"+1:BCC wipe_go
CMP #ASC"A":BCC errSyntax
SBC #6
.wipe_go
AND #15:STA rom
or, for ROM-base code:
lptr=&F2:rom=&AA
LDA (lptr),Y
CMP #ASC"0":BCC errSyntax
CMP #ASC"F"+1:BCS errSyntax
CMP #ASC"9"+1:BCC wipe_go
CMP #ASC"A":BCC errSyntax
SBC #6
.wipe_go
AND #15:STA rom
&900-&AFF are the serial/cassette buffers. They are conventionally
used to load transient *commands. Perfectly safe if you're not
using the serial port, or BPUT/BGETing from tape. (Note: LOAD/SAVE
from tape do **NOT** use &900-&AFF, contrary to what a lot of
documentation implies.)
**DON'T** use any zero-page locations above &8F. They **are** used
by other systems and you **will** crash things, even if you save
and restore them.
Any other memory locations, it's best to stack them before use, and
restore them afterwards, eg:
LDX #31 :\ need 32 bytes of workspace
.savelp
LDA &70,X:PHA:DEX:BPL savelp
...do stuff...
LDX #&E0
.restlp
PLA:STA &50,X:INX:BNE restlp
**Don't** do the common mistake of thinking that &70-&8F being
"reserved for use by BASIC user programs" means "reserved for use
by user programs". It's only available to code being called **from
BASIC**. Any language has carte blanche to use &00-&8F for whatever
it wants.
--
J.G.Harston - jgh@... - mdfs.net/User/JGH
**** DO NOT EMPLOY MARREN BUILDERS/ROOFERS, SHEFFIELD ****