2016-01-13 09:21:24 -08:00
|
|
|
require "lib.setup"
|
|
|
|
require "boilerplate"
|
2016-01-13 07:56:18 -08:00
|
|
|
require "addrs"
|
2015-03-13 12:13:56 -07:00
|
|
|
|
|
|
|
-- precalculate hamming weights of bytes
|
2016-01-13 09:21:24 -08:00
|
|
|
local hamming_weight = {}
|
2015-03-13 12:13:56 -07:00
|
|
|
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
|
|
|
|
|
2016-01-13 09:21:24 -08:00
|
|
|
local function hamming_of(addr, size)
|
|
|
|
local weight = 0
|
|
|
|
local bytes = mainmemory.readbyterange(addr, size)
|
2015-03-13 12:13:56 -07:00
|
|
|
for k,v in pairs(bytes) do
|
|
|
|
if v ~= 0 then
|
|
|
|
weight = weight + hamming_weight[tonumber(v, 16)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return weight
|
|
|
|
end
|
|
|
|
|
2016-01-13 09:21:24 -08:00
|
|
|
local function hamming_of_A(a)
|
2015-05-01 11:15:53 -07:00
|
|
|
return hamming_of(a.addr, a.type)
|
|
|
|
end
|
|
|
|
|
2015-03-13 12:13:56 -07:00
|
|
|
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
|
2015-05-01 11:15:53 -07:00
|
|
|
local ingame = hamming_of_A(addrs.scene_flags_ingame)
|
|
|
|
local save = hamming_of_A(addrs.scene_flags_save)
|
2015-03-13 12:13:56 -07:00
|
|
|
print("current", current)
|
|
|
|
print("ingame ", ingame)
|
|
|
|
print("save ", save)
|