Tämä asiakirja on saatavilla myös suomeksi. Dieses Dokument ist auch auf Deutsch erhältlich.

Marko Mäkelä’s old computers: Commodore C2N datassette emulator with RS-232 interface

1. What is a C2N232?

The C2N232 is a small RS-232 interface that can be plugged to the cassette port of an 8-bit Commodore computer:

1.1 What does the name C2N232 stand for?

The name C2N232 is composed of two parts: C2N and 232. The C2N is the original model name of the Commodore tape deck, also known as the datassette. The number 232 refers to RS-232, the dominating standard for asynchronous serial communication.

1.2 Which Commodore models are supported?

The device can be connected to all Commodore 8-bit computers that are equipped with a cassette port. The Commodore 264 series requires an adapter, as the connector is different.

The device can also be used with other 8-bit computers. The driver software supports the Tangerine Oric-1 tape format.

1.3 Which software is related to the C2N232?

c2n
emulator for the original Commodore tape format (LOAD, SAVE, OPEN)
c2nload
fastloader that loads and starts in less than 10 seconds and loads the actual program at 38,400 bits per second
faucet
loader for low-level tape images (.tap)
cisp
allows the built-in firmware of the C2N232 to be reprogrammed
cbmlink
enables remote control of Commodore computers and copies memory contents, files and disks
cbmconvert
converts between different Commodore file formats

1.4 How is the RS-232 interface wired?

The RS-232 connector is a female 9-pin D-sub connector, designed to match the IBM PC/AT style serial connector.

Normally, an extension cable is connected to the RS-232 end of the C2N232. Three wires are strictly needed: pins 5 (ground), 2 (transmitted data) and 3 (received data). On a 25-pin connector, these signals can be found on the pins 7, 3, and 2, respectively. The connector on the C2N232 is wired as a DCE, that is, a null modem cable must not be used.

2. Basic Usage

2.1 How is the software started up?

The following procedures assume that you have a Commodore 64.

2.1.1 The easiest way: c2nload

  1. Hold the SHIFT key down and press STOP, or type LOAD and press RETURN.
  2. The Commodore responds with the message PRESS PLAY ON TAPE.
  3. On the big computer, start the transfer as follows. You may want to adjust the file name, the name of the serial device and the computer model.
    Commodore AmigaOS:
    c2nload -c serial.device -m 64 file.prg
    Microsoft Windows:
    c2nload -c com1 -m 64 file.prg
    Unix:
    c2nload -c /dev/ttyS0 -m 64 file.prg
  4. The Commodore blanks the screen.
  5. The Commodore responds with the message FOUND FILE.PRG.
  6. Press the C= key immediately or hold it down until the FOUND message flashes on the screen, so that the computer will not miss the rest of the program, as the C2N232 ignores the motor control signal. Do not press the space bar, or the computer may skip the rest and look for the next program header.

If the program is started with a SYS command, you can supply the SYS address with the -j switch.

2.1.2 The most versatile way: cbmlink

  1. Load the cbmlink server as described in previous section, e.g., c2nload -c /dev/ttyS0 -m 64 -j 52224 cbmprg/c2n232/c64/plain.prg.
  2. Finally, the Commodore reports READY..
  3. Now cbmlink can be invoked on the big computer.
    Commodore AmigaOS:
    cbmlink -c c2n232 serial.device
    Microsoft Windows:
    cbmlink -c c2n232 com1
    Unix:
    cbmlink -c c2n232 /dev/ttyS0
  4. You may want to save the cbmlink server to disk or to create a Commodore 128 boot sector to avoid using the slow tape protocol in the future. Note that in the current version of cbmlink, the -fr and -fw options do not translate character sets nor remove directory name prefixes or file name suffixes. You may want to rename the file to upper case first, for example, C64 SYS52224. The Commodore 64 server program can be copied to disk as follows.
    Commodore AmigaOS:
    cbmlink -c c2n232 serial.device -fw cbmprg/c64/plain.prg
    Microsoft Windows:
    cbmlink -c c2n232 com1 -fw cbmprg\c64\plain.prg
    Unix:
    cbmlink -c c2n232 /dev/ttyS0 -fw cbmprg/c64/plain.prg

2.2 Aren’t the tape routines slow?

Yes, but the tape protocol is only needed for loading the c2nload fastloader, for a few seconds. The transfer speed of actual programs is limited by the RS-232 to 38,400 bits or approximately 3,840 bytes per second.

2.3 Can low-level tape images (.tap files) be loaded?

The faucet program works for some files.

2.4 Is the C2N232 supported by any terminal program?

Unfortunately, with the current firmware, the C2N232 can only be controlled via the RS-232 interface. In the future, new firmware and sample code will be released that allow the C2N232 to accept commands from the Commodore side.

2.5 The software does not function properly in Windows!

Are you sure that the hardware FIFO of the serial interface has been enabled in the Device Manager?

You can find the Device Manager via the Control Panel. There, double click on the icon System in order to open the window System Properties. Finally, click on the tab Device Manager. In Windows 2000, there is no such tab in the window. Instead, you must select the tab Hardware and click on the button Device Manager.

A list of device drivers appears. Under Ports (COM & LPT), double click on the serial device where the C2N232 is connected.

A window Communications Port (COMx) Properties appears. Click on the tab Port Settings, select Hardware flow control and click on the button Advanced to open the window Advanced Settings for COMx. Make sure that the check box Use FIFO buffers is activated.

All other settings should be configured properly by the C2N232 software. Should the software still fail, click the button Defaults in the window Advanced Settings or the button Restore Defaults in the tab Port Settings in the Communications Port Properties window.

2.6 The software does not work correctly with USB adapters!

The drivers of USB-RS-232-adapters are generally faulty. Adapters manufactured by Keyspan have been reported to work under Mac OS X. Adapters based on the Prolific PL-2303 work both under Windows and under GNU/Linux with some modifications. Despite their high prices, the products of FTDI cannot be recommended, because the Linux driver does not implement any flow control when sending. Also the Windows driver seems to ignore flow control most of the time.

The Windows driver by Prolific from August 2005 can crash the computer. The Linux driver does not implement XON/XOFF flow control, but luckily it does support CTS/RTS correctly.

3. How is the firmware upgraded?

The firmware can be upgraded via the RS-232 port by using a computer running Unix or Microsoft Windows.

3.1 How must the board be wired?

Four active signals (RxD, TxD, CTS and RTS) must be connected and the RESET line of the AT90S2313 microcontroller (pin 1) must be wired to ground (pin 10 on the microcontroller, pin 5 on the RS-232 connector, or pin 1 of the card edge connector), and power must be supplied to the board.

There are two jumper wire pads on the production version of the board. One is almost under the microcontroller, and it can remain closed at all times. The other is located next to the cassette port connector. This RESET switch of the AT90S2313 is the jumper that must be closed in order to upgrade the firmware.

3.2 How is the software side started up?

At first you may type the following command to make a back up copy of the old firmware.

Commodore AmigaOS:
Sorry, cisp has not been ported to the Amiga yet.
Microsoft Windows:
cisp -c c2n232 com1 -s firm-old.s19
Unix:
cisp -c c2n232 /dev/ttyS0 -s firm-old.s19

Now you should either remove the RESET jumper of the AT90S2313, or power off the C2N232 for a short moment. After that, you can upload the new firmware with the following command sequence.

Commodore AmigaOS:
Sorry, cisp has not been ported to the Amiga yet.
Microsoft Windows:
cisp -c c2n232 com1 -e -l firmware.s19
Unix:
cisp -c c2n232 /dev/ttyS0 -e -l firmware.s19

3.3 cisp: failed to enable the programming mode

Did you forget to pull RESET to ground and power the C2N232 on? Are the RS-232 wires connected properly? Does your Unix box support CTS/RTS handshaking?

3.4 detect: device is locked

As the RESET line is not in the control of the cisp software, it is difficult to cure this misfeature. Most notably, the AT90S2313 will refuse to co-operate after a firmware upload with cisp -l. In order to verify the firmware, you will need to power the C2N232 off and on, or maybe alternatively disconnect and connect the RESET jumper.

4. Where can I get a C2N232?

Unless you want to build a C2N232 yourself according to one of the circuit board layouts, contact Nicolas Welte. The adapters produced by Marko Mäkelä (130 units) have now been sold out. For the latest production run, the price—including shipping to anywhere in the world—was 20 €.

4.1 How does the C2N232 look like?

[The top side of the C2N232 circuit board]

Have a look at our picture gallery for more pictures. Marko sells the devices without case, but you can do what Nicolas Welte did. He adapted a DB9-to-DB25 case for the C2N232 and glued the bottom side of the cassette connector to it:

[A DB9-to-DB25 adapter with two notches sawn on one side][The bottom side of the C2N232 tape connector glued on the case]

4.2 What software is needed?

File name Purpose Systems
c2nload A small auto-starting fastloader for the C2N232 Commodore AmigaOS, Microsoft Windows and Unix-like systems; all Commodores that can load from tape
c2n Tape deck emulator front-end for the C2N232 Commodore AmigaOS, Microsoft Windows and Unix-like systems
cbmlink File transfer and remote management of Commodore computers Commodore AmigaOS, Microsoft Windows and Unix-like systems

All Commodore-side programs have been written in 6502 assembler, while everything else is C. For the convenience of Amiga and Windows users, precompiled executables have been supplied. Users of Unix-like systems must fire up their C compilers.

4.3 Where do I get the firmware?

The C2N232 firmware page contains the firmware source code and some documentation. If you modify the code, you will need GNU Binutils to translate it.

The cisp program for transferring firmware to the AT90S2313 microcontroller, also available from the firmware page, has been tested on FreeBSD, Linux and on Microsoft Windows. You may also be able to use other software instead.

History and Future

The idea of designing the C2N232 arised on the 30th of June 2001, when Marko Mäkelä visited a fellow Commodore hacker in Newcastle upon Tyne, Christopher Phillips. Christopher had no data connection between his Commodore 64 and his main computer, an Apple Macintosh. The only feasible interface of the Mac is RS-232, and existing solutions that require a parallel port were clearly out of question.

The first prototype was assembled on a Vero board in July or August, and the software development started at the same time.

First, some code was written for reading the pulse widths of the cassette write signal, to reverse engineer the details of the Commodore cassette format, as the information supplied in the title Commodore 64 Whole Memory Guide by Tim Arnot turned out to be inaccurate. The c2n program that encodes and decodes Commodore cassette pulses was written, and the cbmconvert utility was enhanced with the high-level Commodore cassette format.

Second, the function for playing back cassette pulses was developed. It was made to work on the 11th of September 2001 when Juha Kouri and Turo Heikkinen were visiting Marko’s place in Espoo and measuring the circuit with a digital oscilloscope.

Designing the custom transfer protocol took several months due to other activities. The protocol was designed in such a way that it works on all 8-bit Commodores. In the idle state of the bus, both the cassette read and write lines are on the logical high level. Both receiving and sending is initiated by the Commodore pulling the cassette write line low. This ensures proper operation of the protocol even if the computer clears the input register that records high-to-low transitions of the cassette read line. The send operation is extremely timing-sensitive: the processor clock speed must remain constant during it.

The digital oscilloscope was needed again in October or November for debugging the custom transfer routines on the Commodore 264 series, whose cassette read input is level-sensitive and not high-to-low sensitive like in all other Commodores.

A prototype run of twenty C2N232 units was produced before entering mass production. On 22nd of May 2002, the first unit was assembled on a professionally manufactured circuit board.

The electronic components that were ordered in April 2002 arrived in early July. The first devices of the second batch were delivered in July or August of 2002. All 110 units were sold out in 2004.

In the summer of 2003, I developed a Commodore serial bus connection for the C2N232. It does successfully emulate a peripheral, such as a disk drive, but for some reason, it fails to work as a controller, i.e., to send commands to a disk drive. I stopped working on this in December 2003. You can have a look at the most recent firmware with partial serial bus support and short notes on how to test it.

I do not have interest to produce another batch of the C2N232 at this time. Nicolas Welte has some plans, including hardware support for the serial bus connection, but these hobby projects tend to take time.

Acknowledgements

Juha Kouri and Turo Heikkinen assisted me in making the prototype circuit boards and in measurements. Nicolas Welte helped me in obtaining some rare components.

Nicolas Welte and Wolfgang Moser have suggested improvements to this document.

Links