Log In  

When compiled to HTML, it was surprisingly easy to inject data inside a PICO-8 cart.

The memory starting at 0x4300 (user data) maps to index 0x10DA1C of the heap in JavaScript. You can get and set the data easily using JavaScript (wait till the cart is loaded):

Module.setValue(0x10DA1C, 3);

Then read it or set in PICO-8 like this:

poke(0x4300, 3)

I'm using it for a multiplayer game where I want to allow several players selection only when there is an internet connection (I haven't worked on the multiplayer communication yet though).

The user data section is 6912 bytes long, so that's a lot of data for PICO-8.
Potentially this technique can be used to do all sort of really cool things like leaderboard inside the cart, downloadable levels or players, syncing several players together (chat, collaboration games, multiplayer games...).


  • Not sure if the index in the heap will remain stable across releases. Is it even stable across carts? It must be decided by some internal logic in Emscripten.
  • It works only in web mode of course.
  • It works only when embedded in a particular web page.
P#20500 2016-05-12 16:32 ( Edited 2016-05-24 07:58)

Thats really interesting. I've been looking how to do networking but with small luck. This might lead the way to a lot of interesting stuff.
Regarding the heap position: surely it might be changing.
BUT you can add a magic number in memory and scan the memory for it.

P#20502 2016-05-12 18:16 ( Edited 2016-05-12 22:16)

The next version seems to add gpio ports, which you can access within JavaScript. You can try to test it with the current BBS player by defining the variable pico8_gpio before the player loads (similar to the pico8_buttons variable commented out in exported HTML files). Once 0.1.7 comes out, I was thinking of using the gpio ports to make a simple Google demo, where you'd type something into PICO-8 and the Google search results would show up, then you could select a result and it'd open up in a new tab. :P
EDIT: I wonder if there will be an external (C?) API to access the gpio ports, without needing to hack into PICO-8's RAM?

P#20644 2016-05-16 11:17 ( Edited 2016-05-16 15:22)

Fayne, how do you know about GPIO ports in the new release?
Also, surely you should be able to write in these GPIO ports, i guess?

P#20646 2016-05-16 11:28 ( Edited 2016-05-16 15:28)
:: JTE

Strike off that "It works only when embedded in a particular web page." caveat, you can just use a bookmarklet or TamperMonkey script to inject JavaScript into even the BBS pages.

This could prove VERY interesting... Good work finding it. :3

P#20675 2016-05-16 20:37 ( Edited 2016-05-17 00:37)

I found the GPIO ports because zep mentioned that PICO-8 on the PocketC.H.I.P. "has gpio mapped to pCHIP's pins, but other platforms will also be non-standard in that way too (e.g. the web version now allows pins to be read/written via javascript)", so I decided to look through the source code and... yeah.
EDIT: And you can also see a SMALL bit of information about the GPIO ports documented on the manual. Just Ctrl-F for "gpio"

P#20680 2016-05-17 02:55 ( Edited 2016-05-17 06:56)


P#20688 2016-05-17 08:49 ( Edited 2016-05-17 12:49)

Speaking of which, I tried named pipes with the cartridge to do some I/O and it totally did not work the way I expected. The cart gets written to every time a dset is called., but is read once and never read again, so meh.

On the other hand, 128 bytes worth of GPIO is enough to do some good IO for networking, with a websocket-enabling bookmarklet and some vigorous handshaking protocol :)

Do you know when 0.1.7 is coming out?

P#20892 2016-05-20 03:58 ( Edited 2016-05-20 07:59)

Nice work! We definitely need some kind of network port. It should be called the user port according to my memory of 80s systems.

P#20901 2016-05-20 06:33 ( Edited 2016-05-20 10:33)
:: keiya

The Pico-8 is more a console than a home computer - remember, the downloadable version is more like the 'dev kit' than what a kid would have in their bedroom. Consoles usually called them 'expansion ports' or 'EXT ports'

P#20945 2016-05-20 14:48 ( Edited 2016-05-20 18:48)
:: JTE

I'm actually really excited at the prospect of those gpio pins being used to create some kind of standard game link cable setup for Pico-8 games to use.

P#21225 2016-05-24 03:38 ( Edited 2016-05-24 07:38)
:: impbox


P#21228 2016-05-24 03:58 ( Edited 2016-05-24 07:58)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-03-07 14:54 | 0.015s | 4194k | Q:34