dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php
MIT License
367 stars 46 forks source link

luamin warning that the character limit is 32k, not 64k? #52

Closed tobiasvl closed 2 years ago

tobiasvl commented 5 years ago

I'm testing out luamin on a cart I'm working on and getting some output I don't understand:

tvl@rocinante:~/src/picotool $ python3 p8tool stats ~/src/lasertank-pico8/lasertank.p8
lasertank (lasertank.p8)
by tobiasvl
- version: 16
- lines: 978
- chars: 58496
- tokens: 4369
- compressed chars: 21826

tvl@rocinante:~/src/picotool $ python3 p8tool luamin ~/src/lasertank-pico8/lasertank.p8
/home/tvl/src/lasertank-pico8/lasertank.p8 -> /home/tvl/src/lasertank-pico8/lasertank_fmt.p8
warning: character count 52175 exceeds the Pico-8 limit of 32768
tvl@rocinante:~/src/picotool $ python3 p8tool stats ~/src/lasertank-pico8/lasertank_fmt.p8
lasertank_fmt.p8
- version: 8
- lines: 934
- chars: 52175
- tokens: 4369
- compressed chars: 20666

But surely the Pico-8 character limit is 65535, not 32768?

I suspect this has something to do with the fact that my cartridge's compressed size is 142% (compared to 134% in the minified cart), but it's not immediately clear what limit I'm hitting from the output.

(Note that the fact that my cart is much too big is OK and unsurprising, since I'm storing level data as strings in the code "ROM" area, and that's fine, but I'm trying to find out how many levels I can cram in there.)

tobiasvl commented 5 years ago

Oh, hm. I found this BBS thread where zep says this:

.p8 files have a ascii character code limit of around 64k, that most users will normally never reach unless they're doing something weird.

When a .p8.png cartridge is saved, the existing cartridge data layout is used. But if the ascii goes over 15k, an lz4-compressed version is saved instead (this is transparent to the user and doesn't remove any information). In the vast majority of cases, the 8k token limit will be reached before the 15k compressed data limit, but if it goes over 15k then the save is declined.

It looks like the new ascii code limit will be 32k characters. But normally the token limit would be reached first (I'm still guessing a bit here). There is a 3rd limit, which is that the code can fit into the 15360 byte section of the cartridge when compressed, but it looks like the vast majority of users won't ever need to deal with or know about this. This limit is only enforced when saving to .p8.png (.p8 can be thought of as dev files).

It's not clear to me what all this entails, but my confusion comes from the fact that my PICO-8 editor window says that my char count is 58519/65535, not 58496/32768. (Note the discrepancy here, PICO-8 says 58519, picotool stats says 58496.)

dansanderson commented 2 years ago

Resolved in 9d25e1774ae61120499baf8f08caa86e48241d67 by updating the character limits in accordance with PICO-8 changes.

This does not resolve character count discrepancies. I'll have to hunt for those separately. But the larger issue of using the incorrect limits is resolved.