Converting a C++ Program to Javascript

April 2, 2009 by Dave Ross

I was screwing around in our “home office” last night, and a floppy disk fell off a shelf. It was my Hunt the Wumpus program, the final project for my C++ class at Harper. I took that class in the Fall of 1999, almost ten years ago, and thought it might be fun to convert the game to run in a browser.

A big part of that class was exploring object-oriented concepts. And, since one of my New Years Resolutions this year was to use more OOP in my Javascript code, I figured Javascript would be the way to go.

It started off well enough. After a few hours, I had the thing pretty much running using document.write and prompt(). It felt like I was back in 1996, on some of the earliest Javascript sites. We’ve come so far since then. So, I threw together a class I called jsTTY, which turned a textarea into something resembling a text console like you’d see in the old DOS days. I even used CSS to give it green text on a black background.

As I started integrating jsTTY into Hunt the Wumpus, I realized that a game like that wouldn’t convert directly into Javascript — I’d have to rewrite a large chunk of the Wumpus code for Javascript’s programming model. Specifically, Javascript lacks blocking I/O or any sort of sleep() command. I wanted something like cin.getline(), which waits until the user hit “enter” before returning a string. jsTTY.line() worked like that, but it had to spin in a do/while() loop, eating up all the CPU and crashing Safari.

Normally, the way to deal with something like this is to sleep in the middle of the loop. Even if it’s just for 1/1000 of a second, that’s an eternity for a modern CPU. The closest thing Javascript offers is setTimeout(), which sets up a timer to run some function and returns right away, something akin to spawning a thread, but not quite.

I realized that my main loop, the core of pretty much any video game, needed to be replaced by a ballet of asynchronous events. That’s only, oh, half the Wumpus code, and certainly more than I want to tackle right now.

Still, it was an interesting experience, and I look forward to getting jsTTY working in some fashion.

 

Bought an IBM Think Pad

March 9, 2009 by Dave Ross

Think PadYeah, I know I just bought a MacBook, but I just couldn’t pass this deal up. I picked up an IBM Think Pad off eBay last week, and it arrived today.

It’s the ultraportable model designed to fit in a shirt pocket, and it has a tablet form factor. It came stock with an IBM 520-5430 for storage, although I don’t know if I can find storage upgrades for it anywhere since it’s kind of an older model.

Ok, this is getting corny. What I bought is indeed one of the original Think pads produced by IBM in the mid 20th century. It has maybe 50 blank, unlined pages and a vinyl cover embossed with the word “Think”, IBM’s internal slogan at the time.

I think it’s time to set up a vintage computer collectables shelf for things like this I’d really like to keep on display.

 

How did we compute before the Internet?

March 8, 2009 by Dave Ross

I picked up an external SCSI hard drive at a garage sale this weekend. Listening to the RetroMacCast has left me wanting to play with the Mac Plus in our spare bedroom and see what I can do it with. I have System 6.0.8 floppies, so there’s a lot of things I can do with it in theory.

But that theory hit the brick wall of practice last night when I tried hooking up the hard drive. Apple’s “HD SC Setup” program only recognizes Apple branded hard drives, not the LaCie I bought. I turned to Google for answers, and found that there were third-party hard disk formatters for the early Macs, as well as a one-byte patch for “HD SC Setup” itself. All I had to do was download the files and copy them to an 800K Mac floppy. Oh, one catch: USB floppy drives won’t write to 800K floppies.

I spent the last hour this morning reading Jef Raskin’s “Book of Macintosh“, a compendium of essays and notes from the preliminary stages of Macintosh design. One thing that stood out was Raskin’s insistance that Macintosh’s hardware didn’t need to be anything special, because the real value of the Mac was the ease of connecting it to a network. The Mac was supposed to be just another node on a LAN, Tymnet, or even ARPANet.

Last night, I reviewed my options, and none were pleasant. To get the software I need in a format my Mac Plus can handle, I have to track down a Mac G3 computer that still has a floppy drive capable of writing 800K disks, or spend $150 on an Ethernet adapter that plugs into the SCSI port. Or, and this is the route I will probably go, I can find someone who already has a networked classic Mac who can get me some software, including those hard drive utilities. I’m sure someone in the chiclassiccomp group can help me.