Classic Computer Magazine Archive PROGRAM LISTING: 83-04/TRACE.LST


31000 TRAP 31046
31002 REM 
31004 REM BASIC TRACE UTILITY
31006 REM ALAN FILIPSKI 1982
31008 REM 
31010 REM FIND START OF STMNT TABLE
31012 DBGST=PEEK(136)+256*PEEK(137)
31014 REM SET ERR IN EACH STMNT
31016 GOSUB 31152
31018 ? " ":? "BASIC TRACE UTILITY":? " "
31020 ? "ENTER LINE NUMBER AT WHICH"
31022 ? "EXECUTION IS TO START"
31024 ? "(FIRST LINE IN PROG IS ";PEEK(DBGST)+256*PEEK(DBGST+1);")"
31026 INPUT DBGSTART
31028 REM CLR ARRAYS IF STARTING AT FIRST STATEMENT
31030 IF DBGSTART<>PEEK(DBGST)+256*PEEK(DBGST+1) THEN 31038
31032 CLR :DBGST=PEEK(136)+256*PEEK(137)
31034 REM RESTORE DBGSTART
31036 DBGSTART=PEEK(DBGST)+256*PEEK(DBGST+1)
31038 ? "HOW MANY LINES TO TRACE ":INPUT DBGTC
31040 IF DBGTC<=0 THEN 31064
31042 GOTO DBGSTART
31044 REM TRAP HERE AT EACH ERROR ENCOUNTERED
31046 DBGST=PEEK(136)+256*PEEK(137)
31048 IF PEEK(195)=17 THEN 31054
31050 REM UNEXPECTED ERROR TYPE
31052 ? "ERR TYPE ";PEEK(195);" AT LINE ";PEEK(186)+256*PEEK(187):GOTO 31064
31054 IF DBGTC>0 THEN 31072
31056 ? "HOW MANY MORE ";
31058 INPUT DBGTC
31060 IF DBGTC>0 THEN 31072
31062 REM TIME TO QUIT. REMOVE ERRS
31064 GOSUB 31212
31066 ? "TRACE ABORTED"
31068 STOP 
31070 REM REINTRODUCE ERR INTO CLEARED "FOR" OR "GOSUB"
31072 IF DBGSAV1=0 THEN 31086
31074 DBGSAV1=DBGSAV1+DBGST:IF PEEK(DBGSAV1+4)=55 THEN 31086
31076 DBGEOL=DBGSAV1+PEEK(DBGSAV1+2)-1
31078 DBGCOM=DBGSAV1+4
31080 POKE DBGEOL,PEEK(DBGEOL)+PEEK(DBGCOM)
31082 POKE DBGCOM,55
31084 REM REINTRODUCE ERR INTO LAST STATEMENT EXECUTED
31086 DBGSAV2=DBGSAV2+DBGST:IF PEEK(DBGSAV2+4)=55 THEN 31098
31088 DBGEOL=DBGSAV2+PEEK(DBGSAV2+2)-1
31090 DBGCOM=DBGSAV2+4
31092 POKE DBGEOL,PEEK(DBGEOL)+PEEK(DBGCOM)
31094 POKE DBGCOM,55
31096 REM CLEAR ERR FROM "FOR" OR "GOSUB" ON TOP OF RUNSTK
31098 DBGSAV1=0
31100 IF PEEK(142)=PEEK(144) AND PEEK(143)=PEEK(145) THEN 31114
31102 DBGTOP=PEEK(144)+256*PEEK(145)
31104 DBGLN1=PEEK(DBGTOP-3)
31106 DBGLN2=PEEK(DBGTOP-2)
31108 GOSUB 31176
31110 DBGSAV1=DBGPTR-DBGST
31112 REM FIND STATEMENT WHICH TRIGGERED TRAP AND CLEAR ERR
31114 DBGLN1=PEEK(186)
31116 DBGLN2=PEEK(187)
31118 GOSUB 31176
31120 DBGSAV2=DBGPTR-DBGST
31122 REM ***************************
31124 REM INSERT USER PRINT STATEMENTS HERE
31126 REM ***************************
31128 REM LIST TRAPPED STMNT
31130 LIST PEEK(DBGPTR)+256*PEEK(DBGPTR+1)
31132 TRAP 40000:TRAP 31046
31134 DBGTC=DBGTC-1
31136 REM IF STMNT IS END OR STOP, CLEAR ALL STATEMENTS
31138 IF PEEK(DBGPTR+4)=21 OR PEEK(DBGPTR+4)=38 THEN GOSUB 31212
31140 REM EXECUTE STATEMENT
31142 GO TO PEEK(DBGPTR)+PEEK(DBGPTR+1)*256
31144 REM 
31146 REM SUB TO SET ERRS
31148 REM SET COMMAND TOKEN IN ALL USER STATEMENTS (EXCEPT DATA STATEMENTS) TO 55 (=ERROR)
31150 REM SAVE ORIGINAL USER COMMAND BY ADDING TO END-OF-LINE BYTE
31152 DBGPTR=DBGST
31154 IF PEEK(DBGPTR+4)=55 OR PEEK(DBGPTR+4)=1 THEN 31164
31156 DBGEOL=DBGPTR+PEEK(DBGPTR+2)-1
31158 DBGCOM=DBGPTR+4
31160 POKE DBGEOL,PEEK(DBGEOL)+PEEK(DBGCOM)
31162 POKE DBGCOM,55
31164 DBGPTR=DBGPTR+PEEK(DBGPTR+2)
31166 IF PEEK(DBGPTR)+256*PEEK(DBGPTR+1)<31000 THEN 31154
31168 RETURN 
31170 REM 
31172 REM SUBROUTINE TO FIND STMNT AND REMOVE ERR.  2-BYTE LINE NO. EXPECTED IN DBGLN1 AND DBGLN2.
31174 REM PTR TO LINE IS RETURNED IN DBGPTR.
31176 DBGPTR=DBGST
31178 IF DBGLN1=PEEK(DBGPTR) AND DBGLN2=PEEK(DBGPTR+1) THEN 31186
31180 DBGPTR=DBGPTR+PEEK(DBGPTR+2)
31182 GOTO 31178
31184 REM REMOVE ERR
31186 IF PEEK(DBGPTR+4)<>55 THEN RETURN 
31188 DBGEOL=DBGPTR+PEEK(DBGPTR+2)-1
31190 DBGCOM=DBGPTR+4
31192 IF PEEK(DBGEOL)>100 THEN 31200
31194 POKE DBGCOM,PEEK(DBGEOL)-22
31196 POKE DBGEOL,22
31198 RETURN 
31200 POKE DBGCOM,PEEK(DBGEOL)-155
31202 POKE DBGEOL,155
31204 RETURN 
31206 REM 
31208 REM SUBROUTINE TO CLEAR ALL ERRORS
31210 REM 
31212 DBGSAVE=DBGPTR:DBGPTR=DBGST
31214 IF PEEK(DBGPTR+4)<>55 THEN 31228
31216 DBGEOL=DBGPTR+PEEK(DBGPTR+2)-1:DBGCOM=DBGPTR+4
31218 IF PEEK(DBGEOL)>100 THEN 31226
31220 REM NON-REM LINE HAS 22 FOR EOL
31222 POKE DBGCOM,PEEK(DBGEOL)-22:POKE DBGEOL,22:GOTO 31228
31224 REM REM LINE HAS 155 FOR EOL
31226 POKE DBGCOM,PEEK(DBGEOL)-155:POKE DBGEOL,155
31228 DBGPTR=DBGPTR+PEEK(DBGPTR+2)
31230 IF PEEK(DBGPTR)+256*PEEK(DBGPTR+1)<31000 THEN 31214
31232 DBGPTR=DBGSAVE
31234 RETURN 

Back to previous page