This is a niche tool to help you save characters when writing carts that are codesize-constrained.
- type in a number; press enter
- then press up/down and ctrl-c/enter to copy a code
- navigate back up (or press backspace) to start typing a new number
Example: 0x6000 can be written as 0x6000 (6 chars), 24576 (5 chars), 6^13 (4 chars) or ⌂-🐱 (3 chars!)
The tool isn't too smart, but it sorts the results by character count, so the top results are your best bet.
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:
-- 94 chars (not including comments or newlines) poke(0x5F10,8,1,251,7,4,0,3,15) --palette poke(0x5F2D,3) --mouse poke(0x5F5C,-1) --disable btnp repeat poke(0x5F5E,0xF4) --shadows on poke(0x5F5E,0xFF) --shadows off
Each of those poke addresses uses 6 characters; we can do better! The first thing I did to save characters was this:
-- 84 chars (not including comments or newlines) A=24365 poke(A-78,8,1,251,7,4,0,3,15) poke(A-49,3) poke(A-2,-1) poke(A,0xF4) poke(A,0xFF)
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 (not including comments or newlines) poke(-15.5-😐,8,1,251,7,4,0,3,15) poke(13.5-😐,3) poke(60.5-😐,-1) poke(62.5-😐,0xF4) poke(62.5-😐,0xFF)
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:
-- 64 chars (not including comments or newlines) q=poke2 q(-15-😐,264,2043,4,3843) q(14-😐,3) q(63-😐,244) q(61-😐,-1,-1)
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)
how did you know moon face was the one to use?!
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!
- v5: show options (and allow them to be copied) as soon as they're found. (no longer need to wait for the entire search to complete)
[Please log in to post a comment]