User File #51326125340200575

Upload All User Files

#51326125340200575 -

maptracker.lua
1 comment, 751 downloads
Uploaded 11/20/2018 11:15 AM by fmp (see all 10)
local TILE_ADDR = 0x00A0

-- drawing
local CANVAS_WIDTH = 600
local CANVAS_HEIGHT = 450

local ROOM_SIZE = 12
local ROOM_GAP = 0
local TILE_SIZE = ROOM_SIZE * 2 + ROOM_GAP * 1

local X_OFFSET = 6
local Y_OFFSET = 50

local DRAW_POS = {
	[1] = { x = 0, y = 0 },
	[2] = { x = 1, y = 0 },
	[3] = { x = 0, y = 1 },
	[4] = { x = 1, y = 1 }
}

-- colors

local HM = 0xC0B8A8 -- houses
local HC = 0xA89868 -- hyrule castle
local AT = HC -- aga's tower
local EX = 0x706890 -- escape
local SY = 0x204020 -- sanctuary
local CV = 0x684830 -- caves

local EP = 0x80A870 -- eastern palace
local DP = 0x807838 -- desert palace
local TH = 0x987870 -- tower of hera

local PD = 0x909090 -- palace of darkness
local SP = 0x7890F8 -- swamp palace
local SW = 0x605030 -- skull woods
local TT = 0x787888 -- thieves town
local IP = 0xA8E0E8 -- ice palace
local MM = 0x408068 -- misery mire
local TR = 0x583028 -- turtle rock
local GT = 0xA09058 -- ganon's tower

local GE = 0x984848 -- empty gt TILEs
local EM = 0x606060 -- empty TILEs

local COMPLETE = 0xFFFF0000
local VISITED = 0xFFFFFF00
local UNVISITED = 0xFFAAAAAA
local CURRENT = 0xFF00FFFF

local BLACK = 0xFF000000
local WHITE = 0xFFFFFFFF

local OPAQUE = 0xFF000000
local TRANS = 0x99000000

local function get_color(color, opacity)
	return bit.bor(color, opacity)
end -- end get_color

-- room number from quadrant variables
local R1, R2, R3, R4 = 1, 2, 3, 4

local TILES_TO_VALS = {
	['RX'] = {
		R1 = { A9 = 0x00, AA = 0x00 },
		R2 = { A9 = 0x01, AA = 0x00 },
		R3 = { A9 = 0x00, AA = 0x02 },
		R4 = { A9 = 0x01, AA = 0x02 }
	},

	['A9AA'] = {
			[0x00] = {
				[0x00] = R1,
				[0x02] = R3
			},
			[0x01] = {
				[0x00] = R2,
				[0x02] = R4
		}
	}
}

local function stop_running()
	running = false
end -- stop_running

local function end_thing()
	the_canvas.Dispose()
	stop_running()
end -- end_thing

local function initialize()
	running = true

	memory.usememorydomain("WRAM")

	the_canvas = gui.createcanvas(CANVAS_WIDTH, CANVAS_HEIGHT)
	the_canvas.set_TopMost(true)
	the_canvas.SetTitle("Map completion")
	the_canvas.add_FormClosing(stop_running)
	the_canvas.set_TopMost(true)

	event.onexit(end_thing)
end -- end initialize

--[==[
Format:
	[0x##] = {          -- room id
		c = XX          -- color
		p = AABA        -- room pattern
		r = { p }       -- pattern as table
		v = 0100        -- rooms reachable without glitches
		x = { v }       -- reachability as table; no dupes
	}
]==]

local TILE_DATA = {
	[0x00] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0x01] = { c = HC, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1100, x = { A = 1, B = 0 } },
	[0x02] = { c = SY, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x03] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x04] = { c = TR, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x05] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x06] = { c = SP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x07] = { c = TH, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x08] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0011, x = { A = 0, B = 0, C = 1, D = 1 } },
	[0x09] = { c = PD, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1100, x = { A = 1, B = 1, C = 0, D = 0 } },
	[0x0A] = { c = PD, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x0B] = { c = PD, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x0C] = { c = GT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x0D] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x0E] = { c = IP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },
	[0x0F] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },

	[0x10] = { c = GT, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x11] = { c = EX, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x12] = { c = SY, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x13] = { c = TR, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x14] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x15] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x16] = { c = SP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x17] = { c = TH, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x18] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0x19] = { c = PD, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x1A] = { c = PD, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x1B] = { c = PD, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1110, x = { A = 1, B = 1, C = 0 } },
	[0x1C] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x1D] = { c = GT, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1100, x = { A = 1, B = 0 } },
	[0x1E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0111, x = { A = 0, B = 1, C = 1, D = 1 } },
	[0x1F] = { c = IP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },

	[0x20] = { c = AT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x21] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x22] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 0011, x = { A = 0, B = 1 } },
	[0x23] = { c = TR, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0x24] = { c = TR, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x25] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x26] = { c = SP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x27] = { c = TH, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x28] = { c = SP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x29] = { c = SW, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0x2A] = { c = PD, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x2B] = { c = PD, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1011, x = { A = 1, B = 0, C = 1 } },
	[0x2C] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x2D] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x2E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0x2F] = { c = CV, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1011, x = { A = 1, B = 0, C = 1 } },

	[0x30] = { c = AT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1010, x = { A = 1, B = 0, C = 1, D = 0 } },
	[0x31] = { c = TH, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x32] = { c = EX, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x33] = { c = DP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x34] = { c = SP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x35] = { c = SP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x36] = { c = SP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x37] = { c = SP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x38] = { c = SP, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0x39] = { c = SW, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },
	[0x3A] = { c = PD, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x3B] = { c = PD, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0x3C] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x3D] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x3E] = { c = IP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 0111, x = { A = 0, B = 1, C = 1 } },
	[0x3F] = { c = IP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },

	[0x40] = { c = AT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1011, x = { A = 1, B = 0, C = 1 } },
	[0x41] = { c = HC, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x42] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1100, x = { A = 1, B = 0 } },
	[0x43] = { c = DP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1101, x = { A = 1, B = 0, C = 1 } },
	[0x44] = { c = TT, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x45] = { c = TT, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x46] = { c = SP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x47] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x48] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x49] = { c = SW, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x4A] = { c = PD, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x4B] = { c = PD, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x4C] = { c = GT, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x4D] = { c = GT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x4E] = { c = IP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1100, x = { A = 1, B = 1, C = 0 } },
	[0x4F] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },

	[0x50] = { c = HC, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x51] = { c = HC, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x52] = { c = HC, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x53] = { c = DP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x54] = { c = SP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x55] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x56] = { c = SW, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x57] = { c = SW, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x58] = { c = SW, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x59] = { c = SW, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x5A] = { c = PD, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0x5B] = { c = GT, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x5C] = { c = GT, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1101, x = { A = 1, B = 0, C = 1 } },
	[0x5D] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1110, x = { A = 1, B = 1, C = 1, D = 0 } },
	[0x5E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0111, x = { A = 0, B = 1, C = 1, D = 1 } },
	[0x5F] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },

	[0x60] = { c = HC, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x61] = { c = HC, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x62] = { c = HC, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x63] = { c = DP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1010, x = { A = 1, B = 0, C = 1 } },
	[0x64] = { c = TT, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },
	[0x65] = { c = TT, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },
	[0x66] = { c = SP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x67] = { c = SW, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x68] = { c = SW, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x69] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x6A] = { c = PD, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x6B] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x6C] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1011, x = { A = 1, B = 0, C = 1, D = 1 } },
	[0x6D] = { c = GT, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1010, x = { A = 1, B = 0, C = 1 } },
	[0x6E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0x6F] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },

	[0x70] = { c = EX, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1000, x = { A = 1, B = 0, C = 0, D = 0 } },
	[0x71] = { c = EX, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1011, x = { A = 1, B = 0, C = 1, D = 1 } },
	[0x72] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x73] = { c = DP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x74] = { c = DP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0x75] = { c = DP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x76] = { c = SP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x77] = { c = TH, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x78] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x79] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x7A] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x7B] = { c = GT, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x7C] = { c = GT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x7D] = { c = GT, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x7E] = { c = IP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 0111, x = { A = 0, B = 1, C = 1 } },
	[0x7F] = { c = IP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1010, x = { A = 1, B = 0, C = 1 } },

	[0x80] = { c = EX, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1100, x = { A = 1, B = 0 } },
	[0x81] = { c = EX, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x82] = { c = EX, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x83] = { c = DP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x84] = { c = DP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x85] = { c = DP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x86] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x87] = { c = TH, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x88] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x89] = { c = EP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1100, x = { A = 1, B = 0 } },
	[0x8A] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x8B] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x8C] = { c = GT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0x8D] = { c = GT, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x8E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0x8F] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },

	[0x90] = { c = MM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0x91] = { c = MM, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x92] = { c = MM, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x93] = { c = MM, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x94] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x95] = { c = GT, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0x96] = { c = GT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1011, x = { A = 1, B = 0, C = 1 } },
	[0x97] = { c = MM, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x98] = { c = MM, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 0011, x = { A = 0, B = 1 } },
	[0x99] = { c = EP, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 0111, x = { A = 0, B = 1, C = 1 } },
	[0x9A] = { c = GE, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0x9B] = { c = GT, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x9C] = { c = GT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0x9D] = { c = GT, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0x9E] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0111, x = { A = 0, B = 1, C = 1, D = 1 } },
	[0x9F] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },

	[0xA0] = { c = MM, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1100, x = { A = 1, B = 1, C = 0 } },
	[0xA1] = { c = MM, p = 'AABA', r = { 'A', 'A', 'B', 'A' }, v = 1101, x = { A = 1, B = 0 } },
	[0xA2] = { c = MM, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xA3] = { c = MM, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0xA4] = { c = TR, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0xA5] = { c = GT, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xA6] = { c = GT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xA7] = { c = TH, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1000, x = { A = 1, B = 0, C = 0 } },
	[0xA8] = { c = EP, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xA9] = { c = EP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xAA] = { c = EP, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xAB] = { c = TT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0xAC] = { c = TT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0xAD] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xAE] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0xAF] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1000, x = { A = 1, B = 0, C = 0, D = 0 } },

	[0xB0] = { c = AT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0xB1] = { c = MM, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xB2] = { c = MM, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xB3] = { c = MM, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1010, x = { A = 1, B = 0, C = 1 } },
	[0xB4] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xB5] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xB6] = { c = TR, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0xB7] = { c = TR, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0xB8] = { c = EP, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0xB9] = { c = EP, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xBA] = { c = EP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1100, x = { A = 1, B = 1, C = 0, D = 0 } },
	[0xBB] = { c = TT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xBC] = { c = TT, p = 'ABCB', r = { 'A', 'B', 'C', 'B' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xBD] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xBE] = { c = IP, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 0101, x = { A = 0, B = 1, C = 1 } },
	[0xBF] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0110, x = { A = 0, B = 1, C = 1, D = 0 } },

	[0xC0] = { c = AT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xC1] = { c = MM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0xC2] = { c = MM, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xC3] = { c = MM, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xC4] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xC5] = { c = TR, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0xC6] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xC7] = { c = TR, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xC8] = { c = EP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0xC9] = { c = EP, p = 'AABB', r = { 'A', 'A', 'B', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xCA] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xCB] = { c = TT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xCC] = { c = TT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xCD] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xCE] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0xCF] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },

	[0xD0] = { c = AT, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },
	[0xD1] = { c = MM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1111, x = { A = 1, B = 1, C = 1, D = 1 } },
	[0xD2] = { c = MM, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xD3] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xD4] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xD5] = { c = TR, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1010, x = { A = 1, B = 0 } },
	[0xD6] = { c = TR, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xD7] = { c = EM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xD8] = { c = EP, p = 'ABAC', r = { 'A', 'B', 'A', 'C' }, v = 0101, x = { A = 0, B = 1, C = 1 } },
	[0xD9] = { c = EP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0011, x = { A = 0, B = 1, C = 1 } },
	[0xDA] = { c = EP, p = 'AABC', r = { 'A', 'A', 'B', 'C' }, v = 0010, x = { A = 0, B = 1, C = 0 } },
	[0xDB] = { c = TT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xDC] = { c = TT, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xDD] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xDE] = { c = IP, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0100, x = { A = 0, B = 1, C = 0, D = 0 } },
	[0xDF] = { c = CV, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 0011, x = { A = 0, B = 0, C = 1 } },

	[0xE0] = { c = AT, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 1110, x = { A = 1, B = 1, C = 1, D = 0 } },
	[0xE1] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xE2] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xE3] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0111, x = { A = 0, B = 1, C = 1, D = 1 } },
	[0xE4] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xE5] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xE6] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xE7] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xE8] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xE9] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xEA] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xEB] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0xEC] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xED] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 1111, x = { A = 1, B = 1 } },
	[0xEE] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xEF] = { c = CV, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 0111, x = { A = 0, B = 1, C = 1 } },

	[0xF0] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xF1] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xF2] = { c = HM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0xF3] = { c = HM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0xF4] = { c = HM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0001, x = { A = 0, B = 0, C = 0, D = 1 } },
	[0xF5] = { c = HM, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0010, x = { A = 0, B = 0, C = 1, D = 0 } },
	[0xF6] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xF7] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xF8] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xF9] = { c = CV, p = 'ABBB', r = { 'A', 'B', 'B', 'B' }, v = 0111, x = { A = 0, B = 1 } },
	[0xFA] = { c = CV, p = 'AAAA', r = { 'A', 'A', 'A', 'A' }, v = 1111, x = { A = 1 } },
	[0xFB] = { c = CV, p = 'ABBB', r = { 'A', 'B', 'B', 'B' }, v = 0111, x = { A = 0, B = 1 } },
	[0xFC] = { c = CV, p = 'ABCD', r = { 'A', 'B', 'C', 'D' }, v = 0000, x = { A = 0, B = 0, C = 0, D = 0 } },
	[0xFD] = { c = CV, p = 'ABAA', r = { 'A', 'B', 'A', 'A' }, v = 1111, x = { A = 1, B = 1 } },
	[0xFE] = { c = CV, p = 'ABAB', r = { 'A', 'B', 'A', 'B' }, v = 0101, x = { A = 0, B = 1 } },
	[0xFF] = { c = CV, p = 'ABCC', r = { 'A', 'B', 'C', 'C' }, v = 1111, x = { A = 1, B = 1, C = 1 } },

}

-- room tracking
local prev = nil
local prev_quad = nil
local check_map = false

-- drawing
local function draw_tile(tile, quad_id)
	if tile == nil then return end

	local x = (bit.band(tile, 0x0F) * TILE_SIZE + 1) + X_OFFSET
	local y = ((bit.band(tile, 0xF0) / 16) * TILE_SIZE + 1) + Y_OFFSET

	the_canvas.DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK, BLACK) -- clear only this section

	local d = TILE_DATA[tile]
	local r = d.r

	local room_completion_colors = { 0, 0, 0, 0 }

	for i=1, 4 do
		room_completion_colors[i] =
			quad_id == TILE_DATA[tile].r[i] and CURRENT
				or UNVISITED and OPAQUE or TRANS
		the_canvas.DrawRectangle(
				x + (ROOM_SIZE) * DRAW_POS[i].x,
				y + (ROOM_SIZE) * DRAW_POS[i].y,
				ROOM_SIZE,
				ROOM_SIZE,
				nil,
				room_completion_colors[i]
			)
		if TILE_DATA[tile].x[r[i]] == 0 then
			--[[the_canvas.DrawText(
				x + (ROOM_SIZE) * DRAW_POS[i].x + 1,
				y + (ROOM_SIZE) * DRAW_POS[i].y - 1,
				"X",
				0x55FFFFFF,
				0
			)]]
		end
	end

	local C0

	if quad_id then
		C0 = CURRENT
	else
		C0 = UNVISITED
	end

	-- vertical separators
	local C1 = r[1] == r[2] and room_completion_colors[1] or C0
	local C2 = r[3] == r[4] and room_completion_colors[3] or C0

	the_canvas.DrawLine(x + ROOM_SIZE + ROOM_GAP, y + ROOM_GAP,
							x + ROOM_SIZE + ROOM_GAP, y + ROOM_SIZE,
							C1)

	the_canvas.DrawLine(x + ROOM_GAP + ROOM_SIZE, y + ROOM_GAP + ROOM_GAP + ROOM_SIZE,
							x + ROOM_GAP + ROOM_SIZE, y + ROOM_SIZE + ROOM_SIZE,
							C2)

	-- horizontal separators
	local C3 = r[1] == r[3] and room_completion_colors[1] or C0
	local C4 = r[2] == r[4] and room_completion_colors[2] or C0

	the_canvas.DrawLine(x + ROOM_GAP + ROOM_GAP, y + ROOM_GAP + ROOM_SIZE,
							x + ROOM_SIZE, y + ROOM_GAP + ROOM_SIZE,
							C3)

	the_canvas.DrawLine(x + ROOM_GAP + ROOM_GAP + ROOM_SIZE, y + ROOM_GAP + ROOM_SIZE,
							x + ROOM_SIZE + ROOM_SIZE, y + ROOM_GAP + ROOM_SIZE,
							C4)

	local C5 = d.p == 'AAAA' and C1 or C0

	the_canvas.DrawPixel(x + ROOM_GAP + ROOM_SIZE, y + ROOM_GAP + ROOM_SIZE, BLACK)
	the_canvas.DrawPixel(x + ROOM_GAP + ROOM_SIZE, y + ROOM_GAP + ROOM_SIZE, C5)

	the_canvas.DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, C0, nil)
end -- end draw_tile

local function draw_all()
	the_canvas.Clear(BLACK)
	for i=0, 0xFF do
		draw_tile(i)
	end

	the_canvas.Refresh()
end -- end draw_all

local function draw_minimap()
	the_canvas.DrawRectangle(405, 5, 150, 150, BLACK, BLACK)
	the_canvas.DrawRectangle(419, 19, 128, 128, CURRENT, BLACK)
	local linky = memory.read_u16_le(0x20) % 0x200

	local linkx = memory.read_u16_le(0x22) % 0x200

	the_canvas.DrawRectangle(420+(linkx/4), 20+(linky/4), 4, 4, VISITED)
end

-- main
local function do_main()
	while running do
		emu.frameadvance()

		local uw_flag = memory.readbyte(0x00A1)
		local ow_flag = memory.readbyte(0x001B)

		if not (uw_flag == 0x00 and ow_flag == 0x01) then
			if check_map and prev ~= nil then
				draw_tile(prev)
				prev = nil
			end
			check_map = false
		else
			if memory.readbyte(0x0010) == 0x07 then
				check_map = true
			else
				check_map = false
				draw_tile(prev)
				prev = nil
			end
		end
		
		if check_map then
			local tile = memory.readbyte(TILE_ADDR)
			local A9 = memory.readbyte(0xA9)
			local AA = memory.readbyte(0xAA)

			local quadrant = TILES_TO_VALS.A9AA[A9][AA]
			local quad_id = TILE_DATA[tile].r[quadrant]

			if quadrant ~= prev_quad or tile ~= prev then
				prev_quad = quadrant
			end

			draw_tile(tile, quad_id)

			if tile ~= prev then
				draw_tile(prev)
				prev = tile
			end
		end

		draw_minimap()

		the_canvas.Refresh()
	end
end -- end do_main

initialize()
draw_all()
do_main()
Dimon12321
on 11/20/2018 6:57 PM
Oh my God! More than 500 lines of code!