JavaScript Space Invaders Emulator
Ajaxian recently posted about a fun JavaScript implementation of PacMan. After spending way too much time on it I wondered how well an emulation of the old arcade game hardware would go in JavaScript.
I've written a few 8080 arcade game emulations before in different languages so I had a go at implementing it in JavaScript. You can try the work in progress at my JavaScript 8080 Emulation page. It runs surprisingly well on modern JavaScript engines.
The page first loads with the arcade game Space Invaders loaded. You can run a set number of instructions, or step through one at a time. It displays the disassembled output. Pressing 'Animate' will run the game in a timer and it can be played. It is a general 8080 arcade game emulator, for the games that use similar hardware to Space Invaders. The buttons at the top load the code for Space Invaders, Lunar Rescue or Balloon Bomber.
If you have a bleeding edge version of Firefox 3.1 with Ogg Vorbis <audio> support, pressing the 'Enable Audio' button will enable sound. The sound support uses <audio> to play the samples when requested by the emulator. This turns out to make a good test case for my audio support and it may need the fixes from bug 449159 and 454364 to work.
If you're interested in the other emulators I've done:The implementation does not get traced with the TraceMonkey tracing JIT yet. I'll look into the reasons why and as TraceMonkey and my implementation improves it'll get faster I'm sure. Even so, it runs very close to full speed.
This implementation uses Canvas, audio for sound and should work on browsers with a fast JS engine and these technologies.
For the emulator loop I run a set number of instructions during a timer that is run via 'setInterval' to prevent the 'script is running too long' message. One thought that Robert O'Callahan suggested was to run the emulator in a worker thread and have communication for input/output via messages to the browser. I'll play with this idea and see how it goes - it'll give me a chance to try out Firefox 3.1 worker threads implementation.
The emulator can be run (without the GUI) from a JavaScript shell for testing purposes. I used the shell to test the implementation by running my Factor version and logging all the state of the emulated CPU, doing the same with the JavaScript version, and making sure the output was the same.
Although it's not quite perfect, it's currently playable, and shows that the types of games that are written as Java or Flash applets can be done in standard HTML and JavaScript in the latest browsers.
Categories: firefox, javascript
I've written a few 8080 arcade game emulations before in different languages so I had a go at implementing it in JavaScript. You can try the work in progress at my JavaScript 8080 Emulation page. It runs surprisingly well on modern JavaScript engines.
The page first loads with the arcade game Space Invaders loaded. You can run a set number of instructions, or step through one at a time. It displays the disassembled output. Pressing 'Animate' will run the game in a timer and it can be played. It is a general 8080 arcade game emulator, for the games that use similar hardware to Space Invaders. The buttons at the top load the code for Space Invaders, Lunar Rescue or Balloon Bomber.
If you have a bleeding edge version of Firefox 3.1 with Ogg Vorbis <audio> support, pressing the 'Enable Audio' button will enable sound. The sound support uses <audio> to play the samples when requested by the emulator. This turns out to make a good test case for my audio support and it may need the fixes from bug 449159 and 454364 to work.
If you're interested in the other emulators I've done:The implementation does not get traced with the TraceMonkey tracing JIT yet. I'll look into the reasons why and as TraceMonkey and my implementation improves it'll get faster I'm sure. Even so, it runs very close to full speed.
This implementation uses Canvas, audio for sound and should work on browsers with a fast JS engine and these technologies.
For the emulator loop I run a set number of instructions during a timer that is run via 'setInterval' to prevent the 'script is running too long' message. One thought that Robert O'Callahan suggested was to run the emulator in a worker thread and have communication for input/output via messages to the browser. I'll play with this idea and see how it goes - it'll give me a chance to try out Firefox 3.1 worker threads implementation.
The emulator can be run (without the GUI) from a JavaScript shell for testing purposes. I used the shell to test the implementation by running my Factor version and logging all the state of the emulated CPU, doing the same with the JavaScript version, and making sure the output was the same.
Although it's not quite perfect, it's currently playable, and shows that the types of games that are written as Java or Flash applets can be done in standard HTML and JavaScript in the latest browsers.
Categories: firefox, javascript
Labels: mozilla

10 Comments:
Very cool, but it's not working for me. Looks like nothing ever gets loaded, all I see are NOPs and a blank screen no matter how long I run it.
What browser modeless? If you get the NOPS then it mostly loaded but it sounds like the rom didn't load. Does the JavaScript console show any error?
It's possible your browser doesn't support canvas createImageData. You might need a nightly build.
No sound with
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b1pre) Gecko/20080911083500 Minefield/3.1b1pre ID:20080911083500
but that could just be my setup borked (again)
fun though
Yeah sound is broken because of bug 454364. I have a local fix for this, so I probably have the only browser in existence that plays sound :)
I'll have the patch for that uploaded when bug 449159 is done since it depends on the refactorings in that.
Looks like building a library to enhance communication with the worker thread, will be required as message-based passing values would require parsing anyway.
Error console gives this error:
Fehler: cpu.ctx.createImageData is not a function
Quelldatei: http://www.bluishcoder.co.nz/js8080/
Zeile: 260
Ah yes, it was createImageData. I was using Firefox 3.0.1 by accident; it works in nightly builds. Cool stuff. Doesn't work in chrome either for the same reason.
Lots of cool stuff being done in javascript lately. Barack Whack is another cool little game done in javascript. Having the audio tag will be a further boon for these types of games. Exciting where this tech is going.
http://games.mozdev.org has been around for years.
Hrm, would be great if they were updated for Firefox 3.
Have you seen 6502asm.com. An assembler and emulator in javascript.
I have my own mutant version converted into flash http://screamingduck.com/Lerc/6502asm/ for speed and higher resolution.
I did the flash conversion quite some time ago, before all of the browsers really got stuck into speeding up Javascript. I really should do a compare with the new batch and see how it goes.
Post a Comment
<< Home