User File #65651239038411573

Upload All User Files

#65651239038411573 - Lua for GBC Daiku no Gen-san

Daiku v1.1.lua
269 downloads
Uploaded 8/26/2020 2:31 PM by ThunderAxe31 (see all 111)
Lua script that displays on screen the position and speed of the player. It does also display the position of enemies and other entities.
--GBC Daiku no Gen-san v1.1 by ThunderAxe31

local addr_x = 0xCD99
local addr_y = 0xCD9C

local x_com = 0
local x_sub = 0
local x_pix = 0
local y_com = 0
local y_sub = 0
local y_pix = 0

local old_x_com = 0
local old_y_com = 0

local framecount = -1

local obj_start = 0xC980
local obj_block = 0x40
local obj_slots = 15

local offset_type = 0x30
local offset_x    = 0x1A
local offset_y    = 0x1D

local addr_cam_x_pix = 0xFF91
local addr_cam_x_sub = 0xFF99
local addr_cam_y_pix = 0xFF93
local addr_cam_y_sub = 0xFF9B

function mainroutine()
	x_com = memory.read_s24_le(addr_x)
	x_sub = bit.band(0xFF, x_com)
	x_pix = math.floor(x_com /256)
	y_com = memory.read_s24_le(addr_y)
	y_sub = bit.band(0xFF, y_com)
	y_pix = math.floor(y_com /256)
	
	local speed_x_com = x_com - old_x_com
	local speed_y_com = y_com - old_y_com
	
	old_x_com = x_com
	old_y_com = y_com
	
	gui.pixelText(0, 128, string.format("X:%4i%4i\nY:%4i%4i", x_pix, x_sub, y_pix, y_sub), 0xFFFFFFFF, 0xFF000000)
	
	if framecount == emu.framecount()-1 then
		gui.pixelText(45, 128, string.format("%+4i\n%+4i", speed_x_com, speed_y_com), 0xFFFFFFFF, 0xFF000000 )
	else
		gui.pixelText(45, 128, "    \n ", 0xFFFFFFFF, 0xFF000000 )
	end
	
	framecount = emu.framecount()
	
	local cam_x = memory.read_u8(addr_cam_x_pix)
	local cam_y = memory.read_u8(addr_cam_y_pix)
	
	if cam_x < 32 then
		cam_x = cam_x +(memory.read_s8(addr_cam_x_sub)+1)*256
	else
		cam_x = cam_x +memory.read_s8(addr_cam_x_sub)*256
	end
	if cam_y < 32 then
		cam_y = cam_y +(memory.read_s8(addr_cam_y_sub)+1)*256
	else
		cam_y = cam_y +memory.read_s8(addr_cam_y_sub)*256
	end
	
	for i=0, obj_slots do
		if memory.read_u8(obj_start +i *obj_block +offset_type) ~= 0 then
			local obj_x = memory.read_s16_le(obj_start +i *obj_block +offset_x)
			local obj_y = memory.read_s16_le(obj_start +i *obj_block +offset_y)
			gui.pixelText(
			math.max(math.min(obj_x-cam_x-7, 147), 0),
			math.max(math.min(obj_y-cam_y+8, 114), 0),
			string.format("%3i\n%3i", obj_x, obj_y), 0xFFFFFFFF, 0x7F000000 )
		end
	end
end

event.onloadstate(mainroutine)
tastudio.onbranchload(mainroutine)
--event.onframeend(mainroutine)

while true do
	mainroutine()		
	emu.frameadvance()
end