diff options
Diffstat (limited to 'packages/libndsfpc/src')
34 files changed, 513 insertions, 85 deletions
diff --git a/packages/libndsfpc/src/dswifi/inc/dswifi9.inc b/packages/libndsfpc/src/dswifi/inc/dswifi9.inc index 0ea15e5b9f..08f29a007a 100644 --- a/packages/libndsfpc/src/dswifi/inc/dswifi9.inc +++ b/packages/libndsfpc/src/dswifi/inc/dswifi9.inc @@ -51,8 +51,8 @@ const WIFIINIT_OPTION_USELED = $0002; - WIFIINIT_OPTION_USEHEAP_128 = $0000; - WIFIINIT_OPTION_USEHEAP_64 = $1000; + WIFIINIT_OPTION_USEHEAP_64 = $0000; + WIFIINIT_OPTION_USEHEAP_128 = $1000; WIFIINIT_OPTION_USEHEAP_256 = $2000; WIFIINIT_OPTION_USEHEAP_512 = $3000; WIFIINIT_OPTION_USECUSTOMALLOC = $4000; diff --git a/packages/libndsfpc/src/fat/fat.inc b/packages/libndsfpc/src/fat/fat.inc index cd65ecb073..a3bc8dc958 100644 --- a/packages/libndsfpc/src/fat/fat.inc +++ b/packages/libndsfpc/src/fat/fat.inc @@ -60,7 +60,8 @@ const // Methods to modify DOS File Attributes function FAT_getAttr(const _file: pcchar): cint; cdecl; external; -function FAT_setAttr(const _file: pcchar; attr: cint): cint; cdecl; external; +function FAT_setAttr(const _file: pcchar; attr: cuint8): cint; cdecl; external; + {$define LIBFAT_FEOS_MULTICWD} diff --git a/packages/libndsfpc/src/fat/gbfs.pp b/packages/libndsfpc/src/fat/gbfs.pp index 2ceb8949da..923a6dfa4a 100644 --- a/packages/libndsfpc/src/fat/gbfs.pp +++ b/packages/libndsfpc/src/fat/gbfs.pp @@ -1,4 +1,7 @@ unit gbfs; + +{$error gbfs is no longer supported on nds} + {$mode objfpc} {$apptype arm9} {$define arm9} diff --git a/packages/libndsfpc/src/nds/arm7/aes.inc b/packages/libndsfpc/src/nds/arm7/aes.inc new file mode 100644 index 0000000000..7dd82039d3 --- /dev/null +++ b/packages/libndsfpc/src/nds/arm7/aes.inc @@ -0,0 +1,76 @@ +{$ifdef NDS_INTERFACE} +type + _aes_keyslot = packed record + normalkey: array [0..15] of pcuint8; + key_x: array [0..15] of pcuint8; + key_y: array [0..15] of pcuint8; + end; + aes_keyslot_t = _aes_keyslot; + Taes_keyslot_t = aes_keyslot_t; + Paes_keyslot_t = ^Taes_keyslot_t; + + +const + REG_AES_CNT: pcuint32 = pointer($04004400); + AES_WRFIFO_FLUSH = (1 shl 10); + AES_RDFIFO_FLUSH = (1 shl 11); + +function AES_CNT_DMA_WRITE_SIZE(size: cint): cint; inline; +function AES_CNT_DMA_READ_SIZE(size: cint): cint; inline; + +function AES_CNT_CCM_SIZE(size: cint): cint; inline; + +const + AES_CCM_PASSTRHOUGH = (1 shl 19); + AES_CNT_KEY_APPLY = (1 shl 24); + +function AES_CNT_KEYSLOT(slot: cint): cint; inline; + +function AES_CNT_MODE(mode: cint): cint; inline; + +const + AES_CNT_IRQ = (1 shl 30); + AES_CNT_ENABLE = (1 shl 31); + + REG_AES_BLKCNT: pcuint32 = pointer($4004404); + + REG_AES_WRFIFO: pcuint32 = pointer($4004408); + REG_AES_RDFIFO: pcuint32 = pointer($400440c); + + REG_AES_IV: pcuint8 = pointer($4004420); + REG_AES_MAC: pcuint8 = pointer($4004430); + + AES_KEYSLOT : Paes_keyslot_t = pointer($4004440); + AES_KEYSLOT0 : Paes_keyslot_t = pointer($4004440); + AES_KEYSLOT1 : Paes_keyslot_t = pointer($4004470); + AES_KEYSLOT2 : Paes_keyslot_t = pointer($40044A0); + AES_KEYSLOT3 : Paes_keyslot_t = pointer($40044D0); +{$endif NDS_INTERFACE} + +{$ifdef NDS_IMPLEMENTATION} +function AES_CNT_DMA_WRITE_SIZE(size: cint): cint; inline; +begin + AES_CNT_DMA_WRITE_SIZE := ((size and 3) shl 12); +end; + +function AES_CNT_DMA_READ_SIZE(size: cint): cint; inline; +begin + AES_CNT_DMA_READ_SIZE := ((size and 3) shl 14); +end; + +function AES_CNT_CCM_SIZE(size: cint): cint; inline; +begin + AES_CNT_CCM_SIZE := ((size and 3) shl 16); +end; + +function AES_CNT_KEYSLOT(slot: cint): cint; inline; +begin + AES_CNT_KEYSLOT := ((slot and 3) shl 26); +end; + +function AES_CNT_MODE(mode: cint): cint; inline; +begin + AES_CNT_MODE := ((mode and 3) shl 28); +end; + +{$endif NDS_IMPLEMENTATION}
\ No newline at end of file diff --git a/packages/libndsfpc/src/nds/arm7/audio.inc b/packages/libndsfpc/src/nds/arm7/audio.inc index 3b44533b5a..fdd5664787 100644 --- a/packages/libndsfpc/src/nds/arm7/audio.inc +++ b/packages/libndsfpc/src/nds/arm7/audio.inc @@ -46,6 +46,37 @@ const type MIC_BUF_SWAP_CB = procedure(completedBuffer: pcuint8; length: cint); + +//--------------------------------------------------------------------------------- +// DSi Registers +//--------------------------------------------------------------------------------- +const + REG_SNDEXTCNT : pcuint16 = pointer($04004700); + REG_MICCNT : pcuint16 = pointer($04004600); + REG_MICDATA : pcuint32 = pointer($04004604); + +function SNDEXTCNT_RATIO(n: cint): cint32; inline; +const + SNDEXTCNT_FREQ_32KHZ = (0 shl 13); // output freq 32.73kHz + SNDEXTCNT_FREQ_47KHZ = (1 shl 13); // output freq 47.61kHz + SNDEXTCNT_MUTE = (1 shl 14); + SNDEXTCNT_ENABLE = (1 shl 15); + +function MICCNT_FORMAT(n: cint): cint; inline; +function MICCNT_FREQ_DIV(n: cint): cint; inline; + +const + MICCNT_EMPTY = (1 shl 8); + MICCNT_NOT_EMPTY = (1 shl 9); + MICCNT_MORE_DATA = (1 shl 10); + MICCNT_OVERRUN = (1 shl 11); + MICCNT_CLEAR_FIFO = (1 shl 12); + MICCNT_ENABLE_IRQ = (1 shl 13); + MICCNT_ENABLE_IRQ2 = (1 shl 14); + MICCNT_ENABLE = (1 shl 15); + + + function micReadData8(): cuint8; cdecl; external; function micReadData12(): cuint16; cdecl; external; @@ -125,4 +156,19 @@ procedure micOff(); inline; begin micSetAmp(PM_AMP_OFF, 0); end; + +function SNDEXTCNT_RATIO(n: cint): cint; inline; +begin + SNDEXTCNT_RATIO := (n and $F); +end; + +function MICCNT_FORMAT(n: cint): cint; inline; +begin + MICCNT_FORMAT := (n and 3); // unknown, always set to '2' +end; + +function MICCNT_FREQ_DIV(n: cint): cint; inline; +begin + MICCNT_FREQ_DIV := (n and 3) shl 2; // F/(n+1) where F is SNDEXTCNT output freq +end; {$endif NDS_IMPLEMENTATION} diff --git a/packages/libndsfpc/src/nds/arm7/clock.inc b/packages/libndsfpc/src/nds/arm7/clock.inc index bcb5f4bd9b..64c574c7cb 100644 --- a/packages/libndsfpc/src/nds/arm7/clock.inc +++ b/packages/libndsfpc/src/nds/arm7/clock.inc @@ -40,8 +40,8 @@ const WRITE_INT_REG1 = $68; READ_INT_REG1 = $69; - READ_INT_REG2 = $6A; - WRITE_INT_REG2 = $6B; + WRITE_INT_REG2 = $6A; + READ_INT_REG2 = $6B; READ_CLOCK_ADJUST_REG = $6C; WRITE_CLOCK_ADJUST_REG = $6D; diff --git a/packages/libndsfpc/src/nds/arm7/codec.inc b/packages/libndsfpc/src/nds/arm7/codec.inc new file mode 100644 index 0000000000..20832fc981 --- /dev/null +++ b/packages/libndsfpc/src/nds/arm7/codec.inc @@ -0,0 +1,38 @@ +{$ifdef NDS_INTERFACE} +{$ifndef ARM7} + {$error DSi TSC is only available on the ARM7} +{$endif ARM7} + +function cdcIsAvailable(): boolean; inline; + +type + cdcBanks = integer; +const + CDC_CONTROL: cdcBanks = $00; // Chip control + CDC_SOUND: cdcBanks = $01; // ADC/DAC control + CDC_TOUCHCNT: cdcBanks = $03; // TSC control + CDC_TOUCHDATA: cdcBanks = $FC; // TSC data buffer + + +// Direct register functions +function cdcReadReg(bank, reg: cuint8): cuint8; cdecl; external; +procedure cdcReadRegArray(bank, reg: cuint8; data: pointer; size: cuint8); cdecl; external; +procedure cdcWriteReg(bank, reg, value: cuint8); cdecl; external; +procedure cdcWriteRegMask(bank, reg, mask, value: cuint8); cdecl; external; +procedure cdcWriteRegArray(bank, reg: cuint8; data: pointer; size: cuint8); cdecl; external; + +// Touchscreen functions +procedure cdcTouchInit(); cdecl; external; +function cdcTouchPenDown(): cbool; cdecl; external; +function cdcTouchRead(pos: PtouchPosition): cbool; cdecl; external; + +{$endif NDS_INTERFACE} + +{$ifdef NDS_IMPLEMENTATION} + +function cdcIsAvailable(): boolean; inline; +begin + cdcIsAvailable := isDSiMode() and ((__DSiHeader^.appflags and $01) <> 0); +end; + +{$endif NDS_IMPLEMENTATION}
\ No newline at end of file diff --git a/packages/libndsfpc/src/nds/arm7/sdmmc.inc b/packages/libndsfpc/src/nds/arm7/sdmmc.inc index f198dc13f0..5099b9b786 100644 --- a/packages/libndsfpc/src/nds/arm7/sdmmc.inc +++ b/packages/libndsfpc/src/nds/arm7/sdmmc.inc @@ -120,18 +120,30 @@ type res: cuint32; end; mmcdevice = TMMCDevice; - -procedure sdmmc_controller_init(); cdecl; external; +const + MMC_DEVICE_SDCARD = 0; + MMC_DEVICE_NAND = 1; + +procedure sdmmc_controller_init(force_init: cbool); cdecl; external; procedure sdmmc_initirq(); cdecl; external; function sdmmc_cardinserted(): cint; cdecl; external; function sdmmc_sdcard_init(): cint; cdecl; external; + +function sdmmc_nand_init(): cint; cdecl; external; +procedure sdmmc_get_cid(devicenumber: cint; cid: pcuint32); cdecl; external; + +procedure sdmmc_nand_cid(cid: pcuint32); inline; +procedure sdmmc_sdcard_cid(cid: pcuint32); inline; + function sdmmc_sdcard_readsectors(sector_no: cuint32; numsectors: cuint32; _out: pointer): cint; cdecl; external; function sdmmc_sdcard_writesectors(sector_no: cuint32; numsectors: cuint32; _in: pointer): cint; cdecl; external; +function sdmmc_nand_readsectors(sector_no: cuint32; numsectors: cuint32; _out: pointer): cint; cdecl; external; +function sdmmc_nand_writesectors(sector_no: cuint32; numsectors: cuint32; _in: pointer): cint; cdecl; external; -var +var sdmmc_curdevice: cint; cvar; external; sdmmc_cid: pcuint32; cvar; external; @@ -183,5 +195,15 @@ begin sdmmc_mask16(REG_SDCLKCTL, $0, $100); end; +procedure sdmmc_nand_cid(cid: pcuint32); inline; +begin + sdmmc_get_cid(MMC_DEVICE_NAND,cid); +end; + +procedure sdmmc_sdcard_cid(cid: pcuint32); inline; +begin + sdmmc_get_cid(MMC_DEVICE_SDCARD,cid); +end; + {$endif NDS_IMPLEMENTATION} diff --git a/packages/libndsfpc/src/nds/arm7/touch.inc b/packages/libndsfpc/src/nds/arm7/touch.inc index 6000b65d8b..108d36e74b 100644 --- a/packages/libndsfpc/src/nds/arm7/touch.inc +++ b/packages/libndsfpc/src/nds/arm7/touch.inc @@ -17,7 +17,7 @@ const TSC_MEASURE_AUX = $E4; TSC_MEASURE_TEMP2 = $F4; - +procedure touchInit(); cdecl; external; procedure touchReadXY(var touchPos: touchPosition); cdecl; external; function touchRead(command: cuint32): cuint16; cdecl; external; diff --git a/packages/libndsfpc/src/nds/arm9/cache_asm.inc b/packages/libndsfpc/src/nds/arm9/cache_asm.inc new file mode 100644 index 0000000000..1a69e9055b --- /dev/null +++ b/packages/libndsfpc/src/nds/arm9/cache_asm.inc @@ -0,0 +1,37 @@ +{$ifdef NDS_INTERFACE} +const + PAGE_4K = (%01011 shl 1); + PAGE_8K = (%01100 shl 1); + PAGE_16K = (%01101 shl 1); + PAGE_32K = (%01110 shl 1); + PAGE_64K = (%01111 shl 1); + PAGE_128K = (%10000 shl 1); + PAGE_256K = (%10001 shl 1); + PAGE_512K = (%10010 shl 1); + PAGE_1M = (%10011 shl 1); + PAGE_2M = (%10100 shl 1); + PAGE_4M = (%10101 shl 1); + PAGE_8M = (%10110 shl 1); + PAGE_16M = (%10111 shl 1); + PAGE_32M = (%11000 shl 1); + PAGE_64M = (%11001 shl 1); + PAGE_128M = (%11010 shl 1); + PAGE_256M = (%11011 shl 1); + PAGE_512M = (%11100 shl 1); + PAGE_1G = (%11101 shl 1); + PAGE_2G = (%11110 shl 1); + PAGE_4G = (%11111 shl 1); + + ITCM_LOAD = (1 shl 19); + ITCM_ENABLE = (1 shl 18); + DTCM_LOAD = (1 shl 17); + DTCM_ENABLE = (1 shl 16); + DISABLE_TBIT = (1 shl 15); + ROUND_ROBIN = (1 shl 14); + ALT_VECTORS = (1 shl 13); + ICACHE_ENABLE = (1 shl 12); + BIG_ENDIAN = (1 shl 7); + DCACHE_ENABLE = (1 shl 2); + PROTECT_ENABLE = (1 shl 0); + +{$endif NDS_INTERFACE} diff --git a/packages/libndsfpc/src/nds/arm9/dldi.inc b/packages/libndsfpc/src/nds/arm9/dldi.inc index fb6f761f9d..796d9f91f8 100644 --- a/packages/libndsfpc/src/nds/arm9/dldi.inc +++ b/packages/libndsfpc/src/nds/arm9/dldi.inc @@ -1,10 +1,10 @@ {$ifdef NDS_INTERFACE} const - FIX_ALL = $01; - FIX_GLUE = $02; - FIX_GOT = $04; - FIX_BSS = $08; +// FIX_ALL = $01; +// FIX_GLUE = $02; +// FIX_GOT = $04; +// FIX_BSS = $08; DLDI_MAGIC_STRING_LEN = 8; DLDI_FRIENDLY_NAME_LEN = 48; diff --git a/packages/libndsfpc/src/nds/arm9/dldi_asm.inc b/packages/libndsfpc/src/nds/arm9/dldi_asm.inc new file mode 100644 index 0000000000..fd615e65af --- /dev/null +++ b/packages/libndsfpc/src/nds/arm9/dldi_asm.inc @@ -0,0 +1,20 @@ +{$ifdef NDS_INTERFACE} +const + FEATURE_MEDIUM_CANREAD = $00000001; + FEATURE_MEDIUM_CANWRITE = $00000002; + FEATURE_SLOT_GBA = $00000010; + FEATURE_SLOT_NDS = $00000020; + + FIX_ALL = $01; + FIX_GLUE = $02; + FIX_GOT = $04; + FIX_BSS = $08; + + DLDI_SIZE_32KB = $0f; + DLDI_SIZE_16KB = $0e; + DLDI_SIZE_8KB = $0d; + DLDI_SIZE_4KB = $0c; + DLDI_SIZE_1KB = $0a; + + +{$endif NDS_INTERFACE} diff --git a/packages/libndsfpc/src/nds/arm9/guitarGrip.inc b/packages/libndsfpc/src/nds/arm9/guitarGrip.inc index 85347def54..dfa8ff93bc 100644 --- a/packages/libndsfpc/src/nds/arm9/guitarGrip.inc +++ b/packages/libndsfpc/src/nds/arm9/guitarGrip.inc @@ -11,7 +11,7 @@ function guitarGripIsInserted(): cbool; cdecl; external; procedure guitarGripScanKeys(); cdecl; external; function guitarGripKeysHeld(): cuint8; cdecl; external; -function guitarGripKeysDown(): cuint8; cdecl; external; -function guitarGripKeysUp(): cuint8; cdecl; external; +function guitarGripKeysDown(): cuint16; cdecl; external; +function guitarGripKeysUp(): cuint16; cdecl; external; {$endif NDS_INTERFACE} diff --git a/packages/libndsfpc/src/nds/arm9/math.inc b/packages/libndsfpc/src/nds/arm9/math.inc index 4d399ccc99..5fd6b69e33 100644 --- a/packages/libndsfpc/src/nds/arm9/math.inc +++ b/packages/libndsfpc/src/nds/arm9/math.inc @@ -53,12 +53,12 @@ procedure normalizef32(a: pcint32); inline; {$ifdef NDS_IMPLEMENTATION} function inttof32(n: cint): cint32; inline; begin - inttof32 := ((n) shl 12); + inttof32 := n * (1 shl 12); end; function f32toint(n: cint32): cint; inline; begin - f32toint := ((n) shr 12); + f32toint := n div (1 shl 12); end; function floattof32(n: cfloat): cint32; inline; diff --git a/packages/libndsfpc/src/nds/arm9/nand.inc b/packages/libndsfpc/src/nds/arm9/nand.inc new file mode 100644 index 0000000000..42d3c9c2aa --- /dev/null +++ b/packages/libndsfpc/src/nds/arm9/nand.inc @@ -0,0 +1,6 @@ +{$ifdef NDS_INTERFACE} +function nand_ReadSectors(sector: sec_t; numSectors: sec_t; buffer: pointer): cbool; cdecl; external; +function nand_WriteSectors(sector: sec_t; numSectors: sec_t; buffer: pointer): cbool; cdecl; external; +function nand_GetSize(): ssize_t; cdecl; external; + +{$endif NDS_INTERFACE} diff --git a/packages/libndsfpc/src/nds/arm9/sassert.inc b/packages/libndsfpc/src/nds/arm9/sassert.inc index b4ca8ceaef..b86620d544 100644 --- a/packages/libndsfpc/src/nds/arm9/sassert.inc +++ b/packages/libndsfpc/src/nds/arm9/sassert.inc @@ -29,7 +29,7 @@ end; procedure sassert2(e: boolean; msg: pchar); inline; var - i: integer; + i: integer = 0; s: string; begin if e then diff --git a/packages/libndsfpc/src/nds/arm9/sprite.inc b/packages/libndsfpc/src/nds/arm9/sprite.inc index bced60a231..ae328c5966 100644 --- a/packages/libndsfpc/src/nds/arm9/sprite.inc +++ b/packages/libndsfpc/src/nds/arm9/sprite.inc @@ -211,7 +211,7 @@ const SpriteMapping_Bmp_1D_128: TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_128) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_128) or (5 shl 28) or 2; SpriteMapping_Bmp_1D_256: TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_256) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_256) or (6 shl 28) or 3; SpriteMapping_Bmp_2D_128: TSpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_128) or (7 shl 28) or 2; - SpriteMapping_Bmp_2D_256: TSpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_256) or (8 shl 28) or 3; + SpriteMapping_Bmp_2D_256: TSpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_256) or cint(cuint(8) shl 28) or 3; type SpriteColorFormat = integer; diff --git a/packages/libndsfpc/src/nds/arm9/video.inc b/packages/libndsfpc/src/nds/arm9/video.inc index c3f2a758b9..b00a469855 100644 --- a/packages/libndsfpc/src/nds/arm9/video.inc +++ b/packages/libndsfpc/src/nds/arm9/video.inc @@ -36,8 +36,8 @@ const function RGB15(r, g, b: cint): cuint16; inline; function RGB5(r, g, b: cint): cuint16; inline; -function RGB8(r, g, b: cint): cuint8; inline; -function ARGB16(a, r, g, b: cint): cuint16; inline; +function RGB8(r, g, b: cint): cuint16; inline; +function ARGB16(a, r, g, b: cint): cuint32; inline; const SCREEN_HEIGHT = 192; @@ -507,12 +507,12 @@ begin RGB5 := ((r) or ((g) shl 5) or ((b) shl 10)); end; -function RGB8(r, g, b: cint): cuint8; inline; -begin +function RGB8(r, g, b: cint): cuint16; inline; +begin RGB8 := (((r) shr 3) or (((g) shr 3) shl 5) or (((b) shr 3) shl 10)); end; -function ARGB16(a, r, g, b: cint): cuint16; inline; +function ARGB16(a, r, g, b: cint): cuint32; inline; begin ARGB16 := ((a shl 15) or r or (g shl 5) or (b shl 10)); end; diff --git a/packages/libndsfpc/src/nds/card.inc b/packages/libndsfpc/src/nds/card.inc index 510f305ae3..d0433cf2af 100644 --- a/packages/libndsfpc/src/nds/card.inc +++ b/packages/libndsfpc/src/nds/card.inc @@ -1,13 +1,13 @@ {$ifdef NDS_INTERFACE} const // Card bus - CARD_COMMAND : pcuint8 = pointer($040001A8); - REG_ROMCTRL : pcuint32 = pointer($040001A4); - REG_AUXSPICNT : pcuint16 = pointer($040001A0); - REG_AUXSPICNTH : pcuint8 = pointer($040001A1); - REG_AUXSPIDATA : pcuint8 = pointer($040001A2); - CARD_DATA_RD : pcuint32 = pointer($04100010); - + REG_CARD_DATA_RD : pcuint32 = pointer($04100010); + REG_AUXSPICNT : pcuint16 = pointer($040001A0); + REG_AUXSPICNTH : pcuint8 = pointer($040001A1); + REG_AUXSPIDATA : pcuint8 = pointer($040001A2); + REG_ROMCTRL : pcuint32 = pointer($040001A4); + REG_CARD_COMMAND : pcuint8 = pointer($040001A8); + CARD_1B0 : pcuint32 = pointer($040001B0); CARD_1B4 : pcuint32 = pointer($040001B4); CARD_1B8 : pcuint16 = pointer($040001B8); @@ -80,7 +80,8 @@ const CARD_SPICNTH_IRQ = (1 shl 6); // in byte 1, i.e. 0x4000 - +procedure enableSlot1(); cdecl; external; +procedure disableSlot1(); cdecl; external; procedure cardWriteCommand(const command: pcuint8); cdecl; external; procedure cardPolledTransfer(flags: cuint32; destination: pcuint32; length: cuint32; const command: pcuint8); cdecl; external; diff --git a/packages/libndsfpc/src/nds/disc_io.inc b/packages/libndsfpc/src/nds/disc_io.inc index 10dbbdb254..80edeafe78 100644 --- a/packages/libndsfpc/src/nds/disc_io.inc +++ b/packages/libndsfpc/src/nds/disc_io.inc @@ -1,10 +1,10 @@ {$ifdef NDS_INTERFACE} -const - FEATURE_MEDIUM_CANREAD = $00000001; - FEATURE_MEDIUM_CANWRITE = $00000002; - FEATURE_SLOT_GBA = $00000010; - FEATURE_SLOT_NDS = $00000020; +//const +// FEATURE_MEDIUM_CANREAD = $00000001; +// FEATURE_MEDIUM_CANWRITE = $00000002; +// FEATURE_SLOT_GBA = $00000010; +// FEATURE_SLOT_NDS = $00000020; function DEVICE_TYPE_DSI_SD(): cuint32; inline; @@ -30,6 +30,8 @@ type DISC_INTERFACE = DISC_INTERFACE_STRUCT; TDISC_INTERFACE = DISC_INTERFACE_STRUCT; PDISC_INTERFACE = ^DISC_INTERFACE_STRUCT; + + (* PARTITION_INTERFACE = ( PI_DEFAULT = 0, @@ -39,16 +41,14 @@ type ); *) -var - __io_dsisd: DISC_INTERFACE; cvar; external; - +function get_io_dsisd(): PDISC_INTERFACE; cdecl; external; {$endif NDS_INTERFACE} {$ifdef NDS_IMPLEMENTATION} function DEVICE_TYPE_DSI_SD(): cuint32; inline; begin - DEVICE_TYPE_DSI_SD := ord('i') or (ord('_') shl 8) or (ord('S') shl 16) or (ord('D') shl 24); + DEVICE_TYPE_DSI_SD := ord('_') or (ord('S') shl 8) or (ord('D') shl 16) or (ord('_') shl 24); end; diff --git a/packages/libndsfpc/src/nds/dma.inc b/packages/libndsfpc/src/nds/dma.inc index e00f2b9985..0a00730552 100644 --- a/packages/libndsfpc/src/nds/dma.inc +++ b/packages/libndsfpc/src/nds/dma.inc @@ -166,10 +166,10 @@ end; procedure dmaFillHalfWords(value: cuint16; dest: pointer; size: cuint32); inline; begin {$ifdef ARM7} - pcuint32($027FFE04)^ := value; + pcuint32($027FFE04)^ := cuint32(value); DMA_SRC(3)^ := $027FFE04; {$else ARM7} - DMA_FILL(3)^ := value; + DMA_FILL(3)^ := cuint32(value); // pcuint32(DMA_SRC(3)^) := pcuint32(DMA_FILL(3)); DMA_SRC(3)^ := cuint32(DMA_FILL(3)); {$endif ARM7} diff --git a/packages/libndsfpc/src/nds/fifocommon.inc b/packages/libndsfpc/src/nds/fifocommon.inc index 06fa3ff1a3..0e7c3d9d9f 100644 --- a/packages/libndsfpc/src/nds/fifocommon.inc +++ b/packages/libndsfpc/src/nds/fifocommon.inc @@ -51,12 +51,12 @@ type FifoSdmmcCommands = integer; const SDMMC_HAVE_SD : FifoSystemCommands = 0; - SDMMC_SD_START : FifoSystemCommands = 1; - SDMMC_SD_IS_INSERTED : FifoSystemCommands = 2; - SDMMC_SD_STOP : FifoSystemCommands = 3; - SDMMC_NAND_START : FifoSystemCommands = 4; - SDMMC_NAND_STOP : FifoSystemCommands = 5; - + SDMMC_SD_START : FifoSystemCommands = 1; + SDMMC_SD_IS_INSERTED : FifoSystemCommands = 2; + SDMMC_SD_STOP : FifoSystemCommands = 3; + SDMMC_NAND_START : FifoSystemCommands = 4; + SDMMC_NAND_STOP : FifoSystemCommands = 5; + SDMMC_NAND_SIZE : FifoSystemCommands = 6; type FifoFirmwareCommands = integer; const @@ -73,7 +73,8 @@ const PM_REQ_SLEEP_DISABLE : FifoPMCommands = (5 shl 16); PM_REQ_SLEEP_ENABLE : FifoPMCommands = (6 shl 16); PM_REQ_BATTERY : FifoPMCommands = (7 shl 16); - PM_DSI_HACK : FifoPMCommands = (8 shl 16); + PM_REQ_SLOT1_DISABLE : FifoPMCommands = (8 shl 16); + PM_REQ_SLOT1_ENABLE : FifoPMCommands = (9 shl 16); type FifoWifiCommands = integer; diff --git a/packages/libndsfpc/src/nds/fifomessages.inc b/packages/libndsfpc/src/nds/fifomessages.inc index a271a39742..f56f44964c 100644 --- a/packages/libndsfpc/src/nds/fifomessages.inc +++ b/packages/libndsfpc/src/nds/fifomessages.inc @@ -69,7 +69,7 @@ type end; ); 6: ( - fwParams: record + blockParams: record buffer: pointer; address: cuint32; length: cuint32; diff --git a/packages/libndsfpc/src/nds/interrupts.inc b/packages/libndsfpc/src/nds/interrupts.inc index 944693128c..26d622273a 100644 --- a/packages/libndsfpc/src/nds/interrupts.inc +++ b/packages/libndsfpc/src/nds/interrupts.inc @@ -25,7 +25,7 @@ const IRQ_LID : IRQ_MASK = (1 shl 22); (* interrupt mask hinge *) IRQ_SPI : IRQ_MASK = (1 shl 23); (* SPI interrupt mask *) IRQ_WIFI : IRQ_MASK = (1 shl 24); (* WIFI interrupt mask (ARM7)*) - IRQ_ALL : IRQ_MASK = (not 0); //$FFFFFF ? + IRQ_ALL : IRQ_MASK = $FFFFFFFF;//(not 0); //$FFFFFF ? type diff --git a/packages/libndsfpc/src/nds/libversion.inc b/packages/libndsfpc/src/nds/libversion.inc index 0c353ae73a..359f084f1f 100644 --- a/packages/libndsfpc/src/nds/libversion.inc +++ b/packages/libndsfpc/src/nds/libversion.inc @@ -1,10 +1,10 @@ {$ifdef NDS_INTERFACE} const _LIBNDS_MAJOR_ = 1; - _LIBNDS_MINOR_ = 5; - _LIBNDS_PATCH_ = 12; + _LIBNDS_MINOR_ = 7; + _LIBNDS_PATCH_ = 3; - _LIBNDS_STRING = 'libNDS Release 1.5.12'; + _LIBNDS_STRING = 'libNDS Release 1.7.3'; {$endif NDS_INTERFACE} {$ifdef NDS_IMPLEMENTATION} diff --git a/packages/libndsfpc/src/nds/memory.inc b/packages/libndsfpc/src/nds/memory.inc index a2c2125cbf..151771a541 100644 --- a/packages/libndsfpc/src/nds/memory.inc +++ b/packages/libndsfpc/src/nds/memory.inc @@ -11,6 +11,16 @@ const ARM7_OWNS_ROM = (1 shl 7); + REG_MBK1: pcuint8 = pointer($04004040); // WRAM_A 0..3 + REG_MBK2: pcuint8 = pointer($04004044); // WRAM_B 0..3 + REG_MBK3: pcuint8 = pointer($04004048); // WRAM_B 4..7 + REG_MBK4: pcuint8 = pointer($0400404C); // WRAM_C 0..3 + REG_MBK5: pcuint8 = pointer($04004050); // WRAM_C 4..7 + REG_MBK6: pcuint32 = pointer($04004054); + REG_MBK7: pcuint32 = pointer($04004058); + REG_MBK8: pcuint32 = pointer($0400405C); + REG_MBK9: pcuint32 = pointer($04004060); + // Protection register (write-once sadly) {$ifdef ARM7} PROTECTION : pcuint32 = pointer($04000308); @@ -69,13 +79,13 @@ type flags: cuint8; // auto-boot flag arm9romOffset: cuint32; - arm9executeAddress: cuint32; - arm9destination: cuint32; + arm9executeAddress: pointer; + arm9destination: pointer; arm9binarySize: cuint32; arm7romOffset: cuint32; - arm7executeAddress: cuint32; - arm7destination: cuint32; + arm7executeAddress: pointer; + arm7destination: pointer; arm7binarySize: cuint32; filenameOffset: cuint32; @@ -108,20 +118,88 @@ type gbaLogo: array [0..155] of cuint8; logoCRC16: cuint16; headerCRC16: cuint16; - + end; + tNDSHeader = sNDSHeader; + pNDSHeader = ^tNDSHeader; + + DSiHeader = packed record + ndshdr: tNDSHeader; debugRomSource: cuint32; debugRomSize: cuint32; debugRomDestination: cuint32; offset_0x16C: cuint32; - zero: array [0..143] of cuint8; + zero: array [0..15] of cuint8; + + global_mbk_setting: array [0..4, 0..3] of cuint8; + arm9_mbk_setting: array [0..2] of cuint32; + arm7_mbk_setting: array [0..2] of cuint32; + mbk9_wramcnt_setting: cuint32; + + region_flags: cuint32; + access_control: cuint32; + scfg_ext_mask: cuint32; + offset_0x1BC: array [0..2] of cuint8; + appflags: cuint8; + + arm9iromOffset: pointer; + offset_0x1C4: cuint32; + arm9idestination: pointer; + arm9ibinarySize: cuint32; + arm7iromOffset: pointer; + offset_0x1D4: cuint32; + arm7idestination: pointer; + arm7ibinarySize: cuint32; + + digest_ntr_start: cuint32; + digest_ntr_size: cuint32; + digest_twl_start: cuint32; + digest_twl_size: cuint32; + sector_hashtable_start: cuint32; + sector_hashtable_size: cuint32; + block_hashtable_start: cuint32; + block_hashtable_size: cuint32; + digest_sector_size: cuint32; + digest_block_sectorcount: cuint32; + + banner_size: cuint32; + offset_0x20C: cuint32; + total_rom_size: cuint32; + offset_0x214: cuint32; + offset_0x218: cuint32; + offset_0x21C: cuint32; + + modcrypt1_start: cuint32; + modcrypt1_size: cuint32; + modcrypt2_start: cuint32; + modcrypt2_size: cuint32; + + tid_low: cuint32; + tid_high: cuint32; + public_sav_size: cuint32; + private_sav_size: cuint32; + reserved3: array [0..175] of cuint8; + age_ratings: array [0..15] of cuint8; + + hmac_arm9: array [0..19] of cuint8; + hmac_arm7: array [0..19] of cuint8; + hmac_digest_master: array [0..19] of cuint8; + hmac_icon_title: array [0..19] of cuint8; + hmac_arm9i: array [0..19] of cuint8; + hmac_arm7i: array [0..19] of cuint8; + reserved4: array [0..39] of cuint8; + hmac_arm9_no_secure: array [0..19] of cuint8; + reserved5: array [0..2635] of cuint8; + debug_args: array [0..383] of cuint8; + rsa_signature: array [0..127] of cuint8; end; - tNDSHeader = sNDSHeader; - pNDSHeader = ^tNDSHeader; + T__DSiHeader = DSiHeader; + P__DSiHeader = ^T__DSiHeader; + const - __NDSHeader : pNDSHeader = pointer($02FFFE00); - + __NDSHeader : pNDSHeader = pointer($02FFFE00); + __DSiHeader : P__DSiHeader = pointer($02FFE000); type sNDSBanner = packed record diff --git a/packages/libndsfpc/src/nds/ndsinclude.inc b/packages/libndsfpc/src/nds/ndsinclude.inc index 0dcfebac7a..c919bccc07 100644 --- a/packages/libndsfpc/src/nds/ndsinclude.inc +++ b/packages/libndsfpc/src/nds/ndsinclude.inc @@ -17,12 +17,15 @@ {$include timers.inc} {$include fifomessages.inc} {$include input.inc} +{$include rsa.inc} +{$include sha1.inc} {$ifdef ARM9} {$include arm9/dynamicArray.inc} {$include arm9/linkedlist.inc} {$include arm9/sassert.inc} {$include arm9/background.inc} + {$include arm9/cache_asm.inc} {$include arm9/cache.inc} {$include arm9/console.inc} {$include arm9/keyboard.inc} @@ -30,6 +33,7 @@ {$include arm9/image.inc} {$include arm9/input.inc} {$include arm9/math.inc} + {$include arm9/nand.inc} {$include arm9/pcx.inc} {$include arm9/rumble.inc} {$include arm9/sound.inc} @@ -44,13 +48,16 @@ {$include arm9/guitarGrip.inc} {$include arm9/paddle.inc} {$include arm9/piano.inc} + {$include arm9/dldi_asm.inc} {$include arm9/dldi.inc} {$include arm9/window.inc} {$endif ARM9} {$ifdef ARM7} + {$include arm7/aes.inc} {$include arm7/audio.inc} {$include arm7/clock.inc} + {$include arm7/codec.inc} {$include arm7/input.inc} {$include arm7/i2c.inc} {$include arm7/serial.inc} diff --git a/packages/libndsfpc/src/nds/ndstypes.inc b/packages/libndsfpc/src/nds/ndstypes.inc index 3d0b140295..926f41ab89 100644 --- a/packages/libndsfpc/src/nds/ndstypes.inc +++ b/packages/libndsfpc/src/nds/ndstypes.inc @@ -7,6 +7,11 @@ #define DTCM_DATA __attribute__((section(".dtcm"))) #define DTCM_BSS __attribute__((section(".sbss"))) + +#define TWL_CODE __attribute__((section(".twl"))) +#define TWL_DATA __attribute__((section(".twl"))) +#define TWL_BSS __attribute__((section(".twl_bss"))) + #define ALIGN(m) __attribute__((aligned (m))) #define PACKED __attribute__ ((packed)) @@ -96,7 +101,9 @@ typedef volatile s16 vs16; typedef volatile s32 vs32; typedef volatile s64 vs64; } - + sec_t = cuint32; + ssize_t = cint; + size_t = cuint; //IntFn = function: pointer; VoidFn = function: pointer; cdecl; diff --git a/packages/libndsfpc/src/nds/registers_alt.inc b/packages/libndsfpc/src/nds/registers_alt.inc index fb856109a9..80d7c40b11 100644 --- a/packages/libndsfpc/src/nds/registers_alt.inc +++ b/packages/libndsfpc/src/nds/registers_alt.inc @@ -270,14 +270,14 @@ const CARD_CR2 = REG_ROMCTRL; CARD_EEPDATA = REG_AUXSPIDATA; - REG_CARD_DATA : pcuint32 = pointer($04100000); - REG_CARD_DATA_RD : pcuint32 = pointer($04100010); - - REG_CARD_1B0 : pcuint32 = pointer($040001B0); - REG_CARD_1B4 : pcuint32 = pointer($040001B4); - REG_CARD_1B8 : pcuint16 = pointer($040001B8); - REG_CARD_1BA : pcuint16 = pointer($040001BA); - + CARD_COMMAND = REG_CARD_COMMAND; + CARD_DATA_RD = REG_CARD_DATA_RD; + + CARD_1B0 = REG_CARD_1B0; + CARD_1B4 = REG_CARD_1B4; + CARD_1B8 = REG_CARD_1B8; + CARD_1BA = REG_CARD_1BA; + SOUND_CR = REG_SOUNDCNT; SOUND_MASTER_VOL = REG_MASTER_VOLUME; SOUND_BIAS = REG_SOUNDBIAS; diff --git a/packages/libndsfpc/src/nds/rsa.inc b/packages/libndsfpc/src/nds/rsa.inc new file mode 100644 index 0000000000..f6e472c9c7 --- /dev/null +++ b/packages/libndsfpc/src/nds/rsa.inc @@ -0,0 +1,31 @@ +{$ifdef NDS_INTERFACE} +type + swiRSAHeapContext = packed record + heapStart: pointer; + heapEnd: pointer; + heapSize: size_t; + end; + swiRSAHeapContext_t = swiRSAHeapContext; + TswiRSAHeapContext = swiRSAHeapContext; + PswiRSAHeapContext = ^TswiRSAHeapContext; + + + swiRSAbuffers = packed record + dst: pointer; + sig: pointer; + key: pointer; + end; + swiRSAbuffers_t = swiRSAbuffers; + TswiRSAbuffers = swiRSAbuffers; + PswiRSAbuffers = ^TswiRSAbuffers; + +function swiRSAInitHeap(ctx: PswiRSAHeapContext; heapStart: pointer; heapSize: size_t): cint; cdecl; external; +function swiRSADecryptRAW(ctx: PswiRSAHeapContext; rsabuffers: PswiRSAbuffers; len: size_t): cint; cdecl; external; +function swiRSADecrypt(ctx: PswiRSAHeapContext; dst: pointer; const sig: pointer; const key: pointer): cint; cdecl; external; +function swiRSADecryptPGP(ctx: PswiRSAHeapContext; dst: pointer; const sig: pointer; const key: pointer): cint; cdecl; external; +{$endif NDS_INTERFACE} + +{$ifdef NDS_IMPLEMENTATION} + + +{$endif NDS_IMPLEMENTATION}
\ No newline at end of file diff --git a/packages/libndsfpc/src/nds/sha1.inc b/packages/libndsfpc/src/nds/sha1.inc new file mode 100644 index 0000000000..0c009e43d4 --- /dev/null +++ b/packages/libndsfpc/src/nds/sha1.inc @@ -0,0 +1,30 @@ +{$ifdef NDS_INTERFACE} + +type + swiSHA1context = packed record + type + TSHA_Block = procedure(var ctx: swiSHA1context; src: pointer; len: size_t); + PSHA_Block = ^TSHA_Block; + var + state: array [0..4] of cuint32; + total: array [0..1] of cuint32; + buffer: array [0..63] of cuint8; + fragment_size: cuint32; + sha_block: PSHA_Block; + end; + swiSHA1context_t = swiSHA1context; + TswiSHA1context_t = swiSHA1context_t; + PswiSHA1context_t = ^TswiSHA1context_t; + + +procedure swiSHA1Init(var ctx: TswiSHA1context_t); cdecl; external; +procedure swiSHA1Update(var ctx: TswiSHA1context_t; data: pointer; len: size_t); cdecl; external; +procedure swiSHA1Final(digest: pointer; var ctx: TswiSHA1context_t); cdecl; external; +procedure swiSHA1Calc(digest: pointer; data: pointer; len: size_t); cdecl; external; +procedure swiSHA1Verify(digest1, digest2: pointer); cdecl; external; +{$endif NDS_INTERFACE} + +{$ifdef NDS_IMPLEMENTATION} + + +{$endif NDS_IMPLEMENTATION}
\ No newline at end of file diff --git a/packages/libndsfpc/src/nds/system.inc b/packages/libndsfpc/src/nds/system.inc index 60cd0ca2e9..8056cc02d0 100644 --- a/packages/libndsfpc/src/nds/system.inc +++ b/packages/libndsfpc/src/nds/system.inc @@ -15,7 +15,18 @@ const REG_VCOUNT : pcuint16 = pointer($04000006); HALT_CR : pcuint16 = pointer($04000300); REG_POWERCNT : pcuint16 = pointer($04000304); - REG_DSIMODE : pcuint32 = pointer($04004000); + + REG_SCFG_ROM : pcuint16 = pointer($04004000); + +{$ifdef ARM7} + REG_SCFG_A9ROM : pcuint8 = pointer($4004000); + REG_SCFG_A7ROM : pcuint8 = pointer($4004001); // ?? +{$endif ARM7} + + REG_SCFG_CLK : pcuint16 = pointer($4004004); + REG_SCFG_RST : pcuint16 = pointer($4004006); + REG_SCFG_EXT : pcuint32 = pointer($4004008); + REG_SCFG_MC : pcuint16 = pointer($4004010); procedure SetYtrigger(Yvalue: cint); inline; @@ -45,8 +56,7 @@ const //procedure SystemSleep(); cdecl; external; procedure ledBlink(bm: cint); cdecl; external; -var - __dsimode: cbool; cvar; external; +function isDSiMode(): cbool; inline; {$ifdef ARM9} procedure SystemSleep(); cdecl; external; @@ -72,12 +82,12 @@ procedure setVectorBase(highVector: cint); cdecl; external; type sysVectors_t = packed record - reset: cuint32; - undefined: cuint32; - swi: cuint32; - prefetch_abort: cuint32; - data_abort: cuint32; - fiq: cuint32; + reset: VoidFn; + undefined: VoidFn; + swi: VoidFn; + prefetch_abort: VoidFn; + data_abort: VoidFn; + fiq: VoidFn; end; sysVectors = sysVectors_t; PsysVectors = ^sysVectors; @@ -88,6 +98,8 @@ var //void setSDcallback(void(*callback)(int)); procedure setSDcallback(callback: pointer); cdecl; external; // ?? +function setCpuClock(speed: cbool): cbool; cdecl; external; + // Helper functions for heap size //! returns current start of heap space function getHeapStart(): pcuint8; cdecl; external; @@ -100,6 +112,9 @@ function getHeapLimit(): pcuint8; cdecl; external; {$ifdef ARM7} +const + REG_CONSOLEID : pcuint64 = pointer($04004D00); + type ARM7_power = cint; const @@ -226,7 +241,7 @@ const __system_argv: Pargv = pointer($02FFFE70); const - BOOTSIG: cardinal = $62757473746F6F62; // ULL? + BOOTSIG: cuint64 = $62757473746F6F62; // ULL? type @@ -308,5 +323,13 @@ begin end; {$endif ARM7} + +var + __dsimode: cbool; cvar; external; +function isDSiMode(): cbool; inline; +begin + isDSiMode := __dsimode; +end; + {$endif NDS_IMPLEMENTATION} diff --git a/packages/libndsfpc/src/nds7.pp b/packages/libndsfpc/src/nds7.pp index 04a4890adf..0b524f8eb5 100644 --- a/packages/libndsfpc/src/nds7.pp +++ b/packages/libndsfpc/src/nds7.pp @@ -39,7 +39,7 @@ unit nds7; {$INLINE ON} {$MACRO ON} {$PACKRECORDS C} - +{$modeswitch ADVANCEDRECORDS} interface uses diff --git a/packages/libndsfpc/src/nds9.pp b/packages/libndsfpc/src/nds9.pp index a53b38b3d3..043e34b339 100644 --- a/packages/libndsfpc/src/nds9.pp +++ b/packages/libndsfpc/src/nds9.pp @@ -39,6 +39,7 @@ unit nds9; {$MACRO ON} {$PACKRECORDS C} {$ASSERTIONS ON} +{$modeswitch ADVANCEDRECORDS} interface uses |