Variable Searcher
- Type
- Utility
- Category
- BASIC variable cross-reference utility
- Author
- Steven Anderson
- Published in
- ANALOG Computing, 1987; reissued by GIA Software on the Czech disk magazine Flop, issue 5
- Year
- 1987
- Language
- Atari BASIC loader for a machine-language routine
- Requirements
- Any 8-bit Atari with Atari BASIC (the REMs say 'for all Atari XL/XE'); page 6 must be free
About the program
Long Atari BASIC programs soon raise questions like "which lines still use T2?" and "is FLAG ever set?". Variable Searcher, by Steven Anderson, answers them. It's a cross-reference tool: one USR call prints every variable name in the program in memory, each followed by the numbers of all the lines that use it. It appeared in ANALOG Computing in 1987. The version here is the one the Czech group GIA Software put on the disk magazine Flop 5, with a REM banner saying so.
What you need
Atari BASIC and free use of page 6 (addresses 1536–1791), which is where the routine lives. The REMs say "for all ATARI XL/XE". Apart from page 6, the code only uses the floating-point routines in the OS ROM, which every 8-bit Atari has.
Typing it in
- Lines 10 and 30 draw a box in the REMs with CTRL-Q, CTRL-R, CTRL-E, CTRL-Z and CTRL-C line-drawing characters. They're decoration only, so you can leave them out.
- Line 100 reads exactly 256 numbers into page 6. Lines 1000–1150 supply those 256. Line 1160 adds eight more, a repeat of the end of line 1150, which are never read. They're harmless, so leave them in or drop them.
- A wrong number will usually crash the machine when you call the routine, so SAVE the loader before you RUN it.
How to use it
- RUN the loader. It POKEs the routine into page 6, sets up a short device name ("E:", Atari's screen editor device) in locations 203–206, and stops.
- Type
NEW, thenLOAD(orENTER) the program you want to examine. Page 6 isn't touched by NEW or LOAD. - Type
X=USR(1536)in immediate mode.
The routine opens the screen editor on channel 3 and works through the variable name table (pointer at 130/131). For each variable it prints the name, then scans the tokenized program (pointer at 136/137) and prints the number of the line for every occurrence of that variable's token. A variable used three times in one line gets that line number three times. Don't be surprised to see X at the end of the list with no line numbers. Typing X=USR(1536) created it.
The routine depends on the device name left in locations 203–206, so run the loader again after using any program that changes that zero-page area.
How it works
Atari BASIC stores each variable as a single token byte, from 128 to 255, in the order the variables were first typed. The routine keeps a counter that starts at 128 and rises with each name it prints from the variable name table, so the counter and the name always correspond. To find uses of a variable it walks the program statement by statement and compares each token with the counter. It skips the six-byte BCD numeric constants (token 14) and string literals (token 15, followed by a length byte), so a number that happens to equal the token isn't counted. Line numbers are converted to decimal with the OS floating-point routines IFP (55722, $D9AA) and FASC (55526, $D8E6).
Listing
10 REM {CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}
20 REM | VARIABLE SEARCHER |
30 REM {CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}
40 REM by Steven Anderson
50 REM (c) 1987 ANALOG Computing
60 REM (p) by GIA Software
70 REM for all ATARI XL/XE
80 REM type: X=USR(1536) to activate
90 REM program uses page 6 of memory
100 FOR I=1536 TO 1791:READ D:POKE I,D:NEXT I
110 POKE 203,69
120 POKE 204,58
130 POKE 205,88
140 POKE 206,155
150 END
1000 DATA 165,130,133,0,165,131,133,1,169,127,133,209,162,48,169,203
1010 DATA 157,68,3,104,133,82,157,69,3,157,75,3,169,8,157,74
1020 DATA 3,169,3,157,66,3,32,86,228,160,0,177,0,16,16,41
1030 DATA 127,32,93,6,32,91,6,230,209,32,111,6,32,91,6,32
1040 DATA 93,6,230,0,208,2,230,1,165,0,197,132,208,219,165,1
1050 DATA 197,133,208,213,169,12,141,114,3,208,15,169,155,162,11,142
1060 DATA 114,3,162,0,142,72,3,142,73,3,162,48,76,86,228,165
1070 DATA 136,133,2,165,137,133,3,32,244,6,133,207,32,244,6,133
1080 DATA 208,201,128,176,121,32,244,6,32,244,6,32,244,6,201,2
1090 DATA 176,9,32,244,6,201,155,208,249,240,220,32,244,6,201,20
1100 DATA 240,230,201,27,240,226,201,22,240,205,201,14,208,10,162,6
1110 DATA 32,244,6,202,208,250,240,227,201,15,208,6,32,244,6,170
1120 DATA 208,238,197,209,208,213,165,207,133,212,165,208,133,213,32,170
1130 DATA 217,32,230,216,160,255,132,175,230,175,164,175,192,8,240,187
1140 DATA 177,243,72,41,127,32,93,6,104,16,237,169,160,164,175,200
1150 DATA 145,243,208,228,160,0,177,2,230,2,208,2,230,3,96,0
1160 DATA 230,2,208,2,230,3,96,0
Credits
- Program listing: Variable Searcher — program listing (ANALOG Computing, 1987; reissued by GIA Software on the Czech disk magazine Flop, issue 5) — Steven Anderson
- Picture: The routine run on its own loader: each variable is followed by a line number for every use. — Steven Anderson (program); screenshot by the site
- Gury's Atari 8-bit Forever — Variable Searcher (listing) — Steven Anderson
- Flop disk magazine directory (linked from the Gury entry) — Magazín FLOP
