Alex Kidd Pico
Part 3:
Code & Music limitations

Pico-8's built in retro limitations even extend to the code storage, and the sound storage.

Code: Token count

Staying under the token count was a fun challenge. It certainly makes you find simpler ways of achieving the same thing, which is always good. Although this arbitrary limitation imposed by Pico 8 seems strange in todays world of gigabytes of RAM to work with, the problem solving you go through will be good experience for solving real optimisation problems on modern systems.

Screenshot

Compressed code limitation

Having said that, the “compressed code limit” in Pico 8 is rather strange. I found it odd that the manual states that you will run into the token limit before the compressed code limit. For the whole project, I found the inverse to be the case. At about 7k tokens I was at 30k compressed bytes, and it wanted 15k. Even with all the text in the game removed it barely made a dint. I already use single letter variable names for frequently used variables, and I tried replacing function names and variable names with shorter versions of themselves and realised very quickly this wasn't going anywhere.

It's a shame because in my search for “compression limit” on the forums, I've seen examples of very interesting projects (such as an RPG in the style of the original Ultima) that were abandoned due to the developer becoming disheartened that they'd never overcome this compression limit, and no word from Zep on the matter in any of the examples I saw. Here is someone else ranting about it and someone pointing out that it causes ugly & difficult to read code, since length of variable names affect the compressed code limit. And another more recent rant that I just stumbled across.

It was only when I tried out PicoTool that I finally overcame this hurdle. Although you end up with an unreadable mess, so you want to edit it yourself, the pre-PicoTool, un-garbled code is here. But that is exactly at the token limit! No room for edits... so I've also provided this slightly earlier version, which gives you a bit of breathing room if you want to experiment, it's missing some tweaks that the final game has, which are bug fixes and extra minor features like the level intro. The final program has the token count maxed, and is about 25k compressed bytes, before running through PicoTool, which brings it down to 9k.

Cramming in all the music!

I started out replicating the music note for note. I used my MIDI USB keyboard and OpenMPT to rough it out (was easier) and then transposed the notes into Pico8. But to achieve the mulitiple harmonies, you use a new "sound effect" in the sound effect index for each instrument track, and I very quickly ran out of sound effect indexes.

So I did what other music developers did back in the day and use the arpeggio effect (the trilling notes you hear) which switch between 2 notes rapidly to give the impression of 2 notes being played at the same time. Pico-8's music tracker has a built in effect for this, like all good music trackers of the time, though it's got some strange limitations. Using this arpeggio trick, I came up with simpler versions of songs with less simultaneous notes (some are just a drum track and a melody!) and in the end, used far less sound effect indexes and was able to cram in all of the songs I wanted to - a total of 7, listed below. As you can see, every last sound index was used, I maxed it out, like the token count.

Music patterns:
00: Main theme
06: Death
07: Water theme
23: Bike theme
27: Janken game
31: Heli theme
33: Castle theme
39: Game over

Sound effect indexes:
00: Jump
01: Punch
02: Main theme: Bass Intro
03: Main theme: Melody Intro
04: Main theme: Bass 1
05: Main theme: Melody 1
06: Main theme: Bass 2
07: Main theme: Melody 2
08: Main theme: Base 3
09: Main theme: Melody 3
10: Main theme: Base 4
11: Main theme: Melody 5
12: Main theme: Percussion 1
13: Main theme: Percussion 2
14: Main theme: Percussion 3
15: Shoot
16: Block break
17: Coin
18: Game Over
19: Castle Theme: Melody 1
20: Castle Theme: Melody 2
21: Monster death
22: Angel: Melody
23: Angel: Harmony
24: Water hit
25: Water hit bass
26: Powerup pickup: Melody
27: Powerup pickup: Harmony
28: Laser Ring
29: Water theme: Bass 1
30: Water theme: Bass 2
31: Water theme: Bass 3
32: Water theme: Bass 4
33: Water theme: Melody 1
34: Water theme: Melody 2
35: Castle Theme: Melody 3
36: Castle Theme: Melody 4
37: Water theme: Melody 3
38: Water theme: Melody 4
39: Castle Theme: Melody 5
40: Pedicopter theme: Bass 1
41: Water theme: Solo 1
42: Water theme: Solo 2
43: Water theme: Solo 3
44: Water theme: Solo 4
45: Water theme: Solo 5
46: Water theme: Solo 6
47: Frog bubbles
48: Water theme: Percussion loop
49: Bike theme: Melody 1
50: Bike theme: Bass 1
51: Pedicopter theme: Bass 2
52: Bike theme: Melody 2
53: Janken match theme: Percussion 1
54: Bike theme: Bass 2
55: Bike theme: Melody 3
56: Janken match theme: Melody 3
57: Bike theme: Bass 3
58: ?? Percussion?
59: Janken match theme: Melody 1
60: Janken match theme: Melody 2
61: Castle theme: Percussion loop
62: Pedicopter theme: Melody 1
63: Pedicopter theme: Melody 2

You can compare the difference if you listen to this early version of the game, which has the first level and water level music, pretty much sounding as they do in the original game (don't play past the water level, it will crash because there's nothing else), and compare it to the music in the final release, by listening to it in this Alex Kidd in Pico World playthrough, where I used arpeggios to simulate harmonies, to cut down space requirements.

That's all folks!

If you like this sort of thing, join the discord and/or subcribe to the newsletter, and I'll let you know when I upload more articles like this. I also have a Discord server where we can chat about game dev.

Discord Contact