--[[ MESHUGGAH's HUD Template
This template features an example to
v contains RAM addresses of position values (hexadecimal)
p positon values stored here after reading memory from location v (memory.readbyte)
pp previous position values stored here to compare with new positions on next frame
--]]
-- Variable array: P1 X, P1 Y, Camera X
local v = {
0x30,
0x32,
0x26
}
-- Position array
local p = {} for i = 1, table.getn(v) do p[i] = 0 end
-- Previous position array
local pp = {} for k,v in pairs(p) do pp[k] = v end
local l = {} for i = 1, 4 do l[i] = 0 end
local h = 0
-----------------------------------------------------------------------
local function objects()
-- display ID if alive
for i = 0, 1 do
if memory.readbyte(0x386+i*19) ~= 0 then
gui.text(memory.readbyte(0x388+i*19)+i*30*2,memory.readbyte(0x38b+i*19)+30*2,i,"#FFFFFFFF","#FF000080")
for j = 0, 18 do
gui.text(500+i*100,140+j*16,memory.readbyte(0x388+i*19+j))
end
gui.text(400,140,string.format("X\n0 / 128\n?\nY\n?\nB - 6\nDirection\n?\n?\n?\nTIMER\n?\nHP\n?\nB - 15\n?\nB - 17\n?\n?"))
end
end
gui.text(100,380,"projectiles")
for i = 0, 2 do
gui.text(100,400+i*16,string.format("%d: %3d, %3d",i,memory.readbyte(0x95+i*10),memory.readbyte(0x97+i*10)))
end
end
local function hud()
-- Display object's ID and X and Y pos
objects()
-- Read new positions
for i = 1, table.getn(v)-1 do p[i] = memory.readbyte(v[i]) end
p[3] = memory.read_u16_le(v[3])
-- CamX pos
gui.text(120,0,string.format("CamX %5d (%d)",p[3],p[3]-pp[3]),"#FFFFFFFF","#00000080")
--for i = 0, 9 do gui.text(120,200+i*16,memory.readbyte(0x360+i))
--gui.text(120,180,"States -->") end
-- Level
gui.text(120,15,string.format("Level %d\n",memory.readbyte(0xee)),"#FFFFFFFF","#00000080")
-- X pos, Y pos
gui.text(280,0,string.format("X %5d (%d)",p[1],p[1]-pp[1]),"#FFFFFFFF","#00000080")
gui.text(280,15,string.format("Y %5d (%d)",p[2],p[2]-pp[2]),"#FFFFFFFF","#00000080")
-- Timer
gui.text(420,0,string.format("0x84 %3d\n0x88 %3d",memory.readbyte(0x84),memory.readbyte(0x88)),"#FFFFFFFF","#00000080")
-- Lag indicators
gui.text(520,0,string.format("LAG %3d %3d %3d %3d %3d\n",memory.readbyte(0x1ea),memory.readbyte(0x1f7),memory.readbyte(0x601),memory.readbyte(0x602),memory.readbyte(0x603)),"#FFFFFFFF","#00000080")
end
local function lag()
l[1] = memory.readbyte(0x1ea)
l[2] = memory.readbyte(0x1f7)
--print(p[1],pp[1],p[3],pp[3])
if (l[2] == 200 and l[2] == l[4]) then
print(string.format("increased lag level @ %5d",emu.framecount()))
end
if (((l[2] == l[4] and l[2] == 200) or (l[1] == 194 and l[3] ~= l[1])) and p[1] == pp[1] and p[3] == pp[3]) then
emu.setislagged()
--p[1]-pp[1]
h = h + 1
print(string.format("HORIZONTAL LAG @ %5d, total: %3d",emu.framecount(),h))
end
l[3] = l[1]
l[4] = l[2]
end
while true do
emu.frameadvance()
for i = 1, table.getn(v)-1 do p[i] = memory.readbyte(v[i]) end
p[3] = memory.read_u16_le(v[3])
--lag()
hud()
-- Store positions to compare them in next frame
for k,v in pairs(p) do pp[k] = v end
end