Is there any way to have Ctrl-C interrupt a BIN program like it does
a Basic program? I know Ctrl-Reset will do it, but that messes up
the screen and probably other things too.
It's not a system feature; it doesn't send a signal the way a UNIX
line discipline does.
Just some thoughts. Maybe none of them are appealing.
I'm assuming you're not using a IIgs where you can interrupt and
Visit the Monitor.
A simple method would be to just poll $C000, then place JSR's to this
routine where you would want the keyboard to be interrupted. Say,
after a page of text is displayed or even throughout your code at
various places.
I am working on a Apple II/e/c program with the cc65 C compiler. I can
check for Ctrl-C in various places.
In this case I suggest to use
- kbhit() and cgetc() to detect the Ctrl-C
- exit() to quit if Ctrl-C was detected
- atexit() to run custom cleanup code
Thanks!
I was thinking of using an asm block to check KBD for
characters. What you said is much better.
I also forgot about atexit().
I need to put that in now to close files. It's like the "finally" block
of a try/catch/finally around main(). I'm a Java programmer during the
day.
You don't need to do so for closing files. All still open files are
closed by the C library exit code.
That code is by the way also executed on Ctrl-Reset during the
runtime of a cc65 C program. So the behavior on Ctrl-Reset isn't as undefined/fatal as you might think.
I even had once the case where I totally ran out of memory so I
couldn't add some quit code. Instead I simply documented Ctrl-Reset
as the official way to quit the program ;-)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (1 / 15) |
Uptime: | 160:10:12 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,056 |
Messages: | 6,416,492 |