diff --git a/main.lua b/main.lua index 4d619fd..f742719 100644 --- a/main.lua +++ b/main.lua @@ -132,6 +132,11 @@ local function boolean_xor(a, b) return true end +local function signbyte(x) + if x >= 128 then x = 256 - x end + return x +end + local _invlog2 = 1 / log(2) local function log2(x) return log(x) * _invlog2 end @@ -309,7 +314,7 @@ local function getxy(i, x_addr, y_addr, pageloc_addr, hipos_addr) end if hipos_addr ~= nil then local hipos = S(hipos_addr + i) - sy = sy + (hipos - 1) * 256 + sy = sy + (signbyte(hipos) - 1) * 256 end return sx, sy @@ -414,9 +419,7 @@ local function handle_hammers() x, y = x + 8, y + 8 local state = R(0x2A + i) -- skip coin effect states. not interactable; we don't care! - if state ~= 0 - and state >= 0x30 - then + if state ~= 0 and state >= 0x30 then mark_sprite(x, y, state + 1) else mark_sprite(0, 0, 0) @@ -933,12 +936,14 @@ local function doit(dummy) mark_sprite(x + 8, y + 24, -powerup - 1) local vx, vy = S(0x57), S(0x9F) - insert(extra_input, vx) - insert(extra_input, vy) + -- i shouldn't need to do this if it's signed, but apparently... + insert(extra_input, signbyte(vx) * 16) + insert(extra_input, signbyte(vy) * 16) if cfg.time_inputs then for i=2,5 do - insert(extra_input, band(total_frames, lshift(1, i))) + local v = band(total_frames, lshift(1, i)) == 0 and -256 or 256 + insert(extra_input, v) end end