Currently, there are two ways to access pico8 memory: peek/poke[2/4] and @/%/$
The @/%/$ operators look a bit weird but are faster and better overall.
However, I think their main drawback is that they don't replace the need for poke, causing code that uses them to necessarily be quite inconsistent, imbalanced and weird whenever it needs to combine peeks with pokes.
I wanted to check how hard it would be to add the ability to poke into @/%/$, so I created the following fork of z8lua that implements it:
https://github.com/thisismypassport/z8lua
Here's how it works:
-- simple poke @0x1000 = 0x1 ?@0x1000 -- outputs 1 -- use of $ as both peek and poke (copying 4 bytes of memory) $0x8000 = $0 -- multiple assignment @1,%2,$4 = 1,2,4 ?@1 -- outputs 1 ?%2 -- outputs 2 ?$4 -- outputs 4 -- compound assignment - worked automatically @1 += 0x80 ?@1 -- outputs 129 (since previously was 1) -- poke metatables meta = setmetatable({}, { __peek=function(self) return "peek" end, __poke=function(self, value) print("poke "..value) end }) @meta ..= " works" -- prints: "poke peek works" -- reason for case added in check_conflict, for reference function f(a, b) @a, a = b, b end f(0x100, 7) ?@0x100 -- outputs 7 -- note: there is a bug in z8lua where @"1" doesn't work. -- Since pico8 itself doesn't have this bug, I decided not to fix it - not for peek nor for poke. |
Comments welcome.
Personally, I think this would be great. I know I or someone else proposed it to @zep in the past, but I think there might have been a technical issue with implementing it.
But, really, it would be the ideal behavior, especially moving forward with the upcoming Picotron platform.
[Please log in to post a comment]