Path: blob/master/Assets/Lua/SNES/Donkey Kong Country 3.lua
2 views
--Author pasky1312local cx3local cy4local data = 0x3C000056local function camera()7cx = mainmemory.read_u16_le(0x493)8cy = mainmemory.read_u16_le(0x497)9end1011function findbit(p)12return 2 ^ (p - 1)13end1415function hasbit(x, p)16return x % (p + p) >= p17end1819local function hex(val)20val = string.format("%X",val)21return val22end2324memory.usememorydomain("CARTROM")2526local function player()27local pbase = 0x87828for i = 0,1,1 do29pbase = pbase + (i * 0x6E)30if mainmemory.read_u8(pbase + 0x24) > 0 then31local point = memory.read_u16_le(mainmemory.read_u16_le(pbase + 0x24) + 0x3C8003)32local properties = mainmemory.read_u16_le(pbase + 0x1E)33local x = mainmemory.read_u16_le(pbase + 0x12) - cx34local y = mainmemory.read_u16_le(pbase + 0x16) - cy35local xoff = memory.read_s8(point + data)36local yoff = memory.read_s8(point + 2 + data)37local xrad = memory.read_u8(point + 4 + data)38local yrad = memory.read_u8(point + 6 + data)3940if hasbit(properties,findbit(15)) then -- If facing right41xoff = xoff * -142xrad = xrad * -143elseif hasbit(properties,findbit(16)) then -- Upside down?44yoff = yoff * -145yrad = yrad * -146end474849gui.drawBox(x+xoff,y+yoff,x+xoff+xrad,y+yoff+yrad,0xFF0000FF,0x400000FF)50end51end52end5354local function enemy()55local start = 0x95456local base57local x58local y59local xoff60local yoff61local xrad62local yrad63local properties64local point65local active66for i = 0,15,1 do67base = start + (i * 0x6E)68active = mainmemory.read_u8(base + 0x30)69properties = mainmemory.read_u16_le(base + 0x1E)7071if mainmemory.read_u8(base + 0x24) > 0 then72point = memory.read_u16_le(mainmemory.read_u16_le(base + 0x24) + 0x3C8003)73properties = mainmemory.read_u16_le(base + 0x1E)74x = mainmemory.read_u16_le(base + 0x12) - cx75y = mainmemory.read_u16_le(base + 0x16) - cy76xoff = memory.read_s8(point + data)77yoff = memory.read_s8(point + 2 + data)78xrad = memory.read_u8(point + 4 + data)79yrad = memory.read_u8(point + 6 + data)808182if hasbit(properties,findbit(15)) then -- If facing right83xoff = xoff * -184xrad = xrad * -185elseif hasbit(properties,findbit(16)) then -- Upside down?86yoff = yoff * -187yrad = yrad * -188end8990gui.drawBox(x+xoff,y+yoff,x+xoff+xrad,y+yoff+yrad,0xFFFF0000,0x40FF0000)91end92end93end9495while true do96camera()97player()98enemy()99emu.frameadvance()100end101102