m
some time to kill = Felice pedantically fixes more PICO-8 capitalization
(New reference article: cstore) Tags: apiedit Visual edit |
m (some time to kill = Felice pedantically fixes more PICO-8 capitalization) |
||
(2 intermediate revisions by the same user not shown) | |||
The <code>cstore()</code> function copies a region of memory to the cartridge, modifying the cartridge file.
This is useful for building
You can load data from an arbitrary cartridge file using the [[Reload|reload()]] function.
If a filename is provided and there exists a cartridge with that name, the data is patched into the appropriate location. If there is no file with the given name, a new empty cartridge is created with the data patched in. Unlike [[Reload|reload()]], the filename must end in <code>.p8</code> or <code>.p8.png</code> if the intended cartridge file has that extension. (The filename extension is not inferred from existing files.)
This feature only works in the
The memory layout for cartridge data is identical to
'''Caution:''' The <code>cstore()</code> function modifies the cartridge file. This operation cannot be undone. Be sure to keep a copy of your original cartridge files, and test to make sure data is written to the correct file and memory location.
== Examples ==
Consider a utility cartridge that generates map data and saves it to a different cartridge:
<syntaxhighlight lang="lua">
-- generate some map data
generate_map()
-- save the map data to a separate cartridge
cstore(0x2000, 0x2000, 0x1000, 'mygame.p8')
</syntaxhighlight>
== See also ==
* [[Memory]]
* [[Peek|<code>peek()</code>]]
* [[Poke|<code>poke()</code>]]
* [[Memcpy|<code>memcpy()</code>]]
* [[Reload|<code>reload()</code>]]
* [[Memset|<code>memset()</code>]]
[[Category:Reference]]
[[Category:API]]
|