protocol to close/quit a game?

Chat about anything CX16 related that doesn't fit elsewhere
User avatar
Daedalus
Posts: 229
Joined: Fri Nov 11, 2022 3:03 am

Re: protocol to close/quit a game?

Post 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:

Code: Select all

	lda #0
	sta $01
	jmp ($FFFC)
	
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.)
User avatar
desertfish
Posts: 1096
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: protocol to close/quit a game?

Post 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 :)
DragWx
Posts: 342
Joined: Tue Mar 07, 2023 9:07 pm

Re: protocol to close/quit a game?

Post 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. :P

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.
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: protocol to close/quit a game?

Post 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.
User avatar
Daedalus
Posts: 229
Joined: Fri Nov 11, 2022 3:03 am

Re: protocol to close/quit a game?

Post 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. :P

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