PICO-8 Wiki
m (→‎See also: formatting)
m (some time to kill = Felice pedantically fixes more PICO-8 capitalization)
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.

Revision as of 02:46, 30 April 2019

cstore( destaddr, sourceaddr, len, [filename] )
Store a region of memory in the cartridge file, or another cartridge file.
destaddr
The address of the first byte of the destination in the cartridge.

sourceaddr
The address of the first byte in memory to copy.

len
The length of the memory region to copy, as a number of bytes.

filename
If specified, the filename of a cartridge to which data is written. The default is to write to the currently loaded cartridge.

The cstore() 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.

You can load data from an arbitrary cartridge file using the 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(), the filename must end in .p8 or .p8.png 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.

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 cstore() 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:

-- generate some map data
generate_map()

-- save the map data to a separate cartridge
cstore(0x2000, 0x2000, 0x1000, 'mygame.p8')

See also