Small really is beautiful

I read a lot of stuff on Medium.com, there’s always plenty of articles to waste a full lunch-time on. Today’s lunch went on an article about building a self-contained game in c# in under 8k!

Yep, pretty impressive for a game, even though it is only a clone of the Snake game that made the Nokia phones so popular. However, it’s impressive because it’s in C# and the extent Michal StrehovskĆ½ went to in removing bits of the executable, not because its 8K. I’m using C# daily and rarely pay any attention to the size of the executables I produce. So, much kudos and respect to the author for picking apart the rubbish that MS puts into those fat, lard-assed .net executables!

A long time ago when I was in the games industry doing arcade conversions to home computers, there use to be a competition for writing games and demo’s with sizes less than 4K. The game competitions were limited to ~2K and the demos were limited to ~4K, this was pre-interweb days.

Because I was working in a game company we wrote everything from scratch in 100% assembly language, no libraries or anything else to help us out. So for a bit of fun, we reduced that game size limit from 2K to 256 bytes just to see what we could come up with! Most of our games at the time were 48k (for the ZX Spectrum) to 512k for the Commodore Amiga / Atari ST, so still tiny by today’s application sizes, but cramming a game with all the rendering and logic into 256 bytes would be a Jedi master level challenge!

I wrote a Space Invaders clone and a Pacman clone. One of the other guys wrote a Scramble clone, but I no longer have the code or executable for that.

Here’s the file size on disk for Space Invaders. 3 bytes under budget!

And a screen capture of the actual game running. This is captured with DOSBox since Windows10 doesn’t run .COM files.

And here’s the file size of pacman :

Looks like its 278 Bytes šŸ™ 22 bytes over budget, but I’ll not lose sleep over that one.

The maze data is a bit pattern crammed into 16 bytes! These bits are then reflected horizontally and vertically to create the symmetrical maze, the code to render the maze is about 38 bytes.

The games are functional, you can clear all the invaders to win, or if the invaders reach the bottom of the screen it’s game over. With Pacman all the dots are edible, and the ghosts can catch you. The ghosts also follow the maze randomly. Neither application totals up the score, that was another 12 bytes I wasn’t willing to spend.

We were pretty pleased with ourselves, giving each other massive pats on the back thinking we were such smart asses (come on, we were young!). Until some other ultra smart ass produced a 256-byte defender clone in Mode10 Graphics (320×200 pixel mode) with parallax star fields, scores and aliens. We all wanted to drown ourselves in a pool of our own tears. Lesson learned. Pride Swallowed.

Theres always a bigger fish.

Me. Swimming in a salty pool of my own tears. Back in 1990.

All this was at least 16 years ago ( I think that’s the time I copied the files to one of my previous PC’s, not the date they were written ), and now a simple HelloWorld app is measured in megabytes! Even though ram is infinite and CPU cycles are free, I still can’t shake the habit of thinking about the size and speed in every line of code I write, be that in C#, GO, or Elixir. Worrying about branches taken vs not taken and CPU pipeline stalls aren’t really a thing anymore but it will always be printed on my brain somewhere in indelible ink. I’m still having nightmares about parallax starfields. Thinking about these things is still useful for IoT or embedded RTOS work, but those opportunities don’t seem to pay as well as making pretty web pages using languages created by 7-year-olds.

If you’re masochistic enough to want to try writing apps that are all about speed and size, check out Steve Gibson Research. There’s still something elegant about writing entire applications in 10s of kilobytes. I think it’s a lost art, and Steve really is one of the masters.

I don’t think there’s a better intro to this alternate universe than Steves Small Is Beautiful Starter Kit.

Have a go and let me know if you produce anything truly tiny. And by tiny I mean less than 8k!

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.