How I Wrote a Book for the ZX Spectrum

I recently released a book on cassette for the ZX Spectrum. It's fair to say that this is something of an experiment, but it's been a fun one.

The actual story itself has its roots in the brief period when Amazon experimented with partwork releases for the Kindle. It got me thinking about writing something episodic for it, but by the time I'd finished it was clear that Amazon's partwork releases had also been something of an experiment, so I shelved it and focused on my next regularly structured novel.

I thought it would be good to write a bit here about how I ended up releasing it on cassette for an obsolete home computer. It may come as a surprise to learn that neither mental breakdown nor drugs were involved.

At the time I wrote The Gang of Four Ride Again, I was brushing up on object-oriented programming design patterns for professional reasons. There's a famous (famous in software engineering circles anyway) book on the subject called Design Patterns: Elements of Reusable Object-oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. They are known colloquially as the Gang of Four, and it struck me as funny that there are a bunch of other Gang of Fours out there. It's become a lazy shorthand for any group of four people across many different fields. I also thought it would be fun to try to write a short story based on each design pattern in said book. The latter proved to be too ambitious, so I loosely took some of the concepts and applied them to a simulated world in which you, the reader are trapped, helplessly watching another Gang of Four blunder their way through a series of misfortunes.

It was fun to write. The characters are fairly broad and fit into a crime-fighting gang archetype. There's John Steel, de facto leader and slab of beef / family man. There's Stacked Tracey, who is dissatisfied with her role in all this and desperately trying to get her name changed. Then there is the Professor, the dapper gent who is supposed to be the brains of the operation. To this end he is aided by the fourth member of the gang, Zed. Zed is, for reasons unknown, a ZX Spectrum home computer. He can talk but other than that he's just so many rubber keys on a flat black block.

Late last year I decided to publish the book through Amazon, but I also wanted to do something else with it. After some consideration the existence of Zed was too much to deny and I decided it would be very entertaining to release the book on the Spectrum. On cassette.

There were a number of challenges along the way, the chief one being that I'd never written anything on a ZX Spectrum. Back in the day I had a Commodore 64. However I do programme computers for a living and one language is much like another, especially when it comes to BASIC. 

I quickly realised that mere BASIC wasn't going to cut it, but I also didn't want to have to write the thing in assembly language, so I looked to see whether anyone had written a BASIC compiler for the Spectrum. Now, this is where writing for a very old computer that still has enthusiasts worked in my favour. Not only was there a BASIC compiler, there were also many useful tools that made this a much more feasible project.

The first real technical challenge was the size of the book. At ~48,000 words, it's short for a novel but long for the mere 48K of RAM available on a Spectrum. That 48K had to hold the programme that displays the book's contents as well as the book itself. After much calculating and fiddling around it became apparent that it simply wouldn't fit, even with compression. Well, technically it could fit if the whole thing were compressed using something like LZ compression, but then there wouldn't be enough RAM left to decompress it into and it would also take forever.

I settled on token substitution based on a frequency analysis of the words in each chunk of the book. Frustratingly, this was not enough to have each episode of the book be a chunk, so in the end I settled on eight chunks in a trade-off with tape loading time.

All the code for compressing the chunks and mapping tokens was written in Python, mostly by Copilot, which did a decent job and let me focus on the Spectrum end of things. That was written in Boriel BASIC, a strongly typed alternative to Sinclair BASIC which can be compiled before running. It was a pretty good experience and let me write a UI that could decompress the book's chunks on a page-by-page basis quickly enough.

With the book itself functional, I turned my attention to any bells and whistles I could add. The most obvious was a loading screen. For this I used Image Spectrumizer, a brilliant piece of software that lets you take any image, preview how it would look reduced to a Spectrum's resolution and palette, and tweak various parameters until you have it looking how you want. I used the ASCII duck from the paperback's cover as the input and came up with something that looks suitably Spectrumized.

Music was something was something I wasn't sure about. The Spectrum is notorious for producing angry bleeps in the place of anything usually considered music, and getting anything more than some crude beeps was technically daunting. However it turns out I needn't have worried, because once again a stranger on the internet has come through for me, this time in the shape of Beepola. Beepola is an old-fashioned music tracker that outputs via a variety of different methods. It also very conveniently outputs as an addressable block of code so all actually needed to do was load it into memory and call it via a system call in my Boriel code. I knocked up a suitably repetitive tune and selected the most 8-bitty sounding output from the selection. The music only plays on the loading screen once loaded - I thought it would be a bit much while reading.

While I was doing all this, I was using the Spectaculator Spectrum emulator to run the code and check everything was working. It's great, and if you want to read the book on a Spectrum but don't one, I can't recommend this highly enough. The Gang of Four Ride Again is also available as a download for use on an emulator via eBay for a mere £3.

Eventually I was done, and it was time to make a tape and test it on an actual Spectrum. I picked a working one up from eBay (they aren't particularly expensive) and used zxtap2wav to create a .wav file from my compiled code. I burned this to CD and recorded it cassette using an Aiwa AD-F640, which is very much overkill for recording a tape for a Spectrum.

At that point I was almost ready for duplication, but I had also been working on a short piece of musical fluff to fill up some empty space on the B-side of the cassette. This was called Fred Does the Dishes and features samples of the legendary Fred Harris from the BBC2 series Micro Live. I made it using Ableton Lite and it probably shows, but it's fun.

Finally, a friend who runs a record label recommended Band CDs to me for cassette duplication. I designed the inlay card and stickers for the cassette shell based on my paperback cover and ordered 20. I'm very pleased with the way they turned out, and maybe you would be too? They are available to buy on eBay, priced at a reasonable £10 including UK delivery.

 

BUT WAIT! THERE'S ALSO A PAPERBACK

If you prefer the more traditional feel of an actual book, then good news! The Gang of Four Ride Again is also available as a paperback on Amazon, where it costs £9.99 in the UK. It is also available internationally where prices are set by Amazon based on conversion rates:

https://www.amazon.co.uk/Gang-Four-Ride-Again-adventure/dp/B0GQGR9J97/ref=tmm_pap_swatch_0

https://www.amazon.com/Gang-Four-Ride-Again-adventure/dp/B0GQGR9J97/ref=tmm_pap_swatch_0

It is also available as a DRM free  eBook (ePub or PDF) on Amazon for £2.99:

https://www.amazon.co.uk/Gang-Four-Ride-Again-adventure-ebook/dp/B0GQCTLDL5/ref=tmm_kin_swatch_0

https://www.amazon.com/Gang-Four-Ride-Again-adventure-ebook/dp/B0GQCTLDL5/ref=tmm_kin_swatch_0

I hope you enjoy The Gang of Four Ride Again in whichever format you select.


 


No comments:

Post a Comment

How I Wrote a Book for the ZX Spectrum

I recently released a book on cassette for the ZX Spectrum. It's fair to say that this is something of an experiment, but it's been ...