USBhost-64 by Luigi Di Fraia USBhost-64 - Turning the Commodore 64 into a USB host for Mass Storage Drives


USBhost-64: what is it?

USBhost-64 is a hardware interface that adds USB host capabilities to the Commodore 64, thus making it possible to access USB flash drives at up to 16.42 kB/s for file read/write purposes. The other good news are that FAT-16 and FAT-32 are both supported.

Changes

Last updated on the 21st of February 2015.
  • 2015/02/21: I had an enclosure prototype produced, ready for mass production if there's enough interest to go to production (at least 100 buyers)

    USBhost-64 enclosure by Luigi Di Fraia USBhost-64 enclosure by Luigi Di Fraia


  • 2014/02/12: I coded two new example applications that take advantage of the file access API


  • 2014/02/11: Further development on the file access API in assembly


  • 2014/02/05: I made a video of TAP Write, my TAP-to-tape tool for USBhost-64


  • 2014/01/27: I finished the initial preview version of USB-Commander, check the video below


  • 2013/12/16: I finished writing and testing the C version of the drivers for USBhost-64 parallel and serial interfaces (so far I had only written drivers in Assembly). These new drivers will be used for USB-Commander, scheduled to be released early in 2014


  • 2013/09/29: I wrote a Koala Painter picture loader along with a slideshow application to play full-screen animations. I plan to insert code optimizations later on


  • 2013/09/27: Benchmark tests of the parallel interface after code optimization measured a throughput of 16.42 kB/s during write!


  • 2013/09/26: I'm looking at allowing pre-ordering and producing a batch of devices :)


  • 2013/09/25: Successfully tested the tape dumping tool after rewriting it from scratch


  • 2013/09/23: I am designing the new header/logo for USBhost-64

    USBhost-64 logo by Luigi Di Fraia


  • 2013/09/22: The USB-Commander project, a file browser utility, was started


  • 2013/09/21: Successfully tested the tape masterer that writes TAP files to tape


  • 2013/09/19: I wrote a new API that provides fopen, fread, fwrite, and alike functions


  • 2013/09/18: Renamed USB-64 to USBhost-64 in order to distinguish it from an existing project


  • 2013/04/28: Published a demonstration of USBhost-64 on YouTube

  • 2011/02/26: USB BASIC was finished

  • 2010/09/03: The parallel version of USB-64 was finished and tested

  • 2010/08/30: The serial version of USB-64 was finished and tested

  • 2010/08/28: The project started as USB-64

Software

The USBhost-64 software consists of ALL of the following components and comes in both assembly and C language (excluding USB-BASIC which is written in assembly only):
  • low level drivers
  • USB Kernel
  • A coder-friendly file access API that provides fopen, fread, fwrite and alike functions
  • BASIC extension (available in direct mode and program mode)
Programmers wanting to support the USBhost-64 hardware in their software have two options:
  • assembly and C programmers should use the USB Kernel or the file access API
  • BASIC programmers should use the BASIC extension: UINIT, USAVE, etc.
Programmers might benefit of the USBhost-64 capabilities for different reasons. Examples include:
  • save animations to a USB drive from a painting program
  • stream an ASCII movie from a USB drive
  • save huge amounts of samples to a USB drive, coming from a custom data acquisition device
  • store DB data on a USB drive
No device number is assigned to USBhost-64. My USB Kernel is alone responsible for all access to a single USBhost-64 device. CBM Kernel routines are simply not used for USB access and therefore do not need to see a new device number to pass control to my USB Kernel.
In this way, I can keep the two Kernels distinct and I don't have to give custom ROMs to users in order to change their CBM Kernel ($E000-$FFFF) into something that understands new device numbers; nor I need to change system vectors to point to code that wraps CBM Kernel routines.

Supported USB Mass Storage Devices

Theoretically USBhost-64 supports all those devices that implement the standard USB mass-storage device class through the SCSI interface (not the IDE/ATAPI one):
  • external magnetic hard drives (SCSI interface only)
  • portable flash memory devices
  • adapters bridging between standard flash memory cards and a USB connection
  • digital cameras
  • various digital audio players & portable media players
  • Card readers
  • PDAs
  • mobile phones
The above list is given for reference purposes only.

I personally tried USBhost-64 with a card reader and with 3 flash drives without issues.

USB-BASIC

USB-BASIC is the easy way to take advantage of the USBhost-64 interface. It integrates into the standard CBM BASIC seamlessly and new commands are available both in program and direct mode.

There are tape, disk, and cartridge versions available so users can take their pick. I personally enjoy running USB-BASIC from my EasyFlash cartridge, but sometimes I have to load it from a TAP file using DC2N especially when I need to use my Action replay VI cartridge at the same time.



USB-BASIC on an EasyFlash cartridge

Example applications developed by myself

  • Because of the transfer rate achievable with the parallel version and because of the amount of RAM available for buffering, I wrote a tape dumping software (in assembly) for the Commodore 64, a la DC2N.
    Recent tests (Sept 2013) have confirmed that 16-bit dumping is feasible and reliable on the Commodore 64 thus making this tool somewhat valuable!



    Tape dumping software in action


  • I also wrote a tape mastering program (in assembly) that writes TAP files back to tapes.



    TAP mastering software in action


  • I am also re-writing a tool (in assembly only this time) that uses the serial version of the device to make D64 images (free time allowing).

    D64 Creator by Luigi Di Fraia



    Disk dumping software in action (WIP)


  • I also wrote a Koala Painter viewer and a slideshow player (in assembly) that can be used to play full-screen animations or presentations. It's best suited for slow-motion animations when used for full-screen hires, but things become quite faster for smaller regions.



    Hires player


  • Finally I am writing a Commander-like tool in C using cc65, USB-Commander, that can be used to explore the USB drive contents, copy files to disk, preview text files and pictures, etc.



    USB-Commander (WIP)

Future plans

  • A number of people have shown interest in USBhost-64 so I am looking at taking pre-orders and producing a batch.

  • I plan to make a third version that fits into the serial port of the Commodore 64 and draws power from an external PSU rather than from the C64 itself. The reason is that the user port connectors are becoming very rare and expensive. (Update: I was told that these connectors are not so rare; in fact, they are still manufactured, e.g. in Germany, and sold at a reasonable price - 2 euros about)
    Of course, it will only allow serial transfer at 1.2 kB/s.

  • The API will be documented in order to let developers take advantage of USBhost-64 in their own software.
    Hopefully together with the above field applications of USBhost-64 people will be encouraged to support it :)


Contact

Comments? Feedback? If you are interested in a USBhost-64 device, let me know: if enough people are interested I might consider producing a batch. The total cost could be around 45 GBP - 60 Euro, for an average batch of the parallel version with a nice enclosure (that does NOT include the cartridge: you would only get the .CRT file to use with your existing cartridge, e.g. EasyFlash).

Just e-mail me.

Pre-ordering will be soon available at this page, so keep checking for updates if interested!

Back to my C64 Section.

History of making

From an idea to a prototype

Back in April 2010 I was attending Breakpoint 2010 in Bingen Am Rhein, Germany. There, among several modern PCs one could easily spot a few Commodore computers with people actually developing some code, pixellating some picture, and the Metalvotze guys watching a pron movie on a Commodore 64.

Long story short: there are people who keep using their Commodore 64 for all sorts of creative work. Nice, isn't it?

Over time several guys have designed and made all sorts of add-ons for the Commodore 64 to make using it a more enjoyable experience nowadays. That's 25+ years after it first came out.

I've probably been a voice out of the chorus with my DC2N project: something that can play back tape ROMs at the same painfully low speed as the original ones did. That's great nostalgic stuff for those who enjoy sitting back and watching a game load, listening to its load music, and so on.
Not much of interest for people in the development area though. Well, DC2N made the task of creating tape ROMs a very straightforward one; that was the original purpose anyway.
I personally also used my DC2N to transfer files from PC, where my cross-development toolchain runs, to the Commodore 64. That occurred quite a few times during the devolopment I did for this project, of course.

So that, after Breakpoint I felt I had been lingering for too long and had to move on, explore the available options in order to add some new "nice-to-have" feature to my Commodore 64: I personally always felt the need to have file transfer using simple, fast, and cheap means.

It was a rainy day in August when I had the idea: turn the C64 into a USB host and load/save files directly from/to a USB drive: the idea of USB-64 was born (it was later renamed to USBhost-64).
It took a few days to arrange the hardware and write a driver in assembly. The first properly assembled prototype was going to appear on the 24th of August. Nobody had been informed about the progress, but a few close friends.

This is what it looked like:

USBhost-64 prototype by Luigi Di Fraia

USBhost-64 prototype (serial transfer version)

BASIC User interface

One of the first things I realized was: I need this to be hassle free also for unexperience users. It also needs to look and feel like a genuine device from the 80's for what concerns the user experience. With a few "must have" enchancements, of course.

So what does that mean? Well, to me it meant writing a superset of the CBM BASIC interpreter with new commands: USB-BASIC. Examples of new commands would include:

    USAVE
    ULOAD
    UVERIFY
    etc.

The error messages had to look and feel like the original ones too. E.g.:

    ?DISK NOT PRESENT  ERROR
    ?DISK FULL  ERROR

Of course, the superset would need to be available in a simple way, possibly having it on a cartridge so that it's ready to use at startup, as enthusi suggested.

It was at that time that I started the BASIC-Plus project: a complete framework to extend the Commodore BASIC V2 with new commands and, why not, functions.

It took a while to check around what was already available. Thanks to Fungus I came across the Transactor magazines which indeed presented an interesting framework for doing exactly what I needed. However, it showed a few features that I thought I could not live with: non BASIC-style tokens, and redefinition of IF (with the added bonus of ELSE, though).

So that, I started working my way through the BASIC and Kernel ROMs and looking for other software here and there. I eventually came to the solution I knew I would have liked. On the 28th of August I did my biggest CVS commit of the whole framework, which included by default two new BASIC commands: COMMANDS and QUIT.

Everything else is up to the programmer who wants to extend the CBM BASIC, including myself when working at USB-BASIC.

BASIC-Plus Commodore BASIC extension framework by Luigi Di Fraia

BASIC-Plus: my framework to extend CBM BASIC

USB Kernel written in assembly

At the same time I worked at BASIC-Plus, I wrote most of the USB Kernel sitting on the device driver and on which the new BASIC commands were going to sit themselves. A first proof of concept for the saving routine was already available on the 20th of August 2010:
    SYS 49501"BASICRAM.PRG",2049,40960
It took 33 seconds to complete without disabling interrupts or blanking the screen. Well, not too bad for a serial transfer. With interrupts disabled and the screen blanked, I later tried the same benchmark test and ended up with roughly 31 seconds. That's 1.2 kB/s transfer rate. Not too bad, but not too good either if you want to handle big files or stream from/to the USB drive.

I went back one step and designed a parallel interface. Unfortunately, this meant more I/O lines required on the Commodore 64 side; so that I had to borrow three from its Serial Port.

Parallel transfer

When I finally got the missing components I built the test device for parallel transfer. It looks like it is fast enough now:
    SYS 49501"BASICRAM.PRG",2049,40960
This time it took less than 4 seconds to complete: 9.5 kB/s about. That's less than half the time it takes for the Action Replay VI fastload to save the same amount of data to disk.


USBhost-64 prototype by Luigi Di Fraia

USBhost-64 prototype (parallel transfer version)

USBhost-64 prototype by Luigi Di Fraia

USBhost-64 connected to a Commodore 64

USB-BASIC load/save tests

Quickly enough I wrote the code to get a whole BASIC extension that was offering basic disk access capabilities seamlessly.


USB-BASIC for Commodore 64 by Luigi Di Fraia

USB-BASIC with a few new USB-related commands



USAVE test (from 2010)



ULOAD test (update to my similar 2010 video)

Optimizations

A few years after the above speed measurement, I decided to set up a proper tool for throughput measurements. The simplest thing I could think of doing was to measure times on the Commodore 64 itself, thus interfering slightly with the test, but not a big deal.

After coding such performance meter tool I did the tests, and this was the outcome:

USBhost-64 becnhmark test results by Luigi Di Fraia

USBhost-64 becnhmark test results: 16.42 kB/s

That's 16.42 kB/s. Is there room for improvement? Yes, there is. The driver and the software that sits on top of it are far from being heavily optimized. This could be pushed a little bit more, if wanted.

Cartridge DIY

I flashed the cartridge version of the handling software on my blank EEPROM, thanks to Dirk, a colleague from which I borrowed an UV eraser and an EPROM programmer. Other users will be able to flash the new ROM into their preferred cart, e.g. EasyFlash.

USBhost-64 cartridge for Commodore 64 by Luigi Di Fraia

USBhost-64 software on a cartridge (2010)

USBhost-64 cartridge menu for Commodore 64 by Luigi Di Fraia

USBhost-64 selection menu (2010)



USB-BASIC oldskool cartridge (2010 - EPROM based!)

Closing note

Over time USBhost-64 has been criticised in favour of IP network-based solutions. I honestly don't think these two belong to the same subject. I mean, USBhost-64 is a proof of concept put together in 2 weeks and during my free time (that means evenings and mainly nights) in August 2010. I learned a big deal of things while working at this project, including the CBM BASIC interpreter and Kernel code style, which was great.
For me, USBhost-64 is more of a proof that with some motivation, enthusiasm and the right information one can achieve things that were not thought of up to that point.


Comers since area creation: Since April 2002 - Best viewed at 1024x768



All images, files, and text on this page are Copyright ©2010 Luigi Di Fraia. All Rights Reserved.
Use of the material provided by means of this page is prohibited without the explicit permission of the owner.