Page 1 of 1

Newbie advice - clean assembly code termination

Posted: Sat Jan 28, 2023 7:46 am
by MartinC
Hi all,

In my first project when I want the program to end, I reset the screen colours to standard, clear the screen and point the customer character set back to the standard ROM characters. Is there a best practice around termination and "garbage collection"? For example my instinct is to try and call a soft reset. I've found threads about NMI and resets - could someone maybe share a code sample as interrupt disabling etc is a bit advanced for me yet. :D

Many thanks

Martin

Re: Newbie advice - clean assembly code termination

Posted: Sat Jan 28, 2023 8:23 am
by Mike
MartinC wrote:[...] i reset the screen colours to standard, clear the screen and point the customer character set back to the standard ROM characters. [...]
Doing a JSR $E518, which is part of the reset sequence and inits screen and keyboard services, takes care of those.
Is there a best practice around termination and "garbage collection"?
If you are working with files, you would call first CLRCHN ($FFCC) to revert I/O to standard (keyboard and screen) and then close all open files. There is the routine CLALL, which however only does half the job, so to speak. Here is a better alternative to CLALL: link.

If you do anything concerning the VIAs, (re-)initializing them with JSR $FDF9 (which is also part of the reset sequence) is also a save bet on program exit.
For example my instinct is to try and call a soft reset.
If there is a lot you would have to re-initialize, a soft reset is probably the simplest solution. The caveat regarding open files still applies (a reset while them still being open for write access on a disk drive will render them non-working).

Lots of programs, especially games, don't even bother. You have to switch off the VIC-20 to terminate them. Even if a program seems to exit cleanly, people often follow up with a manual reset or power cycle to remove all possible "remnants" the exited program might have left.

Re: Newbie advice - clean assembly code termination

Posted: Sun Jan 29, 2023 11:03 am
by MartinC
Thanks for the tips. I will be doing i/o on the user port eventually, so all relevant. :D

Re: Newbie advice - clean assembly code termination

Posted: Mon Jan 30, 2023 9:35 am
by chysn
I usually fall into the "don't even bother" camp. I'll set the NMI vector to restart the program, and the user has to power-cycle or push a reset button to get out. Otherwise, allowing a user to exit with STOP/RESTORE usually works.

If I'm using a machine language utility program from BASIC, a simple

Code: Select all

RTS
does the trick.

Re: Newbie advice - clean assembly code termination

Posted: Mon Jan 30, 2023 9:36 am
by groepaz
Or point the nmi vector to RESET :)