------------------------------------------------------------------ SF .. a Show File program for CP/M systems ------------------------------------------------------------------ By John Gill, Rt 5, Box 370, Blountville, TN 37617 Telephone 615-323-2453 January 25, 1984 Version 1.1 - March 18, 1984 Fixed bug in displaying line numbers on lines with imbedded tabs. Add selectable line number toggle. NOTE: The program "SF" is written in ZILOG Z-80 assembler code and will only run on a Z-80 with CP/M 2.2 or greater. ------------------- I have decided to make the source code available so that others may adapt it easily to their systems. Permission is granted to copy or distribute the program for non-commercial use only. Please contract me if any commercial use of the program is desired or the user makes any significant improvements in the program or its logic. SF is a CP/M utility to SHOW the contents of a ASCII text file on disk. It has several features that make it much more useful than the standard inquiry utilities such as "TYPE17" and CP/M "TYPE". Features and restrictions: -------------------------- 1. Displays the file with or without preceding line numbers. 2. Allows you to move through the file in a forward or backward manner by a line-at-a-time, a page-at-a-time, a line incre- ment, or to go to any absolute line number. 3. Allows the user to switch from page-by-page mode to continu- ous scrolling display at any point in the program. 4. Allows you to search for a string in the file and have the screen display the page where the string is found. COMMAND FORMAT: -------------- Show File is run in the same way as as the CP/M utility TYPE. There is one optional parameter that controls the addition of line numbers to the display. For example: SF MYPROG.ASM displays the file without line numbers. SF MYPROG.Z80 N displays the file with line numbers inserted in the front of each line. INTERNAL COMMANDS ----------------- Once SF is loaded, the program opens the text file and displays the first page of 23 lines. The cursor is then at the bottom of the screen waiting for your next command. The bell will be rung if an invalid key stroke is made. Allowable commands are: Single character commands: These commands take effect as soon as they are entered. No carriage return is required or expected. N Toggles the line number function. This allows the user to start without line numbers and switch to line numbering as desired. Ctl-R Moves the display window 1 page toward the front of the file. Ctl-C Moves the display window 1 page toward the end of the file. (The space bar and return key also perform this function). Ctl-E Moves the window down 1 line and inserts a new line at the top of the screen. The entire screen is actually re- written. Ctl-X Scrolls the entire screen up one line and adds a new line at the bottom of the screen. Ctl-S Causes the program to switch from page-by-page mode to that of continuous scrolling. Pressing any key, while the screen is scrolling, will put the system back in command mode. Ctl-K Exit Show File and return to CP/M. Note: The control codes, listed above, follow the WordStar format for cursor movement. My own system makes use of the Function and arrow keys in place of the control codes. The entry of a Control-C terminates the program and returns to CP/M. The codes are defined at the beginning of the program and can easily be changed to fit your terminal requirements. Multiple character commands: These commands require a carriage return to terminate the input. The backspace key erases the last input character. A control-U will cause the command to be erased so that a new command may be entered. The value "nnnn" represents a 1 to 4 digit ASCII line number. nnnn Move directly to line number "nnnn". The contents of this line will be display on the top line of the screen. See the section below on out of range line numbers. +nnnn Move the screen window FORWARD "nnnn" lines in the file. -nnnn Similar to +nnnn, except the window is moved BACKWARD toward the front of the file. Fstring Searches from the "current line", forward in the file until it finds the string. The line where the string is found will appear at the top of the screen. Note: if the "F" command is entered without a string, it will use the pre- vious string if one is available. This allows repeated Finds without having to re-enter the string each time. The "current line" is defined as the last displayed line on the screen. The second search will start at the end of this last line. Out-of-range line numbers. -------------------------- If end of file is encountered while moving through the file, the program will clear the screen and be waiting for your next command. The line counter will be positioned at the last line number in the file. A command that would cause the line number to be positioned before the front of the file, will be modified so that the first page of the file is shown. The program displays only the portion of the line that will fit the screen width. All characters beyond this limit will not be displayed (no word wrap). They will be processed in the Find command operation. When line numbers are request- ed, the displayed line width is reduced by 6 character positions. A note on how the program operates. ----------------------------------- When displaying data on the CRT, all tab characters are expanded to the standard CP/M positions. Tabs are not expanded in the "Find" command. All control characters, other than Line Feeds or Carriage Returns, are not sent to the screen. The program assumes each line ends with a Line Feed character. Since text files are stored as a collection of variable length records in a CP/M system, there is no easy way to get to any particular record. One must start at the beginning, or some "known point" and read forward sequentially until the desired record is reached. This program builds a table of "known points" as it reads forward in the file. When the user requests a line number that has not been previously processed, the computer locates the closest "known point" that it has and then reads forward. The process is much faster in the backward movement, since the computer has already set these "known points" and can move to the closest one in a fraction of a second. When you start, you are positioned at the end of the last line number on the CRT. At that time, if you request a line that is at the end of the file, the computer has to read forward through the entire file before it can display the requested data. It has somewhat of a speed advantage in that it does not have to send the data to the CRT until it reaches the requested line. The program keeps track of the line numbers that go with the Top and Bottom lines on the screen. If you request forward line movement that is less than a full screen, the program will scroll the screen rather than rewrite the entire screen. Any backward movement (toward the front of the file) will cause the entire screen to be rewritten. The program does no internal data blocking. It operates with the standard 128 byte record. I feel that an increase in speed could be achieved by using a larger record size, but the logic used to keep track of the "known points" could be a lot more complicated than it currently is (and its bad enough as it is). The program occupies about 1600 bytes of memory. It also uses another 400 bytes for table area. All console input/output is done directly through the BIOS. This prevents any of the CP/M control functions from having any effect on program operation. The disk operations are all processed using the standard CP/M BDOS calls. One last word: If you have any problems or suggestions concerning this pro- gram, please let me know about them.