libnds
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 returns a raw byte of the stream. More...
 
typedef int(* getHeaderCallback )(u8 *source, u16 *dest, u32 arg)
 Should return the header of a compressed stream of bytes. More...
 
typedef int(* getResultCallback )(u8 *source)
 Should verify the result after data got decompressed. More...
 
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

void swiChangeSoundBias (int enabled, int delay)
 increments or decrements the sound bias once per delay. More...
 
void swiCopy (const void *source, void *dest, int flags)
 copies or fills some memory. More...
 
uint16 swiCRC16 (uint16 crc, void *data, uint32 size)
 calculates a CRC-16 checksum. More...
 
void swiDecodeDelta16 (void *source, void *destination)
 Decodes a stream of bytes based on the difference of the bytes. More...
 
void swiDecodeDelta8 (void *source, void *destination)
 Decodes a stream of bytes based on the difference of the bytes. More...
 
int swiDecompressHuffman (void *source, void *destination, uint32 toGetSize, TDecompressionStream *stream)
 Decompresses Huffman compressed data. More...
 
int swiDecompressLZSSVram (void *source, void *destination, uint32 toGetSize, TDecompressionStream *stream)
 Decompresses LZSS compressed data vram safe. More...
 
void swiDecompressLZSSWram (void *source, void *destination)
 Decompresses LZSS compressed data. More...
 
int swiDecompressRLEVram (void *source, void *destination, uint32 toGetSize, TDecompressionStream *stream)
 Decompresses RLE compressed data vram safe. More...
 
void swiDecompressRLEWram (void *source, void *destination)
 Decompresses RLE compressed data. More...
 
void swiDelay (uint32 duration)
 delays the code. More...
 
int swiDivide (int numerator, int divisor)
 divides 2 numbers. More...
 
void swiDivMod (int numerator, int divisor, int *result, int *remainder)
 divides 2 numbers and stores both the result and the remainder. More...
 
void swiFastCopy (const void *source, void *dest, int flags)
 copies or fills some memory. can only copy in word chunks. More...
 
uint16 swiGetPitchTable (int index)
 Returns an entry in the pitch table. More...
 
uint16 swiGetSineTable (int index)
 Returns an entry in the sine table. More...
 
uint8 swiGetVolumeTable (int index)
 Returns an entry in the volume table. More...
 
void swiHalt (void)
 Halts the CPU untill an interupt occures. More...
 
int swiIsDebugger (void)
 returns 0 if running on a nintendo hardware debugger. More...
 
int swiRemainder (int numerator, int divisor)
 calculate the remainder of an division. More...
 
void swiSetHaltCR (uint32 data)
 Writes a word of the data to 0x04000300:32. More...
 
void swiSetHaltCR (uint8 data)
 Writes a byte of the data to 0x04000301:8. More...
 
void swiSleep (void)
 Halts the CPU and most of the hardware untill an interupt occures. More...
 
void swiSoftReset (void)
 resets the DS.
 
int swiSqrt (int value)
 calculates the square root. More...
 
void swiSwitchToGBAMode (void)
 Switches the DS to GBA mode. More...
 
void swiUnpackBits (uint8 *source, uint32 *destination, PUnpackStruct params)
 Unpack data stored in multiple elements in a byte to a larger space. More...
 
void swiWaitForIRQ (void)
 wait for any interrupt. More...
 

Detailed Description

Nintendo DS Bios functions.

See gbatek for more information.

Typedef Documentation

typedef u8(* getByteCallback)(u8 *source)

Should returns a raw byte of the stream.

Parameters
sourceA pointer to the byte.
Returns
A byte.
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.
typedef int(* getResultCallback)(u8 *source)

Should verify the result after data got decompressed.

getResult 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. value will be returned from bios function if value is negative.

Function Documentation

void swiChangeSoundBias ( int  enabled,
int  delay 
)

increments or decrements the sound bias once per delay.

Parameters
enabled0 to decrement it until it reaches 0x000, 1 to increment it until it reaches 0x200.
delayIs in the same units of time as swiDelay.
Note
ARM7 exclusive.
void swiCopy ( const void *  source,
void *  dest,
int  flags 
)

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).
uint16 swiCRC16 ( uint16  crc,
void *  data,
uint32  size 
)

calculates a CRC-16 checksum.

Parameters
crcstarting CRC-16 value.
datapointer to data (processed nibble by nibble)
sizesize in bytes.
Returns
the CRC-16 after the data has been processed.
void swiDecodeDelta16 ( void *  source,
void *  destination 
)

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.
void swiDecodeDelta8 ( void *  source,
void *  destination 
)

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.
int swiDecompressHuffman ( void *  source,
void *  destination,
uint32  toGetSize,
TDecompressionStream stream 
)

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
int swiDecompressLZSSVram ( void *  source,
void *  destination,
uint32  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
void swiDecompressLZSSWram ( void *  source,
void *  destination 
)

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
int swiDecompressRLEVram ( void *  source,
void *  destination,
uint32  toGetSize,
TDecompressionStream stream 
)

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
void swiDecompressRLEWram ( void *  source,
void *  destination 
)

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
void swiDelay ( uint32  duration)

delays the code.

Delays for for a period X + Y*duration where X is the swi overhead and Y is a cycle of

     loop:
       sub r0, #1
       bgt loop

of thumb fetches in BIOS memory

Parameters
durationlength of delay
Note
Duration should be 1 or more, a duration of 0 is a huge delay.
int swiDivide ( int  numerator,
int  divisor 
)

divides 2 numbers.

Parameters
numeratorsigned integer to divide
divisorsigned integer to divide by
Returns
numerator / divisor
void swiDivMod ( int  numerator,
int  divisor,
int *  result,
int *  remainder 
)

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
void swiFastCopy ( const void *  source,
void *  dest,
int  flags 
)

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.
uint16 swiGetPitchTable ( int  index)

Returns an entry in the pitch table.

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

Returns an entry in the sine table.

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

Returns an entry in the volume table.

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

Halts the CPU untill an interupt occures.

Note
ARM7 exclusive.
int swiIsDebugger ( void  )

returns 0 if running on a nintendo hardware debugger.

Returns
0 if running on a debugger (8 MB of ram instead of 4 MB), else some other number.
int swiRemainder ( int  numerator,
int  divisor 
)

calculate the remainder of an division.

Parameters
numeratorsigned integer to divide
divisorsigned integer to divide by
Returns
numerator % divisor
void swiSetHaltCR ( uint32  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!
void swiSetHaltCR ( uint8  data)

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

Parameters
dataThe byte to write.
Note
ARM7 exclusive.
void swiSleep ( void  )

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

Note
ARM7 exclusive.
int swiSqrt ( int  value)

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.
void swiSwitchToGBAMode ( void  )

Switches the DS to GBA mode.

Note
ARM7 exclusive.
void swiUnpackBits ( uint8 source,
uint32 destination,
PUnpackStruct  params 
)

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.
void swiWaitForIRQ ( void  )

wait for any interrupt.

Note
ARM9 exclusive.