Jump to content
IGNORED

Safe zero page ranges while running machine language program from BASIC


Recommended Posts

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!

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...