Sunday, June 15, 2008

A bugged life

The title of this post actually applies to two completely different matters. First, I saw a really great movie last night about life in East Germany before the wall came down. It's called "The Lives of Others". German with English subtitles. Highly recommended. One of the best films I've ever seen.

But what I really wanted to tell you about was an obsession that's had a hold on me for the past few weeks. Every now and then I am afflicted with a bout of nostalgia. I have a few boxes of memorabilia stashed away in the garage, and the other day I was digging through one of them and came across a box of 5-1/4 inch floppy disks. For those of you two young to remember, these disks are actually floppy. They bend. And in their day they stored a whopping total of 140 kilobytes of data. Ah, those were the days.

One particular disk caught my attention because its label said "P-Lisp". This was my very first Lisp back in the day, and it arguably launched my career in computer science. So I thought it would be cool to resurrect it and watch it run, for old times' sake.

The plan was fairly straightforward: buy an Apple II from Ebay, get a copy of ADTPro, make a disk image, and run in on an Apple II emulator. I figured getting the Apple would take about a week, and then it would take an hour or two to get ADTPro up and running and grab the image. Just a little diversion.

Little did I know.

I logged on to EBay and found just what I needed: an Apple IIe with two disk drives. The high bid was $5! What a steal! So I, being the naive EBay bidder that I am, bid $10 figuring I was sure to win.

Now, you EBay veterans out there -- I can hear you -- you can stop snickering now. As you might expect, I was outbid and lost the auction. But the person who outbid me backed out of the deal, so I got a "second chance" to accept the deal at my original offer. And because of EBay's auto-bid system I didn't even have to pay the full $10, I just had to beat the $5 bid that was in effect when I placed my bid, so the machine could be mine for $6!

That is, it could have been, if I'd gotten the email in time. The second-chance offer is only good for 24 hours, and I just happened to be on a boat when the message arrived. So by the time I got the message it was too late.

(For those of you who are South Park fans, I would now like to call to mind the episode where the kids are all excited about the fact that some TV network is going to air a program where the word "shit" is spoken without being bleeped out. (It's episode 502 in case you want to go back and review.) The program of course is self-referential, because the discussion of the word is not bleeped out, and there's a little counter at the bottom of the screen that starts counting up the number of times anyone says the word during the episode. The counter reaches an astonishingly high number before it's all over. What follows will be all the more fun if you keep that imagery firmly in your mind as you read.)

No problem, I thought, the seller had already re-listed the computer, so I figured I'd just bid again. This time, though, I had more competition and lost out at $20. (Heck, I'd almost had it for $6, why pay three times as much? Surely another single-digit deal will come along.)

One week and half a dozen failed bids later I decided to give up and order an Apple IIe from Top Micro, which had several of them in stock for $20 each -- plus $40 UPS Ground shipping. Oh well, it's all for the cause of historical preservation I told myself. I still needed a disk drive, but I figured I'd figure that out later. There seemed to be a steady trade in Apple II disk drives on Ebay.

The IIe finally arrived. I plugged it in, turned it on, and it came up with the Apple II prompt. Cool! It works. I hit a few keys...


The keyboard was dead.

No problem, I thought, probably just a loose connection, and when it comes to old computers I'm MacGuyver. So I whip out the trusty phillips screw driver and open 'er up.

Inside I found a twenty year old puddle of coffee. Cream, no sugar.


So I get out a sponge and a shop vac and clean her up as best I can. No dice.

OK, this is obviously not going to work, so back to EBay, where I finally decide that I'm spending too much time on this and I'll just bite the bullet and shell out whatever it takes to get a working Apple with disk drives. "Whatever it takes" turned out to be about $100, but what the heck, it's all for a good cause, yadda yadda yadda.

While I'm waiting for the new machine to arrive I decide I now have nothing to lose by taking drastic measures to try to resurrect the IIe. So I take out the keyboard and give it a good wash with hot water. (You can actually do that safely to most keyboards as long as you dry them out THOROUGHLY before using them again.) No good. OK, here's my new Apple II+ with disks. So I put the IIe away and go to play with my new toy.

Happily, it works out of the box, and within ten minutes I'm actually able to boot one of my old floppy disks. A little bit of playing around convinces me that the drives are in good working order, and I finally work up the courage to try my P-Lisp disk.

Now, I should mention at this point that my P-Lisp disk was, as far as I could determine, the last extant copy on planet Earth. The Lisp community is not that large, and the subject of P-Lisp comes up from time to time, but I had never heard of anyone ever locating another copy despite periodic requests from history buffs to find one. So this is a pretty important disk.

Amazingly, considering all the things that went wrong on this project (and believe me, we're just getting warmed up here) that this one thing *didn't* go wrong is astonishing. I put the disk in the drive and booted it up and it worked. It just worked! There I was playing with a program that hadn't seen the light of day in over twenty-five years. I quickly made a copy of it, and to my amazement (especially in retrospect) that worked too. Cool, I thought, I'm nearly done.

I need to digress for a moment and tell you a little bit about ADTPro. It's a really cool program for resurrecting old Apple II machines. To understand just how cool it is you have to remember that back in 1979 when the Apple II came out they did not have ethernet ports and USB ports and Firewire ports. They had cassette ports. Like audio jacks that you plugged into an actual cassette recorder. That was your mass storage.

ADTPro comes with audio files that you can play back into an Apple II's cassette port to download bootstrap software so that you can get an old II up and running without any disks. This is quite an amazing thing if you think about it, and I can't even begin to imagine what would possess someone to put so much effort into something that is ultimately not really good for very much except nostalgia. But there it is. Anyway, I dug out a bunch of audio cables, hooked it up, and after just two tries (you have to fiddle with the volume a bit) I had uploaded ProDOS and was ready to upload the ADTPro client.

That was the last thing that would go right for a long, long time.

For some reason the ADTPro client just refused to upload. I must have tried it twenty times, with each attempt taking several minutes. The Apple doesn't give you any indication of what goes wrong, it just gets to the end of the upload and prints "ERR" and beeps at you. After about two hours I was about ready to throw that damned machine out the window.

OK, that was obviously not going to work. Happily, ADTPro can also connect via a serial port, which is a more robust connection than the cassette ports. But Apple II's didn't have serial ports built-in, they were add-ons. So back to EBay to buy an SSC and off to Fry's to buy a USB-to-serial converter (because things have come full-circle and Apples once again do not come with built-in serial ports, which is probably as it should be).

By this time my wife is starting to ask me when I'm going to get that damned Apple II out of the workout room.

I watched my Super Serial Card wend its way across the country via UPS's on-line tracking system. In retrospect, this should have been a sign that I was starting to take this project a wee bit too seriously.

The SSC finally arrives, and I breathe a sigh of relief. I can finally get this damn thing done! I plug it in, fire up ADTPro and start the bootstrap procedure...

And it doesn't work! AAARRRGGGHHH!!!

By this time I am completely obsessed. I am determined to get this damned disk image come hell or high water. I am MacGuyver. I eat bugs for a living. No stupid 8-bit machine is going to get the better of me.

Now, I am going to do you a favor and spare you all the details of everything that happened while I was trying to debug the problem I was having with the serial link. Suffice it to say that by the time it was over, two weeks had gone by. I had probably spent twenty hours on it (thirty if you count the trips to Fry's). I had bought three USB/RS232 cables and God only knows how many miscellaneous cables, adapters, breakout boxes, volt meters, crimpers, testers and null modems. I had a frankencable setup so scary it would have made Ridley Scott run screaming in fear.


Sometimes it's really hard to know when you've reached the point of diminishing returns. On the one hand I was fully aware that I was spending way more time on this stupid project than it was worth. But on the other hand I really didn't want to quit. I really felt like I was on the cusp of a breakthrough, and that any minute I would figure it out. And eventually I did.

My best advice in situations like that is to get a good night's sleep. I think if I'd actually followed that advice I might have figured it out in half the time. The problem turned out to be a nasty timing-related bug in the device driver for the USB-serial cable that I was using. But the way in which events unfolded turned out to be an almost perfect conspiracy to make this problem as hard to discover as possible.

The first thing that happened was that I bought one USB-serial cable. I chose the name brand (IOGear) figuring it had the best shot at being reliable. I installed the drivers, plugged it in, and it *mostly* worked. There was just one particular circumstance under which it failed, and ADTPro just happened to hit the one magic combination of timing that triggered the bug.

The second thing that happened was that the symptoms were intermittent data corruption. So my attention was naturally drawn to my cabling setup and the old SSC card, which seemed like a more likely source of random problems than a brand spanking new USB device.

The third thing that happened was that I wrote a little Python program that uploaded the bootstrap software successfully. That made me think it was a bug in ADTPro for a long time.

The fourth thing that happened was that I bought two more USB-serial cables, all different makes and models, and they all did exactly the same thing. Of course, they were all running off the same buggy driver too. But I didn't realize that at the time.

I eventually managed to reproduce the problem between two Macs using Python code, which proved that both ADTPro and the old Apple II hardware were blameless. And after another hour or so of sleuthing I finally decided to try a different driver, which solved the problem. Thirty minutes later I had my disk image. My Apple II is now neatly packed away. And I am MacGuyver again.


[UPDATE:] You can find the plisp image here.


Dan Weinreb said...

Great story!

"The Lives of Others" is indeed an amazingly good film. I was originally put off by the trailer; it's actually a lot more complex and subtle than you might think from the trailer, so, anyone reading this: see it! The star, Ultich Muhe, can act better with just his eyebrows than most actors can act with their whole bodies -- watch him do it!

Curt Sampson said...

Hey, to save the last extant copy of P-Lisp for the Apple II, that's worth all the effort!

Anonymous said...

good god, that is a hardcore story. only a few times have I persevered like that once was when I had taken apart an old royal typewriter and, to put it together again, realized that I needed to perfectly balance four separate ball bearings with gear rings around them simultaneously while at the same time sliding the platen in just right so as to engage the four gears that were floating around the ball bearings. Got it done! phew.

Ronny Svedman said...

I do appreciate your comitment o this, because old data must not cease to exist, and some historian some day will be thankful to you. Also, I now get to try Plisp on my IIe. I just last year learned pascal on the Aplle from 30 year old books, and now I am goiong to try lisp with the old docs you linked to. Retrocomputnig is wonderful hobby, but it does take time.