[net.micro.cbm] Need a program to copy from tape to disk

willy@utcs.UUCP (Bill Lauriston) (02/05/85)

The simplest way to copy a tape file to disk is to load it from
tape and save it to disk. Right?
But when the program loads it takes over .....
Here's an example of how I copied one program from tape to disk;
it should serve as a model.
1) OPEN 1,1,0,"program name"
This loads the cassette buffer with some file info:
$033C   type - was $03 for non-relocatable
$033D-E load address - was $0324 (vector to Kernal CHRIN routine)
$033F-G end address  - was $B000 (right in the middle of BASIC!)

I used SUPERMON for this - it (or something similar) makes the job
managable. Finding that the program was going to load over the top
of BASIC program text RAM meant that I'd have to move SUPERMON up
to the RAM below $D000 from the RAM below $A000. 

It also meant that BASIC would have to be swapped out before saving
memory to disk.

What I intended to do was change the load address and "continue" the
load without the autorun designed in by the vendor. I chose $034C as
the new load address which meant that screen memory would map to some
unrelated area in the displaced program (perhaps I should have chosen
$0800 to remove that concern). Anyway, it meant I had to move screen
memory up to the $C000-$D000 RAM and copy in the character ROM image.
SO - start again ...

0) Rewind the tape, reset the C64, load SUPERMON starting down from
$D000, set up for screen memory (and character ROM image) to be up
there too (2K will give you one set of characters).

1) OPEN 1,1,0,"programname"

2) In monitor "mode", change $033D to $4C, $033F to $28
New load address is $034C, new end address is $B028.

3) Change X register to $03
X reg will be tested for program type ($033C - cassette buffer).

4) .G F55D 
Branch to $F55D to continue the load  .... (this is in the middle of
the code to "load RAM from a device").

5) At end of load, examined memory from $0324 to $033B and compared 
the contents with memory from $034C to $0363. Only $034C-D was different;
$57,$F1 was to become $00,$9F. Aha! Change $034C-D to $57,$F1.

6) Swap out BASIC, swap in underlying RAM.

7) .T 034C B028 0324
Transfer the loaded program to start at the original load address.

8) .S "programname",08,0324,B000
Save memory to disk from the original load to end addresses.

9) Swap BASIC back.
This particular program started by swapping BASIC out and copying the loaded
RAM from $A000-$AFFF to $C000-$CFFF!

10) .G 9F00
Test by branching to the address plugged into the changed vector ....

11) Further test by resetting C64 and LOAD "programname",8,1, followed by
SYS dec9F00.
It worked - there was a chance that it checked to see it came from tape!