Kernel loader plug-in for WAV-PRG
Written by Fabrizio Gennari, 1999

This plug-in allows to convert C64 tapes in ordinary slow format (the one
provided by C64's kernel ROM) to PC using WAV-PRG. Only use it for those very
old programs which do not use a turbo loader, otherwise you will convert the
loader code instead of the game.

This plug-in reads both copies of the header chunk and the first copy of the
data chunk. If the two copies of the header chunk differ, the warning message
"The two copies of the header differ" and the first one will be taken as good.
The second copy of the data chunk is ignored. From the header chunk, the
filename and the start and end addresses are read, but the header chunk itself
is not saved in any file. A different plug-in should be used for that.

After each byte, a parity check is performed and the end-of-byte impulse is
sought for. After the end of the header chunk, a checksum will be performed.
If these tests fail, warning messages are displayed. The checksum test will
not be made for the data chunk.

File format

Three types of impulses appear here: short (about 16 samples at 44100 Hz),
medium (about 24 samples) and long (about 30 samples). The file is
composed by four chunks: first copy of header, second copy of header, first
copy of data, second copy of data. Each chunk begins with a pilot tone of
short
pulses, then a long pulse followed by a medium one marks the beginning of the
lead-in sequence. After the lead-in sequence come actual data bytes and a XOR
checksum of all the data bytes. The latter is sometimes missing in data
chunks.

The bytes are coded this way: one short impulse and one long one is a 0, a
long one and a short one is an 1. The byte endianness is least significant byte
first. At the end of a byte, there is a parity bit: it is 1 if there is an
even number of 1's in the byte, 0 otherwise. Then, a long and a medium impulse
appear, and a new byte begins. After the last byte of a chunk, a long and a
short impulse appear.

The first copies of header and data are introduced by the lead-in sequence of
$89, $88,...,$81. The lead-in sequence for the second copies is
$09, $08,...,$01.

The header chunk is made up of 192 bytes. These are stored in locations from
828 ($033C) to 1019 ($03FB).

828      This can be $01 or $03. $01 means relocatable file: the start address
         is moved to the location pointed to by the locations 43 ($2B) and 44
         ($2C), and the end address is moved of the same amount. This can be
         overridden by typing LOAD"NAME",1,1 (to load the file named NAME) or
         LOAD"",1,1 (to load the first found file): in those cases, the start
         and end addresses provided in the header will always be used. $03
         means on-relocatable file: the start and end addresses provided by the
         header will always be used, no matter whether the flag ,1,1 is set or
         not.
829-830  Start address (low byte, high byte)
831-832  End address (start byte, end byte)
833-848  Filename (padded with spaces until it is 16 characters long)
849-1019 These are usually spaces ($20), but, in some cases, when a fast
         loader is used, they can contain part or even all of the loader code.

Both the plug-in and this document were written with the help of
64loaders.txt, included with Tomaz Kac's 64util.