Settings

Theme

CS/A65: A 6502 computer with USB, Ethernet and co-processors

6502.org

132 points by amrcnimgrnt 4 years ago · 49 comments

Reader

cdcarter 4 years ago

Always love to see a 6502 post here on HN. It's a really unique processor compared to other 8-bit processors at the time. With only one general purpose register, and memory mapped IO, the 6502 offers a ton of "addressing modes" to solve problems that the 8080 would solve with register transfers.

Ben Eater (http://beneater.net/) makes a neat video series and accompanying product kit where you build a 6502 on a breadboard, if you're looking for something a little more approachable than this (very cool) project!

  • spicybright 4 years ago

    A while back I tried writing an Atari 2600 game and got about half way (got sprites, collisions, level, just no goal)

    The console uses a slightly cheaper version, the 6507 I think. Same chip, just smaller address line and no interrupts (!)

    Instead you ran a "wait for the cathode ray to reach the right side of the screen" in order to time everything correctly.

    Very fascinating stuff, I recommend anyone interested in the above dive in and give it a shot.

    All you need is an editor[1] (I found one online!) and the stella manual[2].

    There's something nice about having the entire machine spec in one book instead of leaning on stack overflow...

    [1] https://8bitworkshop.com/v3.8.0/?platform=vcs&file=examples%...

    [2] https://cdn.hackaday.io/files/1646277043401568/stella.pdf

    • kgwxd 4 years ago

      2600 has been my obsession for a few years now. I too havent set a goal but I love to follow what other people are doing for it. The community is fantastic. There's a twitch and yt channel called ZeroPage Homebrew that usually streams twice a week. They exclusivley play homebrews and the devs are usually in the chat. They were 2600 only for a long time but recently started including 7800 and 8-bit.

    • krallja 4 years ago

      There’s also no way to set the horizontal position of sprites other than waiting for the scan line to reach the position you want and yelling “NOW!!!”

  • royjacobs 4 years ago

    It's a really fun architecture, agreed. I spent the last few months writing an assembler, formatter and language server for 6502 code. If you're interested, it's available at https://mos.datatra.sh

  • hota_mazi 4 years ago

    As much as I love the 6502, I have to say the 8080 has some very neat features that I wish I had with 6502, such as conditional returns (in other words, do a RTS only if a certain flag is set or not).

    • earthbee 4 years ago

      What significant advantage does that have over a conditional branch followed by an RTS?

      • anyfoo 4 years ago

        Code density, and you could potentially save a few cycles with a single instruction. Whether that matters at all depends on how much slack you have in your utilization of available memory and CPU cycles. (Strictly talking about "old" CPUs here.)

        It's worth noting that the 8086 got rid of conditional returns, you only have unconditional ones there.

        • earthbee 4 years ago

          A taken branch on the 6502 takes 3 cycles. A not taken branch followed by a Return From Subroutine instruction takes 2 + 6 cycles.

          Looking up the conditional return instructions on the 8080 seems to show it takes 5 cycles when false and 11 when true.

          So the two 6502 instructions add up to being two or three cycles faster than one 8080 conditional return.

          • klodolph 4 years ago

            Cycle counts are super misleading. These processors were limited by the speed of RAM, and cycles per RAM access differed. Suppose you have RAM running at 1 MHz... maybe your 6502 is also clocked at 1 MHz, and your 8080 is clocked at 4 MHz. I know you're not trying to compare 6502 performance to 8080 performance in general, just that there's a fairly wide variation in how much you can accomplish in a cycle, and "how many RAM accesses can the processor make" is probably what you want to look for, since it's a bit more directly comparable across processors of that era.

          • anyfoo 4 years ago

            I was not trying to compare the 6502 with the 8080 here, and I said "potentially" exactly because it depends on the architecture wether it works out (and, as said, 8088/8086 removed the conditional returns). On the 8080 specifically, conditional returns seem to be a little cheaper overall.

          • jonsen 4 years ago

            It’s only fair to compare cycle numbers if you also compare cycle times.

amrcnimgrntOP 4 years ago

Andre Fachat also wrote a pre-emptive multitasking kernel for the 6502:

http://www.6502.org/users/andre/osa/oa1.html

This is basically the same CPU as in the NES.

  • the-dude 4 years ago

    And in the BBC B, Electron and Commodore 64.

  • abdulhaq 4 years ago

    It feels weird to me that some hackers don't know what a 6502 is! Sign of my age I guess.

    • mdp2021 4 years ago

      Days ago a user who declared to be a Google employee wrote that many of his colleagues have no idea what RSS is. (No, sign of the times.)

    • lholden 4 years ago

      Earlier this year, I wrote a 6502 emulator and discovered that none of my coworkers even know what the 6502 was. Almost every conversation resulted in me saying: "You know the NES? It used a 6502 as a CPU".

      • abdulhaq 4 years ago

        As time goes on my experience is that I get more and more intellectually and spiritually isolated, even in a globally connected society. Perhaps it's an inevitable part of continuing personal deveopment in a society changing dramatically over time.

whartung 4 years ago

Some folks may be also interested in his latest endeavor.

https://github.com/fachat/MicroPET

It's quite clever. At it's core, it's PET clone.

But deeper, it's not just a PET clone, but 4 other machines in the PET series.

On top of that it's based on a 65816, has B&W 640x480 VGA graphics, as well as several different text modes. As a cherry on top, it can run 4 "virtual" PETs simultaneously.

This is much closer to a machine that I'm interested in. Fundamentally, a fast 65816 with memory (at least 1MB), UART, and access to a "full speed" USB bus (12.5Mbits), which it boots off of (it could also boot off of an SD Card).

This machine is close. The SPI to the Ethernet and USB is 6MHz, and driven by the CPLD rather than bit banged off the CPU.

  • amrcnimgrntOP 4 years ago

    Thats really cool.

    I feel that modern computers are so powerful that they are productivity sappers. For me to be productive, I think a system with low latency but otherwise very limited would be the best.

    It's like what a friend said in college about getting a dual monitor setup: "Your productivity doubles until you realize you can watch movies on the other one"

jaclaz 4 years ago

As a side-side note, I always found fascinating how you can have essentially a 6502 with display, 2 MB of memory (or more) and a USB port for a few bucks, as demonstrated here:

https://spritesmods.com/?art=picframe&page=1

I often wonder why the manufacturers - besides the photoframe usage - don't sell an "open" version with some toolkit to let people have fun with these devices.

  • krallja 4 years ago

    Western Design Center (who still manufactures 65C02S’s) has a series of development boards based on the 6502: https://www.tindie.com/stores/wdc/

    Of course, they’re way more expensive than an Arduino Mega, which is approximately as powerful…

skyde 4 years ago

Noob her! why use a 6502 versus another 8bit cpu like Atmel AVR? Is there any advantage? Does it consume less electricity while running at similar speed ?

  • klodolph 4 years ago

    I'll step in and say that the Atmel AVR is damn awesome processor, it's just that it's hooked up to on-chip peripherals and the address/data bus is completely internal. This means that if you want to connect something to an Atmel AVR, it will likely be over some serial protocol, like SPI, I2C, or UART.

    This is what you want, like, 99.9% of the time.

    The 6502 just puts its address and data bus on pins, and you can make the memory map for your computer however you want, as long as you are willing to wire up the logic. There's no privilege for on-chip resources... everything is off-chip and completely equal. With the AVR, the resources (RAM, flash, peripherals) are completely fixed but much, much faster. There are a ton of chips you can buy with SPI / I2C interfaces if you want the AVR to do something interesting, and you drive them with the on-chip peripherals. The on-chip peripherals get to sit in memory somewhere, but the external ICs don't. With the 6502, you put things in memory somewhere, figure out a way to decode addresses on the bus, and use a parallel interface for everything.

  • anyfoo 4 years ago

    One thing that might or might not matter, depending on why you are doing the project, is that a 6502-based computer is less opaque.

    A 6502 is a CPU in the "traditional sense". It has limited internal state in the form of a few registers, and communicates with the outside world with address lines and data lines; I only simplified a little there. Everything else is external: RAM, ROM, any external devices on a different bus (I2C etc.), even timers and GPIO need external circuitry with usually other ICs.

    An AVR on the other hand tends to have all of that stuff (or at least a sizable subset) built in. That's, obviously, enormously convenient, and often means that with the AVR itself and just minimal external circuitry you have your needs covered. But it's less educational, you've rather plugged a computer into your circuit than built a computer.

  • retrac 4 years ago

    Sentimentality. The 6502 has been around for almost half a century now. Often the processor in an older programmer's first computer or video game system. It's horribly limited, but assembly programming for the 6502 has become a kind of code golf.

  • vidarh 4 years ago

    Nostalgia and/or familiarity.

    Lots of us grew up with 6502 based machines.

  • schemescape 4 years ago

    I'm not 100% confident about the dates, but my understanding is that the author's project started in 1989, before AVRs were developed (1996).

  • cmrdporcupine 4 years ago

    6502 is about as simple a CPU as you can get without it being a complete pain in the ass to work with. So it's a great CPU to learn nuts and bolts of computer hardware. It's pretty easy to interface it to external devices, pretty easy to learn the instruction set, there's a huge community of enthusiasts for it, it's very cycle efficient and very responsive to interrupts and somehow feels fast, and the ins and outs of how it functions are super well documented and reverse engineered.

  • tyingq 4 years ago

    The Atmel has a modified harvard architecture, so it's easier to use as a microcontroller than to run an OS on. Where there are lots of available OSes for 6502, Z80, etc.

  • wvenable 4 years ago

    More fun/interesting and more potential to be actual computer.

    Probably the main advantage of a 6502 is more RAM/EEPROM (as 8bit microcontrollers are pretty limited that way) and more of a hardware/software ecosystem to work with.

  • the-dude 4 years ago

    I assume memory lanes.

cubano 4 years ago

Back in the mid 80's when I was in collage, my primary CP professor was a huge fan of the 6502 and thought it the ideal chip for undergrads to learn the basics of computer engineering...and it was, for me at least.

Way easier to breadboard and write opcode for then, and more powerful than the Intel 4004 and 8008 (what would eventually become the 8086..the great-great-great grandfather of the i9's we now use of course), my very first working "computer" used a 6502 at its heart for my senior project...we attempted to build a voice-activated phone and actually got something that would pick up and shut off the phone with some noise, but obviously a working voice-activated phone was something that was still many years away.

Also, I remember writing an opcode instruction emulator for the chip as a extra-credit project for one my classes. I wrote a really nice emulator on my beloved Atari ST and, much to my horror, discovered a horrendous bug in he C compiler I used for the project, almost ruining both the project and my grade for the quarter.

The program had a graphical representation all all the primary subsections of a basic computer...CPU, disk memory, the various busses, and some other things that my old brain can no longer remember, and the program would step thru the processors opcodes and show, with literally the 1s and 0s on the screen, how all the parts of the computer processed the opcode instruction set into something that coordinated all the chips into doing very useful stuff.

The problem was that due to some sort of crazy hex arithmetic bug in the compiler, one of the values at one of the nodes was stuck at like x0E or something like that...and no matter what I tried to do to debug it, I could not get the damn thing to work perfectly. I thought I was going to fail the class for sure, and it wasn't even my fault!

Thankfully, I was able to show the results in pure binary form, and the rest of the program was quite impressive. Also, my professor was a HUGE fan of the Atari ST (probably because it used the 68000 and wasn't Intel), so the day of me showing him my work wasn't a total failure...in fact, his face totally lit up when I asked him if I could pop the floppy into the ST in his office, and we verified that, yes, the bug was there in all versions of the compiler.

Only one other student had chosen to do the assignment, and he had used a minicomputer from his work to do it and his results where shown in reams of printouts where mine was there graphically represented in real time updates as you stepped thru the opcode instructions. I remember its addressing modes and GP registers made writing opcode a breeze as you didn't have to waste cycles juggling data and memory addresses at all.

[edit] wow...sorry this was such a long post! I just got lost in remembering old times...

  • afr0ck 4 years ago

    Amazing story! All of this, I wasn't even born (just to point out how old you are xD). As a late millennial, this is the first time ever I hear about this CPU.

userbinator 4 years ago

It's amusing to think that all the peripherals individually probably have more transistors than the CPU itself. Neither USB nor Ethernet controllers are particularly simple.

glonq 4 years ago

Pros and cons of this versus Commander X16 ?

  • deelowe 4 years ago

    X16 is going to be more for folks who want something that just works and they can play around with in software

    Projects like this are more for folks who are looking to build their own computers from scratch. Typically, this is for someone who's more into hardware.

    Personally, I enjoy both. I have probably 6 or so kit computers at this point. FWIW, the two that I've enjoyed the most are Ben Eater's breadboard 6502 project and the nand2tetris series which is all done in software.

  • wvenable 4 years ago

    This is a home built hobby project, if you want one you're going to have to source the parts yourself, create the PCBs, and build it. And it will mostly be one of a kind. It's a fun project if that's what you're into. I'm building a 6502 computer much less involved than this one.

    The Commander X16 will be more of completed commercial project where the appeal is more using the computer to write software than building the computer itself.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection