Script that displays on screen the terrain tiles. Allows to be able to see the level after triggering glitches that corrupt the graphics.
Now works correctly in worlds 1 and 4.
-- Genesis Tinhead - Terrain Display v1.2 by ThunderAxe31
local camera_x = 0x5674
local camera_y = 0x5676
local world_addr = 0x463D
local terrain_addr = 0x9712
local level_width_addr = 0x45CC
if memory.usememorydomain("68K RAM") then
while true do
local tile_x = memory.read_s16_be(camera_x)
local tile_y = memory.read_s16_be(camera_y)
local world = memory.read_u8(world_addr)
local level_width = memory.read_s16_be(level_width_addr)
if world == 3 then
for y = 0, 14 do
for x = 0, 20 do
local tile_id = memory.read_u8(terrain_addr +math.floor(tile_x/16) +math.floor(tile_y/16)*level_width +x +y*level_width)
local tile_x_pos = -(tile_x%16) +x*16
local tile_y_pos = -(tile_y%16) +y*16
if (tile_id>=34 and tile_id<=49) or (tile_id>=111 and tile_id<=143) or (tile_id>=149 and tile_id<=162) or (tile_id>=173 and tile_id<=176) then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15)
elseif tile_id==225 or (tile_id>=193 and tile_id<=201) then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFF00FF00)
elseif (tile_id>=202 and tile_id<=211) then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFF00FFFF)
elseif (tile_id>=218 and tile_id<=222) or (tile_id>=227 and tile_id<=229) then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFFFF0000)
elseif tile_id==213 or tile_id==214 then
gui.drawPolygon({{tile_x_pos+15,tile_y_pos},{tile_x_pos,tile_y_pos+15},{tile_x_pos+15,tile_y_pos+15}})
elseif tile_id==215 or tile_id==216 then
gui.drawPolygon({{tile_x_pos,tile_y_pos},{tile_x_pos+15,tile_y_pos+15},{tile_x_pos,tile_y_pos+15}})
elseif tile_id>=144 then
gui.pixelText(tile_x_pos +2, tile_y_pos +4, tile_id)
end
end
end
else
for y = 0, 14 do
for x = 0, 20 do
local tile_id = memory.read_u8(terrain_addr +math.floor(tile_x/16) +math.floor(tile_y/16)*level_width +x +y*level_width)
local tile_x_pos = -(tile_x%16) +x*16
local tile_y_pos = -(tile_y%16) +y*16
if (tile_id>=118 and tile_id<=143) or tile_id==229 or tile_id==230 or tile_id>=233 then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15)
elseif tile_id>=109 and tile_id<=117 then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFF00FF00)
elseif tile_id>=150 and tile_id<=157 then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFF00FFFF)
elseif (tile_id>=194 and tile_id<=197) or (tile_id>=223 and tile_id<=226) then
gui.drawRectangle(tile_x_pos, tile_y_pos, 15, 15, 0xFFFF0000)
elseif tile_id==144 then
gui.drawPolygon({{tile_x_pos,tile_y_pos},{tile_x_pos+15,tile_y_pos+7},{tile_x_pos+15,tile_y_pos+15},{tile_x_pos,tile_y_pos+15}})
elseif tile_id==145 then
gui.drawPolygon({{tile_x_pos,tile_y_pos+8},{tile_x_pos+15,tile_y_pos+15},{tile_x_pos,tile_y_pos+15}})
elseif tile_id==147 then
gui.drawPolygon({{tile_x_pos,tile_y_pos+7},{tile_x_pos+15,tile_y_pos},{tile_x_pos+15,tile_y_pos+15},{tile_x_pos,tile_y_pos+15}})
elseif tile_id==148 then
gui.drawPolygon({{tile_x_pos,tile_y_pos+15},{tile_x_pos+15,tile_y_pos+8},{tile_x_pos+15,tile_y_pos+15}})
elseif tile_id==158 or tile_id>=201 then
gui.pixelText(tile_x_pos +2, tile_y_pos +4, tile_id)
end
end
end
end
emu.frameadvance()
end
end