Classic Computer Magazine Archive COMPUTE! ISSUE 64 / SEPTEMBER 1985 / PAGE 10

Readers Feedback

 The Editors and Readers of COMPUTE!

Disabling Apple's Break Key
According to your answer to Alex Tarlecky's letter in December 1984, the RESET key can be disabled on the Apple IIc with the command POKE 1012,PEEK(1012) AND 10. But is there a way to also disable the CONTROL-C function to keep people from breaking out of my programs?
Mike Sanders

Yes, there is. After Applesoft BASIC executes a program statement, it checks for any errors that might have occurred. At the same time, it checks to see if CTRL-C was pressed. If so, Applesoft responds as it does when it encounters a syntax error or illegal quantity error. Normally, it stops the program and displays an appropriate error message (BREAK IN line#).
    The secret to trapping CTRL-C is an instruction that changes the way Applesoft handles such errors-the ONERR statement. For instance, once the computer executes a statement such as ONERR GOTO 1000, it responds to any error-including the CTRL-C functionby transferring control to line 1000 (or any other line you specify with ONERR). Make sure, however, that the line specified in the ONERR statement actually exists in your program. Otherwise, Applesoft searches for an undefined line when an error happens, causing another error. The result is an endless loop and a lockedup computer.
    You should put an error-handling routine starting at the line number referred to by ONERR. This routine should PEEK location 222, which contains an error code. If this location contains 255, then CTRL-C was pressed. The best way to deal with CTRL-C is to have your error routine GOTO the program's main menu or some other predictable location, so that CTRL-C still causes a break but doesn't stop the program.
    IF PEEK(222) isn't 255, then CTRL-C wasn't pressed-an actual error occurred. This could be a disk error (wrong disk in the drive, no disk, disk full, etc.) or an error in your program. It is usually easier to let Applesoft handle the errors that you aren't expecting. You can do this by POKEing memory location 216 with 0 to cancel the ONERR trap. Then use the Applesoft RESUME instruction, which reexecutes the statement that caused the error in the first place. Since the instruction didn't finish the first time, you should get the same error, but this time the program halts with an appropriate error message.