Web
Analytics
Log In  

0

I'm any of the pico-8 pros so I probably won't use Peek and Poke, but can I please get an explanation. The Wikia doesn't really help

peek and poke
P#44724 2017-09-28 17:04 ( Edited 2018-02-18 16:48)

::

Peek and Poke are very "low level" commands.

They let you edit memory.

Normally you store data in variables. With names and everything. Like this :
MyVar = 42
But if you happened to know the raw memory address of some unused memory, you could use "poke" to put a number in that memory and "peek" to get it back out. Without ever using a variable.

You could do that, but that would be crazy.

Instead they're mostly used for accessing things you're "not supposed" to touch. Things in the system that there isn't a lua variable for, but the Pico8 operating system stores in its own memory.

For example, Pico8 has eight different video modes, but there's no lua code that switches from one mode to another. If you want to change video modes, you have to use "poke" to edit the memory where the OS keeps track of what video mode it's supposed to be in. I happen to know that's at address 0x5f2c. And I happen to know that the "Horizontal Mirror" mode is mode 5.

poke(0x5f2c, 5)

See. Easy as pie. .ɘiq ƨɒ yƨɒƎ .ɘɘƧ

P#44726 2017-09-28 18:47

::

> You could do that, but that would be crazy.

:p

They also let you do things like use a screen buffer (draw some things to a part of memory and then show it on the screen later). There's a big ol chunk of memory starting at 0x4300 just for these purposes.

You can also compress graphics more efficiently if you store values in sprite memory as data.. I wrote some things about this and some memory stuff in general including understanding binary and hex here: https://www.lexaloffle.com/bbs/?tid=29966 . And you can also update the display manually by poking addresses starting at 0x6000.

Not everything can be saved though. A lot only exists during runtime.

P#44734 2017-09-28 20:59 ( Edited 2017-09-28 21:04)

::

There isn't bright line between "crazy" and "advanced technique'.

P#44742 2017-09-28 23:27

::

@apLundell

I forget who coined it, But there's a variation of that I heard quoted once that goes:

"The fine line between insanity and genius is measured only by success."

:D

P#44838 2017-10-01 21:03

::

Feedback and edits to the wiki are welcome. I recommend the Memory article, to which the Poke and Peek articles refer.

http://pico-8.wikia.com/wiki/Memory

The addressable memory feature of Pico-8 is intended to resemble old-fashioned computers. Abstract functions such as spr() or print() do fancy things to values in memory that the hardware (or in this case, fantasy hardware) converts into a graphical image. As with the old computers, Pico-8 gives you direct access to this memory to make advanced techniques possible.

With the old computers, you usually access memory directly because it is faster than using the abstract functions for a certain task. One oddity with Pico-8 is that it isn't always faster to, say, manipulate the screen data with peek and poke than it is to use the built-in functions. Some of Pico-8's graphics functions actually have faster access to the memory than a program does with peek and poke.

In other cases, peek and poke are the only way Pico-8 gives you to accomplish certain things. For example, there is currently no way for a program to generate or modify sound and music (such as changing notes in a song during gameplay) using a built-in function other than poking new values into the sound and music region of addressable memory.

P#44876 2017-10-02 23:15

::

One oddity with Pico-8 is that it isn't always faster to, say, manipulate the screen data with peek and poke than it is to use the built-in functions. Some of Pico-8's graphics functions actually have faster access to the memory than a program does with peek and poke.

I believe this comes from its console heritage. It's pretending it has special hardware for drawing sprites and tiles.

P#44881 2017-10-03 10:17

::

@apLundell
Is there some documentation of the different video modes you can change by altering the memory at 0x5f2c? Never seen it mentioned and it could be really cool for things I'm doing.

P#45193 2017-10-14 00:17

::

@capnmarcy I had found this before https://www.lexaloffle.com/bbs/?tid=2547

P#45194 2017-10-14 01:13

::

@apLundell I'd say it gets this for "free" by nature of memory accesses just naturally being much slower going through one by one peeks/pokes via an interpreted language. But it is a very "realistic" byproduct; so it could definitely make that claim. :)

P#49393 2018-02-18 16:48

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-10-20 06:16 | 0.251s | 1572k | Q:18