Friday, June 12, 2015

Hooking up with big sister: Switching to the 65816

In which our protagonist whines about getting sidetracked by ancient board games and dead Romans and then makes excuses for abandoning the very processor he claimed he loved so much.

I should probably explain why these entries are few and far between. Apart from the demands and joys of job, family, and house, life in the 21st century turns out to be really, really distracting. In the past weeks, I've rediscovered the game Go -- much more easy to learn with YouTube lectures than with books back in the 80s -- and lost far too much sleep reading The Swerve: How the World Became Modern by Stephen Greenblatt in two late-night sittings. All this means less time for the Übersquirrel.

However, one thing I decided very early with this project is that it is going to be long-term, escapist in the best sense, and not another contributor to my to-do-list. So, it's going to progress in fits and starts.

My latest fit is switching to a different processor.

Let's not pretend this isn't a biggie. The Übersquirrel started out because of my love of the 6502, and abandoning it seems cruel and unfair. However, Tali Forth has shown me that though you can do an amazing amount with a small processor, 64 KByte of memory are simply not enough. A few megabytes, now that should be fine for any system without a GUI.

Fortunately, we can have our cake and eat it, too, regardless of what GlaDOS says. The 6502 has a big sister, the 65816 8/16-bit hybrid CPU. Historically, it only saw brief use, because computer builders quickly switched to full 16- or 32-bit designs such as the 68000 that powered my beloved Atari ST. But while those chips have fallen by the wayside from an hobbyist's point of view, the 65816 is still in production -- and the last CPU standing wins.

The 65816, which really doesn't look much different than the 65c02. Photo by Anthony King, placed in the public domain

The main advantage of the 65816 from our point of view is its address space of 24 bits, giving us 16 MByte of RAM and/or ROM. Consider the memory problem solved. Transition from the eight bit world is easy because its big sister starts off in "emulation" mode which makes it pretend it is a 6502 (with minor differences). In the beginning, we can use our old software. Flipping a bit turns it into a 16 bit machine. That should make lots of things easier.

However, this is also where the problems start. As a hybrid processor, the 65816 is more complicated than a simple 16 bit CPU. For instance, you set the the accumulator (A) and index registers (X and Y) to be eight or 16 bits independently of each other. This means a simple command such as TAX -- transfer contents of the accumulator to the X register -- has four different cases:

A is 16 bit, X is 16 bit
A is 16 bit, X is 8 bit
A is 8 bit, X is 16 bit
A is 8 bit, X is 8 bit

The command itself is always the same: TAX. Remembering what width A, X, and Y have at any given time is one of the things that make programming the 65816 harder. Also, that nice 16 MByte memory range is split up into 256 64 KByte segments. On a more practical level, there is no free emulator for Linux available and fewer assemblers that for the 6502. We might have to write both ourselves.

Our breadboarded 6502 machine was the Übersquirrel Mark Zero, so this new project will be the Mark I. In the next entry, I'll be presenting the rough design of this computer, including a slightly radical step regarding the voltage, and a new horrible pun based on the Mass Effect universe.