Applesoft Searcher
Ilan Reuben
Here's a short but very handy (and fast) programming utility written entirely in machine language. With it, you can instantly locate key statements and phrases in your programs. It works on any Apple with at least 48K RAM and a disk drive.
Many BASIC programs are constructed and debugged by adding new sections and routines to existing sections and routines. As a result, these programs can become excessively long and complex. Debugging becomes a real mess when you have to sift through 2000 lines of BASIC to find a certain routine or statement.
"Applesoft Searcher" is a machine language utility which will scan any BASIC program for all the references to a phrase you specify, and tell you where each reference is—all in the blink of an eye. The machine language program itself is just over a page (256 bytes) in length, and resides at memory location 36864 ($9000 in hexadecimal). If you know little or nothing about machine language, don't worry; you can use Applesoft Searcher as long as you can type in a BASIC program and follow a few simple directions.
Using The Searcher
First, let's get Applesoft Searcher up and running. If you feel more comfortable with BASIC and would like to load the utility as a BASIC program, type in Program 1, the BASIC loader. It's a good idea to save it just in case. Now run it. This puts the machine language portion of the utility into memory, and it remains there even after you erase the BASIC loader. Next, save the machine language portion on disk by typing:
BSAVE SEARCHER, A$9000, L$109
If you'd rather enter Searcher into the computer directly, you can use the monitor listing (Program 2) and save it as shown above. In the future, to load Searcher from disk, type:
BLOAD SEARCHER
Once you have it in memory, you must set the & vector to the start of the program. This lets you run Searcher every time you type &. From BASIC, type:
POKE 1014, 0 : POKE 1015, 144
or from the monitor type:
3F6 : 0 90
Searcher should now be ready to use. Here is a sample BASIC program to show how it works.
10 PRINT "THIS IS A TEST" 20 FOR A = 1 TO 10 30 PRINT A + 10 40 NEXT A
Suppose you want to find all the references to the variable A in the program. You would type:
& A
and the computer would respond with:
FOUND AT LINE 10 FOUND AT LINE 20 FOUND AT LINE 30 FOUND AT LINE 40
To find all the lines in which the number 10 appears, type:
& 10
Searcher will hunt through the program and report:
FOUND AT LINE 20 FOUND AT LINE 30
Notice that line 10 was not included even though there is a 10 in its line number. This is because Searcher ignores line numbers.
Selective Searching
To specify a range of lines for Searcher to look through, type # after the & along with the starting and ending line numbers and the phrase to search for:
$ #20, 30, PRINT
This would search lines 20 through 30 for a PRINT statement.
One more thing about Searcher: It must be used only in direct mode, not in deferred mode (that is, you cannot call it from a BASIC program). If you try, the message ?NOT DEFERRED COMMAND ERROR will be displayed.
If you'd like to have Applesoft Searcher ready to use every time you boot your system, type in the BASIC setup routine (Program 3) and use it as a hello program when initializing disks. Just make sure that you've got the machine language for Searcher saved on that disk.
Program 1: Applesoft Searcher (BASIC Loader)
10 FOR X = 36864 TO 37129 20 READ Y : CK = CK + Y 30 POKE X,Y 40 NEXT X 50 IF CK < > 36799 THEN PRINT "CHECK DATA STATEMENTS FOR TYPING ERRORS" 100 DATA 165, 185, 201, 2, 240, 11, 169, 15, 3, 2, 204 110 DATA 144, 32, 25, 237, 76, 60, 212, 32, 18, 3, 0 120 DATA 201, 35, 208, 40, 32, 177, 0, 32, 103, 221 130 DATA 32, 82, 231, 165, 80, 133, 8, 165, 81, 133 140 DATA 9, 32, 190, 222, 32, 103, 221, 32, 82, 231 150 DATA 165, 80, 133, 10, 165, 81, 133, 11, 3, 2, 190 160 DATA 222, 76, 75, 144, 160, 0, 132, 8, 132, 9 170 DATA 136, 132, 10, 132, 11, 160, 255, 198, 184, 32 180 DATA 177, 0, 201, 34, 208, 8, 165, 193, 73, 233 190 DATA 133, 193, 169, 34, 200, 153, 10, 145, 201, 0 200 DATA 208, 233, 132, 6, 169, 239, 133, 193, 165, 8 210 DATA 133, 80, 165, 9, 133, 81, 32, 26, 214, 169 220 DATA 3, 133, 7, 230, 7, 164, 7, 162, 0, 177 230 DATA 155, 240, 27, 221, 10, 145, 208, 241, 200, 232 240 DATA 228, 6, 208, 241, 169, 0, 32, 204, 144, 160 250 DATA 2, 177, 155, 170, 200, 177, 155, 32, 36, 237 260 DATA 160, 0, 177, 155, 72, 200, 177, 155, 133, 156 270 DATA 104, 133, 155, 177, 155, 240, 10, 16, 0, 3, 177 280 DATA 155, 197, 11, 240, 8, 144, 188, 169, 141, 32 290 DATA 240, 253, 96, 136, 177, 155, 197, 10, 240, 175 300 DATA 144, 173, 176, 239, 170, 169, 141, 32, 240, 253 310 DATA 189, 222, 144, 240, 6, 32, 240, 253, 232, 208 320 DATA 245, 96, 198, 207, 213, 206, 196, 16, 0, 193, 212 330 DATA 160, 204, 201, 206, 197, 160, 0, 135, 191, 206 340 DATA 207, 212, 160, 196, 197, 198, 197, 2, 10, 210, 197 350 DATA 196, 160, 195, 207, 205, 205, 193, 206, 196, 160 360 DATA 197, 210, 210, 207, 210, 0
Program 2: Applesoft Searcher (Monitor Listing)
9000- A5 B9 C9 02 F0 0B A9 0F 9008- 20 CC 90 20 19 ED 4C 3C 9010- D4 20 B7 00 C9 23 D0 28 9018- 20 B1 00 20 67 DD 20 52 9020- E7 A5 50 85 08 A5 51 85 9028- 09 20 BE DE 20 67 DD 20 9030- 52 E7 A5 50 85 0A A5 51 9038- 85 0B 20 BE DE 4C 4B 90 9040- A0 00 84 08 84 09 88 84 9048- 0A 84 0B A0 FF C6 B8 20 9050- B1 00 C9 22 D0 08 A5 C1 9058- 49 E9 85 C1 A9 22 C8 99 9060- 0A 91 C9 00 D0 E9 84 06 9068- A9 EF 85 C1 A5 08 85 50 9070- A5 09 85 51 20 1A D6 A9 9078- 03 85 07 E6 07 A4 07 A2 9080- 00 B1 9B F0 1B DD 0A 91 9088- D0 F1 C8 E8 E4 06 D0 F1 9090- A9 00 20 CC 90 A0 02 B1 9098- 9B AA C8 B1 9B 20 24 ED 90A0- A0 00 B1 9B 48 C8 B1 9B 90A8- 85 9C 68 85 9B B1 9B F0 90B0- 0A A0 03 B1 9B C5 0B F0 90B8- 08 90 BC A9 8D 20 F0 FD 90C0- 60 88 B1 9B C5 0A F0 AF 90C8- 90 AD B0 EF AA A9 8D 20 90D0- F0 FD BD DE 90 F0 06 20 90D8- F0 FD E8 D0 F5 60 C6 CF 90E0- D5 CE C4 A0 C1 D4 A0 CC 90E8- C9 CE C5 A0 00 87 BF CE 90F0- CF D4 A0 C4 C5 C6 C5 D2 90F8- D2 C5 C4 A0 C3 CF CD CD 9100- C1 CE C4 A0 C5 D2 D2 CF 9108- D2 00
Program 3: Applesoft Searcher (Hello Program)
10 D$ = CHR$ (4) : REM CTRL - D 20 PRINT D$ "BLOAD SEARCHER" 30 POKE 1014, 0 : POKE 1015, 144 40 REM ^ SET & VECTOR ^ 50 PRINT "‘SEARCHER’ ENABLED"