Hacker News new | past | comments | ask | show | jobs | submit login
Visual simulation of the 6502 CPU (visual6502.org)
129 points by gaoprea on June 13, 2012 | hide | past | favorite | 24 comments



Any folks on here know of good resources that might help someone begin to understand what they're looking at here?

More generally, learning about the physical operation of microprocessors? I'm particularly iffy when it gets to where the wires and the assembler meet, if you will.


Watch "Reverse Engineering the MOS 6502 CPU".

It's a fascinating talk describing the 6502's history and internal workings, as well as how the visual6502 project came to be.

MP4: http://mirror.fem-net.de/CCC/27C3/mp4-h264-HQ/27c3-4159-en-r...

Youtube: http://www.youtube.com/watch?v=HW9AWBFH1sA


This is not a trivial question at all, since this sort of design is usually a third year undergraduate EE/ECE class, second year at the very earliest, usually in conjunction with semiconductor physics. It took an entire semester for me to be able to comfortable design (by hand) simple circuits in VLSI tools, such an adder. But usually folks will start with the simplest and fundamental of VLSI circuits, the NAND gate:

http://en.wikipedia.org/wiki/CMOS

In particular, see:

http://en.wikipedia.org/wiki/File:CMOS_NAND_Layout.svg

and compare it with the schematic form of the circuit:

http://en.wikipedia.org/wiki/File:CMOS_NAND.svg

which you can think of as a "zoomed" in version of a single gate for the entire chip. Looking at the full chip is often interesting and amusing, but not particularly illuminating. Instead, it's best to start with lower level primitives, just as you would in programming.

Ignoring the ground circuity for now, think of A and B as the inputs, OUT as the OUTPUT, and trying to get a path from "VDD" to OUT to "energize" the output. In this case, you can see that when both A and B are activated ("blocking", if you will) there is no way for the VDD (blue) to make it "through" A or B to get to OUT (center line in yellow square). Again, see the NAND schematic, which also depicts this in non-layout form. On the other hand, when either A or B (or both) are "turned off", VDD has a clear path to OUT through the middle blue segment. The ground circuitry is similar, but it's based on De Morgan's laws.

To be fair, most people don't build CPUs (entirely) by hand anymore. They are often VHDL/Verilog that is run through place/route algorithms. Think of a compiler, except a compiler that generates hardware instead of machine code. Just as optimization in a compiler might mean "reducing" instructions, optimization here might mean minimizing power usage or area of the chip. And just as compilers must deal with "finite registers", these compilers must contend with different layers of metal and making sure that the same metal does not incorrectly touch itself to create shorts.


You could read Petzold's book "Code - The Hidden Language of Computer Hardware and Software"

(http://www.charlespetzold.com/code/)

Or the Art of Electronics Student Manual, which goes through the process of building a computer.

(http://www.amazon.co.uk/The-Art-Electronics-Student-Manual/d...)

One thing that really helped me was getting a circuit diagram for a simple 8 bit computer, and then creating a memory map by tracing the address lines and writing what numbers were needed to enable addressing or not. Uh, I've done a really poor job of explaining this. Wikipedia does slightly better - (http://en.wikipedia.org/wiki/Memory-mapped_I/O) but there must be something even better than that.

These slides have the limitation of being slides, but they seem (at first glance) to be pretty good.

(http://research.cs.tamu.edu/prism/lectures/mbsd/mbsd_l16.pdf)


This is a pretty standard textbook for a Systems Architecture course in a CS program, which is where students typically build a processor from scratch: http://www.amazon.com/Computer-Organization-Design-Fourth-Ed...


"... Any folks on here know of good resources that might help someone begin to understand what they're looking at here? ..."

with this book I learned about SW/HW interfacing with 6502 ~ "Programming & Interfacing the 6502, with Experiments", Marvin L. Dejong ~ http://www.amazon.com/Programming-Interfacing-6502-Experimen... A review can be found here ~ http://www.atarimagazines.com/computeii/issue2/page21.php

There are plenty more references here ~ http://www.6502.org/books


You can tell the software bias in the HN community because almost every book recommended is inappropriate if you want to understand the image of the chip shown in the link. Even looking at "Art of Electronics", it's too high level, and my personal opinion is that it's actually a terrible text book (though a good reference book) -- I sometimes wonder if people who recommend it have actually read it themselves (much like people who recommend Knuth).

Instead, what you will want to look at is the topic of VLSI, if are in fact interested in how to read the chip image (though again, you'd need to be able to "zoom" in). I mentioned earlier that often the pre-requisites to this are basically things like circuit analysis, microelectronic circuits, and semiconductor physics, but the reality is that if you want to just hobby with VLSI then you only need a very small amount of this background knowledge, because the software tools for VLSI abstract many of these concepts out into things like "METAL1" and "METAL2", and the tools knows about the underlying physics rules, to where you don't actually have to worry about deriving the spacing rules for metals and such (that is, given an x nm chip process the minimal spacing between poly should be y nm). Indeed, in day to day usage, I think about custom chip design more as constructing "LEGO" blocks + water pipes rather than their underlying physical properties, and at this point I know them better by their highlight color and honestly have completely forgotten what the metals themselves are actually are.

Now unfortunately, unlike Computer Science, it's hard to find good books that can serve as a textbook rather than a reference tome. I am not sure why this is the case. It's also really hard to find a good book that is positioned correctly. Most are either way too extreme on the Physics side, or too quickly switch to VHDL or high-level chip languages, assuming that the software will generate the chip "image" for you. Another problem is that VLSI chip design is hugely proprietary; the open source tools are decades away from incredibly expensive tools like Mentor, Cadence, Synopsys, etc -- and you will get a nice throwback to Motif and X11 since usability does not seem to be a strong suit of these tools!

So, unfortunately my recommendation is to simply "search for VLSI" or maybe "VHDL" if you want to start more on the software side as a starting keyword for books and pick something that is the appropriate mix of what you are looking for.


Yeah, check out "Feynman Lectures on Computation": https://rapidshare.com/files/2100994846/Feynman_Lectures_on_...

It's fantastic. Feynman dives all the way down to the very fundamentals of how a computer could be built.

Much of the information is likely dated; nonetheless, it's still viable.


Or, if you happen to prefer getting still-in-print books legally rather than pirating them, http://isbn.nu/0738202967 .


There's a chip-layout game in Flash, by the author of SpaceChem, that's pretty realistic. Review: http://jayisgames.com/archives/2009/03/engineer_of_the_peopl...


This book (The Elements of Computing Systems) made it click for me:

http://www1.idc.ac.il/tecs/

One of the most rewarding books I've ever read.


That's an impressively detailed simulation. This is tangentially related, but I made an html5 Apple ][+ emulator which, of course, includes a 6502 component. Mine doesn't simulate gates or anything that cool (and isn't even 100% correct yet) but it boots and runs a lot of different software (at full speed): http://porkrind.org/a2/



I have no idea what is going on here, but it looks really neat.


IIRC, it's a JS simulation based on the physical transistors of the original processor.

Neat, indeed.




Appears to not work in Chrome (at least for me). Safari did the trick though.


Works in Chrome for me. (Windows 7, 64 bit, no extensions installed.)


Fancy. But what's it for?


For writing DCPU-16 emulators, of course!


Preserving history.


Wow this is really cool.


My eye hurts.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: