EASY Apple Screen Editing
Roland Brown
Here's a way to make BASIC programming easier and more fun: an advanced screen editor that makes up for the Apple's lack of full-screen editing. COMPUTE! published an earlier version of this utility, "BASIC Line Editor," in February 1983. This month's all-new version has been updated and enhanced to work on any Apple II-series computer (including the Apple IIc) with DOS 3.3 or ProDOS, in 80-column as well as 40column mode.
Although Applesoft BASIC is a powerful language, its screen editor leaves much to be desired. Some Apple II owners invest in a ROM editor, others write their programs with a word processor, and the rest just suffer with the frustrating ESCape codes. But ROM editors cost money, word processors don't let you flip back and forth between the text editor and BASIC to test changes, and suffering isn't always good for the soul. So here's a better solution: "BASIC Line Editor," a powerful utility that lets you easily modify BASIC program lines.
To prepare the BASIC Line Editor, type in and save the program listed below. It's a BASIC file maker that POKES the machine language program into memory, then BSAVEs it to disk as a binary file (named BLE2 to distinguish it from BLE, the original version of the program).
Once you've run the filemaker, you're ready to use the BASIC Line Editor. Start it by typing BRUN BLE2 and pressing RETURN. The program loads at memory address $2000, then checks to see which operating system is present before moving itself to a safe location. (Note that this process can destroy part of a long BASIC program. If you have a long BASIC program in memory, you should save it before you activate the BASIC Line Editor.)
Now you're ready to put the Editor to work. To edit a BASIC program line, type & followed by the desired line number. For instance, enter &100 to edit line 100. The BASIC Line Editor displays the line on the screen in a format somewhat different than Applesoft's. The line is continuous rather than centered on the screen, there are no extra spaces in the line except between quotation marks, and all control characters are displayed in inverse video.
Editing Commands
The BASIC Line Editor provides 13 new editing functions. Most are accessed by pressing the CTRL (Control) key together with a letter key Here's a quick reference table followed by a detailed description of each command:
CTRL-B | block back |
CTRL-C | convert hex to decimal |
CTRL-D | delete right |
CTRL-F | block forward |
CTRL-H | cursor left |
CTRL-I | insert |
CTRL-M | return |
CTRL-S | search |
CTRL-T | truncate |
CTRL-U | cursor right |
CTRL-V | verbatim |
DELETE | delete left |
ESC | return to BASIC |
CTRL-B (block back) moves the cursor back to the previous colon, or if there is no previous colon, to the beginning of the line.
CTRL-C (convert hex) converts hexadecimal numbers to decimal. This command moves the cursor above the line being edited, prints a $ prompt on the screen and waits for you to enter a number. This value is converted to decimal and printed. Then the cursor returns to its original position on the line.
CTRL-D (delete right) deletes the character under the cursor. The cursor stays where it is and every thing to the right moves back one space.
CTRL-F (block forward) moves the cursor forward to the next colon, or if there is no colon, to the end of the line.
CTRL-H (cursor left) moves the cursor back one space.
CTRL-I (insert) puts the BASIC Line Editor in insert mode. Any characters you type are inserted in the line until you use another Editor command.
CTRL-M (return) is the same as pressing RETURN. No matter where the cursor is located on the line, pressing CTRL-M enters the line into the program.
CTRL-S (search) searches for the next character entered.
CTRL-T (truncate) truncates the line at the cursor position (deletes everything after the cursor). The cursor ends up one space beyond the new end of the line.
CTRL-U (cursor right) moves the cursor forward one space.
CTRL-V (verbatim) lets you enter control characters verbatim. If the keypress immediately after CTRL-V is a CTRL key combination, it is interpreted as a control character rather than as a BASIC Line Editor command. CTRL-V is useful for adding RETURN (CTRLM) or backspace (CTRL-H) characters to a line for improved printing control. If the keypress immediately following CTRL-V is not a CTRL key combination, CTRL-V has no effect. Remember that the BASIC Line Editor shows control characters in reverse video.
DELETE (delete left) deletes the character to the left of the cursor and moves the cursor back one space. (The DELETE key is found only on the IIe and IIc.)
ESC (return to BASIC) puts you back in BASIC. If you make a mistake when editing a line with the BASIC Line Editor, press ESC to exit back to BASIC without losing the line.
Program Notes
Activating the Editor resets the stack to the same level as does BASIC, sets up the ampersand vector ($3F5), moves the DOS buffers downward to protect DOS, and restarts BASIC. The Editor uses existing BASIC routines to read the input line and find the desired line in memory. If you try to edit a line that doesn't exist, the Editor simply returns to BASIC. If the line is found, its contents are read and listed on the screen. Text characters are listed just as they are stored. When the Editor finds a token (an encoded BASIC keyword), it locates the word in the BASIC keyword table and lists it on the screen.
Once the Editor lists the line, it enters editing mode. This part of the program gets a command from the keyboard, processes it, and updates the screen. Space doesn't permit a detailed explanation of how each Editor command works. If you're familiar with Apple machine language programming, you may find it interesting to trace through the various routines on your own.
BASIC Line Editor
Version By Tim Victor, Editorial
Programmer
For instructions on entering this listing, please
refer to "COMPUTEI's Guide to Typing In
Programs" published bimonthly in COMPUTE!.
53 80 FOR I = 8192 TO 9157: READ
A: POKE I,A: NEXT
80 90 PRINT CHR$ (4);"BSAVE BLE2
,A$2000,L$3C6": END
1E 100 DATA 173,0,191,201,76,208
,13,169,3,32
6B 110 DATA 245,190,24,165,116,1
05,4,76,27,32
A0 120 DATA 56,165,116,233,3,133
,116,133,207,141
2D 130 DATA 175,32,165,115,133,2
06,141,174,32,169
20 140 DATA 177,133,235,169,32,1
33,236,160,0,177
AB 150 DATA 235,145,206,230,206,
208,2,230,207,230
85 160 DATA 235,208,2,230,236,16
5,235,201,70,208
75 170 DATA 234,165,236,201,35,2
08,228,177,235,230
1F 180 DATA 235,208,2,230,236,14
1,176,32,17,235
19 190 DATA 240,41,173,176,32,24
,109,174,32,133
BE 200 DATA 206,177,235,230,235,
208,2,230,236,109
0D 210 DATA 175,32,133,207,24,17
7,206,109,174,32
B3 220 DATA 145,206,200,177,206,
109,175,32,145,206
43 230 DATA 136,240,200,173,174,
32,141,246,3,173
F8 240 DATA 175,32,141,247,3,169
,76,141,245,3
FA 250 DATA 160,11,185,162,32,32
,240,253,136,16
5E 260 DATA 247,96,141,217,196,1
93,197,210,160,178
1E 270 DATA 197,204,194,141,56,3
2,32,32,12,218
6E 280 DATA 32,26,214,176,1,96,1
04,104,32,156
5D 290 DATA 252,160,2,177,155,20
0,170,177,155,32
2C 300 DATA 36,237,160,6,140,123
,5,132,206,165
99 310 DATA 37,141,151,2,165,155
,133,235,165,156
C8 320 DATA 133,236,160,4,177,23
5,200,201,0,240
44 330 DATA 44,16,36,162,208,142
,68,0,142,69
4E 340 DATA 0,41,127,170,173,255
,255,48,17,224
96 350 DATA 0,208,3,32,72,1,238,
68,0,208
4B 360 DATA 239,238,69,0,208,234
,202,16,243,32
50 370 DATA 72,1,56,176,205,160,
6,169,192,141
62 380 DATA 152,2,132,207,32,34,
1,32,12,253
1E 390 DATA 201,255,208,2,169,12
8,201,160,144,81
5E 400 DATA 44,152,2,48,15,112,6
5,141,70,1
BC 410 DATA 32,35,2,169,192,141,
152,2,48,218
0C 420 DATA 112,34,72,164,207,13
2,227,164,206,140
5F 430 DATA 149,2,200,32,236,1,1
32,207,32,96
86 440 DATA 1,206,149,2,198,207,
164,227,196,207
E5 450 DATA 208,242,32,34,1,104,
32,110,1,164
73 460 DATA 207,196,206,200,144,
3,32,236,1,76
F7 470 DATA 105,0,164,207,169,19
2,141,152,2,48
BC 480 DATA 157,44,152,2,48,13,8
0,240,162,192
2A 490 DATA 142,152,2,73,192,201
,64,208,213,162
DD 500 DATA 192,142,152,2,201,14
1,240,12,201,155
77 510 DATA 240,46,164,207,32,25
3,1,76,105,0
B0 520 DATA 160,0,132,207,32,34,
1,32,155,1
1D 530 DATA 73,128,16,2,41,63,16
4,207,153,0
87 540 DATA 2,200,196,206,208,23
2,169,0,153,0
4E 550 DATA 2,160,1,162,255,76,6
8,212,164,206
70 560 DATA 32,34,1,160,0,240,23
5,72,173,151
11 570 DATA 2,133,37,152,197,33,
144,6,229,33
61 580 DATA 230,37,176,246,133,3
6,141,123,5,32
33 590 DATA 34,252,104,96,132,20
7,32,34,1,32
32 600 DATA 155,1,201,70,96,140,
150,2,9,128
17 610 DATA 201,160,176,2,73,192
,32,110,1,164
E0 620 DATA 206,200,32,236,1,172
,150,2,96,172
09 630 DATA 149,2,32,34,1,32,155
,1,164,207
AB 640 DATA 32,34,1,141,153,2,16
5,37,72,173
5F 650 DATA 123,5,133,36,72,173,
153,2,32,240
6D 660 DATA 253,104,205,123,5,20
8,7,197,36,165
F5 670 DATA 36,141,123,5,104,144
,7,197,37,208
4B 680 DATA 3,206,151,2,173,153,
2,96,173,123
DF 690 DATA 5,172,179,251,192,6,
208,22,44,31
87 700 DATA 192,16,17,141,1,192,
72,56,101,32
BD 710 DATA 74,144,3,44,85,192,1
04,105,0,74
18 720 DATA 168,177,40,44,84,192
,96,192,0,240
FF 730 DATA 37,32,247,1,132,207,
132,227,32,15
34 740 DATA 2,140,149,2,196,206,
240,13,32,96
3E 750 DATA 1,238,149,2,230,207,
172,149,2,208
D1 760 DATA 239,164,207,32,236,1
,164,227,969132
A9 770 DATA 206,32,34,1,32,156,2
52,164,206,96
07 780 DATA 192,0,240,1,136,96,1
62,11,202,48
06 790 DATA 250,221,127,2,208,24
8,189,138,2,141
66 800 DATA 14,2,176,255,196,206
,240,1,200,96
22 810 DATA 169,128,44,169,0,44,
169,64,141,152
36 820 DATA 2,96,169,186,141,70,
1,164,207,196
0E 830 DATA 206,240,6,200,32,61,
1,208,244,164
D5 840 DATA 207,96,169,186,141,7
0,1,164,207,240
52 850 DATA 6,136,32,61,1,208,24
6,164,207,96
16 860 DATA 172,151,2,136,132,37
,32,34,252,169
9E 870 DATA 0,141,123,5,32,156,2
52,162,0,169
56 880 DATA 164,32,110,1,32,12,2
53,157,0,2
23 890 DATA 232,201,141,208,242,
32,199,255,32,167
62 900 DATA 255,169,189,32,240,2
53,165,63,166,62
72 910 DATA 32,36,237,164,207,96
,128,132,1369149
43 920 DATA 148,137,147,150,134,
130,131,179,188,232
69 930 DATA 0,221,6,9,12,18,38,5
6,35,0
89 940 DATA 59,0,62,0,77,0,80,0,
85,0
B9 950 DATA 93,0,103,0,108,0,124
,0,131,0
B1 960 DATA 134,0,139,0,153,0,15
7,0,162,0
E4 970 DATA 165,0,176,0,180,0,19
0,0,193,0
DF 980 DATA 200,0,205,0,214,0,22
5,0,238,0
60 990 DATA 241,0,248,0,251,0,28
,1,36,1
3C 1000 DATA 64,1,67,1,73,1,84,1
,90,1
F1 1010 DATA 93,1,97,1,100,1,103
,1,108,1
F4 1020 DATA 111,1,123,1,149,1,1
52,1,199,1
73 1030 DATA 206,1,209,1,216,1,2
19,1,224,1
AE 1040 DATA 231,1,239,1,3,2,8,2
,11,2
2F 1050 DATA 30,2,36,2,46,2,56,2
,64,2
F7 1060 DATA 72,2,93,2,0,0