Classic Computer Magazine Archive COMPUTE! ISSUE 78 / NOVEMBER 1986 / PAGE 75

EDIT For Apple II

E. Joseph Billo
Richard A. DeJordy

This short utility improves the editing abilities of Apple Il-series computers using DOS 3.3.

The shortcomings of the Apple's BASIC editor, designed in the infancy of personal computing, are familiar to every Apple owner. If you're a dedicated programmer, you've probably typed POKE 33,33 more times than you care to count. For those who aren't familiar with this command, here's a brief recap of what it does. The usual procedure for editing a BASIC line is to LIST the line, then use ESC and the arrow keys to position the cursor for editing. Although BASIC lists the line in a width of 33 columns, the cursor can travel across the entire 40-column width of the screen. If the line you're editing contains a string that wraps around from one screen line to the next, the editor inserts several extra blank spaces in the string at the place where it wraps. To avoid this unwanted effect, experienced programmers often enter POKE 33,33 before listing the line, to limit the width of the screen window to 33 columns.

In short, the built-in editor demands several steps just to place the cursor at the beginning of the line you wish to edit. First you need to enter POKE 33,33, followed by as many cursor movements as are needed to reach the desired line. "EDIT for Apple II" eliminates the need for such contortions by adding a new command to DOS 3.3.

Typing The Program

Type in the program and save it with the filename HELLO on a disk containing DOS 3.3. When you boot the computer with that disk, the HELLO program automatically installs the EDIT command in DOS 3.3. (Note that any previously formatted DOS 3.3 program will already contain a HELLO program. This program will replace any existing HELLO program, so you should not store this program on any disk which contains a HELLO program you wish to keep.)

To edit a line, simply type EDIT followed by the desired line number. The computer sets the screen width to 33 columns, lists the line, and positions the cursor on the first digit of the line number, ready for editing. If you follow the EDIT command with a range of line numbers (for instance, EDIT 100-120), it displays the range of lines indicated for your reference.

Adding A New DOS Command

One advantage of this program is that it doesn't decrease the amount of memory available for programs. Rather than add a new command, it replaces INT, an existing DOS command. To accomplish this, it's necessary to substitute a new command name for the name INT in the command name table, change the address of the command handler routine in the command handler entry point table, and change the keyword flag bytes in the command valid keywords table.

Perhaps the greatest obstacle faced in making EDIT a DOS command is that the DOS syntax checker doesn't accept any DOS command followed by a number in the range required for line numbers (0–63999). A few commands, such as PR# and MAXFILES, can include numbers, but only within a restricted range.

How, then, to trick DOS into accepting a command followed by a number like 1000? The solution used in this case is to make DOS think it's accepting a filename— something that begins with a letter of the alphabet instead of a number. The new command stored in the command name table is EDI (without a T). When the command parser sees the command EDIT 1000, it interprets it as the command EDI followed by the filename T 1000. Since the first character isn't a numeric digit, the parser lets it pass. The reason for selecting INT is that its three letters can be replaced by EDI without disturbing the rest of the DOS command table.

The simplest way to pass control to the BASIC LIST command handler, along with the line number, is to fool BASIC as well. Before passing control to BASIC, the EDIT program scans the input buffer ($200–$2FF) where the characters EDIT 1000 are located, and changes the command EDI to LIS. Then control is passed to BASIC, where the BASIC syntax checker sees LIST 1000 and proceeds to list the line.

The following table lists the DOS 3.3 and monitor subroutines used in the program. The machine language code for the EDIT command is stored in an area that otherwise contains most of the DOS INIT command. As a result, you can't initialize an unformatted disk when EDIT is in place.

DOS And Monitor Routines

$3DA DOS 3.3 entry point vector for routine that updates monitor I/O routines.
$A012 Exit DOS command parser if command not found in DOS command name table (command must be BASIC).
$A22B Alternate entry point to DOS command handler for PR# command. Executes PR#S (S in A-register).
$FC22 Monitor subroutine to perform VTAB to row specified in cursor vertical ($25).
$FDF0 Monitor subroutine COUTl. Prints character in A register to screen.

EDIT For Apple II

For instructions on entering this listing, please refer to "COMPUTE!'s Guide to Typing In Programs" in this Issue of COMPUTE!.

4E 10 REM :::GREETING PROGRAM TO INSTALL EDIT
D9 20 POKE 43249,69: POKE 43250,68: POKE 43231,201: REM :: 'EDI'
50 30 POKE 40268,147: POKE 40269,174: REM:::ADDRESS
52 40 POKE 43319,32: POKE 43320, 112: REM :::VALID KEYWORDS
7C 50 POKE 40222,207: POKE 40223 ,3: REM :::DISABLE INIT CO MPLETELY
BD 60 FOR X = 44692 TO 44796: READ C: POKE X,C: NEXT
AB 100 DATA 169, 193, 133, 54, 169, 174, 133, 55, 32, 234, 3,
          162, 0, 134, 255, 169, 33, 133, 33, 133, 253, 160, 2, 202,
          232, 189, 0, 2, 217, 247, 174, 208
E0 110 DATA 247, 185, 250, 174, 157, 0, 2, 136, 16, 238, 76,
          18, 160, 133, 254, 201, 221, 240, 11,16 5, 36, 208, 2, 230,
          255, 165, 254, 76, 240, 253, 169, 40
35 120 DATA 197, 253, 240, 17, 133, 2 53, 166, 255, 198, 37,
          202, 208, 231, 165, 37, 16, 15, 169, 23,133, 37, 169, 40,
          133, 33, 169, 0, 32, 43, 162, 208, 217
C3 130 DATA 76, 34, 252, 201, 196, 197, 211, 201, 204