samhocevar [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=14958 CPU cycle exploit? <p>The function <em>peek4()</em> does not properly check its number of arguments, so calling it with no arguments will cost zero cycles. Combined with any other function that costs fewer cycles than its number of arguments, such as <em>shl()</em>, this can be exploited to reclaim CPU cycles.</p> <p>Here is a function that reclaims n cycles:</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function reclaim(n) for i=0,n/5 do shl(peek4(),peek4())shl(peek4(),peek4()) shl(peek4(),peek4())shl(peek4(),peek4()) shl(peek4(),peek4())shl(peek4(),peek4()) end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I do not know to what extent this can be exploited, but here is an example.</p> <p>The following program runs at 15 FPS:</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function _draw() for y=0,127 do m=3+rnd() for x=0,127 do pset(x,y,(x+7)*m%5) end end print(stat(7)..&quot; fps&quot;,1,1,7) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>But this one runs at 30 FPS:</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function _draw() for y=0,127 do m=3+rnd() for x=0,127 do pset(x,y,(x+7)*m%5) end reclaim(200) end print(stat(7)..&quot; fps&quot;,1,1,7) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=32655 https://www.lexaloffle.com/bbs/?tid=32655 Fri, 21 Dec 2018 14:20:57 UTC Dancer Demo <p> <table><tr><td> <a href="/bbs/?pid=60202#p"> <img src="/bbs/thumbs/pico8_dancer-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=60202#p"> dancer</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=60202#p"> [Click to Play]</a> </td></tr></table> </p> <p>106 frames of animation, compressed and embedded in the cart (half in the code, half in the gfx segment).</p> https://www.lexaloffle.com/bbs/?tid=32654 https://www.lexaloffle.com/bbs/?tid=32654 Fri, 21 Dec 2018 13:46:09 UTC API CPU costs <p>I have started measuring function costs precisely, because I like accurate things. It&rsquo;s all <a href="https://pico-8.wikia.com/wiki/CPU">on the wiki</a> but not fully complete.</p> <p>Here are a few funny things I already learned:</p> <ul> <li>&lt;code&gt;x^.5&lt;/code&gt; costs 16 cycles, whereas &lt;code&gt;sqrt(x)&lt;/code&gt; costs 27</li> <li>&lt;code&gt;x^4&lt;/code&gt; costs 8 cycles, but &lt;code&gt;x*x*x*x&lt;/code&gt; only costs 3</li> </ul> <p>Some of these, such as clipped &lt;code&gt;circ()&lt;/code&gt;, are pretty tricky to measure, I hope someone can help!</p> <p><em>Edit</em>: removed claim about shl() because that function behaves a bit differently.</p> https://www.lexaloffle.com/bbs/?tid=32651 https://www.lexaloffle.com/bbs/?tid=32651 Thu, 20 Dec 2018 18:06:35 UTC Calculator <p> <table><tr><td> <a href="/bbs/?pid=59724#p"> <img src="/bbs/thumbs/pico8_calculator-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=59724#p"> calculator</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=59724#p"> [Click to Play]</a> </td></tr></table> </p> <p>Just a work in progress. The parser is not perfect but it needs a lot of work.</p> https://www.lexaloffle.com/bbs/?tid=32467 https://www.lexaloffle.com/bbs/?tid=32467 Wed, 05 Dec 2018 19:01:29 UTC Trouble parsing &quot;\\&quot; <p>This code does not work (<strong>unexpected symbol near 'then'</strong>):<br /> <span style=" display:inline-block; background-color:#eee; padding:2px; margin: 4px; padding-left: 8px; padding-right: 8px; color:#222">if (x == &quot;\\&quot;) then print(x) end</p> <p>But this works OK:<br /> <span style=" display:inline-block; background-color:#eee; padding:2px; margin: 4px; padding-left: 8px; padding-right: 8px; color:#222">bs = &quot;\\&quot; if (x == bs) then print(x) end</p> https://www.lexaloffle.com/bbs/?tid=32464 https://www.lexaloffle.com/bbs/?tid=32464 Wed, 05 Dec 2018 14:31:48 UTC Rainbow Cats [LD43] <p> <table><tr><td> <a href="/bbs/?pid=59669#p"> <img src="/bbs/thumbs/pico8_rainbow_cats-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=59669#p"> Rainbow Cats [LD43]</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=59669#p"> [Click to Play]</a> </td></tr></table> </p> <p>Your kittens are in danger! How could they survive in such a crazy world?</p> <p>You must return them home safely. Select the color of the kittens you wish to call and they will follow you everywhere.</p> <p>Controls:</p> <ul> <li>Navigation and player controls: arrows</li> <li>Call your kittens: X</li> <li>Validation and jump: Z or W</li> </ul> <p>This is the entry for Ludum Dare 43 we made with <a href="https://www.lexaloffle.com/bbs/?uid=30868"> @Niarkou</a>.</p> <ul> <li><a href="https://ldjam.com/events/ludum-dare/43/rainbow-cats">Ludum Dare 43 entry page</a></li> <li><a href="https://github.com/escargames/Rainbow-Cats">Source code on GitHub</a></li> </ul> https://www.lexaloffle.com/bbs/?tid=32452 https://www.lexaloffle.com/bbs/?tid=32452 Tue, 04 Dec 2018 13:08:01 UTC Vanity <p> <table><tr><td> <a href="/bbs/?pid=59086#p"> <img src="/bbs/thumbs/pico59084.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=59086#p"> Vanity</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=59086#p"> [Click to Play]</a> </td></tr></table> <br /> This is my entry for #TweetTweetJam: an unfinished shooter, in about 530 characters of code.</p> <p>Left/right to move, X to shoot.</p> <p>It has music and SFX and many things but no actual gameplay.</p> <p>Jam entry page: <a href="https://itch.io/jam/tweettweetjam/rate/331412">https://itch.io/jam/tweettweetjam/rate/331412</a></p> https://www.lexaloffle.com/bbs/?tid=32265 https://www.lexaloffle.com/bbs/?tid=32265 Fri, 16 Nov 2018 18:06:44 UTC Hidden feature: splash screen <p>I noticed that if there is a file named &quot;splash.png&quot; in PICO-8�s directory, it will be displayed at launch before the boot sequence. This also works with cartridges exported as binary.</p> https://www.lexaloffle.com/bbs/?tid=31683 https://www.lexaloffle.com/bbs/?tid=31683 Thu, 16 Aug 2018 04:20:00 UTC Cat Lady Simulator: LD42 <p> <table><tr><td> <a href="/bbs/?pid=55104#p"> <img src="/bbs/thumbs/pico55138.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=55104#p"> Cat Lady Simulator: LD42</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=55104#p"> [Click to Play]</a> </td></tr></table> </p> <p>My love Niarkou and I made this for Ludum Dare in 72 hours!</p> <p><em>Objectives:</em> Feed your cats by filling their bowls. The more they eat, the more points you get! But too many cats and you will run out of space.</p> <p><em>Controls:</em></p> <ul> <li>Pause: P or Enter</li> <li>Navigation / Player controls: &#9664; &#9650;&#9660; &#9654;</li> <li>Menu validation / Take something / Pour something into the bowl: W / Z</li> <li>Throw away something: X</li> </ul> <p>LDJam link: <a href="https://ldjam.com/events/ludum-dare/42/cat-lady-simulator">https://ldjam.com/events/ludum-dare/42/cat-lady-simulator</a></p> https://www.lexaloffle.com/bbs/?tid=31668 https://www.lexaloffle.com/bbs/?tid=31668 Mon, 13 Aug 2018 19:47:17 UTC z8lua: an almost PICO-8 compatible Lua fork <p>I was working on this a while ago and haven�t found much time for it lately, but I thought it could be interesting to some people. It is a fork of Lua that implements the PICO-8 dialect.</p> <p><strong>Why?</strong></p> <p>If you know how to embed Lua somewhere, then there are chances that you can embed PICO-8 compatible Lua instead! I use it for an unfinished toy emulator project.</p> <p><strong>Features</strong></p> <ul> <li>short <em>if</em> syntax (on one line)</li> <li>short print syntax (<em>?</em> at the beginning of a line)</li> <li>compound assignment operators: <em>+=</em> <em>/=</em> etc.</li> <li>C style not equal operator: <em>!=</em></li> <li>C++ style comments with <em>//</em></li> <li>fixed-point arithmetic with overflows, infinity etc.</li> <li>the PICO-8 math library (<em>shr</em>, <em>atan2</em>, <em>flr</em> etc.)</li> <li>binary literals: <em>0b1001001.10010</em></li> <li>works in Windows and Linux, and probably in OS X too</li> </ul> <p><strong>How?</strong></p> <p>The usual approach to the language extensions is through code parsing and patching. For instance, replacing all occurrences of <em>&lt;something&gt;+=&lt;blah&gt;</em> with <em>&lt;something&gt;=&lt;something&gt;+(&lt;blah&gt;)</em>. This is what PICO-8 itself does, which is why it still has the occasional weird parsing issues (you can write <em>x=0y=1</em> but not <em>x+=0y=1</em>). My approach is to implement these extensions in the Lua parser instead, which is elegant, more robust, and gives better error reporting.</p> <p><strong>Where?</strong></p> <p>It�s on GitHub: <a href="https://github.com/samhocevar/z8lua">https://github.com/samhocevar/z8lua</a></p> <p><strong>Example</strong></p> <p>Here is a z8lua session in my terminal; you can see familiar PICO-8 syntax in here:</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/14958/z8lua.png" width=562 height=549 alt="" /> https://www.lexaloffle.com/bbs/?tid=31577 https://www.lexaloffle.com/bbs/?tid=31577 Mon, 30 Jul 2018 07:38:01 UTC Anthrax (inspired by Pang) <p> <table><tr><td> <a href="/bbs/?pid=54522#p"> <img src="/bbs/thumbs/pico54521.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=54522#p"> Anthrax (inspired by Pang)</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=54522#p"> [Click to Play]</a> </td></tr></table> We made this game over the weekend as some practice for Ludum Dare. It is named after one of our cats.</p> <p>Controls: left/right to move, X to fire.</p> https://www.lexaloffle.com/bbs/?tid=31575 https://www.lexaloffle.com/bbs/?tid=31575 Sun, 29 Jul 2018 17:18:47 UTC Agony Demake Demo <p> <table><tr><td> <a href="/bbs/?pid=47451#p"> <img src="/bbs/thumbs/pico47450.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=47451#p"> Agony Demake Demo</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=47451#p"> [Click to Play]</a> </td></tr></table> <br /> I was working on this during Ludum Dare 39 (4 months ago) but never got the courage to finish it� maybe one day!</p> https://www.lexaloffle.com/bbs/?tid=30458 https://www.lexaloffle.com/bbs/?tid=30458 Sat, 16 Dec 2017 17:17:15 UTC Kabloo8 (LD40 Jam) <p> <table><tr><td> <a href="/bbs/?pid=46977#p"> <img src="/bbs/thumbs/pico46976.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=46977#p"> Kabloo8</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=46977#p"> [Click to Play]</a> </td></tr></table> </p> <p>Made for Ludum Dare. It�s 2 minutes before the deadline, I need some sleep now.</p> https://www.lexaloffle.com/bbs/?tid=30369 https://www.lexaloffle.com/bbs/?tid=30369 Sun, 03 Dec 2017 20:59:27 UTC The Chamber Scrolls [LD37] <p> <table><tr><td> <a href="/bbs/?pid=33420#p"> <img src="/bbs/thumbs/pico33419.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=33420#p"> The Chamber Scrolls</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=33420#p"> [Click to Play]</a> </td></tr></table> </p> <p>A mini adventure game.</p> <p>This cartridge extensively abuses Lua memory, lossy zlib compression, data-stored-in-code, and dget to render a 600&times;252 image with pixel-perfect scrolling. This is more a tech demo but I ended up doing a full mini game for Ludum Dare 37.</p> <p>I�ll write a postmortem to explain all the hacks.</p> https://www.lexaloffle.com/bbs/?tid=28209 https://www.lexaloffle.com/bbs/?tid=28209 Mon, 12 Dec 2016 22:29:27 UTC Textmode colour screenshots <p>This function abuses Unicode and ANSI color codes to output a screenshot of the current screen to a text terminal such as xterm. You can record the PICO-8 rendering and replay it using �cat�! You can run PICO-8 over ssh! You can be anything you want.</p> <p>I also set up a telnet service demonstrating the feature:</p> <pre><span style=" display:inline-block; background-color:#eee; padding:2px; margin: 4px; padding-left: 8px; padding-right: 8px; color:#222">telnet lol.pm 12345</pre> <p>Here is how it looks like; this is PICO-8 (small window) launched from GNOME Terminal (large window) just after screenshot() was called:</p> <p><a href="https://www.lexaloffle.com/bbs/files/14958/pico8-ansi.png"><img style="" border=0 src="https://www.lexaloffle.com/bbs/files/14958/pico8-ansi.png" width=420 height=262.5 alt="" /></a></p> <p>And here is the code:</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> pico-8 cartridge // http://www.pico-8.com version 8 __lua__ -- screenshot to console -- by sam hocevar function screenshot() local l={ 16, 17, 89, 29, 131, 240, 251, 230, 197, 214, 220, 47, 39, 103, 211, 223 } local e=&quot;\027[&quot; printh(e..&quot;?25l&quot;) -- hide cursor for y=0,63 do local ofg,obg=-1,-1 local s=e..(y+1)..&quot;;1\072&quot; -- uppercase h for x=0,127 do fg,bg,ch=pget(x,y*2),pget(x,y*2+1),&quot;\226\150\128&quot; if bg&gt;fg then fg,bg,ch=bg,fg,&quot;\226\150\132&quot; end if fg!=ofg or bg!=obg then s=s..e local t=&quot;&quot; if (bg!=obg) s,t=s..&quot;48;5;&quot;..l[bg+1],&quot;;&quot; if (fg!=ofg) s=s..t..&quot;38;5;&quot;..l[fg+1] s=s..&quot;m&quot; end s=s..ch ofg,obg=fg,bg end printh(s..e..&quot;0m&quot;..e..&quot;\075&quot;) -- uppercase k end printh(e..&quot;?25h&quot;) -- show cursor end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>The terminal must be UTF-8 and 256-color aware, so this will probably work in most Linux and OS X terminals. On Windows I could test it successfully with the MSYS2 terminal.</p> https://www.lexaloffle.com/bbs/?tid=27769 https://www.lexaloffle.com/bbs/?tid=27769 Thu, 29 Sep 2016 08:15:16 UTC King Tut (hi-color demo) <p> <table><tr><td> <a href="/bbs/?pid=27685#p"> <img src="/bbs/thumbs/pico27684.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=27685#p"> King Tut</a><br><br> by <a href="/bbs/?uid=14958"> samhocevar</a> <br><br><br> <a href="/bbs/?pid=27685#p"> [Click to Play]</a> </td></tr></table> </p> <p>Will not work well on slow machines or in the web player.</p> <p>I�m toying with both hi-color images (using 60Hz flickering) and data compression, this is my first attempt. The image size is 128&times;188.</p> <p>The picture is of course a tribute to the Deluxe Paint series!</p> https://www.lexaloffle.com/bbs/?tid=27578 https://www.lexaloffle.com/bbs/?tid=27578 Mon, 29 Aug 2016 20:26:55 UTC