1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-05 05:49:02 -08:00
mm/Lua/lib/flag manager.lua
Connor Olding 1acbaba58c be super strict about globals
theres still a lot of work to do\nsince most scripts just set globals explicitly\nthis is still better than implied globals though
2016-01-13 09:21:24 -08:00

51 lines
1.7 KiB
Lua

local function scene_flag_get_bb(scene, word, bit_)
local byte = scene*0x14 + word*4 + math.floor(3 - bit_/8)
byte = byte + addrs.scene_flags_ingame.addr
local bitmask = bit.lshift(1, bit_ % 8)
return byte, bitmask
end
local function scene_flag_get(scene, word, bit_)
local byte, bitmask = scene_flag_get_bb(scene, word, bit_)
return bit.band(R1(byte), bitmask) ~= 0
end
-- TODO: check if current scene is scene id
-- if it is, adjust scene_flag_current_x so it doesn't overwrite ingame flags
local function scene_flag_reset(scene, word, bit_)
local byte, bitmask = scene_flag_get_bb(scene, word, bit_)
W1(byte, bit.band(R1(byte), 0xFF - bitmask))
end
local function scene_flag_set(scene, word, bit_)
local byte, bitmask = scene_flag_get_bb(scene, word, bit_)
W1(byte, bit.bor(R1(byte), bitmask))
end
local function event_flag_get_bb(byte, bit_)
byte = byte + addrs.week_event_reg.addr
local bitmask = bit.lshift(1, bit_ % 8)
return byte, bitmask
end
local function event_flag_get(byte, bit_)
local byte, bitmask = event_flag_get_bb(byte, bit_)
return bit.band(R1(byte), bitmask) ~= 0
end
local function event_flag_reset(byte, bit_)
local byte, bitmask = event_flag_get_bb(byte, bit_)
W1(byte, bit.band(R1(byte), 0xFF - bitmask))
end
local function event_flag_set(byte, bit_)
local byte, bitmask = event_flag_get_bb(byte, bit_)
W1(byte, bit.bor(R1(byte), bitmask))
end
return globalize{
scene_flag_get_bb = scene_flag_get_bb,
scene_flag_get = scene_flag_get,
scene_flag_reset = scene_flag_reset,
scene_flag_set = scene_flag_set,
event_flag_get_bb = event_flag_get_bb,
event_flag_get = event_flag_get,
event_flag_reset = event_flag_reset,
event_flag_set = event_flag_set,
}