Orwell.

September 8th, 2013

So after finally getting the ROM burning process sorted and getting the core running I started adding IO. First the 6522 VIA. This is very simple to get working. The 8 bit data bus is connected directly. The chip is controlled by registered accessed via four pins. The chip itself has two chip select signals. On a 6502 machine the IO is memory mapped. That is the IO devices are accessed as areas in the memory map of the machine.

A 6502 computer has 16 address lines which means it can address up to 2^16 address locations (65535 addresses). Addresses are usually referred to as hexadecimal values so we say the map goes from $0000 to $FFFF (the $ indicates it’s a hex number).

The 6502 needs a few pieces of information stored in very particular address locations. These are called vectors and there are three of them. They are:

NMI (non maskable interrupt) at $FFFA-$FFFB
RESET at $FFFC-FFFD
IRQ (interrupt) at $FFFE-$FFFF

The most important for now is the RESET vector. This is the first place the processor looks when it starts up (or is reset). It will take whatever value is stored at these two locations and use that as the address to start running code from. It takes two locations to store an address since each location is only 8 bits wide (the data size on a 6502 – hence it being an 8 bit chip) but addresses are 16 bits long.

The other two vectors are used for handling interrupts.

Because the RESET vector is called as soon as the machine start there needs to be somewhere there waiting to be read. Because it has to be there before the computer has even done anything that information is stored in ROM, the read only memory. We have to make sure our ROM is covering those locations. Because I am using a 32k ROM chip (27c256 which is 256k bits of space divided into 256/8 bytes of storage) the ROM will cover the second half of the 64k memory map from $8000 – $FFFF.

The 6502 also has another pre-requisite which is to use certain addressing modes and the processors stack (memory used to temporary store information) there has to be RAM available from $0000 to $01FF. This area of memory is called Page 0 and Page 1. Page 0 is used for the addressing modes and Page 1 is for the stack. Since we have to have RAM at these locations we start the RAM from $0000 and extend upwards. I am using a 32k SRAM chip (62256) but only actually accessing half of it for 16k. So RAM is extending from $0000 to $3FFF.

The ‘hole’ in the middle between RAM and ROM,  from $4000 to $7FFF, is for IO.

Because of the way the address decoding works I can use certain addresses for different IO chips. The VIA I added I made addressable at location $5000. I attach the four register pins of the VIA to the low address pins (A0-A3) so to actually write to the register you simply write to addresses $5000-$5003).

The VIA itself has two 8 bit ports and some control lines. The ports can be used as inputs or outputs. The VIA also has timers and counters built in and it can be used for some interesting things. I will use mine to read the keyboard mainly.

To drive the screen I need a serial output. Apparently you can use a VIA to do this but it never works well so instead I have another IO chip, a 6551 ACIA. This is also mapped into the IO space at location $4800. Like the VIA it has registers to control it. This chip will allow you to do simple serial comms at up to 19200 baud.

I wired that in and am using that to send serial data to my screen. Unfortunately I couldn’t get it working properly. I definitely got data to the screen but often it was garbled. The fact I was getting anything meant the serial connection was working. I confirmed this by temporarily wiring up a MAX232 chip and converting the TTL serial levels into real 232 levels to feed into my ammo tin computer where I could monitor the serial output in Hyper-terminal. I got the same garbled display there as on the screen.

I was stumped for a while until I posted on the 6502 forum and someone there worked out that my data bits 4 and 7 were mirrored. This was causing odd things in my text output where all upper case characters were printing out correctly but numbers were all garbled. Ths is because of how the character set is mapped on my IO device.

I checked my wiring and I did have an error. When breadboarding this is very easy to do. Especially on a complicated layout like a computer. Because of the lack of pins I was picking up the data bus off the simple output latch I have. I am using a 74HC373 IC for that which has an odd pin arrangement. I had one of the wires hooked to the wrong pin! I will change that IC for a 74HC573 which has all data input on one side of the chip and outputs on the other. Much easier to wire up right (and ultimately route on the PCB).

So I finally got the video output working. I wrote some simple code to output constant strings from ROM and that works well and the display looks good.

IMG_4145_1 Video output (complete with typos)!

Next is getting the keyboard working. I am using the same circuit with a 4051 multiplexer as used in the Oric computer described in Garth’s primer here: http://wilsonminesco.com/6502primer/potpourri.html#KBD

So far I have it wired up (more breadboards) so hitting a key will pull down the appropriate pin on the VIA port which is set up as inputs with 4.7k pull up resistors. I think that’s how it is supposed to work. The rows go to the multiplexer and get selected one at a time then I can read the port and check the bits to see which columns are being pulled low (by a pressed key). You scan each row at a time then check each column. When you know which key, or keys, are being pressed by their row and column you can then look up in a table stored in ROM to figure out which actual character that key maps to. You have to handle a few tricky things like how to hand the shift key and how to do key de-bouncing but I should be able to work it out.

IMG_4143_1 Wiring hell!

Oh, the other major thing is I decided the machine needs a name. I decided to call it “Orwell” which seems a perfectly suitable name for a machine that’s meant to be from 1984!

I have also bought and received more of the 80s Usborne books as well as having more on the way. I should start reviewing each of them soon.

IMG_4157_1 Books.

Of course the ultimate aim will be having the programs in them (a lot of which are VERY simple) running on my machine. To do this I will need a Basic interpreter and I think I would like to try to get Microsoft basic running on it. This was the basis of basic on a great many machines at the time including Apple, Atari and Commodore. https://en.wikipedia.org/wiki/Microsoft_BASIC

One Response to “Orwell.”

  1. Andrew Says:

    Very interesting, keep these blog posts coming.