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.
Many thanks
Martin
Newbie advice - clean assembly code termination
Moderator: Moderators
-
- Vic 20 Drifter
- Posts: 33
- Joined: Tue Oct 25, 2022 12:18 pm
- Website: https://winterfam.co.uk
- Location: Kent,uk
- Occupation: Author
- Mike
- Herr VC
- Posts: 4852
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Newbie advice - clean assembly code termination
Doing a JSR $E518, which is part of the reset sequence and inits screen and keyboard services, takes care of those.MartinC wrote:[...] i reset the screen colours to standard, clear the screen and point the customer character set back to the standard ROM characters. [...]
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.Is there a best practice around termination and "garbage collection"?
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.
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).For example my instinct is to try and call a soft reset.
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.
-
- Vic 20 Drifter
- Posts: 33
- Joined: Tue Oct 25, 2022 12:18 pm
- Website: https://winterfam.co.uk
- Location: Kent,uk
- Occupation: Author
Re: Newbie advice - clean assembly code termination
Thanks for the tips. I will be doing i/o on the user port eventually, so all relevant.
- chysn
- Vic 20 Scientist
- Posts: 1205
- Joined: Tue Oct 22, 2019 12:36 pm
- Website: http://www.beigemaze.com
- Location: Michigan, USA
- Occupation: Software Dev Manager
Re: Newbie advice - clean assembly code termination
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
does the trick.
If I'm using a machine language utility program from BASIC, a simple
Code: Select all
RTS
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5
WIP: MIDIcast BASIC extension
he/him/his
WIP: MIDIcast BASIC extension
he/him/his
Re: Newbie advice - clean assembly code termination
Or point the nmi vector to RESET
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.