00001 /*--------------------------------------------------------------------------------- 00002 00003 BIOS functions 00004 00005 Copyright (C) 2005 00006 Michael Noland (joat) 00007 Jason Rogers (dovoto) 00008 Dave Murphy (WinterMute) 00009 00010 This software is provided 'as-is', without any express or implied 00011 warranty. In no event will the authors be held liable for any 00012 damages arising from the use of this software. 00013 00014 Permission is granted to anyone to use this software for any 00015 purpose, including commercial applications, and to alter it and 00016 redistribute it freely, subject to the following restrictions: 00017 00018 1. The origin of this software must not be misrepresented; you 00019 must not claim that you wrote the original software. If you use 00020 this software in a product, an acknowledgment in the product 00021 documentation would be appreciated but is not required. 00022 2. Altered source versions must be plainly marked as such, and 00023 must not be misrepresented as being the original software. 00024 3. This notice may not be removed or altered from any source 00025 distribution. 00026 00027 ---------------------------------------------------------------------------------*/ 00028 00029 #ifndef BIOS_H_INCLUDE 00030 #define BIOS_H_INCLUDE 00031 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 00043 #include "nds/ndstypes.h" 00044 00045 00046 typedef struct DecompressionStream { 00047 int (*getSize)(uint8 * source, uint16 * dest, uint32 r2); 00048 int (*getResult)(uint8 * source); // can be NULL 00049 uint8 (*readByte)(uint8 * source); 00050 } PACKED TDecompressionStream; 00051 00052 00053 typedef struct UnpackStruct { 00054 uint16 sourceSize; // in bytes 00055 uint8 sourceWidth; 00056 uint8 destWidth; 00057 uint32 dataOffset; 00058 } PACKED TUnpackStruct, * PUnpackStruct; 00059 00060 00065 void swiSoftReset(void); 00066 00083 void swiDelay(uint32 duration); 00084 00110 int swiDivide(int numerator, int divisor); 00111 int swiRemainder(int numerator, int divisor); 00112 void swiDivMod(int numerator, int divisor, int * result, int * remainder); 00113 00138 #define COPY_MODE_HWORD (0) 00139 #define COPY_MODE_WORD (1<<26) 00140 #define COPY_MODE_COPY (0) 00141 #define COPY_MODE_FILL (1<<24) 00142 00143 void swiCopy(const void * source, void * dest, int flags); 00144 void swiFastCopy(const void * source, void * dest, int flags); 00145 00146 // swiSqrt (swi 0x0D) 00147 00148 int swiSqrt(int value); 00149 00150 // swiCRC16(uint16 crc, void * data, uint32 size) (swi 0x0E) 00151 // crc - starting CRC-16 00152 // data - pointer to data (processed nibble by nibble) 00153 // size - size in bytes 00154 // 00155 // Returns the CRC-16 after the data has been processed 00156 00157 uint16 swiCRC16(uint16 crc, void * data, uint32 size); 00158 00159 // int swiIsDebugger(void) 00160 // Returns 0 if running on a debugger (8 MB of ram instead of 4 MB) 00161 // 00162 // Note: swi 0x0F on both CPUs 00163 00164 int swiIsDebugger(void); 00165 00166 // swiUnpackBits 00167 // source - Source address 00168 // destination - destination address (word aligned) 00169 // params - Unpack structure 00170 // uint16 sourceSize (in bytes) 00171 // uint8 sourceWidth (1,2,4,8) 00172 // uint8 destWidth (1,2,4,8,16,32) 00173 // uint32 dataOffset (bits 0..30 are added to all non-zero 00174 // destination writes, unless b31 is set, 00175 // which does it for zeros too) 00176 // 00177 // Unpack data stored multiple elements to a byte into a larger space 00178 // i.e. 8 elements per byte (i.e. b/w font), into 1 element per byte 00179 // 00180 // Note: swi 0x10 on both CPUs 00181 00182 void swiUnpackBits(uint8 * source, uint32 * destination, PUnpackStruct params); 00183 00184 // DecompressLZSSWram (swi 0x11) 00185 // source - pointer to a header word, followed by compressed data 00186 // word(31..8) = size of uncompressed data (in bytes) 00187 // word(7..0) = ignored 00188 // destination - destination address 00189 // Writes data a byte at a time 00190 // 00191 // DecompressLZSSVram (swi 0x12) 00192 // Writes data a halfword at a time 00193 // See DecompressRLEVram for parameter details 00194 00195 void swiDecompressLZSSWram(void * source, void * destination); 00196 int swiDecompressLZSSVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream); 00197 00198 // swiDecompressHuffman (swi 0x13) 00199 // See DecompressRLE for parameter details 00200 00201 int swiDecompressHuffman(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream); 00202 00203 // DecompressRLEWram (swi 0x14) 00204 // r0 - pointer to a header word, followed by compressed data 00205 // word(31..8) = size of uncompressed data (in bytes) 00206 // word(7..0) = ignored 00207 // r1 - destination address 00208 // Writes data a byte at a time 00209 // 00210 // DecompressRLEVram (swi 0x15) 00211 // r0 - pointer to compressed source data, maybe! (always goes through 00212 // the function pointers, so could just be an offset) 00213 // r1 - pointer to destination (halfword) 00214 // r2 - no idea, passed to getSize function 00215 // r3 - pointer to a structure 00216 // Writes data a halfword at a time 00217 // 00218 // Result of getSize is a word, with the size of decompressed data in 00219 // bits 31..8, and bits 7..0 are ignored. This value is also returned 00220 // by the swi, unless getResult is non-NULL and returns a neg. value 00221 // 00222 // getResult is used to provide a result for the swi, given the source 00223 // pointer after all data has been read (or if getSize < 0). It can 00224 // be NULL, unlike getSize and readByte. Its value is only returned 00225 // if negative, otherwise the typical result is used, so it is likely 00226 // some sort of error-checking procedure 00227 // 00228 // readByte is used in lieu of directly accessing memory 00229 // 00230 // compressed data format: 00231 // bit(7): 0: uncompressed, 1: compressed 00232 // bit(6..0) when uncompressed: run length - 1, followed by run_length bytes of true data 00233 // bit(6..0) when compressed: run length - 3, followed by one byte of true data, to be repeated 00234 00235 void swiDecompressRLEWram(void * source, void * destination); 00236 int swiDecompressRLEVram(void * source, void * destination, uint32 toGetSize, TDecompressionStream * stream); 00237 00238 // swiDecodeDelta8 00239 // source - pointer to a header word, followed by encoded data 00240 // word(31..8) = size of data (in bytes) 00241 // word(7..0) = ignored 00242 // destination - destination address 00243 // Writes data a byte at a time 00244 // 00245 // Note: ARM9 exclusive swi 0x16 00246 00247 #ifdef ARM9 00248 00254 void swiWaitForIRQ(void); 00255 00256 void swiSetHaltCR(uint32 data); 00257 00258 00259 extern void swiDecodeDelta8(void * source, void * destination); 00260 00261 // swiDecodeDelta16 00262 // source - pointer to a header word, followed by encoded data 00263 // word(31..8) = size of data (in bytes) 00264 // word(7..0) = ignored 00265 // destination - destination address 00266 // Writes data a halfword at a time 00267 // 00268 // Note: ARM9 exclusive swi 0x18 00269 00270 void swiDecodeDelta16(void * source, void * destination); 00271 #endif 00272 00273 00274 #ifdef ARM7 00275 00276 // 00277 // swiHalt (swi 0x06) 00278 // Same as swiSetHaltCR(0x80) 00279 // 00280 // swiSleep (swi 0x07) 00281 // Same as swiSetHaltCR(0xC0) 00282 // 00283 // swiSwitchToGBAMode (not a SWI) 00284 // Same as swiSetHaltCR(0x40) 00285 // 00286 // swiSetHaltCR (swi 0x1F) 00287 // Writes a byte of the data to 0x04000301:8 00288 // 00289 // Note: All of these are ARM7 exclusive 00290 // 00291 // swiSetHaltCR (swi 0x1F) 00292 // Writes a word of the data to 0x04000300:32 00293 // 00294 // Note: This is on the ARM9, but works differently to the ARM7 function! 00295 // 00296 00297 void swiHalt(void); 00298 void swiSleep(void); 00299 void swiSwitchToGBAMode(void); 00300 void swiSetHaltCR(uint8 data); 00301 00302 // swiGetSineTable(int index) 00303 // Returns an entry in the sine table (index = 0..63) 00304 // 00305 // Note: ARM7 exclusive swi 0x1A 00306 00307 uint16 swiGetSineTable(int index); 00308 // 00309 // swiGetPitchTable(int index) 00310 // Returns an entry in the pitch table (index = 0..767) 00311 // 00312 // Note: ARM7 exclusive swi 0x1B 00313 00314 uint16 swiGetPitchTable(int index); 00315 00316 00317 // swiGetVolumeTable(int index) 00318 // Returns an entry in the volume table (index = 0..723) 00319 // 00320 // Note: ARM7 exclusive swi 0x1C 00321 uint8 swiGetVolumeTable(int index); 00322 // swiChangeSoundBias(int enabled, int delay) 00323 // enabled 00324 // 0: decrement SOUND_BIAS once per delay until it reaches 0x000 00325 // 1: increment SOUND_BIAS once per delay until it reaches 0x200 00326 // delay is in the same units of time as swiDelay 00327 // 00328 // Note: ARM7 exclusive SWI 0x08 00329 00330 void swiChangeSoundBias(int enabled, int delay); 00331 00332 00333 #endif //ARM7 00334 00335 00336 #ifdef __cplusplus 00337 } 00338 #endif 00339 00340 00341 #endif 00342