28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/array.h>
32 #include <sifteo/asset/loader.h>
33 #include <sifteo/abi.h>
80 static const unsigned LIMIT = _SYS_FS_MAX_OBJECT_KEYS - 1;
83 static const unsigned MAX_SIZE = _SYS_FS_MAX_OBJECT_SIZE;
90 ASSERT(k >= 0 && k <= LIMIT);
99 operator const _SYSObjectKey ()
const {
return sys; }
113 return StoredObject(LIMIT - _SYS_lti_counter(
"Sifteo.StoredObject", 0));
145 int read(
void *buffer,
unsigned bufferSize, _SYSVolumeHandle volume = 0)
const {
146 return _SYS_fs_objectRead(sys, (uint8_t*)buffer, bufferSize, volume);
172 int write(
const void *data,
unsigned dataSize)
const {
173 return _SYS_fs_objectWrite(sys, (
const uint8_t*)data, dataSize);
187 template <
typename T>
188 int read(T &buffer, _SYSVolumeHandle volume = 0)
const {
189 return read((
void*) &buffer,
sizeof buffer, volume);
193 template <
typename T>
194 int readObject(T &buffer, _SYSVolumeHandle volume = 0)
const {
195 return read((
void*) &buffer,
sizeof buffer, volume);
204 template <
typename T>
206 return write((
const void*) &buffer,
sizeof buffer);
210 template <
typename T>
212 return write((
const void*) &buffer,
sizeof buffer);
240 _SYSVolumeHandle sys;
255 operator const _SYSVolumeHandle ()
const {
return sys; }
262 template <
unsigned T>
265 volumes.
setCount(_SYS_fs_listVolumes(volType, &volumes.
begin()->sys,
301 return (_SYSVolumeHandle) _SYS_fs_runningVolume();
316 return (_SYSVolumeHandle) _SYS_fs_previousVolume();
357 void debugInstanceCounter(
int delta) {
359 static int counter = 0;
367 typedef _SYSUUID UUID;
368 typedef _SYSMetadataCubeRange CubeRange;
370 static const unsigned MAX_BOOTSTRAP_GROUPS = _SYS_MAX_METADATA_ITEM_BYTES /
sizeof(_SYSMetadataBootAsset);
384 : vol(0), offset(0) {
385 debugInstanceCounter(1);
395 debugInstanceCounter(1);
401 debugInstanceCounter(-1);
415 if (this->vol != vol) {
417 offset = _SYS_elf_map(vol);
440 void *
metadata(
unsigned key,
unsigned minSize,
unsigned *actualSize)
const {
441 return _SYS_elf_metadata(vol, key, minSize, actualSize);
459 template <
typename T>
461 return reinterpret_cast<const T*
>(
metadata(key,
sizeof(T), actualSize));
472 template <
typename T>
474 return reinterpret_cast<T*
>(
translate(reinterpret_cast<uint32_t>(va)));
492 const char *
title(
const char *placeholder =
"(untitled)")
const {
493 const char *p = metadata<char>(_SYS_METADATA_TITLE_STR);
494 return p ? p : placeholder;
503 const char *
package(
const char *placeholder =
"(none)")
const {
504 const char *p = metadata<char>(_SYS_METADATA_PACKAGE_STR);
505 return p ? p : placeholder;
514 const char *
version(
const char *placeholder =
"(none)")
const {
515 const char *p = metadata<char>(_SYS_METADATA_VERSION_STR);
516 return p ? p : placeholder;
525 const UUID *p = metadata<UUID>(_SYS_METADATA_UUID);
527 return p ? p : &zero;
566 group.sys.pHdr =
translate(meta->groupHdr);
569 image.sys.pAssetGroup =
reinterpret_cast<uint32_t
>(&group);
570 image.sys.width = meta->width;
571 image.sys.height = meta->height;
572 image.sys.frames = meta->frames;
573 image.sys.format = meta->format;
574 image.sys.pData =
translate(meta->pData);
581 void getBootstrap(BootstrapAssetGroups &groups, BootstrapAssetConfiguration &config)
584 auto vec = metadata<_SYSMetadataBootAsset>(_SYS_METADATA_BOOT_ASSET, &actual);
588 unsigned count = actual /
sizeof *
vec;
589 for (
unsigned i = 0; i != count; ++i) {
614 _SYSFilesystemInfo sys;
623 _SYS_fs_info(&sys,
sizeof sys);
638 return sys.freeUnits;
643 return sys.freeUnits * sys.unitSize;
648 return sys.totalUnits;
653 return sys.totalUnits * sys.unitSize;
664 return sys.systemUnits;
669 return sys.systemUnits * sys.unitSize;
674 return sys.launcherElfUnits;
679 return sys.launcherElfUnits * sys.unitSize;
684 return sys.launcherObjUnits;
689 return sys.launcherObjUnits * sys.unitSize;
694 return sys.gameElfUnits;
699 return sys.gameElfUnits * sys.unitSize;
704 return sys.gameObjUnits;
709 return sys.gameObjUnits * sys.unitSize;
714 return sys.selfElfUnits;
719 return sys.selfElfUnits * sys.unitSize;
724 return sys.selfObjUnits;
729 return sys.selfObjUnits * sys.unitSize;
void getBootstrap(BootstrapAssetGroups &groups, BootstrapAssetConfiguration &config)
Get the bootstrap assets for this Volume, returning the result in the provided BootstrapAssetConfigur...
Definition: filesystem.h:581
static unsigned capacity()
Retrieve the capacity of this array, always constant at compile-time.
Definition: array.h:64
static Volume previous()
Return the Volume corresponding to the previously running program.
Definition: filesystem.h:315
StoredObject(_SYSObjectKey k)
Initialize from a system object.
Definition: filesystem.h:86
uint32_t totalUnits()
Total space, in allocation units.
Definition: filesystem.h:647
uint32_t gameElfUnits()
Space used by all game ELF binaries, in allocation units.
Definition: filesystem.h:693
static Volume running()
Return the Volume corresponding to the currently running program.
Definition: filesystem.h:300
T & append(const T &newItem)
Synonym for push_back()
Definition: array.h:115
void translate(const _SYSMetadataBootAsset &meta, AssetGroup &group)
Translate a bootstrap asset metadata record to an AssetGroup.
Definition: filesystem.h:540
A bundle of compressed tile data, for use by AssetImages.
Definition: group.h:54
A Volume that has been mapped into the secondary flash memory region.
Definition: filesystem.h:348
void translate(const _SYSMetadataImage *meta, AssetImage &image, AssetGroup &group)
Translate an image metadata record to an AssetImage.
Definition: filesystem.h:563
uint32_t allocationUnitSize()
Return the size of one allocation unit.
Definition: filesystem.h:632
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
int read(T &buffer, _SYSVolumeHandle volume=0) const
Template wrapper for read() of fixed-size objects.
Definition: filesystem.h:188
Volume(_SYSVolumeHandle vh)
Initialize from a system object.
Definition: filesystem.h:252
uint32_t freeUnits()
Free space, in allocation units.
Definition: filesystem.h:637
bool operator!=(_SYSVolumeHandle other) const
Inequality comparison operator.
Definition: filesystem.h:325
uint32_t selfObjUnits()
Space used by the current volume's StoredObjects, in allocation units.
Definition: filesystem.h:723
A coarse-grained region of external memory.
Definition: filesystem.h:238
An AssetConfiguration represents an arrangement of AssetGroups to load.
Definition: loader.h:138
const T * metadata(unsigned key, unsigned *actualSize=NULL) const
Look up a metadata value from the mapped Volume. The result is cast to a constant pointer of the indi...
Definition: filesystem.h:460
T * translate(T *va) const
Translate a virtual address in this ELF volume's read-only data segment, into a virtual address in th...
Definition: filesystem.h:473
bool operator==(_SYSObjectKey other) const
Equality comparison operator.
Definition: filesystem.h:216
int erase() const
Erase this object. Equivalent to a zero-length write()
Definition: filesystem.h:177
uint32_t selfElfBytes()
Space used by the current volume's ELF binary, in bytes.
Definition: filesystem.h:718
void bzero(void *s, unsigned count)
Write 'n' zero bytes to memory.
Definition: memory.h:114
int read(void *buffer, unsigned bufferSize, _SYSVolumeHandle volume=0) const
Read a stored object into memory.
Definition: filesystem.h:145
int writeObject(const T &buffer) const
Template wrapper for write() of fixed-size objects.
Definition: filesystem.h:211
MappedVolume()
Construct a detached MappedVolume.
Definition: filesystem.h:383
uint32_t launcherObjUnits()
Space used by the launcher's StoredObjects, in allocation units.
Definition: filesystem.h:683
static StoredObject allocate()
Allocate a unique StoredObject value at compile-time.
Definition: filesystem.h:112
uint32_t freeBytes()
Free space, in bytes.
Definition: filesystem.h:642
uint32_t selfObjBytes()
Space used by the current volume's StoredObjects, in bytes.
Definition: filesystem.h:728
const UUID * uuid() const
Retrieve the volume's UUID.
Definition: filesystem.h:524
AssetConfiguration< MAX_BOOTSTRAP_GROUPS > BootstrapAssetConfiguration
An AssetConfiguration large enough to hold all bootstrap groups.
Definition: filesystem.h:373
int readObject(T &buffer, _SYSVolumeHandle volume=0) const
Template wrapper for read() of fixed-size objects.
Definition: filesystem.h:194
int write(const T &buffer) const
Template wrapper for write() of fixed-size objects.
Definition: filesystem.h:205
MappedVolume(Volume vol)
Map a view of the provided Volume.
Definition: filesystem.h:394
static void list(unsigned volType, Array< Volume, T > &volumes)
List all volumes of the specified type.
Definition: filesystem.h:263
void setCount(unsigned c)
Change the number of elements currently in the array.
Definition: array.h:80
void gather()
Inspects the current state of the filesystem, and fills in the FilesystemInfo accordingly.
Definition: filesystem.h:622
iterator begin()
Return an iterator pointing to the first slot in the array.
Definition: array.h:182
const char * title(const char *placeholder="(untitled)") const
Retrieve a mapped, NUL-terminated string with the volume's title.
Definition: filesystem.h:492
const char * package(const char *placeholder="(none)") const
Retrieve a mapped, NUL-terminated string with the volume's package string.
Definition: filesystem.h:503
Any kind of asset image, as defined in your stir script.
Definition: image.h:67
#define DEBUG_ONLY(_x)
Mark a chunk of code as debug-only.
Definition: macros.h:117
uint32_t systemUnits()
Definition: filesystem.h:663
uint32_t launcherElfBytes()
Space used by the launcher's ELF binary, in bytes.
Definition: filesystem.h:678
uint32_t launcherElfUnits()
Space used by the launcher's ELF binary, in allocation units.
Definition: filesystem.h:673
A statically sized array.
Definition: array.h:51
void exec() const
Transfer control to a new program.
Definition: filesystem.h:289
uint32_t totalBytes()
Total space, in bytes.
Definition: filesystem.h:652
StoredObject(unsigned k)
Initialize from an unsigned integer.
Definition: filesystem.h:94
const char * version(const char *placeholder="(none)") const
Retrieve a mapped, NUL-terminated string with the volume's version string.
Definition: filesystem.h:514
bool operator!=(_SYSObjectKey other) const
Inequality comparison operator.
Definition: filesystem.h:221
#define NULL
Definition: macros.h:356
Volume type for the system launcher.
Definition: filesystem.h:245
Volume type for normal games.
Definition: filesystem.h:244
static const unsigned LIMIT
Maximum allowed value for a key (255)
Definition: filesystem.h:80
Information about the composition of the filesystem.
Definition: filesystem.h:611
Volume()
Default constructor, leaves the Volume with an invalid value of zero.
Definition: filesystem.h:249
Array< AssetGroup, MAX_BOOTSTRAP_GROUPS > BootstrapAssetGroups
An array large enough to hold all bototstrap AssetGroups.
Definition: filesystem.h:376
void * metadata(unsigned key, unsigned minSize, unsigned *actualSize) const
Look up a metadata value from the mapped Volume.
Definition: filesystem.h:440
uint32_t gameObjBytes()
Space used by all game StoredObjects, in bytes.
Definition: filesystem.h:708
uint32_t selfElfUnits()
Space used by the current volume's ELF binary, in allocation units.
Definition: filesystem.h:713
static const unsigned MAX_SIZE
Maximum size of an object, in bytes (4080)
Definition: filesystem.h:83
uint32_t systemBytes()
Space used by system data, in bytes.
Definition: filesystem.h:668
uint32_t gameElfBytes()
Space used by all game ELF binaries, in bytes.
Definition: filesystem.h:698
uint32_t gameObjUnits()
Space used by all game StoredObjects, in allocation units.
Definition: filesystem.h:703
A lightweight ID for a persistently stored object.
Definition: filesystem.h:75
StoredObject(int k)
Initialize from an integer.
Definition: filesystem.h:89
Type
Enumeration of common volume types.
Definition: filesystem.h:243
uint32_t translate(uint32_t va) const
A variant of translate() for pointers that have already been cast to uint32_t, such as pointers that ...
Definition: filesystem.h:482
bool operator==(_SYSVolumeHandle other) const
Equality comparison operator.
Definition: filesystem.h:320
Volume volume() const
Returns the Volume associated with this mapping.
Definition: filesystem.h:422
void attach(Volume vol)
Attach this MappedVolume to a new volume.
Definition: filesystem.h:413
void append(_SYSAssetSlot slot, AssetGroup &group, _SYSVolumeHandle volume=0)
Add an AssetGroup to this configuration.
Definition: loader.h:154
int write(const void *data, unsigned dataSize) const
Save a new version of an object.
Definition: filesystem.h:172
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658
uint32_t launcherObjBytes()
Space used by the launcher's StoredObjects, in bytes.
Definition: filesystem.h:688