Modem Save And Download For The VIC-20
Dennis Colombo
When used together, this series of programs will let you save downloaded VICmodem files and listings. Also included is a program which will convert a downloaded listing to a tokenized BASIC program that you can run. Requires expansion memory.
After I bought my VICmodem, it soon became evident that I needed a way to store all the information which was coming over the line and relentlessly scrolling off the top of the screen. Without a disk drive, I needed a way to store the data on tape so I could later read the information off the screen or edit and make hard copies of selected data such as specific files, airline schedules, or encyclopedia information. Connect time could be appreciably reduced if I didn't have to stop and absorb the information as I received it. With these considerations in mind, I wrote Programs 1, 2, and 3.
Also, there is another type of data which may be retrieved: program listings. While the capability to store and read these listings is useful, they probably won't be in a form your VIC will understand, and they will not run. So I wrote Program 4, which will convert a BASIC listing back into a "tokenized" BASIC program which will run.
Machine Language Is More Effective
Program 2 will run the terminal and allow the information to be saved to tape and printed on the VIC printer. It uses 2K of memory; the remaining RAM is utilized as a buffer to hold the information until it is sent to tape or printer. The program was written with a 16K expander, but will work with an 8K or 24K expander. Although it could easily be modified to run without memory expansion, the small amount of memory left for the text buffer would fill up too quickly to be practical.
Program 1 loads VIC to ASCII and ASCII to VIC lookup tables, a machine language subroutine to send and receive data, and a machine language interrupt service routine into memory. I had originally attempted to write the terminal program entirely in BASIC. I found, however, that for receiving large amounts of text, BASIC was too slow. This resulted in buffer overflow and frequent loss of data. The machine language subroutine in Program 1 which handles data reception and transmission is far more effective.
Program 3 will allow you to search through the text in RAM and select portions to be displayed on the screen and sent to the printer.
Program 4 will download a BASIC listing utilizing the "dynamic keyboard" technique. Each line of the BASIC listing in memory is entered as though it is typed directly from the keyboard.
Creating The Modem Save Program
Program 1 should be typed in first. SAVE a copy on tape or disk, since the program destroys part of itself as it is RUN. When you RUN the program, checksums will be calculated to help detect any typing errors you may have made in the DATA statements. If no errors are reported, type NEW, but do not reset the computer. It is important that the data which Program 1 POKEs into memory still be there when you type in Program 2. Remember that the NEW command does not clear memory, but only resets pointers.
Program 2 should be typed in exactly as shown; otherwise, when it is RUN, the BASIC pointers may cut off the end of the program. After you finish typing it in, PEEK locations 45 and 46. They should contain the values 49 and 20 respectively. If not, you have either added to or left something out of the program. SAVE a temporary back-up copy at this point in case you have problems with the next step.
Now that you have Program 2 typed in, you must attach the tables and machine language programs which were loaded into memory by Program 1. You can do this by typing POKE 45, 1 : POKE 46, 26 and RETURN. This fools BASIC into thinking that Program 2 includes all the memory up to location 6655, the end of the memory loaded by Program 1. You should now SAVE the new Program 2. All further references to Program 2 are to this version of the program which includes the tables and machine language routines.
To test whether all the data from Program 1 was in fact included in Program 2, type SYS 64802 to clear memory, then LOAD Program 2. Next, type in the following direct mode line and hit RETURN:
FOR A = 6144 TO 6655 : SUM = SUM + PEEK (A) : NEXT : PRINT SUM
If the value reported is 62616, then the data has been included. If not, you'll have to LOAD and RUN Program 1 again, type NEW, LOAD the temporary backup copy of Program 2 you made earlier, then try the POKEs to 45 and 46 and the SAVE again. Once your Program 2 passes this test, you won't need Program 1 again.
You're Ready To Dial
When Program 2 is run, the screen will clear and a cursor (_) will appear in the upper-left corner of the screen. You are now ready to dial up CompuServe or another telecommunications service and connect to the modem. Use the Fl key for Control-C; F3 for Control-P (Break); F5 for Control-Q (resume sending); and F7 for Control-S (stop sending). The interrupt service routine signals with an audible alarm when your text buffer is within 256 bytes of being filled.
You then have the option of logging off and saving your text to tape or printer, or remaining on-line while your text is being saved (about five minutes for 16K) and refilling your buffer with more text. These options are implemented by logging off or by depressing F7 (stop sending) and then pushing the British pound sign key. You will then be asked to select from a menu whether you wish to send the text to tape, printer, or both.
After the SAVE, you will be asked if you are still logged on. If not, the program ends. If you respond that you are still logged on, the program resets the text buffer, clears the screen, and you are ready to continue by depressing F5 (resume sending).
After you have saved your text to tape, you can load it back in at any time and use Program 3 to search and select portions for display and printing. When loading the text back into your VIC, you may occasionally get a? LOAD ERROR message. Don't be concerned – your data should still be intact. After loading the text tape, type NEW and LOAD Program 3.
When RUN, Program 3 will display a set of instructions. Press the SPACE BAR to start and stop the printing of text to screen as many times as desired. When the text is stopped, the S or E key can be used to mark the start or end of selected text. The starting or ending point will be the last character to appear on the screen before the text is stopped. The memory location of that character will appear on the screen, and you will be given the opportunity to change the start (or end) of selected text by changing this number. Once the end of the text has been marked, press the D key to display the selected text. You will then be asked if you would like a hard copy. Pressing Y will send the selected text to the printer.
I would have preferred that the start of selected text be marked from the top of the screen rather than from the bottom, but I couldn't find a reliable way to correlate the location of a particular portion of text in screen memory to its location in the text buffer due to the inherent inconsistency of the text. The capability to adjust the start and end of selected text after it is marked should help.
If you find a BASIC listing in the text which you would like to download, find the starting address of the listing with Program 3. Type NEW and load Program 4. When this program is run, you will be prompted for the starting address of the listing. Enter the address and RETURN. Each of the listings will then appear briefly, one at a time, near the top of the screen. It may take awhile, depending on the length of the listing, but when it is done, your listing has become a program. You can now delete Program 4 from the end of your downloaded program and SAVE or RUN it.
When Program 4 reaches the end of a program listing, it terminates with an error message. This is due to the absence of a line number or valid BASIC statement. Although this does end the program at the proper point, maybe you can come up with a more elegant way to terminate execution.
Program 2
Line 2 conditions the interrupt service routine to sound an audible alarm when the text buffer is within 256 bytes of being filled. It also changes the IRQ Vector to point to the interrupt routine and sets upper/lowercase mode.
Line 3 moves the top of memory down to protect the machine language routines, lookup tables, and text buffers.
Line 4 resets the BASIC pointers which were moved when the programs were saved. This must be done before editing or running any part of the program which contains variable names.
Line 5 opens a file to the RS-232 device and sets the baud rate at 300.
Line 20 sets up a zero page pointer to the start of the text buffer. The machine language subroutine then stores text in the buffer beginning at this location and increments once for each character up to the end of available RAM.
Line 40 calls the machine language subroutine loaded by Program 1 which receives data, prints it to the screen, stores it in memory, and sends data from the keyboard to the RS-232 channel. This loop will continue until the British pound sign key is pressed.
Line 125 turns off the out-of-memory alarm.
Lines 130 through 165 display a menu and call an appropriate subroutine, depending upon which menu item is selected.
Lines 170 through 200 are the subroutine which sends data to the printer.
Lines 220 through 240 are the subroutine which saves to tape all memory from the start of BASIC to the last location of data. This is accomplished by moving the start of variables pointer to the location pointed to by memory locations 1 and 2. This subroutine also ascertains whether or not the user is still logged on, continuing the program if he is and ending it if he isn't.
Program 3
Lines 10 through 28 display the instructions on the screen.
Line 30 sets the beginning of text memory and initializes the start of selected text.
Lines 40 through 130 mark the start and end of selected text.
Lines 140 through 150 print the selected text on the screen.
Lines 160 through 190 print out a hard copy of the selected text on the VIC printer.
Lines 200 through 220 are a subroutine which allows adjusting the start of selected text.
Lines 250 through 280 are a subroutine which allows adjusting the end of selected text.
Program 4
Line 60000 inputs the starting address in memory of the program listing.
Lines 60005 and 60010 clear the screen, print the characters which form the listing one at a time, and look for a carriage return character, signaling the end of a line of BASIC.
Line 60020 increments text memory by one and loops back to print the next character.
Line 60030 is executed when the end of a line of BASIC is detected. POKEing a carriage return into the keyboard buffer at this time causes the text on the screen to be centered as if input were from the keyboard.