The Commodore 64 and 1541 Floppy Drive: The Micromanaging Bosses

April 21, 2021
Bamboo waving a 5.25 inch floppy disk in the air.

Ever have a micromanaging boss? Someone who just didn’t think you could do the job right and insisted on doing it all for you? Like, even if you were screwing up in the past, but you worked real hard and got your act together, they would still watch you like a hawk ‘cause they couldn’t trust you? Well, that’s kinda sorta what happened to the data connection between the Commodore 64 computer and the Commodore 1541 floppy drive.

Commodore built a couple of different floppy drives for their early computers, and it’s in the 5.25" 1540 floppy disk drive, made for the VIC-20, the C64’s predecessor, where all the trouble started. The 1540 has two processors – a 6502 that handle talking to the computer and understanding the files on the disk, and a 6504 that handle spinning the disk and moving the read/write head. They send data to and from the computer using a pair of MOS 6522 Versatile Interface Adapter (VIA) chips, one in the computer and one in the drive. These chips work together to transfer data to and from the CPUs in each device.

One of the big reasons for using a 6522 VIA in the VIC-20 was because of a skill it has called the shift register. A register is an area of the CPU it has immediate access to perform operations on, and it’s the fastest thing it can manipulate. When you read a byte of data (the word size of the 6502) off the floppy drive, the CPU can put it into this shift register of the 6522 and then shift a bit of it at a time to another source, like the 6522 VIA in your VIC-20. All the VIC-20 has to do is signal to the drive that it wants the next byte once you’ve received 8 bits. This is very fast since this action is hard-wired into the 6522s, and you can hook these registers up to each other. The CPUs have timers, like drums that they’re beating, so that they and their respective 6522s stay in sync with each other, putting bytes on and taking bytes off their shift registers for future computing use at the right times. It’s a clever setup that just works.

Two cat managers drumming along keeping time while two muskrat workers are moving bits along on a conveyor belt.

Well…it would “just work”, if the MOS6522 VIA didn’t have a bug in it. Occasionally, that signaling between the VIC-20’s and 1540’s shift registers would arrive a little too close to the drumbeat timer the respective CPU had with their 6522. If that happens, the 6522 would get confused, and ignore one of the bits they were shifting.

A worker turns to the manager, who is drumming, and drops the bit.

This is, of course, not good. The VIC-20 doesn’t know they’re missing a bit, the 1540 doesn’t know that they dropped a bit, and crashes would occur.

Now, other computers of the era use 6522s for communications with peripherals. The first Macintosh has a 6522 to accept keyboard input, but since the Mac initiates communication with the keyboard, rather than letting the keyboard stream everything over unchecked, it knows if it receives bad data and can re-request it. Not so with Commodore floppy drives.

Since this hardware-based fast transfer of data couldn’t be trusted, Commodore engineers had to write software that would require the CPUs to take over the jobs of the shift registers, extracting data one bit at a time from the drive and verifying each one. Writing software the CPU executes to handle these sorts of transfers manually instead of letting the hardware handle it is called bit-banging, which–

Bamboo telling us to keep it safe for work

–get your mind out of the gutter, Bamboo. Anyway, the VIC-20 CPU now has to take time out of its busy schedule to coordinate with the floppy drive CPU to gather every bit, one at a time, and assemble them into a byte themselves, acting as a very micromanage-y manager over each 6522:

The cat managers are telling the muskrats to stay focused as the muskrats manually push one bit at a time across a decommissioned conveyor belt.

When the Commodore 64 and 1541 drives came out, the buggy 6522 was replaced with the 6526 CIA, which did not have the shift register issue. Theoretically, these two chips could have been hooked together as intended in the VIC-20 days. But, to ensure that the new 1541s could be used on existing VIC-20s, the C64 and 1541 drive kept using the inefficient CPU-driven bit-banging to send data back and forth. It was made even worse when the video hardware on the C64, the VIC-II chip (the VIC-20 was named after the first generation of the chip), needed to completely halt the CPU many times a second to handle screen drawing. For this reason, the drive was purposely slowed down even more so it would work in the C64 reliably. So a bad situation got even worse!

Two muskrats complaining about being overqualified for the job now and about Vic.

The combo C64 and the 1541 were slow. Like, really really slow. The inefficient management of the bit-banging protocol and fighting VIC-II for CPU time made floppy disk usage awful, esepcially compared to Commodore’s competitors. But, just like at work, a change of management can make a world of difference for the workers. And that’s where fast loader software and cartridges come in.

Except for things written in BASIC, all the code in the C64 is 6502 machine language code and lives in unprotected memory. It’s easy to read and modify any code at any location in the computer, including the code that controls floppy disk communication. Since the 1541 also has a 6502 CPU and RAM, all the code there can be read and modified, too. The simplest way to make the connection between computer and floppy drive faster is to replace the code that runs the bit-banging protocol between the devices. There were a bunch of different cartridges sold, usually by game manufacturers like Epyx and Cinemaware, that would modify the code in the C64 and 1541 to replace the inefficient bit-banging managers with much more efficient, but still bit-banging, ones. It wasn’t as fast as hooking up the shift registers, but it was, even with the most simplistic, naive code, at least 5 times faster than the original Commodore code.

Two coyotes are cheering on two muskrats who are passing entire bytes at a time along the conveyor belt. Everyone is in winter sports gear.

Eventually, the shift registers were hooked up between the Commodore 128 and the 1570/1571 drives (which also had 6526s), and fast loaders weren’t as necessary for performant disk access. The CPU could spend its time doing other things, and no more micromanaging managers were needed to ensure the safety of the data coming off the disk.

Changelog

  • 2021-04-21: Initial post