{"id":10,"date":"2023-08-16T19:18:58","date_gmt":"2023-08-16T19:18:58","guid":{"rendered":"https:\/\/blog.tuhb.org\/?p=10"},"modified":"2023-08-16T19:43:50","modified_gmt":"2023-08-16T19:43:50","slug":"tiny-tic-80-fireworks","status":"publish","type":"post","link":"https:\/\/blog.tuhb.org\/?p=10","title":{"rendered":"Tiny TIC-80 fireworks"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I was so happy that Goerp had fun making his first TIC-80 thing (<a href=\"https:\/\/goerp.nl\/tic80\/yay\/\" data-type=\"link\" data-id=\"https:\/\/goerp.nl\/tic80\/yay\/\">link to live version<\/a>) that I wanted to try my hand at making it tiny. Especially since my earlier attempts at doing fireworks with sound in 256 bytes <a href=\"https:\/\/www.youtube.com\/watch?v=e9OHnF_jqGs\" data-type=\"link\" data-id=\"https:\/\/www.youtube.com\/watch?v=e9OHnF_jqGs\">had failed<\/a>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">256 bytes is a classic category in sizecoding, the demoscene discipline that focuses on programming <em>tiny<\/em> things. During livecoding sessions (called <em>Byte Battles)<\/em>, the number of characters is counted. However, for regular competitions  <em>the size of the binary .tic file<\/em> is what matters. The TIC-80 is a fantasy console that has a lot to offer in the way of making things small, and I&#8217;ll try to document my process here.<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Running a packer<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The TIC-80 internal file format consists of various chunks. By default, the source code is stored in a simple text chunk, but TIC-80 also supports a zlib compressed chunk which is perfect for sizecoding. People created various tools to help convert to this compressed format. What these tools do is take the LUA code from the uncompressed source, reorder it to make it optimal for packing, and then compress it into the compressed block. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Packing changes the rules, as things that would normally make your code smaller (like aliasing math.sin to s) might now actually make the output bigger. It&#8217;s now all about having &#8220;similar rows of characters&#8221; (handwaving) in your source that will compress away. As it can be a bit unpredictable what works best for compression it&#8217;s very important to regularly run a packer from the start.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What I do is I always have a custom little tool running that monitors the TIC-80 folder and compresses after any file change, using the quickest compression scheme from the <a href=\"https:\/\/github.com\/phlubby\/pactic\" data-type=\"link\" data-id=\"https:\/\/github.com\/phlubby\/pactic\">Pactic <\/a>tool . This allows me to keep an eye on the file size, while I can trust that doing a packing run with full compression on (this takes a while) will shave off another 5-10 bytes in the end. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The original .tic file clocks in at <strong>2095<\/strong> bytes. As you can see in the screenshot below, simply running our compressor brings that down to <strong>347 <\/strong>bytes&#8230; Not bad!<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1684\" height=\"608\" src=\"https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image.png\" alt=\"\" class=\"wp-image-11\" srcset=\"https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image.png 1684w, https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image-300x108.png 300w, https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image-1024x370.png 1024w, https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image-768x277.png 768w, https:\/\/blog.tuhb.org\/wp-content\/uploads\/2023\/08\/image-1536x555.png 1536w\" sizes=\"auto, (max-width: 1684px) 100vw, 1684px\" \/><\/figure>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Code optimizations<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code consistently used <em>for i=1,count,1 do<\/em> to enumerate sets. That last ,1 is optional, so it can be safely removed&#8230; however, that left us with a final size of <strong>350<\/strong>! Oh now, we just lost three bytes. Yay compression and it&#8217;s mysterious ways.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Comparisons were done in <em>if value==true<\/em> and <em>if value== false<\/em> style, replacing those with a simple <em>if value<\/em> and <em>if not value <\/em>brought as back on track to <strong>345<\/strong> bytes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Sound<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To be figured out \ud83d\ude04<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Final Compression<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ignoring the sound: pakkettic gets it down to 335 bytes rn. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was so happy that Goerp had fun making his first TIC-80 thing (link to live version) that I wanted to try my hand at making it tiny. Especially since my earlier attempts at doing fireworks with sound in 256 bytes had failed. 256 bytes is a classic category in sizecoding, the demoscene discipline that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[4],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-sizecoding","category-uncategorized","tag-tic-80"],"_links":{"self":[{"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10"}],"version-history":[{"count":3,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tuhb.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}