Converting VIC And 64 Programs To PET
Jim Butterfield, Associate Editor
This handy, short program will automatically fix VIC or 64 programs so they will run correctly on the PET/CBM.
BASIC programs move freely from PET, VIC, or Commodore 64 to the VIC or 64. But they don't flow easily to the PET from the other machines.
If you have a disk, this "Program Converter" will convert your BASIC programs easily and quickly. It will run on PET, VIC, or Commodore 64. The programs must be free from special PEEKs and POKEs, of course; but regular BASIC will work fine on any machine. Program Converter just helps you load it to the PET.
Programs which have been converted will load to any machine: PET, VIC (any memory configuration), and Commodore 64. Before conversion, the PET wasn't in the list; the other machines were capable of adjusting to "foreign" programs.
Type in Program Converter and run. It will ask you for the name of the program you wish to convert (say, a BASIC program written on the 64). Enter the name, and it will then ask you for the new name you wish to give to the converted program. Supply the name, and the job's under way.
If you have a dual drive, the new program will always be written to drive zero. After you have converted the program, the new version will still load without problems to the VIC or 64, but will also load to a standard PET.
The Program
100 PRINT "VIC/64 TO PET" 110 PRINT "PROGRAM CONVERTER" 120 PRINT 130 X = 150 : POKE X, 127 140 IF ST<>127 THEN X = 144 150 DATA 162,1, 32, 198, 255, 32, 228, 255, 166, 150, 8, 72, 32, 204, 255 160 DATA 162, 2, 32, 201, 255, 104, 32, 210, 255, 32, 204, 255, 40, 240, 226, 96 170 FOR J = 828 TO 858 : READA : POKE J, A :T=T+A : NEXT J 180 POKE 837, X:IF T<>4396 THEN STOP 200 CL0SE 1 : CL0SE 2 : CLOSE 15 210 OPEN 15, 8, 15 220 INPUT "BASIC PROGRAM"B$ 230 OPEN 1, 8, 3, B$+",P,R" 240 INPUT #15, E, E$, E1, E2 250 IF E THEN PRINT E$:GOTO 200 260 GET #1, A$, B$ 270 IF A<>CHR$(1) THEN PRINT "OOPS1":GOTO 200 280 INPUT "NEW NAME";N$ 290 OPEN 2, 8, 4, "0:" +N$+",P,W" 300 INPUT #15, E, E$, E1, E2 310 IF E THEN PRINT E$:GOTO200 320 PRINT #2, A$;CHR$(4); 330 SYS 828 340 CLOSE 2 : CLOSE 1 : CLOSE 15 350 PRINT"DONE."
The Machine Language
It may be instructive to examine the simple machine language program which does the job. Machine language isn't vital, of course; it just speeds things up. Let's look at it. At the time this part of the program runs, the files have been opened.
Get a character from the input:
(connect the input)
033C A2 01 LDX #$01 033E 20 C6 FF JSR $FFC6
(get the character)
0341 20 E4 FF JSR $FFE4
(get ST and stack it away)
(on VIC/64, STATUS is hex 90)
0344 A6 96 LDX STATUS 0346 08 PHP
(stack the input character)
0347 48 PHA
(disconnect the input)
0348 20 CC FF JSR $FFCC
(connect the output)
034B A2 02 LDX #$02 034D 20 C9 FF JSR $FFC9
(get character and send)
0350 68 PLA 0351 20 D2 FF JSR $FFD2
(disconnect the output)
0354 20 CC FF JSR $FFCC
(recall ST from stack)
0357 28 PLP 0358 F0 E2 BEQ REPEAT
(quit if ST non-zero)
035A 60 RTS
If you type Program Converter into a VIC or 64, you might like to have it convert itself. That way, you'll have a universal program converter, one that will work on the PET. By the way, the machine language won't get in the way, since it's POKEd into place by the BASIC program.