Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A library should be written to save and restore BASIC ZP on commodore #343

Open
mysterymath opened this issue Jun 25, 2024 · 4 comments
Open
Labels
enhancement New feature or request p2

Comments

@mysterymath
Copy link
Member

For context, see #341 and #315.

Our current commodore targets clobber BASIC ZP. This does seem a reasonable default behavior for a C program: it's like BASIC, but unlike the KERNAL, so it should clobber BASIC but preserve the KERNAL. The commodore targets used to exit by returning to a possibly broken BASIC, but #341 changes them to infinitely loop instead.

It may still be desirable to be able to return to BASIC. This would either require not using the BASIC area, or saving and restoring the BASIC ZP to a buffer. The latter seems more appropriate for a C program. Accordingly, we should see if there's a way to create a library, includable with -lsave-basic, that can save and restore ZP before and after main, across the various commodore targets.

@asiekierka
Copy link
Contributor

I agree. One small side note - perhaps the more appropriate behavior for a C= program would be to jump to the reset vector, as opposed to infinitely looping?

@mysterymath
Copy link
Member Author

I agree. One small side note - perhaps the more appropriate behavior for a C= program would be to jump to the reset vector, as opposed to infinitely looping?

This came up in discussion, and it's only a slight preference on my part. The benefit of warm restart is that the machine is interactive on exit without a hardware reboot; the disadvantage is that any output on screen is cleared. Metaphorically, there isn't really an environment to return to if BASIC is replaced, so looping is vaguely akin to a kernel panic or exit, as it retains a message indicating what happened. This should also just be a question of defaults; it should already be relatively straightforward to provide reset on exit behavior (perhaps this would also make a good library in the SDK?).

@johnwbyrd
Copy link
Member

This may be too obvious to write, but it seems natural that more platforms than Commodore could benefit from having the option to save and restore zero page. Seems like the sort of thing you might want to opt into, per platform or per project.

Personally, I feel that graceful exit should be the default on all platforms, but reasonable people may disagree.

@mysterymath
Copy link
Member Author

If saving/restoring a ZP region can guarantee a clean exit, then:

  • Return to the exit environment requires those ZP values not to have changed, and
  • No interaction between the program and the exit environment can change those ZPs.

That limits the desired applicability of the technique somewhat. It's not particularly applicable on Atari DOS programs, for example, since the program may continually interact with the DOS, and the DUP (menu) can be freely overwritten, since the DOS detects this and reloads it on exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2
Projects
None yet
Development

No branches or pull requests

3 participants