Guest User

Untitled

a guest
May 1st, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | Gaming | 0 0
  1. -- this outputs some information related to the map loading procedure when the screen scrolls,
  2. -- hopefully helpful for researching and recreating the scroll bug
  3. -- script by mugg ; with help from ais523, Sand
  4.  
  5. console.clear()
  6. memory.usememorydomain("System Bus")
  7.  
  8. local cycles_at_frame_start = emu.totalexecutedcycles()
  9. local cycles_at_frame_end = emu.totalexecutedcycles()
  10. local print_after_this_frame = emu.framecount() + 1
  11. local game_version = "-"
  12. local t = ""
  13.  
  14. if gameinfo.getromhash() == "3A4DDB39B234A67FFB361EE7ABC3D23E0A8B1C89" then
  15.     game_version = "1.0"
  16. elseif gameinfo.getromhash() == "418203621B887CAA090215D97E3F509B79AFFD3E" then
  17.     game_version = "1.1"
  18. else
  19.     print("This script will work only with GB Super Mario Land v1.0 or v1.1.")
  20.     return
  21. end
  22.  
  23. function text(x, y, text, color, backcolor)
  24.     gui.pixelText(x, y, text, color, backcolor)
  25. end
  26.  
  27. event.onframestart(function()
  28.     cycles_at_frame_start = emu.totalexecutedcycles()
  29. end)
  30.  
  31. event.onframeend(function()
  32.     if emu.framecount() > print_after_this_frame then
  33.         t = t .. "\nCycles this frame: " .. emu.totalexecutedcycles() - cycles_at_frame_end
  34.     end
  35.     if emu.islagged() then
  36.         t = t .. "\n*** LAG ***"
  37.     end
  38.        
  39.     cycles_at_frame_end = emu.totalexecutedcycles()
  40.     t = t .. "\n\n----- Frame " .. emu.framecount() + 1 .. " -----"
  41.  
  42.     print(t)
  43.     t = ""
  44.    
  45.     loadedstate = false
  46. end)
  47.  
  48. tastudio.onbranchload(function()
  49.     print_after_this_frame = emu.framecount() + 1
  50.     console.clear()
  51. end)
  52.  
  53. event.onloadstate(function()
  54.     print_after_this_frame = emu.framecount() + 1
  55.     console.clear()
  56. end)
  57.  
  58. -- Write to $FFEA
  59. -- passed val is always 0, it seems, hinting that this hook is not fully implemented
  60. event.on_bus_write(function(addr, val, flags)
  61.     if emu.framecount() > print_after_this_frame then
  62.         local val = string.upper(string.format("%02x",memory.read_u8(0xFFEA)))
  63.         t = t .. "\nWrite $FFEA (" .. val .. ") - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  64.     end
  65. end, 0xFFEA)
  66.  
  67. -- Exec $0040
  68. event.on_bus_exec(function(addr, val, flags)
  69.     if emu.framecount() > print_after_this_frame then
  70.         t = t .. "\nExecu $0040 (VBLANK) - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  71.     end
  72. end, 0x0040)
  73.  
  74. -- game version dependent execs
  75. if game_version == "1.0" then
  76.  
  77.     event.on_bus_exec(function(addr, val, flags)
  78.         if emu.framecount() > print_after_this_frame then
  79.             t = t .. "\nExecu $2258 (READ $FFEA) - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  80.         end
  81.     end, 0x224F)
  82.    
  83.     event.on_bus_exec(function(addr, val, flags)
  84.         if emu.framecount() > print_after_this_frame then
  85.             t = t .. "\nExecu $2254 (READ $FFE9) - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  86.         end
  87.     end, 0x2254)
  88.  
  89. elseif game_version == "1.1" then
  90.  
  91.     event.on_bus_exec(function(addr, val, flags)
  92.         if emu.framecount() > print_after_this_frame then
  93.             t = t .. "\nExecu $2258 (READ $FFEA) - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  94.         end
  95.     end, 0x2258)
  96.    
  97.     event.on_bus_exec(function(addr, val, flags)
  98.         if emu.framecount() > print_after_this_frame then
  99.             t = t .. "\nExecu $225D (READ $FFE9) - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start
  100.         end
  101.     end, 0x225D)
  102.  
  103. end
  104.  
  105. --[[
  106. Read hook seems broken, maybe I should be using execution from ROM instead.
  107.  
  108. -- Read $FFEA
  109. event.on_bus_read(function(addr, val, flags)
  110.     if emu.framecount() > print_after_this_frame then
  111.         local val = string.upper(string.format("%02x",memory.read_u8(0xFFEA)))
  112.         print("Read $FFEA (" .. val .. ") - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start)
  113.     end
  114. end, 0xFFEA)
  115.  
  116. -- Read $FFE9
  117. event.on_bus_read(function(addr, val, flags)
  118.     if emu.framecount() > print_after_this_frame then
  119.         local val = string.upper(string.format("%02x",memory.read_u8(0xFFE9)))
  120.         print("Read $FFE9 (" .. val .. ") - current cycle: " .. emu.totalexecutedcycles() - cycles_at_frame_start)
  121.     end
  122. end, 0xFFE9)
  123. ]]
  124.  
  125. while true do  
  126.     emu.frameadvance()
  127. end
  128.  
Advertisement
Add Comment
Please, Sign In to add comment