User File #638209639679064429

Upload All User Files

#638209639679064429 (unlisted) - DisplayInfo.lua

DisplayInfo.lua
167 downloads
Uploaded 5/29/2023 1:32 PM by SBD (see all 61)
-- This is a helper script that displays the values you need to know
-- in order to run DisplayWaitTimes.lua

local TextY = client.getwindowsize() * 0x10

local ScreenAddress, YAddress, XAddress, DirAddress = 0xC6EC, 0xC6ED, 0xC6EE, 0xC6EF
local PlaytimeLo = 0xC622     -- lowbyte of the ingame clock
local RoomAddress = 0xC62C    -- first byte of the second part of the save file
local SaveFileLength = 0x269  -- half the length of the second part of the save file
local InventoryStart = 0xC688 -- = B-button
local InventoryLength = 8     -- half the length of the inventory


local table = {}
local list = {0xB6, 0xB7, 0xC6, 0xC7, 0xD6, 0xD7}
for i = 1, 6 do
    table[list[i]] = {}
    for Y = 0, 0xFF do
        table[list[i]][Y] = {}
    end
end

for line in io.lines("ShipPosition.txt") do
    Frame, Screen, Y, X = tonumber(string.sub(line,1,4)), tonumber(string.sub(line,6,7),16), tonumber(string.sub(line,9,10),16), tonumber(string.sub(line,12,13),16)
    table[Screen][Y][X] = Frame - 1
end
table[0xB6][0x38][0x48] = 1855 -- fix last entry



while true do

    -- calculate checksum
    local D,E = 0,0
	for i = 0, SaveFileLength do
		E = E + memory.readbyte(RoomAddress + 2*i)
		D = D + memory.readbyte(RoomAddress + 2*i + 1)
	end

    -- subtract Pirate Ship
	E = E - memory.readbyte(ScreenAddress) - memory.readbyte(XAddress)
	D = D - memory.readbyte(YAddress) - memory.readbyte(DirAddress)

    -- subtract inventory
    for i = 0, InventoryLength do
        E = E - memory.readbyte(InventoryStart + 2*i)
        D = D - memory.readbyte(InventoryStart + 2*i + 1)
    end

    D = (D + math.floor(E / 0x100)) % 0x100
    E = E % 0x100
    

    local Screen, Y, X = memory.readbyte(ScreenAddress), memory.readbyte(YAddress), memory.readbyte(XAddress)

    if ((table[Screen] or {}) [Y] or {}) [X] then -- sanity check so the script doesn't crash during resets
        local Frame = table[Screen][Y][X] + memory.readbyte(PlaytimeLo)%2 --Ship only moves when PlaytimeLo is even
        if Frame == 1856 then Frame = 0 end

        gui.text(0, TextY       , string.format("frame: %d", Frame))
        gui.text(0, TextY + 0x10, string.format("odd  : %02X", D))
        gui.text(0, TextY + 0x20, string.format("even : %02X", E))
    end

    emu.frameadvance()
end