Turning the Arduino Uno Into an Apple ][
An anonymous reader writes: To demonstrate how powerful modern computers are compared to their forebears, engineer Damian Peckett decided to approximate an Apple ][ with an Arduino Uno. In this post, he explains how he did it, from emulating the 6502 processor to reinventing how characters were displayed on the screen. "The Apple II used a novel approach for video generation, at the time most microcomputers used an interlaced frame buffer where adjacent rows were not stored sequentially in memory. This made it easier to generate interlaced video. The Apple II took this approach one step further, using an 8:1 interlacing scheme. This had the first line followed by the ninth line. This approach allowed Steve Wozniak to avoid read/write collisions with the video memory without additional circuitry. A very smart hack!" Peckett includes code implementations and circuit diagrams.
Apple II w/ 4K of memory would cost $5236.87 ($1298) in todays dollars. While this may be a lot less than a lot of computers at the time I wouldn't call it a cheap computer by any stretch of the imagination.
To be fair, he was mostly emulating a MOS 6502 that would cost about $125 in today's dollars.
Slashdot: providing anti-social weirdos a soapbox, since 1997.
The cool things are that he used a 8-bit AVR microcontroller to emulate the 6502, and that he used a USB chip on the prototyping board to create video...
Unfortunately, it runs much slower than a 1MHz 6502.
It appears that he did his own reverse-engineering of the 6502. One peculiarity that he may have missed is that it has undocumented op-codes, and those do show up in some programs.
Other people have done much more reverse engineering of the chip, down to the gate level even.
"We mustn't be caught by surprise by our own advancing technology" -- Aldous Huxley
I hate to quote the fucking article because who reads that anyway? But When the 6502 was first released it was priced at $25 USD. At the time this was unheard of, being up to six times cheaper than the nearest competitors. Some people even thought that the low price had to be some form of scam. does in fact establish that the processor was considered a cheap processor.
Slashdot: providing anti-social weirdos a soapbox, since 1997.
well, kind of.
I mean it's neat, because it's on such a crapp microcontroller.
the atmel avr used is pretty much an ancient microcontroller today. I mean, it's pretty much slower than the first pc our family had(8mhz x86 vs atmel 8mhz, or maybe 16, depends). our first pc also had a video card to take care about the graphics display and so forth...
sure, if you loaded an emulator on raspberry pi, I wouldn't give a shit or any props. but for this yes.
world was created 5 seconds before this post as it is.
most microcomputers used an interlaced frame buffer where adjacent rows were not stored sequentially in memory
First of all, I know a lot about micros from the late '70s and early '80s (I was there, maaaan!), and I can't remember a single one other than the Apple II series that didn't display rows sequentially.
This approach allowed Steve Wozniak to avoid read/write collisions with the video memory without additional circuitry.
I'm pretty sure the story I heard was that it saved one TTL chip in the counter chain to do it that way, which was just the kind of thing Woz would do.
Collisions? Exactly what kind of collisions are you talking about? IIRC, the Apple II used interleaved access, where the 6502 would access RAM on every other clock, and the video would access it in between. (This method was also used on the original Macintosh, though the 68000 sometimes needed a wait state.) But that has nothing to do with the funky row counters.
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
Well, the 6502 was the shittiest processor of it's generation (which is why the Apple dudes could afford it) so it makes sense to emulate low end with low end.
Your first PC had a CRT controller (likely a 6845 or derivative.) That's a relatively simple LSI chip. People were doing 'cheap video' with software even back in the day (i.e. Lancaster's cookbook)
The 6502 was cheap for a reason. It was the low end alternative. It's no coincidence that the thing eventually was bought out by a video game manufacturer. And that so many warts and 'undocumented' features existed in it.
Fun to hack on. But professionals were specifying 6802s and a little later Z-80s.
The whole 'merit' of the 6502 and Apple at the time was an exclusive 'killer app' (Visicalc) that moved units. Marketing hustle, not technical superiority or even equivalence. That scent of ripe apple, back then and today, much the same.
It's surprising any of it survived the launch of Visicalc on the IBM hardware. And then Lotus 123 just shut the toy 8 bitters right down. They became, well, toys, for kids to learn on because dad had a new better machine in his den.
I was playing with apple emulators 18 years ago and I had the same reaction.
The AVR is a fine microcontroller. It isn't meant to be a CPU for a PC.
There was a 6500 before the 6502 (I had one) but it used a weird technology that meant it drew almost all its power from the clock lines (two phase non-overlapping clock) and the interface voltages were also non-standard, so the 6502 was magnificently better. It was cheaper because of volume - the die size was almost exactly the same - the chip was almost exactly the same. (I think they got some major order before it was even available for general release), and there was a second source (Rockwell).
The 6800 was a superior processor if you did not have much string processing to do. The 68000 was an entirely different beast.
Sent from my ASR33 using ASCII
Memories of programming with the 6502 instruction set are so delicious that the only comparable thing to compare it to was my first orgasm.
I actually first did it on a General Electric GEPAC computer in 1966. It had an almost identical instruction set to the 6502, but with 24 bit words. Hip programmers expressed themselves in octal in those days.
I said that it was ancient, not that it was shitty as such. well, that kind of makes it shitty if you compare what is on the market in 2015 - for any application. it's not particularly cheap either and in official arduino uno board it's ridiculously expensive for what it is.
sure, my 3d printer runs on atmel avr. that's what makes the firmware rather shitty from what it could be and impossible to improve upon, there's no space left on the rom and the ram is exhausted and there's no empty cycles(96% of home 3d printers run on 8 bit avr, it's the reprap standard and makerbot used one too until in their latest line switching to a faster bot - though amazingly their new bot has worse firmware and stepper control).
but comparing it to a cheap modern pc is stupid. that was my point. our first 8mhz/640kb/20mbyte/ega home computer from 1988 or so was leagues ahead of the 8 bit avr. so comparing this project to running an emulator on a cheap modern pc is stupid.
world was created 5 seconds before this post as it is.
The Apple 2 came out in 1977. Visicalc was 1979 and didn't start development until 1978. No Apple was not building the machine around Visicalc.
> Very cheap modern computer is capable to emulating a 28 year old cheap computer.
Actually, it may contradict common sense, but you're missing part of the "history".
As technologies evolve and brands consolidate, some old ideas are lost. Things like the mentioned 8:1 interleave, floppy drive skewing schemes or they way images are generated in vector display are harder to simulate (though feasible). And even if simulated, not everyone would know how to use them. I'm particularly reminded of ATARI 2600 image generation, a nightmare if I ever saw one. It makes me value the ZX80 even more.
Dunno about that...i think the AVR instruction set is probably faster at 8Mhz then an 8086 at the same speed; it's at the very least equivalent. The x86 instruction set really is a mess...
The IBM PC 5150 used CGA and MDA videocards, both used the 6845 text chip. I wonder if you were talking about the IBM 5100...
After they designed the 6800, they realised that processing strings on a 6800 was hell's own job cos it only had one pointer (although it was 16 bit).
Reminds me of my own adventures with assembly language on a Z80 CPU. In writing my first non-trivial (yet not that complex) program, I decided I wanted to establish a calling convention for subroutines as well as use the stack for temporary variables. On an 8086 this is pretty simple, at the beginning of a function you just "MOV BP, SP" followed by "SUB SP, x" to make room for your temporary variables, then reference everything via "[BP+y]" with positive values pointing to the function arguments and negative values pointing to local variables. On the Z80 however, you're in for hell if you want to do something so trivial. Transferring the stack pointer to and from other registers is a pain in the ass. You also can't do math with it, so you have to add room for your local variables while it is in other registers, then move the result back to the stack pointer. The result is that the overhead of function entry and exit is insane. After confirming that there is indeed no good solution by looking at the output of a couple of Z80 C compilers, I gave up and continued to just pass arguments in registers and use global variables for everything.
In the present day, no one would care about such things, as the inefficiency would be hidden by the compiler, but back when these CPUs were new, it's easy to imagine such differences between CPUs being more of a factor in their popularity than their speed or their price. In particular, ease of programmability is going to affect the quality and cost of software available. Thus I'm not too surprised that the 8086 came out on top. I've done a lot of assembly coding for it and never found myself in a "there's no easy way to do this" situation like I keep finding myself in when writing in Z80 or 8052 assembly. Honestly, it's almost like they chose the available instructions for these CPUs completely at random with no concern for how easy it was going to be to do any particular task. Even Atmel's AVR instruction set leaves a lot to be desired once you reach the point where you can't fit all of your variables in the 32 registers and start having to touch the device's RAM, as instruction sequences become so long that you feel like your 20 MHz CPU is about to turn into 2 MHz.
Tandy Color Computer used the opposite side of the clock signal to generate video.
Yeah. Most of the emulators out there use hacks to get them to run smoothly on today's hardware. There's a lot of emulators out there that don't run exactly as the old hardware did. Some emulators like BSNES actually try to run the machine code exactly the same way the old consoles did, while others take short cuts and there fore might only work with the most popular games.
There's even a fair number of N64 emulators that can't play Ocarina of Time properly. There's a part very early in the game where you have to pick a path based on the direction path the song is coming from. Most of the emulators fail at this and just play the song the same no matter which path you go down.
Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
Unlikely. Virtually all mainstream 8 bit CPUs of the time had BCD support in some shape or form, including the 8080 and its compatible rival the Z80 series. The vast majority of microcomputers in the late 1970s were 6502, 6800, 8080, or Z80 based.
Visicalc probably started on the Apple II because that's the computer the authors had at the time.
You are not alone. This is not normal. None of this is normal.
The video produced by the Apple II is not interlaced at all. Many video devices used to mix and overlay video in studios had trouble with this fact. True the video memory is not sequential but that's not the same thing as interlacing. Way back in 1983 I had lunch with Woz and a half dozen or so mostly game developers at the Independent Developrs conference. I asked him if he would want to change anything about the design of the II. He said he might add the two chips needed to make the video memory map sequential. Several of us including myself said that most of us would still use a lookup tables for updating video memory anyway (it was faster) and that didn't really matter much. In the end he agreed.
As far as the 6502 being the shittiest processor of it's generation I would have to disagree. True it has fewer registers and instructions (RISC?) than most even older designs like the 8080, but it did have some unique adressing modes that made it the perfect processor for the graphics the Apple did. This coupled with the fact you can use the 256 bytes of zero page much faster and much like processor registers (indexed memory referencing) made it one neat machine.
I wonder how Woz feels about this kind of development. He has a /. account so if you read this: did you ever think there would be computers powerful enough and people interested enough to implement your brainchild on a credit card sized machine with different architecture within your lifetime. What do you think of the arduino movement in comparison with the DIY computer movement from our time?
Custom electronics and digital signage for your business: www.evcircuits.com
You must have a very different definition of crap than most of us use. It's not ancient either, it is current.
Perhaps you don't know what a microcontroller is for? Hint, for the purposes a microcontroller is intended, the home computer would be a miserable choice, then or now.
You know the Atari 400/800 and Commodore VIC20/64 used the 6502 as well, right? Not exactly a limited or niche processor.
Gamingmuseum.com: Give your 3D accelerator a rest.
The 6502 was years before the 6802 or Z80
6800 - November 1974
6502 - 1975
z80 - July 1976
6802 - March 1977
Things went faster in the past.
Watch this Heartland Institute video
That's the way Apple Computer typed the name and trademarked logo, Apple ][. Possibly the first known use of 133t-speak, and definitely pre-hipster. You are showing your lack of geek cred.
Some mornings it's hardly worth chewing through the restraints to get out of bed.
You have it reversed - the 6800 predated the 6500.
The 6800 was done by Motorola, but those designers were unhappy with the way Motorola was marketing it (expensive processor), so they split off from Motorola and created MOS. They designed (cleanly) the 6500, which was designed to be super cheap ($25), and not only binary compatible, but pin compatible with the 6800. You could literally drop the 6500 into a 6800 socket and it would work just fine (being designed by the same guys helped).
Motorola got pissed at this, and threatened MOS, so they simply created a new processor which was similar to the 6500, but not pin compatible, but close enough. They called it the 6502.
Its low price helped significantly, but also that at every trade show, MOS would have them for sale. Bring $20-25, and they'll sell you a 6502 and all the databooks and manuals you needed to hook it up. Motorola and everyone else required you to go through distributors to obtain that material, and it was also over $100 (I think the 6800 was $200 or so) to boot.
Basically MOS realized there was a home hobbyist market, and they sold processors at every trade show they attended to interested folks.
I probably can't find the quote; but I distinctly remember reading an interview with Woz, stating (among other things), paraphrasing, "If I had known how popular the Apple ][ was going to be, I would have gone ahead and included the two extra chips it would have taken to make the video memory addressed sequentially."
Instead, we had BASCALC and HBASCALC calls in the Apple Monitor ROM.
And we liked it!
What the fuck is a Apple ][?, What the fuck does ][ stand for?, Are you so fucking chic that typing 2, or II is a problem?. Fucking hipsters.
OMFG! You're kidding, right?
You must IMMEDIATELY turn in every single computing device you own.
One of the gentile geniuses of our time
...and one of the Gentle Geniuses, too!
This was easily the best, by far, technical article ever linked in a Slashdot submission.
I just had to express my amazement. Holy shit, such deliciously nerdy article...
"The agriculture ministry is not in charge of Gundam" - Japanese ministry official.
Well I don't know about "also ran". There were lots of CP/M machines. Visicalc was after basic word processing one of the first major applications for CP/M machines moving them from hobbyist to usable for home businesses ...
Regardless the Apple 2 was not designed around the specs for Visicalc per GP. That's just not true.
Both the Atari and Commondore computers you mention had a couple additional processors to handle video, sound, etc. They didn't go with just the 6502 alone. http://en.wikipedia.org/wiki/J...
Actually, the 6502 only cost $6.95 in today's dollars.
http://www.mouser.com/ProductD...
It's for sale right now, but it's still ancient. You can get an ARM CPU for roughly the same price, with 10 times the clock, more peripherals, more choice of packages, more memory, and 32 bits instead of 8.
The x86 instruction set really is a mess...
Clock for clock, a modern intel CPU is much faster than an AVR. Who cares if it doesn't look pretty, when it gets the job done ?
ARM is more expensive. You can get an AVR for $3 quantity 1. ARM also requires more of the board it's connected to and still consumes more power.
I like ARM and when the capability is needed, I wouldn't hesitate to recommend it but it's not a one size fits all world.
It's a 1980's hipsterism. So clearly it's someone getting too senile to use II or 2.
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
A while back I found a Heathkit ET-3400 at a thrift store. I tried writing a simple program for it when I realized that holy shit, the original 6800 doesn't even have the ABX instruction, that was in the 6801/6803 core. I mean, I knew all those other instructions like ADDD and MUL wouldn't be there, but I didn't know ABX would be missing too. And I was doubly annoyed because I had done a lot of 6809 programming so I already knew I was going to miss a lot of things.
And the 6809 was the most superior 8-bit CPU when it came to string processing.
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
Back in the mid '90s, I think everyone was surprised to find that you needed at least a 486DX-25 to emulate the Atari 2600. It was because the 2600 required cycle-accurate timing to emulate it properly. You could, and everyone did, do stuff with the Stella chip (which I call a "1-D" graphics chip) in the middle of a scan line, sometimes abusing its counter registers in interesting ways.
The N64 was a different beast with emulation. I think the biggest problem was needing a lot of RAM to emulate it properly on the Xbox, and I think RAM was also the problem on PSP. But at some level it abstracted the 3-D hardware such that you could usually emulate it with better looking graphics than the original hardware.
And yeah, then there's the sound hardware. That was a big problem for SNES emulators, because there was so much that the sound CPU could do. You either make it work for most cases, or you eat up a lot more CPU time emulating it properly.
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
The 8085 actually had an undocumented instruction to add a constant value to SP and put the result in DE. But apparently all this was happening roughly at the time the 8088 was coming out, and one of their advertised "advantages" was being able to cross-assemble 8080 code to the 8086, so they memory-holed those instructions. Most 8085 clone cores had them though. And yes, I have also seen the result of trying to compile C for the Z-80, and it isn't pretty.
You should look into the 6809 to see what you get when the instruction set isn't chosen "completely at random". It was really nice, and I even got paid to do it for a few years. The only real trouble I had was feeling like I needed just one more register, but you could always cheat by putting stuff on the stack at the cost of cycles.
#naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
in the purposes it serves in many arduino projects, it's crap. it's used for all kinds of things it's crap for. realtime motor controls, motion planning, audio analyzing, you name it. all kinds of stuff it's pretty crappy for but it's the "standard", so it gets thrown in there.
the arduino atmels are a) not low power use b) not powerful.
from what I can look at volume pricing, the volume pricing of the atmels isn't that great either.
it's not intended at any specific application either. it's intended to do anything it possibly can. if you can make a plugin tv console with it that emulates space invaders then good for you. it was intended for purposes like that just as much as it was intended for running a washing machine..
world was created 5 seconds before this post as it is.
Mostly the 6502 was cheap because they made a marketing decision to make it cheap. The convention wisdom of the time was to charge through the nose for small quantities of chips and soak developers. In theory this helped companies keep down the large volume prices of their chips and make them more attractive to companies that were going to buy millions of them. MOS Technology, a startup chip maker, decided to try something radical to put itself on the map: sell single chips at prices low enough that hobbyists and garage startups could afford them. It paid off; Apple's decision to use the 6502 was largely motivated by the low price of the chip.
After MOS Technology went away, the industry returned to business as normal for many years, again charging high prices for small quantity orders and especially for evaluation boards. But that has changed in recent years. We now have a flood of inexpensive evaluation boards for all sorts of microcontrollers - not just open hardware projects like Arduino, but also boards from manufacturers such as the TI Launchpad series and the mbed. The maker movement has been a big beneficiary of the change. The software situation has also improved: we now have open-source tools based on GCC as an alternative to expensive embedded system compilers and debuggers.
The 6500 was MOS Technology's first chip, and sold for $20 in quantity one. It was designed to be pin-compatible with the 6800, though the instruction set was different so it was not a drop-in replacement. The requirement for the quadrature clock was shared with that chip, so it really wasn't any harder to use. MOS Technology withdrew the 6500 from the market under legal pressure from Motorola; MOS Technology probably would have won the legal battle but did not have the resources to fight it.
Meanwhile they had been working on their second product, the 6502. The new chip incorporated the quadrature clock generator in the CPU, so there was no longer a need to generate it externally. (Generating quadrature clocks is not all that difficult - the circuit involves two flip-flops - the main wrinkle is that they have to be non-overlapping, requiring some attention to circuit layout and stray capacitance.) The 6502 also rearranged the pins so it was no longer pin-compatible with the 6800, satisfying Motorola's lawyers. The new chip was easier to use so they raised the price a bit to $25 in quantity one.
Many modern microprocessor designs use quadrature clocks, but they are generated on-chip now just like the 6502. Any microcontroller that takes a clock input that is four times the actual clock speed of the processor uses a quadrature clock. In current designs it's harder to tell because they also often incorporate on-chip PLL clock multipliers, so the actual clock rate of the chip is many times the speed of the external clock. x86 processors are one extreme example; they use a 100 MHz external clock and may multiply it by 40x or more.
VisiCalc was actually developed on a MicroMind? I didn't know that!
The ECD MicroMind was a tragic example of the perfect being the enemy of the good. It was an ambitious design for the time, notably including memory mapping hardware so the system could have more than 64K RAM, and a powerful graphics board that had both bitmap graphics capability and a programmable character generator. It used stackable boards rather than the usual card slots. But they spent so much time perfecting the design and adding more bells and whistles that they never got the system to the point of being able to be mass produced at a reasonable price.
I knew the guys at the time and hung around at the fringes of the project, though I was never really involved. I think they did use the bitmap chess font I designed for it in the chess program.
No, ARM isn't more expensive. Try, for example, the ST Microelectronics STM32F030R8T6. That's a Cortex-M0 ARM, 48MHz, 64K flash, 8K RAM, 55 I/O pins. $2.22 in quantity one. Reference: http://www.digikey.com/product... That's just one part I happen to be familiar with; there may be even cheaper ARM alternatives out there.
Quantity one price of an ATMega328? $3.25. That's the surface mount version; the DIP is $3.38. Reference: http://www.digikey.com/product...
It's true that if you stay with Atmel, ARM will be more expensive. The ATSAMD21G18 that is used in the upcoming Arduino Zero Pro is $6.17 in quantity one. Reference: http://www.digikey.com/product... To be fair, that is a newer design using the somewhat more powerful Cortex-M0+ core.
Times cheaper? Makes no sense. I think you mean one sixth the cost.
ATTINY2313-20PU $1.62.
Not as fast and not as powerful, but if that's all you need, why overbuy? If you slow it way down, it comes in at 20 micro amps @ 1.8v
There's nothing wrong with the ARM, it's just not always what is needed.
One reason AVR looks more expensive is that it is currently the cool maker choice so you see a lot of them at vastly inflated prices. One reason it's 'cool' is it's ease of use and minimal demands for support circuitry.
Another factor is that the AVR chips are mostly still 5 volt parts. That means that they have to be made with a very out-of-date process and are much larger than current designs. (The processors used in AVR Arduinos can be run all the way down to 2V at reduced performance, but the fact that they allow 5V operation dictates the process used.) All the microcontroller ARM chips that I am familiar with are 3.3 volt chips (that's the maximum, most can also be run at lower voltages, typically down to 1.8V); higher end ARMs used in phones and the like run at even lower voltages, often less than one volt.
But... being 5 volt chips, they are easier to use in maker designs. Makers tend to still be using older 5 volt CMOS chips for glue rather than low voltage parts. Other things that they want to hook up are likely to run at 5V. 5V means that you can drive every color of LED directly with an output pin rather than needing a level shifter. Low voltage CPUs usually have less current drive capability as well, so even interfacing to other low voltage devices may require the use of buffers. 5V parts have better noise immunity and are less static sensitive.
The Arduino Due, the first ARM-based Arduino, has failed to catch on. One reason is that it is a 3.3V board with inputs that are not 5V tolerant, which means that a large percentage of existing shields and other modules that are designed to be used with Arduino won't work with it. No real fix for that other than releasing new 3.3V shields.
That is a very good point. I'm in a project now that needs low power. It is nice to be able to power sensors off of one of the DIO pins so I can power them down at will without adding to component count. And as you say, the 5V design will be more robust for little effort.
I tend to think of < 5V as something you do if you have to, never as a first choice.