Probably a dumb question, but I haven't been able to find an answer using the search engine.
What is the correct way to close a game?
For example, in DOS it is common for games to have a "quit" option that closes the game and returns control to the OS.
On X16, if I have a game that modifies the palette, that means I should also consider a routine that restores those values on exit.
On other computers and especially on consoles, the games do not usually have the option to exit, and it is expected that at the end of the game, the hardware must be restarted or turned off, in such a way that it is not necessary to restore any changes that affect the system, How to restore the color palette.
I understand that both are valid options and that it will depend on me, my question is not if it is possible, but rather, what is the expected behavior?
Games with the option to close and return to basic or games that can't be closed unless the hardware is reset?
protocol to close/quit a game?
Re: protocol to close/quit a game?
If we're talking about games written in assembly, I think it'd be OK to just reset the X16 to exit a game, especially one that's meant to "take over" the computer by replacing vectors and using the VERA directly. There's an example in the docs on how to tell the SMC to reset (or power off) the X16, and is what the RESET command from BASIC does, if you wanted to provide an "exit" menu option in your game.
Otherwise, if you did want to try to gracefully return to BASIC, the SYS call that runs your program in the first place is pretty much a JSR that your program can just RTS from. You'd need to restore any vectors you changed (or call RESTOR to reset them back to the kernal's defaults), and you'd need to call CINT to return the VERA to the kernal's default text mode.
I'm not sure if there's any importance to gracefully returning to BASIC though. If it were DOS or CP/M or some kind of fancy operating system, then sure, but BASIC is a pretty simple environment where there's not much to gracefully return to.
Otherwise, if you did want to try to gracefully return to BASIC, the SYS call that runs your program in the first place is pretty much a JSR that your program can just RTS from. You'd need to restore any vectors you changed (or call RESTOR to reset them back to the kernal's defaults), and you'd need to call CINT to return the VERA to the kernal's default text mode.
I'm not sure if there's any importance to gracefully returning to BASIC though. If it were DOS or CP/M or some kind of fancy operating system, then sure, but BASIC is a pretty simple environment where there's not much to gracefully return to.
Re: protocol to close/quit a game?
okie dokie
Thank you very much for your answer.
Thank you very much for your answer.
-
- Posts: 292
- Joined: Wed Jun 03, 2020 11:33 am
- Location: Kalmar, Sweden
Re: protocol to close/quit a game?
I actually take pride in providing the option to quit games even if it is not important. And it is not hard. In the game I am working on now, this is what I do:
Disable sprites
Restore screen settings
Restore the first 16 colors of the palette
Restore the character set (by printing "142" with kernal routine BSOUT)
Clear text screen (by printing "147" with BSOUT)
Restoring interrupt vectors
You might have to reset some of your own variables too in case the user restarts the game. But it is not necessary for me. I offer the option to quit in the main menu and all variables related to game play are (of course) initialized each time the user chooses to start a new game. Settings keep their values if you quit and restart the game.
Disable sprites
Restore screen settings
Restore the first 16 colors of the palette
Restore the character set (by printing "142" with kernal routine BSOUT)
Clear text screen (by printing "147" with BSOUT)
Restoring interrupt vectors
You might have to reset some of your own variables too in case the user restarts the game. But it is not necessary for me. I offer the option to quit in the main menu and all variables related to game play are (of course) initialized each time the user chooses to start a new game. Settings keep their values if you quit and restart the game.
Re: protocol to close/quit a game?
IMO every game should provide a "quit" option. Even if that option just sends a reset or reboot message to the SMC.
In the meantime, you can do one of the following, arranged in order of least to most disruptive:
In the meantime, you can do one of the following, arranged in order of least to most disruptive:
- Use the NMI button to exit to basic.
- Use the Control+Alt+Delete keys to trigger a reset via the SMC
- Use the RESET button to reboot the computer.
- Power cycle the computer.
Re: protocol to close/quit a game?
As a point of interest, the DOS kernel provides an API for when programs want to terminate back to DOS; interrupt 20h, or 21h(00h), or 21h(4Ch) if you want to terminate with a return code.
I think adding a similar API call to the kernal could help keep the door open for people who might want to develop alternative operating environments (like a launcher menu or a persistent GUI) that could benefit from a program gracefully terminating back to. It could just be another programmable vector in RAM, too.
I think adding a similar API call to the kernal could help keep the door open for people who might want to develop alternative operating environments (like a launcher menu or a persistent GUI) that could benefit from a program gracefully terminating back to. It could just be another programmable vector in RAM, too.
Re: protocol to close/quit a game?
I agree with every game having a "quit" option. It should cleanly shutdown any IRQ handlers and switch back to the BASIC screen, but it is in no way responsible for restoring what was ON that BASIC screen.
What I want is a way to do that with one call... basically a kernal call that essentially executes a cold restart, resulting in all traces of the game being wiped, the VERA reset, and a pristine initial screen displayed with the X-16 butterfly in the corner and everything... as if you'd hit the reset button.
But I can't find that kernal call. Is there one?
As an aside, I also pine for a future where the startup screen isn't BASIC, but rather a program execution shell like a simplified version of unix. It would have to save out it's history to the sdcard prior to running the game, then on reboot restart the shell would restart with the saved history. So it would LOOK like you were in the shell, ran a game program, quit the game and returned to the shell. But in reality the entire machine was dedicated to running your game and the shell are restarted as a result of a reset.
What I want is a way to do that with one call... basically a kernal call that essentially executes a cold restart, resulting in all traces of the game being wiped, the VERA reset, and a pristine initial screen displayed with the X-16 butterfly in the corner and everything... as if you'd hit the reset button.
But I can't find that kernal call. Is there one?
As an aside, I also pine for a future where the startup screen isn't BASIC, but rather a program execution shell like a simplified version of unix. It would have to save out it's history to the sdcard prior to running the game, then on reboot restart the shell would restart with the saved history. So it would LOOK like you were in the shell, ran a game program, quit the game and returned to the shell. But in reality the entire machine was dedicated to running your game and the shell are restarted as a result of a reset.
Re: protocol to close/quit a game?
Could you just JMP ($FFFC)?Daedalus wrote: ↑Tue Jul 04, 2023 12:19 am I agree with every game having a "quit" option. It should cleanly shutdown any IRQ handlers and switch back to the BASIC screen, but it is in no way responsible for restoring what was ON that BASIC screen.
What I want is a way to do that with one call... basically a kernal call that essentially executes a cold restart, resulting in all traces of the game being wiped, the VERA reset, and a pristine initial screen displayed with the X-16 butterfly in the corner and everything... as if you'd hit the reset button.
But I can't find that kernal call. Is there one?
As an aside, I also pine for a future where the startup screen isn't BASIC, but rather a program execution shell like a simplified version of unix. It would have to save out it's history to the sdcard prior to running the game, then on reboot restart the shell would restart with the saved history. So it would LOOK like you were in the shell, ran a game program, quit the game and returned to the shell. But in reality the entire machine was dedicated to running your game and the shell are restarted as a result of a reset.
And I don't know whether it has a command history feature, but there's DesertFish's DOS Shell: https://www.commanderx16.com/forum/view ... hp?p=21483
Re: protocol to close/quit a game?
This does a hardware reset, which should tick every box:
Code: Select all
; Reset system at the end of your program
LDX #$42 ; System Management Controller
LDY #$02 ; magic location for system reset
LDA #$00 ; magic value for system power controller
JSR $FEC9 ; power off or reset the system
-
- Posts: 292
- Joined: Wed Jun 03, 2020 11:33 am
- Location: Kalmar, Sweden
Re: protocol to close/quit a game?
I still like having the possibility to quit a game without everything being wiped out. It is a small invitation to the user to try hacking the game, maybe tweak something, correct a bug, or find out some pokes for cheating. Why would anyone do this? Well, for fun, as a challenge, or for nostalgic reasons : ).