Page 2 of 2
Re: protocol to close/quit a game?
Posted: Tue Jul 04, 2023 4:26 pm
by Daedalus
Could you just JMP ($FFFC)?
I had thought of that. When I tried it, it failed miserably (core dump, emulator shut down, etc.) At the time, I didn't care enough to debug it further.
Trying it now, it's obvious why it broke... The reset vector at $FFFC is only there if ROM bank 0 is set. By default, the system sets the ROM bank to 4, because it is, at it's heart, a BASIC centric system. So you gotta set the ROM bank to 0 prior to jumping to ($FFFC)
So:
Tom's solution works without doing that because both ROM bank 0 and ROM bank 4 have vectors at $FE9C (They go to different places, because one is bank 0 actual and one has to switch to it.)
Re: protocol to close/quit a game?
Posted: Tue Jul 04, 2023 5:06 pm
by desertfish
My experience with calling the software reset vector is that not everything of the system is reset to its initial state.
Not all of Vera and the FM audio chip is reset.
The more reliable way to reset the system really is via the SMC.
Also, after a reset, don't forget you can simply type OLD to restore the previous Basic program. A simple RUN after that might restart the game again! So you can modify stuff in memory in between and see what it does
Re: protocol to close/quit a game?
Posted: Tue Jul 04, 2023 6:22 pm
by DragWx
Yeah, I think that's what I'll do in my games, I'll just trigger a reset via the SMC when it's time to exit. Though, the SMC also gives you a "power off" command, so I dunno if anyone would be interested in being able to power off from a game's main menu, but it's certainly possible.
One thing I just thought of; if your program is an autobooting ROM cartridge, simply resetting the computer won't allow you to boot back into BASIC, but having a "terminate program" vector in the kernal might be able to provide such functionality.
Re: protocol to close/quit a game?
Posted: Tue Jul 04, 2023 6:48 pm
by ahenry3068
Part of the beauty of 8 bit systems is the very quick start up.
My main system is a 4 core 3.6 ghz i7.. But it takes minutes to start up in Windows 10
and only slightly less in Linux Mint.
The commander X16 is at the splash screen in < 2 seconds.
Re: protocol to close/quit a game?
Posted: Tue Jul 04, 2023 11:32 pm
by Daedalus
DragWx wrote: ↑Tue Jul 04, 2023 6:22 pm
Yeah, I think that's what I'll do in my games, I'll just trigger a reset via the SMC when it's time to exit. Though, the SMC also gives you a "power off" command, so I dunno if anyone would be interested in being able to power off from a game's main menu, but it's certainly possible.
One thing I just thought of; if your program is an autobooting ROM cartridge, simply resetting the computer won't allow you to boot back into BASIC, but having a "terminate program" vector in the kernal might be able to provide such functionality.
I concur, I'm using the code Tom posted, but I slapped a "switch to ROM bank 0" in it first just so I don't get bit when I try some kind of weird ROM bank shenanigans.
Also, on auto booting ROM cartridges, having it just shut the system down from the main menu, with a warning to NOT unplug the cartridge with the power on just seems prudent.