home   |   primer index   |   1. Intro: Why 6502?   |   2. addr decode   |   3. mem map req.s   |   4. IRQ/NMI conx   |   5. 74 families & timing   |   6. clk gen   |   7. RST   |   8. mystery pins   |   9. AC performance construction   |   10. exp bus & interfaces   |   11. get more on a board   |   12. WW Q&A   |   13. custom PCBs   |   14. I/O ICs   |   15. displays   |   16. getting 65xx parts   |   17. project steps   |   18. program-writing   |   19. debugging   |   20. pgm tips   |   21. workbench equip   |   22. circuit potpourri


6502 PRIMER: Building your own 6502 computer


Intro: Why a 6502?

So you've decided to build a 6502 computer—or maybe you're still deciding.  You've been looking at the 6502 instruction set and some other materials on it.  Go ahead and build.  You'll enjoy it and learn a lot.  My own first creation (in 1985), although it worked, was a lot of work to build, and was not very useful, but it was the beginning of learning what would be easier and more useful.  This set of articles will give you helps and shortcuts I didn't have back then.

On the 6502.org forum, billylegota said, "I love the 6502 for its simplicity.  It is probably the best microprocessor for beginners who want to be able to build their own microcomputer and understand how the entire thing works;" and further down, Ed replied, "I second this - and it's more or the less the reason most of us are here."  commodorejohn added, "The 6502 is the most comfortable, usable minimalistic design I've ever encountered - just enough features and functionality to do pretty much anything you need, and simple enough that it's easy to learn how to put the individual puzzle pieces together to accomplish what you want.  Plus, being as cycle-efficient as it is certainly doesn't hurt."

The 6502 has several attractions over other processors:


Among the reasons companies find it attractive for new embedded controller designs are the small number of gates, small licensing fee, and according to Windbond, easy development.  As a result, the 6502 is being made today in huge volumes (over a hundred million units per year).  They're rather invisible though, controlling processes in automotive, industrial, toy, appliance, and even life-support equipment, inside custom ICs. 

The podcast here is an Aug 2015 interview with Bill Mensch, pres. of WDC who holds the IP for the 65c02 and 65816, regarding these processors and comparing them to ARM, 68000, x86, 6800, 6501, etc., and his business model and his goals.  He plans to keep the 6502 available "forever."  He obviously has a very clear vision, and he is accomplishing what he wants.  Still.  Today.  In the March 2015 podcast interview with WDC's David Cramer, WDC's VP of business development, he says there are hundreds of different products being made today with 65xx processors in them.

Nostalgia might be a reason for some to use the 6502; but for me it's not.  Even 30 years ago however a Z80 had to run at 4MHz to keep up with a 1MHz 6502; and Jack Crenshaw, an embedded-systems engineer who wrote regularly in Embedded Systems Programming magazine said in the 9/98 issue that he still couldn't figure out why, in BASIC benchmark after benchmark, the 6502 could outperform the Z80 which had more and bigger registers, a seemingly more powerful instruction set, and ran at higher clock rates.  (The 6502's zero page and improved indexed and indirect addressing modes no doubt helped.) 

On the forum, sark02 said, "My next computer was an Atari 800XL. [...] Coming from the Z80 I was initially dumbfounded by the criminal lack of registers [see also], but BY GOD was it FAST!  I spent hundreds of hours and wrote 1000s of lines of 6502 code over the following couple of years, diving deeper into the 800XL hardware and capabilities, and really came to enjoy the 6502." 

Sophie Wilson, chief architect of the ARM processor, said, "an 8MHz 32016 was completely trounced in performance terms by a 4MHz 6502."  (The 32016 was National's 32-bit processor, having 15 registers, including 8 general-purpose 32-bit registers.) 

The 65816 even outperformed the 68000 and 8086 in the Sieve of Eratosthenes benchmark. 

Since that time, the 6502's clock speed has increased by an order of magnitude (actually the fastest ones run over 200MHz, but the ones available to the hobbyist are limited to about 20MHz) and the instruction set has improved (especially on the 65816).  Assemblers and compilers have improved, making it easier to develop and maintain software.



6502 forum posts as well as projects and other things posted on the web showed the need for a 6502 primer, mostly for hardware.  We won't totally ignore software here, but there are already a lot of resources available for getting started in 6502 software.  I can't pass up the opportunity to recommend the excellent programming manual, "Programming the 65816 including the 6502, 65C02, and 65802" by David Eyes and Ron Liechty.  This is a .pdf file of a rather large book that is well laid out and is much better than the description there lets on.  Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.

"So why not use a microcontroller like Microchip PIC instead?" you might ask.  Microcontrollers (µCs) are great for tiny jobs where you develop the code once and it stays in the µC's read-only memory rather permanently.  A small µC like a PIC16 however does not have much RAM, which prevents large data arrays, and neither can it run programs from RAM, or compile or assemble code and program the result into its own limited ROM, let alone with instant turn-around, let alone while doing something else at the same time.  I've designed PICs into many commercial products, but it is out of the question for a workbench computer that may be doing a different job every day and where I want faster code development.  It has too many limitations.  And comparing 6502 programming to PIC programming, someone on the forum said, "65x02 is wonderful.  Programming 65x02 feels like vacation; you cannot get tired doing that.  It is natural, logical, it doesn't give you headache."  The microcontroller has its place; but it is usually not a full computer.

"Or why not use one of the hobbyist boards on the market that already have everything done for you?" you might ask.  There are many, and although they have their place, they do not invalidate the type of computer we're talking about.  Many will have the same limitations mentioned above for the microcontrollers.  Others, with all their gee-whiz features (USB, Bluetooth, VGA, multitasking OS, etc.), add software layers to insulate the user from the heart of the machine.  These are supposedly to make it easier; but they limit you, and you will not be learning the innards or have complete control of every I/O bit with microsecond resolution like you will want for various industrial, workbench, or hobby applications.  "enso" on the 6502.org forum has a great post about the value in a system where you can truly understand and control its hardware, its software, and its updates, here.

For any new projects, let me recommend the CMOS version (65c02), not the old original NMOS version.  It's not just about power consumption.  The CMOS version fixed all the bugs of the NMOS one, added a few nice hardware features, added more instructions and addressing modes, and is available in much higher speeds.  I have a comparison here.



Expectations and nonExpectations

This primer is to give a good grasp of computer design basics, so that with good construction, you can make a computer that works on first try, with no hardware troubleshooting.  (There are troubleshooting helps in case it doesn't though.)

Intended for newcomers to the 6502 and hobbyists building their own computers, this primer is rather rudimentary, but assumes that the reader is acquainted with a few things like

It does not assume that you know what to do with every pin of every IC.

Negative logic is marked by a bar over the signal name like CS, or, in the case of writing text, commonly an asterisk or a back slash following the name, like CS* or CS\ for "chip select not", meaning the chip is selected to read from or write to when this line is at a low voltage.  WDC's data sheets use a "B" after the signal name to mean negative logic, as in NMIB in place of NMI.  I suppose the "B" stands for "bar," but they never tell us.

There are loads of things we won't get into here, as they are not necessary for basic computer design and construction, including, but not limited to, DRAM management, wait states, programmable logic, DMA (direct memory access), MMUs (memory-management units), memory banking, multiprocessing, disc drives, USB, and Ethernet.  There's very little about video here but you can find a lot of material on video on the forum.


Next--> address decoding

last updated May 12, 2017