DSC Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
DSC::ReadOnlyData Class Reference

#include <readonly_data.hpp>

Inheritance diagram for DSC::ReadOnlyData:
DSC::AssetData

Public Member Functions

 __attribute__ ((packed)) short header_size
 Some technical observations to account for during implementation:

 
 __attribute__ ((packed)) int data_length
 equilavent of sizeof(*this), but foresees class inheritance
 
 __attribute__ ((packed)) char *data_source
 size in bytes of the actual data

 
 __attribute__ ((packed)) unsigned short flags
 
 ReadOnlyData (int header_size=sizeof(ReadOnlyData))
 
void extract (void *destination) const
 writes all binary data to the given address More...
 
void extract (void *destination, int offset, int length) const
 writes binary data sequence to the given address More...
 
 ReadOnlyData (const ReadOnlyData &)=delete
 
 ReadOnlyData (ReadOnlyData &&)=delete
 
ReadOnlyData operator= (const ReadOnlyData &)=delete
 
ReadOnlyData operator= (ReadOnlyData &&)=delete
 
bool is_file () const
 checks if data is written to file More...
 

Detailed Description

ReadOnlyData denotes a type of static resource that lies either in RAM, FAT or NITRO.

This class represents an abstract interface for resource management and should be able to retrieve any bytes buffer regardless of its localization.

This class can also be derived to describe more specialized resource formats.

This class is NOT the binary data itself, but only an expression of it. It is more like a header that resides only in WRAM, whilst the data it points to can be anywhere.

Instances of this class should be constants, not allow moving/making copies of them. In fact, only DSC specialized tools have to create reliable ReadOnlyData instances.

Referencing instances of this class should only be done through pointers (attention to down/upcasts, no polymorphism is being used)

[ !!! POSSIBLE BUG SOURCE !!! ] There is no "Read-Only Memory" thing on DS homebrew. All the constants are being placed in EWRAM (4MB). The compiler tries its best to prevent programmers from altering constant values, but one can simply break the rule by overwriting a constant only using its dereferenced pointer. Assuming the programmer doesn't try anything strange, there is still a chance that an undefined behavior/RAM corruption/ some accidental buffer overflow (eg. for i=0;i<10;i–) may overwrite in-memory "read-only" data. We should keep a careful eye on that and consider it as a potential explanation for any visual glitches or misterious data corruption. Therefore, when constant data changes its bytes, then something's really messed up.

Constructor & Destructor Documentation

◆ ReadOnlyData()

DSC::ReadOnlyData::ReadOnlyData ( int  header_size = sizeof(ReadOnlyData))

bits 0-7 : see ROD_*
bits 8-15 : defined by derived formats specifications

Member Function Documentation

◆ __attribute__()

DSC::ReadOnlyData::__attribute__ ( (packed)  )

if is_file==true, data_source is the file path (fat://..., nitro://...) if is_file==false, data_source is a pointer to WRAM if data_source==NULL, then the actual data resides right after *this

◆ extract() [1/2]

void DSC::ReadOnlyData::extract ( void *  destination) const

writes all binary data to the given address

Parameters
destinationaddress to extract data to

◆ extract() [2/2]

void DSC::ReadOnlyData::extract ( void *  destination,
int  offset,
int  length 
) const

writes binary data sequence to the given address

Parameters
destinationaddress to extract data to
offsetposition in effetive data where copying starts
lengthlength of data to copy

◆ is_file()

bool DSC::ReadOnlyData::is_file ( ) const

checks if data is written to file

Returns
true if effective data is in file, false if in WRAM

The documentation for this class was generated from the following file: