8

How did the C64 interface tape drives?

I'm aware that the external interface was basically a audio input - but how was this audio converted into digital data, and how was it loaded into RAM and executed?

Basically what I am asking is how the computer handled the audio, as it entered the machine. How was it digitized, and how was this transferred to RAM?

vidarlo
  • 298
  • 1
  • 11
  • Hi vidarlo, and welcome to the site! This question is extremely broad, and so is gathering close votes. I'd encourage you to see if you can narrow the question down a bit. For example, are you asking about how the computer formatted the data on the tape, or are you asking about how to use the BASIC prompt? – Omar and Lorraine Jan 19 '19 at 20:57
  • Sorry! I believed the question to be fairly specific. I will edit it :) – vidarlo Jan 19 '19 at 20:57
  • @vidarlo Yeah; it's clear and specific now. Thanks for the question! I'm interested to see what the answer is. – wizzwizz4 Jan 19 '19 at 22:05
  • 1
    Um, "poorly" and "slowly". Sigh. – Ed Grimm Jan 22 '19 at 04:34

1 Answers1

14

The analogue audio is turned into a 1-bit signal — either high or low.

The machine then detects positive transitions, counting the amount of time between each. That allows them to be bucketed into one of three types:

  • short, which are those closest to a 364 microseconds;
  • long, which are those closest to 524 microseconds; and
  • mark, which are 684 microseconds.

Each byte is preceded by a byte marker, which is a mark wave and a long wave.

From there onwards, 0s are stored as a short wave followed by a long wave, and 1s are stored as a long wave followed by a short wave, and each byte is completed by an odd parity bit.

So reading a byte is as simple as watching for a mark wave, then tracking the sequence of short and long waves, using the parity bit as confirmation.

All files are also preceded by periods of lead-in tone, which is just a prolonged period of short waves. The computer can use that section to calibrate itself to different tape speeds.

A complete program file then looks like:

  • lead-in tone;
  • 192 bytes of header;
  • those bytes, repeated;
  • the program data itself;
  • the program data itself, repeated;
  • 192 bytes of ending data; and
  • those 192 bytes repeated.

Commodore used repeated data as a basic means of checking integrity; it's an outlier in this regard — other micros tend to do more intelligent things but the Commodore ROM just stores bytes directly to their intended destination on first run through, then checks them on the second.

Tommy
  • 36,843
  • 2
  • 124
  • 171
  • With that close timing requirements, tape speeds appears like a crucial factor. Did different devices have close enough playback speed to read each others tapes successfully? Or did the calibration patterns take care of this? – vidarlo Jan 19 '19 at 22:10
  • If the first copy of the data is bad, do they try to use the second copy? – Tim Locke Jan 20 '19 at 00:00
  • 1
    @TimLocke, how do you tell that the first copy is bad? All you can tell is that the first and second copies don't match. – Mark Jan 20 '19 at 01:21
  • 2
    @vidarlo: A casette player whose speed was off by enough to conflate those lengths would be completely unacceptable for playing back music. Making 524 μs into 684 μs or vice versa would shift the key of the music by almost a fourth and make the playing time noticeably longer or shorter. – hmakholm left over Monica Jan 20 '19 at 01:49
  • 3
    It is worth noting, though, that this encoding is fundamentally not "basically an audio input" since the binary level transitions need to be preserved. This could work because the C64 had a dedicated tape drive. If you instead had to depend on a random audio player procured by the user (which might introduce odd phase shifts of the signal components) this format wouldn't be reliable. – hmakholm left over Monica Jan 20 '19 at 02:16
  • @Mark, they have an ODD parity bit to determine if any byte is bad. They could use a checksum, or preferably a CRC, on each copy to check whether either one is corrupted. TurboTape uses a checksum instead of wasting space on a parity bit for each byte. – Tim Locke Jan 20 '19 at 17:29
  • As to the question of how was it written into RAM: the widths of the pulses weren't measured by hardware directly; rather, the signal fed into CIA1, which could then generate an IRQ interrupt. It was up to program code how it measured the time between those interrupts and, from those times, chose what bytes to store in RAM. The OS used the three different time intervals that Tommy mentioned, but games rolled their own to get much higher performance. I highly recommend https://www.youtube.com/watch?v=JqZJ-VO-j84 – Luxocrates Jun 17 '20 at 06:51
  • 1
    I remember, there were TV shows, in the official state television (there was only a single one), where c64 tapes were played. We could record it into a casette, and then we had a program. – peterh Sep 09 '20 at 16:34
  • 1
    Didn't the commodor euse some sort of fsk? just writing the analogue value for on 1 or not does not seem like a thing that could work in practice, – theking2 Nov 15 '21 at 16:47