smbot/monitor_tiles.lua
2018-06-30 20:13:54 +02:00

55 lines
1.4 KiB
Lua

-- keep track of which blocks are actually seen in the game.
-- play back an all-levels TAS with this script running.
local floor = math.floor
local open = io.open
local pairs = pairs
local print = print
local util = require("util")
local R = memory.readbyteunsigned
local W = memory.writebyte
local function S(addr) return util.signbyte(R(addr)) end
local game = require("smb") -- just for advance()
local serial = require "serialize"
local serialize = serial.serialize
local deserialize = serial.deserialize
local fn = 'seen_tiles.lua'
local seen = deserialize(fn) or {}
local function mark_tile(sx, sy, kind)
if not seen[kind] then
seen[kind] = true
print(("%02X"):format(kind))
serialize(fn, seen)
end
end
local function handle_tiles()
--local tile_col = R(0x6A0)
local tile_scroll = floor(R(0x73F) / 16) + R(0x71A) * 16
local tile_scroll_remainder = R(0x73F) % 16
for y = 0, 12 do
for x = 0, 16 do
local col = (x + tile_scroll) % 32
local t
if col < 16 then
t = R(0x500 + y * 16 + (col % 16))
else
t = R(0x5D0 + y * 16 + (col % 16))
end
local sx = x * 16 + 8 - tile_scroll_remainder
local sy = y * 16 + 40
mark_tile(sx, sy, t)
end
end
end
while true do
handle_tiles()
game.advance()
end