Written by CasualPokePlayer.
local function ptr_is_invalid(ptr)
return ptr < 0x02000000 or ptr > 0x0203FFFF
end
local function get_x_pos()
local base_addr = 0x02006614 -- appears to be a constant in the code
local ptr = memory.read_u32_le(base_addr, "System Bus")
if (ptr_is_invalid(ptr)) then
return 0
end
local ptr_ptr = memory.read_u32_le(ptr + 4, "System Bus")
if (ptr_is_invalid(ptr_ptr)) then
return 0
end
-- seems to be a variable offset added at this point, but usually (always?) 0?
-- if this breaks, that offset probably needs to be considered
local ptr_ptr_ptr = memory.read_u32_le(ptr_ptr + 4, "System Bus")
if (ptr_is_invalid(ptr_ptr_ptr)) then
return 0
end
local ptr_ptr_ptr_ptr = memory.read_u32_le(ptr_ptr_ptr + 4, "System Bus")
if (ptr_is_invalid(ptr_ptr_ptr_ptr)) then
return 0
end
local ptr_ptr_ptr_ptr_ptr = memory.read_u32_le(ptr_ptr_ptr_ptr + 0, "System Bus")
if (ptr_is_invalid(ptr_ptr_ptr_ptr_ptr)) then
return 0
end
return memory.read_u32_le(ptr_ptr_ptr_ptr_ptr + 0x17C, "System Bus")
end
local x_pos = get_x_pos()
local last_x_pos = x_pos
while true do
x_pos = get_x_pos()
local x_speed = x_pos - last_x_pos
last_x_pos = x_pos
gui.text(5, 5, string.format("X Speed: %d", x_speed), nil, "topright")
emu.frameadvance()
end