Classic Computer Magazine Archive COMPUTE! ISSUE 43 / DECEMBER 1983 / PAGE 314

TI Word Processor

James D Baker

This menu-based word processor includes many of the basic features of commercial word processors: text creation, addition, deletion, modification, paragraphs, pagination, margin control, page overflow, and text centering. Written for the TI-99/4A with Extended BASIC, a disk drive and printer, the program runs with standard 16K memory.

Just like thousands of other TI users, I have added to my system since the original purchase of the computer and a TV set. After I had purchased Extended BASIC, the Peripheral Expansion Box, disk drive and controller, RS-232 interface, and a printer, my next choice was word processing capability. As the Texas Instruments package was not yet on the market and would also require 32K memory expansion, like all others available, I decided to write my own word processor.

This program runs with standard 16K memory because of linked list access for text files: Only one line of text is in memory at a time, with before and after indices pointing to the previous or following line of text.

With this design, addition and deletion of text lines are possible. The addition of a single line or an entire paragraph of text is possible and, therefore, updating text after the initial input process is easy.

Automatic pagination, margins (top, bottom, left, and right), page overflow, text centering, and text modification are also included features.

The program is written in two distinct sections: first, the create/edit section, then the print section. If additional features are added, it may be necessary to split the program into two separate programs in order to maintain the objective of minimal memory usage.

Let's look in detail at the program features.

Program Initialization

Upon initial execution of the program, the user will be asked for a filename (assumed on DSK1) where text is stored. The subroutine called in line 140 sets characters in lowercase.

Next, a screen menu is displayed with these options:





New Data File

Upon selection of the first option, a header record is written to the opened disk file. This record is used to maintain a pointer to the last text record in the file. Initially, this record does not contain any meaningful information, but will be updated at the end of the program to contain the actual last record number.

Control is then passed to the routine for entering new text (lines 380 – 470). Original text is entered using the LINPUT statement, which limits the length of a single entry to 128 characters. However, this is not a severe limitation; the program will simply cause wraparound of the text from one record to the next. The computer will beep to remind you that you have exceeded the length of the input string, and you must then press ENTER to cause this record to be written to disk and begin entry of the next record. Also, note that during text entry all the standard control key operations are allowed, including cursor left or right, character delete or insert, erase, etc.

The pointers for previous and next record locations are then updated, and a check for one of the special control functions, /E/, is performed. This is used to indicate the end of text and must be entered as the last record of the text. If the record just entered is not the end marker (/E/), the program writes the text line to disk and returns for the next line of text.

When text entry is complete and the /E/ is entered, lines 490 – 510 update record 0 with the record number of the last record on file. Finally, the option of printing the text is offered. If you answer Y for yes, control is passed to the print routine (line 2400); otherwise the program ends.

Other special control functions are also included for editing. By entering /C/ as the first three characters of the text line, the print program will automatically center the text that follows on that line. By entering /P/ as the first three characters of a text line, the print program will automatically indent five spaces for a new paragraph. Also, by entering /N/ as the only three characters on a text line, the print program will automatically cause a top-of-page routine to be executed. These special control functions can be entered as upper- or lowercase letters.


When this second menu option is selected, control is passed to program line 600. This routine simply uses the pointer obtained from the first record on file to retrieve the last record on file (the /E/ record). Then the last actual text record is retrieved by using the previous record pointer from the /E/ record.

The last actual text record on file is then displayed, and control is passed to the routine used for original text entry.

Changing An Existing File

With this option, the program retrieves the first text record, using the pointer obtained from the first record on the file. This line of text and a change menu are then displayed:

9 = QUIT

Next Line. This option displays the next text line. If selected, program execution is transferred to line 900. This routine first sets the number-of-records-forward counter to one. The loop in lines 940 – 980 follows the next record pointer through the file until the requested number of records forward has been read.

A check is made to insure that a read past the end of file does not occur. If this is attempted, the program displays the last line of text, a warning message, and returns to the main change menu. Upon completion of the loop, program control is returned to the main change menu.

It should be noted that the loop is not necessary in order to display the next line. However, it is also used to advance any number of records by using the third option discussed below.

Last Line. This option displays the previous line of text. The routine starting at line 1000 provides for stepping backward through the text file. This routine is the same as the prior routine except that the previous record pointer is used in order to proceed to the previous record.

FWD X Lines and BKW X Lines. Both of these options (3 and 4) are handled in the routine beginning at line 1100. The program asks for the number of lines to be read either forward or backward. This value is then placed in the appropriate counter, and control is transferred to the Next Line or Last Line routine.

Add Before and Add After. These options (5 and 6), initially handled by the same routine (at line 1100), allow for adding text, the first before the current line, and the second after. The program displays the current record and, based on which type of add was requested, prompts you to add before or after.

The new line of text is then entered and the record pointers from the current record are saved. The /E/ is retrieved in order to determine the next available location in the file to store a record (next record pointer). This value is saved, and then the /E/ record is rewritten with the next record pointer incremented. Based on the type of add being done, control is transferred to the appropriate routine.

If you selected Add Before (option 5), control is passed to line 1350.

If you selected Add After (option 6), control is passed to line 1450.

Control is then transferred to line 1430 and processing continues as discussed above.

Change. This option allows you to change an existing line of text. The routine for this option begins at line 1540. The text line is broken into 14 lines of "equal" length. Using the DISPLAY AT and ACCEPT AT statements allows the setting of default values for each of the subtext lines to their initial string value. This eliminates the necessity of retyping the entire line to make a minor correction.

The length of each of the subtext lines is calculated and the first 13 lines are displayed. Note that a special character is added to the end of each line. This is done so a space is not lost at the end of the subtext line.

Line 1650 determines if there is any text remaining for the fourteenth line. This is necessary to avoid an error if the string happens to be less than 13 times the rounded length of a single subtext line length. The fourteenth line is then displayed in preparation for change.

The 14 lines are then "looped" through, allowing any changes desired. Note that the maximum length of any subtext line is limited to 26 characters and that if the special end character is accidentally deleted, the program will restore this character. The length of the new text line is recalculated since this length could now exceed the maximum string length permitted by the computer.

After the text has been changed, the new text length is checked to see if it exceeds 225 characters. If the length is less than 226 characters, the text line is reconstructed and control is transferred to line 2050.

If the length of the new text line exceeds 225 characters, a menu offering two choices is displayed: either update as modified and create a new record on disk or reupdate the line. If the reupdate choice is selected, control is transferred to the beginning of the change routine with no changes made.

If the choice is made to update and create a new record, lines 1900 – 1940 establish two new text strings consisting of the first seven and last seven subtext lines respectively. The current record being changed is then replaced on disk by the first new text string created. The second new text string is then added to the file using the Add After routine. Note that the return switch has been set in line 1950 causing control to return to this routine after the add is completed.

The first of the new records is retrieved, and control is returned to display this as the current record and display the main change menu.

If the change process did not cause a new record to be added, lines 2050 – 2130 display the changed text and offer three choices: perform more updates, update the record as displayed, or exit with no updating.

Delete. The routine for this option, which allows you to delete a line of text, begins at line 2180. You will be asked for confirmation before the delete is executed. If the choice is made not to delete the line, control is passed back to line 780 where the current line is redisplayed and the main menu choices are available.

If you choose to delete the line, the previous and next record pointers from this "to be deleted" record are saved. The previous record is then read and updated with the next record pointer from the deleted record. The record after the deleted record is then read and updated with the previous record pointer from the deleted record. Note that the record just deleted is only deleted from the standpoint that the record pointers no longer allow access to the record.

A check is then made to insure that this delete has not caused all text to be deleted. If this is the case, the program displays a message to that effect and terminates. Otherwise, if a record still exists before the deleted record, control is passed to line 1000 and the previous record is displayed. If the record prior to the deleted record is the header record, control is passed to line 900, and the record following the deleted record is displayed.

Print File

The print routine begins at line 2400. Lines 2480 – 2540 establish the default values for top margin (TM), bottom margin (BM), left margin (LM), page length (PL), lines per page (LPP), and maximum line length (MAXWID). Print control information is then requested, including mode of print (draft or final), spacing (single or double), and optional page numbering.

The input file is then "restored" to restart from the first record on file, and the printer output file is opened. Note that the parallel port is used in this program. If you are using the serial port for your printer, the OPEN statement in line 2730 will require appropriate changes.

The first record on file is read to retrieve the next record pointer for the first text record. The main print "loop" begins at line 2820 where the next text record is read using the next record pointer from the previous record.

If draft printing was requested, control is passed to that routine (line 2880). If the current record is a forced new page request (/N/), the subroutine at line 3900 causes a page eject and the top margin to be printed. Control is then returned to the main print loop.

Line 2850 passes control to the ending routine if this is the last text record. Otherwise, control is passed to the print final routine (line 2980).

Print Draft. This routine (lines 2870 – 2930) simply prints the lines of text in sequence exactly as entered. This includes printing any special print commands, but does not effect these commands. This is useful if you want to see what was entered for verification purposes and do not want pagination, etc. This print mode is also faster than final printing as the special print commands are not executed.

Print Final. This routine begins at line 2980 and prints as much text as will fit on the remainder of the print line, then prints character by character until a space is encountered.

The Print Final routine first checks for any special print commands. If a blank line, centered line, or new paragraph is requested, control is passed to the appropriate routine. If the last character on the text line is a period, two spaces are added to the end of the line to insure proper spacing.

The centering routine begins at line 3550 by printing any unfinished print line and checking for overflow. The length of the text to be centered (excluding the centering command) and the number of spaces required to center the text is then calculated. The line is then printed and control is passed to read the next record.

The routine to print a blank line begins at line 3700. This routine simply prints the preceding line, a blank line, checks for overflow and returns to read the next record.

The routines for top and bottom margins begin at line 3800 and simply loop for the necessary number of blank lines. Page numbering is handled on line 3940.