Skip to content

Instantly share code, notes, and snippets.

@Gargaj

Gargaj/tic80packer.py

Last active Dec 15, 2020
Embed
What would you like to do?
#
# TIC80 packer
#
# Uses the zlib code chunk to crunch down your source
# https://github.com/nesbox/TIC-80/wiki/tic-File-Format
#
# Usage: tic80packer [lua file]
#
import sys
import zlib
with open(sys.argv[1], mode='rb') as file:
uncomp = file.read()
print("Uncompressed length: {} bytes".format(len(uncomp)))
comp = zlib.compress(uncomp, zlib.Z_BEST_COMPRESSION)
print("Compressed length: {} bytes".format(len(comp)))
print("With header: {} bytes".format(len(comp)+4))
with open(sys.argv[1]+".tic", 'wb') as file:
file.write(bytes([16]))
file.write(bytes([len(comp) & 0xFF]))
file.write(bytes([len(comp) >> 8]))
file.write(bytes([0]))
file.write(comp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment