summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/libndsfpc/src')
-rw-r--r--packages/libndsfpc/src/dswifi/dswifi7.inc60
-rw-r--r--packages/libndsfpc/src/dswifi/dswifi7.pp32
-rw-r--r--packages/libndsfpc/src/dswifi/dswifi9.inc220
-rw-r--r--packages/libndsfpc/src/dswifi/dswifi9.pp32
-rw-r--r--packages/libndsfpc/src/dswifi/dswifi_version.inc7
-rw-r--r--packages/libndsfpc/src/dswifi/netdb.inc57
-rw-r--r--packages/libndsfpc/src/dswifi/netinet/in.inc65
-rw-r--r--packages/libndsfpc/src/dswifi/sgIP_errno.inc183
-rw-r--r--packages/libndsfpc/src/dswifi/sys/socket.inc166
-rw-r--r--packages/libndsfpc/src/fat/fat.inc88
-rw-r--r--packages/libndsfpc/src/fat/fat.pp32
-rw-r--r--packages/libndsfpc/src/fat/gbfs.inc75
-rw-r--r--packages/libndsfpc/src/fat/gbfs.pp32
-rw-r--r--packages/libndsfpc/src/libmikmod/inc/mikmod.inc1076
-rw-r--r--packages/libndsfpc/src/libmikmod/mikmod7.pp32
-rw-r--r--packages/libndsfpc/src/libmikmod/mikmod9.pp32
-rw-r--r--packages/libndsfpc/src/nds/arm7/audio.inc200
-rw-r--r--packages/libndsfpc/src/nds/arm7/clock.inc107
-rw-r--r--packages/libndsfpc/src/nds/arm7/serial.inc185
-rw-r--r--packages/libndsfpc/src/nds/arm7/touch.inc66
-rw-r--r--packages/libndsfpc/src/nds/arm9/background.inc96
-rw-r--r--packages/libndsfpc/src/nds/arm9/boxtest.inc52
-rw-r--r--packages/libndsfpc/src/nds/arm9/cache.inc53
-rw-r--r--packages/libndsfpc/src/nds/arm9/console.inc51
-rw-r--r--packages/libndsfpc/src/nds/arm9/exceptions.inc55
-rw-r--r--packages/libndsfpc/src/nds/arm9/image.inc72
-rw-r--r--packages/libndsfpc/src/nds/arm9/input.inc75
-rw-r--r--packages/libndsfpc/src/nds/arm9/math.inc245
-rw-r--r--packages/libndsfpc/src/nds/arm9/ndsmotion.inc72
-rw-r--r--packages/libndsfpc/src/nds/arm9/pcx.inc65
-rw-r--r--packages/libndsfpc/src/nds/arm9/postest.inc86
-rw-r--r--packages/libndsfpc/src/nds/arm9/rumble.inc56
-rw-r--r--packages/libndsfpc/src/nds/arm9/sound.inc45
-rw-r--r--packages/libndsfpc/src/nds/arm9/sprite.inc224
-rw-r--r--packages/libndsfpc/src/nds/arm9/trig_lut.inc50
-rw-r--r--packages/libndsfpc/src/nds/arm9/video.inc766
-rw-r--r--packages/libndsfpc/src/nds/arm9/videoGL.inc1440
-rw-r--r--packages/libndsfpc/src/nds/bios.inc125
-rw-r--r--packages/libndsfpc/src/nds/card.inc101
-rw-r--r--packages/libndsfpc/src/nds/dma.inc206
-rw-r--r--packages/libndsfpc/src/nds/helper.inc139
-rw-r--r--packages/libndsfpc/src/nds/interrupts.inc117
-rw-r--r--packages/libndsfpc/src/nds/ipc.inc180
-rw-r--r--packages/libndsfpc/src/nds/jtypes.inc168
-rw-r--r--packages/libndsfpc/src/nds/memory.inc272
-rw-r--r--packages/libndsfpc/src/nds/nds.inc126
-rw-r--r--packages/libndsfpc/src/nds/ndsinclude.inc39
-rw-r--r--packages/libndsfpc/src/nds/registers_alt.inc309
-rw-r--r--packages/libndsfpc/src/nds/reload.inc84
-rw-r--r--packages/libndsfpc/src/nds/system.inc225
-rw-r--r--packages/libndsfpc/src/nds/timers.inc130
-rw-r--r--packages/libndsfpc/src/nds7.pp32
-rw-r--r--packages/libndsfpc/src/nds9.pp32
53 files changed, 8535 insertions, 0 deletions
diff --git a/packages/libndsfpc/src/dswifi/dswifi7.inc b/packages/libndsfpc/src/dswifi/dswifi7.inc
new file mode 100644
index 0000000000..9a7e1ed445
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/dswifi7.inc
@@ -0,0 +1,60 @@
+(*
+ $Id: dswifi7.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - Arm7 Library Header file (dswifi7.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+{$include dswifi_version.inc}
+
+{$ifdef NDS_INTERFACE}
+
+type
+ WifiSyncHandler = procedure;
+
+procedure Read_Flash(address: cint; destination: pcchar; length: cint); cdecl; external;
+function PowerChip_ReadWrite(cmd, data: cint): cint; cdecl; external;
+procedure Wifi_Interrupt(); cdecl; external;
+procedure Wifi_Update(); cdecl; external;
+procedure Wifi_Init(WifiData: culong); cdecl; external;
+procedure Wifi_Deinit(); cdecl; external;
+procedure Wifi_Sync(); cdecl; external;
+procedure Wifi_SetSyncHandler(sh: WifiSyncHandler); cdecl; external;
+//procedure Wifi_SetSyncHandler(sh: pointer); cdecl; external;
+
+{$endif NDS_INTERFACE}
+
diff --git a/packages/libndsfpc/src/dswifi/dswifi7.pp b/packages/libndsfpc/src/dswifi/dswifi7.pp
new file mode 100644
index 0000000000..635142b1a5
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/dswifi7.pp
@@ -0,0 +1,32 @@
+unit dswifi7;
+{$mode objfpc}
+{$apptype arm7}
+{$define arm7}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds7;
+
+{$linklib nds7}
+{$linklib dswifi7}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include dswifi7.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include dswifi7.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/dswifi/dswifi9.inc b/packages/libndsfpc/src/dswifi/dswifi9.inc
new file mode 100644
index 0000000000..2fdec8a9d8
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/dswifi9.inc
@@ -0,0 +1,220 @@
+(*
+ $Id: dswifi9.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - Arm9 Library Header File (dswifi9.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+
+{$include dswifi_version.inc}
+
+{$include sys/socket.inc}
+{$include netinet/in.inc}
+{$include netdb.inc}
+
+{$ifdef NDS_INTERFACE}
+
+const
+ WIFIINIT_OPTION_USELED = $0002;
+
+ WIFIINIT_OPTION_USEHEAP_128 = $0000;
+ WIFIINIT_OPTION_USEHEAP_64 = $1000;
+ WIFIINIT_OPTION_USEHEAP_256 = $2000;
+ WIFIINIT_OPTION_USEHEAP_512 = $3000;
+ WIFIINIT_OPTION_USECUSTOMALLOC = $4000;
+ WIFIINIT_OPTION_HEAPMASK = $F000;
+
+ WFLAG_PACKET_DATA = $0001;
+ WFLAG_PACKET_MGT = $0002;
+ WFLAG_PACKET_BEACON = $0004;
+ WFLAG_PACKET_CTRL = $0008;
+
+ WFLAG_PACKET_ALL = $FFFF;
+
+
+ WFLAG_APDATA_ADHOC = $0001;
+ WFLAG_APDATA_WEP = $0002;
+ WFLAG_APDATA_WPA = $0004;
+ WFLAG_APDATA_COMPATIBLE = $0008;
+ WFLAG_APDATA_EXTCOMPATIBLE = $0010;
+ WFLAG_APDATA_SHORTPREAMBLE = $0020;
+ WFLAG_APDATA_ACTIVE = $8000;
+
+type
+ TWIFI_RETURN = (
+ WIFI_RETURN_OK = 0,
+ WIFI_RETURN_LOCKFAILED = 1,
+ WIFI_RETURN_ERROR = 2,
+ WIFI_RETURN_PARAMERROR = 3
+ );
+
+ TWIFI_STATS = (
+ WSTAT_RXQUEUEDPACKETS,
+ WSTAT_TXQUEUEDPACKETS,
+ WSTAT_RXQUEUEDBYTES,
+ WSTAT_TXQUEUEDBYTES,
+ WSTAT_RXQUEUEDLOST,
+ WSTAT_TXQUEUEDREJECTED,
+ WSTAT_RXPACKETS,
+ WSTAT_RXBYTES,
+ WSTAT_RXDATABYTES,
+ WSTAT_TXPACKETS,
+ WSTAT_TXBYTES,
+ WSTAT_TXDATABYTES,
+
+ WSTAT_HW_1B0,WSTAT_HW_1B1,WSTAT_HW_1B2,WSTAT_HW_1B3,WSTAT_HW_1B4,WSTAT_HW_1B5,WSTAT_HW_1B6,WSTAT_HW_1B7,
+ WSTAT_HW_1B8,WSTAT_HW_1B9,WSTAT_HW_1BA,WSTAT_HW_1BB,WSTAT_HW_1BC,WSTAT_HW_1BD,WSTAT_HW_1BE,WSTAT_HW_1BF,
+ WSTAT_HW_1C0,WSTAT_HW_1C1,WSTAT_HW_1C4,WSTAT_HW_1C5,
+ WSTAT_HW_1D0,WSTAT_HW_1D1,WSTAT_HW_1D2,WSTAT_HW_1D3,WSTAT_HW_1D4,WSTAT_HW_1D5,WSTAT_HW_1D6,WSTAT_HW_1D7,
+ WSTAT_HW_1D8,WSTAT_HW_1D9,WSTAT_HW_1DA,WSTAT_HW_1DB,WSTAT_HW_1DC,WSTAT_HW_1DD,WSTAT_HW_1DE,WSTAT_HW_1DF,
+
+ NUM_WIFI_STATS
+ );
+
+ TWIFI_MODE = (
+ WIFIMODE_DISABLED,
+ WIFIMODE_NORMAL,
+ WIFIMODE_SCAN,
+ WIFIMODE_ASSOCIATE,
+ WIFIMODE_ASSOCIATED,
+ WIFIMODE_DISASSOCIATE,
+ WIFIMODE_CANNOTASSOCIATE
+ );
+
+ TWIFI_AUTHLEVEL = (
+ WIFI_AUTHLEVEL_DISCONNECTED,
+ WIFI_AUTHLEVEL_AUTHENTICATED,
+ WIFI_AUTHLEVEL_ASSOCIATED,
+ WIFI_AUTHLEVEL_DEASSOCIATED
+ );
+
+ TWIFIGETDATA = (
+ WIFIGETDATA_MACADDRESS,
+ WIFIGETDATA_NUMWFCAPS,
+ MAX_WIFIGETDATA
+ );
+
+
+ TWEPMODES = (
+ WEPMODE_NONE = 0,
+ WEPMODE_40BIT = 1,
+ WEPMODE_128BIT = 2
+ );
+
+ TWIFI_ASSOCSTATUS = (
+ ASSOCSTATUS_DISCONNECTED,
+ ASSOCSTATUS_SEARCHING,
+ ASSOCSTATUS_AUTHENTICATING,
+ ASSOCSTATUS_ASSOCIATING,
+ ASSOCSTATUS_ACQUIRINGDHCP,
+ ASSOCSTATUS_ASSOCIATED,
+ ASSOCSTATUS_CANNOTCONNECT
+ );
+
+ WIFI_TXHEADER = record
+ enable_flags: cuint16;
+ unknown: cuint16;
+ countup: cuint16;
+ beaconfreq: cuint16;
+ tx_rate: cuint16;
+ tx_length: cuint16;
+ end;
+ TWIFI_TXHEADER = WIFI_TXHEADER;
+ PWIFI_TXHEADER = ^WIFI_TXHEADER;
+
+ WIFI_RXHEADER = record
+ a: cuint16;
+ b: cuint16;
+ c: cuint16;
+ d: cuint16;
+ byteLength: cuint16;
+ rssi_: cuint16;
+ end;
+ TWIFI_RXHEADER = WIFI_RXHEADER;
+ PWIFI_RXHEADER = ^WIFI_RXHEADER;
+
+ WIFI_ACCESSPOINT = packed record
+ ssid: array [0..32] of cchar;
+ ssid_len: cchar;
+ bssid: array [0..5] of cuint8;
+ macaddr: array [0..5] of cuint8;
+ maxrate: cuint16;
+ timectr: cuint32;
+ rssi: cuint16;
+ flags: cuint16;
+ spinlock: cuint32;
+ channel: cuint8;
+ rssi_past: array [0..7] of cuint8;
+ base_rates: array [0..15] of cuint8;
+ end;
+ TWIFI_ACCESSPOINT = WIFI_ACCESSPOINT;
+ PWIFI_ACCESSPOINT = ^WIFI_ACCESSPOINT;
+
+ WifiPacketHandler = procedure(packetID, packetlength: cint);
+
+ WifiSyncHandler = procedure;
+
+
+function Wifi_Init(initflags: cint): culong; cdecl; external;
+function Wifi_CheckInit(): cint; cdecl; external;
+procedure Wifi_DisableWifi(); cdecl; external;
+procedure Wifi_EnableWifi(); cdecl; external;
+procedure Wifi_SetPromiscuousMode(enable: cint); cdecl; external;
+procedure Wifi_ScanMode(); cdecl; external;
+procedure Wifi_SetChannel(channel: cint); cdecl; external;
+function Wifi_GetNumAP(): cint; cdecl; external;
+function Wifi_GetAPData(apnum: cint; apdata: PWifi_AccessPoint): cint; cdecl; external;
+function Wifi_FindMatchingAP(numaps: cint; apdata: PWifi_AccessPoint; match_dest: PWifi_AccessPoint): cint; cdecl; external;
+function Wifi_ConnectAP(apdata: PWifi_AccessPoint; wepmode, wepkeyid: cint; wepkey: pcuchar): cint; cdecl; external;
+procedure Wifi_AutoConnect(); cdecl; external;
+function Wifi_AssocStatus(): cint; cdecl; external;
+function Wifi_DisconnectAP(): cint; cdecl; external;
+procedure Wifi_Timer(num_ms: cint); cdecl; external;
+function Wifi_GetIP(): cuint32; cdecl; external;
+function Wifi_GetIPInfo(pGateway, pSnmask, pDns1, pDns2: pcuint32): cuint32; cdecl; external;
+procedure Wifi_SetIP(IPaddr, gateway, subnetmask, dns1, dns2: u32); cdecl; external;
+function Wifi_GetData(datatype, bufferlen: cint; buffer: pcuchar): cint; cdecl; external;
+function Wifi_GetStats(statnum: cint): cuint32; cdecl; external;
+function Wifi_RawTxFrame(datalen, rate: cuint16; data: pcuint16): cint; cdecl; external;
+procedure Wifi_RawSetPacketHandler(wphfunc: WifiPacketHandler); cdecl; external;
+function Wifi_RxRawReadPacket(packetID, readlength: cint32; data: pcuint16): cint; cdecl; external;
+procedure Wifi_Update(); cdecl; external;
+procedure Wifi_Sync(); cdecl; external;
+procedure Wifi_SetSyncHandler(sh: WifiSyncHandler); cdecl; external;
+//procedure Wifi_SetSyncHandler(sh: pointer); cdecl; external;
+
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/dswifi/dswifi9.pp b/packages/libndsfpc/src/dswifi/dswifi9.pp
new file mode 100644
index 0000000000..dca1b60719
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/dswifi9.pp
@@ -0,0 +1,32 @@
+unit dswifi9;
+{$mode objfpc}
+{$apptype arm9}
+{$define arm9}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds9;
+
+{$linklib nds9}
+{$linklib dswifi9}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include dswifi9.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include dswifi9.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/dswifi/dswifi_version.inc b/packages/libndsfpc/src/dswifi/dswifi_version.inc
new file mode 100644
index 0000000000..5515bb84c0
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/dswifi_version.inc
@@ -0,0 +1,7 @@
+{$ifdef NDS_INTERFACE}
+const
+ DSWIFI_MAJOR = 0;
+ DSWIFI_MINOR = 3;
+ DSWIFI_REVISION = 4;
+ DSWIFI_VERSION = '0.3.4';
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/dswifi/netdb.inc b/packages/libndsfpc/src/dswifi/netdb.inc
new file mode 100644
index 0000000000..0041ecadd5
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/netdb.inc
@@ -0,0 +1,57 @@
+(*
+ $Id: netdb.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - socket emulation layer defines/prototypes (netdb.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+{$ifdef NDS_INTERFACE}
+
+type
+ ppcchar = ^pcchar;
+ hostent = record
+ h_name: pcchar;
+ h_aliases: ppcchar;
+ h_addrtype: cint;
+ h_length: cint;
+ h_addr_list: ppcchar;
+ end;
+ phostent = ^hostent;
+
+function gethostbyname(const name: pchar): phostent; cdecl; external;
+
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/dswifi/netinet/in.inc b/packages/libndsfpc/src/dswifi/netinet/in.inc
new file mode 100644
index 0000000000..a43a1367fc
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/netinet/in.inc
@@ -0,0 +1,65 @@
+(*
+ $Id: in.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - socket emulation layer defines/prototypes (netinet/in.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ INADDR_ANY = $00000000;
+ INADDR_BROADCAST = $FFFFFFFF;
+ INADDR_NONE = $FFFFFFFF;
+
+type
+ in_addr = packed record
+ s_addr: culong;
+ end;
+ pin_addr = ^in_addr;
+
+ sockaddr_in = packed record
+ sin_family: cushort;
+ sin_port: cushort;
+ sin_addr: in_addr;
+ sin_zero: array [0..7] of cuchar;
+ end;
+
+
+function inet_addr(const cp: pchar): culong; cdecl; external;
+function inet_aton(const cp: pchar; inp: pin_addr): cint; cdecl; external;
+function inet_ntoa(_in: in_addr): pcchar; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/dswifi/sgIP_errno.inc b/packages/libndsfpc/src/dswifi/sgIP_errno.inc
new file mode 100644
index 0000000000..14cefe7cac
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/sgIP_errno.inc
@@ -0,0 +1,183 @@
+(*
+ $Id: sgIP_errno.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - socket emulation layer defines/prototypes (sgIP_errno.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+
+(**** Note: This file is unused unless you need to build in an environment without newlib ****)
+
+{$ifdef NDS_INTERFACE}
+
+const
+ EPERM = 1; (* Operation not permitted *)
+ ENOENT = 2; (* No such file or directory *)
+ ESRCH = 3; (* No such process *)
+ EINTR = 4; (* Interrupted system call *)
+ EIO = 5; (* I/O error *)
+ ENXIO = 6; (* No such device or address *)
+ E2BIG = 7; (* Arg list too long *)
+ ENOEXEC = 8; (* Exec format error *)
+ EBADF = 9; (* Bad file number *)
+ ECHILD = 10; (* No child processes *)
+ EAGAIN = 11; (* Try again *)
+ ENOMEM = 12; (* Out of memory *)
+ EACCES = 13; (* Permission denied *)
+ EFAULT = 14; (* Bad address *)
+ ENOTBLK = 15; (* Block device required *)
+ EBUSY = 16; (* Device or resource busy *)
+ EEXIST = 17; (* File exists *)
+ EXDEV = 18; (* Cross-device link *)
+ ENODEV = 19; (* No such device *)
+ ENOTDIR = 20; (* Not a directory *)
+ EISDIR = 21; (* Is a directory *)
+ EINVAL = 22; (* Invalid argument *)
+ ENFILE = 23; (* File table overflow *)
+ EMFILE = 24; (* Too many open files *)
+ ENOTTY = 25; (* Not a typewriter *)
+ ETXTBSY = 26; (* Text file busy *)
+ EFBIG = 27; (* File too large *)
+ ENOSPC = 28; (* No space left on device *)
+ ESPIPE = 29; (* Illegal seek *)
+ EROFS = 30; (* Read-only file system *)
+ EMLINK = 31; (* Too many links *)
+ EPIPE = 32; (* Broken pipe *)
+ EDOM = 33; (* Math argument out of domain of func *)
+ ERANGE = 34; (* Math result not representable *)
+ EDEADLK = 35; (* Resource deadlock would occur *)
+ ENAMETOOLONG = 36; (* File name too long *)
+ ENOLCK = 37; (* No record locks available *)
+ ENOSYS = 38; (* Function not implemented *)
+ ENOTEMPTY = 39; (* Directory not empty *)
+ ELOOP = 40; (* Too many symbolic links encountered *)
+ EWOULDBLOCK = EAGAIN; (* Operation would block *)
+ ENOMSG = 42; (* No message of desired type *)
+ EIDRM = 43; (* Identifier removed *)
+ ECHRNG = 44; (* Channel number out of range *)
+ EL2NSYNC = 45; (* Level 2 not synchronized *)
+ EL3HLT = 46; (* Level 3 halted *)
+ EL3RST = 47; (* Level 3 reset *)
+ ELNRNG = 48; (* Link number out of range *)
+ EUNATCH = 49; (* Protocol driver not attached *)
+ ENOCSI = 50; (* No CSI structure available *)
+ EL2HLT = 51; (* Level 2 halted *)
+ EBADE = 52; (* Invalid exchange *)
+ EBADR = 53; (* Invalid request descriptor *)
+ EXFULL = 54; (* Exchange full *)
+ ENOANO = 55; (* No anode *)
+ EBADRQC = 56; (* Invalid request code *)
+ EBADSLT = 57; (* Invalid slot *)
+
+ EDEADLOCK = EDEADLK;
+
+ EBFONT = 59; (* Bad font file format *)
+ ENOSTR = 60; (* Device not a stream *)
+ ENODATA = 61; (* No data available *)
+ ETIME = 62; (* Timer expired *)
+ ENOSR = 63; (* Out of streams resources *)
+ ENONET = 64; (* Machine is not on the network *)
+ ENOPKG = 65; (* Package not installed *)
+ EREMOTE = 66; (* Object is remote *)
+ ENOLINK = 67; (* Link has been severed *)
+ EADV = 68; (* Advertise error *)
+ ESRMNT = 69; (* Srmount error *)
+ ECOMM = 70; (* Communication error on send *)
+ EPROTO = 71; (* Protocol error *)
+ EMULTIHOP = 72; (* Multihop attempted *)
+ EDOTDOT = 73; (* RFS specific error *)
+ EBADMSG = 74; (* Not a data message *)
+ EOVERFLOW = 75; (* Value too large for defined data type *)
+ ENOTUNIQ = 76; (* Name not unique on network *)
+ EBADFD = 77; (* File descriptor in bad state *)
+ EREMCHG = 78; (* Remote address changed *)
+ ELIBACC = 79; (* Can not access a needed shared library *)
+ ELIBBAD = 80; (* Accessing a corrupted shared library *)
+ ELIBSCN = 81; (* .lib section in a.out corrupted *)
+ ELIBMAX = 82; (* Attempting to link in too many shared libraries *)
+ ELIBEXEC = 83; (* Cannot exec a shared library directly *)
+ EILSEQ = 84; (* Illegal byte sequence *)
+ ERESTART = 85; (* Interrupted system call should be restarted *)
+ ESTRPIPE = 86; (* Streams pipe error *)
+ EUSERS = 87; (* Too many users *)
+ ENOTSOCK = 88; (* Socket operation on non-socket *)
+ EDESTADDRREQ = 89; (* Destination address required *)
+ EMSGSIZE = 90; (* Message too long *)
+ EPROTOTYPE = 91; (* Protocol wrong type for socket *)
+ ENOPROTOOPT = 92; (* Protocol not available *)
+ EPROTONOSUPPORT= 93; (* Protocol not supported *)
+ ESOCKTNOSUPPORT= 94; (* Socket type not supported *)
+ EOPNOTSUPP = 95; (* Operation not supported on transport endpoint *)
+ EPFNOSUPPORT = 96; (* Protocol family not supported *)
+ EAFNOSUPPORT = 97; (* Address family not supported by protocol *)
+ EADDRINUSE = 98; (* Address already in use *)
+ EADDRNOTAVAIL = 99; (* Cannot assign requested address *)
+ ENETDOWN = 100; (* Network is down *)
+ ENETUNREACH = 101; (* Network is unreachable *)
+ ENETRESET = 102; (* Network dropped connection because of reset *)
+ ECONNABORTED = 103; (* Software caused connection abort *)
+ ECONNRESET = 104; (* Connection reset by peer *)
+ ENOBUFS = 105; (* No buffer space available *)
+ EISCONN = 106; (* Transport endpoint is already connected *)
+ ENOTCONN = 107; (* Transport endpoint is not connected *)
+ ESHUTDOWN = 108; (* Cannot send after transport endpoint shutdown *)
+ ETOOMANYREFS = 109; (* Too many references: cannot splice *)
+ ETIMEDOUT = 110; (* Connection timed out *)
+ ECONNREFUSED = 111; (* Connection refused *)
+ EHOSTDOWN = 112; (* Host is down *)
+ EHOSTUNREACH = 113; (* No route to host *)
+ EALREADY = 114; (* Operation already in progress *)
+ EINPROGRESS = 115; (* Operation now in progress *)
+ ESTALE = 116; (* Stale NFS file handle *)
+ EUCLEAN = 117; (* Structure needs cleaning *)
+ ENOTNAM = 118; (* Not a XENIX named type file *)
+ ENAVAIL = 119; (* No XENIX semaphores available *)
+ EISNAM = 120; (* Is a named type file *)
+ EREMOTEIO = 121; (* Remote I/O error *)
+ EDQUOT = 122; (* Quota exceeded *)
+
+ ENOMEDIUM = 123; (* No medium found *)
+ EMEDIUMTYPE = 124; (* Wrong medium type *)
+
+
+{$ifndef errno}
+var
+ sgIP_errno: cint; cvar; external;
+ {$define errno := sgIP_errno}
+{$endif}
+
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/dswifi/sys/socket.inc b/packages/libndsfpc/src/dswifi/sys/socket.inc
new file mode 100644
index 0000000000..3f4e6a1988
--- /dev/null
+++ b/packages/libndsfpc/src/dswifi/sys/socket.inc
@@ -0,0 +1,166 @@
+(*
+ $Id: socket.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ DSWifi Project - socket emulation layer defines/prototypes (sys/socket.h)
+ (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
+ ******************************************************************************
+ DSWifi Lib and test materials are licenced under the MIT open source licence:
+ Copyright (c) 2005-2006 Stephen Stair
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ******************************************************************************
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ Comments:
+
+*)
+
+
+{$ifdef NDS_INTERFACE}
+
+const
+//#include <sys/time.h>
+ SOL_SOCKET = $fff; (* options for socket level *)
+ SOL_TCP = 6; (* TCP level *)
+ PF_UNSPEC = 0;
+ PF_INET = 2;
+ PF_INET6 = 10;
+
+ AF_UNSPEC = PF_UNSPEC;
+ AF_INET = PF_INET;
+ AF_INET6 = PF_INET6;
+
+ SOCK_STREAM = 1;
+ SOCK_DGRAM = 2;
+
+// need to sync FIO* values with commonly accepted ones sometime
+ FIONBIO = 1;
+ FIONREAD = 2;
+
+ SOCKET_ERROR = -1;
+
+// send()/recv()/etc flags
+// at present, only MSG_PEEK is implemented though.
+ MSG_WAITALL = $40000000;
+ MSG_TRUNC = $20000000;
+ MSG_PEEK = $10000000;
+ MSG_OOB = $08000000;
+ MSG_EOR = $04000000;
+ MSG_DONTROUTE = $02000000;
+ MSG_CTRUNC = $01000000;
+
+// shutdown() flags:
+ SHUT_RD = 1;
+ SHUT_WR = 2;
+ SHUT_RDWR = 3;
+
+
+ SO_DEBUG = $0001; (* turn on debugging info recording *)
+ SO_ACCEPTCONN = $0002; (* socket has had listen() *)
+ SO_REUSEADDR = $0004; (* allow local address reuse *)
+ SO_KEEPALIVE = $0008; (* keep connections alive *)
+ SO_DONTROUTE = $0010; (* just use interface addresses *)
+ SO_BROADCAST = $0020; (* permit sending of broadcast msgs *)
+ SO_USELOOPBACK = $0040; (* bypass hardware when possible *)
+ SO_LINGER = $0080; (* linger on close if data present *)
+ SO_OOBINLINE = $0100; (* leave received OOB data in line *)
+ SO_REUSEPORT = $0200; (* allow local address & port reuse *)
+
+ SO_DONTLINGER = not SO_LINGER;
+
+ SO_SNDBUF = $1001; (* send buffer size *)
+ SO_RCVBUF = $1002; (* receive buffer size *)
+ SO_SNDLOWAT = $1003; (* send low-water mark *)
+ SO_RCVLOWAT = $1004; (* receive low-water mark *)
+ SO_SNDTIMEO = $1005; (* send timeout *)
+ SO_RCVTIMEO = $1006; (* receive timeout *)
+ SO_ERROR = $1007; (* get error status and clear *)
+ SO_TYPE = $1008; (* get socket type *)
+type
+ sockaddr = record
+ _sa_family: cushort;
+ sa_data: array [0..13] of char;
+ end;
+ psockaddr = ^sockaddr;
+
+
+function socket(domain, _type, protocol: cint): cint; cdecl; external;
+function bind(socket: cint; {const} addr: psockaddr; addr_len: cint): cint; cdecl; external;
+function connect(socket: cint; {const} addr: psockaddr; addr_len: cint): cint; cdecl; external;
+function send(socket: cint; {const} data: pointer; sendlength, flags: cint): cint; cdecl; external;
+function recv(socket: cint; data: pointer; recvlength, flags: cint): cint; cdecl; external;
+function sendto(socket: cint; {const} data: pointer; sendlength, flags: cint; const addr: psockaddr; addr_len: cint): cint; cdecl; external;
+function recvfrom(socket: cint; data: pointer; recvlength, flags: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
+function listen(socket, max_connections: cint): cint; cdecl; external;
+function accept(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
+function shutdown(socket, shutdown_type: cint): cint; cdecl; external;
+function closesocket(socket: cint): cint; cdecl; external;
+
+function ioctl(socket: cint; cmd: clong; arg: pointer): cint; cdecl; external;
+
+function setsockopt(socket, level, option_name: cint; const data: pointer; data_len: cint): cint; cdecl; external;
+function getsockopt(socket, level, option_name: cint; data: pointer; data_len: pcint): cint; cdecl; external;
+
+function getpeername(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
+function getsockname(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
+
+function gethostname(name: pcchar; {size_t} len: cuint): cint; cdecl; external;
+function sethostname(const name: pcchar; {size_t} len: cuint): cint; cdecl; external;
+
+function htons(num: cushort): cushort; cdecl; external;
+function htonl(num: culong): culong; cdecl; external;
+
+function ntohs(num: cushort): cushort; inline;
+function ntohl(num: culong): culong; inline;
+
+
+type
+ fd_set = array [0..7] of clong;
+ pfd_set = ^fd_set;
+
+ timeval = packed record
+ sec: clong;
+ usec: clong;
+ end;
+ ptimeval = ^timeval;
+
+
+function select(nfds: cint; readfds, writefds, errorfds: pfd_set; timeout: ptimeval): cint; cdecl; external;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+function ntohs(num: cushort): cushort; inline;
+begin
+ ntohs := htons(num);
+end;
+
+function ntohl(num: culong): culong; inline;
+begin
+ ntohl := htonl(num);
+end;
+
+{$endif NDS_IMPLEMENTATION}
diff --git a/packages/libndsfpc/src/fat/fat.inc b/packages/libndsfpc/src/fat/fat.inc
new file mode 100644
index 0000000000..83bd8e10bb
--- /dev/null
+++ b/packages/libndsfpc/src/fat/fat.inc
@@ -0,0 +1,88 @@
+(*
+ $Id: fat.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+{$ifdef NDS_INTERFACE}
+
+const
+ FEATURE_MEDIUM_CANREAD = $00000001;
+ FEATURE_MEDIUM_CANWRITE = $00000002;
+ FEATURE_SLOT_GBA = $00000010;
+ FEATURE_SLOT_NDS = $00000020;
+
+type
+ FN_MEDIUM_STARTUP = function: cbool;
+ FN_MEDIUM_ISINSERTED = function: cbool;
+ FN_MEDIUM_READSECTORS = function(sector, numSectors: cuint32; buffer: pointer): cbool;
+ FN_MEDIUM_WRITESECTORS = function(sector, numSectors: cuint32; const buffer: pointer): cbool;
+ FN_MEDIUM_CLEARSTATUS = function: cbool;
+ FN_MEDIUM_SHUTDOWN = function: cbool;
+
+ IO_INTERFACE_STRUCT = record
+ ioType: cuint32;
+ features: cuint32;
+ fn_startup: FN_MEDIUM_STARTUP;
+ fn_isInserted: FN_MEDIUM_ISINSERTED;
+ fn_readSectors: FN_MEDIUM_READSECTORS;
+ fn_writeSectors: FN_MEDIUM_WRITESECTORS;
+ fn_clearStatus: FN_MEDIUM_CLEARSTATUS;
+ fn_shutdown: FN_MEDIUM_SHUTDOWN;
+ end;
+
+ IO_INTERFACE = IO_INTERFACE_STRUCT;
+ TIO_INTERFACE_STRUCT = IO_INTERFACE_STRUCT;
+ PIO_INTERFACE_STRUCT = ^IO_INTERFACE_STRUCT;
+
+ PARTITION_INTERFACE = (
+ PI_DEFAULT = 0,
+ PI_SLOT_1,
+ PI_SLOT_2,
+ PI_CUSTOM
+ );
+
+
+function fatInit(cacheSize: cuint32; setAsDefaultDevice: cbool): cbool; cdecl; external;
+function fatInitDefault(): cbool; cdecl; external;
+function fatMountNormalInterface(partitionNumber: PARTITION_INTERFACE; cacheSize: cuint32): cbool; cdecl; external;
+function fatMountCustomInterface(const device: PIO_INTERFACE_STRUCT; cacheSize: cuint32): cbool; cdecl; external;
+function fatUnmount(partitionNumber: PARTITION_INTERFACE): cbool; cdecl; external;
+function fatUnsafeUnmount(partitionNumber: PARTITION_INTERFACE): cbool; cdecl; external;
+function fatSetDefaultInterface(partitionNumber: PARTITION_INTERFACE): cbool; cdecl; external;
+
+{$endif NDS_INTERFACE}
+
diff --git a/packages/libndsfpc/src/fat/fat.pp b/packages/libndsfpc/src/fat/fat.pp
new file mode 100644
index 0000000000..502209f339
--- /dev/null
+++ b/packages/libndsfpc/src/fat/fat.pp
@@ -0,0 +1,32 @@
+unit fat;
+{$mode objfpc}
+{$apptype arm9}
+{$define arm9}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds9;
+
+{$linklib nds9}
+{$linklib libfat.a}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include fat.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include fat.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/fat/gbfs.inc b/packages/libndsfpc/src/fat/gbfs.inc
new file mode 100644
index 0000000000..027809703f
--- /dev/null
+++ b/packages/libndsfpc/src/fat/gbfs.inc
@@ -0,0 +1,75 @@
+(*
+ $Id: gbfs.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright
+ 2002-2004 Damian Yerrick
+ Additional code Dave Murphy
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+{$ifdef NDS_INTERFACE}
+(* to make a 300 KB space called samples do GBFS_SPACE(samples, 300) *)
+
+{$define GBFS_SPACE(filename, kbytes) := filename: array [(kbytes)*1024 - 1] of char = 'PinEightGBFSSpace-' + filename + '-' + kbytes}
+
+type
+ GBFS_FILE = packed record
+ magic: array [0..15] of char; // "PinEightGBFS\r\n\032\n"
+ total_len: cuint32; // total length of archive
+ dir_off: cuint16; // offset in bytes to directory
+ dir_nmemb: cuint16; // number of files
+ reserved: array [0..7] of char; // for future use
+ end;
+ PGBFS_FILE = ^GBFS_FILE;
+
+ GBFS_ENTRY = packed record
+ name: array [0..23] of char; // filename, nul-padded
+ len: cuint32; // length of object in bytes
+ data_offset: cuint32; // in bytes from beginning of file
+ end;
+ PGBFS_ENTRY = ^GBFS_ENTRY;
+
+procedure gbfs_search_range(gbfs_1st_limit: cuint32; gbfs_2nd_start: cuint32;
+ gbfs_2nd_limit: cuint32; gbfs_stride: cuint32); cdecl; external;
+
+function find_first_gbfs_file(const start: pointer): PGBFS_FILE; cdecl; external;
+function skip_gbfs_file(const _file: PGBFS_FILE): pointer; cdecl; external;
+function gbfs_get_obj(const _file: PGBFS_FILE; const name: pchar; len: pcuint32): pointer; cdecl; external;
+function gbfs_get_nth_obj(const _file: PGBFS_FILE; n: cint {was size_t}; name: pchar; len: pcuint32): pointer; cdecl; external;
+function gbfs_copy_obj(dst: pointer; const _file: PGBFS_FILE; const name: pchar): pointer; cdecl; external;
+function gbfs_count_objs(const _file: PGBFS_FILE): cint {was size_t}; cdecl; external;
+
+{$endif NDS_INTERFACE}
+
diff --git a/packages/libndsfpc/src/fat/gbfs.pp b/packages/libndsfpc/src/fat/gbfs.pp
new file mode 100644
index 0000000000..2ceb8949da
--- /dev/null
+++ b/packages/libndsfpc/src/fat/gbfs.pp
@@ -0,0 +1,32 @@
+unit gbfs;
+{$mode objfpc}
+{$apptype arm9}
+{$define arm9}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds9;
+
+{$linklib nds9}
+{$linklib fat}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include gbfs.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include gbfs.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/libmikmod/inc/mikmod.inc b/packages/libndsfpc/src/libmikmod/inc/mikmod.inc
new file mode 100644
index 0000000000..0c9204761b
--- /dev/null
+++ b/packages/libndsfpc/src/libmikmod/inc/mikmod.inc
@@ -0,0 +1,1076 @@
+(* MikMod sound library
+ (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS
+ for complete list.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*)
+
+
+{$ifdef NDS_INTERFACE}
+(**** CONST *******************************************************************)
+const
+ LIBMIKMOD_VERSION_MAJOR = 3;
+ LIBMIKMOD_VERSION_MINOR = 1;
+ LIBMIKMOD_REVISION = 10;
+
+ LIBMIKMOD_VERSION = (
+ (LIBMIKMOD_VERSION_MAJOR shl 16) or
+ (LIBMIKMOD_VERSION_MINOR shl 8) or
+ (LIBMIKMOD_REVISION)
+ );
+
+ SFX_CRITICAL = 1;
+
+ SF_16BITS = $0001;
+ SF_STEREO = $0002;
+ SF_SIGNED = $0004;
+ SF_BIG_ENDIAN = $0008;
+ SF_DELTA = $0010;
+ SF_ITPACKED = $0020;
+
+ SF_FORMATMASK = $003F;
+
+ SF_LOOP = $0100;
+ SF_BIDI = $0200;
+ SF_REVERSE = $0400;
+ SF_SUSTAIN = $0800;
+
+ SF_PLAYBACKMASK = $0C00;
+
+ SF_OWNPAN = $1000;
+ SF_UST_LOOP = $2000;
+
+ SF_EXTRAPLAYBACKMASK = $3000;
+
+ PAN_LEFT = 0;
+ PAN_HALFLEFT = 64;
+ PAN_CENTER = 128;
+ PAN_HALFRIGHT = 192;
+ PAN_RIGHT = 255;
+ PAN_SURROUND = 512;
+
+ INSTNOTES = 120;
+
+ ENVPOINTS = 32;
+
+ UF_MAXCHAN = 64;
+
+ UF_XMPERIODS = $0001;
+ UF_LINEAR = $0002;
+ UF_INST = $0004;
+ UF_NNA = $0008;
+ UF_S3MSLIDES = $0010;
+ UF_BGSLIDES = $0020;
+ UF_HIGHBPM = $0040;
+ UF_NOWRAP = $0080;
+ UF_ARPMEM = $0100;
+ UF_FT2QUIRKS = $0200;
+ UF_PANNING = $0400;
+
+ MUTE_EXCLUSIVE = 32000;
+ MUTE_INCLUSIVE = 32001;
+
+ DMODE_16BITS = $0001;
+ DMODE_STEREO = $0002;
+ DMODE_SOFT_SNDFX = $0004;
+ DMODE_SOFT_MUSIC = $0008;
+ DMODE_HQMIXER = $0010;
+ DMODE_SURROUND = $0100;
+ DMODE_INTERP = $0200;
+ DMODE_REVERSE = $0400;
+
+ OCTAVE = 12;
+
+ UF_MAXMACRO = $10;
+ UF_MAXFILTER = $100;
+
+ FILT_CUT = $80;
+ FILT_RESONANT = $81;
+
+ IF_OWNPAN = 1;
+ IF_PITCHPAN = 2;
+
+ EF_ON = 1;
+ EF_SUSTAIN = 2;
+ EF_LOOP = 4;
+ EF_VOLENV = 8;
+
+ NNA_CUT = 0;
+ NNA_CONTINUE = 1;
+ NNA_OFF = 2;
+ NNA_FADE = 3;
+
+ NNA_MASK = 3;
+
+ DCT_OFF = 0;
+ DCT_NOTE = 1;
+ DCT_SAMPLE = 2;
+ DCT_INST = 3;
+
+ DCA_CUT = 0;
+ DCA_OFF = 1;
+ DCA_FADE = 2;
+
+ KEY_KICK = 0;
+ KEY_OFF = 1;
+ KEY_FADE = 2;
+ KEY_KILL = (KEY_OFF or KEY_FADE);
+
+ KICK_ABSENT = 0;
+ KICK_NOTE = 1;
+ KICK_KEYOFF = 2;
+ KICK_ENV = 4;
+
+ AV_IT = 1;
+
+ POS_NONE = (-2);
+
+ LAST_PATTERN = word(-1);
+
+ S3MIT_OLDSTYLE = 1;
+ S3MIT_IT = 2;
+ S3MIT_SCREAM = 4;
+
+ MAXSAMPLEHANDLES = 384;
+
+
+(****** Types *****************************************************************)
+type
+ SBYTE = cschar;
+ PSBYTE = ^cschar;
+ UBYTE = cuchar;
+ PUBYTE = ^cuchar;
+ SWORD = csshort;
+ PSWORD = ^csshort;
+ UWORD = cushort;
+ PUWORD = ^cushort;
+ SLONG = csint;
+ PSLONG = ^csint;
+ ULONG = cuint;
+ PULONG = ^cuint;
+ BOOL = cint;
+
+ MikMod_Errors = (
+ MMERR_OPENING_FILE = 1,
+ MMERR_OUT_OF_MEMORY,
+ MMERR_DYNAMIC_LINKING,
+
+ MMERR_SAMPLE_TOO_BIG,
+ MMERR_OUT_OF_HANDLES,
+ MMERR_UNKNOWN_WAVE_TYPE,
+
+ MMERR_LOADING_PATTERN,
+ MMERR_LOADING_TRACK,
+ MMERR_LOADING_HEADER,
+ MMERR_LOADING_SAMPLEINFO,
+ MMERR_NOT_A_MODULE,
+ MMERR_NOT_A_STREAM,
+ MMERR_MED_SYNTHSAMPLES,
+ MMERR_ITPACK_INVALID_DATA,
+
+ MMERR_DETECTING_DEVICE,
+ MMERR_INVALID_DEVICE,
+ MMERR_INITIALIZING_MIXER,
+ MMERR_OPENING_AUDIO,
+ MMERR_8BIT_ONLY,
+ MMERR_16BIT_ONLY,
+ MMERR_STEREO_ONLY,
+ MMERR_ULAW,
+ MMERR_NON_BLOCK,
+
+ MMERR_AF_AUDIO_PORT,
+
+ MMERR_AIX_CONFIG_INIT,
+ MMERR_AIX_CONFIG_CONTROL,
+ MMERR_AIX_CONFIG_START,
+
+ MMERR_GUS_SETTINGS,
+ MMERR_GUS_RESET,
+ MMERR_GUS_TIMER,
+
+ MMERR_HP_SETSAMPLESIZE,
+ MMERR_HP_SETSPEED,
+ MMERR_HP_CHANNELS,
+ MMERR_HP_AUDIO_OUTPUT,
+ MMERR_HP_AUDIO_DESC,
+ MMERR_HP_BUFFERSIZE,
+
+ MMERR_OSS_SETFRAGMENT,
+ MMERR_OSS_SETSAMPLESIZE,
+ MMERR_OSS_SETSTEREO,
+ MMERR_OSS_SETSPEED,
+
+ MMERR_SGI_SPEED,
+ MMERR_SGI_16BIT,
+ MMERR_SGI_8BIT,
+ MMERR_SGI_STEREO,
+ MMERR_SGI_MONO,
+
+ MMERR_SUN_INIT,
+
+ MMERR_OS2_MIXSETUP,
+ MMERR_OS2_SEMAPHORE,
+ MMERR_OS2_TIMER,
+ MMERR_OS2_THREAD,
+
+ MMERR_DS_PRIORITY,
+ MMERR_DS_BUFFER,
+ MMERR_DS_FORMAT,
+ MMERR_DS_NOTIFY,
+ MMERR_DS_EVENT,
+ MMERR_DS_THREAD,
+ MMERR_DS_UPDATE,
+
+ MMERR_WINMM_HANDLE,
+ MMERR_WINMM_ALLOCATED,
+ MMERR_WINMM_DEVICEID,
+ MMERR_WINMM_FORMAT,
+ MMERR_WINMM_UNKNOWN,
+
+ MMERR_MAC_SPEED,
+ MMERR_MAC_START,
+
+ MMERR_MAX
+ );
+
+ SAMPLE = packed record
+ panning: csshort;
+ speed: culong;
+ volume: cuchar;
+ inflags: cushort;
+ flags: cushort;
+ length: cuint;
+ loopstart: cuint;
+ loopend: cuint;
+ susbegin: cuint;
+ susend: cuint;
+ globvol: cuchar;
+ vibflags: cuchar;
+ vibtype: cuchar;
+ vibsweep: cuchar;
+ vibdepth: cuchar;
+ vibrate: cuchar;
+ samplename: pcchar;
+ avibpos: cushort;
+ divfactor: cuchar;
+ seekpos: cuint;
+ handle: csshort;
+ end;
+ TSample = SAMPLE;
+ PSample = ^SAMPLE;
+
+ ENVPT = packed record
+ pos: csshort;
+ val: csshort;
+ end;
+ TENVPT = ENVPT;
+ PENVPT = ^ENVPT;
+
+ INSTRUMENT = packed record
+ insname: pcchar;
+ flags: cuchar;
+ samplenumber: array [0..INSTNOTES - 1] of cushort;
+ samplenote: array [0..INSTNOTES - 1] of cuchar;
+ nnatype: cuchar;
+ dca: cuchar;
+ dct: cuchar;
+ globvol: cuchar;
+ volfade: cushort;
+ panning: csshort;
+ pitpansep: cuchar;
+ pitpancenter: cuchar;
+ rvolvar: cuchar;
+ rpanvar: cuchar;
+ volflg: cuchar;
+ volpts: cuchar;
+ volsusbeg: cuchar;
+ volsusend: cuchar;
+ volbeg: cuchar;
+ volend: cuchar;
+ volenv: array [0..ENVPOINTS - 1] of ENVPT;
+ panflg: cuchar;
+ panpts: cuchar;
+ pansusbeg: cuchar;
+ pansusend: cuchar;
+ panbeg: cuchar;
+ panend: cuchar;
+ panenv: array [0..ENVPOINTS - 1] of ENVPT;
+ pitflg: cuchar;
+ pitpts: cuchar;
+ pitsusbeg: cuchar;
+ pitsusend: cuchar;
+ pitbeg: cuchar;
+ pitend: cuchar;
+ pitenv: array [0..ENVPOINTS - 1] of ENVPT;
+ end;
+ TInstrument = INSTRUMENT;
+ PInstrument = ^INSTRUMENT;
+
+ MP_CHANNEL = packed record
+ i: PInstrument;
+ s: PSample;
+ sample: cuchar;
+ note: cuchar;
+ outvolume: csshort;
+ chanvol: cschar;
+ fadevol: cushort;
+ panning: csshort;
+ kick: cuchar;
+ period: cushort;
+ nna: cuchar;
+ volflg: cuchar;
+ panflg: cuchar;
+ pitflg: cuchar;
+ keyoff: cuchar;
+ handle: csshort;
+ notedelay: cuchar;
+ start: csint;
+ end;
+ TMPChannel = MP_CHANNEL;
+ PMPChannel = ^MP_CHANNEL;
+
+ ENVPR = packed record
+ flg: cuchar;
+ pts: cuchar;
+ susbeg: cuchar;
+ susend: cuchar;
+ beg: cuchar;
+ _end: cuchar;
+ p: csshort;
+ a: cushort;
+ b: cushort;
+ env: PENVPT;
+ end;
+ TENVPR = ENVPR;
+ PENVPR = ^ENVPR;
+
+
+ PMP_VOICE = ^MP_VOICE;
+
+ MP_CONTROL = packed record
+ main: MP_CHANNEL;
+ slave: PMP_VOICE;
+ slavechn: cuchar;
+ muted: cuchar;
+ ultoffset: cushort;
+ anote: cuchar;
+ oldnote: cuchar;
+ ownper: csshort;
+ ownvol: csshort;
+ dca: cuchar;
+ dct: cuchar;
+ row: pcuchar;
+ retrig: cschar;
+ speed: cuint;
+ volume: csshort;
+ tmpvolume: csshort;
+ tmpperiod: cushort;
+ wantedperiod: cushort;
+ arpmem: cuchar;
+ pansspd: cuchar;
+ slidespeed: cushort;
+ portspeed: cushort;
+ s3mtremor: cuchar;
+ s3mtronof: cuchar;
+ s3mvolslide: cuchar;
+ sliding: cschar;
+ s3mrtgspeed: cuchar;
+ s3mrtgslide: cuchar;
+ glissando: cuchar;
+ wavecontrol: cuchar;
+ vibpos: cschar;
+ vibspd: cuchar;
+ vibdepth: cuchar;
+ trmpos: cschar;
+ trmspd: cuchar;
+ trmdepth: cuchar;
+ fslideupspd: cuchar;
+ fslidednspd: cuchar;
+ fportupspd: cuchar;
+ fportdnspd: cuchar;
+ ffportupspd: cuchar;
+ ffportdnspd: cuchar;
+ hioffset: cuint;
+ soffset: cushort;
+ sseffect: cuchar;
+ ssdata: cuchar;
+ chanvolslide: cuchar;
+ panbwave: cuchar;
+ panbpos: cuchar;
+ panbspd: cschar;
+ panbdepth: cuchar;
+ newsamp: cushort;
+ voleffect: cuchar;
+ voldata: cuchar;
+ pat_reppos: csshort;
+ pat_repcnt: cushort;
+ end;
+ TMPControl = MP_CONTROL;
+ PMPControl = ^MP_CONTROL;
+
+ MP_VOICE = packed record
+ main: MP_CHANNEL;
+ venv: ENVPR;
+ penv: ENVPR;
+ cenv: ENVPR;
+ avibpos: cushort;
+ aswppos: cushort;
+ totalvol: cuint;
+ mflag: cint;
+ masterchn: csshort;
+ masterperiod: cushort;
+ master: PMPControl;
+ end;
+ TMPVoice = MP_VOICE;
+ PMPVoice = ^MP_VOICE;
+
+ ppcuchar = ^pcuchar;
+
+ MODULE = packed record
+ songname: pcchar;
+ modtype: pcchar;
+ comment: pcchar;
+ flags: cushort;
+ numchn: cuchar;
+ numvoices: cuchar;
+ numpos: cushort;
+ numpat: cushort;
+ numins: cushort;
+ numsmp: cushort;
+ instruments: PInstrument;
+ samples: PSample;
+ realchn: cuchar;
+ totalchn: cuchar;
+ reppos: cushort;
+ initspeed: cuchar;
+ inittempo: cushort;
+ initvolume: cuchar;
+ panning: array [0..UF_MAXCHAN - 1] of cushort;
+ chanvol: array [0..UF_MAXCHAN - 1] of cuchar;
+ bpm: cushort;
+ sngspd: cushort;
+ volume: csshort;
+ extspd: cint;
+ panflag: cint;
+ wrap: cint;
+ loop: cint;
+ fadeout: cint;
+ patpos: cushort;
+ sngpos: csshort;
+ sngtime: cuint;
+ relspd: csshort;
+ numtrk: cushort;
+ tracks: ppcuchar;
+ patterns: pcushort;
+ pattrows: pcushort;
+ positions: pcushort;
+ forbid: cint;
+ numrow: cushort;
+ vbtick: cushort;
+ sngremainder: cushort;
+ control: PMPControl;
+ voice: PMPVoice;
+ globalslide: cuchar;
+ pat_repcrazy: cuchar;
+ patbrk: cushort;
+ patdly: cuchar;
+ patdly2: cuchar;
+ posjmp: csshort;
+ bpmlimit: cushort;
+ end;
+ TModule = MODULE;
+ PModule = ^MODULE;
+
+ drvenum1 = (
+ MD_MUSIC = 0,
+ MD_SNDFX
+ );
+
+ drvenum2 = (
+ MD_HARDWARE = 0,
+ MD_SOFTWARE
+ );
+
+ PMReader = ^MREADER;
+ TSeek1 = function(value1: PMReader; value2: clong; value3: cint): pcint;
+ PSeek1 = ^TSeek1;
+ TTell1 = function(value: PMReader): pclong;
+ PTell1 = ^TTell1;
+ TRead = function(value1: PMReader; value2: pointer; value3: cint): pcint;
+ PRead = ^TRead;
+ TGet = function(value: PMReader): pcint;
+ PGet = ^TGet;
+ TEof = function(value: PMReader): pcint;
+ PEof = ^TEof;
+
+ MREADER = packed record
+ Seek: TSeek1;
+ Tell: TTell1;
+ Read: TRead;
+ Get: TGet;
+ Eof: TEof;
+ end;
+
+ PMWriter = ^MWRITER;
+ TSeek2 = function(value1: PMWriter; value2: clong; value3: cint): pcint;
+ PSeek2 = ^TSeek2;
+ TTell2 = function(value: PMWriter): pclong;
+ PTell2 = ^TTell2;
+ TWrite = function(value1: PMWriter; value2: pointer; value3: cint): pcint;
+ PWrite = ^TWrite;
+ TPut = function(value1: PMWriter; value2: cint): pcint;
+ PPut = ^TPut;
+
+ MWRITER = packed record
+ Seek: TSeek2;
+ Tell: TTell2;
+ Write: TWrite;
+ Put: TPut;
+ end;
+ TMWriter = MWRITER;
+
+ PSampLoad = ^SAMPLOAD;
+ PPSampLoad = ^PSampLoad;
+ SAMPLOAD = packed record
+ next: PSampLoad;
+ length: cuint;
+ loopstart: cuint;
+ loopend: cuint;
+ infmt, outfmt: cushort;
+ scalefactor: cint;
+ sample: PSample;
+ reader: PMReader;
+ end;
+ TSampLoad = SAMPLOAD;
+
+ TMDCommandLine = procedure(value: pcchar);
+ PMDCommandLine = ^TMDCommandLine;
+ TMDIsPresent = function(): cint;
+ PMDIsPresent = ^TMDIsPresent;
+ TMDSampleLoad = function (value1: PSAMPLOAD; value2: cint): csshort;
+ PMDSampleLoad = ^TMDSampleLoad;
+ TMDSampleUnload = procedure(value: csshort);
+ PMDSampleUnload = ^TMDSampleUnload;
+ TMDFreeSampleSpace = function(value: cint): cuint;
+ PMDFreeSampleSpace = ^TMDFreeSampleSpace;
+ TMDRealSampleLength = function(value1: cint; value2: PSAMPLE): cuint;
+ PMDRealSampleLength = ^TMDRealSampleLength;
+ TMDInit = function(): cint;
+ PMDInit = ^TMDInit;
+ TMDExit = procedure();
+ PMDExit = ^TMDExit;
+ TMDReset = function(): cint;
+ PMDReset = ^TMDReset;
+ TMDSetNumVoices = function(): cint;
+ PMDSetNumVoices = ^TMDSetNumVoices;
+ TMDPlayStart = function(): cint;
+ PMDPlayStart = ^TMDPlayStart;
+ TMDPlayStop = procedure();
+ PMDPlayStop = ^TMDPlayStop;
+ TMDUpdate = procedure();
+ PMDUpdate = ^TMDUpdate;
+ TMDPause = procedure();
+ PMDPause = ^TMDPause;
+ TMDVoiceSetVolume = procedure(value1: cuchar; value2: cushort);
+ PMDVoiceSetVolume = ^TMDVoiceSetVolume;
+ TMDVoiceGetVolume = function(value: cuchar): cushort;
+ PMDVoiceGetVolume = ^TMDVoiceGetVolume;
+ TMDVoiceSetFrequency = procedure(value1: cuchar; value2: cuint);
+ PMDVoiceSetFrequency = ^TMDVoiceSetFrequency;
+ TMDVoiceGetFrequency = function(value: cuchar): cuint;
+ PMDVoiceGetFrequency = ^TMDVoiceGetFrequency;
+ TMDVoiceSetPanning = procedure(value1: cuchar; value2: cuint);
+ PMDVoiceSetPanning = ^TMDVoiceSetPanning;
+ TMDVoiceGetPanning = function(value: cuchar): cuint;
+ PMDVoiceGetPanning = ^TMDVoiceGetPanning;
+ TMDVoicePlay = procedure(value1: cuchar; value2: csshort; value3, value4, value5, value6: cuint; value7: cushort);
+ PMDVoicePlay = ^TMDVoicePlay;
+ TMDVoiceStop = procedure(value: cuchar);
+ PMDVoiceStop = ^TMDVoiceStop;
+ TMDVoiceStopped = function(value: cuchar): cint;
+ PMDVoiceStopped = ^TMDVoiceStopped;
+ TMDVoiceGetPosition = function(value: cuchar): csint;
+ PMDVoiceGetPosition = ^TMDVoiceGetPosition;
+ TMDVoiceRealVolume = function(value: cuchar): cuint;
+ PMDVoiceRealVolume = ^TMDVoiceRealVolume;
+
+ PMDriver = ^MDRIVER;
+ MDRIVER = packed record
+ next: PMdriver;
+ Name: pcchar;
+ Version: pcchar;
+ HardVoiceLimit: cuchar;
+ SoftVoiceLimit: cuchar;
+ Alias: pcchar;
+ CommandLine: TMDCommandLine;
+ IsPresent: TMDIsPresent;
+ SampleLoad: TMDSampleLoad;
+ SampleUnload: TMDSampleUnload;
+ FreeSampleSpace: TMDFreeSampleSpace;
+ RealSampleLength: TMDRealSampleLength;
+ Init: TMDInit;
+ Exit: TMDExit;
+ Reset: TMDReset;
+ SetNumVoices: TMDSetNumVoices;
+ PlayStart: TMDPlayStart;
+ PlayStop: TMDPlayStop;
+ Update: TMDUpdate;
+ Pause: TMDPause;
+ VoiceSetVolume: TMDVoiceSetVolume;
+ VoiceGetVolume: TMDVoiceGetVolume;
+ VoiceSetFrequency: TMDVoiceSetFrequency;
+ VoiceGetFrequency: TMDVoiceGetFrequency;
+ VoiceSetPanning: TMDVoiceSetPanning;
+ VoiceGetPanning: TMDVoiceGetPanning;
+ VoicePlay: TMDVoicePlay;
+ VoiceStop: TMDVoiceStop;
+ VoiceStopped: TMDVoiceStopped;
+ VoiceGetPosition: TMDVoiceGetPosition;
+ VoiceRealVolume: TMDVoiceRealVolume;
+ end;
+ TMDriver = MDRIVER;
+
+ MikMod_player = procedure();
+ TMikModPlayer = MikMod_player;
+ MikMod_player_t = ^MikMod_player;
+ PMikModPlayer = ^MikMod_player;
+
+ uni_fx = (
+ UNI_NOTE = 1,
+ UNI_INSTRUMENT,
+ UNI_PTEFFECT0, // arpeggio
+ UNI_PTEFFECT1, // porta up
+ UNI_PTEFFECT2, // porta down
+ UNI_PTEFFECT3, // porta to note
+ UNI_PTEFFECT4, // vibrato
+ UNI_PTEFFECT5, // dual effect 3+A
+ UNI_PTEFFECT6, // dual effect 4+A
+ UNI_PTEFFECT7, // tremolo
+ UNI_PTEFFECT8, // pan
+ UNI_PTEFFECT9, // sample offset
+ UNI_PTEFFECTA, // volume slide
+ UNI_PTEFFECTB, // pattern jump
+ UNI_PTEFFECTC, // set volume
+ UNI_PTEFFECTD, // pattern break
+ UNI_PTEFFECTE, // extended effects
+ UNI_PTEFFECTF, // set speed
+ UNI_S3MEFFECTA, // set speed
+ UNI_S3MEFFECTD, // volume slide
+ UNI_S3MEFFECTE, // porta down
+ UNI_S3MEFFECTF, // porta up
+ UNI_S3MEFFECTI, // tremor
+ UNI_S3MEFFECTQ, // retrig
+ UNI_S3MEFFECTR, // tremolo
+ UNI_S3MEFFECTT, // set tempo
+ UNI_S3MEFFECTU, // fine vibrato
+ UNI_KEYOFF, // note off
+ UNI_KEYFADE, // note fade
+ UNI_VOLEFFECTS, // volume column effects
+ UNI_XMEFFECT4, // vibrato
+ UNI_XMEFFECT6, // dual effect 4+A
+ UNI_XMEFFECTA, // volume slide
+ UNI_XMEFFECTE1, // fine porta up
+ UNI_XMEFFECTE2, // fine porta down
+ UNI_XMEFFECTEA, // fine volume slide up
+ UNI_XMEFFECTEB, // fine volume slide down
+ UNI_XMEFFECTG, // set global volume
+ UNI_XMEFFECTH, // global volume slide
+ UNI_XMEFFECTL, // set envelope position
+ UNI_XMEFFECTP, // pan slide
+ UNI_XMEFFECTX1, // extra fine porta up
+ UNI_XMEFFECTX2, // extra fine porta down
+ UNI_ITEFFECTG, // porta to note
+ UNI_ITEFFECTH, // vibrato
+ UNI_ITEFFECTI, // tremor (xy not incremented)
+ UNI_ITEFFECTM, // set channel volume
+ UNI_ITEFFECTN, // slide / fineslide channel volume
+ UNI_ITEFFECTP, // slide / fineslide channel panning
+ UNI_ITEFFECTT, // slide tempo
+ UNI_ITEFFECTU, // fine vibrato
+ UNI_ITEFFECTW, // slide / fineslide global volume
+ UNI_ITEFFECTY, // panbrello
+ UNI_ITEFFECTZ, // resonant filters
+ UNI_ITEFFECTS0,
+ UNI_ULTEFFECT9, // Sample fine offset
+ UNI_MEDSPEED,
+ UNI_MEDEFFECTF1, // play note twice
+ UNI_MEDEFFECTF2, // delay note
+ UNI_MEDEFFECTF3, // play note three times
+ UNI_OKTARP, // arpeggio
+ UNI_LAST
+ );
+
+ extsound_fx = (
+ SS_GLISSANDO = 1,
+ SS_FINETUNE,
+ SS_VIBWAVE,
+ SS_TREMWAVE,
+ SS_PANWAVE,
+ SS_FRAMEDELAY,
+ SS_S7EFFECTS,
+ SS_PANNING,
+ SS_SURROUND,
+ SS_HIOFFSET,
+ SS_PATLOOP,
+ SS_NOTECUT,
+ SS_NOTEDELAY,
+ SS_PATDELAY
+ );
+
+ itcol_fx = (
+ VOL_VOLUME = 1,
+ VOL_PANNING,
+ VOL_VOLSLIDE,
+ VOL_PITCHSLIDEDN,
+ VOL_PITCHSLIDEUP,
+ VOL_PORTAMENTO,
+ VOL_VIBRATO
+ );
+
+ FILTER = packed record
+ filter, inf: cuchar;
+ end;
+ TFilter = FILTER;
+ PFilter = ^FILTER;
+
+ TMLInit = function(): cint;
+ PMLInit = ^TMLInit;
+ TMLTest = function(): cint;
+ PMLTest = ^TMLTest;
+ TMLLoad = function(value: cint): cint;
+ PMLLoad = ^TMLLoad;
+ TMLCleanup = procedure();
+ PMLCleanup = ^TMLCleanup;
+ TMLLoadTitle = function(): pcchar;
+ PMLLoadTitle = ^TMLLoadTitle;
+
+ PMLoader = ^MLOADER;
+ MLOADER = packed record
+ next: PMLoader;
+ _type: pcchar;
+ version: pcchar;
+ Init: TMLInit;
+ Test: TMLTest;
+ Load: TMLLoad;
+ Cleanup: TMLCleanup;
+ LoadTitle: TMLLoadTitle;
+ end;
+ TMLoader = MLOADER;
+
+ MikMod_handler = procedure;
+ MikMod_handler_t = ^MikMod_handler;
+ TMikModHandler = MikMod_handler;
+ PMikModHandler = ^TMikModHandler;
+
+
+var
+ _mm_errno : MikMod_Errors;
+ _mm_critical : cint;
+ _mm_errorhandler : MikMod_handler_t; cvar; external;
+
+ unioperands: array [0.. integer(UNI_LAST) - 1] of cushort; cvar; external;
+
+ MikMod_errno: cint; cvar; external;
+ MikMod_critical: cint; cvar; external;
+
+ load_669: MLOADER; cvar; external; (* 669 and Extended-669 (by Tran/Renaissance) *)
+ load_amf: MLOADER; cvar; external; (* DMP Advanced Module Format (by Otto Chrons) *)
+ load_dsm: MLOADER; cvar; external; (* DSIK internal module format *)
+ load_far: MLOADER; cvar; external; (* Farandole Composer (by Daniel Potter) *)
+ load_gdm: MLOADER; cvar; external; (* General DigiMusic (by Edward Schlunder) *)
+ load_it: MLOADER; cvar; external; (* Impulse Tracker (by Jeffrey Lim) *)
+ load_imf: MLOADER; cvar; external; (* Imago Orpheus (by Lutz Roeder) *)
+ load_med: MLOADER; cvar; external; (* Amiga MED modules (by Teijo Kinnunen) *)
+ load_m15: MLOADER; cvar; external; (* Soundtracker 15-instrument *)
+ load_mod: MLOADER; cvar; external; (* Standard 31-instrument Module loader *)
+ load_mtm: MLOADER; cvar; external; (* Multi-Tracker Module (by Renaissance) *)
+ load_okt: MLOADER; cvar; external; (* Amiga Oktalyzer *)
+ load_stm: MLOADER; cvar; external; (* ScreamTracker 2 (by Future Crew) *)
+ load_stx: MLOADER; cvar; external; (* STMIK 0.2 (by Future Crew) *)
+ load_s3m: MLOADER; cvar; external; (* ScreamTracker 3 (by Future Crew) *)
+ load_ult: MLOADER; cvar; external; (* UltraTracker (by MAS) *)
+ load_uni: MLOADER; cvar; external; (* MikMod and APlayer internal module format *)
+ load_xm: MLOADER; cvar; external; (* FastTracker 2 (by Triton) *)
+
+ md_volume: cuchar; cvar; external; (* global sound volume (0-128) *)
+ md_musicvolume: cuchar; cvar; external; (* volume of song *)
+ md_sndfxvolume: cuchar; cvar; external; (* volume of sound effects *)
+ md_reverb: cuchar; cvar; external; (* 0 = none; 15 = chaos *)
+ md_pansep: cuchar; cvar; external; (* 0 = mono; 128 == 100% (full left/right) *)
+
+ md_device: cushort; cvar; external; (* device *)
+ md_mixfreq: cushort; cvar; external; (* mixing frequency *)
+ md_mode: cushort; cvar; external; (* mode. See DMODE_? flags above *)
+
+ md_driver: PMDRIVER; cvar; external; (* Current driver in use. *)
+
+ drv_nos: MDRIVER; cvar; external; (* no sound *)
+ drv_nds_sw: MDRIVER; cvar; external; (* Nintendo DS Software driver *)
+ drv_nds_hw: MDRIVER; cvar; external; (* Nintendo DS Hardware driver *)
+
+
+{$ifdef ARM9}
+var
+ md_bpm: cushort; cvar;
+procedure MikMod9_SendCommand(command: cuint); cdecl; {forward;}external;
+function Player_LoadMemory(const buffer: pointer; size: cint; maxchan: cint; curious: cint): PModule; cdecl; external;
+{$endif ARM9}
+
+{$ifdef ARM7}
+procedure MikMod7_ProcessCommand(command: cuint); cdecl; external;
+{$endif ARM7}
+
+
+function MikMod_GetVersion(): clong; cdecl; external;
+
+function _mm_malloc(value: cint): pointer; cdecl; external;
+function _mm_calloc(value1, value2: cint): pointer; cdecl; external;
+
+procedure _mm_free(var p: pointer); inline;
+
+function Player_Init(value: PModule): cint; cdecl; external;
+procedure Player_Exit(value: PModule); cdecl; external;
+procedure Player_HandleTick(); cdecl; external;
+
+function _mm_new_file_reader(fp: P_FILE): PMReader; cdecl; external;
+procedure _mm_delete_file_reader(value: PMReader); cdecl; external;
+
+function _mm_new_file_writer(fp: P_FILE): PMWriter; cdecl; external;
+procedure _mm_delete_file_writer(value: PMWriter); cdecl; external;
+
+function _mm_FileExists(fname: pcchar): cint; cdecl; external;
+
+
+
+
+procedure _mm_iobase_setcur(value: PMReader); cdecl; external;
+procedure _mm_iobase_revert(); cdecl; external;
+function _mm_fopen(value1, value2: pcchar): P_FILE; cdecl; external;
+function _mm_fclose(value: P_FILE): cint; cdecl; external;
+procedure _mm_write_string(value1: pcchar; value2: PMWriter); cdecl; external;
+function _mm_read_string (value1: pcchar; value2: cint; value3: PMReader): cint; cdecl; external;
+
+function _mm_read_M_SWORD(value: PMReader): csshort; cdecl; external;
+function _mm_read_I_SWORD(value: PMReader): csshort; cdecl; external;
+function _mm_read_M_UWORD(value: PMReader): cushort; cdecl; external;
+function _mm_read_I_UWORD(value: PMReader): cushort; cdecl; external;
+
+function _mm_read_M_SLONG(value: PMReader): csint; cdecl; external;
+function _mm_read_I_SLONG(value: PMReader): csint; cdecl; external;
+function _mm_read_M_ULONG(value: PMReader): cuint; cdecl; external;
+function _mm_read_I_ULONG(value: PMReader): cuint; cdecl; external;
+
+function _mm_read_M_SWORDS(value1: pcsshort; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_I_SWORDS(value1: pcsshort; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_M_UWORDS(value1: pcushort; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_I_UWORDS(value1: pcushort; value2: cint; value3: PMReader): cint; cdecl; external;
+
+function _mm_read_M_SLONGS(value1: pcsint; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_I_SLONGS(value1: pcsint; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_M_ULONGS(value1: pcuint; value2: cint; value3: PMReader): cint; cdecl; external;
+function _mm_read_I_ULONGS(value1: pcuint; value2: cint; value3: PMReader): cint; cdecl; external;
+
+procedure _mm_write_M_SWORD(value1: csshort; value2: PMWriter); cdecl; external;
+procedure _mm_write_I_SWORD(value1: csshort; value2: PMWriter); cdecl; external;
+procedure _mm_write_M_UWORD(value1: cushort; value2: PMWriter); cdecl; external;
+procedure _mm_write_I_UWORD(value1: cushort; value2: PMWriter); cdecl; external;
+
+procedure _mm_write_M_SLONG(value1: csint; value2: PMWriter); cdecl; external;
+procedure _mm_write_I_SLONG(value1: csint; value2: PMWriter); cdecl; external;
+procedure _mm_write_M_ULONG(value1: cuint; value2: PMWriter); cdecl; external;
+procedure _mm_write_I_ULONG(value1: cuint; value2: PMWriter); cdecl; external;
+
+procedure _mm_write_M_SWORDS(value1: pcsshort; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_I_SWORDS(value1: pcsshort; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_M_UWORDS(value1: pcushort; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_I_UWORDS(value1: pcushort; value2: cint; value3: PMWriter); cdecl; external;
+
+procedure _mm_write_M_SLONGS(value1: pcsint; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_I_SLONGS(value1: pcsint; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_M_ULONGS(value1: pcuint; value2: cint; value3: PMWriter); cdecl; external;
+procedure _mm_write_I_ULONGS(value1: pcuint; value2: cint; value3: PMWriter); cdecl; external;
+
+
+function MikMod_strerror(value: cint): pcchar; cdecl; external;
+function MikMod_RegisterErrorHandler(value: MikMod_handler_t): MikMod_handler_t; cdecl; external;
+
+procedure MikMod_RegisterAllDrivers(); cdecl; external;
+
+function MikMod_InfoDriver(): pcchar; cdecl; external;
+procedure MikMod_RegisterDriver(value: PMDriver); cdecl; external;
+function MikMod_DriverFromAlias(value: pcint): cint; cdecl; external;
+
+function MikMod_Init(value: string): cint; cdecl; external;
+procedure MikMod_Exit(); cdecl; external;
+function MikMod_Reset(value: pcint): cint; cdecl; external;
+function MikMod_SetNumVoices(value1, value2: cint): cint; cdecl; external;
+function MikMod_Active(): cint; cdecl; external;
+function MikMod_EnableOutput(): cint; cdecl; external;
+procedure MikMod_DisableOutput(); cdecl; external;
+procedure MikMod_Update(); cdecl; external;
+
+function MikMod_InitThreads(): cint; cdecl; external;
+procedure MikMod_Lock(); cdecl; external;
+procedure MikMod_Unlock(); cdecl; external;
+
+function Sample_Load(value: pcchar): PSAMPLE; cdecl; external;
+function Sample_LoadFP(value: P_FILE): PSAMPLE; cdecl; external;
+function Sample_LoadGeneric(value: PMREADER): PSAMPLE; cdecl; external;
+procedure Sample_Free(value: PSAMPLE); cdecl; external;
+function Sample_Play(value1: PSAMPLE; value2: cuint; value3: cuchar): cschar; cdecl; external;
+
+procedure Voice_SetVolume(value1: cschar; value2: cushort); cdecl; external;
+function Voice_GetVolume(value: cschar): cushort; cdecl; external;
+procedure Voice_SetFrequency(value1: cschar; value2: cuint); cdecl; external;
+function Voice_GetFrequency(value: cschar): cuint; cdecl; external;
+procedure Voice_SetPanning(value1: cschar; value2: cuint); cdecl; external;
+function Voice_GetPanning(value: cschar): cuint; cdecl; external;
+procedure Voice_Play(value1: cschar; value2: PSAMPLE; value3: cuint); cdecl; external;
+procedure Voice_Stop(value: cschar); cdecl; external;
+function Voice_Stopped(value: cschar): cint; cdecl; external;
+function Voice_GetPosition(value: cschar): csint; cdecl; external;
+function Voice_RealVolume(value: cschar): cuint; cdecl; external;
+
+function MikMod_InfoLoader(): pcchar; cdecl; external;
+procedure MikMod_RegisterAllLoaders(); cdecl; external;
+procedure MikMod_RegisterLoader(value: PMLOADER); cdecl; external;
+
+function Player_Load(value1: pcchar; value2: cint; value3: cint): PMODULE; cdecl; external;
+function Player_LoadFP(value1: P_FILE; value2: cint; value3: cint): PMODULE; cdecl; external;
+function Player_LoadGeneric(value1: PMREADER; value2: cint; value3: cint): PMODULE; cdecl; external;
+function Player_LoadTitle(value: pcchar): pcchar; cdecl; external;
+function Player_LoadTitleFP(value: P_FILE): pcchar; cdecl; external;
+procedure Player_Free(value: PMODULE); cdecl; external;
+procedure Player_Start(value: PMODULE); cdecl; external;
+function Player_Active(): cint; cdecl; external;
+procedure Player_Stop(); cdecl; external;
+procedure Player_TogglePause(); cdecl; external;
+function Player_Paused(): cint; cdecl; external;
+procedure Player_NextPosition(); cdecl; external;
+procedure Player_PrevPosition(); cdecl; external;
+procedure Player_SetPosition(value: cushort); cdecl; external;
+function Player_Muted(value: cuchar): cint; cdecl; external;
+procedure Player_SetVolume(value: csshort); cdecl; external;
+function Player_GetModule(): PMODULE; cdecl; external;
+procedure Player_SetSpeed(value: cushort); cdecl; external;
+procedure Player_SetTempo(value: cushort); cdecl; external;
+procedure Player_Unmute(value: csint; args: array of const); cdecl; external;
+procedure Player_Mute(value: csint; args: array of const); cdecl; external;
+procedure Player_ToggleMute(value: csint; args: array of const); cdecl; external;
+function Player_GetChannelVoice(value: cuchar): cint; cdecl; external;
+function Player_GetChannelPeriod(value: cuchar): cushort; cdecl; external;
+
+function MikMod_RegisterPlayer(value: MikMod_player_t): MikMod_player_t; cdecl; external;
+
+function VC_Init(): cint; cdecl; external;
+procedure VC_Exit(); cdecl; external;
+function VC_SetNumVoices(): cint; cdecl; external;
+function VC_SampleSpace(value: cint): cuint; cdecl; external;
+function VC_SampleLength(value1: cint; value2: PSAMPLE): cuint; cdecl; external;
+
+function VC_PlayStart(): cint; cdecl; external;
+procedure VC_PlayStop(); cdecl; external;
+
+function VC_SampleLoad(value1: PSAMPLOAD; value2: cint): csshort; cdecl; external;
+procedure VC_SampleUnload(value: csshort); cdecl; external;
+
+function VC_WriteBytes(value1: pcschar; value2: cuint): cuint; cdecl; external;
+function VC_SilenceBytes(value1: pcschar; value2: cuint): cuint; cdecl; external;
+
+procedure VC_VoiceSetVolume(value1: cuchar; value2: cushort); cdecl; external;
+function VC_VoiceGetVolume(value: cuchar): cushort; cdecl; external;
+procedure VC_VoiceSetFrequency(value1: cuchar; value2: cuint); cdecl; external;
+function VC_VoiceGetFrequency(value: cuchar): cuint; cdecl; external;
+procedure VC_VoiceSetPanning(value1: cuchar; value2: cuint); cdecl; external;
+function VC_VoiceGetPanning(value: cuchar): cuint; cdecl; external;
+procedure VC_VoicePlay(value1: cuchar; value2: csshort; value3, value4, value5, value6: cuint; value7: cushort); cdecl; external;
+
+procedure VC_VoiceStop(value: cuchar); cdecl; external;
+function VC_VoiceStopped(value: cuchar): cint; cdecl; external;
+function VC_VoiceGetPosition(value: cuchar): csint; cdecl; external;
+function VC_VoiceRealVolume(value: cuchar): cuint; cdecl; external;
+
+
+(****** NDS part **************************************************************)
+const
+ NDS_HW_MAXSAMPLES = 128;
+ NDS_HW_MAXVOICES = 16;
+
+ NDS_HW_CHANGE_START = (1 shl 0);
+ NDS_HW_CHANGE_STOP = (1 shl 1);
+ NDS_HW_CHANGE_VOLUME = (1 shl 2);
+ NDS_HW_CHANGE_FREQUENCY = (1 shl 3);
+ NDS_HW_CHANGE_PANNING = (1 shl 4);
+
+type
+ NDS_SW_IPC = packed record
+ buffer: pcschar;
+ prevTimer: cint;
+ writeCursor: cint;
+ readCursor: cint;
+ bufferSize: cint;
+ sampleRate: cint;
+ format: cint;
+ playing: cint;
+ end;
+
+ NDS_HW_VOICE = packed record
+ handle: csshort;
+ start: cuint;
+ length: cuint;
+ loopstart: cuint;
+ loopend: cuint;
+ flags: cushort;
+ volume: cushort;
+ frequency: cuint;
+ panning: cuint;
+ playing: cint;
+ changes: cuchar;
+ end;
+
+ NDS_HW_IPC = packed record
+ samples: array [0..NDS_HW_MAXSAMPLES - 1] of pointer;
+ voices: array [0..NDS_HW_MAXVOICES - 1] of NDS_HW_VOICE;
+ end;
+
+ NDS_COMMAND = (
+ NDS_SW_CMD_INIT = 1,
+ NDS_SW_CMD_START,
+ NDS_SW_CMD_UPDATE,
+ NDS_SW_CMD_STOP,
+ NDS_SW_CMD_EXIT,
+ NDS_HW_CMD_INIT,
+ NDS_HW_CMD_EXIT,
+ NDS_HW_CMD_PLAY_START,
+ NDS_HW_CMD_PLAY_STOP,
+ NDS_HW_CMD_RESET,
+ NDS_HW_CMD_VOICE_UPDATE
+ );
+
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+{$ifdef ARM9}
+//procedure MikMod9_SendCommand(command: cuint); cdecl; forward;
+{$endif ARM9}
+
+procedure _mm_free(var p: pointer); inline;
+begin
+ if p <> nil then
+ FreeMem(p);
+ p := nil;
+end;
+{$endif NDS_IMPLEMENTATION}
diff --git a/packages/libndsfpc/src/libmikmod/mikmod7.pp b/packages/libndsfpc/src/libmikmod/mikmod7.pp
new file mode 100644
index 0000000000..c228dbf3a9
--- /dev/null
+++ b/packages/libndsfpc/src/libmikmod/mikmod7.pp
@@ -0,0 +1,32 @@
+unit mikmod7;
+{$mode objfpc}
+{$apptype arm7}
+{$define arm7}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds7;
+
+{$linklib nds7}
+{$linklib mikmod7}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include inc/mikmod.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include inc/mikmod.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/libmikmod/mikmod9.pp b/packages/libndsfpc/src/libmikmod/mikmod9.pp
new file mode 100644
index 0000000000..e4ac249101
--- /dev/null
+++ b/packages/libndsfpc/src/libmikmod/mikmod9.pp
@@ -0,0 +1,32 @@
+unit mikmod9;
+{$mode objfpc}
+{$apptype arm9}
+{$define arm9}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes, nds9;
+
+{$linklib nds9}
+{$linklib mikmod9}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include inc/mikmod.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+{$define NDS_IMPLEMENTATION}
+{$include inc/mikmod.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/nds/arm7/audio.inc b/packages/libndsfpc/src/nds/arm7/audio.inc
new file mode 100644
index 0000000000..e06f7954a6
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm7/audio.inc
@@ -0,0 +1,200 @@
+(*
+ $Id: audio.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM7}
+{$error Audio is only available on the ARM7}
+{$endif ARM7}
+
+{$ifdef NDS_IMPLEMENTATION}
+function SOUND_VOL(n: cint): cint; inline;
+begin
+ SOUND_VOL := (n);
+end;
+
+function SOUND_FREQ(n: cint): cint; inline;
+begin
+ SOUND_FREQ := ((-$1000000 div (n)));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ SOUND_ENABLE = (1 shl 15);
+ SOUND_REPEAT = (1 shl 27);
+ SOUND_ONE_SHOT = (1 shl 28);
+ SOUND_FORMAT_16BIT = (1 shl 29);
+ SOUND_FORMAT_8BIT = (0 shl 29);
+ SOUND_FORMAT_PSG = (3 shl 29);
+ SOUND_FORMAT_ADPCM = (2 shl 29);
+ SOUND_16BIT = (1 shl 29);
+ SOUND_8BIT = (0);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function SOUND_PAN(n: cint): cint; inline;
+begin
+ SOUND_PAN := ((n) shl 16);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ SCHANNEL_ENABLE = (1 shl 31);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+//---------------------------------------------------------------------------------
+// registers
+//---------------------------------------------------------------------------------
+function SCHANNEL_CR(n: cint): pcuint32; inline;
+begin
+ SCHANNEL_CR := pcuint32($04000400 + ((n) shl 4));
+end;
+
+function SCHANNEL_VOL(n: cint): pcuint8; inline;
+begin
+ SCHANNEL_VOL := pcuint8($04000400 + ((n) shl 4));
+end;
+
+function SCHANNEL_PAN(n: cint): pcuint8; inline;
+begin
+ SCHANNEL_PAN := pcuint8($04000402 + ((n) shl 4));
+end;
+
+function SCHANNEL_SOURCE(n: cint): pcuint32; inline;
+begin
+ SCHANNEL_SOURCE := pcuint32($04000404 + ((n) shl 4));
+end;
+
+function SCHANNEL_TIMER(n: cint): pcuint16; inline;
+begin
+ SCHANNEL_TIMER := pcuint16($04000408 + ((n) shl 4));
+end;
+
+function SCHANNEL_REPEAT_POINT(n: cint): pcuint16; inline;
+begin
+ SCHANNEL_REPEAT_POINT := pcuint16($0400040A + ((n) shl 4));
+end;
+
+function SCHANNEL_LENGTH(n: cint): pcuint32; inline;
+begin
+ SCHANNEL_LENGTH := pcuint32($0400040C + ((n) shl 4));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ SOUND_CR : pcuint16 = pointer($04000500);
+ SOUND_MASTER_VOL : pcuint8 = pointer($04000500);
+
+//---------------------------------------------------------------------------------
+// not sure on the following
+//---------------------------------------------------------------------------------
+ SOUND_BIAS : pcuint16 = pointer($04000504);
+ SOUND508 : pcuint16 = pointer($04000508);
+ SOUND510 : pcuint16 = pointer($04000510);
+ SOUND514 : pcuint16 = pointer($04000514);
+ SOUND518 : pcuint16 = pointer($04000518);
+ SOUND51C : pcuint16 = pointer($0400051C);
+
+
+(*---------------------------------------------------------------------------------
+ microphone code based on neimod's microphone example.
+ See: http://neimod.com/dstek/
+ Chris Double (chris.double@double.co.nz)
+ http://www.double.co.nz/nintendo_ds
+---------------------------------------------------------------------------------*)
+
+
+(*---------------------------------------------------------------------------------
+ Read a byte from the microphone
+---------------------------------------------------------------------------------*)
+function MIC_ReadData(): cuint8; cdecl; external;
+
+(*---------------------------------------------------------------------------------
+ Fill the buffer with data from the microphone. The buffer will be
+ signed sound data at 16kHz. Once the length of the buffer is
+ reached, no more data will be stored. Uses ARM7 timer 0.
+---------------------------------------------------------------------------------*)
+procedure StartRecording(buffer: pcuint8; length: cint); cdecl; external;
+
+(*---------------------------------------------------------------------------------
+ Stop recording data, and return the length of data recorded.
+---------------------------------------------------------------------------------*)
+function StopRecording(): cint; cdecl; external;
+
+(* This must be called during IRQ_TIMER0 *)
+procedure ProcessMicrophoneTimerIRQ(); cdecl; external;
+
+procedure PM_SetAmp(control: cuint8); cdecl; external;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+//---------------------------------------------------------------------------------
+// Turn the microphone on
+//---------------------------------------------------------------------------------
+procedure MIC_On(); inline;
+begin
+ PM_SetAmp(PM_AMP_ON);
+end;
+
+//---------------------------------------------------------------------------------
+// Turn the microphone off
+//---------------------------------------------------------------------------------
+procedure MIC_Off(); inline;
+begin
+ PM_SetAmp(PM_AMP_OFF);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+function SOUND_VOL(n: cint): cint; inline;
+function SOUND_FREQ(n: cint): cint; inline;
+function SOUND_PAN(n: cint): cint; inline;
+function SCHANNEL_CR(n: cint): pcuint32; inline;
+function SCHANNEL_VOL(n: cint): pcuint8; inline;
+function SCHANNEL_PAN(n: cint): pcuint8; inline;
+function SCHANNEL_SOURCE(n: cint): pcuint32; inline;
+function SCHANNEL_TIMER(n: cint): pcuint16; inline;
+function SCHANNEL_REPEAT_POINT(n: cint): pcuint16; inline;
+function SCHANNEL_LENGTH(n: cint): pcuint32; inline;
+procedure MIC_On(); inline;
+procedure MIC_Off(); inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm7/clock.inc b/packages/libndsfpc/src/nds/arm7/clock.inc
new file mode 100644
index 0000000000..d95d4be2d1
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm7/clock.inc
@@ -0,0 +1,107 @@
+(*
+ $Id: clock.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM7}
+{$error The clock is only available on the ARM7}
+{$endif ARM7}
+
+{$ifdef NDS_INTERFACE}
+const
+// RTC registers
+ WRITE_STATUS_REG1 = $60;
+ READ_STATUS_REG1 = $61;
+ STATUS_POC = (1 shl 7); // read-only, cleared by reading (1 if just powered on)
+ STATUS_BLD = (1 shl 6); // read-only, cleared by reading (1 if power dropped below the safety threshold)
+ STATUS_INT2 = (1 shl 5); // read-only, INT2 has occured
+ STATUS_INT1 = (1 shl 4); // read-only, INT1 has occured
+ STATUS_SC1 = (1 shl 3); // R/W scratch bit
+ STATUS_SC0 = (1 shl 2); // R/W scratch bit
+ STATUS_24HRS = (1 shl 1); // 24 hour mode when 1, 12 hour mode when 0
+ STATUS_RESET = (1 shl 0); // write-only, reset when 1 written
+
+ WRITE_STATUS_REG2 = $62;
+ READ_STATUS_REG2 = $63;
+ STATUS_TEST = (1 shl 7); //
+ STATUS_INT2AE = (1 shl 6); //
+ STATUS_SC3 = (1 shl 5); // R/W scratch bit
+ STATUS_SC2 = (1 shl 4); // R/W scratch bit
+
+ STATUS_32kE = (1 shl 3); // Interrupt mode bits
+ STATUS_INT1AE = (1 shl 2); //
+ STATUS_INT1ME = (1 shl 1); //
+ STATUS_INT1FE = (1 shl 0); //
+
+ // full 7 bytes for time and date
+ WRITE_TIME_AND_DATE = $64;
+ READ_TIME_AND_DATE = $65;
+
+ // last 3 bytes of current time
+ WRITE_TIME = $66;
+ READ_TIME = $67;
+
+
+ WRITE_INT_REG1 = $68;
+ READ_INT_REG1 = $69;
+
+ READ_INT_REG2 = $6A;
+ WRITE_INT_REG2 = $6B;
+
+ READ_CLOCK_ADJUST_REG = $6C;
+ WRITE_CLOCK_ADJUST_REG = $6D;
+// clock-adjustment register
+
+ READ_FREE_REG = $6E;
+ WRITE_FREE_REG = $6F;
+
+
+procedure rtcReset(); cdecl; external;
+procedure rtcTransaction(command: pcuint8; commandLength: cuint32; result: pcuint8; resultLength: cuint32); cdecl; external;
+procedure rtcGetTime(time: pcuint8); cdecl; external;
+procedure rtcSetTime(time: pcuint8); cdecl; external;
+procedure rtcGetData(data: pcuint8; size: cuint32); cdecl; external;
+
+procedure rtcGetTimeAndDate(time: pcuint8); cdecl; external;
+procedure rtcSetTimeAndDate(time: pcuint8); cdecl; external;
+
+procedure BCDToInteger(data: pcuint8; length: cuint32); cdecl; external;
+procedure integerToBCD(data: pcuint8; length: uint32); cdecl; external;
+
+procedure initClockIRQ(); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm7/serial.inc b/packages/libndsfpc/src/nds/arm7/serial.inc
new file mode 100644
index 0000000000..8a30b9c7f5
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm7/serial.inc
@@ -0,0 +1,185 @@
+(*
+ $Id: serial.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM7}
+{$error Serial header is for ARM7 only}
+{$endif ARM7}
+
+{$ifdef NDS_INTERFACE}
+const
+// 'Networking'
+ REG_RCNT : pcuint16 = pointer($04000134);
+ REG_KEYXY : pcuint16 = pointer($04000136);
+ RTC_CR : pcuint16 = pointer($04000138);
+ RTC_CR8 : pcuint8 = pointer($04000138);
+
+ REG_SIOCNT : pcuint16 = pointer($04000128);
+
+ SIO_DATA8 : pcuint8 = pointer($0400012A);
+ SIO_DATA32 : pcuint32 = pointer($04000120);
+
+
+// Fixme: Does the hardware still support 16 bit comms mode?
+// BIOS makes use of 32 bit mode, so some regs still exist
+ SIO_MULTI_0 : pcuint16 = pointer($04000120);
+ SIO_MULTI_1 : pcuint16 = pointer($04000122);
+ SIO_MULTI_2 : pcuint16 = pointer($04000124);
+ SIO_MULTI_3 : pcuint16 = pointer($04000126);
+ SIO_MULTI_SEND : pcuint16 = pointer($0400012A);
+
+
+// SPI chain registers
+ REG_SPICNT : pcuint16 = pointer($040001C0);
+ REG_SPIDATA : pcuint16 = pointer($040001C2);
+
+ SPI_ENABLE = (1 shl 15);
+ SPI_IRQ = (1 shl 14);
+ SPI_BUSY = (1 shl 7);
+
+// Pick the SPI clock speed
+ SPI_BAUD_4MHZ = 0;
+ SPI_BAUD_2MHZ = 1;
+ SPI_BAUD_1MHZ = 2;
+ SPI_BAUD_512KHZ = 3;
+
+// Pick the SPI transfer length
+ SPI_BYTE_MODE = (0 shl 10);
+ SPI_HWORD_MODE = (1 shl 10);
+
+// Pick the SPI device
+ SPI_DEVICE_POWER = (0 shl 8);
+ SPI_DEVICE_FIRMWARE = (1 shl 8);
+ SPI_DEVICE_NVRAM = (1 shl 8);
+ SPI_DEVICE_TOUCH = (2 shl 8);
+ SPI_DEVICE_MICROPHONE = (2 shl 8);
+
+// When used, the /CS line will stay low after the transfer ends
+// i.e. when we're part of a continuous transfer
+ SPI_CONTINUOUS = (1 shl 11);
+
+// Fixme: does this stuff really belong in serial.h?
+
+// Power management registers
+ PM_CONTROL_REG = 0;
+ PM_BATTERY_REG = 1;
+ PM_AMPLIFIER_REG = 2;
+ PM_READ_REGISTER = (1 shl 7);
+
+// PM control register bits - power control
+ PM_SOUND_AMP = (1 shl 0); // Power the sound hardware (needed to hear stuff in GBA mode too)
+ PM_SOUND_MUTE = (1 shl 1); // Mute the main speakers, headphone output will still work.
+ PM_BACKLIGHT_BOTTOM = (1 shl 2); // Enable the top backlight if set
+ PM_BACKLIGHT_TOP = (1 shl 3); // Enable the bottom backlight if set
+ PM_SYSTEM_PWR = (1 shl 6); // Turn the power *off* if set
+ PM_POWER_DOWN = (1 shl 6); // Same thing, I like this name better tho
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+// PM control register bits - LED control
+function PM_LED_CONTROL(m: cint): cint; inline;
+begin
+ PM_LED_CONTROL := m shl 4; // ?
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ PM_LED_ON = (0 shl 4); // Steady on
+ PM_LED_SLEEP = (1 shl 4); // Blinking, mostly off
+ PM_LED_BLINK = (3 shl 4); // Blinking, mostly on
+
+
+ PM_AMP_OFFSET = 2;
+ PM_AMP_ON = 1;
+ PM_AMP_OFF = 0;
+
+// Fixme: does this stuff really belong in serial.h?
+
+// Firmware commands
+ FIRMWARE_WREN = $06;
+ FIRMWARE_WRDI = $04;
+ FIRMWARE_RDID = $9F;
+ FIRMWARE_RDSR = $05;
+ FIRMWARE_READ = $03;
+ FIRMWARE_PW = $0A;
+ FIRMWARE_PP = $02;
+ FIRMWARE_FAST = $0B;
+ FIRMWARE_PE = $DB;
+ FIRMWARE_SE = $D8;
+ FIRMWARE_DP = $B9;
+ FIRMWARE_RDP = $AB;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+procedure SerialWaitBusy(); inline;
+begin
+ while (REG_SPICNT^ and SPI_BUSY) <> 0 do
+ swiDelay(1);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+// Warning: These functions use the SPI chain, and are thus 'critical'
+// sections, make sure to disable interrupts during the call if you've
+// got a VBlank IRQ polling the touch screen, etc...
+
+// Read/write a power management register
+
+{$ifdef NDS_INTERFACE}
+function writePowerManagement(reg: cint; command: cint): cint; cdecl; external;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function readPowerManagement(reg: cint): cint; inline;
+begin
+ readPowerManagement := writePowerManagement(reg or PM_READ_REGISTER, 0);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+// Read the firmware
+procedure readFirmware(address: cuint32; destination: pointer; size: cuint32); cdecl; external;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function PM_LED_CONTROL(m: cint): cint; inline;
+procedure SerialWaitBusy(); inline;
+function readPowerManagement(reg: cint): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm7/touch.inc b/packages/libndsfpc/src/nds/arm7/touch.inc
new file mode 100644
index 0000000000..5230a74152
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm7/touch.inc
@@ -0,0 +1,66 @@
+(*
+ $Id: touch.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM7}
+{$error Touch screen is only available on the ARM7}
+{$endif ARM7}
+
+{$ifdef NDS_INTERFACE}
+const
+ SCREEN_WIDTH = 256;
+ SCREEN_HEIGHT = 192;
+
+
+ TSC_MEASURE_TEMP1 = $84;
+ TSC_MEASURE_Y = $90;
+ TSC_MEASURE_BATTERY = $A4;
+ TSC_MEASURE_Z1 = $B4;
+ TSC_MEASURE_Z2 = $C4;
+ TSC_MEASURE_X = $D0;
+ TSC_MEASURE_AUX = $E4;
+ TSC_MEASURE_TEMP2 = $F4;
+
+
+
+function touchReadXY(): touchPosition; cdecl; external;
+
+function touchRead(command: cuint32): cuint16; cdecl; external;
+function touchReadTemperature(t1: pcint; t2: pcint): cuint32; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/background.inc b/packages/libndsfpc/src/nds/arm9/background.inc
new file mode 100644
index 0000000000..f4453dc7f9
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/background.inc
@@ -0,0 +1,96 @@
+(*
+ $Id: background.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+// Background control defines
+
+{$ifdef NDS_INTERFACE}
+// BGxCNT defines ///
+const
+ BG_MOSAIC_ENABLE = $40;
+ BG_COLOR_256 = $80;
+ BG_COLOR_16 = $00;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function CHAR_BASE_BLOCK(n: cint): cint; inline;
+begin
+ CHAR_BASE_BLOCK := (n * $4000)+ $06000000;
+end;
+
+function CHAR_BASE_BLOCK_SUB(n: cint): cint; inline;
+begin
+ CHAR_BASE_BLOCK_SUB := (n * $4000)+ $06200000;
+end;
+
+function SCREEN_BASE_BLOCK(n: cint): cint; inline;
+begin
+ SCREEN_BASE_BLOCK := (n * $800) + $06000000;
+end;
+
+function SCREEN_BASE_BLOCK_SUB(n: cint): cint; inline;
+begin
+ SCREEN_BASE_BLOCK_SUB := (n * $800) + $06200000;
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ CHAR_SHIFT = 2;
+ SCREEN_SHIFT = 8;
+ TEXTBG_SIZE_256x256 = $0;
+ TEXTBG_SIZE_256x512 = $8000;
+ TEXTBG_SIZE_512x256 = $4000;
+ TEXTBG_SIZE_512x512 = $C000;
+
+ ROTBG_SIZE_128x128 = $0;
+ ROTBG_SIZE_256x256 = $4000;
+ ROTBG_SIZE_512x512 = $8000;
+ ROTBG_SIZE_1024x1024 = $C000;
+
+ WRAPAROUND = $1;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function CHAR_BASE_BLOCK(n: cint): cint; inline;
+function CHAR_BASE_BLOCK_SUB(n: cint): cint; inline;
+function SCREEN_BASE_BLOCK(n: cint): cint; inline;
+function SCREEN_BASE_BLOCK_SUB(n: cint): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/boxtest.inc b/packages/libndsfpc/src/nds/arm9/boxtest.inc
new file mode 100644
index 0000000000..976e927778
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/boxtest.inc
@@ -0,0 +1,52 @@
+(*
+ $Id: boxtest.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+{$ifdef NDS_INTERFACE}
+function BoxTest(x, y, z, width, height, depth: {v16}cuint16): cint; cdecl; external;
+
+function BoxTestf(x, y, z, width, height, depth: cfloat): cint; cdecl; external;
+
+procedure BoxTest_Asynch(x, y, z, width, height, depth: {v16}cuint16); cdecl; external;
+
+procedure BoxTestf_Asynch(x, y, z, width, height, depth: cfloat); cdecl; external;
+
+function BoxTestResult(): cint; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/cache.inc b/packages/libndsfpc/src/nds/arm9/cache.inc
new file mode 100644
index 0000000000..f5ec28b5e4
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/cache.inc
@@ -0,0 +1,53 @@
+(*
+ $Id: cache.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+procedure IC_InvalidateAll(); cdecl; external;
+
+procedure IC_InvalidateRange(const base: pointer; size: cuint32); cdecl; external;
+
+procedure DC_FlushAll(); cdecl; external;
+
+procedure DC_FlushRange(const base: pointer; size: cuint32); cdecl; external;
+
+procedure DC_InvalidateAll(); cdecl; external;
+
+procedure DC_InvalidateRange(const base: pointer; size: cuint32); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/console.inc b/packages/libndsfpc/src/nds/arm9/console.inc
new file mode 100644
index 0000000000..0c3421b823
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/console.inc
@@ -0,0 +1,51 @@
+(*
+ $Id: console.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ CONSOLE_USE_COLOR255 = 16;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+procedure consoleInit(font: pcuint16; charBase: pcuint16; numCharacters: cuint16; charStart: cuint8; map: pcuint16; pal: cuint8; bitDepth: cuint8); cdecl; external;
+procedure consoleInitDefault(map: pcuint16; charBase: pcuint16; bitDepth: cuint8); cdecl; external;
+procedure consoleDemoInit(); cdecl; external;
+procedure consoleClear(); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/exceptions.inc b/packages/libndsfpc/src/nds/arm9/exceptions.inc
new file mode 100644
index 0000000000..5dc10c5329
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/exceptions.inc
@@ -0,0 +1,55 @@
+(*
+ $Id: exceptions.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ EXCEPTION_VECTOR : ^VoidFunctionPointer = pointer($27FFD9C);
+
+var
+ exceptionC: ^VoidFunctionPointer; cvar; external;
+ exceptionStack: cuint32; cvar; external;
+ exceptionRegisters: pcint32; cvar; external;
+
+procedure enterException(); cdecl; external;
+procedure setExceptionHandler(handler: VoidFunctionPointer); cdecl; external;
+procedure defaultExceptionHandler(); cdecl; external;
+
+function getCPSR(): cuint32; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/image.inc b/packages/libndsfpc/src/nds/arm9/image.inc
new file mode 100644
index 0000000000..5eba23e25a
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/image.inc
@@ -0,0 +1,72 @@
+(*
+ $Id: image.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+type
+//holds a rgb triplet
+ RGB_24 = packed record
+ r: cuchar;
+ g: cuchar;
+ b: cuchar;
+ end;
+
+ //holds a basic image type for loading image files
+ sImage = record
+ height: cshort;
+ width: cshort;
+ bpp: cint;
+ palette: pcushort;
+ image: record
+ case integer of
+ 0: (data8: pcuchar);
+ 1: (data16: pcushort);
+ 2: (data32: pcuint);
+ end;
+ end;
+ TsImage = sImage;
+ PsImage = ^sImage;
+
+
+procedure image24to16(img: PsImage); cdecl; external;
+procedure image8to16(img: PsImage); cdecl; external;
+procedure image8to16trans(img: PsImage; transperentColor: cuint8); cdecl; external;
+procedure imageDestroy(img: PsImage); cdecl; external;
+procedure imageTileData(img: PsImage); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/input.inc b/packages/libndsfpc/src/nds/arm9/input.inc
new file mode 100644
index 0000000000..821706258d
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/input.inc
@@ -0,0 +1,75 @@
+(*
+ $Id: input.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+// Keyboard
+type
+ KEYPAD_BITS = cint;
+const
+//! Bit values for the keypad buttons.
+ KEY_A : KEYPAD_BITS = (1 shl 0); // Keypad A button.
+ KEY_B : KEYPAD_BITS = (1 shl 1); // Keypad B button.
+ KEY_SELECT : KEYPAD_BITS = (1 shl 2); // Keypad SELECT button.
+ KEY_START : KEYPAD_BITS = (1 shl 3); // Keypad START button.
+ KEY_RIGHT : KEYPAD_BITS = (1 shl 4); // Keypad RIGHT button.
+ KEY_LEFT : KEYPAD_BITS = (1 shl 5); // Keypad LEFT button.
+ KEY_UP : KEYPAD_BITS = (1 shl 6); // Keypad UP button.
+ KEY_DOWN : KEYPAD_BITS = (1 shl 7); // Keypad DOWN button.
+ KEY_R : KEYPAD_BITS = (1 shl 8); // Right shoulder button.
+ KEY_L : KEYPAD_BITS = (1 shl 9); // Left shoulder button.
+ KEY_X : KEYPAD_BITS = (1 shl 10); // Keypad X button.
+ KEY_Y : KEYPAD_BITS = (1 shl 11); // Keypad Y button.
+ KEY_TOUCH : KEYPAD_BITS = (1 shl 12); // Touchscreen pendown.
+ KEY_LID : KEYPAD_BITS = (1 shl 13); // Lid state.
+
+procedure scanKeys(); cdecl; external;
+
+function keysHeld(): cuint32; cdecl; external;
+
+function keysDown(): cuint32; cdecl; external;
+
+function keysDownRepeat(): cuint32; cdecl; external;
+
+procedure keysSetRepeat(setDelay: cuint8; setRepeat: cuint8); cdecl; external;
+
+function keysUp(): cuint32; cdecl; external;
+
+function touchReadXY(): touchPosition; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/math.inc b/packages/libndsfpc/src/nds/arm9/math.inc
new file mode 100644
index 0000000000..0cf3bfc88f
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/math.inc
@@ -0,0 +1,245 @@
+(*
+ $Id: math.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+// Math coprocessor register definitions
+const
+ DIV_CR : pcuint16 = pointer($04000280);
+ DIV_NUMERATOR64 : pcint64 = pointer($04000290);
+ DIV_NUMERATOR32 : pcint32 = pointer($04000290);
+ DIV_DENOMINATOR64 : pcint64 = pointer($04000298);
+ DIV_DENOMINATOR32 : pcint32 = pointer($04000298);
+ DIV_RESULT64 : pcint64 = pointer($040002A0);
+ DIV_RESULT32 : pcint32 = pointer($040002A0);
+ DIV_REMAINDER64 : pcint64 = pointer($040002A8);
+ DIV_REMAINDER32 : pcint32 = pointer($040002A8);
+
+ SQRT_CR : pcuint16 = pointer($040002B0);
+ SQRT_PARAM64 : pcint64 = pointer($040002B8);
+ SQRT_RESULT32 : pcint32 = pointer($040002B4);
+ SQRT_PARAM32 : pcint32 = pointer($040002B8);
+
+// Math coprocessor modes
+
+ DIV_64_64 = 2;
+ DIV_64_32 = 1;
+ DIV_32_32 = 0;
+ DIV_BUSY = (1 shl 15);
+
+ SQRT_64 = 1;
+ SQRT_32 = 0;
+ SQRT_BUSY = (1 shl 15);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function divf32(num: cint32; den: cint32): cint32; inline;
+begin
+ DIV_CR^ := DIV_64_32;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ DIV_NUMERATOR64^ := cint64(num) shl 12;
+ DIV_DENOMINATOR32^ := den;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ divf32 := DIV_RESULT32^;
+end;
+
+function mulf32(a, b: cint32): cint32; inline;
+var
+ rslt: clonglong;
+begin
+ rslt := clonglong(a) * clonglong(b);
+ mulf32 := cint32(rslt shr 12);
+end;
+
+// Fixed point square root
+// Takes 1.19.12 fixed point value and
+// returns the fixed point result
+function sqrtf32(a: cint32): cint32; inline;
+begin
+ SQRT_CR^ := SQRT_64;
+
+ while (SQRT_CR^ and SQRT_BUSY) <> 0 do;
+
+ SQRT_PARAM64^ := cint64(a) shl 12;
+
+ while (SQRT_CR^ and SQRT_BUSY) <> 0 do;
+
+ sqrtf32 := SQRT_RESULT32^;
+end;
+
+// Integer versions
+
+// Integer divide
+// Takes a 32 bit numerator and 32 bit
+// denominator and returns 32 bit result
+function div32(num, den: cint32): cint32; inline;
+begin
+ DIV_CR^ := DIV_32_32;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ DIV_NUMERATOR32^ := num;
+ DIV_DENOMINATOR32^ := den;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ div32 := DIV_RESULT32^;
+end;
+
+// Integer divide
+// Takes a 32 bit numerator and 32 bit
+// denominator and returns 32 bit result
+function mod32(num, den: cint32): cint32; inline;
+begin
+ DIV_CR^ := DIV_32_32;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ DIV_NUMERATOR32^ := num;
+ DIV_DENOMINATOR32^ := den;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ mod32 := DIV_REMAINDER32^;
+end;
+
+// Integer divide
+// Takes a 64 bit numerator and 32 bit
+// denominator are returns 32 bit result
+function div64(num: cint64; den: cint32): cint32; inline;
+begin
+ DIV_CR^ := DIV_64_32;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ DIV_NUMERATOR64^ := num;
+ DIV_DENOMINATOR32^ := den;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ div64 := DIV_RESULT32^;
+end;
+
+// Integer divide
+// Takes a 64 bit numerator and 32 bit
+// denominator are returns 32 bit result
+function mod64(num: cint64; den: cint32): cint32; inline;
+begin
+ DIV_CR^ := DIV_64_32;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ DIV_NUMERATOR64^ := num;
+ DIV_DENOMINATOR32^ := den;
+
+ while (DIV_CR^ and DIV_BUSY) <> 0 do;
+
+ mod64 := DIV_REMAINDER32^;
+end;
+
+// Integer square root
+// takes a 32 bit integer and returns
+// 32 bit result
+function sqrt32(a: cint32): cint32; inline;
+begin
+ SQRT_CR^ := SQRT_32;
+
+ while(SQRT_CR^ and SQRT_BUSY) <> 0 do;
+
+ SQRT_PARAM32^ := a;
+
+ while(SQRT_CR^ and SQRT_BUSY) <> 0 do;
+
+ sqrt32 := SQRT_RESULT32^;
+end;
+
+// Trig Functions 1.19.12 fixed point
+
+// Cross product
+// x = Ay * Bz - By * Az
+// y = Az * Bx - Bz * Ax
+// z = Ax * By - Bx * Ay
+procedure crossf32(a: pcint32; b: pcint32; res: pcint32); inline;
+begin
+ res[0] := mulf32(a[1], b[2]) - mulf32(b[1], a[2]);
+ res[1] := mulf32(a[2], b[0]) - mulf32(b[2], a[0]);
+ res[2] := mulf32(a[0], b[1]) - mulf32(b[0], a[1]);
+end;
+
+// Dot Product
+// result = Ax * Bx + Ay * By + Az * Bz
+function dotf32(a, b: pcint32): cint32; inline;
+begin
+ dotf32 := mulf32(a[0], b[0]) + mulf32(a[1], b[1]) + mulf32(a[2], b[2]);
+end;
+
+// Normalize
+// Ax = Ax / mag
+// Ay = Ay / mag
+// Az = Az / mag
+procedure normalizef32(a: pcint32); inline;
+var
+ magnitude: cint32;
+begin
+ // magnitude = sqrt ( Ax^2 + Ay^2 + Az^2 )
+ magnitude := sqrtf32( mulf32(a[0], a[0]) + mulf32(a[1], a[1]) + mulf32(a[2], a[2]) );
+
+ a[0] := divf32(a[0], magnitude);
+ a[1] := divf32(a[1], magnitude);
+ a[2] := divf32(a[2], magnitude);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+function divf32(num: cint32; den: cint32): cint32; inline;
+function mulf32(a, b: cint32): cint32; inline;
+function sqrtf32(a: cint32): cint32; inline;
+function div32(num, den: cint32): cint32; inline;
+function mod32(num, den: cint32): cint32; inline;
+function div64(num: cint64; den: cint32): cint32; inline;
+function mod64(num: cint64; den: cint32): cint32; inline;
+function sqrt32(a: cint32): cint32; inline;
+procedure crossf32(a: pcint32; b: pcint32; res: pcint32); inline;
+function dotf32(a, b: pcint32): cint32; inline;
+procedure normalizef32(a: pcint32); inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/ndsmotion.inc b/packages/libndsfpc/src/nds/arm9/ndsmotion.inc
new file mode 100644
index 0000000000..65008566dd
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/ndsmotion.inc
@@ -0,0 +1,72 @@
+(*
+ $Id: ndsmotion.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2007
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2007 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+type
+ MotionCalibration = record
+ xoff, yoff, zoff, goff: cshort;
+ xsens, ysens, zsens, gsens: cshort;
+ end;
+ TMotionCalibration = MotionCalibration;
+ PMotionCalibration = ^MotionCalibration;
+
+function motion_init(): cint; cdecl; external;
+procedure motion_deinit(); cdecl; external;
+function motion_read_x(): csint; cdecl; external;
+function motion_read_y(): csint; cdecl; external;
+function motion_read_z(): csint; cdecl; external;
+function motion_read_gyro(): csint; cdecl; external;
+function motion_acceleration_x(): cint; cdecl; external;
+function motion_acceleration_y(): cint; cdecl; external;
+function motion_acceleration_z(): cint; cdecl; external;
+procedure motion_set_sens_x(sens: cint); cdecl; external;
+procedure motion_set_sens_y(sens: cint); cdecl; external;
+procedure motion_set_sens_z(sens: cint); cdecl; external;
+procedure motion_set_sens_gyro(sens: cint); cdecl; external;
+procedure motion_set_offs_x(); cdecl; external;
+procedure motion_set_offs_y(); cdecl; external;
+procedure motion_set_offs_z(); cdecl; external;
+procedure motion_set_offs_gyro(); cdecl; external;
+function motion_rotation(): cint; cdecl; external;
+function motion_get_calibration(): PMotionCalibration; cdecl; external;
+procedure motion_set_calibration(cal: PMotionCalibration); cdecl; external;
+procedure motion_enable_ain_1(); cdecl; external;
+procedure motion_enable_ain_2(); cdecl; external;
+function motion_read_ain_1(): cint; cdecl; external;
+function motion_read_ain_2(): cint; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/pcx.inc b/packages/libndsfpc/src/nds/arm9/pcx.inc
new file mode 100644
index 0000000000..6bbf176ee2
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/pcx.inc
@@ -0,0 +1,65 @@
+(*
+ $Id: pcx.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+type
+ // short int = cint16???
+ PCXHeader = packed record
+ manufacturer: cchar; //should be 0
+ version: cchar; //should be 5
+ encoding: cchar; //should be 1
+ bitsPerPixel: cchar; //should be 8
+ xmin,ymin: cint16; //coordinates for top left,bottom right
+ xmax,ymax: cint16;
+ hres: cint16; //resolution
+ vres: cint16;
+ palette16: array [0..47] of cchar; //16 color palette if 16 color image
+ reserved: cchar; //ignore
+ colorPlanes: cchar; //ignore
+ bytesPerLine: cint16;
+ paletteYype: cint16; //should be 2
+ filler: array [0..57] of cchar; //ignore
+ end;
+ TPCXHeader = PCXHeader;
+ PPCXHeader = ^PCXHeader;
+
+
+function loadPCX(pcx: pcuchar; image: PsImage): cint; cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/postest.inc b/packages/libndsfpc/src/nds/arm9/postest.inc
new file mode 100644
index 0000000000..8b1d134894
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/postest.inc
@@ -0,0 +1,86 @@
+(*
+ $Id: postest.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2007
+ Michael Noland (joat)
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2007 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_IMPLEMENTATION}
+function PosTestBusy(): cbool; inline;
+begin
+ PosTestBusy := (GFX_STATUS^ and (1 shl 0)) <> 0;
+end;
+
+procedure PosTest_Asynch(x, y, z: v16); inline;
+begin
+ GFX_POS_TEST^ := VERTEX_PACK(x, y);
+ GFX_POS_TEST^ := z;
+end;
+
+procedure PosTest(x, y, z: v16); inline;
+begin
+ PosTest_Asynch(x, y, z);
+ while PosTestBusy() do;
+end;
+
+function PosTestWresult(): cint32; inline;
+begin
+ PosTestWresult := GFX_POS_RESULT[3];
+end;
+
+function PosTestXresult(): cint32; inline;
+begin
+ PosTestXresult := GFX_POS_RESULT[0];
+end;
+
+function PosTestYresult(): cint32; inline;
+begin
+ PosTestYresult := GFX_POS_RESULT[1];
+end;
+
+function PosTestZresult(): cint32; inline;
+begin
+ PosTestZresult := GFX_POS_RESULT[2];
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+function PosTestBusy(): cbool; inline;
+procedure PosTest_Asynch(x, y, z: v16); inline;
+procedure PosTest(x, y, z: v16); inline;
+function PosTestWresult(): cint32; inline;
+function PosTestXresult(): cint32; inline;
+function PosTestYresult(): cint32; inline;
+function PosTestZresult(): cint32; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/rumble.inc b/packages/libndsfpc/src/nds/arm9/rumble.inc
new file mode 100644
index 0000000000..5fe9f6fefa
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/rumble.inc
@@ -0,0 +1,56 @@
+(*
+ $Id: rumble.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ RUMBLE_PAK: pcuint16 = pointer($08000000);
+ WARIOWARE_PAK: pcuint16 = pointer($080000C4);
+ WARIOWARE_ENABLE: pcuint16 = pointer($080000C6);
+
+type
+ RUMBLE_TYPE = (
+ RUMBLE, WARIOWARE
+ );
+ TRumbleType = RUMBLE_TYPE;
+
+
+function isRumbleInserted(): cbool; cdecl; external;
+procedure setRumble(position: cbool); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/sound.inc b/packages/libndsfpc/src/nds/arm9/sound.inc
new file mode 100644
index 0000000000..c3979aef47
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/sound.inc
@@ -0,0 +1,45 @@
+(*
+ $Id: sound.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+procedure playSound(sound: pTransferSoundData); cdecl; external;
+procedure setGenericSound(rate: cuint32; vol: cuint8; pan: cuint8; format: cuint8); cdecl; external;
+procedure playGenericSound(const data: pointer; length: cuint32); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/sprite.inc b/packages/libndsfpc/src/nds/arm9/sprite.inc
new file mode 100644
index 0000000000..504d71611f
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/sprite.inc
@@ -0,0 +1,224 @@
+(*
+ $Id: sprite.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ sprite.h -- definitions for DS sprites
+
+ Copyright (C) 2007
+ Liran Nuna (LiraNuna)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM9}
+ {$error Sprites are only available on the ARM9}
+{$endif ARM9}
+
+// Sprite control defines
+
+{$ifdef NDS_INTERFACE}
+// Attribute 0 consists of 8 bits of Y plus the following flags:
+const
+ ATTR0_NORMAL = (0 shl 8);
+ ATTR0_ROTSCALE = (1 shl 8);
+ ATTR0_DISABLED = (2 shl 8);
+ ATTR0_ROTSCALE_DOUBLE = (3 shl 8);
+
+ ATTR0_TYPE_NORMAL = (0 shl 10);
+ ATTR0_TYPE_BLENDED = (1 shl 10);
+ ATTR0_TYPE_WINDOWED = (2 shl 10);
+ ATTR0_BMP = (3 shl 10);
+
+ ATTR0_MOSAIC = (1 shl 12);
+
+ ATTR0_COLOR_16 = (0 shl 13); //16 color in tile mode...16 bit in bitmap mode
+ ATTR0_COLOR_256 = (1 shl 13);
+
+ ATTR0_SQUARE = (0 shl 14);
+ ATTR0_WIDE = (1 shl 14);
+ ATTR0_TALL = (2 shl 14);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function OBJ_Y(m: cint): cint; inline;
+begin
+ OBJ_Y := ((m) and $00ff);
+end;
+
+function ATTR1_ROTDATA(n: cint): cint; inline;
+begin
+ ATTR1_ROTDATA := ((n) shl 9) // note: overlaps with flip flags
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ ATTR1_FLIP_X = (1 shl 12);
+ ATTR1_FLIP_Y = (1 shl 13);
+ ATTR1_SIZE_8 = (0 shl 14);
+ ATTR1_SIZE_16 = (1 shl 14);
+ ATTR1_SIZE_32 = (2 shl 14);
+ ATTR1_SIZE_64 = (3 shl 14);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function OBJ_X(m: cint): cint; inline;
+begin
+ OBJ_X := ((m) and $01ff);
+end;
+
+// Atribute 2 consists of the following:
+function ATTR2_PRIORITY(n: cint): cint; inline;
+begin
+ ATTR2_PRIORITY := ((n) shl 10);
+end;
+
+function ATTR2_PALETTE(n: cint): cint; inline;
+begin
+ ATTR2_PALETTE := ((n) shl 12);
+end;
+
+function ATTR2_ALPHA(n: cint): cint; inline;
+begin
+ ATTR2_ALPHA := ((n) shl 12);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+type
+ TObjMode = (OBJMODE_NORMAL, OBJMODE_BLENDED, OBJMODE_WINDOWED, OBJMODE_BITMAP);
+ TObjShape = (OBJSHAPE_SQUARE, OBJSHAPE_WIDE, OBJSHAPE_TALL, OBJSHAPE_FORBIDDEN);
+ TObjSize = (OBJSIZE_8, OBJSIZE_16, OBJSIZE_32, OBJSIZE_64);
+ TObjColMode = (OBJCOLOR_16, OBJCOLOR_256);
+ TObjPriority = (OBJPRIORITY_0, OBJPRIORITY_1, OBJPRIORITY_2, OBJPRIORITY_3);
+
+ sSpriteEntry = packed record
+ case integer of
+ 0: (st1: packed record
+ st1: bitpacked record
+ posY: 0..8;
+ case integer of
+ 0: (st1: bitpacked record
+ __padding1: 0..1;
+ isHidden: 0..1;
+ __padding2: 0..6;
+ end;
+ );
+ 1: (st2: bitpacked record
+ isRotoscale: 0..1;
+ rsDouble: 0..1;
+ objMode: 0..2;
+ isMosaic: 0..1;
+ colMode: 0..1;
+ objShape: 0..2;
+ end;
+ );
+ end;
+ st2: bitpacked record
+ tileIdx: 0..10;
+ objPriority: 0..2;
+ objPal: 0..4;
+ end;
+ attribute3: cuint16;
+ case integer of
+ 0: (st1: bitpacked record
+ posX: 0..9;
+ __padding1: 0..7;
+ end;
+ );
+ 1: (st2: bitpacked record
+ __padding1: 0..8;
+ case integer of
+ 0: (st1: bitpacked record
+ __padding1: 0..4;
+ hFlip: 0..1;
+ vFlip: 0..1;
+ __padding2: 0..2;
+ end;
+ );
+ 1: (st2: bitpacked record
+ __padding1: 0..1;
+ rsMatrixIdx: 0..5;
+ objSize: 0..2;
+ end;
+ );
+ end;
+ );
+ end;
+ );
+ 1: (st: packed record
+ attribute: array [0..2] of cuint16;
+ filler: cuint16;
+ end;
+ );
+ end;
+ SpriteEntry = sSpriteEntry;
+ TSpriteEntry = sSpriteEntry;
+ PSpriteEntry = ^sSpriteEntry;
+
+
+ sSpriteRotation = record
+ filler1: array [0..2] of cuint16;
+ hdx: cint16;
+ filler2: array [0..2] of cuint16;
+ hdy: cint16;
+ filler3: array [0..2] of cuint16;
+ vdx: cint16;
+ filler4: array [0..2] of cuint16;
+ vdy: cint16;
+ end;
+ SpriteRotation = sSpriteRotation;
+ TSpriteRotation = sSpriteRotation;
+ pSpriteRotation = ^sSpriteRotation;
+
+
+const
+ SPRITE_COUNT = 128;
+ MATRIX_COUNT = 32;
+
+type
+ TOAM = record
+ case integer of
+ 0: (spriteBuffer: array [0..SPRITE_COUNT-1] of TSpriteEntry;);
+ 1: (matrixBuffer: array [0..MATRIX_COUNT-1] of TSpriteRotation;);
+ end;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function OBJ_Y(m: cint): cint; inline;
+function ATTR1_ROTDATA(n: cint): cint; inline;
+function OBJ_X(m: cint): cint; inline;
+function ATTR2_PRIORITY(n: cint): cint; inline;
+function ATTR2_PALETTE(n: cint): cint; inline;
+function ATTR2_ALPHA(n: cint): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/trig_lut.inc b/packages/libndsfpc/src/nds/arm9/trig_lut.inc
new file mode 100644
index 0000000000..a054f86f36
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/trig_lut.inc
@@ -0,0 +1,50 @@
+(*
+ $Id: trig_lut.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+var
+ COS_bin: array [0..0] of cshort; cvar; external;
+ SIN_bin: array [0..0] of cshort; cvar; external;
+ TAN_bin: array [0..0] of cshort; cvar; external;
+
+{$define _COS := COS_bin}
+{$define _SIN := SIN_bin}
+{$define _TAN := TAN_bin}
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/video.inc b/packages/libndsfpc/src/nds/arm9/video.inc
new file mode 100644
index 0000000000..9772a6949d
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/video.inc
@@ -0,0 +1,766 @@
+(*
+ $Id: video.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifndef ARM9}
+ {$error Video is only available on the ARM9}
+{$endif ARM9}
+
+{$ifdef NDS_IMPLEMENTATION}
+function RGB15(r, g, b: cint): cuint16;
+begin
+ RGB15 := ((r) or ((g) shl 5) or ((b) shl 10));
+end;
+
+function RGB5(r, g, b: cint): cuint16;
+begin
+ RGB5 := ((r) or ((g) shl 5) or ((b) shl 10));
+end;
+
+function RGB8(r, g, b: cint): cuint8;
+begin
+ RGB8 := (((r) shr 3) or (((g) shr 3) shl 5) or (((b) shr 3) shl 10));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ SCREEN_HEIGHT = 192;
+ SCREEN_WIDTH = 256;
+
+// Vram Control
+ VRAM_CR : pcuint32 = pointer($04000240);
+ VRAM_A_CR : pcuint8 = pointer($04000240);
+ VRAM_B_CR : pcuint8 = pointer($04000241);
+ VRAM_C_CR : pcuint8 = pointer($04000242);
+ VRAM_D_CR : pcuint8 = pointer($04000243);
+ VRAM_E_CR : pcuint8 = pointer($04000244);
+ VRAM_F_CR : pcuint8 = pointer($04000245);
+ VRAM_G_CR : pcuint8 = pointer($04000246);
+ WRAM_CR : pcuint8 = pointer($04000247);
+ VRAM_H_CR : pcuint8 = pointer($04000248);
+ VRAM_I_CR : pcuint8 = pointer($04000249);
+
+ VRAM_ENABLE = (1 shl 7);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function VRAM_OFFSET(n: cint): cint; inline;
+begin
+ VRAM_OFFSET := ((n) shl 3);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+type
+ VRAM_A_TYPE = cint;
+const
+ VRAM_A_LCD : VRAM_A_TYPE = 0;
+ VRAM_A_MAIN_BG : VRAM_A_TYPE = 1;
+ VRAM_A_MAIN_BG_0x06000000 : VRAM_A_TYPE = 1 or (0 shl 3);
+ VRAM_A_MAIN_BG_0x06020000 : VRAM_A_TYPE = 1 or (1 shl 3);
+ VRAM_A_MAIN_BG_0x06040000 : VRAM_A_TYPE = 1 or (2 shl 3);
+ VRAM_A_MAIN_BG_0x06060000 : VRAM_A_TYPE = 1 or (3 shl 3);
+ VRAM_A_MAIN_SPRITE : VRAM_A_TYPE = 2;
+ VRAM_A_MAIN_SPRITE_0x06400000 : VRAM_A_TYPE = 2;
+ VRAM_A_MAIN_SPRITE_0x06420000 : VRAM_A_TYPE = 2 or (1 shl 3);
+ VRAM_A_TEXTURE : VRAM_A_TYPE = 3;
+ VRAM_A_TEXTURE_SLOT0 : VRAM_A_TYPE = 3 or (0 shl 3);
+ VRAM_A_TEXTURE_SLOT1 : VRAM_A_TYPE = 3 or (1 shl 3);
+ VRAM_A_TEXTURE_SLOT2 : VRAM_A_TYPE = 3 or (2 shl 3);
+ VRAM_A_TEXTURE_SLOT3 : VRAM_A_TYPE = 3 or (3 shl 3);
+
+type
+ VRAM_B_TYPE = cint;
+const
+ VRAM_B_LCD : VRAM_B_TYPE = 0;
+ VRAM_B_MAIN_BG : VRAM_B_TYPE = 1 or (1 shl 3);
+ VRAM_B_MAIN_BG_0x06000000 : VRAM_B_TYPE = 1 or (0 shl 3);
+ VRAM_B_MAIN_BG_0x06020000 : VRAM_B_TYPE = 1 or (1 shl 3);
+ VRAM_B_MAIN_BG_0x06040000 : VRAM_B_TYPE = 1 or (2 shl 3);
+ VRAM_B_MAIN_BG_0x06060000 : VRAM_B_TYPE = 1 or (3 shl 3);
+ VRAM_B_MAIN_SPRITE : VRAM_B_TYPE = 2 or (1 shl 3);
+ VRAM_B_MAIN_SPRITE_0x06400000 : VRAM_B_TYPE = 2;
+ VRAM_B_MAIN_SPRITE_0x06420000 : VRAM_B_TYPE = 2 or (1 shl 3);
+ VRAM_B_TEXTURE : VRAM_B_TYPE = 3 or (1 shl 3);
+ VRAM_B_TEXTURE_SLOT0 : VRAM_B_TYPE = 3 or (0 shl 3);
+ VRAM_B_TEXTURE_SLOT1 : VRAM_B_TYPE = 3 or (1 shl 3);
+ VRAM_B_TEXTURE_SLOT2 : VRAM_B_TYPE = 3 or (2 shl 3);
+ VRAM_B_TEXTURE_SLOT3 : VRAM_B_TYPE = 3 or (3 shl 3);
+
+
+type
+ VRAM_C_TYPE = cint;
+const
+ VRAM_C_LCD : VRAM_C_TYPE = 0;
+ VRAM_C_MAIN_BG : VRAM_C_TYPE = 1 or (2 shl 3);
+ VRAM_C_MAIN_BG_0x06000000 : VRAM_C_TYPE = 1 or (0 shl 3);
+ VRAM_C_MAIN_BG_0x06020000 : VRAM_C_TYPE = 1 or (1 shl 3);
+ VRAM_C_MAIN_BG_0x06040000 : VRAM_C_TYPE = 1 or (2 shl 3);
+ VRAM_C_MAIN_BG_0x06060000 : VRAM_C_TYPE = 1 or (3 shl 3);
+ VRAM_C_ARM7 : VRAM_C_TYPE = 2;
+ VRAM_C_ARM7_0x06000000 : VRAM_C_TYPE = 2;
+ VRAM_C_ARM7_0x06020000 : VRAM_C_TYPE = 2 or (1 shl 3);
+ VRAM_C_SUB_BG : VRAM_C_TYPE = 4;
+ VRAM_C_SUB_BG_0x06200000 : VRAM_C_TYPE = 4 or (0 shl 3);
+ VRAM_C_SUB_BG_0x06220000 : VRAM_C_TYPE = 4 or (1 shl 3);
+ VRAM_C_SUB_BG_0x06240000 : VRAM_C_TYPE = 4 or (2 shl 3);
+ VRAM_C_SUB_BG_0x06260000 : VRAM_C_TYPE = 4 or (3 shl 3);
+ VRAM_C_TEXTURE : VRAM_C_TYPE = 3 or (2 shl 3);
+ VRAM_C_TEXTURE_SLOT0 : VRAM_C_TYPE = 3 or (0 shl 3);
+ VRAM_C_TEXTURE_SLOT1 : VRAM_C_TYPE = 3 or (1 shl 3);
+ VRAM_C_TEXTURE_SLOT2 : VRAM_C_TYPE = 3 or (2 shl 3);
+ VRAM_C_TEXTURE_SLOT3 : VRAM_C_TYPE = 3 or (3 shl 3);
+
+
+type
+ VRAM_D_TYPE = cint;
+const
+ VRAM_D_LCD : VRAM_D_TYPE = 0;
+ VRAM_D_MAIN_BG : VRAM_D_TYPE = 1 or (3 shl 3);
+ VRAM_D_MAIN_BG_0x06000000 : VRAM_D_TYPE = 1 or (0 shl 3);
+ VRAM_D_MAIN_BG_0x06020000 : VRAM_D_TYPE = 1 or (1 shl 3);
+ VRAM_D_MAIN_BG_0x06040000 : VRAM_D_TYPE = 1 or (2 shl 3);
+ VRAM_D_MAIN_BG_0x06060000 : VRAM_D_TYPE = 1 or (3 shl 3);
+ VRAM_D_ARM7 : VRAM_D_TYPE = 2 or (1 shl 3);
+ VRAM_D_ARM7_0x06000000 : VRAM_D_TYPE = 2;
+ VRAM_D_ARM7_0x06020000 : VRAM_D_TYPE = 2 or (1 shl 3);
+ VRAM_D_SUB_SPRITE : VRAM_D_TYPE = 4;
+ VRAM_D_TEXTURE : VRAM_D_TYPE = 3 or (3 shl 3);
+ VRAM_D_TEXTURE_SLOT0 : VRAM_D_TYPE = 3 or (0 shl 3);
+ VRAM_D_TEXTURE_SLOT1 : VRAM_D_TYPE = 3 or (1 shl 3);
+ VRAM_D_TEXTURE_SLOT2 : VRAM_D_TYPE = 3 or (2 shl 3);
+ VRAM_D_TEXTURE_SLOT3 : VRAM_D_TYPE = 3 or (3 shl 3);
+
+type
+ VRAM_E_TYPE = cint;
+const
+ VRAM_E_LCD : VRAM_E_TYPE = 0;
+ VRAM_E_MAIN_BG : VRAM_E_TYPE = 1;
+ VRAM_E_MAIN_SPRITE : VRAM_E_TYPE = 2;
+ VRAM_E_TEX_PALETTE : VRAM_E_TYPE = 3;
+ VRAM_E_BG_EXT_PALETTE : VRAM_E_TYPE = 4;
+ VRAM_E_OBJ_EXT_PALETTE : VRAM_E_TYPE = 5;
+
+type
+ VRAM_F_TYPE = cint;
+const
+ VRAM_F_LCD : VRAM_F_TYPE = 0;
+ VRAM_F_MAIN_BG : VRAM_F_TYPE = 1;
+ VRAM_F_MAIN_SPRITE : VRAM_F_TYPE = 2;
+ VRAM_F_MAIN_SPRITE_0x06000000 : VRAM_F_TYPE = 2;
+ VRAM_F_MAIN_SPRITE_0x06004000 : VRAM_F_TYPE = 2 or (1 shl 3);
+ VRAM_F_MAIN_SPRITE_0x06010000 : VRAM_F_TYPE = 2 or (2 shl 3);
+ VRAM_F_MAIN_SPRITE_0x06014000 : VRAM_F_TYPE = 2 or (3 shl 3);
+ VRAM_F_TEX_PALETTE : VRAM_F_TYPE = 3;
+ VRAM_F_BG_EXT_PALETTE : VRAM_F_TYPE = 4;
+ VRAM_F_OBJ_EXT_PALETTE : VRAM_F_TYPE = 5;
+
+type
+ VRAM_G_TYPE = cint;
+const
+ VRAM_G_LCD : VRAM_G_TYPE = 0;
+ VRAM_G_MAIN_BG : VRAM_G_TYPE = 1;
+ VRAM_G_MAIN_SPRITE : VRAM_G_TYPE = 2;
+ VRAM_G_MAIN_SPRITE_0x06000000 : VRAM_G_TYPE = 2;
+ VRAM_G_MAIN_SPRITE_0x06004000 : VRAM_G_TYPE = 2 or (1 shl 3);
+ VRAM_G_MAIN_SPRITE_0x06010000 : VRAM_G_TYPE = 2 or (2 shl 3);
+ VRAM_G_MAIN_SPRITE_0x06014000 : VRAM_G_TYPE = 2 or (3 shl 3);
+ VRAM_G_TEX_PALETTE : VRAM_G_TYPE = 3;
+ VRAM_G_BG_EXT_PALETTE : VRAM_G_TYPE = 4;
+ VRAM_G_OBJ_EXT_PALETTE : VRAM_G_TYPE = 5;
+
+type
+ VRAM_H_TYPE = cint;
+const
+ VRAM_H_LCD : VRAM_H_TYPE = 0;
+ VRAM_H_SUB_BG : VRAM_H_TYPE = 1;
+ VRAM_H_SUB_BG_EXT_PALETTE : VRAM_H_TYPE = 2;
+
+type
+ VRAM_I_TYPE = cint;
+const
+ VRAM_I_LCD : VRAM_I_TYPE = 0;
+ VRAM_I_SUB_BG : VRAM_I_TYPE = 1;
+ VRAM_I_SUB_SPRITE : VRAM_I_TYPE = 2;
+ VRAM_I_SUB_SPRITE_EXT_PALETTE : VRAM_I_TYPE = 3;
+
+type
+ TPalette = array [0..255] of cuint16;
+ TExtPalette = array [0..15] of TPalette;
+ PPalette = ^TPalette;
+ PExtPalette = ^TExtPalette;
+
+var
+ VRAM_E_EXT_PALETTE : PExtPalette absolute VRAM_E;
+ VRAM_F_EXT_PALETTE : PExtPalette absolute VRAM_F;
+ VRAM_G_EXT_PALETTE : PExtPalette absolute VRAM_G;
+ VRAM_H_EXT_PALETTE : PExtPalette absolute VRAM_H;
+
+function vramSetMainBanks(a: VRAM_A_TYPE; b: VRAM_B_TYPE; c: VRAM_C_TYPE; d: VRAM_D_TYPE): cuint32; cdecl; external;
+procedure vramRestoreMainBanks(vramTemp: cuint32); cdecl; external;
+
+procedure vramSetBankA(a: VRAM_A_TYPE); cdecl; external;
+procedure vramSetBankB(b: VRAM_B_TYPE); cdecl; external;
+procedure vramSetBankC(c: VRAM_C_TYPE); cdecl; external;
+procedure vramSetBankD(d: VRAM_D_TYPE); cdecl; external;
+procedure vramSetBankE(e: VRAM_E_TYPE); cdecl; external;
+procedure vramSetBankF(f: VRAM_F_TYPE); cdecl; external;
+procedure vramSetBankG(g: VRAM_G_TYPE); cdecl; external;
+procedure vramSetBankH(h: VRAM_H_TYPE); cdecl; external;
+procedure vramSetBankI(i: VRAM_I_TYPE); cdecl; external;
+
+
+// Display control registers
+const
+ DISPLAY_CR : pcuint32 = pointer($04000000);
+ SUB_DISPLAY_CR : pcuint32 = pointer($04001000);
+
+ MODE_0_2D = $10000;
+ MODE_1_2D = $10001;
+ MODE_2_2D = $10002;
+ MODE_3_2D = $10003;
+ MODE_4_2D = $10004;
+ MODE_5_2D = $10005;
+
+// main display only
+ MODE_6_2D = $10006;
+ MODE_FIFO = (3 shl 16);
+
+ ENABLE_3D = (1 shl 3);
+
+ DISPLAY_BG0_ACTIVE = (1 shl 8);
+ DISPLAY_BG1_ACTIVE = (1 shl 9);
+ DISPLAY_BG2_ACTIVE = (1 shl 10);
+ DISPLAY_BG3_ACTIVE = (1 shl 11);
+ DISPLAY_SPR_ACTIVE = (1 shl 12);
+ DISPLAY_WIN0_ON = (1 shl 13);
+ DISPLAY_WIN1_ON = (1 shl 14);
+ DISPLAY_SPR_WIN_ON = (1 shl 15);
+
+
+// Main display only
+ MODE_0_3D = (MODE_0_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_1_3D = (MODE_1_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_2_3D = (MODE_2_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_3_3D = (MODE_3_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_4_3D = (MODE_4_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_5_3D = (MODE_5_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+ MODE_6_3D = (MODE_6_2D or DISPLAY_BG0_ACTIVE or ENABLE_3D);
+
+ MODE_FB0 = ($00020000);
+ MODE_FB1 = ($00060000);
+ MODE_FB2 = ($000A0000);
+ MODE_FB3 = ($000E0000);
+
+ DISPLAY_SPR_HBLANK = (1 shl 23);
+
+ DISPLAY_SPR_1D_LAYOUT = (1 shl 4);
+
+ DISPLAY_SPR_1D = (1 shl 4);
+ DISPLAY_SPR_2D = (0 shl 4);
+ DISPLAY_SPR_1D_BMP = (4 shl 4);
+ DISPLAY_SPR_2D_BMP_128 = (0 shl 4);
+ DISPLAY_SPR_2D_BMP_256 = (2 shl 4);
+
+
+ DISPLAY_SPR_1D_SIZE_32 = (0 shl 20);
+ DISPLAY_SPR_1D_SIZE_64 = (1 shl 20);
+ DISPLAY_SPR_1D_SIZE_128 = (2 shl 20);
+ DISPLAY_SPR_1D_SIZE_256 = (3 shl 20);
+ DISPLAY_SPR_1D_BMP_SIZE_128 = (0 shl 22);
+ DISPLAY_SPR_1D_BMP_SIZE_256 = (1 shl 22);
+
+
+ DISPLAY_SPR_EXT_PALETTE = (1 shl 31);
+ DISPLAY_BG_EXT_PALETTE = (1 shl 30);
+
+ DISPLAY_SCREEN_OFF = (1 shl 7);
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+function DISPLAY_CHAR_BASE(n: cuint32): cuint32; inline;
+begin
+ DISPLAY_CHAR_BASE := ((n) and 7) shl 24;
+end;
+
+function DISPLAY_SCREEN_BASE(n: cuint32): cuint32; inline;
+begin
+ DISPLAY_SCREEN_BASE := ((n) and 7) shl 27;
+end;
+
+procedure videoSetMode(mode: cuint32); inline;
+begin
+ DISPLAY_CR^ := mode;
+end;
+
+procedure videoSetModeSub(mode: cuint32); inline;
+begin
+ SUB_DISPLAY_CR^ := mode;
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ BRIGHTNESS : pcuint16 = pointer($0400006C);
+ SUB_BRIGHTNESS : pcuint16 = pointer($0400106C);
+
+ BGCTRL : pcuint16 = pointer($04000008);
+ BG0_CR : pcuint16 = pointer($04000008);
+ BG1_CR : pcuint16 = pointer($0400000A);
+ BG2_CR : pcuint16 = pointer($0400000C);
+ BG3_CR : pcuint16 = pointer($0400000E);
+
+ BGCTRL_SUB : pcuint16 = pointer($04001008);
+ SUB_BG0_CR : pcuint16 = pointer($04001008);
+ SUB_BG1_CR : pcuint16 = pointer($0400100A);
+ SUB_BG2_CR : pcuint16 = pointer($0400100C);
+ SUB_BG3_CR : pcuint16 = pointer($0400100E);
+
+ BG_256_COLOR = (1 shl 7);
+ BG_16_COLOR = (0);
+
+ BG_MOSAIC_ON = (1 shl 6);
+ BG_MOSAIC_OFF = (0);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function BG_PRIORITY(n: cint): cint; inline;
+begin
+ BG_PRIORITY := (n);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ BG_PRIORITY_0 = (0);
+ BG_PRIORITY_1 = (1);
+ BG_PRIORITY_2 = (2);
+ BG_PRIORITY_3 = (3);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function BG_TILE_BASE(base: cint): cint; inline;
+begin
+ BG_TILE_BASE := ((base) shl 2);
+end;
+
+function BG_MAP_BASE(base: cint): cint; inline;
+begin
+ BG_MAP_BASE := ((base) shl 8);
+end;
+
+function BG_BMP_BASE(base: cint): cint; inline;
+begin
+ BG_BMP_BASE := ((base) shl 8);
+end;
+
+
+function BG_MAP_RAM(base: cint): cint; inline;
+begin
+ BG_MAP_RAM := (((base) * $800) + $06000000);
+end;
+
+function BG_MAP_RAM_SUB(base: cint): cint; inline;
+begin
+ BG_MAP_RAM_SUB := (((base) * $800) + $06200000);
+end;
+
+
+function BG_TILE_RAM(base: cint): cint; inline;
+begin
+ BG_TILE_RAM := (((base) * $4000) + $06000000);
+end;
+
+function BG_TILE_RAM_SUB(base: cint): cint; inline;
+begin
+ BG_TILE_RAM_SUB := (((base) * $4000) + $06200000);
+end;
+
+
+function BG_BMP_RAM(base: cint): cint; inline;
+begin
+ BG_BMP_RAM := (((base) * $4000) + $06000000);
+end;
+
+function BG_BMP_RAM_SUB(base: cint): cint; inline;
+begin
+ BG_BMP_RAM_SUB := (((base) * $4000) + $06200000);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ BG_WRAP_OFF = (0);
+ BG_WRAP_ON = (1 shl 13);
+
+ BG_32x32 = (0 shl 14);
+ BG_64x32 = (1 shl 14);
+ BG_32x64 = (2 shl 14);
+ BG_64x64 = (3 shl 14);
+
+ BG_RS_16x16 = (0 shl 14);
+ BG_RS_32x32 = (1 shl 14);
+ BG_RS_64x64 = (2 shl 14);
+ BG_RS_128x128 = (3 shl 14);
+
+ BG_BMP8_128x128 = (BG_RS_16x16 or BG_256_COLOR);
+ BG_BMP8_256x256 = (BG_RS_32x32 or BG_256_COLOR);
+ BG_BMP8_512x256 = (BG_RS_64x64 or BG_256_COLOR);
+ BG_BMP8_512x512 = (BG_RS_128x128 or BG_256_COLOR);
+ BG_BMP8_1024x512 = (1 shl 14);
+ BG_BMP8_512x1024 = 0;
+
+ BG_BMP16_128x128 = (BG_RS_16x16 or BG_256_COLOR or (1 shl 2));
+ BG_BMP16_256x256 = (BG_RS_32x32 or BG_256_COLOR or (1 shl 2));
+ BG_BMP16_512x256 = (BG_RS_64x64 or BG_256_COLOR or (1 shl 2));
+ BG_BMP16_512x512 = (BG_RS_128x128 or BG_256_COLOR or (1 shl 2));
+
+ BG_PALETTE_SLOT0 = 0;
+ BG_PALETTE_SLOT1 = 0;
+ BG_PALETTE_SLOT2 = (1 shl 13);
+ BG_PALETTE_SLOT3 = (1 shl 13);
+
+type
+ bg_scroll = record
+ x: cuint16;
+ y: cuint16;
+ end;
+ Tbg_scroll = bg_scroll;
+ Pbg_scroll = ^bg_scroll;
+
+ bg_rotation = record
+ xdx: cuint16;
+ xdy: cuint16;
+ ydx: cuint16;
+ ydy: cuint16;
+ centerX: cuint32;
+ centerY: cuint32;
+ end;
+ Tbg_rotation = bg_rotation;
+ Pbg_rotation = ^bg_rotation;
+
+ bg_attribute = record
+ control: array [0..3] of cuint16;
+ scroll: array [0..3] of bg_scroll;
+ bg2_rotation: bg_rotation;
+ bg3_rotation: bg_rotation;
+ end;
+ Tbg_attribute = bg_attribute;
+ Pbg_attribute = ^bg_attribute;
+
+
+const
+ BACKGROUND : Pbg_attribute = pointer($04000008);
+ BACKGROUND_SUB : Pbg_attribute = pointer($04001008);
+
+ BG_OFFSET : Pbg_scroll = pointer($04000010);
+
+ BG0_X0 : pcuint16 = pointer($04000010);
+ BG0_Y0 : pcuint16 = pointer($04000012);
+ BG1_X0 : pcuint16 = pointer($04000014);
+ BG1_Y0 : pcuint16 = pointer($04000016);
+ BG2_X0 : pcuint16 = pointer($04000018);
+ BG2_Y0 : pcuint16 = pointer($0400001A);
+ BG3_X0 : pcuint16 = pointer($0400001C);
+ BG3_Y0 : pcuint16 = pointer($0400001E);
+
+ BG2_XDX : pcuint16 = pointer($04000020);
+ BG2_XDY : pcuint16 = pointer($04000022);
+ BG2_YDX : pcuint16 = pointer($04000024);
+ BG2_YDY : pcuint16 = pointer($04000026);
+ BG2_CX : pcuint32 = pointer($04000028);
+ BG2_CY : pcuint32 = pointer($0400002C);
+
+ BG3_XDX : pcuint16 = pointer($04000030);
+ BG3_XDY : pcuint16 = pointer($04000032);
+ BG3_YDX : pcuint16 = pointer($04000034);
+ BG3_YDY : pcuint16 = pointer($04000036);
+ BG3_CX : pcuint32 = pointer($04000038);
+ BG3_CY : pcuint32 = pointer($0400003C);
+
+ SUB_BG0_X0 : pcuint16 = pointer($04001010);
+ SUB_BG0_Y0 : pcuint16 = pointer($04001012);
+ SUB_BG1_X0 : pcuint16 = pointer($04001014);
+ SUB_BG1_Y0 : pcuint16 = pointer($04001016);
+ SUB_BG2_X0 : pcuint16 = pointer($04001018);
+ SUB_BG2_Y0 : pcuint16 = pointer($0400101A);
+ SUB_BG3_X0 : pcuint16 = pointer($0400101C);
+ SUB_BG3_Y0 : pcuint16 = pointer($0400101E);
+
+ SUB_BG2_XDX : pcuint16 = pointer($04001020);
+ SUB_BG2_XDY : pcuint16 = pointer($04001022);
+ SUB_BG2_YDX : pcuint16 = pointer($04001024);
+ SUB_BG2_YDY : pcuint16 = pointer($04001026);
+ SUB_BG2_CX : pcuint32 = pointer($04001028);
+ SUB_BG2_CY : pcuint32 = pointer($0400102C);
+
+ SUB_BG3_XDX : pcuint16 = pointer($04001030);
+ SUB_BG3_XDY : pcuint16 = pointer($04001032);
+ SUB_BG3_YDX : pcuint16 = pointer($04001034);
+ SUB_BG3_YDY : pcuint16 = pointer($04001036);
+ SUB_BG3_CX : pcuint32 = pointer($04001038);
+ SUB_BG3_CY : pcuint32 = pointer($0400103C);
+
+// Window 0
+ WIN0_X0 : pcuint8 = pointer($04000041);
+ WIN0_X1 : pcuint8 = pointer($04000040);
+ WIN0_Y0 : pcuint8 = pointer($04000045);
+ WIN0_Y1 : pcuint8 = pointer($04000044);
+
+// Window 1
+ WIN1_X0 : pcuint8 = pointer($04000042);
+ WIN1_X1 : pcuint8 = pointer($04000043);
+ WIN1_Y0 : pcuint8 = pointer($04000047);
+ WIN1_Y1 : pcuint8 = pointer($04000046);
+
+ WIN_IN : pcuint16 = pointer($04000048);
+ WIN_OUT : pcuint16 = pointer($0400004A);
+
+// Window 0
+ SUB_WIN0_X0 : pcuint8 = pointer($04001041);
+ SUB_WIN0_X1 : pcuint8 = pointer($04001040);
+ SUB_WIN0_Y0 : pcuint8 = pointer($04001045);
+ SUB_WIN0_Y1 : pcuint8 = pointer($04001044);
+
+// Window 1
+ SUB_WIN1_X0 : pcuint8 = pointer($04001042);
+ SUB_WIN1_X1 : pcuint8 = pointer($04001043);
+ SUB_WIN1_Y0 : pcuint8 = pointer($04001047);
+ SUB_WIN1_Y1 : pcuint8 = pointer($04001046);
+
+ SUB_WIN_IN : pcuint16 = pointer($04001048);
+ SUB_WIN_OUT : pcuint16 = pointer($0400104A);
+
+ MOSAIC_CR : pcuint16 = pointer($0400004C);
+ SUB_MOSAIC_CR : pcuint16 = pointer($0400104C);
+
+ BLEND_CR : pcuint16 = pointer($04000050);
+ BLEND_AB : pcuint16 = pointer($04000052);
+ BLEND_Y : pcuint16 = pointer($04000054);
+
+ SUB_BLEND_CR : pcuint16 = pointer($04001050);
+ SUB_BLEND_AB : pcuint16 = pointer($04001052);
+ SUB_BLEND_Y : pcuint16 = pointer($04001054);
+
+ BLEND_NONE = (0 shl 6);
+ BLEND_ALPHA = (1 shl 6);
+ BLEND_FADE_WHITE = (2 shl 6);
+ BLEND_FADE_BLACK = (3 shl 6);
+
+ BLEND_SRC_BG0 = (1 shl 0);
+ BLEND_SRC_BG1 = (1 shl 1);
+ BLEND_SRC_BG2 = (1 shl 2);
+ BLEND_SRC_BG3 = (1 shl 3);
+ BLEND_SRC_SPRITE = (1 shl 4);
+ BLEND_SRC_BACKDROP = (1 shl 5);
+
+ BLEND_DST_BG0 = (1 shl 8);
+ BLEND_DST_BG1 = (1 shl 9);
+ BLEND_DST_BG2 = (1 shl 10);
+ BLEND_DST_BG3 = (1 shl 11);
+ BLEND_DST_SPRITE = (1 shl 12);
+ BLEND_DST_BACKDROP = (1 shl 13);
+
+// Display capture control
+
+ REG_DISPCAPCNT: pcuint32 = pointer($04000064);
+ REG_DISP_MMEM_FIFO: pcuint32 = pointer($04000068);
+
+ DCAP_ENABLE = (1 shl 31);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function DCAP_MODE(n: cint): cint; inline;
+begin
+ DCAP_MODE := (((n) and 3) shl 29);
+end;
+
+function DCAP_DST(n: cint): cint; inline;
+begin
+ DCAP_DST := (((n) and 3) shl 26);
+end;
+
+function DCAP_SRC(n: cint): cint; inline;
+begin
+ DCAP_SRC := (((n) and 3) shl 24);
+end;
+
+function DCAP_SIZE(n: cint): cint; inline;
+begin
+ DCAP_SIZE := (((n) and 3) shl 20);
+end;
+
+function DCAP_OFFSET(n: cint): cint; inline;
+begin
+ DCAP_OFFSET := (((n) and 3) shl 18);
+end;
+
+function DCAP_BANK(n: cint): cint; inline;
+begin
+ DCAP_BANK := (((n) and 3) shl 16);
+end;
+
+function DCAP_B(n: cint): cint; inline;
+begin
+ DCAP_B := (((n) and $1F) shl 8);
+end;
+
+function DCAP_A(n: cint): cint; inline;
+begin
+ DCAP_A := (((n) and $1F) shl 0);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+// 3D core control
+const
+ GFX_CONTROL : pcuint16 = pointer($04000060);
+
+ GFX_FIFO : pcuint32 = pointer($04000400);
+ GFX_STATUS : pcuint32 = pointer($04000600);
+ GFX_COLOR : pcuint32 = pointer($04000480);
+
+ GFX_VERTEX10 : pcuint32 = pointer($04000490);
+ GFX_VERTEX_XY : pcuint32 = pointer($04000494);
+ GFX_VERTEX_XZ : pcuint32 = pointer($04000498);
+ GFX_VERTEX_YZ : pcuint32 = pointer($0400049C);
+ GFX_VERTEX_DIFF : pcuint32 = pointer($040004A0);
+
+ GFX_VERTEX16 : pcuint32 = pointer($0400048C);
+ GFX_TEX_COORD : pcuint32 = pointer($04000488);
+ GFX_TEX_FORMAT : pcuint32 = pointer($040004A8);
+ GFX_PAL_FORMAT : pcuint32 = pointer($040004AC);
+
+ GFX_CLEAR_COLOR : pcuint32 = pointer($04000350);
+ GFX_CLEAR_DEPTH : pcuint16 = pointer($04000354);
+
+ GFX_LIGHT_VECTOR : pcuint32 = pointer($040004C8);
+ GFX_LIGHT_COLOR : pcuint32 = pointer($040004CC);
+ GFX_NORMAL : pcuint32 = pointer($04000484);
+
+ GFX_DIFFUSE_AMBIENT : pcuint32 = pointer($040004C0);
+ GFX_SPECULAR_EMISSION : pcuint32 = pointer($040004C4);
+ GFX_SHININESS : pcuint32 = pointer($040004D0);
+
+ GFX_POLY_FORMAT : pcuint32 = pointer($040004A4);
+ GFX_ALPHA_TEST : pcuint16 = pointer($04000340);
+
+ GFX_BEGIN : pcuint32 = pointer($04000500);
+ GFX_END : pcuint32 = pointer($04000504);
+ GFX_FLUSH : pcuint32 = pointer($04000540);
+ GFX_VIEWPORT : pcuint32 = pointer($04000580);
+ GFX_TOON_TABLE : pcuint16 = pointer($04000380);
+ GFX_EDGE_TABLE : pcuint16 = pointer($04000330);
+ GFX_FOG_COLOR : pcuint32 = pointer($04000358);
+ GFX_FOG_OFFSET : pcuint32 = pointer($0400035C);
+ GFX_FOG_TABLE : pcuint8 = pointer($04000360);
+ GFX_BOX_TEST : pcint32 = pointer($040005C0);
+ GFX_POS_TEST : pcint32 = pointer($040005C4);
+ GFX_POS_RESULT : pcint32 = pointer($04000620);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function GFX_BUSY: boolean; inline;
+begin
+ GFX_BUSY := GFX_STATUS^ and (1 shl 27) <> 0;
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+const
+ GFX_VERTEX_RAM_USAGE : pcuint16 = pointer($04000606);
+ GFX_POLYGON_RAM_USAGE : pcuint16 = pointer($04000604);
+
+ GFX_CUTOFF_DEPTH : pcuint16 = pointer($04000610);
+
+// Matrix processor control
+
+ MATRIX_CONTROL : pcuint32 = pointer($04000440);
+ MATRIX_PUSH : pcuint32 = pointer($04000444);
+ MATRIX_POP : pcuint32 = pointer($04000448);
+ MATRIX_SCALE : pcint32 = pointer($0400046C);
+ MATRIX_TRANSLATE : pcint32 = pointer($04000470);
+ MATRIX_RESTORE : pcuint32 = pointer($04000450);
+ MATRIX_STORE : pcuint32 = pointer($0400044C);
+ MATRIX_IDENTITY : pcuint32 = pointer($04000454);
+ MATRIX_LOAD4x4 : pcint32 = pointer($04000458);
+ MATRIX_LOAD4x3 : pcint32 = pointer($0400045C);
+ MATRIX_MULT4x4 : pcint32 = pointer($04000460);
+ MATRIX_MULT4x3 : pcint32 = pointer($04000464);
+ MATRIX_MULT3x3 : pcint32 = pointer($04000468);
+
+//matrix operation results
+ MATRIX_READ_CLIP : pcint32 = pointer($04000640);
+ MATRIX_READ_VECTOR : pcint32 = pointer($04000680);
+ POINT_RESULT : pcint32 = pointer($04000620);
+ VECTOR_RESULT : pcuint16 = pointer($04000630);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function RGB15(r, g, b: cint): cuint16;
+function RGB5(r, g, b: cint): cuint16;
+function RGB8(r, g, b: cint): cuint8;
+function VRAM_OFFSET(n: cint): cint; inline;
+function DISPLAY_CHAR_BASE(n: cuint32): cuint32; inline;
+function DISPLAY_SCREEN_BASE(n: cuint32): cuint32; inline;
+procedure videoSetMode(mode: cuint32); inline;
+procedure videoSetModeSub(mode: cuint32); inline;
+function BG_PRIORITY(n: cint): cint; inline;
+function BG_TILE_BASE(base: cint): cint; inline;
+function BG_MAP_BASE(base: cint): cint; inline;
+function BG_BMP_BASE(base: cint): cint; inline;
+function BG_MAP_RAM(base: cint): cint; inline;
+function BG_MAP_RAM_SUB(base: cint): cint; inline;
+function BG_TILE_RAM(base: cint): cint; inline;
+function BG_TILE_RAM_SUB(base: cint): cint; inline;
+function BG_BMP_RAM(base: cint): cint; inline;
+function BG_BMP_RAM_SUB(base: cint): cint; inline;
+function DCAP_MODE(n: cint): cint; inline;
+function DCAP_DST(n: cint): cint; inline;
+function DCAP_SRC(n: cint): cint; inline;
+function DCAP_SIZE(n: cint): cint; inline;
+function DCAP_OFFSET(n: cint): cint; inline;
+function DCAP_BANK(n: cint): cint; inline;
+function DCAP_B(n: cint): cint; inline;
+function DCAP_A(n: cint): cint; inline;
+function GFX_BUSY: boolean; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/arm9/videoGL.inc b/packages/libndsfpc/src/nds/arm9/videoGL.inc
new file mode 100644
index 0000000000..e7bed53055
--- /dev/null
+++ b/packages/libndsfpc/src/nds/arm9/videoGL.inc
@@ -0,0 +1,1440 @@
+(*
+ $Id: videoGL.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+{$ifndef ARM9}
+ {$error 3D hardware is only available from the ARM9}
+{$endif}
+
+
+{$ifdef NDS_INTERFACE}
+(*---------------------------------------------------------------------------------
+ lut resolution for trig functions
+ (must be power of two and must be the same as LUT resolution)
+ in other words dont change unless you also change your LUTs
+---------------------------------------------------------------------------------*)
+const
+ LUT_SIZE = (512);
+ LUT_MASK = ($1FF);
+
+type
+ GLuint = cuint32;
+ GLfloat = cfloat;
+
+//////////////////////////////////////////////////////////////////////
+// Fixed point / floating point / integer conversion macros
+//////////////////////////////////////////////////////////////////////
+
+ fixed12d3 = cuint16 ;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function int_to_12d3(n: cint): fixed12d3; inline;
+begin
+ int_to_12d3 := fixed12d3(n shl 3);
+end;
+
+function float_to_12d3(n: cfloat): fixed12d3; inline;
+begin
+ float_to_12d3 := fixed12d3(trunc( n * (1 shl 3)));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ GL_MAX_DEPTH = $7FFF;
+{$endif NDS_INTERFACE}
+
+//////////////////////////////////////////////////////////////////////
+
+{$ifdef NDS_IMPLEMENTATION}
+function inttof32(n: cint): cint32; inline;
+begin
+ inttof32 := ((n) shl 12);
+end;
+
+function f32toint(n: cint32): cint; inline;
+begin
+ f32toint := ((n) shr 12);
+end;
+
+function floattof32(n: cfloat): cint32; inline;
+begin
+ floattof32 := trunc((n) * (1 shl 12));
+end;
+
+// check it!
+function f32tofloat(n: cint32): cfloat; inline;
+begin
+ f32tofloat := (n * 1.0) / ((1 shl 12) * 1.0);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+type
+ t16 = cint16; // text coordinate 12.4 fixed point (or cint?)
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function f32tot16(n: cint32): t16; inline;
+begin
+ f32tot16 := t16(n shr 8);
+end;
+
+function inttot16(n: cint): cint32; inline; //???
+begin
+ inttot16 := (n shl 4);
+end;
+
+function t16toint(n: t16): cint; inline;
+begin
+ t16toint := cint((n) shr 4);
+end;
+
+function floattot16(n: cfloat): t16; inline;
+begin
+ floattot16 := t16(trunc(n * (1 shl 4)));
+end;
+
+function TEXTURE_PACK(u, v: cint): cint; inline;
+begin
+ TEXTURE_PACK := (u and $FFFF) or (v shl 16);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+type
+ v16 = cuint16; // vertex 4.12 fixed format
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function inttov16(n: cint): cint; inline;
+begin
+ inttov16 := (n shl 12);
+end;
+
+function f32tov16(n: cint32): v16; inline;
+begin
+ f32tov16 := v16(n);
+end;
+
+function v16toint(n: v16): cint; inline;
+begin
+ v16toint := cint((n) shr 12);
+end;
+
+function floattov16(n: cfloat): v16; inline;
+begin
+ floattov16 := v16(trunc(n * (1 shl 12)));
+end;
+
+function VERTEX_PACK(x,y: cint): cint; inline;
+begin
+ VERTEX_PACK := (x and $FFFF) or (y shl 16);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+type
+ v10 = cint16;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function inttov10(n: cint): cint; inline;
+begin
+ inttov10 := ((n) shl 9);
+end;
+
+function f32tov10(n: cint32): cint; inline;
+begin
+ f32tov10 := (n shr 3);
+end;
+
+function v10toint(n: v10): cint; inline;
+begin
+ v10toint := cint((n) shr 9);
+end;
+
+function floattov10(n: cfloat): v10; inline;
+begin
+ if n > 0.998 then
+ floattov10 := v10($1FF)
+ else
+ floattov10 := trunc(n * (1 shl 9));
+end;
+
+function NORMAL_PACK(x,y,z: cint): cint; inline;
+begin
+ NORMAL_PACK := ((x and $3FF) or ((y and $3FF) shl 10) or (z shl 20));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+type
+ rgb = cushort;
+
+ m3x3 = record
+ m: array [0..8] of cint32;
+ end;
+ pm3x3 = ^m3x3;
+
+ m4x4 = record
+ m: array [0..15] of cint32;
+ end;
+ pm4x4 = ^m4x4;
+
+ m4x3 = record
+ m: array [0..11] of cint32;
+ end;
+ pm4x3 = ^m4x3;
+
+ GLvector = record
+ x,y,z: cint32;
+ end;
+ PGLvector= ^GLvector;
+
+//////////////////////////////////////////////////////////////////////
+
+const
+ GL_FALSE = 0;
+ GL_TRUE = 1;
+
+//////////////////////////////////////////////////////////////////////
+// glBegin constants
+//////////////////////////////////////////////////////////////////////
+type
+ GL_GLBEGIN_ENUM = cint32;
+const
+ GL_TRIANGLES : GL_GLBEGIN_ENUM = 0;
+ GL_QUADS : GL_GLBEGIN_ENUM = 1;
+ GL_TRIANGLE_STRIP : GL_GLBEGIN_ENUM = 2;
+ GL_QUAD_STRIP : GL_GLBEGIN_ENUM = 3;
+ GL_TRIANGLE : GL_GLBEGIN_ENUM = 0;
+ GL_QUAD : GL_GLBEGIN_ENUM = 1;
+
+//////////////////////////////////////////////////////////////////////
+// glMatrixMode constants
+//////////////////////////////////////////////////////////////////////
+type
+ GL_MATRIX_MODE_ENUM = cint32;
+const
+ GL_PROJECTION : GL_MATRIX_MODE_ENUM = 0;
+ GL_POSITION : GL_MATRIX_MODE_ENUM = 1;
+ GL_MODELVIEW : GL_MATRIX_MODE_ENUM = 2;
+ GL_TEXTURE : GL_MATRIX_MODE_ENUM = 3;
+
+//////////////////////////////////////////////////////////////////////
+// glMaterialf constants
+//////////////////////////////////////////////////////////////////////
+type
+ GL_MATERIALS_ENUM = cint32;
+const
+ GL_AMBIENT : GL_MATERIALS_ENUM = $01;
+ GL_DIFFUSE : GL_MATERIALS_ENUM = $02;
+ GL_AMBIENT_AND_DIFFUSE : GL_MATERIALS_ENUM = $03;
+ GL_SPECULAR : GL_MATERIALS_ENUM = $04;
+ GL_SHININESS : GL_MATERIALS_ENUM = $08;
+ GL_EMISSION : GL_MATERIALS_ENUM = $10;
+
+////////////////////////////////////////////////////////////
+// glPolyFmt constants
+////////////////////////////////////////////////////////////
+type
+ GL_POLY_FORMAT_ENUM = cint32;
+const
+ POLY_DECAL : GL_POLY_FORMAT_ENUM = (1 shl 4);
+ POLY_TOON_SHADING : GL_POLY_FORMAT_ENUM = (1 shl 5);
+ POLY_CULL_BACK : GL_POLY_FORMAT_ENUM = (1 shl 7);
+ POLY_CULL_FRONT : GL_POLY_FORMAT_ENUM = (1 shl 6);
+ POLY_CULL_NONE : GL_POLY_FORMAT_ENUM = (3 shl 6);
+ POLY_FORMAT_LIGHT0 : GL_POLY_FORMAT_ENUM = (1 shl 0);
+ POLY_FORMAT_LIGHT1 : GL_POLY_FORMAT_ENUM = (1 shl 1);
+ POLY_FORMAT_LIGHT2 : GL_POLY_FORMAT_ENUM = (1 shl 2);
+ POLY_FORMAT_LIGHT3 : GL_POLY_FORMAT_ENUM = (1 shl 3);
+
+
+
+
+////////////////////////////////////////////////////////////
+// glTexImage2d constants
+////////////////////////////////////////////////////////////
+type
+ GL_TEXTURE_SIZE_ENUM = cint32;
+const
+ TEXTURE_SIZE_8 : GL_TEXTURE_SIZE_ENUM = 0;
+ TEXTURE_SIZE_16 : GL_TEXTURE_SIZE_ENUM = 1;
+ TEXTURE_SIZE_32 : GL_TEXTURE_SIZE_ENUM = 2;
+ TEXTURE_SIZE_64 : GL_TEXTURE_SIZE_ENUM = 3;
+ TEXTURE_SIZE_128 : GL_TEXTURE_SIZE_ENUM = 4;
+ TEXTURE_SIZE_256 : GL_TEXTURE_SIZE_ENUM = 5;
+ TEXTURE_SIZE_512 : GL_TEXTURE_SIZE_ENUM = 6;
+ TEXTURE_SIZE_1024 : GL_TEXTURE_SIZE_ENUM = 7;
+
+type
+ GL_TEXTURE_PARAM_ENUM = cuint32;
+const
+ GL_TEXTURE_WRAP_S : GL_TEXTURE_PARAM_ENUM = (1 shl 16);
+ GL_TEXTURE_WRAP_T : GL_TEXTURE_PARAM_ENUM = (1 shl 17);
+ GL_TEXTURE_FLIP_S : GL_TEXTURE_PARAM_ENUM = (1 shl 18);
+ GL_TEXTURE_FLIP_T : GL_TEXTURE_PARAM_ENUM = (1 shl 19);
+ GL_TEXTURE_COLOR0_TRANSPARENT : GL_TEXTURE_PARAM_ENUM = (1 shl 29);
+ GL_TEXTURE_ALPHA_MASK : GL_TEXTURE_PARAM_ENUM = (1 shl 29);
+ TEXGEN_OFF : GL_TEXTURE_PARAM_ENUM = (0 shl 30);
+ TEXGEN_TEXCOORD : GL_TEXTURE_PARAM_ENUM = (1 shl 30);
+ TEXGEN_NORMAL : GL_TEXTURE_PARAM_ENUM = (2 shl 30);
+ TEXGEN_POSITION : GL_TEXTURE_PARAM_ENUM = (3 shl 30);
+
+
+type
+ GL_TEXTURE_TYPE_ENUM = cint32;
+const
+ GL_RGB32_A3 : GL_TEXTURE_TYPE_ENUM = 1;
+ GL_RGB4 : GL_TEXTURE_TYPE_ENUM = 2;
+ GL_RGB16 : GL_TEXTURE_TYPE_ENUM = 3;
+ GL_RGB256 : GL_TEXTURE_TYPE_ENUM = 4;
+ GL_COMPRESSED : GL_TEXTURE_TYPE_ENUM = 5;
+ GL_RGB8_A5 : GL_TEXTURE_TYPE_ENUM = 6;
+ GL_RGBA : GL_TEXTURE_TYPE_ENUM = 7;
+ GL_RGB : GL_TEXTURE_TYPE_ENUM = 8;
+
+
+
+type
+ DISP3DCNT_ENUM = cint32;
+const
+ GL_TEXTURE_2D : DISP3DCNT_ENUM = (1 shl 0);
+ GL_TOON_HIGHLIGHT : DISP3DCNT_ENUM = (1 shl 1);
+ GL_ALPHA_TEST : DISP3DCNT_ENUM = (1 shl 2);
+ GL_BLEND : DISP3DCNT_ENUM = (1 shl 3);
+ GL_ANTIALIAS : DISP3DCNT_ENUM = (1 shl 4);
+ GL_OUTLINE : DISP3DCNT_ENUM = (1 shl 5);
+ GL_COLOR_UNDERFLOW : DISP3DCNT_ENUM = (1 shl 12);
+ GL_POLY_OVERFLOW : DISP3DCNT_ENUM = (1 shl 13);
+ GL_CLEAR_BMP : DISP3DCNT_ENUM = (1 shl 14);
+
+
+////////////////////////////////////////////////////////////
+// glGet constants
+////////////////////////////////////////////////////////////
+
+type
+ GL_GET_ENUM = (
+ GL_GET_VERTEX_RAM_COUNT,
+ GL_GET_POLYGON_RAM_COUNT,
+ GL_GET_MATRIX_VECTOR,
+ GL_GET_MATRIX_POSITION,
+ GL_GET_MATRIX_PROJECTION,
+ GL_GET_MATRIX_CLIP,
+ GL_GET_TEXTURE_WIDTH,
+ GL_GET_TEXTURE_HEIGHT
+ );
+
+
+type
+ GLFLUSH_ENUM = cint32;
+const
+ GL_TRANS_MANUALSORT: GLFLUSH_ENUM = (1 shl 0);
+ GL_WBUFFERING : GLFLUSH_ENUM = (1 shl 1);
+
+////////////////////////////////////////////////////////////
+// Misc. constants
+////////////////////////////////////////////////////////////
+
+const
+ MAX_TEXTURES = 2048; //this should be enough ! but feel free to change
+ GL_LIGHTING = 1; // no idea what this is for / who defined it
+
+type
+ gl_hidden_globals = record
+ matrixMode: GL_MATRIX_MODE_ENUM; // holds the current Matrix Mode
+ // holds the current state of the clear color register
+ clearColor: cuint32; // state of clear color register
+ // texture globals
+ textures: array [0..MAX_TEXTURES-1] of cuint32;
+ activeTexture: cuint32;
+ nextBlock: pcuint32;
+ nextPBlock: cuint32;
+ nameCount: cint;
+ end;
+ TGLHiddenGlobals = gl_hidden_globals;
+ PGLHiddenGlobals = ^gl_hidden_globals;
+
+var
+ // Pointer to global data for videoGL
+ glGlob: PGLHiddenGlobals = nil;
+
+
+
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+//---------------------------------------------------------------------------------
+//Fifo commands
+//---------------------------------------------------------------------------------
+function FIFO_COMMAND_PACK(c1,c2,c3,c4: cint): cint; inline;
+begin
+ FIFO_COMMAND_PACK := (((c4) shl 24) or ((c3) shl 16) or ((c2) shl 8) or (c1));
+end;
+
+function REG2ID(r: pcuint32): cuint8; inline;
+begin
+ REG2ID := cuint8((cuint32(r) - $04000400) shr 2);
+end;
+
+function FIFO_NOP(): cuint8; inline;
+begin
+ FIFO_NOP := REG2ID(GFX_FIFO);
+end;
+
+function FIFO_STATUS(): cuint8; inline;
+begin
+ FIFO_STATUS := REG2ID(GFX_STATUS);
+end;
+
+function FIFO_COLOR(): cuint8; inline;
+begin
+ FIFO_COLOR := REG2ID(GFX_COLOR);
+end;
+
+
+function FIFO_VERTEX16(): cuint8; inline;
+begin
+ FIFO_VERTEX16 := REG2ID(GFX_VERTEX16);
+end;
+
+function FIFO_TEX_COORD(): cuint8; inline;
+begin
+ FIFO_TEX_COORD := REG2ID(GFX_TEX_COORD);
+end;
+
+function FIFO_TEX_FORMAT(): cuint8; inline;
+begin
+ FIFO_TEX_FORMAT := REG2ID(GFX_TEX_FORMAT);
+end;
+
+function FIFO_PAL_FORMAT(): cuint8; inline;
+begin
+ FIFO_PAL_FORMAT := REG2ID(GFX_PAL_FORMAT);
+end;
+
+
+function FIFO_CLEAR_COLOR(): cuint8; inline;
+begin
+ FIFO_CLEAR_COLOR := REG2ID(GFX_CLEAR_COLOR);
+end;
+
+function FIFO_CLEAR_DEPTH(): cuint8; inline;
+begin
+ FIFO_CLEAR_DEPTH := REG2ID(pcuint32(GFX_CLEAR_DEPTH));
+end;
+
+
+function FIFO_LIGHT_VECTOR(): cuint8; inline;
+begin
+ FIFO_LIGHT_VECTOR := REG2ID(GFX_LIGHT_VECTOR);
+end;
+
+function FIFO_LIGHT_COLOR(): cuint8; inline;
+begin
+ FIFO_LIGHT_COLOR := REG2ID(GFX_LIGHT_COLOR);
+end;
+
+function FIFO_NORMAL(): cuint8; inline;
+begin
+ FIFO_NORMAL := REG2ID(GFX_NORMAL);
+end;
+
+function FIFO_DIFFUSE_AMBIENT(): cuint8; inline;
+begin
+ FIFO_DIFFUSE_AMBIENT := REG2ID(GFX_DIFFUSE_AMBIENT);
+end;
+
+function FIFO_SPECULAR_EMISSION(): cuint8; inline;
+begin
+ FIFO_SPECULAR_EMISSION := REG2ID(GFX_SPECULAR_EMISSION);
+end;
+
+function FIFO_SHININESS(): cuint8; inline;
+begin
+ FIFO_SHININESS := REG2ID(GFX_SHININESS);
+end;
+
+
+function FIFO_POLY_FORMAT(): cuint8; inline;
+begin
+ FIFO_POLY_FORMAT := REG2ID(GFX_POLY_FORMAT);
+end;
+
+
+function FIFO_BEGIN(): cuint8; inline;
+begin
+ FIFO_BEGIN := REG2ID(GFX_BEGIN);
+end;
+
+function FIFO_END(): cuint8; inline;
+begin
+ FIFO_END := REG2ID(GFX_END);
+end;
+
+function FIFO_FLUSH(): cuint8; inline;
+begin
+ FIFO_FLUSH := REG2ID(GFX_FLUSH);
+end;
+
+function FIFO_VIEWPORT(): cuint8; inline;
+begin
+ FIFO_VIEWPORT := REG2ID(GFX_VIEWPORT);
+end;
+
+{ $define FIFO_NOP := REG2ID(GFX_FIFO)}
+{ $define FIFO_STATUS := REG2ID(GFX_STATUS)}
+{ $define FIFO_COLOR := REG2ID(GFX_COLOR)}
+
+{ $define FIFO_VERTEX16 := REG2ID(GFX_VERTEX16)}
+{ $define FIFO_TEX_COORD := REG2ID(GFX_TEX_COORD)}
+{ $define FIFO_TEX_FORMAT := REG2ID(GFX_TEX_FORMAT)}
+{ $define FIFO_PAL_FORMAT := REG2ID(GFX_PAL_FORMAT)}
+
+{ $define FIFO_CLEAR_COLOR := REG2ID(GFX_CLEAR_COLOR)}
+{ $define FIFO_CLEAR_DEPTH := REG2ID(GFX_CLEAR_DEPTH)}
+
+{ $define FIFO_LIGHT_VECTOR := REG2ID(GFX_LIGHT_VECTOR)}
+{ $define FIFO_LIGHT_COLOR := REG2ID(GFX_LIGHT_COLOR)}
+{ $define FIFO_NORMAL := REG2ID(GFX_NORMAL)}
+
+{ $define FIFO_DIFFUSE_AMBIENT := REG2ID(GFX_DIFFUSE_AMBIENT)}
+{ $define FIFO_SPECULAR_EMISSION := REG2ID(GFX_SPECULAR_EMISSION)}
+{ $define FIFO_SHININESS := REG2ID(GFX_SHININESS)}
+
+{ $define FIFO_POLY_FORMAT := REG2ID(GFX_POLY_FORMAT)}
+
+{ $define FIFO_BEGIN := REG2ID(GFX_BEGIN)}
+{ $define FIFO_END := REG2ID(GFX_END)}
+{ $define FIFO_FLUSH := REG2ID(GFX_FLUSH)}
+{ $define FIFO_VIEWPORT := REG2ID(GFX_VIEWPORT)}
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+
+
+//---------------------------------------------------------------------------------
+//float wrappers for porting
+//---------------------------------------------------------------------------------
+
+procedure glRotatef32i(angle: cint; x, y, z: cint32); cdecl; external;
+function glTexImage2D(target, empty1: cint; _type: GL_TEXTURE_TYPE_ENUM; sizeX, sizeY, empty2, param: cint; texture: pcuint8): cint; cdecl; external;
+procedure glTexLoadPal(const pal: pcuint16; count: cuint16; addr: cuint32); cdecl; external;
+function gluTexLoadPal(const pal: pcuint16; count: cuint16; format: cuint8): cint; cdecl; external;
+procedure glTexParameter(sizeX, sizeY: cuint8; const addr: pcuint32; mode: GL_TEXTURE_TYPE_ENUM; param: cuint32); cdecl; external;
+function glGetTexParameter(): cuint32; cdecl; external;
+function glGetTexturePointer(name: cint): pointer; cdecl; external;
+procedure glBindTexture(target, name: cint); cdecl; external;
+procedure glColorTable(format: cuint8; addr: cuint32); cdecl; external;
+function glGenTextures(n: cint; names: pcint): cint; cdecl; external;
+procedure glResetTextures(); cdecl; external;
+procedure glTexCoord2f32(u, v: cint32); cdecl; external;
+procedure glMaterialf(mode: GL_MATERIALS_ENUM; color: rgb); cdecl; external;
+procedure glInit_C(); cdecl; external;
+function glGetGlobals(): PGLHiddenGlobals; cdecl; external;
+{$endif NDS_INTERFACE}
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////// ////////////
+//////////// ////////////
+//////////// ////////////
+//////////// INLINED FUNCTIONS ////////////
+//////////// ////////////
+//////////// ////////////
+//////////// ////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+{$ifdef NDS_IMPLEMENTATION}
+function POLY_ALPHA(n: cint): cuint32; inline;
+begin
+ POLY_ALPHA := cuint32((n) shl 16);
+end;
+
+function POLY_ID(n: cint): cuint32; inline;
+begin
+ POLY_ID := cuint32((n) shl 24);
+end;
+
+procedure glBegin(mode: GL_GLBEGIN_ENUM); inline;
+begin
+ GFX_BEGIN^ := mode;
+end;
+
+procedure glEnd(); inline;
+begin
+ GFX_END^ := 0;
+end;
+
+procedure glClearDepth(depth: fixed12d3); inline;
+begin
+ GFX_CLEAR_DEPTH^ := depth;
+end;
+
+procedure glColor3b(red, green, blue: cuint8); inline;
+begin
+ GFX_COLOR^ := cuint32(RGB15(red shr 3, green shr 3, blue shr 3));
+end;
+
+procedure glColor(color: rgb); inline;
+begin
+ GFX_COLOR^ := cuint32(color);
+end;
+
+procedure glVertex3v16(x, y, z: v16); inline;
+begin
+ GFX_VERTEX16^ := cuint32((y shl 16) or (x and $FFFF));
+ GFX_VERTEX16^ := cuint32(cuint16(z));
+end;
+
+procedure glTexCoord2t16(u, v: t16); inline;
+begin
+ GFX_TEX_COORD^ := TEXTURE_PACK(u, v);
+end;
+
+procedure glPushMatrix(); inline;
+begin
+ MATRIX_PUSH^ := 0;
+end;
+
+procedure glPopMatrix(num: cint32); inline;
+begin
+ MATRIX_POP^ := num;
+end;
+
+procedure glRestoreMatrix(index: cint32); inline;
+begin
+ MATRIX_RESTORE^ := index;
+end;
+
+procedure glStoreMatrix(index: cint32); inline;
+begin
+ MATRIX_STORE^ := index;
+end;
+
+procedure glScalev(const v: PGLvector); inline;
+begin
+ MATRIX_SCALE^ := v^.x;
+ MATRIX_SCALE^ := v^.y;
+ MATRIX_SCALE^ := v^.z;
+end;
+
+
+procedure glTranslatev(const v: PGLvector) ; inline;
+begin
+ MATRIX_TRANSLATE^ := v^.x;
+ MATRIX_TRANSLATE^ := v^.y;
+ MATRIX_TRANSLATE^ := v^.z;
+end;
+
+procedure glTranslate3f32(x, y, z: cint32); inline;
+begin
+ MATRIX_TRANSLATE^ := x;
+ MATRIX_TRANSLATE^ := y;
+ MATRIX_TRANSLATE^ := z;
+end;
+
+procedure glScalef32(factor: cint32); inline;
+begin
+ MATRIX_SCALE^ := factor;
+ MATRIX_SCALE^ := factor;
+ MATRIX_SCALE^ := factor;
+end;
+
+procedure glLight(id: cint; color: rgb; x, y, z: v10); inline;
+begin
+ id := (id and 3) shl 30;
+ GFX_LIGHT_VECTOR^ := id or ((z and $3FF) shl 20) or ((y and $3FF) shl 10) or (x and $3FF);
+ GFX_LIGHT_COLOR^ := id or color;
+end;
+
+procedure glNormal(normal: cuint32); inline;
+begin
+ GFX_NORMAL^ := normal;
+end;
+
+procedure glLoadIdentity(); inline;
+begin
+ MATRIX_IDENTITY^ := 0;
+end;
+
+procedure glIdentity(); inline;
+begin
+ MATRIX_IDENTITY^ := 0;
+end;
+
+procedure glMatrixMode(mode: GL_MATRIX_MODE_ENUM); inline;
+begin
+ MATRIX_CONTROL^ := mode;
+end;
+
+procedure glViewport(x1, y1, x2, y2: cuint8); inline;
+begin
+ GFX_VIEWPORT^ := (x1) + (y1 shl 8) + (x2 shl 16) + (y2 shl 24);
+end;
+
+procedure glFlush(mode: cuint32); inline;
+begin
+ GFX_FLUSH^ := mode;
+end;
+
+procedure glMaterialShinyness(); inline;
+var
+ shiny32: array [0..31] of cuint32;
+ shiny8: pcuint8;
+ i: integer;
+begin
+ shiny8 := pcuint8(@shiny32);
+
+ i := 0;
+ while i < (128 * 2) do
+ begin
+ shiny8[i shr 1] := i;
+ inc(i, 2);
+ end;
+
+ for i := 0 to 31 do
+ GFX_SHININESS[i] := shiny32[i];
+end;
+
+
+procedure glCallList(list: pcuint32); inline;
+var
+ count: cuint32;
+begin
+ count := list^;
+ inc(list);
+ DC_FlushRange(list, count*4);
+ while ( ((DMA_CR(0)^ and DMA_BUSY) <> 0) or
+ ((DMA_CR(1)^ and DMA_BUSY) <> 0) or
+ ((DMA_CR(2)^ and DMA_BUSY) <> 0) or
+ ((DMA_CR(3)^ and DMA_BUSY) <> 0)) do;
+
+ DMA_SRC(0)^ := cuint32(list);
+ DMA_DEST(0)^ := $4000400;
+ DMA_CR(0)^ := DMA_FIFO or count;
+ while (DMA_CR(0)^ and DMA_BUSY) <> 0 do;
+end;
+
+procedure glPolyFmt(params: cuint32); inline;
+begin
+ GFX_POLY_FORMAT^ := params;
+end;
+////////////////////////////////////////////////////////////////
+
+procedure glEnable(bits: cint); inline;
+begin
+ GFX_CONTROL^ := GFX_CONTROL^ or bits;
+end;
+
+procedure glDisable(bits: cint); inline;
+begin
+ GFX_CONTROL^ := GFX_CONTROL^ and not bits;
+end;
+
+procedure glLoadMatrix4x4(const m: pm4x4); inline;
+begin
+ MATRIX_LOAD4x4^ := m^.m[0];
+ MATRIX_LOAD4x4^ := m^.m[1];
+ MATRIX_LOAD4x4^ := m^.m[2];
+ MATRIX_LOAD4x4^ := m^.m[3];
+
+ MATRIX_LOAD4x4^ := m^.m[4];
+ MATRIX_LOAD4x4^ := m^.m[5];
+ MATRIX_LOAD4x4^ := m^.m[6];
+ MATRIX_LOAD4x4^ := m^.m[7];
+
+ MATRIX_LOAD4x4^ := m^.m[8];
+ MATRIX_LOAD4x4^ := m^.m[9];
+ MATRIX_LOAD4x4^ := m^.m[10];
+ MATRIX_LOAD4x4^ := m^.m[11];
+
+ MATRIX_LOAD4x4^ := m^.m[12];
+ MATRIX_LOAD4x4^ := m^.m[13];
+ MATRIX_LOAD4x4^ := m^.m[14];
+ MATRIX_LOAD4x4^ := m^.m[15];
+end;
+
+
+procedure glLoadMatrix4x3(const m: pm4x3); inline;
+begin
+ MATRIX_LOAD4x3^ := m^.m[0];
+ MATRIX_LOAD4x3^ := m^.m[1];
+ MATRIX_LOAD4x3^ := m^.m[2];
+ MATRIX_LOAD4x3^ := m^.m[3];
+
+ MATRIX_LOAD4x3^ := m^.m[4];
+ MATRIX_LOAD4x3^ := m^.m[5];
+ MATRIX_LOAD4x3^ := m^.m[6];
+ MATRIX_LOAD4x3^ := m^.m[7];
+
+ MATRIX_LOAD4x3^ := m^.m[8];
+ MATRIX_LOAD4x3^ := m^.m[9];
+ MATRIX_LOAD4x3^ := m^.m[10];
+ MATRIX_LOAD4x3^ := m^.m[11];
+end;
+
+
+procedure glMultMatrix4x4(const m: pm4x4); inline;
+begin
+ MATRIX_MULT4x4^ := m^.m[0];
+ MATRIX_MULT4x4^ := m^.m[1];
+ MATRIX_MULT4x4^ := m^.m[2];
+ MATRIX_MULT4x4^ := m^.m[3];
+
+ MATRIX_MULT4x4^ := m^.m[4];
+ MATRIX_MULT4x4^ := m^.m[5];
+ MATRIX_MULT4x4^ := m^.m[6];
+ MATRIX_MULT4x4^ := m^.m[7];
+
+ MATRIX_MULT4x4^ := m^.m[8];
+ MATRIX_MULT4x4^ := m^.m[9];
+ MATRIX_MULT4x4^ := m^.m[10];
+ MATRIX_MULT4x4^ := m^.m[11];
+
+ MATRIX_MULT4x4^ := m^.m[12];
+ MATRIX_MULT4x4^ := m^.m[13];
+ MATRIX_MULT4x4^ := m^.m[14];
+ MATRIX_MULT4x4^ := m^.m[15];
+end;
+
+procedure glMultMatrix4x3(const m: pm4x3); inline;
+begin
+ MATRIX_MULT4x3^ := m^.m[0];
+ MATRIX_MULT4x3^ := m^.m[1];
+ MATRIX_MULT4x3^ := m^.m[2];
+ MATRIX_MULT4x3^ := m^.m[3];
+
+ MATRIX_MULT4x3^ := m^.m[4];
+ MATRIX_MULT4x3^ := m^.m[5];
+ MATRIX_MULT4x3^ := m^.m[6];
+ MATRIX_MULT4x3^ := m^.m[7];
+
+ MATRIX_MULT4x3^ := m^.m[8];
+ MATRIX_MULT4x3^ := m^.m[9];
+ MATRIX_MULT4x3^ := m^.m[10];
+ MATRIX_MULT4x3^ := m^.m[11];
+end;
+
+procedure glMultMatrix3x3(const m: pm3x3); inline;
+begin
+ MATRIX_MULT3x3^ := m^.m[0];
+ MATRIX_MULT3x3^ := m^.m[1];
+ MATRIX_MULT3x3^ := m^.m[2];
+
+ MATRIX_MULT3x3^ := m^.m[3];
+ MATRIX_MULT3x3^ := m^.m[4];
+ MATRIX_MULT3x3^ := m^.m[5];
+
+ MATRIX_MULT3x3^ := m^.m[6];
+ MATRIX_MULT3x3^ := m^.m[7];
+ MATRIX_MULT3x3^ := m^.m[8];
+end;
+
+procedure glRotateXi(angle: cint); inline;
+var
+ sine, cosine: cint32;
+begin
+ sine := _SIN[angle and LUT_MASK];
+ cosine := _COS[angle and LUT_MASK];
+
+ MATRIX_MULT3x3^ := inttof32(1);
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := 0;
+
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := cosine;
+ MATRIX_MULT3x3^ := sine;
+
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := -sine;
+ MATRIX_MULT3x3^ := cosine;
+end;
+
+procedure glRotateYi(angle: cint); inline;
+var
+ sine, cosine: cint32;
+begin
+ sine := _SIN[angle and LUT_MASK];
+ cosine := _COS[angle and LUT_MASK];
+
+ MATRIX_MULT3x3^ := cosine;
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := -sine;
+
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := inttof32(1);
+ MATRIX_MULT3x3^ := 0;
+
+ MATRIX_MULT3x3^ := sine;
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := cosine;
+end;
+
+procedure glRotateZi(angle: cint); inline;
+var
+ sine, cosine: cint32;
+begin
+ sine := _SIN[angle and LUT_MASK];
+ cosine := _COS[angle and LUT_MASK];
+
+ MATRIX_MULT3x3^ := cosine;
+ MATRIX_MULT3x3^ := sine;
+ MATRIX_MULT3x3^ := 0;
+
+ MATRIX_MULT3x3^ := -sine;
+ MATRIX_MULT3x3^ := cosine;
+ MATRIX_MULT3x3^ := 0;
+
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := 0;
+ MATRIX_MULT3x3^ := inttof32(1);
+end;
+
+procedure glOrthof32(left, right, bottom, top, zNear, zFar: cint32); inline;
+begin
+ MATRIX_MULT4x4^ := divf32(inttof32(2), right - left);
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := divf32(inttof32(2), top - bottom);
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := divf32(inttof32(-2), zFar - zNear);
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := -divf32(right + left, right - left);//0;
+ MATRIX_MULT4x4^ := -divf32(top + bottom, top - bottom); //0;
+ MATRIX_MULT4x4^ := -divf32(zFar + zNear, zFar - zNear);//0;
+ MATRIX_MULT4x4^ := floattof32(1.0);
+
+ //glStoreMatrix(0);
+end;
+
+procedure gluLookAtf32(eyex, eyey, eyez, lookAtx, lookAty, lookAtz, upx, upy, upz: cint32); inline;
+var
+ side, forwrd, up, eye: array [0..2] of cint32;
+begin
+
+ forwrd[0] := eyex - lookAtx;
+ forwrd[1] := eyey - lookAty;
+ forwrd[2] := eyez - lookAtz;
+
+ normalizef32(@forwrd);
+
+ up[0] := upx;
+ up[1] := upy;
+ up[2] := upz;
+ eye[0] := eyex;
+ eye[1] := eyey;
+ eye[2] := eyez;
+
+ crossf32(@up, @forwrd, @side);
+
+ normalizef32(@side);
+
+ // Recompute local up
+ crossf32(@forwrd, @side, @up);
+
+ glMatrixMode(GL_MODELVIEW);
+
+
+ // should we use MATRIX_MULT4x3?
+ MATRIX_MULT4x3^ := side[0];
+ MATRIX_MULT4x3^ := up[0];
+ MATRIX_MULT4x3^ := forwrd[0];
+
+ MATRIX_MULT4x3^ := side[1];
+ MATRIX_MULT4x3^ := up[1];
+ MATRIX_MULT4x3^ := forwrd[1];
+
+ MATRIX_MULT4x3^ := side[2];
+ MATRIX_MULT4x3^ := up[2];
+ MATRIX_MULT4x3^ := forwrd[2];
+
+ MATRIX_MULT4x3^ := -dotf32(@eye,@side);
+ MATRIX_MULT4x3^ := -dotf32(@eye,@up);
+ MATRIX_MULT4x3^ := -dotf32(@eye,@forwrd);
+end;
+
+procedure glFrustumf32(left, right, bottom, top, zNear, zFar: cint32); inline;
+begin
+(*
+ MATRIX_MULT4x4^ := divf32(2*znear, right - left);
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := divf32(right + left, right - left);
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := divf32(2*znear, top - bottom);
+ MATRIX_MULT4x4^ := divf32(top + bottom, top - bottom);
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := -divf32(zfar + znear, zfar - znear);
+ MATRIX_MULT4x4^ := floattof32(-1.0);
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := -divf32(2 * mulf32(zfar, znear), zfar - znear);
+ MATRIX_MULT4x4^ := 0;
+*)
+ MATRIX_MULT4x4^ := divf32(2*znear, right - left);
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := divf32(2*znear, top - bottom);
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := divf32(right + left, right - left);
+ MATRIX_MULT4x4^ := divf32(top + bottom, top - bottom);
+ MATRIX_MULT4x4^ := -divf32(zfar + znear, zfar - znear);
+ MATRIX_MULT4x4^ := floattof32(-1.0);
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := -divf32(2 * mulf32(zfar, znear), zfar - znear);
+ MATRIX_MULT4x4^ := 0;
+end;
+
+procedure gluPerspectivef32(fovy: cint; aspect, zNear, zFar: cint32); inline;
+var
+ xmin, xmax, ymin, ymax: cint32;
+begin
+ ymax := mulf32(zNear, TAN_bin[(fovy shr 1) and LUT_MASK]);
+ ymin := -ymax;
+ xmin := mulf32(ymin, aspect);
+ xmax := mulf32(ymax, aspect);
+
+ glFrustumf32(xmin, xmax, ymin, ymax, zNear, zFar);
+end;
+
+procedure glTexCoord2f(s, t: cfloat); inline;
+var
+ x, y: cint;
+begin
+ x := ((glGlob^.textures[glGlob^.activeTexture]) shr 20) and 7;
+ y := ((glGlob^.textures[glGlob^.activeTexture]) shr 23) and 7;
+
+ glTexCoord2t16(floattot16(s*(8 shl x)), floattot16(t*(8 shl y)));
+end;
+
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+type
+ TArr4ofInt = array [0..3] of cint32;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+procedure gluPickMatrix(x, y, width, height: cint32; const viewport: TArr4ofInt); inline;
+begin
+ MATRIX_MULT4x4^ := inttof32(viewport[2]) div width;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := inttof32(viewport[3]) div height;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := inttof32(1);
+ MATRIX_MULT4x4^ := 0;
+
+ MATRIX_MULT4x4^ := inttof32(viewport[2] + ((viewport[0] - x) shl 1)) div width;
+ MATRIX_MULT4x4^ := inttof32(viewport[3] + ((viewport[1] - y) shl 1)) div height;
+ MATRIX_MULT4x4^ := 0;
+ MATRIX_MULT4x4^ := inttof32(1);
+end;
+
+procedure glResetMatrixStack(); inline;
+begin
+ // make sure there are no push/pops that haven't executed yet
+ while (GFX_STATUS^ and (1 shl 14)) <> 0 do
+ begin
+ GFX_STATUS^ := GFX_STATUS^ or (1 shl 15); // clear push/pop errors or push/pop busy bit never clears
+ end;
+
+ // pop the projection stack to the top; poping 0 off an empty stack causes an error... weird?
+ if (GFX_STATUS^ and (1 shl 13)) <> 0 then
+ begin
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix(1);
+ end;
+
+ // 31 deep modelview matrix; 32nd entry works but sets error flag
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix((GFX_STATUS^ shr 8) and $1F);
+
+ // load identity to all the matrices
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+end;
+
+procedure glSetOutlineColor(id: cint; color: rgb); inline;
+begin
+ GFX_EDGE_TABLE[id] := cuint16(color);
+end;
+
+procedure glSetToonTable(const table: pcuint16); inline;
+var
+ i: integer;
+begin
+ for i := 0 to 31 do
+ GFX_TOON_TABLE[i] := table[i];
+end;
+
+procedure glSetToonTableRange(_start, _end: cint; color: rgb); inline;
+var
+ i: integer;
+begin
+ for i := _start to _end do
+ GFX_TOON_TABLE[i] := cuint16(color);
+end;
+
+procedure glGetFixed(const param: GL_GET_ENUM; f: pcint32); inline;
+var
+ i: integer;
+begin
+ case param of
+ GL_GET_MATRIX_VECTOR:
+ begin
+ while (GFX_BUSY) do; // wait until the graphics engine has stopped to read matrixes
+ for i := 0 to 8 do
+ f[i] := MATRIX_READ_VECTOR[i];
+ end;
+ GL_GET_MATRIX_CLIP:
+ begin
+ while (GFX_BUSY) do; // wait until the graphics engine has stopped to read matrixes
+ for i := 0 to 15 do
+ f[i] := MATRIX_READ_CLIP[i];
+ end;
+ GL_GET_MATRIX_PROJECTION:
+ begin
+ glMatrixMode(GL_POSITION);
+ glPushMatrix(); // save the current state of the position matrix
+ glLoadIdentity(); // load an identity matrix into the position matrix so that the modelview matrix = projection matrix
+ while (GFX_BUSY) do; // wait until the graphics engine has stopped to read matrixes
+ for i := 0 to 15 do
+ f[i] := MATRIX_READ_CLIP[i]; // read out the projection matrix
+ glPopMatrix(1); // restore the position matrix
+ end;
+ GL_GET_MATRIX_POSITION:
+ begin
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix(); // save the current state of the projection matrix
+ glLoadIdentity(); // load a identity matrix into the projection matrix so that the modelview matrix = position matrix
+ while (GFX_BUSY) do; // wait until the graphics engine has stopped to read matrixes
+ for i := 0 to 15 do
+ f[i] := MATRIX_READ_CLIP[i]; // read out the position matrix
+ glPopMatrix(1); // restore the projection matrix
+ end;
+ end;
+end;
+
+procedure glAlphaFunc(alphaThreshold: cint); inline;
+begin
+ GFX_ALPHA_TEST^ := alphaThreshold;
+end;
+
+procedure glCutoffDepth(wVal: fixed12d3); inline;
+begin
+ GFX_CUTOFF_DEPTH^ := wVal;
+end;
+
+procedure glInit(); inline;
+begin
+ glGlob := glGetGlobals(); // make sure globals are synced between compilation units
+ glInit_C(); // actually does the initialization
+end;
+
+procedure glClearColor(red, green, blue, alpha: cuint8); inline;
+begin
+ GFX_CLEAR_COLOR^ := (glGlob^.clearColor and $FFE08000) or ($7FFF and RGB15(red, green, blue)) or ((alpha and $1F) shl 16);
+ glGlob^.clearColor := GFX_CLEAR_COLOR^;
+end;
+
+procedure glClearPolyID(ID: cuint8); inline;
+begin
+ GFX_CLEAR_COLOR^ := ( glGlob^.clearColor and $C0FFFFFF) or (( ID and $3F ) shl 24 );
+ glGlob^.clearColor := GFX_CLEAR_COLOR^;
+end;
+
+procedure glGetInt(param: GL_GET_ENUM; var i: cint); inline;
+begin
+ case param of
+ GL_GET_POLYGON_RAM_COUNT:
+ i := GFX_POLYGON_RAM_USAGE^;
+ GL_GET_VERTEX_RAM_COUNT:
+ i := GFX_VERTEX_RAM_USAGE^;
+ GL_GET_TEXTURE_WIDTH:
+ i := 8 shl (((glGlob^.textures[glGlob^.activeTexture]) shr 20) and 7);
+ GL_GET_TEXTURE_HEIGHT:
+ i := 8 shl (((glGlob^.textures[glGlob^.activeTexture]) shr 23) and 7);
+ end;
+end;
+
+//---------------------------------------------------------------------------------
+// INLINED FlOAT WRAPPERS
+
+procedure glVertex3f(x, y, z: cfloat); inline;
+begin
+ glVertex3v16(floattov16(x), floattov16(y), floattov16(z));
+end;
+
+procedure glRotatef32(angle: cfloat; x, y, z: cint32); inline;
+begin
+ glRotatef32i(trunc(angle * LUT_SIZE / 360.0), x, y, z);
+end;
+
+procedure glRotatef(angle, x, y, z: cfloat); inline;
+begin
+ glRotatef32(angle, floattof32(x), floattof32(y), floattof32(z));
+end;
+
+procedure glColor3f(r, g, b: cfloat); inline;
+begin
+ glColor3b(trunc(r*255), trunc(g*255), trunc(b*255));
+end;
+
+procedure glScalef(x, y, z: cfloat); inline;
+begin
+ MATRIX_SCALE^ := floattof32(x);
+ MATRIX_SCALE^ := floattof32(y);
+ MATRIX_SCALE^ := floattof32(z);
+end;
+
+procedure glTranslatef(x, y, z: cfloat); inline;
+begin
+ MATRIX_TRANSLATE^ := floattof32(x);
+ MATRIX_TRANSLATE^ := floattof32(y);
+ MATRIX_TRANSLATE^ := floattof32(z);
+end;
+
+procedure glNormal3f(x, y, z: cfloat); inline;
+begin
+ glNormal(NORMAL_PACK(floattov10(x), floattov10(y), floattov10(z)));
+end;
+
+procedure glRotateX(angle: cfloat); inline;
+begin
+ glRotateXi(trunc(angle * LUT_SIZE / 360.0));
+end;
+
+procedure glRotateY(angle: cfloat); inline;
+begin
+ glRotateYi(trunc(angle * LUT_SIZE / 360.0));
+end;
+
+procedure glRotateZ(angle: cfloat); inline;
+begin
+ glRotateZi(trunc(angle * LUT_SIZE / 360.0));
+end;
+
+procedure glOrtho(left, right, bottom, top, zNear, zFar: cfloat); inline;
+begin
+ glOrthof32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(zNear), floattof32(zFar));
+end;
+
+procedure gluLookAt(eyex, eyey, eyez, lookAtx, lookAty, lookAtz, upx, upy, upz: cfloat); inline;
+begin
+ gluLookAtf32(floattof32(eyex), floattof32(eyey), floattof32(eyez),
+ floattof32(lookAtx), floattof32(lookAty), floattof32(lookAtz),
+ floattof32(upx), floattof32(upy), floattof32(upz));
+end;
+
+procedure glFrustum(left, right, bottom, top, znear, zfar: cfloat); inline;
+begin
+ glFrustumf32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(znear), floattof32(zfar));
+end;
+
+procedure gluPerspective(fovy, aspect, zNear, zFar: cfloat); inline;
+begin
+ gluPerspectivef32(trunc(fovy * LUT_SIZE / 360.0), floattof32(aspect), floattof32(zNear), floattof32(zFar));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+function int_to_12d3(n: cint): fixed12d3; inline;
+function float_to_12d3(n: cfloat): fixed12d3; inline;
+function inttof32(n: cint): cint32; inline;
+function f32toint(n: cint32): cint; inline;
+function floattof32(n: cfloat): cint32; inline;
+function f32tofloat(n: cint32): cfloat; inline;
+function f32tot16(n: cint32): t16; inline;
+function inttot16(n: cint): cint32; inline; //???
+function t16toint(n: t16): cint; inline;
+function floattot16(n: cfloat): t16; inline;
+function TEXTURE_PACK(u, v: cint): cint; inline;
+function inttov16(n: cint): cint; inline;
+function f32tov16(n: cint32): v16; inline;
+function v16toint(n: v16): cint; inline;
+function floattov16(n: cfloat): v16; inline;
+function VERTEX_PACK(x,y: cint): cint; inline;
+function inttov10(n: cint): cint; inline;
+function f32tov10(n: cint32): cint; inline;
+function v10toint(n: v10): cint; inline;
+function floattov10(n: cfloat): v10; inline;
+function NORMAL_PACK(x,y,z: cint): cint; inline;
+function FIFO_COMMAND_PACK(c1,c2,c3,c4: cint): cint; inline;
+function REG2ID(r: pcuint32): cuint8; inline;
+function FIFO_NOP(): cuint8; inline;
+function FIFO_STATUS(): cuint8; inline;
+function FIFO_COLOR(): cuint8; inline;
+function FIFO_VERTEX16(): cuint8; inline;
+function FIFO_TEX_COORD(): cuint8; inline;
+function FIFO_TEX_FORMAT(): cuint8; inline;
+function FIFO_PAL_FORMAT(): cuint8; inline;
+function FIFO_CLEAR_COLOR(): cuint8; inline;
+function FIFO_CLEAR_DEPTH(): cuint8; inline;
+function FIFO_LIGHT_VECTOR(): cuint8; inline;
+function FIFO_LIGHT_COLOR(): cuint8; inline;
+function FIFO_NORMAL(): cuint8; inline;
+function FIFO_DIFFUSE_AMBIENT(): cuint8; inline;
+function FIFO_SPECULAR_EMISSION(): cuint8; inline;
+function FIFO_SHININESS(): cuint8; inline;
+function FIFO_POLY_FORMAT(): cuint8; inline;
+function FIFO_BEGIN(): cuint8; inline;
+function FIFO_END(): cuint8; inline;
+function FIFO_FLUSH(): cuint8; inline;
+function FIFO_VIEWPORT(): cuint8; inline;
+function POLY_ALPHA(n: cint): cuint32; inline;
+function POLY_ID(n: cint): cuint32; inline;
+procedure glBegin(mode: GL_GLBEGIN_ENUM); inline;
+procedure glEnd(); inline;
+procedure glClearDepth(depth: fixed12d3); inline;
+procedure glColor3b(red, green, blue: cuint8); inline;
+procedure glColor(color: rgb); inline;
+procedure glVertex3v16(x, y, z: v16); inline;
+procedure glTexCoord2t16(u, v: t16); inline;
+procedure glPushMatrix(); inline;
+procedure glPopMatrix(num: cint32); inline;
+procedure glRestoreMatrix(index: cint32); inline;
+procedure glStoreMatrix(index: cint32); inline;
+procedure glScalev(const v: PGLvector); inline;
+procedure glTranslatev(const v: PGLvector) ; inline;
+procedure glTranslate3f32(x, y, z: cint32); inline;
+procedure glScalef32(factor: cint32); inline;
+procedure glLight(id: cint; color: rgb; x, y, z: v10); inline;
+procedure glNormal(normal: cuint32); inline;
+procedure glLoadIdentity(); inline;
+procedure glIdentity(); inline;
+procedure glMatrixMode(mode: GL_MATRIX_MODE_ENUM); inline;
+procedure glViewport(x1, y1, x2, y2: cuint8); inline;
+procedure glFlush(mode: cuint32); inline;
+procedure glMaterialShinyness(); inline;
+procedure glCallList(list: pcuint32); inline;
+procedure glPolyFmt(params: cuint32); inline;
+procedure glEnable(bits: cint); inline;
+procedure glDisable(bits: cint); inline;
+procedure glLoadMatrix4x4(const m: pm4x4); inline;
+procedure glLoadMatrix4x3(const m: pm4x3); inline;
+procedure glMultMatrix4x4(const m: pm4x4); inline;
+procedure glMultMatrix4x3(const m: pm4x3); inline;
+procedure glMultMatrix3x3(const m: pm3x3); inline;
+procedure glRotateXi(angle: cint); inline;
+procedure glRotateYi(angle: cint); inline;
+procedure glRotateZi(angle: cint); inline;
+procedure glOrthof32(left, right, bottom, top, zNear, zFar: cint32); inline;
+procedure gluLookAtf32(eyex, eyey, eyez, lookAtx, lookAty, lookAtz, upx, upy, upz: cint32); inline;
+procedure glFrustumf32(left, right, bottom, top, zNear, zFar: cint32); inline;
+procedure gluPerspectivef32(fovy: cint; aspect, zNear, zFar: cint32); inline;
+procedure gluPickMatrix(x, y, width, height: cint32; const viewport: TArr4ofInt); inline;
+procedure glResetMatrixStack(); inline;
+procedure glSetOutlineColor(id: cint; color: rgb); inline;
+procedure glSetToonTable(const table: pcuint16); inline;
+procedure glSetToonTableRange(_start, _end: cint; color: rgb); inline;
+procedure glGetFixed(const param: GL_GET_ENUM; f: pcint32); inline;
+procedure glAlphaFunc(alphaThreshold: cint); inline;
+procedure glCutoffDepth(wVal: fixed12d3); inline;
+procedure glInit(); inline;
+procedure glClearColor(red, green, blue, alpha: cuint8); inline;
+procedure glClearPolyID(ID: cuint8); inline;
+procedure glGetInt(param: GL_GET_ENUM; var i: cint); inline;
+procedure glVertex3f(x, y, z: cfloat); inline;
+procedure glRotatef32(angle: cfloat; x, y, z: cint32); inline;
+procedure glRotatef(angle, x, y, z: cfloat); inline;
+procedure glColor3f(r, g, b: cfloat); inline;
+procedure glScalef(x, y, z: cfloat); inline;
+procedure glTranslatef(x, y, z: cfloat); inline;
+procedure glNormal3f(x, y, z: cfloat); inline;
+procedure glRotateX(angle: cfloat); inline;
+procedure glRotateY(angle: cfloat); inline;
+procedure glRotateZ(angle: cfloat); inline;
+procedure glOrtho(left, right, bottom, top, zNear, zFar: cfloat); inline;
+procedure gluLookAt(eyex, eyey, eyez, lookAtx, lookAty, lookAtz, upx, upy, upz: cfloat); inline;
+procedure glFrustum(left, right, bottom, top, znear, zfar: cfloat); inline;
+procedure gluPerspective(fovy, aspect, zNear, zFar: cfloat); inline;
+procedure glTexCoord2f(s, t: cfloat); inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/bios.inc b/packages/libndsfpc/src/nds/bios.inc
new file mode 100644
index 0000000000..9796342148
--- /dev/null
+++ b/packages/libndsfpc/src/nds/bios.inc
@@ -0,0 +1,125 @@
+(*
+ $Id: bios.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+
+type
+ TGetSize = function(source: pcuint8; dest: pcuint16; r2: cuint32): pcint;
+ TGetResult = function(source: pcuint8): pcint;
+ TReadByte = function(source: pcuint8): pcuint8;
+
+
+type
+ DecompressionStream = packed record
+ getSize: TGetSize;
+ getResult: TGetResult;
+ readByte: TReadByte;
+ end;
+ TDecompressionStream = DecompressionStream;
+ PDecompressionStream = ^TDecompressionStream;
+
+ UnpackStruct = packed record
+ sourceSize: cuint16; // in bytes
+ sourceWidth: cuint8;
+ destWidth: cuint8;
+ dataOffset: cuint32;
+ end;
+ TUnpackStruct = UnpackStruct;
+ PUnpackStruct = ^TUnpackStruct;
+
+
+procedure swiSoftReset(); cdecl; external;
+
+procedure swiDelay(duration: cuint32); cdecl; external;
+
+procedure swiIntrWait(waitForSet: cint; flags: cuint32); cdecl; external;
+
+procedure swiWaitForVBlank(); cdecl; external;
+
+function swiDivide(numerator, divisor: cint): cint; cdecl; external;
+function swiRemainder(numerator, divisor: cint): cint; cdecl; external;
+procedure swiDivMod(numerator, divisor: cint; result, remainder: pcint); cdecl; external;
+
+const
+ COPY_MODE_HWORD = (0);
+ COPY_MODE_WORD = (1 shl 26);
+ COPY_MODE_COPY = (0);
+ COPY_MODE_FILL = (1 shl 24);
+
+procedure swiCopy(const source: pointer; dest: pointer; flags: cint); cdecl; external;
+procedure swiFastCopy(const source: pointer; dest: pointer; flags: cint); cdecl; external;
+
+function swiSqrt(value: cint): cint; cdecl; external;
+
+function swiCRC16(crc: cuint16; data: pointer; size: cuint32): cuint16; cdecl; external;
+
+function swiIsDebugger(): cint; cdecl; external;
+
+procedure swiUnpackBits(source: pcuint8; destination: pcuint32; params: PUnpackStruct); cdecl; external;
+
+procedure swiDecompressLZSSWram(source, destination: pointer); cdecl; external;
+function swiDecompressLZSSVram(source, destination: pointer; toGetSize: cuint32; stream: PDecompressionStream): cint; cdecl; external;
+
+function swiDecompressHuffman(source, destination: pointer; toGetSize: cuint32; stream: PDecompressionStream): cint; cdecl; external;
+
+procedure swiDecompressRLEWram(source, destination: pointer); cdecl; external;
+function swiDecompressRLEVram(source, destination: pointer; toGetSize: cuint32; stream: PDecompressionStream): cint; cdecl; external;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_INTERFACE}
+{$ifdef ARM9}
+procedure swiWaitForIRQ(); cdecl; external;
+procedure swiSetHaltCR(data: cuint32); cdecl; external;
+procedure swiDecodeDelta8(source, destination: pointer); cdecl; external;
+procedure swiDecodeDelta16(source, destination: pointer); cdecl; external;
+{$endif ARM9}
+
+{$ifdef ARM7}
+procedure swiHalt(); cdecl; external;
+procedure swiSleep(); cdecl; external;
+procedure swiSwitchToGBAMode(); cdecl; external;
+procedure swiSetHaltCR(data: cuint8); cdecl; external;
+function swiGetSineTable(index: cint): cuint16; cdecl; external;
+function swiGetPitchTable(index: cint): cuint16; cdecl; external;
+function swiGetVolumeTable(index: cint): cuint8; cdecl; external;
+procedure swiChangeSoundBias(enabled, delay: cint); cdecl; external;
+{$endif ARM7}
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/card.inc b/packages/libndsfpc/src/nds/card.inc
new file mode 100644
index 0000000000..8f399d6ae8
--- /dev/null
+++ b/packages/libndsfpc/src/nds/card.inc
@@ -0,0 +1,101 @@
+(*
+ $Id: card.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+{$ifdef NDS_INTERFACE}
+const
+ // Card bus
+ CARD_CR1 : pcuint16 = pointer($040001A0);
+ CARD_CR1H : pcuint8 = pointer($040001A1);
+ CARD_EEPDATA : pcuint8 = pointer($040001A2);
+ CARD_CR2 : pcuint32 = pointer($040001A4);
+ CARD_COMMAND : pcuint8 = pointer($040001A8);
+
+ CARD_DATA_RD : pcuint32 = pointer($04100010);
+
+ CARD_1B0 : pcuint32 = pointer($040001B0);
+ CARD_1B4 : pcuint32 = pointer($040001B4);
+ CARD_1B8 : pcuint16 = pointer($040001B8);
+ CARD_1BA : pcuint16 = pointer($040001BA);
+
+
+ CARD_CR1_ENABLE = $80; // in byte 1, i.e. 0x8000
+ CARD_CR1_IRQ = $40; // in byte 1, i.e. 0x4000
+
+
+// CARD_CR2 register:
+ CARD_ACTIVATE = (1 shl 31); // when writing, get the ball rolling
+ // 1<<30
+ CARD_nRESET = (1 shl 29); // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
+ CARD_28 = (1 shl 28); // when writing
+ CARD_27 = (1 shl 27); // when writing
+ CARD_26 = (1 shl 26);
+ CARD_22 = (1 shl 22);
+ CARD_19 = (1 shl 19);
+ CARD_ENCRYPTED = (1 shl 14); // when writing, this command should be encrypted
+ CARD_13 = (1 shl 13); // when writing
+ CARD_4 = (1 shl 4); // when writing
+
+ // 3 bits in b10..b8 indicate something
+ // read bits
+ CARD_BUSY = (1 shl 31); // when reading, still expecting incomming data?
+ CARD_DATA_READY = (1 shl 23); // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go
+
+
+
+procedure cardWriteCommand(const command: pcuint8); cdecl; external;
+
+procedure cardPolledTransfer(flags: cuint32; destination: pcuint32; length: cuint32; const command: pcuint8); cdecl; external;
+procedure cardStartTransfer(const command: pcuint8; destination: pcuint32; channel: cint; flags: cuint32); cdecl; external;
+function cardWriteAndRead(const command: pcuint8; flags: cuint32): cuint32; cdecl; external;
+procedure cardRead00(address: cuint32; destination: pcuint32; length: cuint32; flags: cuint32); cdecl; external;
+procedure cardReadHeader(header: pcuint8); cdecl; external;
+function cardReadID(flags: cuint32): cint; cdecl; external;
+procedure cardReadEeprom(address: cuint32; data: pcuint8; length: cuint32; addrtype: cuint32); cdecl; external;
+procedure cardWriteEeprom(address: cuint32; data: pcuint8; length: cuint32; addrtype: cuint32); cdecl; external;
+
+function cardEepromReadID(i: cuint8): cuint8; cdecl; external;
+function cardEepromCommand(command: cuint8; address: cuint32): cuint8; cdecl; external;
+function cardEepromGetType({void}): cint; cdecl; external;
+function cardEepromGetSize(): cuint32; cdecl; external;
+procedure cardEepromChipErase({void}); cdecl; external;
+procedure cardEepromSectorErase(address: cuint32); cdecl; external;
+{$endif NDS_INTERFACE}
+
diff --git a/packages/libndsfpc/src/nds/dma.inc b/packages/libndsfpc/src/nds/dma.inc
new file mode 100644
index 0000000000..4118bb78f8
--- /dev/null
+++ b/packages/libndsfpc/src/nds/dma.inc
@@ -0,0 +1,206 @@
+(*
+ $Id: dma.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+
+{$ifdef NDS_INTERFACE}
+const
+ DMA0_SRC : pcuint32 = pointer($040000B0);
+ DMA0_DEST : pcuint32 = pointer($040000B4);
+ DMA0_CR : pcuint32 = pointer($040000B8);
+
+ DMA1_SRC : pcuint32 = pointer($040000BC);
+ DMA1_DEST : pcuint32 = pointer($040000C0);
+ DMA1_CR : pcuint32 = pointer($040000C4);
+
+ DMA2_SRC : pcuint32 = pointer($040000C8);
+ DMA2_DEST : pcuint32 = pointer($040000CC);
+ DMA2_CR : pcuint32 = pointer($040000D0);
+
+ DMA3_SRC : pcuint32 = pointer($040000D4);
+ DMA3_DEST : pcuint32 = pointer($040000D8);
+ DMA3_CR : pcuint32 = pointer($040000DC);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function DMA_SRC(n: cint): pcuint32; inline;
+begin
+ DMA_SRC := pcuint32($040000B0 + (n * 12));
+end;
+
+function DMA_DEST(n: cint): pcuint32; inline;
+begin
+ DMA_DEST := pcuint32($040000B4 + (n * 12));
+end;
+
+function DMA_CR(n: cint): pcuint32; inline;
+begin
+ DMA_CR := pcuint32($040000B8 + (n * 12));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+// DMA control register contents
+// The defaults are 16-bit, increment source/dest addresses, no irq
+const
+ DMA_ENABLE = (1 shl 31); //BIT(31);
+ DMA_BUSY = (1 shl 31); //BIT(31);
+ DMA_IRQ_REQ = (1 shl 30); //BIT(30);
+
+ DMA_START_NOW = 0;
+ DMA_START_CARD = (5 shl 27);
+
+{$ifdef ARM7}
+ DMA_START_VBL = (1 shl 27); //BIT(27);
+{$endif ARM7}
+
+{$ifdef ARM9}
+ DMA_START_HBL = (1 shl 28); //BIT(28);
+ DMA_START_VBL = (1 shl 27); //BIT(27);
+ DMA_START_FIFO = (7 shl 27);
+ DMA_DISP_FIFO = (4 shl 27);
+{$endif ARM9}
+
+ DMA_16_BIT = 0;
+ DMA_32_BIT = (1 shl 26); //BIT(26);
+
+ DMA_REPEAT = (1 shl 25); //BIT(25);
+
+ DMA_SRC_INC = (0);
+ DMA_SRC_DEC = (1 shl 23); //BIT(23);
+ DMA_SRC_FIX = (1 shl 24); //BIT(24);
+
+ DMA_DST_INC = (0);
+ DMA_DST_DEC = (1 shl 21); //BIT(21);
+ DMA_DST_FIX = (1 shl 22); //BIT(22);
+ DMA_DST_RESET = (3 shl 21);
+
+ DMA_COPY_WORDS = (DMA_ENABLE or DMA_32_BIT or DMA_START_NOW);
+ DMA_COPY_HALFWORDS = (DMA_ENABLE or DMA_16_BIT or DMA_START_NOW);
+{$ifdef ARM9}
+ DMA_FIFO = (DMA_ENABLE or DMA_32_BIT or DMA_DST_FIX or DMA_START_FIFO);
+{$endif ARM9}
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+
+procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(channel)^ := cuint32(src);
+ DMA_DEST(channel)^ := cuint32(dest);
+ DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
+ while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
+end;
+
+procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(channel)^ := cuint32(src);
+ DMA_DEST(channel)^ := cuint32(dest);
+ DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
+ while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
+end;
+
+procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(3)^ := cuint32(source);
+ DMA_DEST(3)^ := cuint32(dest);
+ DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
+ while (DMA_CR(3)^ and DMA_BUSY <> 0) do;
+end;
+
+procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(channel)^ := cuint32(src);
+ DMA_DEST(channel)^ := cuint32(dest);
+ DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
+end;
+
+procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(channel)^ := cuint32(src);
+ DMA_DEST(channel)^ := cuint32(dest);
+ DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
+end;
+
+procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(3)^ := cuint32(source);
+ DMA_DEST(3)^ := cuint32(dest);
+ DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
+end;
+
+procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(3)^ := cuint32(src);
+ DMA_DEST(3)^ := cuint32(dest);
+ DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_WORDS or (size shr 2);
+ while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
+end;
+
+procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
+begin
+ DMA_SRC(3)^ := cuint32(src);
+ DMA_DEST(3)^ := cuint32(dest);
+ DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_HALFWORDS or (size shr 1);
+ while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
+end;
+
+function dmaBusy(channel: cuint8): cint; inline;
+begin
+ dmaBusy := (DMA_CR(channel)^ and DMA_BUSY) shr 31;
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+function DMA_SRC(n: cint): pcuint32; inline;
+function DMA_DEST(n: cint): pcuint32; inline;
+function DMA_CR(n: cint): pcuint32; inline;
+procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
+procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
+function dmaBusy(channel: cuint8): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/helper.inc b/packages/libndsfpc/src/nds/helper.inc
new file mode 100644
index 0000000000..4664e02e56
--- /dev/null
+++ b/packages/libndsfpc/src/nds/helper.inc
@@ -0,0 +1,139 @@
+(*
+ $Id: helper.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2007 Francesco Lombardi
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+(* +------------------------------------------------------------------------+ *)
+(* Begin Random function *)
+(* +------------------------------------------------------------------------+ *)
+{$ifdef NDS_INTERFACE}
+const
+ QRAN_SHIFT = 15;
+ QRAN_MASK = ((1 shl QRAN_SHIFT) - 1);
+ QRAN_MAX = QRAN_MASK;
+ QRAN_A = 1664525;
+ QRAN_C = 1013904223;
+
+var
+ RandSeed: dword = 42;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function Randomize(seed: cint): cint;
+var
+ old: cint;
+begin
+ old := RandSeed;
+ RandSeed := seed;
+ Randomize := old;
+end;
+
+function Rand(): cint;
+begin
+ RandSeed := QRAN_A * RandSeed + QRAN_C;
+ Rand := (RandSeed shr 16) and QRAN_MAX;
+end;
+
+function Rand(value: cint): cint;
+var
+ a: cint;
+begin
+ RandSeed := QRAN_A * RandSeed + QRAN_C;
+ a := (RandSeed shr 16) and QRAN_MAX;
+ Rand := (a * value) shr 15;
+end;
+(* +------------------------------------------------------------------------+ *)
+(* End Random function *)
+(* +------------------------------------------------------------------------+ *)
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+(* Some libc functions *)
+function printf(format: Pchar; args: array of const): longint; cdecl; external;
+function printf(format: Pchar): longint; cdecl; varargs; external;
+function sprintf(s: Pchar; format: Pchar; args: array of const): longint; cdecl; external;
+function sprintf(s: Pchar; format: Pchar): longint; varargs; cdecl; external;
+function iprintf(format: Pchar; args: array of const): longint; cdecl; external;
+function iprintf(format: Pchar): longint; varargs; cdecl; external;
+function scanf(format: Pchar; args: array of const): longint; cdecl; external;
+function scanf(format: Pchar): longint; cdecl; varargs; external;
+function sscanf(s: Pchar; format: Pchar; args: array of const): longint; cdecl; external;
+function sscanf(s: Pchar; format: Pchar): longint; cdecl; varargs; external;
+
+
+(* libc file handling types and routines *)
+type
+ _FILE = record
+ firstCluster: cuint;
+ length: cuint;
+ curPos: cuint;
+ curClus: cuint; // Current cluster to read from
+ curSect: integer; // Current sector within cluster
+ curByte: integer; // Current byte within sector
+ readBuffer: array [0..511] of byte; // Buffer used for unaligned reads
+ appClus: cuint; // Cluster to append to
+ appSect: integer; // Sector within cluster for appending
+ appByte: integer; // Byte within sector for appending
+ read: boolean; // Can read from file
+ write: boolean; // Can write to file
+ append: boolean;// Can append to file
+ inUse: boolean; // This file is open
+ dirEntSector: cuint; // The sector where the directory entry is stored
+ dirEntOffset: integer; // The offset within the directory sector
+ end;
+ P_FILE = ^_FILE;
+
+const
+ SEEK_SET = 0;
+ SEEK_CUR = 1;
+ SEEK_END = 2;
+
+function fopen(filename: Pchar; modes: Pchar): P_FILE; cdecl; external;
+function fread(ptr: pointer; size: longint; n: longint; stream: P_FILE): longint; cdecl; external;
+function fwrite(ptr: pointer; size: longint; n: longint; s: P_FILE): longint; cdecl; external;
+function ftell(stream: P_FILE): longint; cdecl; external;
+function fseek(stream: P_FILE; off: longint; whence: longint): longint; cdecl; external;
+function fclose(stream: P_FILE): longint; cdecl; external;
+{$endif NDS_INTERFACE}
+
+
+
+
+{$ifdef NDS_INTERFACE}
+function Randomize(seed: cint): cint;
+function Rand(): cint;
+function Rand(value: cint): cint;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/interrupts.inc b/packages/libndsfpc/src/nds/interrupts.inc
new file mode 100644
index 0000000000..1571a70e27
--- /dev/null
+++ b/packages/libndsfpc/src/nds/interrupts.inc
@@ -0,0 +1,117 @@
+(*
+ $Id: interrupts.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+
+{$ifdef NDS_INTERFACE}
+type
+ IRQ_MASKS = cuint;
+ IRQ_MASK = IRQ_MASKS;
+const
+ IRQ_VBLANK : IRQ_MASK = (1 shl 0); (* vertical blank interrupt mask *)
+ IRQ_HBLANK : IRQ_MASK = (1 shl 1); (* horizontal blank interrupt mask *)
+ IRQ_VCOUNT : IRQ_MASK = (1 shl 2); (* vcount match interrupt mask *)
+ IRQ_TIMER0 : IRQ_MASK = (1 shl 3); (* timer 0 interrupt mask *)
+ IRQ_TIMER1 : IRQ_MASK = (1 shl 4); (* timer 1 interrupt mask *)
+ IRQ_TIMER2 : IRQ_MASK = (1 shl 5); (* timer 2 interrupt mask *)
+ IRQ_TIMER3 : IRQ_MASK = (1 shl 6); (* timer 3 interrupt mask *)
+ IRQ_NETWORK : IRQ_MASK = (1 shl 7); (* serial interrupt mask *)
+ IRQ_DMA0 : IRQ_MASK = (1 shl 8); (* DMA 0 interrupt mask *)
+ IRQ_DMA1 : IRQ_MASK = (1 shl 9); (* DMA 1 interrupt mask *)
+ IRQ_DMA2 : IRQ_MASK = (1 shl 10); (* DMA 2 interrupt mask *)
+ IRQ_DMA3 : IRQ_MASK = (1 shl 11); (* DMA 3 interrupt mask *)
+ IRQ_KEYS : IRQ_MASK = (1 shl 12); (* Keypad interrupt mask *)
+ IRQ_CART : IRQ_MASK = (1 shl 13); (* GBA cartridge interrupt mask *)
+ IRQ_IPC_SYNC : IRQ_MASK = (1 shl 16); (* IPC sync interrupt mask *)
+ IRQ_FIFO_EMPTY : IRQ_MASK = (1 shl 17); (* Send FIFO empty interrupt mask *)
+ IRQ_FIFO_NOT_EMPTY : IRQ_MASK = (1 shl 18); (* Receive FIFO empty interrupt mask *)
+ IRQ_CARD : IRQ_MASK = (1 shl 19); (* interrupt mask *)
+ IRQ_CARD_LINE : IRQ_MASK = (1 shl 20); (* interrupt mask *)
+ IRQ_GEOMETRY_FIFO : IRQ_MASK = (1 shl 21); (* geometry FIFO interrupt mask *)
+ IRQ_LID : IRQ_MASK = (1 shl 22); (* interrupt mask *)
+ 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 = $FFFFFF {not 0};
+
+const
+ MAX_INTERRUPTS = 25;
+
+
+
+const
+ REG_IE : pcuint32 = pointer($04000210);
+ REG_IF : pcuint32 = pointer($04000214);
+ REG_IME : pcuint16 = pointer($04000208);
+
+type
+ IME_VALUE = integer;
+const
+ IME_DISABLE : IME_VALUE = 0; (* Disable all interrupts. *)
+ IME_ENABLE : IME_VALUE = 1; (* Enable all interrupts not masked out in REG_IE *)
+
+
+var
+// __irq_vector: array [0..0] of VoidFunctionPointer; cvar; external;
+// __irq_vector: array [0..0] of Pointer; cvar; external;
+// __irq_flags: array [0..0] of cuint32; cvar; external;
+// __irq_flags: pcuint32; cvar; external;
+// __irq_vector: ^VoidFunctionPointer; cvar; external;
+ __irq_vector: Pointer; cvar; external;
+ __irq_flags: pcuint32; cvar; external;
+
+
+
+{$define VBLANK_INTR_WAIT_FLAGS := __irq_flags}
+{$define IRQ_HANDLER := __irq_vector}
+
+type
+ IntTable = record
+ handler: IntFn;
+ mask: cuint32;
+ end;
+
+procedure irqInit(); cdecl; external;
+//procedure irqSet(irq: IRQ_MASK; handler: VoidFunctionPointer); cdecl; external;
+procedure irqSet(irq: IRQ_MASK; handler: pointer); cdecl; external;
+procedure irqClear(irq: IRQ_MASK); cdecl; external;
+//procedure irqInitHandler(handler: VoidFunctionPointer); cdecl; external;
+procedure irqInitHandler(handler: pointer); cdecl; external;
+procedure irqEnable(irq: cuint32); cdecl; external;
+procedure irqDisable(irq: cuint32); cdecl; external;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/ipc.inc b/packages/libndsfpc/src/nds/ipc.inc
new file mode 100644
index 0000000000..9054ac512d
--- /dev/null
+++ b/packages/libndsfpc/src/nds/ipc.inc
@@ -0,0 +1,180 @@
+(*
+ $Id: ipc.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+type
+ sTransferSoundData = record
+ data: pointer;//pcint;
+ len: cuint32;
+ rate: cuint32;
+ vol: cuint8;
+ pan: cuint8;
+ format: cuint8;
+ PADDING: cuint8;
+ end;
+ TransferSoundData = sTransferSoundData;
+ TTransferSoundData = TransferSoundData;
+ PTransferSoundData = ^sTransferSoundData;
+
+ sTransferSound = record
+ data: array [0..15] of TransferSoundData;
+ count: cuint8;
+ PADDING: array [0..2] of cuint8;
+ end;
+ TransferSound = sTransferSound;
+ TTransferSound = TransferSound;
+ PTransferSound = ^sTransferSound;
+
+ sTransferRegion = record
+ touchX, touchY: cint16; // TSC X, Y
+ touchXpx, touchYpx: cint16; // TSC X, Y pixel values
+ touchZ1, touchZ2: cint16; // TSC x-panel measurements
+ tdiode1, tdiode2: cuint16; // TSC temperature diodes
+ temperature: cuint32; // TSC computed temperature
+
+ buttons: cuint16; // X, Y, /PENIRQ buttons
+
+ time: record
+ case integer of
+ 0: (curtime: array [0..7] of cuint8); // current time response from RTC
+ 1: (rtc: record
+ command: cuint8;
+ year: cuint8; //add 2000 to get 4 digit year
+ month: cuint8; //1 to 12
+ day: cuint8; //1 to (days in month)
+
+ incr: cuint8;
+ hours: cuint8; //0 to 11 for AM, 52 to 63 for PM
+ minutes: cuint8; //0 to 59
+ seconds: cuint8; //0 to 59
+ end;
+ );
+ end;
+ unixTime: cint32;
+
+ battery: cuint16; // battery life ?? hopefully. :)
+ aux: cuint16; // i have no idea...
+
+
+ // Don't rely on these below, will change or be removed in the future
+ soundData: pTransferSound;
+ mailAddr: cuint32;
+ mailData: cuint32;
+ mailRead: cuint8;
+ mailBusy: cuint8;
+ mailSize: cuint32;
+
+ end;
+ TransferRegion = sTransferRegion;
+ TTransferRegion = TransferRegion;
+ PTransferRegion = ^sTransferRegion;
+
+
+const
+ //IPC : pTransferRegion = pointer($027FF000);
+
+ IPC_PEN_DOWN = (1 shl 6);
+ IPC_X = (1 shl 0);
+ IPC_Y = (1 shl 1);
+ IPC_LID_CLOSED = (1 shl 7);
+
+//---------------------------------------------------------------------------------
+// Synchronization register
+//---------------------------------------------------------------------------------
+ REG_IPC_SYNC : pcuint16 = pointer($04000180);
+
+type
+ IPC_SYNC_BITS = longint;
+const
+ IPC_SYNC_IRQ_ENABLE: IPC_SYNC_BITS = (1 shl 14);
+ IPC_SYNC_IRQ_REQUEST: IPC_SYNC_BITS = (1 shl 13);
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_IMPLEMENTATION}
+function getIPC(): pTransferRegion; inline;
+begin
+ getIPC := pTransferRegion(pointer($027FF000));
+end;
+
+function IPC(): TransferRegion;
+begin
+ IPC := getIPC()^;
+end;
+
+procedure IPC_SendSync(sync: cuint); inline;
+begin
+ REG_IPC_SYNC^ := (REG_IPC_SYNC^ and $f0ff) or (((sync) and $0f) shl 8) or IPC_SYNC_IRQ_REQUEST;
+end;
+
+function IPC_GetSync(): cint; inline;
+begin
+ IPC_GetSync := REG_IPC_SYNC^ and $0f;
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+const
+ REG_IPC_FIFO_TX : pcuint32 = pointer($04000188);
+ REG_IPC_FIFO_RX : pcuint32 = pointer($04100000);
+ REG_IPC_FIFO_CR : pcuint16 = pointer($04000184);
+
+type
+ IPC_CONTROL_BITS = cint;
+
+const
+ IPC_FIFO_SEND_EMPTY : IPC_CONTROL_BITS = (1 shl 0);
+ IPC_FIFO_SEND_FULL : IPC_CONTROL_BITS = (1 shl 1);
+ IPC_FIFO_SEND_IRQ : IPC_CONTROL_BITS = (1 shl 2);
+ IPC_FIFO_SEND_CLEAR : IPC_CONTROL_BITS = (1 shl 3);
+ IPC_FIFO_RECV_EMPTY : IPC_CONTROL_BITS = (1 shl 8);
+ IPC_FIFO_RECV_FULL : IPC_CONTROL_BITS = (1 shl 9);
+ IPC_FIFO_RECV_IRQ : IPC_CONTROL_BITS = (1 shl 10);
+ IPC_FIFO_ERROR : IPC_CONTROL_BITS = (1 shl 14);
+ IPC_FIFO_ENABLE : IPC_CONTROL_BITS = (1 shl 15);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function getIPC(): pTransferRegion; inline;
+function IPC(): TransferRegion;
+procedure IPC_SendSync(sync: cuint); inline;
+function IPC_GetSync(): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/jtypes.inc b/packages/libndsfpc/src/nds/jtypes.inc
new file mode 100644
index 0000000000..65fd1b23b9
--- /dev/null
+++ b/packages/libndsfpc/src/nds/jtypes.inc
@@ -0,0 +1,168 @@
+(*
+ $Id: jtypes.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+//---------------------------------------------------------------------------------
+{
+//---------------------------------------------------------------------------------
+// libgba compatible section macros
+//---------------------------------------------------------------------------------
+#define ITCM_CODE __attribute__((section(".itcm"), long_call))
+
+#define DTCM_DATA __attribute__((section(".dtcm")))
+#define DTCM_BSS __attribute__((section(".sbss")))
+#define ALIGN(m) __attribute__((aligned (m)))
+
+#define PACKED __attribute__ ((packed))
+#define packed_struct struct PACKED
+}
+//---------------------------------------------------------------------------------
+// These are linked to the bin2o macro in the Makefile
+//---------------------------------------------------------------------------------
+{ ### To do
+#define GETRAW(name) (name)
+#define GETRAWSIZE(name) ((int)name##_size)
+#define GETRAWEND(name) ((int)name##_end)
+}
+
+{$ifdef NDS_INTERFACE}
+type
+ (* Unsigned types *)
+ uint8 = cuint8;
+ uint16 = cuint16;
+ uint32 = cuint32;
+ uint64 = cuint64;
+ puint8 = pcuint8;
+ puint16 = pcuint16;
+ puint32 = pcuint32;
+ puint64 = pcuint64;
+
+ (* Signed types *)
+ int8 = cint8;
+ int16 = cint16;
+ int32 = cint32;
+ pint8 = pcint8;
+ pint16 = pcint16;
+ pint32 = pcint32;
+ pint64 = pcint64;
+
+
+ float32 = cfloat;
+
+{
+typedef volatile uint8 vuint8;
+typedef volatile uint16 vuint16;
+typedef volatile uint32 vuint32;
+typedef volatile uint64 vuint64;
+
+typedef volatile int8 vint8;
+typedef volatile int16 vint16;
+typedef volatile int32 vint32;
+typedef volatile int64 vint64;
+
+typedef volatile float32 vfloat32;
+typedef volatile float64 vfloat64;
+}
+
+
+{
+typedef volatile int32 vfixed;
+}
+
+ u8 = cuint8;
+ u16 = cuint16;
+ u32 = cuint32;
+ u64 = cuint64;
+ pu8 = pcuint8;
+ pu16 = pcuint16;
+ pu32 = pcuint32;
+ pu64 = pcuint64;
+
+ s8 = cint8;
+ s16 = cint16;
+ s32 = cint32;
+ s64 = cint64;
+ ps8 = pcint8;
+ ps16 = pcint16;
+ ps32 = pcint32;
+ ps64 = pcint64;
+
+{
+typedef volatile u8 vu8;
+typedef volatile u16 vu16;
+typedef volatile u32 vu32;
+typedef volatile u64 vu64;
+
+typedef volatile s8 vs8;
+typedef volatile s16 vs16;
+typedef volatile s32 vs32;
+typedef volatile s64 vs64;
+}
+
+ touchPosition = record
+ x: cint16;
+ y: cint16;
+ px: cint16;
+ py: cint16;
+ z1: cint16;
+ z2: cint16;
+ end;
+ TtouchPosition = touchPosition;
+ PtouchPosition = ^touchPosition;
+
+ //IntFn = function: pointer;
+ VoidFunctionPointer = function: pointer; cdecl;
+ //fp = function: pointer;
+
+ IntFn = procedure;
+ //VoidFunctionPointer = procedure; cdecl;
+ fp = procedure;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function BIT(n: cint): cint; inline;
+begin
+ BIT := (1 shl (n));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef NDS_INTERFACE}
+function BIT(n: cint): cint; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/memory.inc b/packages/libndsfpc/src/nds/memory.inc
new file mode 100644
index 0000000000..a5519a1421
--- /dev/null
+++ b/packages/libndsfpc/src/nds/memory.inc
@@ -0,0 +1,272 @@
+(*
+ $Id: memory.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+// WAIT_CR: Wait State Control Register
+const
+{$ifdef ARM9}
+ REG_EXMEMCNT : pcuint16 = pointer($04000204);
+{$else}
+ REG_EXMEMSTAT: pcuint16 = pointer($04000204);
+{$endif}
+ ARM7_MAIN_RAM_PRIORITY = (1 shl 15);
+ ARM7_OWNS_CARD = (1 shl 11);
+ ARM7_OWNS_ROM = (1 shl 7);
+
+
+// Protection register (write-once sadly)
+{$ifdef ARM7}
+ PROTECTION : pcuint32 = pointer($04000308);
+{$endif ARM7}
+
+
+ ALLRAM : pcuint8 = pointer($00000000);
+
+ MAINRAM8 : pcuint8 = pointer($02000000);
+ MAINRAM16 : pcuint16 = pointer($02000000);
+ MAINRAM32 : pcuint32 = pointer($02000000);
+
+// fixme: shared RAM
+
+// GBA_BUS is volatile, while GBAROM is not
+ GBA_BUS : pcuint16 = pointer($08000000);
+ GBAROM : pcuint16 = pointer($08000000);
+
+ SRAM : pcuint8 = pointer($0A000000);
+
+
+{$ifdef ARM9}
+ PALETTE : pcuint16 = pointer($05000000);
+ PALETTE_SUB : pcuint16 = pointer($05000400);
+
+ BG_PALETTE : pcuint16 = pointer($05000000);
+ BG_PALETTE_SUB : pcuint16 = pointer($05000400);
+
+ SPRITE_PALETTE : pcuint16 = pointer($05000200);
+ SPRITE_PALETTE_SUB : pcuint16 = pointer($05000600);
+
+ BG_GFX : pcuint16 = pointer($06000000);
+ BG_GFX_SUB : pcuint16 = pointer($06200000);
+ SPRITE_GFX : pcuint16 = pointer($06400000);
+ SPRITE_GFX_SUB : pcuint16 = pointer($06600000);
+
+ VRAM_0 : pcuint16 = pointer($06000000);
+ VRAM : pcuint16 = pointer($06800000);
+ VRAM_A : pcuint16 = pointer($06800000);
+ VRAM_B : pcuint16 = pointer($06820000);
+ VRAM_C : pcuint16 = pointer($06840000);
+ VRAM_D : pcuint16 = pointer($06860000);
+ VRAM_E : pcuint16 = pointer($06880000);
+ VRAM_F : pcuint16 = pointer($06890000);
+ VRAM_G : pcuint16 = pointer($06894000);
+ VRAM_H : pcuint16 = pointer($06898000);
+ VRAM_I : pcuint16 = pointer($068A0000);
+
+ OAM : pcuint16 = pointer($07000000);
+ OAM_SUB : pcuint16 = pointer($07000400);
+{$endif ARM9}
+
+{$ifdef ARM7}
+ VRAM : pcuint16 = pointer($06000000);
+{$endif ARM7}
+
+type
+ sGBAHeader = packed record
+ entryPoint: cuint32;
+ logo: array [0..155] of cuint8;
+ title: array [0..11] of cchar;
+ gamecode: array [0..3] of cchar;
+ makercode: cuint16;
+ is96h: cuint8;
+ unitcode: cuint8;
+ devicecode: cuint8;
+ unused: array [0..6] of cuint8;
+ version: cuint8;
+ complement: cuint8;
+ checksum: cuint16;
+ end;
+ TGBAHeader = sGBAHeader;
+ PGBAHeader = ^sGBAHeader;
+
+const
+ GBA_HEADER : pGBAHeader = pointer($08000000);
+
+type
+ sNDSHeader = packed record
+ gameTitle: array [0..11] of cchar;
+ gameCode: array [0..3] of cchar;
+ makercode: array [0..1] of cchar;
+ unitCode: cuint8;
+ deviceType: cuint8; // type of device in the game card
+ deviceSize: cuint8; // device capacity (1<<n Mbit)
+ reserved1: array [0..8] of cuint8;
+ romversion: cuint8;
+ flags: cuint8; // auto-boot flag
+
+ arm9romSource: cuint32;
+ arm9executeAddress: cuint32;
+ arm9destination: cuint32;
+ arm9binarySize: cuint32;
+
+ arm7romSource: cuint32;
+ arm7executeAddress: cuint32;
+ arm7destination: cuint32;
+ arm7binarySize: cuint32;
+
+ filenameSource: cuint32;
+ filenameSize: cuint32;
+ fatSource: cuint32;
+ fatSize: cuint32;
+
+ arm9overlaySource: cuint32;
+ arm9overlaySize: cuint32;
+ arm7overlaySource: cuint32;
+ arm7overlaySize: cuint32;
+
+ cardControl13: cuint32; // used in modes 1 and 3
+ cardControlBF: cuint32; // used in mode 2
+ bannerOffset: cuint32;
+
+ secureCRC16: cuint16;
+
+ readTimeout: cuint16;
+
+ unknownRAM1: cuint32;
+ unknownRAM2: cuint32;
+
+ bfPrime1: cuint32;
+ bfPrime2: cuint32;
+ romSize: cuint32;
+
+ headerSize: cuint32;
+ zeros88: array [0..13] of cuint32;
+ gbaLogo: array [0..155] of cuint8;
+ logoCRC16: cuint16;
+ headerCRC16: cuint16;
+
+ debugRomSource: cuint32;
+ debugRomSize: cuint32;
+ debugRomDestination: cuint32;
+ offset_0x16C: cuint32;
+
+ zero: array [0..143] of cuint8;
+ end;
+ tNDSHeader = sNDSHeader;
+ pNDSHeader = ^tNDSHeader;
+
+const
+ NDSHeader : pNDSHeader = pointer($027FFE00);
+
+
+type
+ sNDSBanner = packed record
+ version: cuint16;
+ crc: cuint16;
+ reserved: array [0..27] of cuint8;
+ icon: array [0..511] of cuint8;
+ palette: array [0..15] of cuint16;
+ titles: array [0..5, 0..127] of cuint16;
+ end;
+ tNDSBanner = sNDSBanner;
+ pNDSBanner = ^tNDSBanner;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef ARM9}
+{$ifdef NDS_INTERFACE}
+const
+ BUS_OWNER_ARM9 = true;
+ BUS_OWNER_ARM7 = false;
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+// Changes only the gba rom bus ownership
+procedure sysSetCartOwner(arm9: cbool); inline;
+var
+ i: cint;
+begin
+ if arm9 then
+ i := 0
+ else
+ i := ARM7_OWNS_ROM;
+ REG_EXMEMCNT^ := (REG_EXMEMCNT^ and not ARM7_OWNS_ROM) or (i);
+end;
+
+// Changes only the nds card bus ownership
+procedure sysSetCardOwner(arm9: cbool); inline;
+var
+ i: cint;
+begin
+ if arm9 then
+ i := 0
+ else
+ i := ARM7_OWNS_ROM;
+ REG_EXMEMCNT^ := (REG_EXMEMCNT^ and not ARM7_OWNS_CARD) or (i);
+end;
+
+// Changes all bus ownerships
+procedure sysSetBusOwners(arm9rom, arm9card: cbool); inline;
+var
+ pattern: cuint16;
+ a9r, a9c: cint;
+begin
+ pattern := REG_EXMEMCNT^ and not (ARM7_OWNS_CARD or ARM7_OWNS_ROM);
+ if arm9card then
+ a9c := 0
+ else
+ a9c := ARM7_OWNS_CARD;
+ if arm9rom then
+ a9r := 0
+ else
+ a9r := ARM7_OWNS_ROM;
+
+ pattern := pattern or (a9c) or (a9r);
+ REG_EXMEMCNT^ := pattern;
+end;
+{$endif NDS_IMPLEMENTATION}
+{$endif ARM9}
+
+{$ifdef NDS_INTERFACE}
+{$ifdef ARM9}
+procedure sysSetCartOwner(arm9: cbool); inline;
+procedure sysSetCardOwner(arm9: cbool); inline;
+procedure sysSetBusOwners(arm9rom, arm9card: cbool); inline;
+{$endif ARM9}
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/nds.inc b/packages/libndsfpc/src/nds/nds.inc
new file mode 100644
index 0000000000..42da1454f0
--- /dev/null
+++ b/packages/libndsfpc/src/nds/nds.inc
@@ -0,0 +1,126 @@
+(*
+ $Id: nds.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+ Use this file as inclusion if you don't want to use the nds7/nds9 ppu library:
+
+ program main;
+
+ {$apptype arm9} // or arm7
+ {$define arm9} // or arm7
+ {$mode objfpc}
+
+
+ uses
+ ctypes;
+
+ {$include nds.inc}
+
+ begin
+ // do stuff
+ end.
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+*
+*
+{$ifndef NDS_INC}
+{$define NDS_INC}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+{$if not defined(ARM7) and not defined (ARM9)}
+ {$error Either ARM7 or ARM9 must be defined}
+{$endif}
+
+
+{$define NDS_INCLUSION}
+{$define NDS_INTERFACE}
+{$define NDS_IMPLEMENTATION}
+
+{$include helper.inc}
+
+{$include jtypes.inc}
+{$include bios.inc}
+{$include card.inc}
+{$include dma.inc}
+{$include interrupts.inc}
+{$include ipc.inc}
+{$include memory.inc}
+{$include system.inc}
+{$include timers.inc}
+
+{$ifdef ARM9}
+ {$include arm9/background.inc}
+ {$include arm9/boxtest.inc}
+ {$include arm9/cache.inc}
+ {$include arm9/console.inc}
+ {$include arm9/exceptions.inc}
+ {$include arm9/image.inc}
+ {$include arm9/input.inc}
+ {$include arm9/math.inc}
+ {$include arm9/pcx.inc}
+ { $include nds/arm9/postest.inc} // da rimuovere
+ {$include arm9/rumble.inc}
+ {$include arm9/sound.inc}
+ {$include arm9/trig_lut.inc}
+ {$include arm9/video.inc}
+ {$include arm9/videoGL.inc}
+ {$include arm9/sprite.inc}
+{$endif ARM9}
+
+{$ifdef ARM7}
+ {$include arm7/audio.inc}
+ {$include arm7/clock.inc}
+ {$include arm7/serial.inc}
+ {$include arm7/touch.inc}
+{$endif ARM7}
+
+{$ifdef ARM7}
+ {$linklib libnds7.a}
+{$endif ARM7}
+{$ifdef ARM9}
+ {$linklib libnds9.a}
+{$endif ARM9}
+
+{$linklib libc.a}
+{$linklib libgcc.a}
+{$linklib libsysbase.a}
+
+{$endif NDS_INC}
+
diff --git a/packages/libndsfpc/src/nds/ndsinclude.inc b/packages/libndsfpc/src/nds/ndsinclude.inc
new file mode 100644
index 0000000000..485cc4856b
--- /dev/null
+++ b/packages/libndsfpc/src/nds/ndsinclude.inc
@@ -0,0 +1,39 @@
+
+{$include helper.inc}
+{$include jtypes.inc}
+{$include bios.inc}
+{$include card.inc}
+{$include dma.inc}
+{$include interrupts.inc}
+{$include ipc.inc}
+{$include memory.inc}
+{$include system.inc}
+{$include timers.inc}
+{$include reload.inc}
+
+{$ifdef ARM9}
+ {$include arm9/background.inc}
+ {$include arm9/boxtest.inc}
+ {$include arm9/cache.inc}
+ {$include arm9/console.inc}
+ {$include arm9/exceptions.inc}
+ {$include arm9/image.inc}
+ {$include arm9/input.inc}
+ {$include arm9/math.inc}
+ {$include arm9/ndsmotion.inc}
+ {$include arm9/pcx.inc}
+ {$include arm9/rumble.inc}
+ {$include arm9/sound.inc}
+ {$include arm9/sprite.inc}
+ {$include arm9/trig_lut.inc}
+ {$include arm9/video.inc}
+ {$include arm9/videoGL.inc}
+ {$include arm9/postest.inc}
+{$endif ARM9}
+
+{$ifdef ARM7}
+ {$include arm7/audio.inc}
+ {$include arm7/clock.inc}
+ {$include arm7/serial.inc}
+ {$include arm7/touch.inc}
+{$endif ARM7}
diff --git a/packages/libndsfpc/src/nds/registers_alt.inc b/packages/libndsfpc/src/nds/registers_alt.inc
new file mode 100644
index 0000000000..f63b197b96
--- /dev/null
+++ b/packages/libndsfpc/src/nds/registers_alt.inc
@@ -0,0 +1,309 @@
+(*
+ $Id: registers_alt.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ REG_DISPCNT : pcuint32 = pointer($4000000);
+
+{$ifdef ARM9}
+ WAIT_CR = REG_EXMEMCNT;
+{$else}
+ WAIT_CR = REG_EXMEMSTAT;
+{$endif}
+
+ DISP_SR = REG_DISPSTAT;
+ DISP_Y = REG_VCOUNT;
+
+ REG_BGCTRL : pcuint16 = pointer($4000008);
+ REG_BG0CNT : pcuint16 = pointer($4000008);
+ REG_BG1CNT : pcuint16 = pointer($400000A);
+ REG_BG2CNT : pcuint16 = pointer($400000C);
+ REG_BG3CNT : pcuint16 = pointer($400000E);
+
+ REG_BGOFFSETS : pcuint16 = pointer($4000010);
+ REG_BG0HOFS : pcuint16 = pointer($4000010);
+ REG_BG0VOFS : pcuint16 = pointer($4000012);
+ REG_BG1HOFS : pcuint16 = pointer($4000014);
+ REG_BG1VOFS : pcuint16 = pointer($4000016);
+ REG_BG2HOFS : pcuint16 = pointer($4000018);
+ REG_BG2VOFS : pcuint16 = pointer($400001A);
+ REG_BG3HOFS : pcuint16 = pointer($400001C);
+ REG_BG3VOFS : pcuint16 = pointer($400001E);
+
+ REG_BG2PA : pcuint16 = pointer($4000020);
+ REG_BG2PB : pcuint16 = pointer($4000022);
+ REG_BG2PC : pcuint16 = pointer($4000024);
+ REG_BG2PD : pcuint16 = pointer($4000026);
+
+ REG_BG2X : pcuint32 = pointer($4000028);
+ REG_BG2X_L : pcuint16 = pointer($4000028);
+ REG_BG2X_H : pcuint16 = pointer($400002A);
+
+ REG_BG2Y : pcuint32 = pointer($400002C);
+ REG_BG2Y_L : pcuint16 = pointer($400002C);
+ REG_BG2Y_H : pcuint16 = pointer($400002E);
+
+ REG_BG3PA : pcuint16 = pointer($4000030);
+ REG_BG3PB : pcuint16 = pointer($4000032);
+ REG_BG3PC : pcuint16 = pointer($4000034);
+ REG_BG3PD : pcuint16 = pointer($4000036);
+
+ REG_BG3X : pcuint32 = pointer($4000038);
+ REG_BG3X_L : pcuint16 = pointer($4000038);
+ REG_BG3X_H : pcuint16 = pointer($400003A);
+ REG_BG3Y : pcuint32 = pointer($400003C);
+ REG_BG3Y_L : pcuint16 = pointer($400003C);
+ REG_BG3Y_H : pcuint16 = pointer($400003E);
+
+ REG_WIN0H : pcuint16 = pointer($4000040);
+ REG_WIN1H : pcuint16 = pointer($4000042);
+ REG_WIN0V : pcuint16 = pointer($4000044);
+ REG_WIN1V : pcuint16 = pointer($4000046);
+ REG_WININ : pcuint16 = pointer($4000048);
+ REG_WINOUT : pcuint16 = pointer($400004A);
+
+ REG_MOSAIC : pcuint32 = pointer($400004C);
+ REG_MOSAIC_L : pcuint32 = pointer($400004C);
+ REG_MOSAIC_H : pcuint32 = pointer($400004E);
+
+ REG_BLDMOD : pcuint16 = pointer($4000050);
+ REG_COLV : pcuint16 = pointer($4000052);
+ REG_COLY : pcuint16 = pointer($4000054);
+
+ SERIAL_CR = REG_SPICNT;
+ SERIAL_DATA = REG_SPIDATA;
+ SIO_CR = REG_SIOCNT;
+ R_CR = REG_RCNT;
+
+ (* secondary screen *)
+ REG_DISPCNT_SUB : pcuint32 = pointer($4001000);
+ REG_BGCTRL_SUB : pcuint16 = pointer($4001008);
+ REG_BG0CNT_SUB : pcuint16 = pointer($4001008);
+ REG_BG1CNT_SUB : pcuint16 = pointer($400100A);
+ REG_BG2CNT_SUB : pcuint16 = pointer($400100C);
+ REG_BG3CNT_SUB : pcuint16 = pointer($400100E);
+
+ REG_BGOFFSETS_SUB : pcuint16 = pointer($4001010);
+ REG_BG0HOFS_SUB : pcuint16 = pointer($4001010);
+ REG_BG0VOFS_SUB : pcuint16 = pointer($4001012);
+ REG_BG1HOFS_SUB : pcuint16 = pointer($4001014);
+ REG_BG1VOFS_SUB : pcuint16 = pointer($4001016);
+ REG_BG2HOFS_SUB : pcuint16 = pointer($4001018);
+ REG_BG2VOFS_SUB : pcuint16 = pointer($400101A);
+ REG_BG3HOFS_SUB : pcuint16 = pointer($400101C);
+ REG_BG3VOFS_SUB : pcuint16 = pointer($400101E);
+
+ REG_BG2PA_SUB : pcuint16 = pointer($4001020);
+ REG_BG2PB_SUB : pcuint16 = pointer($4001022);
+ REG_BG2PC_SUB : pcuint16 = pointer($4001024);
+ REG_BG2PD_SUB : pcuint16 = pointer($4001026);
+
+ REG_BG2X_SUB : pcuint32 = pointer($4001028);
+ REG_BG2Y_SUB : pcuint32 = pointer($400102C);
+
+ REG_BG3PA_SUB : pcuint16 = pointer($4001030);
+ REG_BG3PB_SUB : pcuint16 = pointer($4001032);
+ REG_BG3PC_SUB : pcuint16 = pointer($4001034);
+ REG_BG3PD_SUB : pcuint16 = pointer($4001036);
+
+ REG_BG3X_SUB : pcuint32 = pointer($4001038);
+ REG_BG3X_L_SUB : pcuint16 = pointer($4001038);
+ REG_BG3X_H_SUB : pcuint16 = pointer($400103A);
+ REG_BG3Y_SUB : pcuint32 = pointer($400103C);
+ REG_BG3Y_L_SUB : pcuint16 = pointer($400103C);
+ REG_BG3Y_H_SUB : pcuint16 = pointer($400103E);
+
+ REG_WIN0H_SUB : pcuint16 = pointer($4001040);
+ REG_WIN1H_SUB : pcuint16 = pointer($4001042);
+ REG_WIN0V_SUB : pcuint16 = pointer($4001044);
+ REG_WIN1V_SUB : pcuint16 = pointer($4001046);
+ REG_WININ_SUB : pcuint16 = pointer($4001048);
+ REG_WINOUT_SUB : pcuint16 = pointer($400104A);
+
+ REG_MOSAIC_SUB : pcuint32 = pointer($400104C);
+ REG_MOSAIC_L_SUB : pcuint32 = pointer($400104C);
+ REG_MOSAIC_H_SUB : pcuint32 = pointer($400104E);
+
+ REG_BLDMOD_SUB : pcuint16 = pointer($4001050);
+ REG_COLV_SUB : pcuint16 = pointer($4001052);
+ REG_COLY_SUB : pcuint16 = pointer($4001054);
+
+ (*common*)
+ REG_DMA : pcuint32 = pointer($40000B0);
+
+ REG_DMA0SAD : pcuint32 = pointer($40000B0);
+ REG_DMA0SAD_L : pcuint16 = pointer($40000B0);
+ REG_DMA0SAD_H : pcuint16 = pointer($40000B2);
+ REG_DMA0DAD : pcuint32 = pointer($40000B4);
+ REG_DMA0DAD_L : pcuint16 = pointer($40000B4);
+ REG_DMA0DAD_H : pcuint16 = pointer($40000B6);
+ REG_DMA0CNT : pcuint32 = pointer($40000B8);
+ REG_DMA0CNT_L : pcuint16 = pointer($40000B8);
+ REG_DMA0CNT_H : pcuint16 = pointer($40000BA);
+
+ REG_DMA1SAD : pcuint32 = pointer($40000BC);
+ REG_DMA1SAD_L : pcuint16 = pointer($40000BC);
+ REG_DMA1SAD_H : pcuint16 = pointer($40000BE);
+ REG_DMA1DAD : pcuint32 = pointer($40000C0);
+ REG_DMA1DAD_L : pcuint16 = pointer($40000C0);
+ REG_DMA1DAD_H : pcuint16 = pointer($40000C2);
+ REG_DMA1CNT : pcuint32 = pointer($40000C4);
+ REG_DMA1CNT_L : pcuint16 = pointer($40000C4);
+ REG_DMA1CNT_H : pcuint16 = pointer($40000C6);
+
+ REG_DMA2SAD : pcuint32 = pointer($40000C8);
+ REG_DMA2SAD_L : pcuint16 = pointer($40000C8);
+ REG_DMA2SAD_H : pcuint16 = pointer($40000CA);
+ REG_DMA2DAD : pcuint32 = pointer($40000CC);
+ REG_DMA2DAD_L : pcuint16 = pointer($40000CC);
+ REG_DMA2DAD_H : pcuint16 = pointer($40000CE);
+ REG_DMA2CNT : pcuint32 = pointer($40000D0);
+ REG_DMA2CNT_L : pcuint16 = pointer($40000D0);
+ REG_DMA2CNT_H : pcuint16 = pointer($40000D2);
+
+ REG_DMA3SAD : pcuint32 = pointer($40000D4);
+ REG_DMA3SAD_L : pcuint16 = pointer($40000D4);
+ REG_DMA3SAD_H : pcuint16 = pointer($40000D6);
+ REG_DMA3DAD : pcuint32 = pointer($40000D8);
+ REG_DMA3DAD_L : pcuint16 = pointer($40000D8);
+ REG_DMA3DAD_H : pcuint16 = pointer($40000DA);
+ REG_DMA3CNT : pcuint32 = pointer($40000DC);
+ REG_DMA3CNT_L : pcuint16 = pointer($40000DC);
+ REG_DMA3CNT_H : pcuint16 = pointer($40000DE);
+
+ REG_TIME : pcuint16 = pointer($4000100);
+ REG_TM0D : pcuint16 = pointer($4000100);
+ REG_TM0CNT : pcuint16 = pointer($4000102);
+ REG_TM1D : pcuint16 = pointer($4000106);
+ REG_TM2D : pcuint16 = pointer($4000108);
+ REG_TM2CNT : pcuint16 = pointer($400010A);
+ REG_TM3D : pcuint16 = pointer($400010C);
+ REG_TM3CNT : pcuint16 = pointer($400010E);
+
+
+ REG_SIOCNT : pcuint16 = pointer($4000128);
+ REG_SIOMLT_SEND : pcuint16 = pointer($400012A);
+
+ KEYS = REG_KEYINPUT;
+ KEYS_CR = REG_KEYCNT;
+ //???
+ REG_RCNT : pcuint16 = pointer($4000134);
+ REG_HS_CTRL : pcuint16 = pointer($4000140);
+
+ (* Interupt enable registers *)
+ IE = REG_IE;
+ _IF = REG_IF;
+ IME = REG_IME;
+
+ (*controls power 0x30f is all on *)
+ POWER_CR = REG_POWERCNT;
+
+ (* ram controllers 0x8 is enabled, other bits have to do with mapping *)
+ REG_VRAM_A_CR : pcuint8 = pointer($4000240);
+ REG_VRAM_B_CR : pcuint8 = pointer($4000241);
+ REG_VRAM_C_CR : pcuint8 = pointer($4000242);
+ REG_VRAM_D_CR : pcuint8 = pointer($4000243);
+ REG_VRAM_E_CR : pcuint8 = pointer($4000244);
+ REG_VRAM_F_CR : pcuint8 = pointer($4000245);
+ REG_VRAM_G_CR : pcuint8 = pointer($4000246);
+ REG_VRAM_H_CR : pcuint8 = pointer($4000248);
+ REG_VRAM_I_CR : pcuint8 = pointer($4000249);
+ REG_WRAM_CNT : pcuint8 = pointer($4000247);
+
+
+
+
+ (*3D graphics suff*)
+ REG_GFX_FIFO : pcuint32 = pointer($4000400);
+ REG_GFX_STATUS : pcuint32 = pointer($4000600);
+ REG_GFX_CONTROL : pcuint16 = pointer($4000060);
+ REG_COLOR : pcuint32 = pointer($4000480);
+ REG_VERTEX16 : pcuint32 = pointer($400048C);
+ REG_TEXT_COORD : pcuint32 = pointer($4000488);
+ REG_TEXT_FORMAT : pcuint32 = pointer($40004A8);
+
+
+ REG_CLEAR_COLOR : pcuint32 = pointer($4000350);
+ REG_CLEAR_DEPTH : pcuint16 = pointer($4000354);
+
+ REG_LIGHT_VECTOR : pcuint32 = pointer($40004C8);
+ REG_LIGHT_COLOR : pcuint32 = pointer($40004CC);
+ REG_NORMAL : pcuint32 = pointer($4000484);
+
+ REG_DIFFUSE_AMBIENT : pcuint32 = pointer($40004C0);
+ REG_SPECULAR_EMISSION : pcuint32 = pointer($40004C4);
+ REG_SHININESS : pcuint32 = pointer($40004D0);
+
+ REG_POLY_FORMAT : pcuint32 = pointer($40004A4);
+
+ REG_GFX_BEGIN : pcuint32 = pointer($4000500);
+ REG_GFX_END : pcuint32 = pointer($4000504);
+ REG_GFX_FLUSH : pcuint32 = pointer($4000540);
+ REG_GFX_VIEWPORT : pcuint32 = pointer($4000580);
+
+ REG_MTX_CONTROL : pcuint32 = pointer($4000440);
+ REG_MTX_PUSH : pcuint32 = pointer($4000444);
+ REG_MTX_POP : pcuint32 = pointer($4000448);
+ REG_MTX_SCALE : pcint32 = pointer($400046C);
+ REG_MTX_TRANSLATE : pcint32 = pointer($4000470);
+ REG_MTX_RESTORE : pcuint32 = pointer($4000450);
+ REG_MTX_STORE : pcuint32 = pointer($400044C);
+ REG_MTX_IDENTITY : pcuint32 = pointer($4000454);
+ REG_MTX_LOAD4x4 : ^f32 = pointer($4000458);
+ REG_MTX_LOAD4x3 : ^f32 = pointer($400045C);
+ REG_MTX_MULT4x4 : ^f32 = pointer($4000460);
+ REG_MTX_MULT4x3 : ^f32 = pointer($4000464);
+ REG_MTX_MULT3x3 : ^f32 = pointer($4000468);
+
+ // Card bus
+
+ REG_CARD_CR1 : pcuint32 = pointer($040001A0);
+ REG_CARD_CR1H : pcuint8 = pointer($040001A1);
+ REG_CARD_CR2 : pcuint32 = pointer($040001A4);
+ REG_CARD_COMMAND : pcuint8 = pointer($040001A8);
+
+ 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);
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/reload.inc b/packages/libndsfpc/src/nds/reload.inc
new file mode 100644
index 0000000000..2af937abb8
--- /dev/null
+++ b/packages/libndsfpc/src/nds/reload.inc
@@ -0,0 +1,84 @@
+(*
+ $Id: reload.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+type
+ COPYFUNC = function (const value: pcchar): pointer;
+ QUERYFUNC = function(value: cuint32): pcuint32;
+
+ LOADER_DATA = record
+ VERSION: cuint32; // contains version information about loader
+ QUERY: QUERYFUNC; // used to retreive extended information from loader
+ ARM7FUNC: COPYFUNC; // a pointer to the ARM7 load function
+ ARM9FUNC: COPYFUNC; // a pointer to the ARM9 load function
+ PATH: pcchar; // THIS VALUE IS SET FOR YOU, DONT TOUCH IT
+ RESERVED: cuint32; // reserved for future expansion
+ end;
+ TLOADER_DATA = LOADER_DATA;
+ PLOADER_DATA = ^LOADER_DATA;
+
+const
+ LOADNDS : PLOADER_DATA = pointer($02800000-48);
+ BOOT_NDS = pcchar(-1);
+{$endif NDS_INTERFACE}
+
+
+
+(*
+dump this near the begining of your ARM7's main function
+
+LOADNDS->PATH = 0;
+
+
+inside of your ARM7's main loop or VBlank IRQ or what-ever, add this code:
+
+if (LOADNDS->PATH != 0) {
+ LOADNDS->ARM7FUNC(LOADNDS->PATH);
+}
+
+
+//////////////////////////////////////
+
+in your ARM9 code, to return to the menu, call this function:
+
+WAIT_CR &= ~0x8080;
+LOADNDS->ARM9FUNC(BOOT_NDS);
+
+*)
diff --git a/packages/libndsfpc/src/nds/system.inc b/packages/libndsfpc/src/nds/system.inc
new file mode 100644
index 0000000000..34edb63c0c
--- /dev/null
+++ b/packages/libndsfpc/src/nds/system.inc
@@ -0,0 +1,225 @@
+(*
+ $Id: system.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+const
+ REG_DISPSTAT : pcuint16 = pointer($04000004);
+ DISP_IN_VBLANK = (1 shl 0);
+ DISP_IN_HBLANK = (1 shl 1);
+ DISP_YTRIGGERED = (1 shl 2);
+ DISP_VBLANK_IRQ = (1 shl 3);
+ DISP_HBLANK_IRQ = (1 shl 4);
+ DISP_YTRIGGER_IRQ = (1 shl 5);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+procedure SetYtrigger(Yvalue: cint); inline;
+begin
+ REG_DISPSTAT^ := (REG_DISPSTAT^ and $007F ) or (Yvalue shl 8) or (( Yvalue and $100 ) shr 2);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ REG_VCOUNT : pcuint16 = pointer($04000006);
+ HALT_CR : pcuint16 = pointer($04000300);
+ REG_POWERCNT : pcuint16 = pointer($04000304);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+procedure powerON(Aon: cint); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ or Aon;
+end;
+
+procedure powerSET(Aon: cint); inline;
+begin
+ REG_POWERCNT^ := Aon;
+end;
+
+procedure powerOFF(off: cint); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ and (not off);
+end;
+{$endif NDS_IMPLEMENTATION}
+
+
+{$ifdef ARM9}
+{$ifdef NDS_INTERFACE}
+{$ifdef DOXYGEN}
+type
+ ARM9_power = cint;
+const
+ POWER_LCD : ARM9_power = 0;
+ POWER_2D_A : ARM9_power = 1;
+ POWER_MATRIX : ARM9_power = 2;
+ POWER_3D_CORE : ARM9_power = 3;
+ POWER_2D_B : ARM9_power = 4;
+ POWER_SWAP_LCDS : ARM9_power = 5;
+{$else DOXYGEN}
+const
+ POWER_LCD = (1 shl 0);
+ POWER_2D_A = (1 shl 1);
+ POWER_MATRIX = (1 shl 2);
+ POWER_3D_CORE = (1 shl 3);
+ POWER_2D_B = (1 shl 9);
+ POWER_SWAP_LCDS = (1 shl 15);
+ POWER_ALL_2D = (POWER_LCD or POWER_2D_A or POWER_2D_B);
+ POWER_ALL = (POWER_ALL_2D or POWER_3D_CORE or POWER_MATRIX);
+{$endif DOXYGEN}
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+procedure lcdSwap(); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ xor POWER_SWAP_LCDS;
+end;
+
+procedure lcdMainOnTop(); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ or cint(POWER_SWAP_LCDS);
+end;
+
+procedure lcdMainOnBottom(); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS));
+end;
+{$endif NDS_IMPLEMENTATION}
+{$endif ARM9}
+
+{$ifdef ARM7}
+{$ifdef NDS_INTERFACE}
+{$ifdef DOXYGEN}
+type
+ ARM7_power = cint;
+const
+ POWER_SOUND: ARM7_power = 0;
+ POWER_UNKNOWN: ARM7_power = 1;
+{$else DOXYGEN}
+const
+ POWER_SOUND = (1 shl 0);
+ POWER_UNKNOWN = (1 shl 1);
+{$endif DOXYGEN}
+procedure readUserSettings(); cdecl; external;
+{$endif NDS_INTERFACE}
+{$endif ARM7}
+
+
+{$ifdef NDS_INTERFACE}
+type
+ tPERSONAL_DATA = bitpacked record
+ RESERVED0: array [0..1] of cuint8;
+
+ theme: cuint8;
+ birthMonth: cuint8;
+ birthDay: cuint8;
+
+ RESERVED1: array [0..0] of cuint8;
+
+ name: array [0..9] of cint16;
+ nameLen: cuint16;
+
+ message: array [0..25] of cint16;
+ messageLen: cuint16;
+
+ alarmHour: cuint8;
+ alarmMinute: cuint8;
+
+ RESERVED2: array [0..3] of cuint8;
+
+ calX1: cuint16;
+ calY1: cuint16;
+ calX1px: cuint8;
+ calY1px: cuint8;
+
+ calX2: cuint16;
+ calY2: cuint16;
+ calX2px: cuint8;
+ calY2px: cuint8;
+
+
+ _user_data: packed record
+ language: 0..3;
+ gbaScreen: 0..1;
+ defaultBrightness: 0..2;
+ autoMode: 0..1;
+ RESERVED4: 0..1;
+ settingsLost: 0..1;
+ RESERVED2: 0..6;
+ end;
+ RESERVED3: cuint16;
+ rtcOffset: cuint32;
+ RESERVED4: cuint32;
+ end;
+ PERSONAL_DATA = tPERSONAL_DATA;
+ PPERSONAL_DATA = ^tPERSONAL_DATA;
+
+const
+ REG_KEYINPUT : pcuint16 = pointer($04000130);
+ REG_KEYCNT : pcuint16 = pointer($04000132);
+ PersonalData : PPERSONAL_DATA = pointer($27FFC80);
+
+
+type
+ __argv = record
+ argvMagic: cint; // argv magic number, set to 0x5f617267 ('_arg') if valid
+ commandLine: pcchar; // base address of command line, set of null terminated strings
+ length: cint; // total length of command line
+ end;
+ Targv = __argv;
+ Pargv = ^Targv;
+
+const
+ libnds_argv: Pargv = pointer($027FFF70);
+ argvMagic = $5f617267;
+{$endif NDS_INTERFACE}
+
+
+{$ifdef NDS_INTERFACE}
+procedure SetYtrigger(Yvalue: cint); inline;
+procedure powerON(Aon: cint); inline;
+procedure powerSET(Aon: cint); inline;
+procedure powerOFF(off: cint); inline;
+{$ifdef ARM9}
+procedure lcdSwap(); inline;
+procedure lcdMainOnTop(); inline;
+procedure lcdMainOnBottom(); inline;
+{$endif ARM9}
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds/timers.inc b/packages/libndsfpc/src/nds/timers.inc
new file mode 100644
index 0000000000..2a601812d1
--- /dev/null
+++ b/packages/libndsfpc/src/nds/timers.inc
@@ -0,0 +1,130 @@
+(*
+ $Id: timers.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+ ------------------------------------------------------------------------------
+ Copyright (C) 2005
+ Jason Rogers (dovoto)
+ Dave Murphy (WinterMute)
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you use
+ this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+ ------------------------------------------------------------------------------
+
+
+ Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+ (http://www.freepascal.org)
+
+ Copyright (C) 2006 Francesco Lombardi
+ Check http://sourceforge.net/projects/libndsfpc for updates
+
+ ------------------------------------------------------------------------------
+
+ $Log$
+
+*)
+
+{$ifdef NDS_IMPLEMENTATION}
+function TIMER_FREQ(n: cint): cint; inline;
+begin
+ TIMER_FREQ := cint(-$2000000 div (n));
+end;
+
+function TIMER_FREQ_64(n: cint): cint; inline;
+begin
+ TIMER_FREQ_64 := cint(-($2000000 shr 6) div (n));
+end;
+
+function TIMER_FREQ_256(n: cint): cint; inline;
+begin
+ TIMER_FREQ_256 := cint(-($2000000 shr 8) div (n));
+end;
+
+function TIMER_FREQ_1024(n: cint): cint; inline;
+begin
+ TIMER_FREQ_1024 := cint(-($2000000 shr 10) div (n));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ //! Same as %TIMER_DATA(0).
+ TIMER0_DATA : pcuint16 = pointer($04000100);
+ //! Same as %TIMER_DATA(1).
+ TIMER1_DATA : pcuint16 = pointer($04000104);
+ //! Same as %TIMER_DATA(2).
+ TIMER2_DATA : pcuint16 = pointer($04000108);
+ //! Same as %TIMER_DATA(3).
+ TIMER3_DATA : pcuint16 = pointer($0400010C);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function TIMER_DATA(n: cuint): pcuint16; inline;
+begin
+ TIMER_DATA := pcuint16($04000100 + (n shl 2));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+// Timer control registers
+ //! Same as %TIMER_CR(0).
+ TIMER0_CR : pcuint16 = pointer($04000102);
+ //! Same as %TIMER_CR(1).
+ TIMER1_CR : pcuint16 = pointer($04000106);
+ //! Same as %TIMER_CR(2).
+ TIMER2_CR : pcuint16 = pointer($0400010A);
+ //! Same as %TIMER_CR(3).
+ TIMER3_CR : pcuint16 = pointer($0400010E);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_IMPLEMENTATION}
+function TIMER_CR(n: cint): pcuint16; inline;
+begin
+ TIMER_CR := pcuint16($04000102 + (n shl 2));
+end;
+{$endif NDS_IMPLEMENTATION}
+
+{$ifdef NDS_INTERFACE}
+const
+ //! Enables the timer.
+ TIMER_ENABLE = (1 shl 7);
+
+ //! Causes the timer to request an Interupt on overflow.
+ TIMER_IRQ_REQ = (1 shl 6);
+
+ //! When set will cause the timer to count when the timer below overflows (unavailable for timer 0).
+ TIMER_CASCADE = (1 shl 2);
+
+ //! Causes the timer to count at 33.514Mhz.
+ TIMER_DIV_1 = (0);
+ //! Causes the timer to count at (33.514 / 64) Mhz.
+ TIMER_DIV_64 = (1);
+ //! Causes the timer to count at (33.514 / 256) Mhz.
+ TIMER_DIV_256 = (2);
+ //! Causes the timer to count at (33.514 / 1024)Mhz.
+ TIMER_DIV_1024 = (3);
+{$endif NDS_INTERFACE}
+
+{$ifdef NDS_INTERFACE}
+function TIMER_FREQ(n: cint): cint; inline;
+function TIMER_FREQ_64(n: cint): cint; inline;
+function TIMER_FREQ_256(n: cint): cint; inline;
+function TIMER_FREQ_1024(n: cint): cint; inline;
+function TIMER_DATA(n: cuint): pcuint16; inline;
+function TIMER_CR(n: cint): pcuint16; inline;
+{$endif NDS_INTERFACE}
diff --git a/packages/libndsfpc/src/nds7.pp b/packages/libndsfpc/src/nds7.pp
new file mode 100644
index 0000000000..4318e0754b
--- /dev/null
+++ b/packages/libndsfpc/src/nds7.pp
@@ -0,0 +1,32 @@
+unit nds7;
+{$mode objfpc}
+{$apptype arm7}
+{$define arm7}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes;
+
+{$linklib nds7}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include nds/ndsinclude.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+
+{$define NDS_IMPLEMENTATION}
+{$include nds/ndsinclude.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.
diff --git a/packages/libndsfpc/src/nds9.pp b/packages/libndsfpc/src/nds9.pp
new file mode 100644
index 0000000000..540fc72aa4
--- /dev/null
+++ b/packages/libndsfpc/src/nds9.pp
@@ -0,0 +1,32 @@
+unit nds9;
+{$mode objfpc}
+{$apptype arm9}
+{$define arm9}
+
+{$J+}
+{$INLINE ON}
+{$MACRO ON}
+{$PACKRECORDS C}
+
+interface
+
+uses
+ ctypes;
+
+{$linklib nds9}
+
+{$linklib c}
+{$linklib gcc}
+{$linklib sysbase}
+
+{$define NDS_INTERFACE}
+{$include nds/ndsinclude.inc}
+{$undef NDS_INTERFACE}
+
+implementation
+
+{$define NDS_IMPLEMENTATION}
+{$include nds/ndsinclude.inc}
+{$undef NDS_IMPLEMENTATION}
+
+end.