Machine Language Compactor
David L. Evans
This compactor analyzes and compresses BASIC at lightning speed. For PET/CBM, Upgrade and 4.0 BASIC, with disk drive.
When the programs "Compactor" and "UnCompactor" by Robert Baker appeared in the Sept./Oct., 1980 and May, 1981, issues, respectively, of COMPUTE! I immediately typed them in and tried them out on several of my programs.
To my dismay, compacting a 16K program required approximately 48-52 minutes. I am a college student and spend a limited amount of time on my computer (a 16K 4.0 PET) due to study time and my job. That compacting time ate heavily into the time I spend on my PET and I decided to do something about it. This program is the result.
I tried several different BASIC versions of the program, but could come up with no noticeable increase in speed. I then decided to give machine language a try. The result? A 947% increase in speed! Even this phenomenal increase in speed can be improved a bit further by eliminating the error checking in my input subroutine.
The program consists of five different sections. The input section prints the directions and inputs the input and output file names. The scanning section scans the BASIC program for target line numbers and prints them for you to see, while also storing them for use by the compacting section. The compacting section compacts the program (where possible) and prints "DONE" when finished.
A following subroutine section contains an input subroutine, a line number checking routine, and a disk error routine. Following these four sections is the data and work storage area. This program was designed to run on both Upgrade and 4.0 ROMs. It will automatically adjust itself to work on either ROM set, so all the user has to do is to LOAD the PROGRAM and type RUN.
Running the program is fairly simple. Load the program into memory with the LOAD or DLOAD command, depending upon which computer you have. If you do not have DOS 2.0 or higher, make sure that both drives are initialized. Type RUN, and the computer will print a short greeting along with some brief directions.
Typing In Compactor
Below are the step-by-step instructions for entering and SAVEing Compactor. COMPUTE! generally provides BASIC loaders so that readers who don't know machine language can easily type in and use machine language subroutines and programs. Though it could be done, we felt that creating a BASIC loader for Compactor would be too complicated to be worthwhile: Compactor sits in memory starting at address 1024 (like a BASIC program). A loader would involve an awkward process of writing over itself and checksums would be equally difficult to use.
Instead, Compactor is presented as hex dump. To enter it into the computer:
After reading the directions, type in your input file name preceded by the drive number the file is on. Example : 0:COMPACTOR. You will then be asked for the output file name; do the same with it as you did with the input file name. The computer will then scan and compact your program. If any disk error is detected, the program will report it and will return to BASIC. After your program has been compacted, LOAD it into memory and type the CLR command; this will fix all the line links. Be sure to reSAVE the corrected copy.
Clearly, machine language lends itself to input/output programs more readily than BASIC does. Once the basics of how to open files from machine language are learned (see COMPUTE!, April, 1981, #11), it is easy to generate input/output programs in machine language which will run at a phenomenal speed.
For those of you who do not want to type this in, I will make you a copy of it if you will send me $3.00 and a self-addressed, stamped mailer and a blank tape or disk. For those who send a disk, I have DOS 2.0, so all disks will be written in DOS 2.0.
2202 Ellis Ave.
Caldwell, ID 83605