Universal Tape Append For PET/CBM

Started by Blacklord, August 09, 2009, 08:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Blacklord

Many times we run into the situation where we'd like to combine programs which have been SAVEd separately. Typical examples include subroutines which can be used in many different programs; interest calculations for mortgage, loan, or savings programs; complex arithmetic for math or engineering programs; and sorting routines for data processing applications.

Owners of Commodore PET/CBM 2001-series computers have several alternatives. Several firms offer a plug-in ROM (read-only memory) in the $50 to $100 range, which adds an APPEND command to the normal instruction repertoire.

The program described here allows owners of Version 1 (BASIC 2.0), Version 2 (BASIC 3.0), or 8000 series (BASIC 4.0) PET/CBM computers automatically to combine two or more programs which were saved on cassette from either one of those two computers.

In use, the program is extremely simple. First, LOAD this APPEND program from its cassette. Next, take the APPEND cassette out of the recorder, and replace it with the cassette that has the first program you want to append to it. DO NOT LOAD the second cassette, but RUN the APPEND program that is already in the computer. You'll be instructed to "Press Play on Cassette #1", and once you do that, the program takes over. After the first program has been added, take out the cassette and insert the second one you want to add. When you RUN the APPEND program again, it will once more ask you to "Press Play...", then add the second program at the end of the first. After you've combined all the programs you want to join, delete the BASIC Append routine (type each line number, 0 through 29, pressing ‘RETURN’ after each), and use the BASIC SAVE command to store the combined version.

Preparing Programs to be Combined

A few rules must be observed with regard to the programs which are to be joined. In general, you must assure that there is no overlap in line numbers between the two (or more) programs. For example, if you have two programs where one contains lines numbered from 100 to 500 and the other contains lines 300 to 700, the computer's operating system will not react ‘normally’ if the two are appended. An easy ‘fix’ is to renumber one program or the other, so that none of its line numbers fall in the range of numbers used in the other program. An exception to this rule is the Append routine itself, because it will be deleted before you start using the combined programs.

When programs are appended, the one(s) with lower line numbers should be done first, to avoid problems.

Some programs, especially those prepared commercially, were SAVEd from the Monitor rather than BASIC, and contain machine language instructions ahead of the BASIC routines. These may not be combined using this program unless the BASIC and machine language sections are "broken apart" and stored separately. You may be able to figure out how to do this by careful study of this article and some experimentation... but be sure that you have backup copies of everything critical before you start! If the APPEND program detects one of these (relatively unusual) programs, it will give you an error message and stop without trying to do the APPEND.

As long as you have sufficient room left in the computers free memory, you may keep adding programs. If you try to add a program which requires more than the remaining free space, the program will print an error message and not attempt to APPEND.

How the Program Works

Actually there are two separate programs which work together to do the job. The first (Figure 1) is a machine-language routine, loaded in the second cassette buffer, which inspects the program in the BASIC text area and calculates where the BASIC program ends.

C*
       PC IRQ  SR  AC XR  YR  SP
";   C6FB E62E 3A  9E 36  34  FA
"
":   033A B8 08 A9 01 8D 55 03 69
":   0342 01 8D 4F 03 A9 04 8D 50
":   034A 03 8D 56 03 AD B9 08 F0
":   0352 18 AA AD B8 08 8D 55 03
":   035A 69 01 8D 4F 03 8A 8D 56
":   0362 03 69 00 8D 50 03 4C 4E
":   036A 03 AD 55 03 8D 3A 03 AD
":   0372 56 03 8D 3D 03 60 FE B7
"

Figure 1a. Machine Language Program Listing (Monitor Version, for entering in computer).

The BASIC Append routine (Figure 2) uses the machine-language routine to find the end of the current program in memory. Then it uses one of the built-in ROM (read-only memory) routines to find the "header" on the cassette tape at the beginning of the SAVEd program. That header contains the starting and ending addresses from which its program was saved, and knowing those values allows us to calculate the length of the program on tape.

", 033C A9 01    LDA #$01
", 033E 8D 55 03 STA $0355
", 0341 69 01    ADC #$01
", 0343 8D 4F 03 STA $034F
", 0346 A9 04    LDA #$04
", 0348 8D 50 03 STA $0350
", 034B 8D 56 03 STA $0356
", 034E AD B9 08 LDA $08B9
", 0351 F0 18    BEQ $036B
", 0353 AA       TAX
", 0354 RD B8 08 LDA $08B8
", 0357 8D 55 03 STA $0355
", 035A 69 01    ADC #$01
", 035C 8D 4F 03 STA $034F
", 035F 8A       TXA
", 0360 8D 56 03 STA $0356
", 0363 69 00    ADC #$00
", 0365 8D 50 03 STA $0350
", 0368 4C 4E 03 JMP $034E
", 036B AD 55 03 LDA $0355
", 036E 8D 3A 03 STA $033A
", 0371 AD 56 03 LDA $0356
", 0374 8D 3B 03 STA $033B
", 0377 60       RTS

Figure lb. Machine Language Program (Disassembly Listing)

Armed with knowledge of the end of the current program in memory, and the length of the program to be appended, we can calculate new starting and ending locations for loading the program from tape. By changing those values before we bring the program in from the computer, we can start loading the new program right where the old one ends.

Complications

Back when there was only one operating system (set of ROMs) for the PET, the APPEND routine was much simpler. The second version (BASIC 3.0) made several changes which increased the challenge in designing an APPEND program to run on either version and APPEND a tape which had been created on either version. Appearance of BASIC 4.0 in the 8000 series complicated matters further. There are now nine possible combinations, as depicted in Figure 3.

The first problem, and most obvious, is that the/various "built-in" routines used by the program are in different locations in the two versions. Further­more, some "fixing-up" which is done automatically in BASIC 2.0 by the tape load routine requires calls to other routines in BASIC 3.0 and 4.0. A summary of these differences is shown in Figure 4.

0 REM-SUPER APPEND-FOR PET/CBM, COPYRIGHT OCT 79 BY ROY BUSDIECKER
1 P=256 : SYS828 : PRINTPEEK <826> + P*PEEK <827> : PV = PEEK<50003> :PRINT"*******"
2 GOSUB 12 : A1 = PEEK <826> +P*PEEK <827> -1 : A2%=A1/256 : A3=A1 -P*A2% : IFPV = 160THEN16
3 ONPV + 1GOTO14, 15
4 P = 256 : B1 = PEEK <635>+P*PEEK <636> : B2 = PEEK <637> + P*PEEK <638> : IFPEEK <636> <> 4THEN27
5 IFPEEK<635>=0THEN8
6 IFPEEK <635> = i THENA 1 =A1 + 1 : A2%=A1/256 : A3=A1 -P*A2% : GOTO8
7 GOTO27
8 B3 = B2 -B1 + A1 : C1% = B3/256 : C2 = B3 - P*C1% : POKE635, A3 : POKE636, A2% : POKE637, C2
9 POKE638, C1% : IFC1%> PEEK <53> ORC1% = PEEK < 53> ANDC2> = PEEK <52> THEN29
10 IFPV = 160THEN23
11 ONPV + 1GOTO17,18
12 IFPV = 160THENPOKE158,9 : BU = 623 : FORI = BUTOBU + 8 : POKEI, 13: NEXT : RETURN
13 POKE525-PV*367,9 : BU=527+PV*96 : FORI = BUTOBU + 8 : POKEI, 13 : NEXT : RETURN
14 PRINT "SYS62894*******" : PRINT "GOTO4.IIIIIIIIIIIIII" : STOP
15 PRINT "SYS62886*******" : PRINT "GOTO4. IIIIIIIIIIIIII" : STOP
16 PRINT "SYS62949*******" : PRINT "GOTO4: IIIIIIIIIIIIII" : STOP
17 GOSUB12 : PRINT."*****3YS62403" : PRINT": IIIIIIIII" : STOP
18 GOSUB12 : PRINT " *****SYS62393WWW" : PRINT " GOTO19: IIIIIIIIIIIIII" : STOP
19 SYS50242
20 SYS828
21 POKE42,PEEK <826>+2:P0KE44,PEEK <826>+2:POKE46, PEEK <826>+2
22 POKE43,PEEK <827> :POKE45,PEEK <827> :POKE47, PEEK <827> : END
23 GOSUB12 : PRINT " *****SYS62456 ***" : PRINT "GOTO24:IIIIIIIIIIIII" : STOP
24 SYS46262
25 SYS828
26 GOTO21
27 PRINT"**ERRQR.&squf; TAPE TO BE APPENDED IS NOT A SIMPLE BASIC PROGRAM."
28 PRINT"MRCHINE-LANGUAGE SEGMENTS MUST BE SAVED SEPARATELY." : END
29 PRINT"**ERROR.&squf; NOT ENOUGH MEMORY SPACE LEFT TO APPEND THIS PROGRAM." : END