Yesterday’s Full Frontal javascript conference turned out to be the ideal setting to compare notes with Ben Firshman of JSNES fame on the finer points of implementing emulators in Javascript – so this new release of JSSpeccy is the natural consequence of that. I’ve put in an optimisation which might possibly be a speed boost on Chrome (only writing bytes to ImageData when absolutely absolutely necessary), and the much-needed ability to load your own snapshot files, using the little-known getAsBinary method on file upload objects. (Unfortunately Firefox 3.5 is the only browser which supports it right now, but it looks like it may be in the process of getting the official W3C blessing right now.) And since I was on a roll, on the train back I implemented tape loading traps and the ability to load .TAP files (again, only on Firefox 3.5). Wahey!
Archive for the ‘Hacks’ Category
JSSpeccy v20091121
Saturday, November 21st, 2009Midibeep
Thursday, October 29th, 2009Last week I posted possibly the most tedious Basic type-in listing ever to World Of Spectrum:

(continues for approx 1500 more lines)
Anyone typing it in in its entirety would be rewarded with this:
Not bad for an evening’s work. Mind you, I did take an ever so teeny shortcut, by writing a Ruby program to convert a MIDI file to BEEP format. (Any .mid file will do, although ones with a single instrument will survive the rather primitive selective-note-butchering process better. Oh, and anything much longer than this one will exceed the 48K Spectrum memory…) And now you can try it out too:
- Midibeep source/downloads at Github
- Midibeep Windows build (thanks to Karl McNeil)
- Minute Waltz (TAP, 38K)
JSSpeccy v20090929 (Don’t-Mess-With-Geeks Edition)
Tuesday, September 29th, 2009I wasn’t really planning on developing JSSpeccy further, because I didn’t consider it a serious project with a future. However, it turns out that someone else did. Enough to rip it off wholesale and pass it off as their own work on the iPhone app store for £1.29 a pop, no less. Yes, thanks to the detective work of Phil Kendall we now know that ZXGamer, the much heralded Spectrum emulator for the iPhone, was nothing more than JSSpeccy with a fancy title screen tacked on. (Which of course is a blatant violation of the GPL, and being pure Javascript, would explain why it ran at less than the speed of a real Spectrum on a 600 MHz device, and why it was overwhelmingly rated at one out of five stars. Epic fail.) It’s been pulled from the app store now – so while ZXGamer is gradually disappearing from the internet, it’s time to redress the balance a bit.
A new version of JSSpeccy is out. It doesn’t run at full speed on an iPhone either (although it positively speeds along on recent versions of Safari on real computers), but it does boast the following changes:
- GPL v3 licenced, with prominent notices to make it clear that playing silly buggers like the above will not be tolerated (even if they do include source…)
- A bit of speed optimisation (about 15% faster maybe)
- A pimped-up user interface with shiny icons
- And most relevantly, entirely controllable via iPhone / iPod Touch touchscreen. In principle. (If you’re expecting an immersive gaming experience, you’ll be disappointed.)
So there you go – probably the best Spectrum emulator for the iPhone ever. And it’s free.
Sleeper – mapping European night trains
Wednesday, June 10th, 2009
It’s now been 10 months and 10 demo parties since I last saw the inside of an airport (with plenty more to come over the next couple of months… parties that is, not airports), and for any eco-conscious European traveller like me, knowing which sleeper trains to catch is the key to happy travels. So, it’s a bit of a shame that there’s no single website you can go to to find out the best sleeper train to get to European Destination X. Sure, Seat 61 is a fantastic resource for finding out how to get to your country of choice, but you can never be sure whether you’d get better results by heading just across the border, or tweaking your journey times slightly…
So, in a classic case of building a website to scratch a personal itch, and not wanting to let niggly licencing issues get in the way of a cool idea… Sleeper is my new website aimed at searching and mapping the European sleeper train network in its entirety. It’s been put together with Ruby, Rails (gosh, that’s rather apt isn’t it…), Geokit, Google Maps, Hpricot and my own freshly open-sourced Bahn library for snarfing data from Deutsche Bahn’s website, and hopefully it can give you a fuller picture than ever before of what actually exists in the wonderful world of sleeper trains. Right now it stops short of providing one overall definitive map of the network (it would probably crash your browser if I tried plotting it on Google Maps), but that’s on the todo list.
Ode To Claire / Snakebite
Wednesday, June 10th, 2009A couple of fast-made Spectrum releases for last month’s most excellent Outline demo party. Ode To Claire is a curious little 128 byte intro, using a trick I’ve been wanting to try out for ages. It’s not exactly a fast-paced action extravaganza, but it does fit 150-odd characters of avant-garde poetry, the printing routine, and a demo effect into 128 bytes of code. Working out how is an exercise for the reader (and I’m quite interested to know whether the secret is immediately obvious to anyone who’s at all familiar with the Spectrum…)
On the musical front, Snakebite is a chiptune with a middle-eastern vibe, modelled after every Turkish Eurovision entry ever. It got third place in the competition, and originally they weren’t going to give out a third prize, but they had some spare food left over on the Saturday night, so I won a jar of sausages. Best. Prize. Ever.
JSSpeccy: A ZX Spectrum emulator in Javascript
Sunday, October 19th, 2008I’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.
Antisocial
Thursday, October 9th, 2008
This is it then… my big comeback to the Javascript demo scene after a two year absence, and also the moment when my demo coding muse returned from a long holiday, I guess. Ladies and gentlemen, I give you… Antisocial, a biting satire on social networking phenomena.
Visit the Antisocial microsite…
With my characteristic lack of organisation, I found myself with two weeks to go to the Sundown party, having promised a demo release, and with nothing specific in the pipeline. So, I decided to take a chance and run with an idea that had been sitting on top of my “demos to write when I have more free time than I do right now” pile for the best part of a year. I had it all planned out in my head, right down to the soundtrack: a mysterious track from an unlabelled CD I picked up at a ZX Spectrum Orchestra gig in 2005 (which turned out to be Round, from their Clive Live^3 EP). A quick bit of permission-getting later, and I was at the point of no return.
I knew it would be an ambitious job, and a bit of a leap artistically and technically from my usual stuff. I pencilled in a rough project plan in my diary. I drew up storyboards. I read up on the maths that was too nasty to contemplate on previous projects. And shockingly enough, I actually enjoyed all of the above.
Some rather opinionated plugins
Saturday, August 30th, 2008Update: The belongs_to patch has now made it into core Rails. Thanks to Jon for persevering with it where I threw in the towel, and to Koz and Pratik for giving it their attention. I’m still not entirely convinced that going through the conventional channels (as opposed to “whinging on a blog”) would have yielded the crucial feedback to get the patch in a state where it could be accepted, but all’s well that ends well…
Take this as the rantings of a pissed-off curmudgeon who’s had his second core patch rejected if you will, but it’s my sad duty to report that Rails has jumped the shark. It happened when it stopped being a framework and started being a collection of opinions instead.
You see, in my book a framework is something that’s meant to make programmers work more effectively – not to lecture them about what they’re doing wrong. Lecturing can be a good thing, as long as it ultimately results in better code – I’ll happily admit that following the Rails learning curve has taught me an awful lot about good programming practices. More and more though, I’m finding it being used to justify just plain broken features: If it doesn’t work, it’s your fault for not doing it the right way. Take this bit of profoundly broken behaviour:
let’s say we have a Company model, which belongs_to :city
>> torchbox = Company.find_by_name('Torchbox')
=> #<Company id: 1, name: "Torchbox", city_id: 1>
>> torchbox.city
=> #<City id: 1, name: "London">
Aha, we’ve got the city wrong. Let’s reassign a bundle of attributes then, like we would if we were doing this through a web form:
>> torchbox.attributes = {:name => 'Torchbox', :city_id => 2}
=> {:name => 'Torchbox', :city_id => 2}
Right, so now we should retrieve the correct one.
>> torchbox.city => #<City id: 1, name: "London">
Er, oops.
(more…)
Comet Chaos
Monday, July 7th, 2008Thanks to Oleg for reminding me at OpenTech that I still hadn’t written this up yet…
This started out as an experiment in Comet techniques (which allow you to actively push data out from web servers without the client having to initiate the request) which quickly ballooned in ambitiousness – I didn’t set out to write Just Another Chat Application after all. The end result is a realtime multiplayer Javascript conversion of the Spectrum wargame Chaos… or a reasonable chunk of it, at least.
If you’re interested in the workings behind it, check out this video from my Oxford Geek Nights presentation to hear about how Comet is like a small child on a car journey, find out how close web developers can get to world domination, and watch a live demonstration going pear-shaped.
Djerb: Django-ish templates in Ruby
Thursday, April 10th, 2008As is fairly well documented by now, I like Rails, and I’ve done quite a bit of stuff in it. However, through a brief stint of work on The Carbon Account I’ve been getting my feet wet with arch-rival (ok, not really) framework Django, and I found myself hugely impressed with its templating system. A less stubborn person than me would think “That’s a nice idea. Maybe I should think about switching to Django.” My reaction, however, is “That’s a nice idea. I think I’ll steal it.”
(more…)