1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-05 01:19:02 -08:00

pointer boilerplate

this also fixes a subtle bug with Z targets,
since `(not 0) == false` in Lua
This commit is contained in:
Connor Olding 2015-03-26 16:36:44 -07:00
parent 9a57ee1975
commit d83517d31b
3 changed files with 20 additions and 24 deletions

View file

@ -35,20 +35,16 @@ function T_BL(x, y, s, color) T(x, y, s, color, "bottomleft") end
function T_TL(x, y, s, color) T(x, y, s, color, "topleft") end function T_TL(x, y, s, color) T(x, y, s, color, "topleft") end
function T_TR(x, y, s, color) T(x, y, s, color, "topright") end function T_TR(x, y, s, color) T(x, y, s, color, "topright") end
function pmask(p)
return bit.band(p, 0x7FFFFFFF)
end
function get_actor_count(i) function get_actor_count(i)
return R4(addrs.actor_counts[i].addr) return R4(addrs.actor_counts[i].addr)
end end
function get_first_actor(i) function get_first_actor(i)
return pmask(R4(addrs.actor_firsts[i].addr)) return deref(R4(addrs.actor_firsts[i].addr))
end end
function get_next_actor(addr) function get_next_actor(addr)
return pmask(R4(addr + actor_t.next.addr)) return deref(R4(addr + actor_t.next.addr))
end end
function count_actors() function count_actors()
@ -78,10 +74,10 @@ function iter_actors(counts)
addr = get_first_actor(at) addr = get_first_actor(at)
else else
addr = get_next_actor(addr) addr = get_next_actor(addr)
if addr == 0 then end
T_TR(0, 0, "no actor found", "yellow") if not addr then
return nil T_TR(0, 0, "no actor found", "yellow")
end return nil
end end
return at, ai, addr return at, ai, addr
@ -234,12 +230,13 @@ local function run()
local color = name:sub(1,1) == "?" and "red" or "orange" local color = name:sub(1,1) == "?" and "red" or "orange"
T_BL(0, 7, name, color) T_BL(0, 7, name, color)
local dmg = pmask(R4(addr + actor_t.damage_table.addr)) local dmg = deref(R4(addr + actor_t.damage_table.addr))
if dmg > 0 then if dmg then
for i = 0, 31 do for i = 0, 31 do
local name = damage_names[i] local name = damage_names[i]
local str = ('%9s: %02X'):format(name, R1(dmg + i)) local str = ('%9s: %02X'):format(name, R1(dmg + i))
local pos = 'topleft' local pos = 'topleft'
if i >= 16 then i = i - 16; pos = 'topright' end if i >= 16 then i = i - 16; pos = 'topright' end
T(0, i, str, nil, pos) T(0, i, str, nil, pos)
end end
@ -283,8 +280,8 @@ local function run()
T_BR(0, 0, ("unique:%3i"):format(#seen_strs_sorted)) T_BR(0, 0, ("unique:%3i"):format(#seen_strs_sorted))
if any > 0 then if any > 0 then
local cursor = pmask(addrs.z_cursor_actor()) local cursor = deref(addrs.z_cursor_actor())
local target = pmask(addrs.z_target_actor()) local target = deref(addrs.z_target_actor())
local z = target or cursor local z = target or cursor
if z then if z then
local num = R2(z) local num = R2(z)

View file

@ -58,6 +58,14 @@ function printf(fmt, ...)
print(fmt:format(...)) print(fmt:format(...))
end end
function is_ptr(ptr)
return bit.band(0xFF800000, ptr) == 0x80000000
end
function deref(ptr)
return is_ptr(ptr) and ptr - 0x80000000
end
function asciize(bytes) function asciize(bytes)
local str = "" local str = ""
local seq = false local seq = false

View file

@ -6,15 +6,6 @@ function gs2(addr, value)
W2(addr, value) W2(addr, value)
end end
function is_ptr(ptr)
local head = bit.band(0xFF000000, ptr)
return head == 0x80000000
end
function deref(ptr)
return is_ptr(ptr) and ptr - 0x80000000
end
function dump_half_row(addr) function dump_half_row(addr)
printf("%04X %04X %04X %04X", R2(addr), R2(addr+2), R2(addr+4), R2(addr+6)) printf("%04X %04X %04X %04X", R2(addr), R2(addr+2), R2(addr+4), R2(addr+6))
end end
@ -172,7 +163,7 @@ end
local last_addr local last_addr
while true do while true do
local addr = deref(addrs.room_ptr()) local addr = deref(addrs.room_pointer())
if addr and addr ~= last_addr then if addr and addr ~= last_addr then
console.clear() console.clear()
print('# setup: 00') print('# setup: 00')