Log In  


this nifty code lets you debug your project. Features it provides are in the codes guide on how to use it~

Cart #superdebug-0 | 2019-01-31 | Code ▽ | Embed ▽ | No License
3

--super debug v 1.0
--shooting★

--[[
…………………………………………
      how-to use
…………………………………………
to use this code, check out tab
2 and copy the compressed code.
once its coppied, you'll need
to put "sdbg()" (without
quotes) inside of your
_draw() function, at the very
bottom. make sure its drawn
last.

by default, the key to display
debug info is the tilde key (
the ` next to the number 1 on
standard u.s keyboards). you
can change this by simply
changing dbg_dbtn. at your init,
you can put dbg_dbtn = 't' for
example, and then 't' on your
keyboard will open the debug
info.

if you want to adjust the
memory location, you can adjust
the variable called addr.
by default, its 0x5e00. to edit
it, do the same as editing
dbg_dbtn, just put it in
_init(). ( addr = 0x5e01 )
…………………………………………
      ★features★
…………………………………………
this code displays the following
information:
 ◆ framerate
 				(top-right)
  ………
 ◆ cpu usage
  ………
 ◆ mem usage/max mem
  ………
 ◆ test count
 				(how many times
    	you tested your project
    	since installing this code)
  ………
 ◆ mouse info
 				(location, click
    	#)
  ………
 ◆ tile flags & id
 				(displays all 8 flags on the tile
    	you're hovering over)
  ………
 ◆ color of hovering-pixel
 				(gets the color of the
 				pixel you're currently
 				hovering the mouse over.)
  ………
 ◆pico version
	 ………
 ◆ uptime
     (how long the test has
     been running for)
  ………
]]

Alternatively, you can copy the compressed code directly and just follow instructions from the code displayed above. here's the compressed code that makes the entire thing run.

--code
dbg_dbtn = '`' dbt = 7 don = false cc = 8 mc = 15 addr = 0x5e00 function dtxt(txt,x,y,c) print(txt, x,y+1,1) print(txt,x,y,c) end function init_dbg() poke(0x5f2d, 1) test_num = peek(∧addr) or 0 poke(∧addr, test_num+1) end dbtm = 0 dbu = {0,0,0} function sdbg() if stat(31) == dbg_dbtn then if don==false then don=true else don=false end end if don != true then return end local c=dbt local cpu=stat(1)*100 local mem=(stat(0)/100)/10*32 local fps=stat(7) local u=stat(7)..'' local _x=124-(#u*4) local du = {dbu[1],dbu[2],dbu[3]} dtxt(u, 124-(#u*4), 1, c) u=cpu..'%' dtxt(u, 124-(#u*4), 7, c) u=mem..'kb /' dtxt(u, 124-(#u*4)-32, 13, c) dtxt('31.25kib', 128-33, 13, c) dtxt(du[3]..'h', 124-44, 128-9, c) dtxt(du[2]..'m', 124-28, 128-9, c) dtxt(du[1] ..'s', 124-12, 128-9, c) dtxt('cpu', 1, 7, c) dtxt('mem', 1, 13, c) dtxt('pico-'..stat(5), 1, 128-15, c) dtxt('uptime', 1, 128-9, c) dbtm+=1 dbu[1] = flr(dbtm/stat(8)) dbu[2] = flr(dbu[1]/60) dbu[3] = flr(dbu[2]/60) dtxt('test number: '..peek(0x5e00), 0, 24, c) dtxt('mouse: {'..stat(32)..','..stat(33)..'}\nbitmask: '..stat(34), 0, 30, c) draw_dbg_info(c) end function draw_dbg_info(c) local m = {stat(32)/8, stat(33)/8} local tile=fget(mget(m[0],m[1]), 0) dtxt('tile flags', 0, 6*8, c) local res = {} res[1] = fget(mget(m[1],m[2]), 0) res[2] = fget(mget(m[1],m[2]), 1) res[3] = fget(mget(m[1],m[2]), 2) res[4] = fget(mget(m[1],m[2]), 3) res[5] = fget(mget(m[1],m[2]), 4) res[6] = fget(mget(m[1],m[2]), 5) res[7] = fget(mget(m[1],m[2]), 6) res[8] = fget(mget(m[1],m[2]), 7) dtxt('{'.. blton(res[1]) ..','..blton(res[2]) ..','..blton(res[3]) ..','..blton(res[4]) ..'\n '..blton(res[5]) ..','..blton(res[6]) ..','..blton(res[7]) ..','..blton(res[8]) ..'}\ntile-id: '..mget(m[1],m[2]), 0, 6*9, c) print('color: '..pget(m[1]*8,m[2]*8), 0, 6*12, max(pget(m[1]*8,m[2]*8), 1)) circ(stat(32), stat(33), 3, c) circfill(stat(32), stat(33),1, c) end function blton(v) return v and 1 or 0 end
3


I forgot to mention, you also need to type init_dbg() inside of your _init() function


Great to have a library of sorts for this! I always hack it into my carts.

The boilerplate clocks in at 659 tokens, plus the init_dbg() and sdbg() function calls.

Just one thing, you say that it's the tilde key that triggers the debug info, but it's actually the grave accent key. I understand that tilde and grave accent are located on the same key on US keyboards, as you say, but if it were the tilde that triggered it you'd have to press SHIFT + ` and that's not the case.

(On my keyboard, ` and ~ are not on the same key and I need to press AltGr + ^ to trigger it.)


Ah, thank you, tobiasvl :)


I'll be re-making this now that I'm more familiar with pico8 :P



[Please log in to post a comment]