Hacker News new | past | comments | ask | show | jobs | submit login
6502 simulated at transistor level in Javascript (visual6502.org)
123 points by pnp on Sept 17, 2010 | hide | past | web | favorite | 28 comments



At the transistor level? I assume this means that each transistor is simulated digitally, as a pure switch, and not as an analog component, which I imagine would be near impossible to do in Javascript on current hardware.

Not the most practical way to emulate a CPU, but surely a good exercise in learning how a processor works from the component level on up.


Yes, according to the FAQ, it is a digital simulation, with no delays.

Notably, the description of the 6502 was reverse engineered from die photographs.


I assume this means that each transistor is simulated digitally, as a pure switch, and not as an analog component, which I imagine would be near impossible to do in Javascript on current hardware.

Thought this for the longest time, too, but reality can't be simulated on a computer. Only a simplified model can.


Maybe not exactly, but you can get pretty damn close. The digital audio guys are the ones who are really into this. It's the only way to get the exact feel of old audio gear.

http://www.simulanalog.org/

An amp is much simpler than a microchip but the ideas are there:

http://dafx.labri.fr/main/papers/p169.pdf


> Maybe not exactly, but you can get pretty damn close.

Pretty different things those two, if you consider chaos theory.

Still, computers are by design created in a way which can be easily modeled.


> I imagine would be near impossible to do in Javascript on current hardware.

In JavaScript, most probably. But on current hardware, just perhaps. You can't forget the immense floating-point power we have compositing polygons on our displays... GPUs could be used to simulate such a system close to real time, I guess (didn't do the math on that).


Now that is a hard core obsession; with retrocomputing or JavaScript, I'm not sure which.


I put on a hat so I could take it off again. Very impressive. Now I know what do to do with those old Atari game cartridges which have been sitting in a box by my desk for 5 years.

Also, this seems like it should have a unit to itself on any CS course, not to mention serving as a platform much further research. Maybe I should take up 6502 Assembler as a hobby. Their SigGraph slides are well worth a look: http://www.visual6502.org/docs/6502_in_action_14_web.pdf


I might be biased as a retrocoder hobbyist myself, but I feel like 6502 assembly would still be very useful in the classroom as a teaching tool, with it's small and (IMO) relatively straightforward instruction set - in some ways it's sort of like the 8-bit RISC-before-there-was-RISC processor. Plus there's great retrocoding potential once you learn it! ;)


We could call it "LISC". The instruction set was never reduced, but its growth was limited by what Peddle and hist folks could fit on the chip.

And yes. I learned to program on a TI-55 calculator. Limiting complexity is a very useful tool to introduce someone to programming.


This is pretty cool.

It reminds me of 6502-sim for my Apple ][ - it was a 6502 application (Sorry Captain Obvious), but it was cool as it was showing how each instruction worked.

This goes beyond it :)


Wow. It's beautiful.


Amazing.

It runs at 27hz (not 27Mhz)...

And some people are willing to simulate the brain? Good luck!


That's the Python sim. "The JavaScript sim is only a few hertz, limited by drawing the chip parts."

By contrast, the Apple II ran at 1 Mhz.


I don't think anyone wants to simulate a brain in JavaScript. Or Python (which is the 27Hz number you have), BTW.

But you could simulate a lot using a couple GPUs. That's what OpenCL is for.


The 6510 (C64 6502 with extra ports) has secret opcodes, basically holes in the circuitry, which emulators have to support because they're used in demos for extra speed (eg, write to x what's in a).

I wonder if this simulation also has secret opcodes?


I thought TAX was one of the standard 6502 opcodes?


Couldn't think of a decent example off the top of my head.

Also, proper term is 'undocumented opcodes' for further searching.

Try

"AXS * (SAX) AXS ANDs the contents of the A and X registers (without changing the contents of either register) and stores the result in memory. AXS does not affect any flags in the processor status register."

http://www.ffd2.com/fridge/docs/6502-NMOS.extra.opcodes


Non-CS majors who want to dig deeper might enjoy:

But How Do It Know? - The Basic Principles of Computers for Everyone http://amazon.com/dp/0615303765


Can you imagine what a contemporary CPU or GPU would look like if displayed like this?


For a modern CPU, it would have about as many transistors as there are warp/weft crossings on a bedsheet.


A standard double-size bed is 4 ft 6 in by 6 ft 3 in (http://en.wikipedia.org/wiki/Bed#Bed_sizes). A standard cotton sheet is 150 thread count, which means 75 threads per inch of warp and 75 threads per inch of weft (usually) (http://en.wikipedia.org/wiki/Thread_count#Thread_count). That gives about 4050 threads by about 5625 threads, omitting the part of the sheet that tucks down around the edge of the mattress, for a total of about 23 million thread crossings.

The Intel Core i7 has about 781 million transistors (http://en.wikipedia.org/wiki/Intel_cpus#Core_i7), which is about the number of warp/weft crossings in 34 standard bedsheets, omitting the stuff around the edge of the mattress. I thought maybe ARM chips would be smaller, but http://www.geek.com/articles/mobile/arm-introduces-cortex-a8... says the Cortex-A8 has over a billion transistors. (Although there are certainly low-end microcontroller ARMs that are much smaller. And of course the C18 is smaller still; is it "modern"?)

If you're talking about bigger beds and finer sheets, you might get the number down to less than 10 bedsheets per CPU.

But that doesn't mean you could make a diagram of a modern CPU that was only the size of ten to forty bedsheets, with the transistors the size of warp/weft crossings in a bedsheet. If I remember correctly, only a minority of the chip area typically consists of transistors and other active devices.


Awesome ... how long before someone can use this to run NES games ?


I nearly expect it to have already been done, given that there's a gameboy emulator in JS: http://www.codebase.es/jsgb/


NES has been done as well: http://benfirshman.com/projects/jsnes/


Not as cool as watching the CPU do its thing while playing a game :)


Wow, hot!


chip-u-licious! kudos to the creators. i'll check out the Python one tonight. old time 6502 hacker here...




Registration is open for Startup School 2019. Classes start July 22nd.

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

Search: