Sunday, September 29, 2013

A Minor Update to the Previous Post

In which our protagonist admits he's been using old software for months and provides a link to the current version.

Uh, remember in the previous entry we introduced the Ophis cross-assembler? Well, it turns out there is a newer version, a 2.0 to be exact. One thing that has changed is the way we call it:

python ophis -c infile.asm

This will produce an outfile named ophis.bin which can be fed to py65mon as before. There doesn't seem to be a new version of that, at least.

In the next entry, we return to our scheduled programming.

Wednesday, September 18, 2013

The Software Tool Chain

In which our protagonist rekindles the Editor War and then introduces tools for writing 65c02 code even before the first chip has been unpacked.

We have lots of old electronic junk in our attic, cellar, and garage, but what we don't have is an working 8-bit computer. Which leaves us with the problem of writing an operating system (to use a very grand word for a very humble piece of code) for the Übersquirrel. How do you write programs for a machine you haven't built yet?

Chuck Norris, of course, would just use two wires connected to an EEPROM on the breadboard to tap-tap-tap in the whole OS directly, because that's how Chuck Norris writes operating systems. The rest of us need some way to develop, code, and test the thing. This is what cross-assemblers and emulators are for.

(I'll be using the terms "emulator" and "simulator" interchangeably. The formal difference is that a simulator tries to model the internal state of an object as closely as possible, while an emulator doesn't give a damn and just works like it.)

Because the 6502 is such a popular processor, there are quite a number of tools available for free -- see this list, for example. For the Übersquirrel, we'll be using three programs:

Editor: Vim. This is obvious and does not require further discussion.

[Well, maybe it does if you spent your youth with healthy outdoor sports and studying Pre-Raphaelite art instead of fooling around with computers in the basement. The Editor War is the name given to the, ah, discussion between the users of the vim (historically "vi") and Emacs editors on Unix-like systems. All you need to know here is that vim is the right choice, GlaDOS was written with Emacs, and you can trust me because I've been using vi-clones for almost 30 years now.]

Vim comes with highlight support out of the box (on OS X) for files that end with ".asm".

A fragment of the Übersquirrel kernel (version alpha 008) in vim, coded in the Ophis syntax. Note that the hash sign triggers color coding for comments. Probably easy to fix, but I can't be bothered at the moment. Note also the BRA "branch always" instruction that is not available on the original 6502.

Cross-Assembler: Ophis. Written in Python by Michael Martin, it should run on most platforms. The assembler syntax is slightly different than that of most assemblers, but easy enough to learn. Most importantly, Ophis supports the extended commands of the 65c02. In our case, we invoke it with

ophis -65c02 sqos.asm sqos.prg

where sqos.asm is the assembler text written with vim and sqos.prg is the binary output. Ophis supports macros, which can be extremely useful.

Emulator: py65mon. Another Python program, written by Mike Naberezny and others, and again picked for its support of the 65c02. The documentation is a bit sparse, but a look at the code shows us where the hardwired I/O-addresses are:

$F001 - put character
$F004 - get character
$F005 - blocking get character

We invoke py65mon with

py65mon --mpu 65C02 —rom sqos.prg

and a first ghost of the computer that will be the Übersquirrel comes to life.

Now all you have to know is that the 65c02 looks for a jump vector at $FFFC and $FFFD after a reset, and then you can begin to merrily code away at your very own operating system for the 65c02.

So much for software. In the next entry, we'll discuss the hardware toolchain.

Tuesday, September 10, 2013

Back with a design change

In which our protagonist finally returns to the project with a small design change and powerful new tools, mostly created by other people.

Ah, Real Life, can't live without it, can't get jack done with it. I was too busy this summer with stuff in the house, traveling halfway across the world and back, digging a new veggie garden, and all kinds of other stuff to make progress with the 65c02. This, I have learned, will be more of a winter project.

However, there are some advantages to taking a long break.

First, the ACIA 65c51 is available again without breaking the bank. It is a far less powerful chip than the 2692A DUART we had originally considered, but it is also far simpler to use, and we'll go with that. It still needs its own clock, and a support chip (the MAX232), but this will make things easier.

Second, other people did an enormous amount of work in the meantime. Mario got his Meeprommer Project running, a EEPROM programmer for the Arduino. And to make that even better, another, UnaClocker, put together a matching shield. This makes my life a lot easier, as standing on the shoulders of taller people always does.

The Arduino and the Meeprommer shield. One fits over the other.

Of course, to use the shield, we need an Arduino, and to use the Arduino, we need a computer, and so on and so forth. So in the next entry, I'll talk some more about the tool chain. Unless some room suddenly needs to be repainted or something.