Classic Computer Magazine Archive COMPUTE! ISSUE 34 / MARCH 1983 / PAGE 185

BASIC Trace For The VIC

Jim Wilcox

A trace program is very helpful as a tool for finding errors, for debugging. It will let the operator see at which line number the program is, while it is running. The programmer can see errors in program flow as well as find the areas where problems are located.

This "Trace" program will adjust to any size memory in the VIC. It uses fewer than 200 bytes of memory. The program will be protected in the uppermost memory positions.

Type in the BASIC program below and double check the DATA statements. Once you're sure the program is right, SAVE it. RUN the program, and in a couple of seconds the screen should show you the SYS values to turn the TRACE on and off. On an unexpanded VIC the following will be printed:

TRACE ON SYS(7501)
TRACE OFF SYS(7488)

If, when you type SYS(7501) on an unexpanded VIC, the machine "crashes," or does something unexpected, something was typed in wrong. The solution is to LOAD the program and correct any mistakes, then try again.

After you've got a working tracer, the program that you would like TRACEd may now be LOADed or typed in. Type in the SYS and hit RETURN to turn the TRACE on and RUN the program. The line numbers will be printed in reverse field.

Trace will help you find bugs faster and correct them. It will also show exactly where a program is operating at any given time during execution.

5 F = 0 : C = PEEK (55) -192 : IFC<0 THEN C = C + 256 : F = -1
10 D = PEEK (56) + F : POKE 55, C : POKE 56, D : CLR
15 N = PEEK (55) + 256 * PEEK (56)
20 F = 0 : FOR D = N TO N + 191 : READ A$ : IF ASC (A$)<58 THEN A = VAL (A$) : GOTO 35
25 IF ASC (A$) = 76 THEN A = VAL (RIGHT$ (A$, LEN(A$) -1)) + PEEK (55) : IF A>255 THEN A = A - 256 : F = 1
30 IF ASC(A$) = 72 THEN A = VAL (RIGHT$ (A$, LEN(A$) -1)) + PEEK (56) + F : F = 0
35 POKED, A : NEXT
40 PRINT"TRACE ON  SYS("N + 13")"
45 PRINT"TRACE OFF SYS("N")" : NEW
50 DATA 169, 230, 133, 115, 169, 122, 133, 116, 169, 208, 133, 117, 96, 169, 255, 141, 61, 3, 169, 76
55 DATA 133, 115, 169, L31, 133, 116, 169, H0, 133, 117, 96, 72, 138, 72, 152, 72, 165, 58, 201, 250
60 DATA 176, 12, 205, 61, 3, 208, 10, 165, 57, 205, 60, 3, 208, 3, 76, L134, H0, 165, 57, 141
65 DATA 60, 3, 141, 62, 3, 165, 58, 141, 61, 3, 141, 63, 3, 169, 18, 32, 210, 255, 169, 32
70 DATA 32, 210, 255, 169, 0, 141, 64, 3, 162, 0, 32, L148, H0, 173, 65, 3, 240, 3, 238, 64
75 DATA 3, 173, 64, 3, 240, 8, 173, 65, 3, 9, 48, 32, 210, 255, 232, 224, 5, 208, 227, 173
80 DATA 64, 3, 208, 5, 169, 48, 32, 210, 255, 169, 146, 32, 210, 255, 104, 168, 104, 170, 104, 230
85 DATA 122, 208, 2, 230, 123, 76, 121, 0, 169, 0, 141, 65, 3, 56, 173, 62, 3, 253, L182, H0
90 DATA 168, 173, 63, 3, 253, L187, H0, 144, 12, 238, 65, 3, 141, 63, 3, 140, 62, 3, 76, L153
95 DATA H0, 96, 16, 232, 100, 10, 1, 39, 3, 0, 0, 0, 32, 56, 53, 32, 4, 1, 20, 1