constant companion: shorten your tweetcart constants!

Published 2023-06-12


This is a niche tool to help you save characters when writing carts that are codesize-constrained.

Example: 0x6000 can be written as 0x6000 (6 chars), 24576 (5 chars), 6^13 (4 chars) or βŒ‚-🐱 (3 chars!)

The tool sorts the results by character count (on twitter), so the top results are your best bet.

Update: The latest versions of pico8 havespecial P8SCII codes for pokingwhich are often fewer characters than calling poke directly (even after using this tool). e.g. ?"\^!5f10249?" instead of poke(0x5f10,50,52,57,63). Consider using that instead! But this tool might still be useful sometimes, and at the very least, it's an interesting artifact.

While I was making Free Cell 1K (itch | twitter | bbs) for the #Pico1K jam, I realized I could save characters by taking advantage of the built-in constants. I needed to poke a few things to various addresses (for setting the palette, drawing dynamic shadows with bitplanes, and enabling the mouse) so I had code that looked like this:

Each of those poke addresses uses 6 characters; we can do better! The first thing I did to save characters was this:

But then I saw @zep tweet a trick for writing sqrt(x) as x^β–ˆ instead (because β–ˆ (shift+A) is defined to have a value of 0.5), and I realized I could do even better: the 😐 (shift+M) character is defined to have a value of -24351.5, so I did this:

95 chars is not an improvement... yet! However, poke() ignores fractional addresses, so those .5s aren't necessary. Also, I was able to combine the 0x5F5C and 0x5F5E pokes into a single poke, which nullifies some of the relative advantage of the A=24365 technique. In the end, this was the shortest code I could find:

This saves 2 characters over the equivalent version that uses A=24365 instead of the moon face. (or maybe just 1 character, if the newline after q=poke2 can't be removed)

I didn't! I wrote a program to brute-force try all the built-in symbols and see if any were useful for my needs. Check out tab 5 of the cart ("analysis") to see the brute-force algorithm I used.

I've cleaned that program up and posted it here for you. It might be less useful for tweetcarts (because stuff like 😐 takes up 2 characters on twitter) but it saved me 1~2 entire characters (genuinely very helpful!) during the Pico1K jam, and I hope it helps you too.

Leave a message here or tag me on twitter if you found it useful; I'd like to see what you make!