Log In  

Cart #set_resolution-1 | 2021-12-23 | Code ▽ | Embed ▽ | No License
8

PICO-8's resolution can easily be lowered to 64x64 with:
poke(0x5f2c,3)
but it's always bothered me that you can't set the resolution to other factors of 128. So, I made this function that allows you to scale up whatever is currently drawn to the screen to any factor of 128 excluding 1 (2, 4, 8, 16, 32, 64, 128). The performance for 64x64 is pretty awful, so you're better off using poke(0x5f2c,3) if that's the resolution you're after. The others perform fairly well, with 32x32 using about <12% CPU and everything below it using <3%. One advantage of using this function is that after scaling down the currently drawn screen, you're free to draw over top it in full resolution, as demonstrated by the CPU performance text. I'm sure the performance can be improved somehow. I think this may be possible using memset, but I don't understand how to apply it to this case, or if it would even improve performance. If anyone has any optimizations, feel free to reply and I'll update the cart. Hope someone finds this useful!

P#103378 2021-12-23 01:19

1

this is neat! I admire the work you put in to get it working pixel-by-pixel; here's an alternate approach that uses the new 0.2.4 video remapping stuff:

function setres(_res)
  poke(0x5f54,0x60) --set sspr source to screen data
  sspr(0,0,_res,_res,0,0,128,128)
  poke(0x5f54,0) -- reset sspr source
end

this makes setres() take 12% of the cpu, no matter the resolution. This is worse, speedwise, than your original code (for everything below 64x64), but it's simple and very token-efficient

P#103394 2021-12-23 09:02
1

here are some small optimizations to your original method; they're just small local equivalences (e.g. z*2 is the same as z<<1, but z<<1 is faster)

function setres(_res)
    if _res<65 then
        local t=128/_res
        local i=8191*(_res/128)
        local h=_res/2
        while i>0 do
            if(i&63>h)i-=64-h
            local x=(((i&0x3f.ffff)<<1)-1)*t+2
            local y=(i>>6)*t
            local pair=@(0x6000+i)
            rectfill(x-t,y,x-1,y+t-1,pair&15)
            rectfill(x,y,x+t-1,y+t-1,pair>>4)
            i-=1
        end
    end
end

performance improvements:

  • 64x64: 44.9% -> 36.1%
  • 32x32: 14.1% -> 11.9%
  • etc
P#103395 2021-12-23 09:11
1

Thanks pancelor, I had other people bring to my attention the new features of 0.2.4 that I had no idea existed, and your implementation works great. Thanks for the optimizations too! I really know very little about to write code that performs well in PICO-8, and I just got as far as I had using common sense lol.

P#103539 2021-12-26 00:21

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 08:02:48 | 0.010s | Q:18