-
oldxPos = 0
oldyPos = 0
oldsxPos = 0
local oldPV = 0;
bestr = {}
bestl = {}
local deltaPpm = "1"
local deltaPComp = 0
local deltaSComp = 0
local deltaPfr = 0
local lastDeltaP = 0
local lastDeltaS = 0
local lastDeltaPCurPos = 0
local lastDeltaSCurPos = 0
local save = false
local tInc = -0.5
local tRoot = 0
local fRoot = 0
local lagLog = {}
local lagSmoothLog = {}
local usualSpeed = 1
local usualScreen = 128*256
horzDisp = 600
function doStuff()
fr = emu.framecount()
newR = ""
if bestr[fr] == nil then
bestr[fr] = -1000000000
end
x1 = 0 --mainmemory.readbyte(0xA2D2)--Subpixel
x2 = mainmemory.readbyte(0x0A24) + mainmemory.readbyte(0x06A0)--Pixel
x3 = mainmemory.readbyte(0x06A1)--Superpixel
if x2 > 255 then
x3 = x3+1
x2 = x2-256
end
xPos = x3*256 + x2 --+ x1
if xPos < bestr[fr] then
col = "red"
else
col = "green"
end
y1 = 0 --mainmemory.readbyte(0xA2D6)--Subpixel
y2 = mainmemory.readbyte(0x0A22)--Pixel
y3 = 0 --mainmemory.readbyte(0xA2D4)--Superpixel
yPos = y2 --y3*256*256 + y2*256 + y1
tPred = tRoot+tInc*(emu.framecount()-fRoot)
timerVal = getTimerVal()
lagFrames = timerVal-tPred
lagLog[emu.framecount()] = lagFrames
--lagFrames = lagFrames
lagSmooth = 0.5*(lagLog[emu.framecount()-1]+lagFrames)-0.25
lagSmoothLog[emu.framecount()] = lagSmooth
if tastudio.engaged() then
if lagSmooth ~= lagSmoothLog[emu.framecount()-1] and lagSmoothLog[emu.framecount()-1] ~= nil then
--print("hi")
tastudio.setlag(emu.framecount(),true)
end
end
vx1 = 0 --mainmemory.readbyte(0xA2DA) --Subpixel
vx2 = 0 --mainmemory.readbyte(0xA2D9) --Pixel
xVel = vx2*256+vx1
if bestr[fr] < xPos then
newR = "oldR: "..string.upper(string.format("%x", math.floor(bestr[fr]/65536))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%65536)/256))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%256))))
bestr[fr] = xPos
if save == true then
if vx1 > 2 then
if fr%20 == 0 then
movie.save("C:/Users/Jake/Desktop/TAS/BizHawk-2.8-win-x64/Movies/Sonic Blast/Logs/"..fr.."-"..string.upper(string.format("%x", math.floor(bestr[fr]/65536))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%65536)/256))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%256)))))
end
end
end
end
vy1 = 0 --mainmemory.readbyte(0xA2DE)
vy2 = 0 --mainmemory.readbyte(0xA2DD)
yVel = vy2*256 + vy1
dx = xPos - oldxPos
dy = yPos - oldyPos
oldxPos = xPos
oldyPos = yPos
gui.text(horzDisp,200,"xPos: "..string.upper(string.format("%x", x3)).." "..string.upper(string.format("%x", x2)).." "..string.upper(string.format("%x", x1)),col)
gui.text(horzDisp,220,"xSpd: "..string.upper(string.format("%x", vx2)).." "..string.upper(string.format("%x", vx1)))
gui.text(horzDisp,240," dx: "..string.upper(string.format("%x", dx)))
gui.text(horzDisp,280,"yPos: "..string.upper(string.format("%x", y2)).." "..string.upper(string.format("%x", y1)))
gui.text(horzDisp,300,"ySpd: "..string.upper(string.format("%x", vy2)).." "..string.upper(string.format("%x", vy1)))
gui.text(horzDisp,320," dy: "..string.upper(string.format("%x", dy)))
gui.text(horzDisp,360,"Timer Predict: "..tPred)
gui.text(horzDisp,380,"Timer Actual: "..timerVal)
gui.text(horzDisp,400,"Lag Frames: "..lagFrames)
gui.text(horzDisp,420,"Lag Smooth: "..lagSmooth)
gui.text(horzDisp+30,450,"Lag Total: "..lagSmooth*2)
deltaPCurPos = xPos
if deltaPCurPos ~= lastDeltaPCurPos then
lastDeltaP = deltaPCurPos - (deltaPComp + deltaPpm * usualSpeed * (emu.framecount() - deltaPfr))
end
lastDeltaPCurPos = deltaPCurPos
lastDeltaSCurPos = deltaSCurPos
gui.text(horzDisp,500," dP: "..lastDeltaP)
gui.text(horzDisp,520," dPH: "..string.upper(string.format("%x", lastDeltaP)))
gui.text(horzDisp,540," dS: "..lastDeltaS)
gui.text(horzDisp,560," dSH: "..string.upper(string.format("%x", lastDeltaS)))
gui.text(horzDisp,180,newR)
gui.text(horzDisp,160,"BesR: "..string.upper(string.format("%x", math.floor(bestr[fr]/65536))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%65536)/256))).." "..string.upper(string.format("%x",math.floor((bestr[fr]%256)))))
--gui.text(horzDisp,140,"Bestl: "..string.upper(string.format("%x", math.floor(bestl[fr]/65536))).." "..string.upper(string.format("%x",math.floor((bestl[fr]%65536)/256))).." "..string.upper(string.format("%x",math.floor((bestl[fr]%256)))))
end
event.onframeend(doStuff)
function dP(pm)
deltaPpm = pm
deltaPfr = emu.framecount()
deltaPComp = xPos
deltaSComp = sxPos
end
function tRes()
tRoot = getTimerVal()
fRoot = emu.framecount()
end
function res()
bestr = {}
bestl = {}
end
function nosave()
save = false
end
function yessave()
save = true
end
function getTimerVal()
tH = mainmemory.readbyte(0x1FC5)
tT = mainmemory.readbyte(0x1FC4)
tU = mainmemory.readbyte(0x1FC3)
tM = mainmemory.readbyte(0x1FC2)
return (tH*100+tT*10+tU)*30+tM
end
tRes()