Amaraticando

lsnes: current instruction on screen

Mar 30th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- this outputs the current line of trace logger on screen
  2. -- very basic and not well tested, but helps when executing SNES' open bus, which is bugged on bsnes
  3.  
  4. local PFLAGS_ON = string.reverse("NVMXDIZC")
  5. local PFLAGS_OFF = string.lower(PFLAGS_ON)
  6.  
  7. function on_paint(frame_advance)
  8.     gui.top_gap(32)
  9.     gui.left_gap(24)
  10.     gui.right_gap(24)
  11.    
  12.     local previous_bus = memory.getregister("pbpc")
  13.     local A, X, Y, S = memory.getregister("a"), memory.getregister("x"), memory.getregister("y"), memory.getregister("s")
  14.     local D, DB = memory.getregister("d"), memory.getregister("db")
  15.     local processor_flags = bit.rflagdecode(memory.getregister("p"), 8, PFLAGS_ON, PFLAGS_OFF)
  16.     local V, H = memory.getregister("vcounter"), memory.getregister("hcounter")
  17.     local code = memory.disassemble("snes-XA", 0x1000000 + previous_bus, 1)[1].disasm
  18.    
  19.     local log_text = string.format("%.6x  A:%.4x X:%.4x Y:%.4x S:%.4x D:%.4x DB:%.2x %s V:%3d H:%4d",
  20.                                     previous_bus, A, X, Y, S, D, DB, processor_flags, V, H)
  21.     gui.text(-24, -32, log_text, "white", "darkblue")
  22.     gui.text(-24, -16, code, "red", "darkblue")
  23. end
  24.  
  25. gui.repaint()
Advertisement
Add Comment
Please, Sign In to add comment