EDIT Command for S-C Assembler II................Mike Laumer

At last!  Owners of the S-C Assembler II Version 4.0 can now have the power of an EDIT command similar in function to the popular "Program Line Editor" (PLE) by Neil Knozen.  (PLE only works with INteger BASIC and Applesoft, although some wizards have figured out how to interface it with the S-C Assembler.)  The program presented here will patch itself into Version 4.0 to turn the "USR" command into an EDIT command.

Several weeks ago Bob Sander-Cederlof contacted me about some contract programming, to help out on various projects he had in mind.  So I suggested lunch, and we met to discuss some of his projects.  I was amazed at the list (as long as my arm!) of the the ideas for just one of his products, the S-C Assembler II.  (If you like version 3.2, as I did; if you are thrilled with version 4.0, as I am; then version 5.0 will ....)  So I picked out a couple that would be fairly straightforward and would let me pick up the internal structure of the assembler gradually.

After signing a non-disclosure agreement, I obtained the source files and made a listing of the assembler.  Lucky for me I have a brand new Epson MX-80 printer!  I think it is the greatest!

Thursday, I made the listing.  Friday I looked at the listing.  Friday night I began writing code for the EDIT command.  Saturday from 9AM till 1AM I wrote more code, read it through, and rewrote it.  Sunday morning I typed it into my Apple and eliminated the assembly errors (typos).  And by 11AM, with the exception of two trivial bugs, I had it working!  I nearly fell out of my chair!  A 377-line program worked on the first run!

After you type in the program, assemble it, and BRUN it, the USR command will work as an edit command.  If you type the command USR with no line number, it will do nothing.  If you type USR and one line number, it will list the line on the bottom of the screen and set yo up to edit it.  If you type USR and two line numbers, separated by a comma, all the lines in the range will be set up to edit, one at a time.

How to Use EDIT:  Twelve editing functions are available, and you may see fit to add some more.  Each function is selected by typing a control character.  If you type a normal character, it will write over the top of the characters already in the line.  The control characters and their associated functions are:

control-B  Move to beginning of line.
control-D  Delete character beneath cursor.
control-E  Move to end of line.
control-F  Find a character; the character searched for
           is typed after the control-F; repeatedly
           typing the same character will keep looking
           successive occurrences.
control-H  Backspace (left arrow).
control-I  Insert characters before current cursor
           position.
control-M  (RETURN)  Stop editing the line,
           and submit it to the line input routine
           in the assembler.
control-O  Same as control-I, except next character
           may be any control character.
control-Q  same as control-M, but line beyond cursor
           is truncated.
control-T  Skip to next tab stop.
control-U  (Right Arrow)  Move cursor forward.
control-X  Kill edit, does not submit line.


How EDIT Works:  When you BRUN the file B.EDIT (after assembly has written the object code there!), the code in lines 1360-1530 is executed.  This patches the USR command vector to jump to EDIT (line 1720), and makes some patches inside the assembler.  The patches only work for version 4.0!  Their purpose is to make the code which processes a source line into a subroutine.

Lines 1540-1620 are part of the patch code for the source line processing subroutine.

Lines 1720-2040 determine the number of line numbers typed, and search for them in the source program.  Then E.LIST is called for each line to be edited.

Lines 2050-2360 list the source line on the screen and also stuff it into the line input buffer at $0200.  All changes will be made in the buffer, not in the source program.

Lines 2370-2530 read a key from the keyboard and search the command table.  If the key is found in the table, then DOIT is called to execute the command.  If the key is not found, I assume it is a type-over character.  The command table search is actually performed by a rather neat subroutine inside the assembler, called SEARCH.

Lines 2540-2690 process a type-over character, in which the key just typed replaces the character under the cursor.  Then the modified line in the buffer is re-displayed on the screen.

Lines 2700-2750 position the cursor at the beginning of line 19 (on the screen), where the source line will be listed.

Lines 2760-2900 display the line from the buffer.  Display always starts at line 19 on the screen.  Control characters are shown in inverse video.

Lines 2910-4090 process the various commands.  Each processor is written as a subroutine.  The RTS returns to line 2520; at this point the Carry Status is used to flag whether or not to re-display the source line from the buffer.

Lines 4100-4260 read a character from the keyboard by calling on the monitor RDKEY subroutine.  The internal line buffer index is also converted to cursor line and column position on the screen.

Lines 4270 through the end are the command table.  The first line defines the entry size and key size for the SEARCH subroutine;  3 bytes per entry, with a one byte key at the fron of each entry.  The remaining two bytes of each entry are the starting-address-minus-one of the command processor rotuine.  A final $00 byte terminates the table.

WARNING!  I have used the patch for Bob's assembler which allows a list of .DA items!  Lines 4270-4420 require this patch to be installed.  You can read about the patch in Apple Assembly Line for December, 1980, on page 9.  If you have not installed the patch, then lines 4270-4420 need to be re-written with each .DA item on a separate source line.

Well, you better get typing on that Apple, I know this is one routine you can't wait to key in.  I know I couldn't wait to create it!  Or, if you CAN wait, you can get the source on the next Disk of the Quarter from Bob.
