libnds
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
bios.h File Reference

Nintendo DS BIOS functions. More...

#include <nds/ndstypes.h>

Data Structures

struct  DecompressionStream
 A struct that contains callback function pointers used by the decompression functions. More...
 
struct  UnpackStruct
 A struct and struct pointer with information about unpacking data. More...
 

Macros

#define COPY_MODE_COPY   (0)
 copy a range of memory to another piece of memory
 
#define COPY_MODE_FILL   BIT(24)
 Fill a piece of memory with a value.
 
#define COPY_MODE_HWORD   (0)
 Copy in chunks of halfword size.
 
#define COPY_MODE_WORD   BIT(26)
 Copy in chunks of word size.
 

Typedefs

typedef u8(* getByteCallback) (u8 *source)
 Should return a raw byte of the stream.
 
typedef u16(* getHalfWordCallback) (u16 *source)
 Should return a raw halfword of the stream.
 
typedef int(* getHeaderCallback) (u8 *source, u16 *dest, u32 arg)
 Should return the header of a compressed stream of bytes.
 
typedef int(* getResultCallback) (u8 *source)
 Should verify the result after data got decompressed.
 
typedef u32(* getWordCallback) (u32 *source)
 Should return a raw word of the stream.
 
typedef struct DecompressionStream TDecompressionStream
 A struct that contains callback function pointers used by the decompression functions.
 
typedef struct UnpackStruct TUnpackStruct
 A struct and struct pointer with information about unpacking data.
 

Functions

static void swiChangeSoundBias (int enabled, int delay)
 Increments or decrements the sound bias once per delay.
 
static void swiCopy (const void *source, void *dest, int flags)
 Copies or fills some memory.
 
static uint16_t swiCRC16 (uint16_t crc, const void *data, uint32_t size)
 Calculates a CRC-16 checksum using the following configuration:
 
static void swiDecodeDelta16 (const void *source, void *destination)
 Decodes a stream of bytes based on the difference of the bytes.
 
static void swiDecodeDelta8 (const void *source, void *destination)
 Decodes a stream of bytes based on the difference of the bytes.
 
static int swiDecompressHuffman (const void *source, void *destination, uint32_t toGetSize, TDecompressionStream *stream)
 Decompresses Huffman compressed data.
 
int swiDecompressLZSSVram (const void *source, void *destination, uint32_t toGetSize, TDecompressionStream *stream)
 Decompresses LZSS compressed data vram safe.
 
static void swiDecompressLZSSWram (const void *source, void *destination)
 Decompresses LZSS compressed data.
 
static int swiDecompressRLEVram (const void *source, void *destination, uint32_t toGetSize, TDecompressionStream *stream)
 Decompresses RLE compressed data vram safe.
 
static void swiDecompressRLEWram (const void *source, void *destination)
 Decompresses RLE compressed data.
 
static void swiDelay (uint32_t duration)
 Delays the code.
 
static int swiDivide (int numerator, int divisor)
 Divides 2 numbers.
 
static void swiDivMod (int numerator, int divisor, int *result, int *remainder)
 Divides 2 numbers and stores both the result and the remainder.
 
static void swiFastCopy (const void *source, void *dest, int flags)
 Copies or fills some memory.
 
static uint16_t swiGetPitchTable (int index)
 Returns an entry in the pitch table.
 
static uint16_t swiGetSineTable (int index)
 Returns an entry in the sine table.
 
static uint8_t swiGetVolumeTable (int index)
 Returns an entry in the volume table.
 
static void swiHalt (void)
 Halts the CPU until an interupt occures.
 
static int swiIsDebugger (void)
 Returns 1 if running on a Nintendo hardware debugger.
 
static int swiRemainder (int numerator, int divisor)
 Calculate the remainder of an division.
 
void swiSetHaltCR (uint32_t data)
 Writes a word of the data to 0x04000300:32.
 
void swiSetHaltCR (uint8_t data)
 Writes a byte of the data to 0x04000301:8.
 
static void swiSleep (void)
 Halts the CPU and most of the hardware untill an interupt occures.
 
static void swiSoftReset (void)
 Resets the DS.
 
static int swiSqrt (int value)
 Calculates the square root.
 
void swiSwitchToGBAMode (void)
 Switches the DS to GBA mode.
 
static void swiUnpackBits (const void *source, void *destination, TUnpackStruct *params)
 Unpack data stored in multiple elements in a byte to a larger space.
 
static void swiWaitForIRQ (void)
 Wait for any interrupt.
 

Detailed Description

Nintendo DS BIOS functions.

See gbatek for more information.

Typedef Documentation

◆ getByteCallback

typedef u8(* getByteCallback) (u8 *source)

Should return a raw byte of the stream.

Parameters
sourceA pointer to the byte.
Returns
A byte.

◆ getHalfWordCallback

typedef u16(* getHalfWordCallback) (u16 *source)

Should return a raw halfword of the stream.

Parameters
sourceA pointer to the halfword.
Returns
A halfword.

◆ getHeaderCallback

typedef int(* getHeaderCallback) (u8 *source, u16 *dest, u32 arg)

Should return the header of a compressed stream of bytes.

The result is a word, with the size of decompressed data in bits 8 - 31, and bits 0 - 7 are ignored. This value is also returned by the bios function, unless getResult is non-NULL and returns a negative value. This useally returns the 4 bytes that source points to.

Parameters
sourceA pointer to the compressed data.
destA pointer to the space where the decompressed data should be copied to.
argA callback value that gets passed to the bios function.
Returns
The header of the compressed data containing the length of the data and the compression type.

◆ getResultCallback

typedef int(* getResultCallback) (u8 *source)

Should verify the result after data got decompressed.

getResultCallback is used to provide a result for the bios function, given the source pointer after all data has been read (or if getSize < 0). Its value is only returned if negative, otherwise the typical result is used, so it is likely some sort of error-checking procedure.

Parameters
sourceThe current source address.
Returns
0 if it went right, or a negative number if something went wrong. The value will be returned from BIOS function if value is negative.

◆ getWordCallback

typedef u32(* getWordCallback) (u32 *source)

Should return a raw word of the stream.

Parameters
sourceA pointer to the word.
Returns
A word.

Function Documentation

◆ swiChangeSoundBias()

static void swiChangeSoundBias ( int  enabled,
int  delay 
)
inlinestatic

Increments or decrements the sound bias once per delay.

Parameters
enabledSet to 0 to decrement it until it reaches 0x000, set to 1 to increment it until it reaches 0x200.
delayIs in the same units of time as swiDelay.
Note
ARM7 exclusive.

◆ swiCopy()

static void swiCopy ( const void *  source,
void *  dest,
int  flags 
)
inlinestatic

Copies or fills some memory.

Parameters
sourcePointer to transfer source or pointer to value to fill the memory with.
destPointer to transfer destination.
flagsbits(0-20): size of data to copy/fill in words, or'd with the copy mode size (word or halfword) and type (copy or fill).

◆ swiCRC16()

static uint16_t swiCRC16 ( uint16_t  crc,
const void *  data,
uint32_t  size 
)
inlinestatic

Calculates a CRC-16 checksum using the following configuration:

  • Input reflected: Yes
  • Result reflected: Yes
  • Polynomial: 0x8005
Parameters
crcInitial CRC-16 value.
dataPointer to data (processed nibble by nibble)
sizeSize in bytes.
Returns
The CRC-16 value after the data has been processed.

◆ swiDecodeDelta16()

static void swiDecodeDelta16 ( const void *  source,
void *  destination 
)
inlinestatic

Decodes a stream of bytes based on the difference of the bytes.

Parameters
sourcePointer to a header word, followed by encoded data. word(31..8) = size of data (in bytes). word(7..0) = ignored.
destinationDestination address.
Note
Writes data a halfword at a time.
ARM9 exclusive.

◆ swiDecodeDelta8()

static void swiDecodeDelta8 ( const void *  source,
void *  destination 
)
inlinestatic

Decodes a stream of bytes based on the difference of the bytes.

Parameters
sourcePointer to a header word, followed by encoded data. word(31..8) = size of data (in bytes). word(7..0) = ignored.
destinationDestination address.
Note
Writes data a byte at a time.
ARM9 exclusive.

◆ swiDecompressHuffman()

static int swiDecompressHuffman ( const void *  source,
void *  destination,
uint32_t  toGetSize,
TDecompressionStream stream 
)
inlinestatic

Decompresses Huffman compressed data.

Parameters
sourcePointer to source data (always goes through the function pointers, so could just be an offset).
destinationPointer to destination.
toGetSizeCallback value that is passed to getHeaderCallback function pointer.
streamPointer to struct with callback function pointers.
Returns
The length of the decompressed data, or a signed errorcode from the Open/Close functions.
See also
decompress.h

◆ swiDecompressLZSSVram()

int swiDecompressLZSSVram ( const void *  source,
void *  destination,
uint32_t  toGetSize,
TDecompressionStream stream 
)

Decompresses LZSS compressed data vram safe.

Parameters
sourcePointer to source data (always goes through the function pointers, so could just be an offset).
destinationPointer to destination.
toGetSizeCallback value that is passed to getHeaderCallback function pointer.
streamPointer to struct with callback function pointers.
Returns
The length of the decompressed data, or a signed errorcode from the Open/Close functions.
Note
Writes data a halfword at a time.
See also
decompress.h

◆ swiDecompressLZSSWram()

static void swiDecompressLZSSWram ( const void *  source,
void *  destination 
)
inlinestatic

Decompresses LZSS compressed data.

Parameters
sourcePointer to a header word, followed by compressed data. bit 0-7 of header is ignored. bit 8-31 of header is size of uncompressed data in bytes.
destinationDestination address.
Note
Writes data a byte at a time.
See also
decompress.h

◆ swiDecompressRLEVram()

static int swiDecompressRLEVram ( const void *  source,
void *  destination,
uint32_t  toGetSize,
TDecompressionStream stream 
)
inlinestatic

Decompresses RLE compressed data vram safe.

Compressed data format:

  • bit(7): 0 = uncompressed, 1 = compressed.
  • bit(0-6) when uncompressed: run length - 1, followed by run_length bytes of true data.
  • bit(0-6) when compressed: run length - 3, followed by one byte of true data, to be repeated.
Parameters
sourcePointer to source data (always goes through the function pointers, so could just be an offset).
destinationPointer to destination.
toGetSizeCallback value that is passed to getHeaderCallback function pointer.
streamPointer to struct with callback function pointers.
Returns
The length of the decompressed data, or a signed errorcode from the Open/Close functions.
Note
Writes data a halfword at a time.
See also
decompress.h

◆ swiDecompressRLEWram()

static void swiDecompressRLEWram ( const void *  source,
void *  destination 
)
inlinestatic

Decompresses RLE compressed data.

Compressed data format:

  • bit(7): 0= uncompressed, 1= compressed.
  • bit(0-6) when uncompressed: run length - 1, followed by run_length bytes of true data.
  • bit(0-6) when compressed: run length - 3, followed by one byte of true data, to be repeated.
Parameters
sourcePointer to a header word, followed by compressed data. bit 0-7 of header is ignored. bit 8-31 of header is size of uncompressed data in bytes.
destinationDestination address.
Note
Writes data a byte at a time.
See also
decompress.h

◆ swiDelay()

static void swiDelay ( uint32_t  duration)
inlinestatic

Delays the code.

Delays for for a period "X + Y * duration" where X is the swi overhead and Y is a cycle of Thumb fetches in BIOS memory.

     loop:
       sub r0, #1
       bgt loop

Parameters
durationLength of delay.
Note
Duration should be 1 or more, a duration of 0 is a huge delay.

◆ swiDivide()

static int swiDivide ( int  numerator,
int  divisor 
)
inlinestatic

Divides 2 numbers.

Parameters
numeratorSigned integer to divide.
divisorSigned integer to divide by.
Returns
Numerator / divisor

◆ swiDivMod()

static void swiDivMod ( int  numerator,
int  divisor,
int *  result,
int *  remainder 
)
inlinestatic

Divides 2 numbers and stores both the result and the remainder.

Parameters
numeratorSigned integer to divide.
divisorSigned integer to divide by.
resultPointer to integer set to numerator / divisor.
remainderPointer to integer set to numerator % divisor.

◆ swiFastCopy()

static void swiFastCopy ( const void *  source,
void *  dest,
int  flags 
)
inlinestatic

Copies or fills some memory.

Can only copy in word chunks.

Parameters
sourcePointer to transfer source or pointer to value to fill the memory with.
destPointer to transfer destination.
flagsbits(0-20): size of data to copy/fill in words, or'd with the type (copy or fill).
Note
Transfers more quickly than swiCopy, but has higher interrupt latency.

◆ swiGetPitchTable()

static uint16_t swiGetPitchTable ( int  index)
inlinestatic

Returns an entry in the pitch table.

Parameters
indexThe index of the pitch table (0 - 767).
Returns
The entry.
Note
ARM7 exclusive.

◆ swiGetSineTable()

static uint16_t swiGetSineTable ( int  index)
inlinestatic

Returns an entry in the sine table.

Parameters
indexThe index of the sine table (0 - 63).
Returns
The entry.
Note
ARM7 exclusive.

◆ swiGetVolumeTable()

static uint8_t swiGetVolumeTable ( int  index)
inlinestatic

Returns an entry in the volume table.

Parameters
indexThe index of the volume table (0 - 723).
Returns
The entry.
Note
ARM7 exclusive.

◆ swiHalt()

static void swiHalt ( void  )
inlinestatic

Halts the CPU until an interupt occures.

Note
ARM7 exclusive.

◆ swiIsDebugger()

static int swiIsDebugger ( void  )
inlinestatic

Returns 1 if running on a Nintendo hardware debugger.

Note
It only works in DS mode (not DSi mode), and with the cache disabled. It's recommended to use isHwDebugger() instead, which works in DSi mode too, and it doesn't require the cache to be disabled.
Returns
1 if running on a debugger (8 MB of RAM instead of 4 MB), else 0.

◆ swiRemainder()

static int swiRemainder ( int  numerator,
int  divisor 
)
inlinestatic

Calculate the remainder of an division.

Parameters
numeratorSigned integer to divide
divisorSigned integer to divide by
Returns
Numerator % divisor

◆ swiSetHaltCR() [1/2]

void swiSetHaltCR ( uint32_t  data)

Writes a word of the data to 0x04000300:32.

Parameters
dataThe word to write.
Note
This is on the ARM9, but works differently then the ARM7 function!

◆ swiSetHaltCR() [2/2]

void swiSetHaltCR ( uint8_t  data)

Writes a byte of the data to 0x04000301:8.

Parameters
dataThe byte to write.
Note
ARM7 exclusive.

◆ swiSleep()

static void swiSleep ( void  )
inlinestatic

Halts the CPU and most of the hardware untill an interupt occures.

Note
ARM7 exclusive.

◆ swiSqrt()

static int swiSqrt ( int  value)
inlinestatic

Calculates the square root.

Parameters
valueThe value to calculate.
Returns
The square root of the value as an integer.
Note
Use fixed point math if you want more accuracy.

◆ swiSwitchToGBAMode()

void swiSwitchToGBAMode ( void  )

Switches the DS to GBA mode.

Note
ARM7 exclusive.

◆ swiUnpackBits()

static void swiUnpackBits ( const void *  source,
void *  destination,
TUnpackStruct params 
)
inlinestatic

Unpack data stored in multiple elements in a byte to a larger space.

i.e. 8 elements per byte (i.e. b/w font), into 1 element per byte.

Parameters
sourceSource address.
destinationDestination address (word aligned).
paramsPointer to an UnpackStruct.

◆ swiWaitForIRQ()

static void swiWaitForIRQ ( void  )
inlinestatic

Wait for any interrupt.

Note
ARM9 exclusive.