BASIC Program Merges: PET And VIC
If you have two BASIC Programs, it's hard to consolidate them together without getting typer's cramp. The command LOAD wipes the old program as it loads in the new one. This is a disappointment. There are times when you have a group of DATA statements in a program and would like to bring them into another program which will use them for a new set of computations. The same thing is true of your favorite subroutines: it's annoying to have to type them in all over again.
Merging – true merging, that is – solves this for you. You can arrange to slip extra lines into your program as if you had typed them in at the keyboard.
VIC To PET Transfers
Merging can be used to transfer BASIC programs from VIC to PET. A merged program will occupy the proper memory addresses as it arrives into the PET. LOADing a VIC program into the PET often doesn't work.
There are potential problems in moving a program between VIC and PET. For one thing, VIC color won't show on a CBM/PET.
If the program has PEEKsand POKEs, chances are it will take quite a bit of work to fit it into the other machine. If you're lucky, they can be changed to PEEK or POKE a new set of addresses; but it's not always possible to find a one-to-one translation between VIC and PET.
If the program contains machine language – look for a SYS command or USR function – you'll probably have problems cutting it over to the new machine. Some machine language programs won't even work on all models of PET – so a move to or from VIC would be much too big a shock. And the method that I will outline below won't work on machine language programs, anyway; just pure BASIC.
Writing Out The Program
To transfer a BASIC program, we're going to write cassette tape in an unusual way. It won't be a normal program tape: instead, it will be something called an ASCII listing tape. It will take about twice as long to write, and occupy about twice as much tape ... but it will be compatible.
Here's how to write this type of tape. Type:OPEN 1,1,1, "PROGNAME" : CMD 1 : LIST
... and as soon as you press the RETURN key, you'll be requested to PRESS PLAY AND RECORD ... Do it, and the tape will start. If you watch carefully, you may see the tape hesitating every few seconds or so. Eventually the tape will stop. When it does, type:PRINT #1 : CLOSE 1 ...
and tape will move one last time. When it stops, the computer will say READY and you may rewind the tape and take it out of the drive.
You have some options on the above procedure. You may call the ASCII listing anything you like: instead of PROGNAME you can call it WHISKERS or CLOUD 9. It's a good idea to give a meaningful name to tape files; when you have fifty or more tapes sitting around you'll be very happy to get a hint as to what's on a given tape. You could (if you wished) write part of a program to tape instead of the whole thing: for example, you might type LIST 300-400 instead of just LIST in the first line.
You have quite a miraculous thing on the cassette tape. It's a program, but it's written as a data file. We could read the program as if it were data, analyze it, and do any kind of computing on it we wanted to. That's unusual: programs are programs and data are data ... they seldom mix.
Getting Ready To Bring It Back
When we recall the program from this oddly formatted tape, we will bring in the lines, one at a time, and merge them with any program already in place in the computer. It will work just as if we typed the lines: new lines will fit into the program in the correct line number sequence; and if a new line number matches an old one, the new line will replace the old one.
If we are just transporting a program from VIC to PET, we must say NEW. This means that we are merging the program with nothing. The result will be the program by itself – but properly placed in the PET.
If we want to merge the program we have saved with another program, now's the time to bring that other program into your computer. The lines from tape will mix in.
The Magic Merge
Don't try to understand it. Just do it carefully. In the following, PET4 is for 4.0 Machines, PETU is for PET Upgrade Machines (they power up with ### Commodore Basic ###) and PET1 is for the Original ROM machines.
Put your "merge tape" – the one we just wrote – into the cassette drive of the computer. Now type:
VIC: POKE 19, 1 OPEN 1 PET4: POKE 16, 1 OPEN 1 PETU: POKE 13, 1 OPEN 1 PET1: POKE 3, 1 OPEN 1
... and when you press RETURN, you'll be asked to PRESS PLAY... Do it, and the tape will move briefly and the computer will report FOUND PROGNAME.
We're almost there, but you must follow the next instructions very, very carefully. Clear the screen, and type exactly three cursor down characters. Watch it! The cursor-down key may repeat if you hold it too long. Type the following starting on line 4 (if you've followed instructions, you must be on line 4, right?):
VIC : PRINT"[home]" : POKE198, 1 : POKE631, 13 : POKE 153,1 PET4 : PRINT"[home]" : POKE 158, 1 : POKE 623, 13 : POKE 175, 1 PETU : PRINT"[home]" : POKE158,1 : POKE 623,13 : POKE175, 1 PET1 : PRINT"[home]" : POKE525, 1 : POKE 527, 13 : POKE611, 1
The designation [home] above means : press the home key; the computer will print a reverse-S character. Don't type the letters H-O-M-E; that won't get you anywhere. After you've input the above line, press RETURN and things will suddenly get very busy. The cassette tape will start to move, and it will keep moving with brief stops for some time. There will be no sign of activity on the screen, except that the word READY may mysteriously appear above the line you typed.
Eventually the tape will stop moving and an error notice will print. It might be ?OUT OF DATA and it might be ?SYNTAX ERROR – but, in either case, ignore it: it's not a real error. To be neat, you should now type CLOSE 1.
Your program is now in the machine. You may go ahead and use it, or SAVE it in the more conventional way for future use.
How It Works
The basic procedure was evolved by Brad Templeton. If you want more details and happen to run across Brad, ask him. But you'd better have a week to spare.
You can merge programs together. You can transfer programs from VIC to PET (or vice versa, for that matter). But we've only just begin to tap the treasures of the Merge sequence.
For a few glorious moments, the tape unit took over control from the keyboard. Everything "typed in" from tape was executed; it just happened to be program lines in this case. We have broken the distinction between data and program files, and a world of new possibilities emerges. Programs that write programs? Programs that control the computer's other activities? They are all possible.