PICO-8 Wiki
Edit Page

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 9: Line 9:
 
The <code>cstore()</code> function copies a region of memory to the cartridge, modifying the cartridge file.
 
The <code>cstore()</code> function copies a region of memory to the cartridge, modifying the cartridge file.
   
This is useful for building PICO-8 development tools inside PICO-8, such as a specialized graphics editor that saves sprite or map data to another cartridge.
+
This is useful for building Pico-8 development tools inside Pico-8, such as a specialized graphics editor that saves sprite or map data to another cartridge.
   
 
You can load data from an arbitrary cartridge file using the [[Reload|reload()]] function.
 
You can load data from an arbitrary cartridge file using the [[Reload|reload()]] function.
Line 15: Line 15:
 
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.)
 
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 PICO-8 app, and does not work in the web player or [[Forum]].
+
This feature only works in the Pico-8 app, and does not work in the web player or [[Forum]].
   
The memory layout for cartridge data is identical to PICO-8 memory for the address region 0x0000-0x4300. See [[Memory]] for an explanation of memory and cartridge data, and for a description of the memory layout.
+
The memory layout for cartridge data is identical to Pico-8 memory for the address region 0x0000-0x4300. See [[Memory]] for an explanation of memory and cartridge data, and for a description of the memory layout.
   
 
'''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.
 
'''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.
Line 23: Line 23:
 
== Examples ==
 
== Examples ==
 
Consider a utility cartridge that generates map data and saves it to a different cartridge:
 
Consider a utility cartridge that generates map data and saves it to a different cartridge:
  +
<pre>
<syntaxhighlight lang="lua">
 
 
-- generate some map data
 
-- generate some map data
 
generate_map()
 
generate_map()
Line 29: Line 29:
 
-- save the map data to a separate cartridge
 
-- save the map data to a separate cartridge
 
cstore(0x2000, 0x2000, 0x1000, 'mygame.p8')
 
cstore(0x2000, 0x2000, 0x1000, 'mygame.p8')
  +
</pre>
</syntaxhighlight>
 
   
 
== See also ==
 
== See also ==
   
 
* [[Memory]]
 
* [[Memory]]
* [[Peek|<code>peek()</code>]]
+
* [[Peek|peek]]
* [[Poke|<code>poke()</code>]]
+
* [[Poke|poke]]
* [[Memcpy|<code>memcpy()</code>]]
+
* [[Memcpy|memcpy]]
* [[Reload|<code>reload()</code>]]
+
* [[Reload|reload]]
* [[Memset|<code>memset()</code>]]
+
* [[Memset|memset]]
 
[[Category:Reference]]
 
[[Category:Reference]]
 
[[Category:API]]
 
[[Category:API]]

Please note that all contributions to the PICO-8 Wiki are considered to be released under the CC-BY-SA

Cancel Editing help (opens in new window)

Template used on this page: