Load Commodore Computer Programs Using a Web Browser

by RaspberryPioneer in Circuits > Computers

446 Views, 7 Favorites, 0 Comments

Load Commodore Computer Programs Using a Web Browser

app-start-screen.png

Here's a cheap and simple way of loading software onto a Commodore 64 or Commodore Vic-20 retro-computer via a web browser, with the help of an Arduino / clone microcontroller. The web browser must support the Web Serial API, which up-to-date versions of Chrome, Edge and Opera all do.

 Some of the main features are:

  1. Load D64, PRG and T64 program files, including multi-loaders to your Commodore
  2. Works with the C64 EPYX fast-load cartridge
  3. Runs from local HTML/JavaScript files. No webserver is required
  4. Select programs using a simple GUI
  5. View box art for the program where this has been set-up
  6. Works with various 5V 16Mhz Arduino / clone microcontrollers, including the popular Arduino Uno
  7. Requires simple connections to the Commodore serial interface and Windows PC / laptop

If this project seems familiar, it is a follow up to the Load Commodore Computer Programs Using MS Excel project! Apart from the browser interface, the main differences are the introduction of EPYX fast-load cartridge support and display of the program file directory via the browser.

Supplies

components.png

The parts are cheap and readily available on eBay.

  1. For connecting to the Commodore, a 5V 16Mhz Arduino / clone microcontroller is used. This may be an ATmega32U4 device (Micro, Pro-Micro and variations) or ATmega328P device (Uno, Nano)
  2. Cables, wires and headers are needed to connect the Commodore, Arduino and PC together. This varies a bit depending on the choice of Arduino used, explained further in the next section
  3. Connection to the Commodore serial port is via the 6 pin DIN socket and 5 wire cable (or jumper wires)

Chrome, Edge and Opera running on a Windows PC have been used to test this project with. I recommend using the Pro-Micro ATmega32U4 because it is compact and reliable.

Depending on what you have available to connect to the Commodore serial port, soldering a new cable may be necessary.

Hardware Connections

pro-micro-usb-beetle-to-6-pin-male-din.png
pro-micro-to-6-pin-male-din.png
arduino-uno-to-6-pin-male-din.png
pro-micro-usb-beetle-with-case.png

Important! Although the connections required are simple, there is potential for variation and errors, so only proceed if you are content to take on all risks involved. Some specific points to be aware of are listed below.

  1. Only use a 5V 16Mhz Arduino / clone microcontroller as listed in the supplies section. A 3.3V Arduino / clone is likely to be damaged if connected directly the Commodore
  2. The connections to the Commodore and Arduino are essential to get right. Damage to the Commodore and Arduino may result if this isn't done
  3. This project potentially involves soldering the pin connections for the Commodore and Arduino. Ensure you're confident to do this and that connections will be secure and will not leave pins touching one another

Next, decide the Arduino / clone to use, which also determines the cable needed to connect to your PC.

  1. The Pro-Micro needs a standard micro-USB to USB cable
  2. The Pro-Micro USB Beetle needs a USB female to USB male cable
  3. The Uno needs a USB B-type male to USB male cable

To connect the Commodore and Arduino, prepare a cable as shown in the diagrams.

  1. Soldering wires onto the 6 pin DIN connector is a bit tricky, so it's worth checking YouTube videos for tips if not done before
  2. Any digital pins may be used. The digital pins used in these diagrams are working examples
  3. The Arduino pin connections need to terminate as male pins for the Uno. For the others, usually female pins are required (depends on the choice of header pins used)

Having a reset button is useful for restarting the Arduino which is occasionally needed if a program fails in loading. The Arduino Micro and Uno already have one but many Arduino clones do not.

  1. To make one, a momentary button needs to be connected between the reset pin (usually labelled RES or RST) and ground pin (GND)
  2. Alternatively, the Arduino needs to be re-plugged in to reset it

A picture is shown of a completed, working example using a Pro-Micro USB Beetle with a reset button mounted in a Lego case. I chose the Pro-Micro USB Beetle as my main device because it is the smallest option and has a sturdy male USB header for the PC connection.

Software Installation and Configuration

  1. Copy this project from https://github.com/raspberrypioneer/JSCBMLoader to a folder on a PC
  2. Download and install the Arduino IDE
  3. Use the Arduino IDE to open the sketch called commodore_sketch.ino
  4. If using the C64 EPYX fast-load cartridge, additional steps are needed. Refer to the step below for details
  5. Select the Arduino board and port. Pro-micro clones are often mentioned as being Arduino Leonardo compliant. If yours is like this, choose Arduino Leonardo as your board
  6. Compile and upload the Arduino sketch
  7. Edit the settings section at the top of the cbmloader.js program file with the Arduino pins and serial device filters used
  8. Box art images are optional, but if used must be located in the resources/art/c64 and resources/art/vic20 subfolders and given the same name as their corresponding program with a -image.jpg extension, e.g. Blue Max.d64 should have an associated image called Blue Max-image.jpg
  9. Optional help information can be added into the resources/info_c64.js and resources/info_vic20.js files for each program as shown in the example below

const info_c64 = {

,"Alien 3.d64":"Joystick port 2"

,"Blue Max.d64":"Joystick port 2"

,"Boulder Dash.d64":"Joystick port 1"

}

C64 EPYX Fast-load Cartridge Installation Steps

Skip this step if not using the C64 EPYX fast-load cartridge.

The C64 EPYX fast-load cartridge requires cycle-exact timing to work. For this, AVR assembler code is needed which may need minor amendment for the choice of input/output pins used on the Arduino.

Arduino board pin to AVR chip pin mappings

Arduino board pins are mapped to pins on the AVR chip. The AVR assembler code requires the AVR-chip pin mappings not the Arduino board pins, so a slight code change is needed to accommodate this.

The board pin to AVR-chip pin mappings are found in files created when the Arduino IDE is installed, examples below for Windows Arduino IDE v2.3.2.

Leonardo / Pro-Micro: C:\Users\xxxx\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\leonardo\pins_arduino.h

Standard / Uno: C:\Users\xxxx\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\standard\pins_arduino.h

In the ...\leonardo\pins_arduino.h file for instance, digital pin 9 (D9) maps to AVR pin 5 on port B (PB5). The AVR pin input and output port names are also needed (PINB and PORTB for PB5).

Determine the AVR-chip mapping for the Arduino pins being used

The AVR-chip pin and port mapping depend on the choice of Arduino board pins. They do not depend on the type of Arduino, so although an Uno and Pro-Micro are mentioned in the examples below, it is just the Arduino board pin choice that matters.

The simplest scenario is where all board pins share the same AVR-chip input and output port names, such as the example below used for the Arduino Uno in this case.

Atn mapped to board pin 2 (D2) is PD2. The PD pins have an input port name PIND, output PORTD, mode (not used here) DDRD

Clock mapped to board pin 3 (D3) is PD3

Data mapped to board pin 4 (D4) is PD4

Reset mapped to board pin 5 (D5) is PD5

A split port name example is below, used in this case for the Pro-Micro / Leonardo.

Atn mapped to board pin 9 (D9) is PB5. The PB pins have an input port name PINB, output PORTB, mode (not used here) DDRB

Clock mapped to board pin 18 (D20) is PF7. The PF pins have an input port name PINF, output PORTF, mode (not used here) DDRF

Data mapped to board pin 19 (D20) is PF6

Reset mapped to board pin 20 (D20) is PF5

Note. Data and clock pins must be on the same input/output port. If they are not, different board pins should be chosen.

Apply the AVR chip mappings to the epyxfastload files

From the above, find the scenario which best matches your pin selection, create a sketch subfolder and copy existing epyxfastload.h and epyxfastload.cpp files into it. The epyxfastload.h and epyxfastload.cpp will come from the uno subfolder (example where all pins share the same AVR chip input and output port names) or promicro subfolder (example where port names are split).

Amend the epyxfastload.h with the pin choices. The epyxfastload.cpp may need amendment to change the port labels (to avoid confusion), for example IEC_INPUT_B, IEC_OUTPUT_B may become IEC_INPUT_D, IEC_OUTPUT_D where port D is being used instead of B. A global change/replace in epyxfastload.h and epyxfastload.cpp will easily do this.

Copy both files into the main sketch folder and compile the sketch.

Usage Instructions

app-instructions.png
  1. Ensure all the physical connections are made between the Commodore, Arduino and PC
  2. Remember that the Commodore should always be turned off when physically connecting to it
  3. Open index.html in Chrome, Edge or Opera
  4. Click the Open files icon then navigate to a folder containing D64, PRG and T64 programs
  5. To select all files, click on one of them then press CTRL + A together and then choose Open
  6. Turn the Commodore on and click the Connect icon to select an Arduino device and connect to it
  7. From the program list, choose the program to load
  8. On the Commodore, issue the required LOAD command

LOAD "*",8 used to load the selected D64, PRG or T64 based program. The disk drive number is always 8

LOAD "*",8,1 this version of the load command is needed for many Vic-20 games and some C64 games. The program will be loaded at the memory location given in the first two bytes of a PRG file

LOAD "ABC*",8 for D64, T64 programs, used to load a program starting with certain characters (e.g. ABC)

/* shortcut for LOAD "*",8,1 with C64 EPYX fast-load cartridge only

RUN runs the program following LOAD above

LOAD "$",8 loads a directory listing of the contents of a D64 or T64 file

LIST lists the directory contents after the above

$ shortcut for LOAD "$",8 with C64 EPYX fast-load cartridge only

  1. The Search web icon searches for the selected program on the Internet, providing a shortcut to get more information about it
  2. Directory listings showing the contents of D64 and T64 files are displayed by clicking on the associated art image. They are automatically displayed if no art exists for a program

Note that load times in disk drive mode are not fast by modern standards, taking just over a minute for most C64 programs. If the C64 EPYX fast-load cartridge is used, loading takes around 4-5 seconds.

As this is not a 'true' disk drive emulator, there are some related downsides and some things which have not been tested.

  1. Some program files, typically for the C64, do not load because they require features of the actual disk drive hardware
  2. Has not been tested with C64 fast-load cartridges other than EPYX fast-load
  3. Has not been fully tested with programs that use two or more D64 files
  4. Saving programs or handling disk operations e.g. renaming a file is not currently supported
  5. This project has used a PAL C64 and Vic-20 for testing, so it's uncertain how this might work on NTSC machines

A program title may have many different roms. If having a problem, try other versions instead, especially for a favourite game.

Acknowledgements

The information and code shared by the following developers and sources is gratefully acknowledged:

  1. New 1541 emulator for arduino via desktop computer: uno2iec - Commodore 64 (C64) Forum (lemon64.com), developer Lars Wadefalk
  2. SD2IEC project, for EPYX fast-load cartridge additions
  3. How Does Epyx Fastload Make Loading Faster on a Commodore 64?, YouTube video by Commodore History

Conclusion

Future improvements could be a web-hosted version of this which could open the door to saving game high-scores. It could also allow for remote gaming, probably with turn-based games like chess.

Comments and ideas are welcome!