Raspberry Pi Becomes Cycle Exact Commodore Drive Emulator

The Commodore 1541 disk drive is unlike anything you’ll ever see in modern computer hardware. At launch, the 1541 cost almost as much as the Commodore 64 it was attached to ($400, or about $1040 at today’s value). This drive had a CPU, and had its own built-in operating system. Of course, anyone using a Commodore 64 now doesn’t deal with this drive these days — you can buy an SD2IEC for twenty dollars and load all your C64 games off an SD card. If you’re cheap, there’s always the tape drive interface and a ten dollar Apple Lightning to 3.5mm headphone adapter.

But the SD2IEC isn’t compatible with everything, and hacking something together using the tape drive doesn’t have the panache required of serious Commodoring. What’s really needed is a cycle-accurate emulation of the 1541 disk drive, emulating the 6502 CPU and the two 6522 VIAs in this ancient disk drive. The Raspberry Pi comes to the rescue. [Steve White] created the Pi1541, an emulation of the Commodore 1541 disk drive that runs on the Raspberry Pi 3B.

Pi1541 is a complete emulation of the 6502 and two 6522s found inside the Commodore 1541 disk drive. It runs the same code the disk drive does, and supports all the fast loaders, demos, and copy protected original disk images that can be used with an original drive.

The only hardware required to turn a Raspberry Pi 3 into a 1541 are a few transistors in the form of a bi-directional logic level shifter, and a plug for a six-pin serial port cable. This can easily be constructed out of some Sparkfun, Adafruit, Amazon, or AliExpress parts, although we suspect anyone could whip up a Raspberry Pi hat with the same circuit in under an hour. The binaries necessary to run Pi1541 on the Raspberry Pi are available on [Steve]’s website, and he’ll be releasing the source soon.

This is a great project for the retrocomputing scene, although there is one slight drawback. Pi1541 requires a Raspberry Pi 3, and doesn’t work on the Raspberry Pi Zero. That would be an amazing bit of software, as ten dollars in parts could serve as a complete emulation of a Commodore disk drive. That said, you’re still likely to be under $50 in parts and you’re not going to find a better drive emulator around.

83 thoughts on “Raspberry Pi Becomes Cycle Exact Commodore Drive Emulator

    1. SD2IEC are fine for quick disk shuffling, loading disks you doiwnloaded from internet, making backup copies of your personal disks to SD card, etc but it’s not real good for many uncracked commercial games that uses custom fastloader code since that is what fails on SD2IEC. There are UK1541 and 1541 Ultimate but they costs a few hundred dollars and are more for hard core C64 fans.

      If you still have working 1541 drive (or 1571), you can use disk copy program to copy from disk images to real disk and run games off those real disks.

      1. I got a 1541 Ultimate II+ last year and this thing is insane. emulates 4 1541/1571 drives, tapes, twin SIDS, Ethernet, DAC audio, 16MB memory expansion (watching color nuvie videos on C64 is crazy) ROM replacement including SX64 and jiggydos, cartridge emulation including fastload and action reply with freeze functions. FTP, telnet lets you hot swap out data in the memory expantion using DMA in realtime without freezing.

        1. Also made it real easy to use a disk copy to get my old disks onto a flash card. I wound up killing a 1541’s VIA chip getting a homemade PC parallel to C64 serial adapter to work.

        2. I got a Ultimate 1541 II+ waiting for me at the post office, but cannot get it today. It sure is pretty amazing though as it can be used with both the C64 and the C128 and it supports carts, copy protected disks and copy protected tapes. Also it can give you the 16mb REU RAM so you can run some C64 REU based videos.

          1. I found the original ones most useful. Me and my brother bother learned computers and programming on them. including loading in a spreadsheet and word proc app byte by byte to help with school work. The original monitor was also dual useful since it had a composite in port so I could watch movies straight from a VCR.

        1. Exactly. CBM stands for Commodore Business Machines. They had lots of business use cases back in the day, just like a PC– when IBM wasn’t nearly as interested in the PC as they were their (more expensive) mainframe and (to some extent) their AS/400 platforms.

    1. Of course it was. I ran a business from one, programming eproms, writing code in my own assembler for microcontrollers. I kept a client database, made documents and forms on it. Still a capable machine.

  1. Stupid question here, but why can’t this be run from a Pi 1 or Pi 2? Is it a computing power/resources issue?

    A lot of us have those older units kicking around and it’d be nice to put them to use without sacrificing a Pi 3.

    1. maybe its written in python, or nodejs ;-)
      but seriously, cycle accurate can be a killer. Personally I wouldnt bother, you can get most(if not all) c64 games pre cracked anyway, I dont see the magic in waiting 30-60 seconds for disk load.

      1. It’s not the crack, it’s the software loader that speeds up disk load time. They work on real 1541/1571 but because SD2IEC does not emulate 1541 100%, the turbo loader fails.

        Look for Ultima 5 disk images and load the Program disk. On a C64 and on 128 in 64 mode, you will see a screen asking which disk drive you are using. If you choose 1541 while running off SD2IEC, the game will crash. If you choose other, it will load fine but at very slow load speed (original serial speed!)

        1. crack/patch, are there still any non patched games left? are there still any people alive playing them?
          as for non turbo slow speed there are replacement kernals with patched in turbo

    2. At the outset I fully intended to get is to work on a Pi Zero. It almost works on a Pi2. I just have not had the time to investigate why not. It is currently multi-core at the moment. One core runs the emulator whilst the other handles USB interrupts and updates the screen. I have no doubt that after I release the source (soon) it will be ported to all kinds of devices.

  2. So hilarious! The commodore DOS for C64 and the PET, was so unfinished as to barely be called a disk operating system! I never understood why they didn’t make a better implementation.
    beyond all of that! very cool project by the way!!

    1. On the other hand, that DOS allowed you to use the drive as a coprocessor. If there would have been something like Bitcoin in the 1980s, people would have written bitcoin miners for the Commodore disk drives so they’d have something to do while you’re not downloading file “$”.

      1. I remember code in one of the RUN magazine that you could set drive 8 and 9 to automatically copy disk. Once you sent the code to both disk drive, you could disconnect C64 and it’d run by itself copying disks all day long.

        No other computer have disk drive that can do this by itself with just software!

    2. They did make a better implementation. The 4000 & 8000 series PETs had a much better DOS than the C64, but those machines were limited to 32K RAM. In order to squeeze 64K RAM + kernel + BASIC into the C64, they were limited to 4K ROM for BASIC & 4K for kernel, and the DOS functionality was crippled as a result.

    3. As primitive as the dos seemed it have an advantage in that the drives were intelligent devices so the host did not have to care about the details of the file system.
      You could just hook a 1581 to a C64 and it would work.

      1. Yes, you only needed to care about paying for a drive as much as you already paid for the computer in the first place!
        I always assumed it was Tramiels “brilliant” plan of selling more MOS chips at big markup. After all alternative would be sourcing real floppy controller chip like NEC 765 or WD1771, you know, like normal people did, aka everyone.
        Hmmm, ship a cartridge with controller chip, small rom and address decoder plus STANDARD floppy? or whole effing computer at huge margin? choices choices…

        1. Had they done that way, they would have needed a filesystem and FDD driver on the C64 side taking up valuable space in the very limited ROM space of the C64. Giving the disk drive its own CPU, RAM and ROM meant the disk drive interface was fairly simple and didn’t require very much in the way of ROM and RAM space in the C64 itself.

          1. somehow everyone else managed with onboard ram without selling you kitchen sinks, not to mention Apple 2 Woz machine hack in 4 KB ram computer.

          2. Drives were more expensive because they packed almost whole another C64 inside. At the end of 1983 C64 cost ~$200, precisely the difference between Tandon TM100-1 and 1541. You paid 2x more for 10x slower drive.

          3. Yes, they had to pack more intelligence into the disk drive, to compensate for the cheaper (lower spec) main unit. My understanding of it is that C64 was targeted at a lower price point, and so corners were cut. The version of BASIC used was an older version with “very poor disk support” because it used half the RAM and they didn’t envisage disks to be that popular with their target market.

            You might have a point that the C64 disk drive was poorly designed and implemented and had a whole load of redundant hardware, but that wasn’t for the want of trying …

          4. C64 is not a multi threaded machine, no one needs non blocking IO. Why put another computer inside the drive when your main one will just be sitting there waiting for an answer, “serial” port is polled and bitbanged anyway because of “brilliant” hardware design. All this when you just needed a pass thru cartridge with floppy controller chip, additional ROM for disk handling code, and mapper (PAL/GAL, for pass thru). You could even get rid of third chip giving up pass thru, dedicating expansion port solely to the floppy.
            But Commodore/MOS didnt manufacture any floppy controller chips, think of all the lost revenue! :(

            TLDR: it would look like this:

            what is this? Precisely what I am describing :) It was called 3.5″ The Ultimate Drive TIB PLC DD-001 and was made by third party. Uses 82C765 floppy controller chip. From test in zzap64 magazine:

            “Commodore 1541 5.25″ drive
            Intro — 48 seconds
            Main Game — 130 seconds

            Commodore 1541 5.25″ drive (plus Action Replay Fastload)
            Intro — 8 seconds
            Main Game — 11 seconds

            TIB 3.5″ Ultimate Disk Drive
            Intro — 3 seconds (virtually instant, as drive takes about 3 seconds to initialize)
            Main Game — 6 seconds ”

            Standard PC drive, ROM, and standard 82C765 floppy controller chip instead of whole computer crammed into huge box, 20x faster than out of the box Commodore 1541.
            I suspect it was Commodore management driven design, and we all know how good that was cough C128, cough A600, cough CDTV, cough CD32.

          5. “But Commodore/MOS didnt manufacture any floppy controller chips,”

            Well that’s it exactly? Why would they undermine their whole business model (i.e. vertically integrated manufacturing to reduce costs) by buying in chips from a 3rd party? Just so that some hardware afficionado 30 years later can laud their parsimonious design aesthetic? That makes no sense.

            Commodore brought personal computers to the masses by doing it cheap and nasty, but “good enough”. It makes no sense to consider the cost of the 1541 without considering the cost of the original unit.

            You are comparing Apples with Apples, which is fine but you’re forgetting about the rest of the basket.

        2. Actually the 1541s $400 price doesnt seem that bad. The atari 1050s 128k drive cost $300, the shugart sa-400 cost $390 with no controller, and a Disk II with controller cost $595. The computers which these were used with would all be a much worse buy than the C64.

    4. This was actually noted by one of the design engineers in an early magazine article. They purposely used an old version of BASIC with limited disk support because the more up to date version was double the size. He said it was a painful decision but since they expected it to be mostly used with tapes anyway they decided to save the disk space. Only read this a couple of weeks ago but if I can remember where I’ll post the link.

    1. Actually this supports files which 1541 Ultimate doesn’t support, yet. I think the point was this is a $40 project that you can build yourself, instead of ordering a $200ish 1541 Ultimate and come away with a sense of accomplishment that you got it working.

  3. This looks great and could be interesting if teamed up with the raspberry pi touch screen. One thing though, I wonder if it would be possible to design something similar but instead of using an ss card to store your images on, access a network share instead? I’ve got all my d64 images on a NAS and would love the ability to access them using something like this ..

    1. I actually started to implement code for the official Raspberry Pi touch screen. Then thought that they were so expensive, very few would actually use it. I then thought about supporting all kinds of low res inexpensive SPI screens. My goal was always to keep the hardware as inexpensive as possible. Then one day I thought that the cheapest, hires touch screen is the one everybody owns already. I’m currently developing a smartphone app that can be used to communicate with the Pi via BlueTooth.

      NAS really? A 32GB SD card is too small for all your disk images?

    2. I would use SSHFS on the rPi to mount the D64 images folder on your NAS.
      Can even mount the folder over an internet connection from multiple devices.
      The files are small enough that they would still probably load decently.

  4. Exactly what I was trying to accomplish with a Pi Zero, using a bare metal kernel (this do that as well), but lost interest. Nice to see it is not impossible.
    Maybe I’ll give it another go, but with the ESP32 this time. I guess it would be possible to run emulation on one core.

    1. A few years ago, I bought an original copy of M.U.L.E. from eBay. Although 30+ yrs old, it loaded and ran perfectly! :-)
      (and that’s still one of the catchiest game tunes ever)

  5. Great project! Recently got my hands on a C64 (the all biege version )and a 1541 with a few disks.
    I had the origional C64 and a 1541 and learned to program on it inand a Commodore PET with a whopping 4k of memory. should be fun to build but what are other logic levelers other then the sparkfun bob12009. I am looking on eBay and Amazon for the needed parts.

  6. “If you’re cheap, there’s always the tape drive interface and a ten dollar Apple Lightning to 3.5mm headphone adapter.”

    You can’t just make a comment like this and not explain it. I’ve Googled this sentence and variations thereof and can’t figure out what how this works.

    1. Most likely they are referring to the jack that you would connect a cassette deck to in order to load from/save to tapes. With the correct cable and an adapter (if needed) you can playback tape files from a modern device with audio playback capabilities.

      1. Thanks for the reply but it still doesn’t explain everything. I have a Datasette, but I don’t remember seeing a headphone jack on it. I have a tape recorder with a headphone jack, but why would I need a lightning cable for that? There’s no way I can see to attach a lightning cable to the cassette interface. There’s also no way I can see to attach a 3.5mm plug to the cassette interface, either. Bewildering.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.