Home For Fiction – Blog

for thinking people


June 13, 2022

My 48K Challenge: A Programming Lesson on Creativity

Programming, Society

creativity, javascript, nostalgia, patience, programming, society, video games

There are all sorts of asinine challenges in the ocean of mediocrity that is social media, and let me assure you, this isn’t one of them. My “48K challenge” is something I came up with when I noticed something disturbing on my “smart” phone: The size of the calculator app is 8MB. That of the alarm clock is 19MB. And my personal favorite, the messages app (just SMS, that is) is a whooping 204MB.

Are these people serious?

When I was a kid, you could pack an entire video game in 48KB. In other words, the space the calculator app requires is the equivalent of more than 165 video games for the ZX Spectrum – my first computer.

It goes without saying that technology has advanced a lot; the games of the 80s can’t be technically compared to those we have today. And yet, it feels programming has become sloppy.

I’m of course generalizing, but it feels as if the more the resources we have, the less the creativity and the greater our laziness. It all leads to resource hogs that take too much space and are often buggy. Because, hey, let’s all keep updating all the time.

And so, I gave myself what I termed the 48K challenge. I decided to make a retro-style video game in JavaScript, that had to be 48KB or less. The results were intriguing and revealing – and a little bit disappointing, but not in the way you imagine.

48k challenge
Here’s a screenshot from the result of my 48K challenge. The acuity of the image is deliberately low. I coded the program in 256×192 pixels (the native ZX Spectrum resolution) which I then quadrupled, to emulate the loss of acuity when projected on a TV, as we did in the 80s monitor.

My 48K Challenge: Setup

The first thing I decided coming up with the setup of my 48K challenge was that it couldn’t be a text adventure game. That would’ve been way too easy, for obvious reasons. It would also take too much time that would be writing time, rather than coding time. To put it simply, I didn’t want to spend hours and hours just writing a fantasy novella.

One of my favorite childhood games was Basket Master – which was fairly difficult, may I add – so I opted for something in the same topic. For simplicity’s sake (my goal was not to make a “real” game, only a proof of concept sort of thing), I only kept the basketball theme and thought to simply make a one-player shooting game. I decided to… casually name the program “Casual Hoops”.

The… Challenges of a 48K Challenge

It became very obvious early on that I couldn’t rely on any external libraries. The p5.js library that I often use – for instance, check Planet Generator or Text to Art – is something like 600KB in size. That’s more than 10 times my self-imposed limit.

Therefore, I realized I needed to do everything from scratch. Of course, for such a simple implementation, that’s more than fine. But let’s not fool ourselves: Making anything remotely complex (in terms of graphics or gameplay) would require some coding wizardry to fit in 48KB. The… challenge was a bit biased, in other words.

More still, there’s another element worth talking about: That nowadays, programming doesn’t exist in a vacuum.

home for fiction

The Ecosystem of Programs

The vast majority of video games of the 80s were made in ways that, shall we say, were a bit more complex than your usual console.log("Hello World"); – the process involved machine code or assembly, and all sorts of other things, far less transparent than simple JavaScript.

The full details greatly exceed the scope of this post, but if you’re interested, take a look at this interesting thread. And if you really want to have a laugh, check out what “Hello World” in Spectrum assembly really involved!

What you had was basically a program than ran on a bare-bones firmware. I mean, ZX Spectrum didn’t exactly have an operating system, like Windows or Linux. It had a simple Sinclair Basic interpreter stored in ROM (which wasn’t suitable for any serious program), and the rest was made with machine code or assembly instructions – that is, commands had to be issued directly to the processor.

So, in this context, where there was no internet, no browser, basically no operating system, you had to tell the processor to do the stuff you wanted it to do, and fit it in 48KB.

Things have changed since then.

What Is a “Program” Today?

Believe it or not, I never consciously pondered on such things until I began this 48K challenge. But in the process, I realized something: It was impossible for me to realistically emulate the experience of fitting a game in 48KB. The reason?

That a program today – at least the way I made it – is not a clearly separate, individual entity. I used an existing language, JavaScript, to make it. It runs in a browser. The browser relies on an operating system.

There are just too many crutches there, it’s just too easy. I was a bit disappointed when I realized that.

I mean, here’s a very simple example of creating a timer. Even if you can’t read JavaScript, I’m sure you can follow. That’s the whole point of how easy it is:

function theTimer() {
	var counter = 30;
	var countdown = setInterval(function () {
		counter--;
		if (counter ==0) {
			clearInterval(countdown);
			gameOver();
		}
	}, 1000);
}

Let’s face it, I don’t even want to imagine how much more complex this would be with machine code on an original ZX Spectrum.

My 48K Challenge: Aftermath

I have to be honest: I began this 48K challenge motivated, but I lost some of this motivation when I realized it was far easier than I thought. Alas, machine code is not something I’m familiar with, so that I could try a more authentic emulation.

In the end, the total size of this very simple game turned out to be 12KB – without minification or anything of the sort to reduce size further. If you absolutely want to try it, feel free (click inside the frame for the buttons to be registered properly; obviously enough, it doesn’t work on mobile devices). If you’re looking for the source code, get it on GitHub.

Click to run the program

Nonetheless, there was also a silver lining in this entire process: I realized my initial approach was justified. We can do better, if we’re creative. No, an alarm clock app doesn’t need to be 20MB in size.

I mean, if you could fit a game like Rainbow Islands in 128KB, I’m sure we can do better!

Click to display the embedded YouTube video

facade placeholder