diff --git a/Lua/A common.lua b/Lua/A common.lua index cfffecc..c0b9c60 100755 --- a/Lua/A common.lua +++ b/Lua/A common.lua @@ -232,6 +232,11 @@ return { bomb_counter = AG(0x1CD4, 1), z_cursor_actor = AG(0x1DF8, 4), z_target_actor = AG(0x1DFC, 4), + current_scene_flags_2 = AG(0x1E58, 4), -- note: I use SRAM ordering here + current_scene_flags_3 = AG(0x1E5C, 4), + current_scene_flags_1 = AG(0x1E68, 4), + current_scene_flags_4 = AG(0x1E6C, 4), + current_scene_flags_5 = AG(0x1E74, 4), link_actor = merge(Actor(AA(0,0).addr), { item_in_hand = AA(0x148, 1), diff --git a/Lua/addrs.lua b/Lua/addrs.lua index 3a0246b..74e134b 100755 --- a/Lua/addrs.lua +++ b/Lua/addrs.lua @@ -1,4 +1,4 @@ -versions = { +versions = { -- sha1 hashes of .z64s ['D6133ACE5AFAA0882CF214CF88DABA39E266C078'] = "US10", ['2F0744F2422B0421697A74B305CB1EF27041AB11'] = "USDE", ['9743AA026E9269B339EB0E3044CD5830A440C1FD'] = "USGC", diff --git a/Lua/count flags.lua b/Lua/count flags.lua new file mode 100755 index 0000000..63df48b --- /dev/null +++ b/Lua/count flags.lua @@ -0,0 +1,34 @@ +require "addrs" + +-- precalculate hamming weights of bytes +hamming_weight = {} +for i = 0, 255 do + local w = 0 + for b = 0, 7 do + w = w + bit.band(bit.rshift(i, b), 1) + end + hamming_weight[i] = w +end + +function hamming_of(addr, size) + weight = 0 + bytes = mainmemory.readbyterange(addr, size) + for k,v in pairs(bytes) do + if v ~= 0 then + weight = weight + hamming_weight[tonumber(v, 16)] + end + end + return weight +end + +print("###") +local current = 0 +for i = 1, 5 do + local addr = addrs['current_scene_flags_'..tostring(i)].addr + current = current + hamming_of(addr, 4) +end +local ingame = hamming_of(addrs.scene_flags_ingame.addr, 0x960) +local save = hamming_of(addrs.scene_flags_save.addr, 0x960) +print("current", current) +print("ingame ", ingame) +print("save ", save)