Auto Line Numbering +

16K Cassette or Disk
by Same Wiley


If you're like me, you love to write programs but hate to even think about the mental and physical work involved in keeping track of line numbers as you program. After all, we geniuses need to think about program logic and not the next line increment!

This utility will do four things. First, it will put line numbers on the screen. Second, it will check the line that you typed in for an error and BEEP you by ringing the bell. This is also known as printing CHR$(253) or hitting CTRL-2. Third, it displays, near the top of the screen, how many variables you have left and, also, how much memory you have left. Fourth, it disables the BREAK key and the clear screen keys. There is also full-screen editing of the lines that are on the screen. You can change the starting line number, or the increment, by pressing CTRL-3 and typing GOTO AUTO. After hitting CTRL-3, you can LIST your program, edit it or add statements. The utility will go back to the next line that it was working on, before CTRL-3 was pressed, by typing GOTO NEXT.

Although most of it is in BASIC, it uses the "forced read mode" to read the entire screen every time RETURN is pressed. This is what allows for full screen editing. There is a short machine language subroutine to check the entire BASIC program for an error and find out how many variables have been defined. Both of these functions work very fast, so there is hardly any wait while you are entering your program. The program that you are typing in can be separated from the auto-numbering utility by LISTing it to the disk or cassette with the line numbers 0-31999. Here is an example: LIST "D:YOURPROG.EXT",0,31999. This will only LIST your program to the disk. For a cassette-based system, use LIST "C:",0,31999. Lines 32045 and 32055 contain the REM equivalent of these statements. I suggest you type in whichever one applies, and then you can delete the line number and the REM. For disk users, fill in the name that you want to call your program on Line 32045. Press RETURN, and it will be properly LISTed to disk. Cassette users can use Line 32055. By using the LIST command, you will have to use the ENTER command to get your program back into the computer. I suggest you use the SAVE command to save this utility and the LIST command to save your program. This way you can always merge the two by loading the utility first and then using ENTER to load your program.

The machine language subroutine is placed in a string (ML$) to allow access to page 6. The BREAK key is disabled, because it was put too close to the RETURN and editing keys on the 800. Instead you use CTRL-3 to interrupt the auto-numbering process. This will also restore the BREAK key for normal editing.

Type in the program and use one of ANALOG's error-checking programs, C:CHECK or D:CHECK. I just can't say enough about this idea for typing in programs from printed media. Until they came along, I always thought that the magazine was printing the wrong code. No way. I learned what a really lousy typist I was. At any rate, after the CHECKSUM DATA checks out, type RUN. The screen will go blank for a few seconds, while the utility loads the machine language subroutine into the string. The first thing that prints is "STARTING LINE NUMBER?" Answer with the line number you want to begin auto line numbering with. If you don't answer with a number, the utility will repeat the question. The second thing you are asked is "INCREMENTS DESIRED?" Answer with the number of lines that are to be between each line number. A good number is 10. This way you can insert 9 lines between each line that you type in, if you find out later that something new should be added.

Next, the first line will appear, and the utility will wait for you to enter a statement. All of the keys are accepted, with the exception of CTRL-CLEAR and SHIFT-CLEAR. These keys are useless during screen editing. If the ESC key is pressed prior to CTRL-CLEAR or SHIFT-CLEAR, it will accept the key(s). When RETURN is pressed, the screen blanks for a second. If there was no error in the line, it will click the console speaker to alert you that it is ready to accept the next line. This is so you don't have to look away from whatever you are typing in. At the top of the screen will be the utility commands. They are: 1. CTRL-3 -- Use instead of BREAK key; 2. G.NEXT -- GOTO next line number of a predefined increment; and 3. G.AUTO -- Set up new line numbers and increments.

Under this is displayed how many variables are left and how much memory is left. The memory is displayed as "BYTES LEFT=". The last two lines are displayed, along with the next line. If there was an error in the line you typed in, the console bell (CTRL-2) will ring, and the only thing on the screen will be the error line and statement following it. The cursor is positioned at the beginning of the line number. Be sure to remove the ERROR- and also the cursor that shows where the error is, to avoid getting another error. When it is corrected, press RETURN, and the utility will go to the next line number.

You may also use the utility to delete lines of code. Type GOTO AUTO and give the starting line number and increments of the lines that you want deleted. Then just hit RETURN when the line numbers appear. I also use it to type in programs from magazines and books. Sometimes the line numbers are not in even numerical increments (like in this program). When this is the case, you have to use the GOTO AUTO to keep changing the starting line number and the increments. For myself, it's most useful for program development from scratch.

You may wonder why the utility only LISTs two of the previous program lines. In studying the listing, you will see that Line 32113 can be modified to LIST three or even four previous lines. For instance, after the TRAP statement, a LIST LINE-INC*3 will LIST the last three lines. The reason for the two lines is due to the Atari being in the "forced read mode." Even though the CONT is at Line 19, if there are three full lines on the screen (a logical line can be four physical lines), and the fourth line contains an error, the error message could cover up the CONT, and the computer never regains consciousness until SYSTEM RESET is pressed. In the "forced read mode," if a line is encountered with an error, the line is immediately displayed again with the ERROR- message.

This is what can cover up the CONT, which is used to exit the mode. Without the CONT, the mode can't be exited, so we get a blank screen. While we're on the subject, there is also one other thing that can cause no exit. If you want to ring the bell and clear the screen, the code is: [Linenum] PRINT "[ESC CTRL-2 ESC CTRL-CLEAR]". If you leave out the leading quotation mark, an error line is generated. The screen is cleared and ZAP! No CONT. This one should be a rarity, but it did happen to me. When I first wrote the utility, Line 32081 wasn't in it. This is the ESC checking line. I added it later to insure that all of the keycodes could be accepted, to make the C:CHECK and D:CHECK kind of programs produce the correct data. Without this line, only ESC CTRL [SHIFT]-CLEAR is masked out. At any rate, feel free to experiment.

The utility consumes 27 of the 128 variables that you can possibly have. I did it this way to conserve RAM. If you need more than 101 variables, you can substitute the variables on Line 32061 to numbers and change them in the program.

If you type RUN after you have keyed in some or all of your program, you will need to type GOTO 32000 to restore the auto line numbering utility.

Program description

Lines 32060-32061
Initialize variables and set screen color to blue when ANTIC is turned off. (Whatever color is in 712 when you do a POKE 559,0 is the color the whole screen turns.) Use READ statement to assign variables to statement commands. (NEXT, ON, CLR and GETKEY would not normally be allowed.) Use READ statement to assign numbers to variables that are frequently used. Assigning the value of 1 to C1 and using it instead of a 1 saves memory (but uses a variable) every time it is used instead of the number 1.
Lines 32064-32067
Load machine language subroutine that checks BASIC program for an error and the number of variables used.
Lines 32068-32075
Open keyboard for input, disable BREAK key, clear screen, make speaker click, and get starting line number and increments. Print first line number.
Lines 32080-32085
GETKEY routine. Reads keyboard and prints to screen until a RETURN is encountered. Masks out CTRL-CLEAR, SHIFT-CLEAR. Checks for ESC key.
Lines 32100-32111
Turn ANTIC off for speed. Set up screen for "forced read mode," and read. Stop "forced read" and exit to machine language subroutine, to check BASIC for error and variables. If no error occurred, increment line by the value in the variable INC.
Lines 32112-32114
Clear screen. Print utility commands. Print number of variables and memory left. LIST last two lines and the next line number. Turn ANTIC back on and make the console speaker click. Return control to user for input of statements.
Line 32115
This is where the utility goes when you type GOTO NEXT. This insures that the keyboard is closed and reopened to avoid a 129 or 133 error. Turn ANTIC off and branch back to LIST the last two lines and line number.
Line 32116
Keyboard and BREAK disable subroutine.
Line 32120
If we can't find a previous line number to LIST, we just display the current line numbel Make sure ANTIC is on, and return to user for input.
Lines 32520-32525
If there was an error found in the machine language subroutine, we perform this routine. Find out the address of the line number where the error is. Get the line number. Place it in the variable ERRLINE. Alert user by ringing bell. Clear screen. LIST the line with the error. Turn ANTIC on. Position cursor over line number. Return to user for input.
Line 32600
DATA for the variables at Line 32061.
Lines 32700-32704
DATA for the machine language subroutine.
Line 32710
This is where the utility goes when CTRI-3 is pressed. Restore BREAK key and END.
BASIC Listing

AUTONUM.LST is available in ATASCII format.

This BASIC listing uses an image to display special characters
Checksum Data
32000 DATA 817,853,381,628,829,564,188
,613,65,889,900,577,885,821,234,9244
32060 DATA 489,905,547,686,813,199,265
,153,32,582,86,942,593,267,511,7070
32113 DATA 83,424,117,529,817,770,866,
226,606,578,931,723,409,419,7498
Assembly language listing

AUTONUM.ASM is available in ATASCII format.

;   CODE IN DATA STATEMENTS
;    AT LINES 32700-32704
;
;  SEARCH THE BASIC PROGRAM
;  FOR ERRORS AND VARIABLES
;
;        SET UP EQUATES
;
VARTAB=134           ;Var valu table
NUMVAR=205           ;For BASIC
STMTAB=136           ;BASIC's start
NEXLINE=209          ;Storage
ERRFLG=207           ;For BASIC
POINTER=203          ;BAS zero page
ERROR=55             ;BOO-BOO
;
;     POINT TO STATEMENTS
;
 *=1664              ;ASM use only
 PLA                 ;Don't need
 LDA STMTAB          ;Set up zero
 STA POINTER         ; page pointers
 LDA STMTAB+1        ; for BASIC
 STA POINTER+1       ; search.
;
;         LAST LINE?
;
NEXT LDY #1          ;End loop if we
 LDA (POINTER),Y     ; reached the
 BMI RETURN          ; last line.
;
;    GET NEXTLINE POINTER
;
GETNEXT INY          ;Point to next
 LDA (POINTER),Y     ; NEXTLINE byte
 STA NEXLINE         ; and keep it.
;
;       CHECK FOR ERROR
;
 LDY #4              ;COMMAND offset
 LDA (POINTER),Y     ;Point to it
 CMP #ERROR          ;Error?
 BEQ RETURN2         ;Yes-Return a 2
;
;       UPDATE POINTER
;
 CLC                 ;No error so
 LDA NEXLINE         ; let's get the
 ADC POINTER         ; next line's
 STA POINTER         ; address and
 BCC NEXT            ; go back to
 INC POINTER+1       ; check some
 BNE NEXT            ; more.
;
;      WE FOUND AN ERROR
;
RETURN2 LDA #2       ;Tell BASIC we
 STA ERRFLG          ; goofed. (POKE
 RTS                 ; 207,2)-- exit
;
;         NO ERROR
;
RETURN LDA #1        ;Tell BASIC no
 STA ERRFLG          ; boo-boo's.
;
;     HOW MANY VARIABLES?
;
 LDA VARTAB          ;Set up zero
 STA POINTER         ; page pointers
 LDA VARTAB+1        ; for variable
 STA POINTER+1       ; search.
;
;         INITIALIZE
;
 LDA #0              ;Put a zero in
 STA NUMVAR          ; our counter
;
;       LAST VARIABLE?
;
NEXTVAR LDA POINTER  ;Last one
 CMP STMTAB          ; yet?
 BNE INCREM          ;No add 1 more
 LDA POINTER+1       ;How about
 CMP STMTAB+1        ; now?
 BNE INCREM          ;No add 1 more
 RTS                 ;Now you may go
;
;     GET NEXTVAR POINTER
;
INCREM INC NUMVAR    ;Add 1 more
 CLC                 ;Get set to add
 LDA #8              ;Var # offset
 ADC POINTER         ;Let's update
 STA POINTER         ; our pointers
 BCC NEXTVAR         ; and continue
 INC POINTER+1       ; our search.
 BNE NEXTVAR         ;Uncond. branch

Previous | Contents | Next

Original text copyright 1984 by ANALOG Computing. Reprinted with permission by the Digital ANALOG Archive.