WAV-PRG
By Fabrizio Gennari, 1998

This programs runs on Windows 95 or NT. It does two things:
- converts WAV files containing samples of Turbo Tape 64 files to PC in emulator-readable format
(.PRG or .P00), so they can be played with PC emulators
- converts programs from .PRG, .P00 and .T64 files to WAV files, which can be recorded on a tape
and loaded on a Commodore 64 as Turbo Tape files.

Let's see how to do this.

1. CONVERTING FROM C64 TO PC
This is done in three steps.

1.1 SAMPLING THE FILE
For this you need:
- a sound card
- a tape player
- a cable connecting the output of your tape player (e.g., the headphone jack socket) to the
  input of your sound card (on a Sound Blaster, this is a jack socket marked as LINE IN)
- a sampling program (e.g. WaveStudio, bundled with any SoundBlaster, or Goldwave)

First of all, connect the tape player to the sound card. You should hear the sounds emitted
by the player from the speakers of your sound card. Set the volume of your player to a
reasonably high level (half the maximum should be fine). Set the mixing options of your
sound card so the recording level of the external output is the highest, and the other
recording sources are disabled (this is done using Windows' Volume Control application).
Set the volume of your computer speakers low, so you will not be made deaf by the grating sound
coming from the tape. Now, run the sampling program amd set the recording options as it follows:
Sampling frequency: 44100 Hz
Sample size: 8 bits
Format: PCM uncompressed, mono
WAV-PRG will not recognize files in a different format than this.
Now, sample the file and save it in WAV format. Some sound programs (e.g. Goldwave or CoolEdit)
show the waveforms in WAV files: if you can see a nice sinusoidal waveform of reasonable
amplitude, everything should work.

1.2 CONVERTING THE FILE
This is what WAV-PRG does.
Run WAV-PRG, select the page "From C64 to PC", look for your file and click on its name. If
it is not a WAV file, the message "This is not a wave file" should appear. If it is a WAV
file, but the format is not as mentioned before (44100 Hz, 8 bits, PCM mono), the message
"The format of this wave file differs from the required one" should appear. If the file is
recognized, the message "This is a convertable file" will appear. If you want the file to be
converted to the .P00 format, check the box "Convert to P00 (PC64) format". Otherwise, the
file will be converted to the .PRG format. Now, press OK.
The conversion process will start, and in a few seconds, one of the following messages
should pop up:
* "No valid Turbo Tape header was found in the file <filename>": this could mean that:
- the file is not a Turbo Tape file
- the Turbo Tape header (the initial part) is corrupted or recorded at a too high or too low
volume: try sampling the file again, adjusting the volume of your player, and retry. If it
still doesn't work, try "regenerating the signal": don't worry, it is easier than it sounds.
Just load the file on your C64 and, if it loaded without errors, save it on a new tape. The
freshly-saved file will be easier to convert.
- your sound card reverses waveforms. If this is true, toggle the "Reversed waveform" box
and try again.
* "Found!": the header has been recognized, and the conversion starts. You should see the C64
filename, the start and end addresses, and a progress bar. If the chosen format for the
converted file is .PRG, its name will be the same as on the C64, with the .PRG extension added.
If it is .P00, the C64 name will be shrunk to 8 characters using the PC64 rules, and the
extension .P00 will be appended. If a file with that name already exists, it will be overwritten.

At the end of the conversion, you will see one of these messages:
* "A checksum error occurred": this is the same as ?LOAD  ERROR. You could try sampling the
file again, adjusting the output volume of your tape player so it is not too high nor too low.
Try "regenerating the signal" as well.
* "The file <WAV filename> unexpectedly ended while converting": either the final part of the
tape was not sampled, or the recording quality was low. In the first case, try sampling for a
longer time, in the second case, try adjusting the volume of your player, or regenerating the
signal.
* "The file <filename> has been created successfully": everything went fine.

1.3 PLAYING THE GAME
You need a C64 emulator for this.
All the most popular emulators should recognize the .PRG and .P00 formats (CCS64 and VICE do,
PC64 does .P00). If you have got an emulator which doesn't, you will have to import your file
to a tape image (.T64) or a disk image (.D64) using Star Commander (http://sta.c64.org/sc.html)
or another suitable program.
The emulator C64S does not recognize .PRG or .P00 files, but can import them with the built-in
Import function.

2. CONVERTING FROM PC TO C64
This too is done in three steps.

2.1 CREATING THE .WAV FILE
This is done by WAV-PRG. Just select the page "From PC to C64", look for the file you want
to convert and click on its name. If it is a valid .PRG or .P00 file, you will see the message
"This is a convertable file" followed by the start and end addresses (the former is 2049 in
99% cases, the latter should never exceed 65536) and, in the case of .P00, the C64 filename.
To convert these files, click on OK. If it is a valid .T64 file, WAV-PRG will show the number
of total and used entries in that file. Click on OK, and the T64 dialog box appears: for each
entry, the start and end addresses and the offset inside the T64 file are shown. Click on an
entry and press OK.
Now another dialog box is shown. Type the filename you want to appear when loading the game on
the C64 (next to FOUND). If a file with the name filename.WAV already exists, a window
allows you to choose whether to overwrite it or keep it. Then, the .WAV file will be
written.

2.2 RECORDING THE .WAV FILE ON A TAPE
You need:
- a sound card
- a tape recorder with a sound input (generally marked with AUX, CD or PHONO)
- a suitable cable
- a program which allows you to play .WAV files

Connect the input of your recorder to the output of your sound card (on the Sound Blaster,
there are two outputs, LINE OUT and SPK OUT: the latter is better because of the louder
output). Now you should hear the sounds emitted by the sound card from the speakers of your
tape recorder. Set the output volume of the sound card as high as possible, disable all
the sound sources but the Wave output, keep the output volume of your tape recorder low (the
.WAV files created by WAV-PRG aren't nice to be heard), press RECORD on the recorder and
play the .WAV file.

2.3 PLAYING THE GAME
If you have got the Turbo Tape 64 program, load it, then load the game with (left arrow)L, as
usual.

Some games interfere with Turbo Tape 64 (e.g. the ones from the Blast from the Past
disks): to get around this, load the game, type
POKE 50001,228
POKE 50006,167
SYS50000
then RUN as usual.

If the end address exceeds 40960, a fake ?LOAD  ERROR message appears, but the game should
run fine. If it still doesn't, you have two alternatives:
- load the game, type
POKE 46,<end-address>/256
POKE 45,<end-address>-PEEK(46)*256
then RUN as usual.
- load Turbo Tape, then, before loading the game, turn off the fake message by typing
POKE 50566,234
POKE 50567,234

If the end address exceeds 50400, the program which is being loaded overwrites the loader,
and the C64 will crash. You will need to type the following program (you should do
this if you don't own a copy of Turbo Tape 64, too).

10 INPUT "FILENAME";A$
20 PRINT "PLEASE WAIT..."
30 FOR I = 1 TO 16
40 IF I < = LEN (A$) THEN POKE 832 + I, ASC ( MID$ (A$,I,1)): GOTO 60
50 POKE 832 + I,32
60 NEXT
70 POKE 828,3: POKE 829,38: POKE 830,3
80 POKE 831,12: POKE 832,5: POKE 171,105
90 FOR I = 38 TO 51
100 READ A: POKE 49152 + I,A: NEXT
110 FOR I = 52 TO 267
120 READ A: POKE 49408 + I,A: NEXT
130 SYS 63447: SYS 63595
140 POKE 193,38: POKE 194,192
150 POKE 174,12: POKE 175,194: SYS 63591
200 DATA 52,4,237,246,62,241,47,243
210 DATA 102,254,165,244,237,245
220 DATA 120,169,7,133,1,32,96,4
230 DATA 173,60,3,133,195,173,61,3
240 DATA 133,196,173,62,3,133,174,173
250 DATA 63,3,133,175,32,117,4,165
260 DATA 189,69,215,240,3,76,226,252
270 DATA 32,21,253,96,32,171,4,201
280 DATA 0,240,249,133,171,32,229,4
290 DATA 145,178,200,192,192,208,246,240
300 DATA 234,32,171,4,32,229,4,72
310 DATA 169,4,133,1,104,145,195,69
320 DATA 215,133,215,169,7,133,1,230
330 DATA 195,208,2,230,196,165,195,197
340 DATA 174,165,196,229,175,144,221,32
350 DATA 229,4,200,132,192,88,24,169
360 DATA 0,141,160,2,76,147,252,160
370 DATA 0,132,192,173,17,208,41,239
380 DATA 141,17,208,202,208,253,136,208
390 DATA 250,132,215,169,7,141,6,221
400 DATA 162,1,32,245,4,38,189,165
410 DATA 189,201,2,208,245,160,9,32
420 DATA 229,4,201,2,240,249,196,189
430 DATA 208,232,32,229,4,136,208,246
440 DATA 96,169,8,133,163,32,245,4
450 DATA 38,189,198,163,208,247,165,189
460 DATA 96,169,16,44,13,220,240,251
470 DATA 173,13,221,142,7,221,72, 169
480 DATA 25,141,15,221,104,74,74,96

Save it for a future use. This program writes loaders: run it, type a name, then, when
prompted, save the loader on a tape. On the same tape, just after the loader, record the
.WAV file you want to load. Rewind the tape up to the start of the loader, and load it as
usual (with LOAD, or SHIFT+RUN-STOP). The loader and the game will be loaded automatically.
In case of a loading error, a SYS64738 will be performed.

3. DISCLAIMER
This program comes with NO WARRANTY whatsoever. The programmer cannot be held responsible
for any damages caused by the use of this program. Use it at your own risk.

4. DISTRIBUTION
This program is freeware. You can use it without paying any fee, and redistribute it as you
like. Just do not charge anything for it, and do not modify it without asking the author
first.

5. HISTORY
1.0 (29th July, 1998)

First release.

1.1 (14th January, 1999)

Additions:
- Added support for .P00 and .T64 files when converting to C64.
- Added support for .P00 when converting to PC.

Refinements:
- When a new window is shown, other windows are disabled.
- Some minor graphical enhancements have been made.

Bug fixes:
- Sometimes, the message "An error occurred while opening this file" was not shown.
- A bug which caused .WAV files to be read sometimes incorrectly (the Turbo Tape header
could not be found even if it was present) has been fixed.

6. LATEST VERSION
The latest version of the program is available at
http://www.geocities.Com/SiliconValley/Platform/8224/wavprg.html .

7. CONTACTING THE AUTHOR
If you have suggestions, bug reports etc., you can send mail to the author at:
fabrigennari@iol.it

Enjoy!