( 8 July 88 -- MFB)

( FILE: TRAP)
( This file, when loaded, redefines BRZ, XLOOP, etc. to check
  console for a control-x.  If a control-x was entered, then
  execution is aborted and control returned to CLI.  The stack
  is also displayed.

  This is useful for recovering control when debugging words
  that go into "endless loops".  A few quirks:

	- When the program is performing console output or
	  input, hit control-x several times to abort.
	- Works only on words defined after this file loaded.
	- Decompiler says (for example) "BRZ OOPS" instead
	  of "BRZ 6200" on words defined after this is loaded.
        - If your potential endless loop is in asm. language,
	  this won't work unless you put a " ' ABRTCK# CALL,"
	  inside the loop. The call destroys DE,HL, and PSW.
)

CODE ABRTCK#
  B PUSH, E FFH MVI, C 6 MVI, 5 CALL, B POP, 18H CPI, ifnz ret, then ( RNZ,)
  :ENTER CRLF " Console Abort. TOS =" ." SP@ .H
  CRLF ( DISPLAY ) CLI ; ASM

ON REDEFINE
CODE BRZ     ' ABRTCK# CALL,  ' BRZ JMP,     ;NOTHREAD ASM
CODE XLOOP   ' ABRTCK# CALL,  ' XLOOP JMP,   ;NOTHREAD ASM
CODE X+LOOP  ' ABRTCK# CALL,  ' X+LOOP JMP,  ;NOTHREAD ASM
CODE XIF[    ' ABRTCK# CALL,  ' XIF[ JMP,    ;NOTHREAD ASM
( code trace   ' abrtck# call,  ' trace jmp,   ;nothread asm)
OFF REDEFINE