Imran Nazar&39's JavaScript emulator can run 1989-era Game Boy games in a Web browser.

(Credit: screenshot by Stephen Shankland/CNET)

One consequence of the steady increase in computer power is that newer machines can emulate the behavior of older ones, with software running fast enough to simulate operations that formerly required hardware.

Now, in an illustration of just how far Web programming has come, one coder has begun a project called jsGB that lets a Web browser emulate Nintendo's original Game Boy handheld game console.

Imran Nazar, a 26-year-old programmer from Manchester, U.K., has begun work to emulate the Game Boy in JavaScript, the Web programming language whose performance has become a top priority of browser makers today. JavaScript is used for everything from pop-up dialog boxes on Facebook to the Google Docs online productivity applications, but Nazar is busy adding 1989-era Tetris and similar games to the list.

"New JavaScript engines such as [Firefox 4's JaegerMonkey] mean much higher speeds for the core processing, more than enough to cover emulation of a basic system," Nazar said in a blog post on Mozilla's gaming site. In addition, HTML5 now offers the Canvas element for easily controlling a two-dimensional graphical display, he said.

"Why write a console emulator It's a good way to learn the ins and outs of a particular console, and excellent for bringing together the lowest and highest levels of development," Nazar said. "And why build a console emulator in the browser, using JavaScript and HTML5 I say: why not"

The work spotlights the growing capability of Web-based programs. JavaScript performance increases, though hard to measure, are opening new horizons for Web programmers. The cloud computing philosophy, which can let people get access to information and use online tools wherever they have a browser, is gaining credibility. New Web standards and browser features such as offline storage, advanced graphics, and hardware acceleration improve what browsers can do.

It's not all easy going, though. Perhaps the most advanced embodiment of the Web-app future, Google's Chrome OS, is stumbling on its way to market. Its troubles aside, however, it's clear more and more gets done in a browser window.

Nazar isn't the first to tackle the subject. Another JavaScript Game Boy emulator from 2009 is available on the Web, though like Nazar's so far, it's silent.

But Nazar has been chronicling his Game Boy project at his Web site. It's interesting as much for the gory details of how the Game Boy works as it is for how Nazar brings it to JavaScript.

The handheld computer introduced two decades ago didn't have much horsepower. The Game Boy came with a modified Zilog Z80 processor, an 8-bit model that could only address a 16-bit memory space of 65,536 bytes--less than a thousandth of what typical computers have today.

Getting the performance right is tricky because browsers' JavaScript execution speeds vary more than the Game Boy's processor clock frequency, though.

"Timing of the games is pretty much bang-on, since the original games based their timings on the cycles of the CPU: since the CPU timing is accurate, games run in step," Nazar said in an interview. "Actual running speed is highly dependent on the browser used: I've noticed that Chrome and newer beta builds of Firefox run the emulation much more quickly, thanks to the new JavaScript engines in these browsers."

Its screen was simple, too. The display measured just 160x144 pixels, each able to display black, dark gray, light gray, or white. The entire thing fits easily into a patch of "frame buffer" memory controlled through the HTML Canvas element.

Nazar also has figured out how to simulate the input controls--a relatively simple layout with a four-way rocker switch and four control buttons.

Nazar didn't have to figure out the hardware details himself. "The Game Boy hardware is very well documented, since so many people have reverse-engineered its internals over the years. Pan/ATX compiled the more-or-less definitive specification of the Game Boy hardware' I've got it mirrored."

The games themselves are hosted on his server, from which the emulator retrieves them to load them. "All the games I've used to build and test the emulator are public-domain and available on pdroms.de, apart from a recompiled version of Tetris built from reverse-engineered source code," he said.

Perhaps later he'll tackle the color version of the Game Boy, he said.

"The color Game Boy is a significantly more complicated beast, but I won't rule out putting together an emulation of it," Nazar said. "It won't be for a while yet, though."

Updated 9:58 a.m. PT with comments from Nazar.


Discuss   Add this link to...  Bury

Comments Who Voted Related Links