' *****************
' *** DEBUG.LST ***
' *****************
'
DEFWRD "a-z"
'
> PROCEDURE debug
  ' *** Merge (temporarily) with a program if you need help with debugging
  ' *** activate Procedure Debug in main program with : TRON debug
  ' *** run program, press <Alternate> <Control> <Right Shift> for debug-menu
  ' *** uses VT52-commands (on TOS-screen, not in window)
  ' *** uses Standard Globals
  ' *** Global :  DEBUG.SPEED  DEBUG.TRON!  DEBUG.LINE$  DEBUG.LINES
  LOCAL screen$,dump.par$,scr%,sy,dy
  IF BIOS(11,-1)=13 OR INSTR(TRACE$,debug.line$)
    PRINT CHR$(27)+"j";         ! save current cursor-position
    SGET screen$                ! save screen
    DO
      IF debug.lines<1
        debug.lines=4
      ENDIF
      CLS
      PRINT AT(1,2);" *** GFA-BASIC DEBUGGER ***"
      PRINT
      PRINT " <S> Stop program (Command mode)"
      PRINT
      PRINT " <D> Change TRON-delay"
      PRINT " <L> TRON-lines on screen"
      IF debug.tron!
        PRINT " <T> Switch TRON off"
      ELSE
        PRINT " <T> Switch TRON on"
      ENDIF
      PRINT
      PRINT " <V> Dump variables to screen"
      PRINT " <P> Dump procedures/functions"
      PRINT " <B> Dump labels"
      PRINT
      PRINT " <W> Wait for string (breakpoint)"
      PRINT
      PRINT " <C> Continue with main program"
      PRINT
      PRINT " <Q> Quit program, go to editor"
      PRINT AT(1,20);" Delay = ";debug.speed;"/50 s     TRON = ";
      IF debug.tron!
        PRINT "on (";debug.lines;" lines)"
      ELSE
        PRINT "off"
      ENDIF
      IF debug.line$<>""
        PRINT " Search-string: ";debug.line$
      ENDIF
      '
      IF INSTR(TRACE$,debug.line$)
        PRINT AT(1,23);"String found:"
      ELSE
        PRINT AT(1,23);"Current line:"
      ENDIF
      OUT 5,3
      PRINT " ";TRACE$;
      '
      SELECT UPPER$(CHR$(INP(2)))
      CASE "S"
        KEYPRESS &H1C000D
        STOP
      CASE "D"
        PRINT AT(1,21);SPACE$(80);
        PRINT AT(1,21);" Delay (in 1/50 s): ";
        INPUT "",debug.speed
      CASE "L"
        PRINT AT(1,21);SPACE$(80);
        PRINT AT(1,21);" TRON-lines (ò1): ";
        INPUT "",debug.lines
      CASE "T"
        debug.tron!=NOT debug.tron!
      CASE "V"
        PRINT AT(1,21);SPACE$(80);
        PRINT AT(1,21);" DUMP-Parameter: ";
        INPUT "",dump.par$
        CLS
        PRINT " *** Use <CapsLock> or right <Shift> ***"
        PRINT
        DUMP dump.par$
        PRINT
        PRINT " (Press any key to continue)";
        ~INP(2)
      CASE "P"
        CLS
        PRINT " *** Use <CapsLock> or right <Shift> ***"
        PRINT
        DUMP "@"
        PRINT
        PRINT " (Press any key to continue)";
        ~INP(2)
      CASE "B"
        CLS
        PRINT " *** Use <CapsLock> or right <Shift> ***"
        PRINT
        DUMP ":"
        PRINT
        PRINT " (Press any key to continue)";
        ~INP(2)
      CASE "W"
        PRINT AT(1,21);SPACE$(80);
        PRINT AT(1,21);" Search-string: ";
        INPUT "",debug.line$
      CASE "C"
        EXIT IF TRUE
      CASE "Q"
        EDIT
      ENDSELECT
    LOOP
    SPUT screen$                ! restore screen
    PRINT CHR$(27)+"k";         ! restore cursor
  ENDIF
  '
  PAUSE debug.speed
  '
  IF debug.tron!
    IF debug.lines>1
      scr%=XBIOS(2)                        ! physical screen
      sy=MUL(SUCC(SUB(scrn.lin.max,debug.lines)),char.height)
      dy=SUB(sy,char.height)
      RC_COPY scr%,0,sy,scrn.x.max,MUL(PRED(debug.lines),char.height) TO scr%,0,dy
      PRINT AT(1,scrn.lin.max);"jwK";TRACE$;"kv";
    ELSE
      PRINT AT(1,scrn.lin.max);"jwK";TRACE$;"kv";
    ENDIF
  ENDIF
RETURN
' **********
'
