SHARE
TWEET

SNES Lag Visualization

Dotsarecool Jul 30th, 2016 687 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- PARAMETERS
  2.  
  3. local END_OF_VBLANK = 0x2C3
  4. local END_OF_GAME_LOOP = 0x75
  5. -- location in ROM space, e.g. $0082C3 = 0x2C3
  6.  
  7. -------------
  8.  
  9. local V_TOP = 1
  10. local V_BOTTOM = 38
  11. local H_LEFT = 22
  12. local H_RIGHT = 62
  13.  
  14. local vv, vh = -20, -30
  15. local gv, gh = -20, -30
  16. local lag = 0
  17. local function get_vblank_scan()
  18.     lag = lag + 1
  19.     vh = memory.getregister("hcounter")
  20.     vv = memory.getregister("vcounter")
  21. end
  22. memory.registerexec("ROM",END_OF_VBLANK,get_vblank_scan)
  23. local function get_game_scan()
  24.     lag = 0
  25.     gv = memory.getregister("vcounter")
  26.     gh = memory.getregister("hcounter")
  27. end
  28. memory.registerexec("ROM",END_OF_GAME_LOOP,get_game_scan)
  29.  
  30. function on_paint()
  31.     gui.top_gap(2*V_TOP)
  32.     gui.left_gap(2*H_LEFT)
  33.     gui.right_gap(2*H_RIGHT)
  34.     gui.bottom_gap(2*V_BOTTOM)
  35.    
  36.     if lag ~= 0 then
  37.         gui.rectangle(2*(0-H_LEFT),2*(0-V_TOP),2*340,2*263,0x6000FF00,0x6000FF00)
  38.     else
  39.         if gv < 0xE1 then
  40.             gui.rectangle(2*(0-H_LEFT),2*(0xE1-V_TOP),2*340,2*38,0x6000FF00,0x6000FF00)
  41.             gui.rectangle(2*(0-H_LEFT),2*(0-V_TOP),2*340,2*gv,0x6000FF00,0x6000FF00)
  42.             gui.rectangle(2*(0-H_LEFT),2*(gv-V_TOP),2*(math.floor(gh/4)),2*1,0x6000FF00,0x6000FF00)
  43.         else
  44.             gui.rectangle(2*(0-H_LEFT),2*(0xE1-V_TOP),2*340,2*(gv-0xE1),0x6000FF00,0x6000FF00)
  45.             gui.rectangle(2*(0-H_LEFT),2*(gv-V_TOP),2*(math.floor(gh/4)),2*1,0x6000FF00,0x6000FF00)
  46.         end
  47.     end
  48.    
  49.     if vv < 0xE1 then
  50.         gui.rectangle(2*(0-H_LEFT),2*(0xE1-V_TOP),2*340,2*38,0x60FF0000,0x60FF0000)
  51.         gui.rectangle(2*(0-H_LEFT),2*(0-V_TOP),2*340,2*vv,0x60FF0000,0x60FF0000)
  52.         gui.rectangle(2*(0-H_LEFT),2*(vv-V_TOP),2*(math.floor(vh/4)),2*1,0x60FF0000,0x60FF0000)
  53.     else
  54.         gui.rectangle(2*(0-H_LEFT),2*(0xE1-V_TOP),2*340,2*(vv-0xE1),0x60FF0000,0x60FF0000)
  55.         gui.rectangle(2*(0-H_LEFT),2*(vv-V_TOP),2*(math.floor(vh/4)),2*1,0x60FF0000,0x60FF0000)
  56.     end
  57.    
  58.     gui.text(10,10,"lag: " .. lag)
  59.     gui.text(10,30,"game: (" .. gv .. "," .. gh .. ")")
  60.     gui.text(10,50,"vblank: (" .. vv .. "," .. vh .. ")")
  61. end
  62. gui.repaint()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top