Skip to content

Instantly share code, notes, and snippets.

@jshiell
Created June 12, 2020 07:49
Show Gist options
  • Save jshiell/5846da20710ec93fd37b0cac7c953f9f to your computer and use it in GitHub Desktop.
Save jshiell/5846da20710ec93fd37b0cac7c953f9f to your computer and use it in GitHub Desktop.
Read/write an array of bits in PICO-8
buffer_base = 0x4300
buffer_width = 127
buffer_height = 127
function init()
memset(buffer_base, 0, (buffer_width * buffer_height) / 8)
end
function set(x, y, value)
local offset = (x + (buffer_width * y))
local mem_offset = offset / 8
local shift = offset % 8
local current = peek(buffer_base + mem_offset)
if value == 0 then
poke(buffer_base + mem_offset, current & ~(1 << shift))
else
poke(buffer_base + mem_offset, current | (1 << shift))
end
end
function get(x, y)
local offset = (x + (buffer_width * y))
local mem_offset = offset / 8
local shift = offset % 8
return (peek(buffer_base + mem_offset) >> shift) & 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment