Sunday, July 27, 2014

How to boot strap your C64 cheap!

So you decided to go retro and buy yourself a Commodore 64 and a disk drive. Welcome to the world of retro computing. But now what?

You start by searching the net for how to get software onto the c64. You quickly find out there’s an entire realm of ways to hook up the 1541 to your computer through a variety of cables. Some cables are newer and faster than others, and overall is a confusing mess of documentation. 

The other route is to buy an extra piece of hardware that lets you use memory cards, or USB, or something else to replace the disk drive, This will work, but it costs money, and well, it removes the disk drive from the picture! You want to go full retro!

I decided to go a different route. I built a ‘modern’ serial port for the commodore, following the instructions http://biosrhythm.com/?p=1136#comment-35325. Its mentioned there that you don’t need to hook up the VCC line, but in my case, I needed to. Without that VCC line, I was not able to transmit.

Once I had that, I spent a better portion of a day writing a BASIC application to handle a simple file transfer. I probably made this overly complicated, but it does have simplistic error checking (not very good, but better than nothing), and its pretty slow. But it does fit onto a single 64 screen! 

A few notes. First, the baud rate is set at 600. Not 300, not 1200. 600. This was the fastest baud I could go at, and reliably transfer files. If you want to try 1200, change the 7 in the first line to an 8. For 300 baud, change it to a 6.

To change the filename, edit line 1000.

In order to send the file from my desktop (A MacBookPro), I used a python application that looks like this:

#!/usr/bin/env python
import serial

s = serial.Serial("/dev/tty.usbserial-A100TLCU", baudrate=600)

# send the command to open the file.
s.write("\x01")

byte=1
with open("Handyterm.prg", "r") as f:
    while f:
        ret = -1
        data = f.read(1)
        if len(data) == 0:
            break
        s.write("\x02") # send data command
        while ret != data:
            print "sending byte: ", byte
            s.write(data)
            print "sedning: ", ord(data)
            ret = s.read(1)
            print "rec'ed: ", ord(ret)
            if ret != data:
                s.write("\x03")
            else:
                byte+=1
                break
    s.write("\x04")

To change the serial port, edit the Serial() line. You’ll also need to change the open() to serve the file you want.

Start the c64 side first, then start the desktop side. The file will be written to disk on the c64 side. If it completes successfully, both sides will exit cleanly. When i was attempting things at 1200 baud, it seems the c64 side would miss a character and ‘lock up’.. At that point, I would have to stop both sides, and do the following on the C64 side:

close1
open1,8,15,”s:zterm”;close1

That will close the file that was being written to, and then delete the incomplete file. You then need to start over.

I would transfer a decent terminal program over first. I tried CCGMS, but that seems to have a buggy Xmodem transfer. Novaterm is too many files to transfer to get working. So I settled on HandyTerm from http://www.zimmers.net/anonftp/pub/cbm/c64/comm/. HandyTerm’s Xmodem seems to work, at least at 300 baud for me (no choice for 600). 1200 failed. I suspect my serial cable is flakey.

Note that you need to transfer .prg files. Compressed files (.arc, zip) and .d64 won’t work.

1 comment:

  1. I have gone a different route to achieve the same [0]. The post is a few years old already, but it consists mainly of a description of the hardware protocol I came up with myself, with which I transfered data from the paralel port to the CIA (DB9 Joystick) in port at a "dynamical" speed.
    See, the commodore 64's cpu is paused in the c64 to enable video output, so your programs, even if they're in assembly will go out of time sync with your expectation, about every 350 cycles. My way around it is reserving two lines for state, leaving three bits for transfer.
    I also have a Action Replay cartridge that can easily handle the saving to disk. Implementing that in asm or basic wouldn't be that hard either.
    I think I don't have the code online anywhere, but I gladly share it upon request.
    [0] http://mar77i.ch/blog/c64-datatransfer

    ReplyDelete