local x, y, camx, camy, ttype, ttypehigh, tcolor, warpdest
memory.usememorydomain('System Bus')
function bitswap (swappy)
nib2 = bit.band(swappy,0xF)
return (nib2*0x10+bit.rshift(swappy,4))
end
function gettile (wx,wy)
hix = bit.rshift(bit.band(0xFF00,wx),8)
hiy = bit.rshift(bit.band(0xFF00,wy),8)
lox = bit.band(0xFF,wx)
loy = bit.band(0xFF,wy)
tiley = bit.band(bitswap(bit.band(hiy,0x0F))+bit.band(bitswap(loy),0x0F),0xFF)
tilex = bitswap(bit.band(hix,0x0F))+bit.band(bitswap(lox-0x4),0x0F)
rawloc = bit.band(tiley*0x100+tilex+0xc000,0xFFFF)
return (rawloc)
end
while true do
x = memory.read_u16_be(0xa913) -- position in level
y = memory.read_u16_be(0xa911)
camx = memory.read_u16_be(0xa902)
camy = memory.read_u16_be(0xa900)
for i = -5,9,1 do
for j = -5,9,1 do
ttype = bit.band(memory.readbyte(gettile(camx+i*16-12,camy+j*16)),0x7F)
if (ttype<0x60) and (ttype~=0x46) and (ttype~=0x47) then
if (ttype==0x2b) or (ttype==0x2c) then -- breakable
tcolor = 'PINK'
elseif (ttype==0x44) or (ttype==0x45) then -- ladder
tcolor = 'BROWN'
elseif (ttype==0x48) then -- door
tcolor = 'LIMEGREEN'
elseif (ttype==0x40) or (ttype==0x41) or (ttype==0x42) or (ttype==0x3a) or (ttype==0x3b) then -- platform
tcolor = 'YELLOW'
else -- solid or unidentified
tcolor = 'RED'
end
gui.drawBox(i*16+64-(camx%16),j*16+64,(i+1)*16+63-(camx%16),(j+1)*16+63,tcolor)
end
end
end
gui.drawText(3,3,string.format("%X",gettile(x,y-32))..' '..string.format("%X",bit.band(memory.readbyte(gettile(x,y-32)),0x7F)),'RED')
gui.drawText(3,12,string.format("%X",gettile(x,y-16))..' '..string.format("%X",bit.band(memory.readbyte(gettile(x,y-16)),0x7F)),'RED')
gui.drawText(3,21,string.format("%X",gettile(x,y))..' '..string.format("%X",bit.band(memory.readbyte(gettile(x,y)),0x7F)),'RED')
emu.frameadvance()
end