User File #65593981198691761

Upload All User Files

#65593981198691761 - Kirby Tilt 'n' Tumble LUA Script

kirby_tilt_and_tumble_lua_2.lua
328 downloads
Uploaded 8/24/2020 12:38 AM by dekutony (see all 376)
Uploading this lua script for kirby here just in case. It was made for the Japanese version. Note: I didn't make this.
memory.usememorydomain("System Bus")
AddrXBig		= 0xFFA5;
AddrXSmall		= 0xFFA6;
AddrXSub		= 0xFFA7;
AddrXSpd		= 0xFFD2; --big endian 16
AddrYBig		= 0xFFA8;
AddrYSmall		= 0xFFA9;
AddrYSub		= 0xFFAA;
AddrYSpd		= 0xFFD4; --big endian 16
AddrZBig		= 0xFFAB;
AddrZSmall		= 0xFFAC;
AddrZSub		= 0xFFAD;
AddrZSpd		= 0xFFD6; --big endian 16

--C134,135,136 are the 3 digits of the timer
AddrFrameTimer  = 0xC137;

PrevX = 0
XDiff = 0
PrevY = 0
YDiff = 0
PrevZ = 0
ZDiff = 0
PrevFrameTimer = -1
PrevFrame = -1


XPosTable = {}
YPosTable = {}

XColor = "white"
XDiffColor = "white"
XSpdColor = "white"

--gui.defaultPixelFont("gens")
gui.defaultPixelFont("fceux")

while true do
	emu.frameadvance();
	--Position
	XSmall=memory.readbyte(AddrXSmall);
	XBig=memory.readbyte(AddrXBig);
	X=XBig*256+XSmall;
	
	XSub=memory.readbyte(AddrXSub);
	X = (X + (XSub/256))
	
	XDiff = X - PrevX;
	PrevX = X;
	
	--in this game vertical travel is what needs to be compared, generally
	--[[if (XPosTable[emu.framecount()] == null or XPosTable[emu.framecount()] == X) then
		XPosTable[emu.framecount()] = X;
		XColor = "white";
	elseif (XPosTable[emu.framecount()] < X) then
		XPosTable[emu.framecount()] = X;
		XColor = "green";
	else
		XColor = "red";
	end]]
	--[[if XDiff>1.5 then
		XDiffColor = "green"
	elseif XDiff<1.5 then
		XDiffColor = "red"
	else
		XDiffColor = "white"
	end]]
	
	YSmall=memory.readbyte(AddrYSmall);
	YBig=memory.readbyte(AddrYBig);
	Y=YBig*256+YSmall;
	YSub=memory.readbyte(AddrYSub);
	Y = (Y + (YSub/256))
	
	YDiff = Y - PrevY;
	PrevY = Y;
	
	if (YPosTable[emu.framecount()] == null or YPosTable[emu.framecount()] == Y) then
		YPosTable[emu.framecount()] = Y;
		YColor = "white";
	elseif (YPosTable[emu.framecount()] > Y) then
		YPosTable[emu.framecount()] = Y;
		YColor = "green";
	else
		YColor = "red";
	end
	
	-- negative 2 pixels per frame is the target speed
	if YDiff<-2 then
		YDiffColor = "green"
	elseif YDiff>-2 then
		YDiffColor = "red"
	else
		YDiffColor = "white"
	end
	
	ZSmall=memory.readbyte(AddrZSmall);
	ZBig=memory.readbyte(AddrZBig);
	Z=ZBig*256+ZSmall;
	ZSub=memory.readbyte(AddrZSub);
	Z = (Z + (ZSub/256))
	
	ZDiff = Z - PrevZ;
	PrevZ = Z;
	
	--the speed variables are not proving useful/accurate compared to diff
	--Speed
	--XSpd=memory.read_s16_be(AddrXSpd)/256;
	--YSpd=memory.read_s16_be(AddrYSpd)/256;
	--ZSpd=memory.read_s16_be(AddrZSpd)/256;
	
	gui.pixelText(3, 2, string.format("% 9.3f",X),XColor)
	--gui.pixelText(10, 18, string.format("% 9.3f",XSpd),XSpdColor)
	gui.pixelText(3, 11, string.format("% 9.3f",XDiff),XDiffColor)
	
	gui.pixelText(58, 2, string.format("% 9.3f",Y),YColor)
	--gui.pixelText(65, 18, string.format("% 9.3f",YSpd))
	gui.pixelText(58, 11, string.format("% 9.3f",YDiff),YDiffColor)
	
	gui.pixelText(113, 2, string.format("% 7.3f",Z))
	--gui.pixelText(120, 18, string.format("% 9.3f",ZSpd))
	gui.pixelText(113, 11, string.format("% 7.3f",ZDiff))
	
	--Determine Lag
	FrameTimer = memory.readbyte(AddrFrameTimer);
	if (FrameTimer == PrevFrameTimer and PrevFrame ~= emu.framecount()) then
		--Check if all our diffs are 0, but positions are not
		if (XDiff == 0 and YDiff == 0 and ZDiff == 0 and (X ~= 0 or Y ~= 0 or Z ~= 0)) then
			tastudio.setlag(emu.framecount(),true)
		end
	end
	PrevFrameTimer = FrameTimer
	PrevFrame = emu.framecount()
	
end