Saving Machine Language Programs
I'd like to protect programs I write on my VIC-20, and I know that using machine language accomplishes this. But how do you save machine language on tape?
The easiest, quickest, and most efficient way to save a machine language program is from within a machine language monitor. There are many monitor/assembler packages available for your VIC-20, among them "TINYMON1," published in COMPUTE!'s First Book Of VIC, and the VICMON Machine Language Monitor Cartridge available at your local Commodore dealer. The following technique will also work successfully on the Commodore 64.
Once a monitor is loaded and running, the usual format for saving to cassette tape is: S "name", XXXX, YYYY, 01 where S = save, name = name of program, XXXX = starting address of the machine language program to be saved, YYYY = ending address of the program, and 01 is the device number (tape). Saving to disk would use the same format, except that the device number would be 08 (disk). However, it should be noted that some monitor/assemblers use a different format. See the accompanying documentation.
There is another way to save machine language programs, but it involves some redefining of the VIC's operating system. You can save a machine language program in the same manner that you would a BASIC program. To accomplish this, you have to redefine, or POKE three sets of pointers. First, you have to determine the beginning and the ending addresses of the machine language program. Once this is known, POKE 43 and 44 (start of BASIC pointer) to point to the beginning of the program, POKE 45 and 46 (start of BASIC variables, or end of BASIC pointer) to point about 10 bytes past the end of the program, and POKE 55 and 56 (highest address used by BASIC) to point about 30 bytes past the end of the program. Next type CLR. Now you are ready to save to tape or disk in the normal manner, i.e., "SAVE filename, 1" (for tape) or "SAVE filename, 8" (disk).
To LOAD the programs back into memory, use the standard format for LOADing machine language programs: LOAD filename, device number, 1. For example, LOAD "filename", 8, 1.
COMPUTE! welcomes questions, comments, or solutions to issues raised in this column. Write to: Readers' Feedback, COMPUTE! Magazine, P.O. Box 5406, Greensboro, NC 27403. COMPUTE! reserves the right to edit or abridge published letters.