Log In  


I wrote a new tool that turns carts upside down.

% ./p8upsidedown jelpi.p8.png

Cart #16098 | 2015-11-02 | Code ▽ | Embed ▽ | No License
1

The tool is built with the picotool library (discussion). This version of the tool inverts the sprites, inverts the map, and translates the code to use inverted coordinates for drawing functions.

This is meant as a hack/demo and is known not to work with every cart. It works with many carts, and some of the failures are interesting. Notably:

  • The code translation increases the token count, so large carts (Celeste, Dusk Child) can't be turned upside down.

  • This version doesn't support spr/sspr calls that draw a rectangle of tiles. This wouldn't be too difficult to support: it'd need to flip the entire spritesheet not just individual sprites, translate the sprite IDs in the map, and extend the code to rewrite sprite ID args. But I have other things to do this weekend. :)

  • The print function will always print left to right, so we compromise and merely relocate the y coordinate for print / cursor calls. There's nothing the tool can do with carts that call multiple coordinate-less prints.

  • I wrote this to exercise and demonstrate the picotool libraries for mutating Lua code via the AST. The lib doesn't know how to write out an arbitrary AST and preserve other comments/spaces, so p8upsidedown generates hideous code. Unfortunately the luafmt writer isn't entirely up to snuff either so it's not much help. This is mostly not an issue to Pico-8, though I did find a bug where Pico-8's special "t += val" syntax rejects a newline between the "+=" and the "val", which p8upsidedown might accidentally introduce.

Anyway, a fun weekend hack with picotool. Enjoy!

-- Dan

1


What has science wrought...

You know, vertical and/or horizontal screen flipping should really just be a video mode setting you could poke to 0x5f2c. :| It would probably be more useful than the mirroring modes it currently provides... marginally.


Very cool. Could you add also optional argument that would flip controls as well?


Sure thing! I also added a reverse sfx option. Here you go:

./p8upsidedown --flipbuttons --flipsounds jelpi.p8.png



That reversed music is awesome.



[Please log in to post a comment]