Newbie advice - clean assembly code termination

Basic and Machine Language

Moderator: Moderators

Post Reply
MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Newbie advice - clean assembly code termination

Post 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
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Newbie advice - clean assembly code termination

Post 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.
MartinC
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

Post by MartinC »

Thanks for the tips. I will be doing i/o on the user port eventually, so all relevant. :D
User avatar
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

Post 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.
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
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Newbie advice - clean assembly code termination

Post by groepaz »

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.
Post Reply