A few weeks ago, a friend of my Dad’s wanted to get rid of his old C64 and as it turned out he had only used it a couple of times and it was in great condition still in its original box.
For a small fee I acquired the machine and various accessories, which seem harder and harder to get these days. I say “harder and harder to get” because I went to a local flee market the other day that had stalls with so-called “Vintage” computing hardware – but all I found were Super Nintendos, Game Cube’s, Playstation 1’s and a few home-built arcade machines with MAME interiors. Nothing really old or of note. Maybe I just don’t hang out at the right flee markets *shrug* A quick search of eBay right now reveals there are only 7 C64’s for sale, so maybe the supply is starting to dry up!
I unboxed the C64 and got it started up on the 46” LCD display I had handy:

Seeing that blue screen again gives me a good feeling, its quite a complex thing to describe. I was lucky discovering computing through the Commodore 64. As a computers go, its more of an alive creature than today’s computers. If you turn the volume up on the sound output of a C64 you can hear it processing, give it some work to do and you can hear the patterns in the data … but enough nostalgia 
I now had a functioning C64, but didn’t have anything interesting to do with it. It came with a DataSette for loading data from tape, but to do anything really interesting you need a Disk Drive.

I used to have a 1541 disk drive of my very own when I was a kid, so I decided to go and get it from storage out of my Mum’s shed.
Something to know about the 1541 disk drive it that it is a serial device that responds to commands sent to it by the C64. Electronically its almost as complex and powerful as the C64 itself – certainly alot heavier!
I powered up my 1541 drive, but alas after 15 years sitting in the shed it wasn’t working. The normal behaviour is that the green light comes on, then the red, the drive motor spins – then the red light and drive motor go off. My drive motor and red light didn’t go off, which meant the 1541 didn’t pass its own start-up diagnostic process. Disheartened I opened it up vacuumed it out and checked the obvious rubber belts and mechanics but all seemed fine.
On the main PCB I noticed that all the main IC’s were in sockets. I thought of a little trick my Dad showed me and gently pressed on each IC until it creaked slightly. Reassembled and it worked – the red light and drive motor stopped after switching it on.

Now I had a C64 and Disk Drive .. awesome.
I had an idea and decided I would get the C64 to do some slideshows. This involved getting the C64 to display coloured bitmaps – an easy task for almost any digital device these days, but back in the 64’s day displaying a photo-realistic image was a difficult task.
The C64 has a display that is 320x200 pixels and there are 16 possible colours on the C64 however that is not the whole story. The C64 has two bitmap modes:
-
Hi-Res Mode: 320x200 2 colours.
-
Multi-Colour Mode: 160x200 with 3 colours per 4x8 square plus a global background colour.
It is this second multi-colour mode that I am interested in, and while this mode displays the most colours, we lose half the horizontal resolution in exchange for the increased colour space.
The way it works is that each pixel has two bits assigned to it that specify one of four locations to find a nybble (4 bits) that designate a colour from the full 16 available on the machine.
-
00 – Get colour from the global background colour at 53280
-
01 – Upper 4 bits of screen memory (1024 to 2023)
-
10 – Lower 4 bits of screen memory (1024 to 2023)
-
11 – Lower 4 bits Colour memory (55296 to 56295)
Each group of 4x8 pixels is assigned one byte from both the screen memory and colour memory to get the additional colour space information.

This makes the total amount of storage consumed 10,001 bytes for the frame, quite a complex setup. This whole mechanism is aimed at conserving memory as it is pretty tight on a machine that really only has 40k of usable RAM.
The next challenge is to get a normal JPG photo into this format – hmmmm

The first step is to get the photo into the correct dimensions.
Resize into 320x200 first and then warp the aspect ratio into 160x200 – remembering that since all the pixels are double width, the aspect ratio will fix itself up later when it actually renders.

Next, we need to get the image into the correct colour space. I could write my own dithering algorithm, but really Adobe Photoshop does it best. Just setup a colour table with the 16 C64 colours in it and tell PhotoShop to sort it out:

Result:

The next part couldn’t be done by PhotoShop – I wrote a small program in C# to do it:
- Survey the entire picture to find the most populous colour – this will become the global background colour.
- Survey each 4x8 area of the photo find out the 3 most popular colours, and then fit the remaining pixels into the closest fit.
- Create a file containing the resulting Hi-Res buffer, Screen Memory and Colour memory.
- Render a preview just for fun


So now I have a file that is 10,001 bytes long, just have to get it onto the C64. Hook up the 1541 via the special serial cable to an old NEC Laptop (its the only thing I had around that actually still has an old SPP style parallel port!) and transfer the file into an SEQ (Sequential) file using an old DOS utility called Star Commander – its a very well written piece of software that uses the PC parallel port to emulate a C64 serial port to talk to the 1541 drive. Very clever.
With heavy reference to the C64 Programmers Reference Guide I wrote a program in BASIC that loads the file from disk and puts all the bytes where they are supposed to go.
It was then I also remembered how BASIC on the C64 actually executes … very slowly!
Oh well – re-writing it in machine code is a project for later!
And the final rendered result on the C64 ……

…… I don’t know why, but I think thats an awesome result from a 30 year old computer 