You can do something like this (I've tested):
Language: lua
-- add other entries if you want
-- you might want to index by name and use a table of tables: address_name = {address = 0x43c, value = 0}
local past_values = {
[0x043c] = 0,
[0x043e] = 0,
}
-- IMO, the position of the text as the first arguments is more consistent
local function speedtext(whereX, whereY, address, address_name)
if not past_values[address] then
print("Address", address)
error"is invalid"
end
local current_value = mainmemory.read_u16_le(address)
local speed = current_value - past_values[address]
past_values[address] = current_value
address_name = address_name or string.format("%4x", address)
gui.pixelText(whereX, whereY, address_name .. ": " .. speed)
end
while true do
local whereX, whereY = 138, 128
speedtext(whereX, whereY, 0x043c, "1spX")
speedtext(whereX, whereY + 8, 0x043e, "1spY")
emu.frameadvance()
end