Compiling QuickBASIC's Gorillas on Linux... surprisingly tricky
Even with QB64 and FreeBASIC, compiling the classic GORILLA.BAS is not easy... but it works!
Want to skip the details and the story and simply download the tweaked source code for GORILLA.BAS along with a Linux binary? Head over to Lunduke.Itch.Io and download like the wind.
“QBasic Gorillas” is one of the most recognizable “programming example games” out there. It is absolutely iconic.
Every kid that played around with QuickBASIC had a copy of GORILLA.BAS. A simple game where two gorilla’s toss explosive bananas at each other while standing on the tops of buildings. Set the Angle, set the Power… toss the boom boom.
Think “Worms” or “Scorched Earth”. Except simpler. With Gorillas.
Just one teensy tiny little problem… we don’t have a Linux native version of QuickBASIC to run GORILLA.BAS.
Luckily we do have two “QB” compatible compilers that are Linux native: FreeBASIC and QB64. So I do what any red blooded nerd would do… I grab FreeBASIC and do a quick:
fbc -lang qb gorilla.bas
(That "-lang qb" tells the FreeBASIC compiler to use the "QuickBASIC" language mode)
Whooooooo, doggy. Yikes. After a bit of investigating… turns out the “Quick Basic” language mode of FreeBASIC is only mostly QBASIC compatible. So many errors.
Ok. Way too much work to make this thing compile in FreeBASIC. At least for how lazy I’m feeling. Let’s try QB64.
Hey! Only one error! I’ll take that!
And, turns out it’s a super simple error. “DEF” is an old-school QBasic way of defining a function. QB64 doesn’t support the “DEF” statement. And there’s only one of those in GORILLA.BAS. No biggy.
Looks like that “FnRan” function is super duper simple. Let’s just comment it out and recreate it as a dedicated function.
Boom. Save. Run.
BOOOYA!
The classic “QBasic GORILLAS” intro screen! Sound even works! Huzzah!
So far so good. Setting the game up. Let’s “View Intro” just for the heck of it!
Shazam! Works like a charm!
…
Wait a sec. The monkey’s aren’t moving. (Gorilla’s… whatever.)
They’re supposed to move their arms up and down. But nobody’s moving. And we’re just stuck on this screen. No way to leave.
Dangit. Time to do a little digging.
There’s the problem!
The “Rest” subroutine. Basically pauses suspension of the program for a set amount of time using a timer and a little math.
You know what… let’s just nuke it.
Boom! Commented out entirely! Now it does absolutely nothing!
Because… why not? When in doubt… comment out!
Let’s see what happens!
Theeere we go! The game plays!
Only the explosive bananas fly so fast you can’t see ‘em. And all animations play way too fast too. Kinda makes it hard to play with the bananas traveling faster than the speed of light.
Ok. So maaaaaybe that Rest() function actually should do something.
At first I added in a SLEEP command (as QB64 supports that)… but SLEEP does a regular delay for times of 1 second or higher… but times less than 1 second simply pause the execution indefinitely until a key is pressed. And almost all of the “Rest”s are a fraction of a second.
When I did this I needed to hit the spacebar continuously to advance animations forward. Which is kinda cool. But not great.
Luckily QB64 provides a “_DELAY” that works perfectly! Check that out! Full drop in replacement for the entire Rest() functionl.
We now have a working GORILLA.BAS on Linux! With sound and everything!
You can grab the tweaked source code for GORILLA.BAS along with a Linux binary over on Lunduke.Itch.Io.
Subscribing to The Lunduke Journal is simply a wonderful thing to do. With oh so many perks (like free eBooks). Plus you support stuff like this. Which you really want to do.
You are truly doing the Lord's work here! DOS, QBasic, DesqView, and EMM386 will live forever as long as we keep them in our hearts and minds--and you're reminding us of the goodness that they were, and are!