Blog.

Coding with a ZX Spectrum with VS Code - Part 1

Cover Image for Coding with a ZX Spectrum with VS Code - Part 1

So, being a geek interested in retro gaming, I've always fancied trying my hand at coding an old 8-bit game. The idea that you can create a piece of entertainment with such limited resources always made me want to try it. I consider myself a fairly bright chap, but the idea of coding in assembly or machine guide just beguiles me, and even basic seemed to be a bit of a leap. Still, If I'm going to try anything, I may as well start with some Basic.

So I dusted off my old spectrum and try to type in my first ever program that I learned to code:

10 PRINT "HELLO FROM JAMES"
20 GO TO 10
RUN

Christ, that was hard work. Have you ever tried to type in one of these?

It's nigh on impossible. Those little spongy keys that, while iconic and retro looking, are just utter rubbish to type on.

But hey, there are emulators, let's try that. There are emulators for the Mac such as Fuse (https://fuse-for-macosx.sourceforge.io/) and even JavaScript-based ones like JssSpeccy (https://jsspeccy.zxdemo.org/) that you can try on, but then I realised that even then, editing a spectrum Basic screen and trying to save it through some clunky tape recording was going to be hard work too. I thought to myself, there has to be a better way!

And there is! We can use a VS Code combination to save basic *.bas files. We even have a plugin called ZX Basic (https://marketplace.visualstudio.com/items?itemName=jsjlogin.zxbasic), which is an extension that helps us format and check the basic file format. Ok, so far so good. But how do we get a bas file from a pc onto the spectrum? The secret sauce is the Boriel ZX Basic compiler (https://www.boriel.com/pages/the-zx-basic-compiler.html) which is based in Python. It can turn a basic *.bas file into a spectrum tape, all compiled and read to go as a bin, tzx or tap file and in machine code. Yes, it can take that slow-as-heck basic and turn it into something fast and wondrous. OK, there is more to being a spectrum programmer than writing in basic, but needless to say, I'm excited about what I can achieve.

The great thing about using the ZX Basic extension for vs code is that not only do you get code syntax highlighting and auto-complete, but also it has support for the Boriel extended basic language so that you can actually do a lot more with basic code than you can do with ordinally basic. This means I can possibly hook into more powerful commands and really leverage that machine code power! Or at least that's the theory.

So far, I have created this example hosted in Vercel (https://spectrum-game-eight.vercel.app/) and this is the source code (https://github.com/jayjaybeeuk/spectrum-game). I'm hoping to add some more interesting games to this stack, but for 30 mins to set up a quick pipeline it was relatively easy. In my next article, I'll go into more detail about how I set up the pipeline.

I have to give thanks to this article (https://richhewlett.com/2021/06/12/coding-in-spectrum-basic-again/) which led me down this path of discovery!


More Stories

Cover Image for My first Arduino project

My first Arduino project

My first go at a simple circuit.

Cover Image for Modern Frontends Live 17-18th Nov 2022

Modern Frontends Live 17-18th Nov 2022

Modern Frontends Live talks about the Web, Web apps, Native apps as well as all THE FRAMEWORKS, LIBRARIES, BROWSERS, TOOLS, PLATFORMS, DATABASES, APIs and EVERYTHING ELSE that powers them up behind the scenes! Sorry about the shouting, but that’s how they sell the conference in the blurb. Will all the speakers scheduled on the website, once couldn't help but be initially ...