I’m really typecasting myself here. If there were an international “Person most likely to write a Spectrum emulator in Javascript” award, I’d have taken it for the last five years running. So here it is – probably the most stereotypical project I’ll ever come up with.
- Readme file
- Run JSSpeccy online (includes 10 classic games!)
- Download JSSpeccy (644Kb)
- JSSpeccy Subversion repository
Writing this wasn’t actually such a big deal – the Z80 core was ported from the one in Fuse, with the Perl-and-C-preprocessor-munging trickery still intact, and Javascript is syntactically close enough to C that that wasn’t a mammoth task. (I got 90% of it done on the train journey back from International Vodka Party alongside recording silly songs about tube stations.) The one fiddly bit was working around the places where the Fuse code used low-level C constructs to its advantage: using unions to chop and change between individual registers and 16-bit register pairs, and relying on limited-size C data types (often in pretty subtle ways) to truncate 8-bit and 16-bit values at the right time, whereas Javascript only has integers. (Actually, the really time-consuming bit was debugging it all… luckily, Fuse has a rather excellent test suite too.)
The rest is just creative abuse of the <canvas> element, as usual… it’ll take advantage of the putImageData interface to do the pixel pushing if available (on my machine Firefox has it, Safari doesn’t) and fall back on drawing 1×1 pixel rectangles otherwise. This time I’ve thrown in Google’s ExplorerCanvas as a nod to those poor unfortunates still stuck with Internet Explorer. Incidentally, I’d be curious to know how it rates on Google Chrome (I don’t have an XP/Vista box to test on) – if the hype is true (and it implements the putImageData interface like all good up-to-date browsers should) then I’d expect it to comfortably reach 100% Spectrum speed on modest hardware.
Insane! What a fundamentally bad idea. Good work, sir!
[...] Z80 Speccy [...]
[...] nombre es JJSpeccy y ha sido creado por Matt West. Aquí podéis jugar online, o descargarlo y usarlo como queráis. [...]
Simply excellent !
[...] emulador online de Spectrum, que se puede usar desde el navegador (incluye diez juegos) o también descargar desde la página oficial (Vía [...]
[...] browser. Matt Westcott (who also made the Antisocial demo) pulled another rabbit out of the hat, JSSpeccy the ZX Spectrum emulator. That’s just way [...]
[...] browser. Matt Westcott (who also made the Antisocial demo) pulled another rabbit out of the hat, JSSpeccy the ZX Spectrum emulator. That’s just way [...]
[...] Ciao a tutti, all’indirizzo http://matt.west.co.tt/spectrum/jsspeccy/ potete trovare un emulatore dello Spectrum scritto interamente in Javascript. Io lo trovo lento ed [...]
[...] Amiga in javascript http://www.chiptune.com/ ZX spectrum in javascript (JSSpeccy): http://matt.west.co.tt/spectrum/jsspeccy/ __________________ XTemu | GeneralEmu | Webcomics ……-.________ —( )_)_______) -> [...]
[...] Westcott创造的JSSpeccy the ZX Spectrum emulator 。 James Urquhart 创造的SCUMM interpreter [...]
nice one. have you checked out the one I made (AS3) ? http://flexiblefactory.co.uk/spectrum
Probably the most impressive, amazing, awesome code I have seen so far this YEAR. (Together with http://flexiblefactory.co.uk/spectrum of course :))
Thank you both and congratulations for your efforts to convert your ideas into reality.
I would be interested to know if anyone’s had any success writing an Acorn BBC or Atari ST emulator in Javascript or similar? (I have seen http://atari.isource.net.nz).
Thanks and BEST regards,
James
It works great with chrome!
good job..
[...] few months ago, I stumbled across Matt Westcott’s excellent JSSpeccy. I had seen some pretty imaginative canvas creations, but Javascript emulators? What a perfect idea [...]
[...] JavaScript pagalba. Projekto autoriui Ben Firshman kaip jis pats teigia gime perskaičius Matt Westcott straipsniuką apie JSSpeccy biblioteką. Ben [...]
[...] A ZX Spectrum emulator in Javascript. Nothing like playing Super Mario and Contra in [...]
[...] you can. Check out this story! A few months ago, I stumbled across Matt Westcott’s excellent JSSpeccy. I had seen some pretty imaginative canvas creations, but Javascript emulators? What a perfect idea [...]
Cool! I was so impressed of your stuff so I have moved my old i8080 emulator to the JavaScript rails. The hardware is the 8-bit Russian computer based on i8080 named Radio-86RK.
The project site is http://code.google.com/p/radio86/
It is on Russian because that computer is 99% Russian ;-), but the direct link to the emulator (http://radio86.googlecode.com/files/radio86.html) actually gives a clue how it works like.
BTW, I’ve found a bit weird logic in your Z80 implementation. For example, a register increment:
Your implementation is:
case 0×0c:
{ (z80.c) = ((z80.c) + 1) & 0xff; z80.f = ( z80.f & 0×01 ) | ( (z80.c)==0×80 ? 0×04 : 0 ) | ( (z80.c)&0×0f ? 0 : 0×10 ) | sz53_table[(z80.c)];};
So I’ve got rid of weird calculation of the parity flag — “( (z80.c)==0×80 ? 0×04 : 0 )” and just use “sz53p_table” instead of “sz53_table” to calculate the parity flag.
I guess maybe for Z80 it is correct but for I8080 it should be like this:
case 0×0c: // inr c
i8080.tstates += 5;
i8080.c = (i8080.c + 1) & 0xff;
i8080.f = (i8080.f & 0×01) | (i8080.c & 0×0f ? 0 : 0×10) | sz53p_table[i8080.c];
break;
So I had to change the register increment and decrement routines (INR x and DCR x in I8080 notation).
Maybe it could be useful for you.
Anyway, thanks for idea.
Alexander: more my implementation (as part of Fuse) than Matt’s really, and it’s right for the Z80: in this case it’s acting as the oVerflow flag to indicate a change of sign rather than as the parity flag. You’ll be right for the 8080 though :-) Cheers!
[...] I stumbled across Matt Westcott’s JSSpeccy and it sparked my imagination. I have a tendency to get trapped by overly ambitious projects, and a [...]
Awesome!!! Runs on my HTC Magic Android mobile :-)
Since you asked it works well on Google Chrome Browser.
Hi,
How do I install this on Android?
I have motorols droid….
Paul: There’s nothing to install – it just runs directly from the web page at jsspeccy.zxdemo.org. (Unless I’m getting the wrong end of the stick, and ‘installing’ a webpage so that you can view it offline is a standard practice on Android phones – in which case, I have no idea…)
[...] been used for a number of unusual projects in the past few years. We’ve had NES emulators, Spectrum emulators, and even Amiga emulators. But a Flash player?… What’s the point of emulating a [...]
Great for iPhone users !!!!!
So, how can I use it with iPhone ?
It works, but there is no keyboard…
There is a workaround to brings up the virtual keyboard ?
There is another way to use it with touch ?
Think about that THIS emulator can be actually the ONLY ONE solution to emulate Speccy with a non-jailbroken iPhone…..
Nope, no virtual keyboard support… you need to use the ‘joystick’ icon to set up mappings between Spectrum keys and joystick directions, and then you can touch the appropriate areas of the screen to trigger those keys.
doesn’t work on nexus one for some reason :(