Using VIA2 and ISR to "auto-reset" system after N seconds
Posted: Sat Jun 08, 2024 12:01 am
NOTE: for the emulator, you have to run it with the "-via2" command line argument to enable VIA #2.
So an idea occurred to me: suppose I want to demo software on the X16 "non-interactively." That is, suppose I want to rotate between a set of sample titles every few minutes (and suppose that software is just some demo-thing that doesn't require keyboard input). And I want to then rotate/load in another software automatically after the first one finishes, and do so automatically. Sort of like in-store running demos that cycle between software, but without impacting the build of those software titles.
One way I thought to do that is to install an ISR that uses the VIA#2 counter to increment a value in memory every second. When that value reaches my desired wait-time (say 10 seconds), then just invoke a system reset (and then the autoboot.x16 of the system would manage RNG selecting a program and loading it, etc).
So attached is an example that does exactly that, using BASLOAD to set it up. You could BLOAD the asm blobs yourself and not involve BASIC, but the example here is intended where the BASIC MAIN_LOOP would be replaced by the menu-selection or program-choice code if desired.
Basically set $0404 (in golden RAM region not used by BASIC or System ROM) to the number of seconds to wait until the ISR forces a reset. This example is setup to only use a single byte, so max is 255 seconds or a little over 4 minutes.
The code to "install the ISR" (add it into the ISR address chain) is at $0500 (also in Golden RAM). This setup also involves configure the VIA#2 to initiate a 1-second counter (independent of whatever else the system is doing).
The ISR itself is set at $0600 (also in Golden RAM), which monitors the VIA#2 counter to determine if the specified number of seconds has elapsed - and if so, then issue the reset.
NOTE: The following example, just BASLOAD "RNDRESET.BASL.TXT" (don't need to rename it to .BASL but you can), then just RUN it. It shows how to proceed with an interactive BASIC program while it is running. The default demo will automatically reset the system in 10 seconds after running it. Note, despite the name, this isn't really "random" yet - the idea was the value written into $0404 would be a random number of seconds, but I just set it to 10 seconds in this sample.
NOTE: When using on hardware - the VIA#2 hardware has to actually be installed! When I first tested this on hardware, it wasn't working - and turns out it happened to the one X16 that I didn't put the 2MB and VIA#2 chips in! Ha! But it does work on hardware.
So an idea occurred to me: suppose I want to demo software on the X16 "non-interactively." That is, suppose I want to rotate between a set of sample titles every few minutes (and suppose that software is just some demo-thing that doesn't require keyboard input). And I want to then rotate/load in another software automatically after the first one finishes, and do so automatically. Sort of like in-store running demos that cycle between software, but without impacting the build of those software titles.
One way I thought to do that is to install an ISR that uses the VIA#2 counter to increment a value in memory every second. When that value reaches my desired wait-time (say 10 seconds), then just invoke a system reset (and then the autoboot.x16 of the system would manage RNG selecting a program and loading it, etc).
So attached is an example that does exactly that, using BASLOAD to set it up. You could BLOAD the asm blobs yourself and not involve BASIC, but the example here is intended where the BASIC MAIN_LOOP would be replaced by the menu-selection or program-choice code if desired.
Basically set $0404 (in golden RAM region not used by BASIC or System ROM) to the number of seconds to wait until the ISR forces a reset. This example is setup to only use a single byte, so max is 255 seconds or a little over 4 minutes.
The code to "install the ISR" (add it into the ISR address chain) is at $0500 (also in Golden RAM). This setup also involves configure the VIA#2 to initiate a 1-second counter (independent of whatever else the system is doing).
The ISR itself is set at $0600 (also in Golden RAM), which monitors the VIA#2 counter to determine if the specified number of seconds has elapsed - and if so, then issue the reset.
NOTE: The following example, just BASLOAD "RNDRESET.BASL.TXT" (don't need to rename it to .BASL but you can), then just RUN it. It shows how to proceed with an interactive BASIC program while it is running. The default demo will automatically reset the system in 10 seconds after running it. Note, despite the name, this isn't really "random" yet - the idea was the value written into $0404 would be a random number of seconds, but I just set it to 10 seconds in this sample.
NOTE: When using on hardware - the VIA#2 hardware has to actually be installed! When I first tested this on hardware, it wasn't working - and turns out it happened to the one X16 that I didn't put the 2MB and VIA#2 chips in! Ha! But it does work on hardware.