local B_POINT = 0x8DDD0
local B_XTEXT = 5
local B_YTEXT = 120
local B_ANGLE = 0
local B_SIN, B_COS, T_SIN, T_COS
local T_POINT = 0x8DDE4
--local T_XTEXT = client.bufferwidth()-137
--local T_XTEXT = client.screenwidth()-137
local T_XTEXT
local T_YTEXT = 120
local T_ANGLE = 0
while true do
for i=1, 1, 1 do
T_XTEXT = client.screenwidth()-137
B_DATA = memory.read_u32_le( B_POINT ) - 0x80000000
T_DATA = memory.read_u32_le( T_POINT ) - 0x80000000
if (B_DATA<0) or (B_DATA>2097152) or (T_DATA<0) or (T_DATA>2097152) then break end
B_X_SPD = memory.read_s16_le( B_DATA + 0x70 ) / 1
B_Y_SPD = memory.read_s16_le( B_DATA + 0x74 ) / 1
B_X_POS = memory.read_s16_le( B_DATA + 0xB8 )
B_Y_POS = memory.read_s16_le( B_DATA + 0xC0 )
B_Z_POS = memory.read_s16_le( B_DATA + 0xBC )
B_SIN = memory.read_s16_le( B_DATA + 0xA4 )
B_COS = memory.read_s16_le( B_DATA + 0xA8 )
B_SPD = math.sqrt(B_X_SPD^2 + B_Y_SPD^2)
B_SPD2 = math.sqrt(B_SIN^2 + B_COS^2)
-- if (B_X_SPD == 0 or B_Y_SPD == 0)
-- then B_ANGLE = B_ANGLE
-- else --B_ANGLE = math.atan(B_SIN/B_SPD2, B_COS/B_SPD2) * 360 / (math.pi/2)
-- if B_ANGLE<0 then B_ANGLE = B_ANGLE + 360 end
-- B_ANGLE = math.acos(B_COS/B_SPD2) * 180 / math.pi
-- if B_SIN < 0 then B_ANGLE = 360 - B_ANGLE end
-- end
B_ANGLE = math.acos(B_COS/B_SPD2) * 180 / math.pi
if B_SIN < 0 then B_ANGLE = 360 - B_ANGLE end
T_X_SPD = memory.read_s16_le( T_DATA + 0x70 ) / 1
T_Y_SPD = memory.read_s16_le( T_DATA + 0x74 ) / 1
T_X_POS = memory.read_s16_le( T_DATA + 0xB8 )
T_Y_POS = memory.read_s16_le( T_DATA + 0xC0 )
T_Z_POS = memory.read_s16_le( T_DATA + 0xBC )
T_SIN = memory.read_s16_le( T_DATA + 0xA4 )
T_COS = memory.read_s16_le( T_DATA + 0xA8 )
T_SPD = math.sqrt(T_X_SPD^2 + T_Y_SPD^2)
T_SPD2 = math.sqrt(T_SIN^2 + T_COS^2)
T_ANGLE = math.acos(T_COS/T_SPD2) * 180 / math.pi
if T_SIN < 0 then T_ANGLE = 360 - T_ANGLE end
gui.text(B_XTEXT+16, B_YTEXT - 40, "Bugs Bunny", "white")
gui.text(B_XTEXT, B_YTEXT + 0, "X pos :" .. string.format("%6.0f", B_X_POS), "white")
gui.text(B_XTEXT, B_YTEXT + 20, "Y pos :" .. string.format("%6.0f", B_Y_POS), "white")
gui.text(B_XTEXT, B_YTEXT + 40, "Y pos :" .. string.format("%6.0f", B_Z_POS), "white")
gui.text(B_XTEXT, B_YTEXT + 80, "Speed :" .. string.format("%6.1f", B_SPD), "white")
gui.text(B_XTEXT, B_YTEXT + 100, "Angle :" .. string.format("%6.1f", B_ANGLE), "white")
gui.text(T_XTEXT+50, T_YTEXT - 40, "Taz", "white")
gui.text(T_XTEXT, T_YTEXT + 0, "X pos :" .. string.format("%6.0f", T_X_POS), "white")
gui.text(T_XTEXT, T_YTEXT + 20, "Y pos :" .. string.format("%6.0f", T_Y_POS), "white")
gui.text(T_XTEXT, T_YTEXT + 40, "Y pos :" .. string.format("%6.0f", T_Z_POS), "white")
gui.text(T_XTEXT, T_YTEXT + 80, "Speed :" .. string.format("%6.1f", T_SPD), "white")
gui.text(T_XTEXT, T_YTEXT + 100, "Angle :" .. string.format("%6.1f", T_ANGLE), "white")
end
emu.frameadvance()
end