Archive for the ‘Hacks’ Category

JSModPlayer – a Javascript .MOD player

Sunday, May 23rd, 2010

The epic Pacman 30th anniversary Google Doodle, along with Ben Firshman’s dynamicaudio.js library for dynamically generating audio, collectively persuaded me that I haven’t done any mad Javascript hacking for far too long. My response to this state of affairs is JSModPlayer, a player for .MOD music files (the mainstay of Amiga and PC sample-based music circa 1990).

So far it only implements a subset of the possible sample effects, and it demands a very fast Javascript engine – luckily all the new breed of browsers are pretty competitive at that now. Even so, unless your CPU is an absolute behemoth, it’ll probably struggle to keep up – the audio output is fixed at 44100Hz, and that’s rather a lot of numbers for Javascript to crunch, especially when the MOD file gets up to 16 or more channels. Which, amusingly enough, is exactly the situation we had back when we were using Gravis Ultrasounds on 386es. Hurrah for progress!

Update 2010-06-08: Oops. In the process of testing how Safari 5 shapes up, I discovered a rather silly oversight: the audio buffering routine was set up to never use more than 10% of CPU. Now that I’ve fixed it, it turns out that Chrome and Safari (at least) have no trouble at all playing Jugi’s Dope theme in its 28-channel glory. (However, taking the brakes off the buffering does mean that we can’t reliably pause the audio any more. A small price to pay, I think you’ll agree.)

DivIDEo v0.2.0 – video converters for the masses

Tuesday, May 18th, 2010

I’ve rewritten the DivIDEo converter app in pure C, and as a result it’s now available in friendly standalone Windows and Mac OS X command line executables (and slightly less crazy and Ruby-ish to compile for other platforms). All the necessary libraries (including a major chunk of ffmpeg) are compiled in, so now there’s nothing standing between you and full-on ZX Spectrum video converting action. Head over to the DivIDEo website for the downloads.

Incidentally, a couple of people have asked about the identity of the singer in the Outline presentation. Apparently, while that clip is what we sneeringly refer to as an “internet phenomenon”, it’s not quite reached 100% saturation, so: it is Edward Anatolevich Hill, with a Russian TV performance of the song “I am very glad, because I’m finally back home”, or as it’s becoming increasingly better known, Trololololo.

DivIDEo – Spectrum streaming video

Monday, May 3rd, 2010

Six years after my first tentative attempts at streaming video from the DivIDE interface were presented at Notcon 2004, I’ve finally come up with a system that I’m happy with. It boasts 25fps playback with audio somewhere above the ‘nails in a vacuum cleaner’ quality of previous attempts (through the use of delta compression on the video data and variable bitrate audio to use up whatever processor time is left), a one-shot conversion utility that handles all the video decoding, rendering and re-packing, and a player routine that more or less respects the ATA spec (so won’t fall apart as soon as someone else tries it on a different CompactFlash card. Hopefully). Here’s how I presented it at the Outline demo party:

The full description, and a whole bunch of downloads, is on the DivIDEo project website.

JSSpeccy v20091121

Saturday, November 21st, 2009

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!

Midibeep

Thursday, October 29th, 2009

Last week I posted possibly the most tedious Basic type-in listing ever to World Of Spectrum:

5 BEEP 0.212765, 20; 10 BEEP 0.106383,19...
(continues for approx 1500 more lines)

Anyone typing it in in its entirety would be rewarded with this:

Download midibeep_minute_waltz.mp3

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:

Update 2010-05-26: Karl McNeil has adapted Midibeep into a variant called Mid2ASM, which outputs an assembler listing rather than Basic – this enables the data to be packed much more efficiently, paving the way for altogether longer pieces of music. Download Mid2ASM (453K, Windows EXE included)

Update 2010-06-02: Another update from Karl, featuring a Windows GUI, more space-saving tweaks, and embedding the output in a Basic REM statement. Download Mid2ASM v2 (3.4Mb)

JSSpeccy v20090929 (Don’t-Mess-With-Geeks Edition)

Tuesday, September 29th, 2009

I 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, 2009

A 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.

Download gasman_-_snakebite.mp3

JSSpeccy: A ZX Spectrum emulator in Javascript

Sunday, October 19th, 2008

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.

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.

(more…)