Hello, World 1975 Style

Some time ago I stumbled across Ben Eater’s website where he builds a fully working 8-Bit Computer with little more than logic chips (7400 series) assembled on a breadboard. This caught my interest and I set down a path to build my own. 2 years on, I am still going (more on that in another post). However since then Ben has a new set of videos on building a 6502 Computer, again on a breadboard but a little easier to manage as using the MOS 6502 Microprocessor. I won’t go into details on the full build, as Ben explains this far better than I could with his excellent set of videos on YouTube which are worth a watch even if you are not planning on building one, just to appreciate how these machines work.

The MOS 6502 MPU was used in the Apple II, Atari 2600, Commodore 64, BBC Micro and Nintendo NES to name a few iconic machines of the era. It more than holds its own in the home computing revolution of the 1980s. The C64 was the best selling home PC of all time.

This home-brew project uses a modern day version of the 6502, but still executes the same code. Boasting a whopping 16KB of RAM (reasons for this, but could get it up to 64KB), and as it stands it’s able to run a very simple program. There is no input device, however there is an LCD screen for output, allowing the obligatory Hello, World message.

The main components are the 6502 chip, an EEPROM and the Versatile Interface Adapter (VIA made to compliment the 6502) chip to latch the output, as this is only available for a single clock cycle on the CPU. The 6502 has 56 instructions and its actually relatively straightforward to wire up. Instructions are given via the 8 data lines and 16 address lines. The program is stored on an EEPROM (each 16 bit address contains a single byte). I am using an assembler to take the source code in assembly language (sample below) to generate the object code (bytes) which are then stored on the EPPROM. The CPU fetches the instruction at the memory location on the EEPROM via the address lines. 

There is still some work to do to tidy up some of the wiring by replacing the temporary jumper wires with nicely pre-cut ones.

Early Build Stages – No Screen, No RAM

The build was done in a number of stages, the screen coming quite late on, so to see what was going on when the chip was powered up, an Arduino Mega 2560 was used to read the state of the address and data lines and output this to the Arduino Serial Monitor. The Mega provided enough IO pins to achieve this without the need to use shift registers or any fancy circuitry, keeping this element simple.

Using the Arduino IDE’s Serial Monitor, the address, data and ‘Read or Write’ status is easily outputted to screen to see visually what was going on with the chip.

It was very satisfying to see the 6502 come alive and starting to look for the next instruction to process. The datasheet is a must when working directly with the chip.

The serial monitor was able to show address being read and the data.

e.g. Address 0xf766 contained the instruction 0xea – which is the no-op instruction.

Programming the 6502

The source is written in Assembly using the 6502 instruction set. Once the VIA was attached I was able to send output to it which would then set the address lines on the LCD screen to drive that directly.

Sample Assembly Code

....
  ; Sends the character H to the LCD
 
  lda #"H"
  sta PORTB
  lda #RS         ; Set RS; Clear RW/E bits
  sta PORTA
  lda #(RS | E)   ; Set E bit to send instruction
  sta PORTA
  lda #RS         ; Clear E bits
  sta PORTA
 
....

The full source code is passed through the assembler and produces the program (object code)  as a list of bytes;

A9 48 8D 01 60

LDA = 0xA9. //Load a value into the Accumulator register 
STA = 0x8D. //Store a value from the Accumulator to a specified memory location 

These bytes are then written and stored in an EEPROM connected to the bus and the CPU simply reads them using its internal address pointer to know what address to read next and then executes the instruction. 

E.g LDA (LoaD Accumulator) translates to 0xA9 and stores the value 0x48 in the register. The STA (0x8D) the writes the value to address 0x6001, which goes to the interface chip, as this is effectively responding to any data at that address.

I used an Arduino Nano to create an EEPROM programmer which saved me buying a commercial EEPROM programmer.

I actually repurposed this EEPROM programmer from the 8-Bit Computer project, one extra wire and I was able to burn the code directly to the AT28C256 EEPROM.

Whats next?

I’m not sure if this is finished or not, still waiting for the next video in the series. However I would like to expand its capabilities. An ideal scenario (time being the main constraint) I would love to expand it to full 64 KB RAM and then install a 6502 version of BASIC on the EEPROM – but that’s a way off yet. I know some followers of the channel have gone as far as printing up a PCB, that would be pretty cool too.

I have enjoyed the experience, it must of been a fantastic journey back in the 70’s and 80’s with the likes of the Home Brew Computer Club to discover and build these computers that set us on the path we are on today.