Undeveloper
Retcon

Learn how computers work by building a retro game console

main menu

GORILLAS.BAS

(bananas + physics) x explosions = fun!

GORILLAS.BAS

One of my earliest memories of turning my hand to computer programming was as a very small child — exactly how young I was I don’t actually remember — at a family friend’s house methodically typing in lines of BASIC code into a ZX Spectrum. I still have that code in an original copy of the wonderful orange user manual that came with the Spectrum:

10 REM Guess the number
20 INPUT a: CLS
30 INPUT "Guess the number", b
40 IF b=a THEN PRINT "That is correct": STOP
50 IF b<a THEN PRINT "That is too small, try again"
60 IF b>a THEN PRINT "That is too big, try again"
70 GO TO 30

My Spectrum programming career didn’t go much further than that, but some years later when I got access to a PC, one of the things that I was obsessed with for a while was writing programs in QBasicopen_in_new — another variant of BASIC developed by Microsoft in the very early 1990s. QBasic came for free with MS-DOS, and provided a full IDE (text editor) and integrated debugger which, for the time, was pretty incredible. Also, QBasic came with two example programs: NIBBLES.BAS and GORILLAS.BAS.

Nibbles was kind of fun — another in a seemingly infinite series of Blockadeopen_in_new clones which were pretty ubiquitous at the time — but Gorillas was something different. A one or two player game, the original Gorillas saw two onscreen gorillas hurling explosive bananas at each other over a cityscape. The bananas were directed not by timed button press as in most arcade games, but by using the keyboard to type in the angle and velocity and using realistic projectile motion to plot the path of the banana through the air. You could even change the gravitational constant at the beginning of the game to provide an answer to the much-asked question of: “What would happen if two absolutely enormous gorillas were sat on top of buildings throwing huge explosive bananas at each other...but on the surface of Mars?”

Here's a video of the original GORILLAS.BAS gameplay in all its gloryopen_in_new.

Part of the reason I slog away at the Retcon project is that I fell in love with an online community I started following over the Covid pandemic — SMSPower!open_in_new Maybe it’s something about Sega enthusiasts in particular, maybe it’s the general demographic factor of retro gaming fans being that little bit mellower or maybe it’s the calming blue colour scheme. Whatever it is, the SMSPower! community are probably some of the loveliest people on the internet. I think being part of communities that make you feel welcomed is important, and it’s also nice to give something back, so for the last two years I’ve decided to take some time out of “serious” work and join in with the festivities in SMSPower!’s annual coding competition which runs in March. Actually there are three annual competitions — coding, ROM hacking and music making — but I don’t have enough interest in hacking, nor enough patience for music making so I guess we know what’s left.

In 2022 I very quickly knocked up a clone of Wordle (hey, remember Wordle!?) that I called “Segle”, written in (very, very bad) Z80 assembler. This year, inspired by some chat on the forums, I decided to push the boat a lot further out and come up with my homage to GORILLAS.BAS — “Primates”.

I wrote Primates in the C programming language, which I’m very comfortable using, mostly to try out a project called devkitSMSopen_in_new from the legendary "sverx". devkitSMS is essentially a nice small and productive C library written for the cool open source SDCC compileropen_in_new which targets the Z80 amongst other CPUs.

Writing with devkitSMS was pretty dreamy — sverx has really taken the time to make the API very intuitive and I think it’s a great way to get into Master System development if you come from a C background or if you’re a beginner who has struggled to get your head around assembler. Naturally I had concerns about performance, in particular with the physics of banana tossing, but with a few pokes and prods the game turned out very playable at a full frame rate of 60fps.

Primates pretty much clones the gameplay of GORILLAS.BAS as is, making some allowances for use of a control pad rather than a keyboard, and also for the smaller screen resolution of the Master System. But, not content with a straight clone, I also managed to squeeze in the outrageous “Arcade Mode” which sees both gorillas able to throw bananas at each other in “real time” (rather than taking turns) and also gives the graphics a little gussy up.

At some point I'm going to make a full video all about Primates, but for now please enjoy this capture kindly made by Sega Zone demonstrating the Arcade Mode:

 

One of the things I find most enjoyable about the coding competitions is the opportunity to create some unique cover art. For those who remember the original Master System boxes, they employed this rather strange line art style which, objectively, tended to look pretty awful. With Primates I decided to run with the line art idea, but to make it a little more stylised and abstract, and this is what I came up with. I'll leave the judgements to you.

Box art of Primates - on the right hand side is a stylised graphic of a peeled banana. On the left is some text and screenshots

You can download the source code for Primates from github hereopen_in_new or ROM builds hereopen_in_new. Bear in mind that I was writing this against a deadline so there's a lot of tidying up I didn't get time to do and it might not be the best example of code to base your own work on!

Primates runs fine on Emuliciousopen_in_new and (I’m told!) on real SMS hardware and, of course, on the Retcon SMS build.

To see more Primates in action, and to see reviews of the other entries to this year’s SMSPower! coding competition, check out Dudley of Yesterzine’s review videoopen_in_new.