User File #73353016102155940

Upload All User Files

#73353016102155940 - Fist of the North Star HUD v6

hokuto2-fancy.lua
229 downloads
Uploaded 8/8/2021 10:58 AM by MESHUGGAH (see all 292)
  • Added but disabled zero page addresses shown for debugging purposes
  • Changed powerup to ID
--[[ MESHUGGAH's HUD Template

NES Hokuto no Ken 2
NES Fist of the North Star
Bizhawk 2.6.2

This template features an example to NES Hokuto no Ken 2 (Japan) and NES Fist of the North Star (USA).
	1 player X, Y
	1 camera X
	enemy data
	enemy data size 19

To use this in FCEUX:
	replace memory.read_u16_le with memory.readword
	
To use BIGGER text for the hud:
	replace gui.pixelText with gui.pixelText
--]]

-- v	RAM addresses of position values in hexadecimal format
-- Variable array: P1 X, P1 Y, Camera X
local v = {
0x30,
0x32,
0x26
}
-- p	positon values stored here after reading memory from location v (memory.read_u16_le or memory.readword)
-- Position array
local p = {} for i = 1, table.getn(v) do p[i] = 0 end

-- pp	previous position values stored here to compare with new positions on next frame
-- Previous position array
local pp = {} for k,v in pairs(p) do pp[k] = v end

-- Lag indicators array
local l = {} for i = 1, 4 do l[i] = 0 end

-- Horizontal lag counter
local h = 0

-- Text settings
gui.defaultTextBackground("#5f000000")
gui.defaultForeground("#ffffffff")
gui.defaultPixelFont("0");


-----------------------------------------------------------------------

local function objects()

-- display ID if alive
	for i = 0, 1 do
		-- TODO: this condition uses 0x385 "direction" / 0x386 "unknown" instead of "alive" address!!!
		if memory.readbyte(0x386+i*19) ~= 0 then
			gui.pixelText(memory.readbyte(0x388+i*19),memory.readbyte(0x38b+i*19)+0,i)
			for j = 0, 18 do
				gui.pixelText(60+i*20,40+j*9,string.format("%3d",memory.readbyte(0x388+i*19+j)))
			end
			-- helping text
			gui.pixelText(0,40,string.format("X\n0 / 128\n?\nY\n?\n?\nDirection\n?\n?\n?\nTIMER\n?\nHP\n?\nB - 15\n?\nID\n?\n?"))
		end
	end

end

local function zero()
	for i = 1, 2 do
		for j = 0, 18 do
			gui.pixelText(120+i*20,40+j*9,string.format("%3d",memory.readbyte(0x7a+j*i)))
		end
	end
	
	for j = 0, 18 do
			--gui.pixelText(120,40+j*9,string.format("%3d: %3d",j+0x7a,memory.readbyte(0x7a+j)))
	end
	
		for j = 0, 18 do
			gui.pixelText(180,40+j*9,string.format("%3d: %3d",j+0x94,memory.readbyte(0x94+j)))
	end
	
	--projectiles info
	for i = 0, 2 do
		--if memory.readbyte() ~= 0 then
		--gui.pixelText(200,200+i*8,string.format("%d: %3d, %3d",i,memory.readbyte(0x95+i*10),memory.readbyte(0x97+i*10)))
		--end
	end
end

local function hud()
	-- Camera X pos
	gui.pixelText(50,0,string.format("Cam X %5d (%d)",p[3],p[3]-pp[3]))
	
	i = 0, 9 do gui.pixelText(120,100+i*8,memory.readbyte(0x360+i))
	gui.pixelText(120,180,"States ^") end
	gui.pixelText(120,188,string.format("boss hp %d",memory.readbyte(0x6a)))
	gui.pixelText(120,196,string.format("boss hp %d",memory.readbyte(0x7a)))
	
	-- Level
	gui.pixelText(50,8,string.format("Level %d=S%d\n",memory.readbyte(0xee),memory.readbyte(0xee)+1))
	
	-- X pos, Y pos
	gui.pixelText(150,0,string.format("X %5d (%d)",p[1],p[1]-pp[1]))
	gui.pixelText(150,8,string.format("Y %5d (%d)",p[2],p[2]-pp[2]))
	
	-- Level timer
	gui.pixelText(120,8,string.format("%d%d", memory.readbyte(0x65), memory.readbyte(0x64)))
end

-- Lag indicators
local function lag()
	l[1] = memory.readbyte(0x1ea)
	l[2] = memory.readbyte(0x1f7)
	--print(p[1],pp[1],p[3],pp[3])
	gui.pixelText(170,70,string.format("Lag indicators\n%3d %3d %3d\n",memory.readbyte(0x1ea),memory.readbyte(0x1f7),memory.readbyte(0x601)))
	
	if (l[2] == 200 and l[2] == l[4]) then
			gui.pixelText(110,100,string.format("increased\nlag level\n@ %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() 
		h = h +1
		gui.pixelText(80,90,string.format("HORIZONTAL LAG\n@ %5d\ntotal: %3d",emu.framecount(),h))
	end
	
	l[3] = l[1]
	l[4] = l[2]
end

while true do
	emu.frameadvance()
	
	-- 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])
	
	-- Clear text
	gui.cleartext()
	
	-- Display lag information
	--lag()
	
	-- Display object's ID and X and Y pos and a lot of other data
	objects()
	
	-- Display some addresses from zero page
	--zero()
	hud()
	
	-- Store positions to compare them in next frame
	for k,v in pairs(p) do pp[k] = v end
end