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...

Defines

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

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:
source A 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:
source A pointer to the compressed data.
dest A pointer to the space where the decompressed data should be copied to.
arg A 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:
source The 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:
enabled 0 to decrement it until it reaches 0x000, 1 to increment it until it reaches 0x200.
delay Is 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:
source pointer to transfer source or pointer to value to fill the memory with.
dest pointer to transfer destination.
flags bits(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).
Examples:
Graphics/Sprites/allocation_test/source/main.c.
uint16 swiCRC16 ( uint16  crc,
void *  data,
uint32  size 
)

calculates a CRC-16 checksum.

Parameters:
crc starting CRC-16 value.
data pointer to data (processed nibble by nibble)
size size 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:
source Pointer to a header word, followed by encoded data. word(31..8) = size of data (in bytes). word(7..0) = ignored.
destination Destination 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:
source Pointer to a header word, followed by encoded data. word(31..8) = size of data (in bytes). word(7..0) = ignored.
destination Destination 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:
source Pointer to source data (always goes through the function pointers, so could just be an offset).
destination Pointer to destination.
toGetSize Callback value that is passed to getHeaderCallback function pointer.
stream Pointer 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:
source Pointer to source data (always goes through the function pointers, so could just be an offset).
destination Pointer to destination.
toGetSize Callback value that is passed to getHeaderCallback function pointer.
stream Pointer 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:
source pointer 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.
destination destination 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:
source Pointer to source data (always goes through the function pointers, so could just be an offset).
destination Pointer to destination.
toGetSize Callback value that is passed to getHeaderCallback function pointer.
stream Pointer 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:
source pointer 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.
destination destination 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:
duration length 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:
numerator signed integer to divide
divisor signed 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:
numerator signed integer to divide
divisor signed integer to divide by
result pointer to integer set to numerator / divisor
remainder pointer 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:
source pointer to transfer source or pointer to value to fill the memory with.
dest pointer to transfer destination.
flags bits(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:
index The 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:
index The 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:
index The 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:
numerator signed integer to divide
divisor signed integer to divide by
Returns:
numerator % divisor
void swiSetHaltCR ( uint8  data  ) 

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

Parameters:
data The byte to write.
Note:
ARM7 exclusive.
void swiSetHaltCR ( uint32  data  ) 

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

Parameters:
data the word to write.
Note:
This is on the ARM9, but works differently then the ARM7 function!
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:
value the 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:
source Source address.
destination destination address (word aligned).
params pointer to an UnpackStruct.
void swiWaitForIRQ ( void   ) 

wait for any interrupt.

Note:
ARM9 exclusive.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Sat Oct 2 12:55:12 2010 for libnds by  doxygen 1.6.3