freetz Posted August 15, 2022 Share Posted August 15, 2022 Hi everyone, I have yet to find a comprehensive list of zero page addresses used by BASIC that states more than for example what "Mapping" describes, such as the 146 to 202 range. Yes, I could go through the BASIC source code listing, but before doing that, I wanted to ask for your help. I'm working on a machine language utility that should reside in page 6 and works with a buffer (at least 30-40 bytes) that I would like to store in the zero page in order to save code space by using zero page addressing. I was thinking that despite some memory locations being used by BASIC, I might be able to use them while running the utility because BASIC code is not running at the same time. For example the current BASIC statement pointer in STMCUR or STOPLN are probably dynamically used, so I assume I could use them safely until the utility returns to BASIC. On the other hand, PTABW (201) would make the ATARI crash if set to 0 after a subsequent comma-generated printed tabulator, as this is value is not recreated by BASIC. But what about the zero page floating point locations? I would assume these are only used when a FP operation is executed. Or are there locations that carry a certain value that is reused in every FP operation? Then this would be out of the question, too. Related question: If zero page is not an option for this buffer, is there a safe way to determine which RAM is not used by BASIC - across all machines from 400 to 800XL? Can I safely assume that the area above BASIC MEMTOP (144, 145) and below OS MEMTOP (741, 742) can safely be used temporarily by my utility? The data stored there can safely be overwritten by BASIC if the BASIC program grows. Do I have to add 1 to BASIC MEMTOP for the first safe location or is BASIC MEMTOP already the first free location? Thanks for any suggestions! Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 15, 2022 Share Posted August 15, 2022 This is assuming a simple USR() call - stuff like DLIs and VBlank NMIs coexist with a running program so would be very restricted. If no CIO operations are taking place then you could use $20-$2F. $30-$40 is mainly used by SIO and should be able to be safely used. Some other various locations 0-7F can be used but it should be noted that normal allocation of some locations varies depending on OS version. Locations under $14 you want to stay well clear of. Also note most of the lower z-page is cleared on warmstart. Locations $80-$91 are Basic program pointers which you'd never want to modify - the main danger being if you press Reset while the value isn't valid you'd cause corruption. $92-$CA are various Basic work variables, some of which you could modify but some of which might cause a problem if changed. $CB-$D1 are spare and free to use. $D2-D3 used by Basic. $D4-$F2 used by Floating Point - you could trash these without isse. But $D4-$D5 is the returned value of the USR call which you might want to set to some value or return code. $F3-$FF you could probably use without issue also. Note that practically any location you use aside from the mentioned spare/free bytes won't be guaranteed to be preserved once your Basic program resumes after a USR() call. One thing you could do is copy the work area you want to use somewhere else then restore it on exit. But you have to assume your program might be interrupted by a Reset press which would mean the restore operation is skipped. Quote Link to comment Share on other sites More sharing options...
freetz Posted August 15, 2022 Author Share Posted August 15, 2022 Thanks! Yes, the idea is to call it via X=USR(1536) and it's only a buffer, so it doesn't have to be preserved after exiting the program. So $D4-$FF sound like a large enough area for me to use, thanks! Quote Link to comment Share on other sites More sharing options...
+CharlieChaplin Posted August 15, 2022 Share Posted August 15, 2022 Maybe usefull for you... (in front of your program) $0400-447 - switches Basic off - clears zero page - clears RAM under Basic $0244-0244 Reset = coldstart $0400-041E shows a black screen during loading (screen is NOT switched off!) And errm, after executing, page 4 is available again and can be used by your program (or packer/depacker). CLEARZP.XEX Quote Link to comment Share on other sites More sharing options...
freetz Posted August 15, 2022 Author Share Posted August 15, 2022 Thanks, but the idea is to call the utilty from BASIC and return to BASIC, so switching BASIC off etc. would go against the purpose ;)... Quote Link to comment Share on other sites More sharing options...
phaeron Posted August 16, 2022 Share Posted August 16, 2022 The floating point area is mostly safe to use during a USR() call, but there is one location to watch out for -- $FB contains the degree/radian flag, and needs to be preserved/reset or else trig functions will break. 1 Quote Link to comment Share on other sites More sharing options...
freetz Posted August 16, 2022 Author Share Posted August 16, 2022 Great, that's good to know, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.