Apple //t

twitter2In the summer of 1980 my family took a trip to the East Coast, and we flew American Airlines. It was my first time on an airplane and I remember being very excited. I had good cause to be excited – I was about to have the entire course of my life impacted, but didn’t know it yet.

I was reading the in-flight magazine and came across something that boggled my young mind. It was a full-page advertisement for a computer – a personal computer that you could buy and use yourself. I must have sat there and stared at that page for 15 minutes studying the picture of this thing called a “personal computer”. I tore the ad out and carried it around with me for the rest of the trip. It took about a year of bugging my parents but they eventually bought me an Apple II with 16K of RAM.

These were my formative years and I learned that machine inside and out, making indelible memories that last to this day. I met Steve Wozniak at a book signing recently and told him I was surprised to find that nobody had yet grabbed the license plate “LDA C030” for their vehicle. [Blank stare from Woz] “You know, L..D..A..” I repeated myself more slowly and loudly, the way you might to someone who doesn’t speak Engligh in the hopes of being understood and with similar results. He had no idea what the hell I was talking about. And why should he? The obscure 6502 machine language command to make the Apple II speaker click would never have anywhere near the meaning to him as it did me. To me it was my fundamental introduction to making electronic music, whereas to him it was simply a feature he stuck in a product he built decades ago. His brain was doing the sensible thing and had purged this knowledge sometime in the past 30 years. In my case, this information was carved in stone and I put it all to use last weekend.the-ad

Actually the story begins another week or two earlier at the Silicon Valley Electronics Flea Market. I came across a guy with a bunch of Apple II computers stacked up and ended up buying an Apple //e and a disk drive for $20. His prices were $10 for an Apple //e and $25 for an Apple II+. The Apple II+ is technically the lesser machine – an earlier model that lacked the features of the Apple //e but is more expensive due to scarcity. The computer my parents purchased for me was the original Apple II, an even older and more rare model. I asked him if he had any of that model and he said no, but if he did they’d run a few hundred dollars.

I loved that he said this, because when the Apple //e was released I recall thinking that it was an abomination. My original Apple II computer came with a full set of schematics and programming documentation. The Apple //e was the first computer Apple released that didn’t include instructions on how to program it. By that time there was enough commercially available software and, like today’s computers, it actually did useful things without the owner having to program it. At the age of 15 this felt like a change for the worse and made the Apple //e a lesser computer in my mind.

I brought my $20 worth of computer gear home and decided to turn it on. The sound of the beep and the noise the disk drive made instantly transported me back 30 years – it was a sound as familiar as any I’ve heard in my entire life. It was the 1980s and I was a teenager with all the 6502 opcodes memorized. Time to build something.

I have zero intention of becoming the Twitter Display Guy, but since I had just finished a Twitter Display project I thought it would be cool to do a Twitter/Apple II mash-up. So where to start…

Bootstrap

I had exactly zero software for the Apple //e I had just purchased, so I looked for a 6502 assembler that ran on the PC and was able to find several. But I needed a way to transfer the resulting binaries to the Apple and also would need a way to communicate with my PC to send the Twitter information.

I ended up implementing an SPI-like interface between the PC and Apple II using an FTDI USB cable in bit-bang mode. This essentially gives you 4 logic lines you can control from your PC. I hooked these up to the Apple II joystick connector to the button inputs and wrote software on the Apple II to listen to the virtual button presses being hammered out by the PC. I tested this software first by just driving some LEDs with the FTDI cable to get the switching software right.

bitbang-leds Once I could reliably toggle the logic lines on the FTDI cable, I hooked wires up to the Joystick button port as seen below. I call it the Track & Field protocol since it works by rapidly toggling the joystick buttons. Track & Field was an Apple II game where you had to mash the buttons as fast as you could to race, and was notorious for kids breaking their keyboards by pounding the buttons so hard. I was able to get this Rube Goldberg system working reliably at 3600 baud.

gameport-context gameport-closeup

ftdi-connectedBut of course the very first piece of software had to be entered by hand on the Apple II, so I wrote a tiny bootloader in about 50 bytes that will load a stream of my bit-banged data into RAM. I then used this bootloader to transfer the full program. Writing the bootloader was surprisingly easy – I did almost all of it from memory. The 6502 has 8-bit registers but 16-bit memory addresses so you can’t reference a byte of memory indirect through a register. So you either need to store the address pointer in the first 256 bytes of memory (Zero Page) or use a longer instruction with an absolute address. I dimly recalled there were limitations on which Zero Page addresses were available for your use so I wrote the program to be self-modifying with absolute addressing.

self-modifyingThis loop increments the variable PagePointer to store each successive byte received. Look closely and you’ll see that PagePointer actually points to program code. It’s pointing to where the address byte is for the STA $xxxx,Y instruction. So the code is modifying itself as it goes through the loop. Computers go out of their way to prevent you from making these kinds of “mistakes” today but back then we all did it and it was bad-ass.

Not So Fast

The Apple II has an 8-bit 6502 CPU running at 1 MHz, so it can literally execute thousands of instructions per second. In other words, it’s about a million times slower that the computer you are using right now. So I wasn’t about to write a networking stack or Twitter client on the Apple II itself. Just like the TweetWall the communication with Twitter would happen on a PC and the Apple is just used for display.

The Apple II has 2 graphics modes. Low-resolution mode, or LORES as the cool kids call it, supports 40×40 pixels with 16 fixed colors. The colors are bizarre – lots of blues but kind of short on reds. Two of the colors are the exact same shade of gray, but are shifted a half pixel from each other. The other mode is high-resolution mode (HIRES) which gives 280×192 pixels and 6 colors. But you can’t just put any color anywhere you want. You kinda lose half your horizontal resolution once you start using color and even then you can’t just put a green pixel next to an orange one. It’s unbelievably complicated (cue Amiga fans to retort with tales of Hold And Modify mode). This same set of constraints is what makes the text on the Apple II have those purple and green fringes around the edges.

I wrote software on the PC to turn Twitter avatars into both LORES and HIRES graphic representations. The result is a cool 8-bit vibe, and in many cases the graphics are distant abstractions that bear little resemblance to the original image. Here are a few examples:

IMG_2208  IMG_2245

IMG_2215 IMG_2241

IMG_2227 IMG_2217

The PC software does the conversion of images into the exact native memory-mapped graphics format needed for the Apple II. Then it uses the bit-bang joystick protocol to pump the graphics buffers over directly to the screen. There is some additional software on the Apple II that can scroll the bottom text or the LORES graphics for transition effects.

Fragile

Once I got it working it was nice but I didn’t have a good way to save it. If I turned off the Apple //e I would have to re-enter the bootloader by hand and then re-download the software. I tried using the tape-recorder save/load interface but it wasn’t reliable.

I managed to win an auction on eBay for some blank 5.25” floppies and was able to download an image of the DOS 3.3 system disk for the Apple II. I used my bootloader to load this disk into memory the first time and once I had that going I was able to use it to initialize one of my blank eBay floppies and then I was golden. The video below shows the end result – a bootable Twitter floppy that shows old-school tweets. I recommend playing Rush while watching this.

Tags: , ,

41 comments

  1. every single one of your projects are amazing – love it.

  2. It’s been -ages- but if I remember right the two grey colors are actually on purpose: the colors used some properties of the Apple monitors to make one be a "left grey" and the other a "right grey", and you would use them when anti-aliasing graphics so they would stick to the proper side of the edge.

  3. oh man…I’m jonesing for my old ||c and composite monitor. I had a CoCo somewhere too…

  4. That is freakin’ awesome. Have you considered releasing this to the retro Apple community with documentation?

  5. Jim, the point about the 2 out-of-phase grays is dead on. Each LORES pixel has 3 and a half (!) pixels as far as the video generator is concernd, so it makes perfect sense. It’s also why my gray stuff has chroma-crawl beating all over the edges. How cool that I’m still learning subtle details like this about the Apple II!

    Garrett, the IIc was the bomb. They did mad industrial design on that model. In retrospect it would have been a much better choice as it’s small and would look great hanging on the wall. Maybe I’ll be spending another $20 soon :)

    Ken, I must admit I thought I was the only oldster out there tinkering with these things. I’d be thrilled to hand this off to the community and see where that goes. Shoot me a mail at the Contact link at the top and let me know where the cool kids hang out these days.

  6. Nice project. The swoosh swoosh of the drive brings back memories of junior high.

  7. Yeah, but can computers think.

  8. Amazing!
    It takes me back. I got started programming one of those fellows.

  9. The Apple II community (some of them) hangs out in usenet comp.sys.apple2 — and a2central.com is the place to go for the news.

  10. Very cool. You might check out this software, it’s kind of a virtual floppy drive that connects via serial link to a PC or Mac for bootstrapping an Apple II with a binary disk image.
    http://www.apple.com/downloads/macosx/unix_open_source/appledisktransferprodos.html

  11. This is amazing. Great job. :)

  12. I have an Apple II but no OS. Does someone have one? I can make a copy.
    Please!

  13. Awesome project. Nice work Chris! :-)

  14. Small correction: hires is 280×192 (7 bits each of 40 bytes across, with the 8th bit being used for the half-pixel shift that gives 2 more obvious colors, plus some less-than obvious ones). Yes, I also grew up with an Apple II (original).

  15. Wow, what an awesome project. I still have my Apple ][ (standard, not +) and all my disks, but I’ve never actually done anything with it like you did. Thanks for the trip down memory lane!

  16. This is the hotness!
    1. Did you (or would you) consider doing it double-lo-res to still keep the blocky awesomeness but give a little more clarity?
    2. Would you consider releasing the floppy as an image so other folks could have this running? I would definitely buy a //c and a monitor for this app!
    3. Would you consider selling the cable pre-made?

    Thanks!

  17. "I was about to have the entire course of my life impacted…" Really? Impact is not a verb.

  18. Nathan, you are a dick. yergacheffe, this is an awesome project! Congratulations!

  19. You might be (awesomely) crazy enough to look into this: A <A href="http://sites.google.com/site/idiskapple2/">USB flash drive</a> for the IIe (also w/ Bluetooth).

    Solves bootstrapping issues, I reckon.

  20. Shut up, Nathan.

  21. 1 Mhz = 1 million instructions per second assuming 1 instruction per cycle
    1 Ghz = 1000 million instructions per second (same assumption)

    So the 6502 is thousands of times slower, not millions

  22. For nostalgia without the effort you can’t go past

    http://www.xs4all.nl/~gp/VirtualII/

    which emulates an Apple ][ with the disk noises and dot-matrix printer.

  23. <i>Really? Impact is not a verb.</i>

    Impact has been used as a verb since at least the 1960s, longer than the hardware featured in the video has been around. Deal with it, Nathan.

  24. SC II, since I never had an Apple //e or an 80-column card I never learned the double-LORES graphics modes. A buddy of mine at work was explaining it to me today and said it’s 2 LORES pages interleaved which is so sick it must be explored. The couple of evenings I spent on this is about the max time investment I can afford, so my inclination is to document things in more detail and release the software for others to improve and maintain.

    Also, how cool is it that a flame war about grammar broke out on my very own forums? I feel like I’ve arrived.

  25. So cool! Sigivald posted this yesterday but the link got jacked, so here’s a pointer to it:

    http://sites.google.com/site/idiskapple2/

    It’s a card that emulates a Disk II controller and allows you to use USB mass storage devices with your Apple II. Full of win.

  26. This is the awesomest thing in the history of Ever. I just wanted to say that.

  27. I use to have Apple IIe but threw it out with the garbage in the early 1990s :-( Now I recently wanted one back and bought Apple IIc for 20 bucks! IIc is without slots – simpler to set up for old computer forgetful like me!

  28. I use to have Apple IIe but threw it out in early 1990s along with the trash! :-( I wish I had it back so I recently bought Apple IIc it is like IIe but easier to set up for old computer forgetful like me!

  29. überRegenbogen

    Not only is there the 80×40 (with the caption area) double lo-res mode, there is also the 560×160 double hi-res mode, which yields the same 16 colours as lo-res at virtually 140×160. It’s a bit trickier, as many of those virtual pixels cross byte boundaries; and those bytes, like the lo-res bytes, are interleaved between main and auxiliary memory. But it would open the door not only to less chunky icons, but to dithering colours.

    FWIW, handling TCP/IP and Twitter API calls on a 1 MHz 8 bit machine is not as far out as you seem to imagine. Hell, someone even did it on a 5k VIC-20. (And there is at least one popular ethernet adapter for the II.)

    (I realise that you’re not looking to go gonzo on this project; but i reckon that you’ll at least find these things interesting.)

  30. Wow, I saw this exhibit at Maker Faire over the weekend and was very impressed. Of course, I had to tweet about it so I could see my tweet get its spot in the rotation. Makes me wish I hadn’t given away my Apple ][+ with 16k Language Card, 300 baud Hayes Micromodem, and disk drives years ago… *Sigh*

  31. Thanks for coming by the booth, Mike. I’m slowly over the course of this week replying to everyone who sent tweets to the Apple II with their HIRES and LORES profile pics, so at least you’ll have that :)

    Cheers,
    -Chris

  32. this Apple device is booting faster than my new pc :)

  33. I last bugged you about this in April….

    1. Any more thoughts (or time to make thoughts) about double-lores?
    2. Any more consideration for selling a floppy and/or cable so others can make this "go"?

    Thanks!

  34. I’m finally pulling together the code and documentation for this. It’s not complete yet but you can track it on my github:

    http://github.com/yergacheffe/apple2t

    /y

  35. Hi Modder,

    I have a working Apple IIe and all the core gear along with the best joystick I could find back then, a 3.5 drive, the original Hayes 300/b modem, and assorted software, games, manuals, etc.. This was my first computer purchase back in the 80s. I had played with a Commodor and Amiga as well, but I’ve been an Apple guy ever since. I have tons of subsequent systems that still work… up until the latest trends and products that is, most of which I find overpriced, overhyped and low-denominator consumer-driven. I write this from my G4 dual 500 tower on which I still have yet to install the 1ghz processor upgrades I bought about 3 years ago. A G5 tower is running music and video editing out in my studio, along my G4 PowerBook sidekick. I love these machines. They get what I need done.

    Anyway, I loved your story. If you don’t mind, might I pick your brain as to how I might easiest create an interface to extract text data from the old floppy 5.25 format (I have a working IIe dual drive) to either a more modern Mac or PC? The text files were created in AppleWorks as part of a SciFi novel I worked on then called “Project Titan” which my son loves seems to think I should finish. My idea was to try and connect to the internet with the Hayes modem and try to post the text into an email, which I would then retrieve. But haven’t tried that yet, and your ingenuity has me thinking there might be a better -or- more challenging way!

    Thanks buddy for a great story and I appreciate any ideas if you have time.

    deej

  36. Flash back… I loved the Apple II

  37. I remember playing games like Oregon Trail on the Apple 2 in the early 90′s during elementary school computer class… ps good work on the software! Love the 8 bit look.

  38. Nice technology, back to the 80′s.

  39. So inspirational. I’m so in love with Apple2, my heart is about pop out. I wrote the Apple2JS emulator a while back, and now I think I’m ready to develop my own Apple2 game :)

  40. So inspirational. I’m so in love with Apple2, my heart is about pop out. I wrote the Apple2JS emulator a while back, and now I think I’m ready to develop my own Apple2 game :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>