summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src/nds/arm7
diff options
context:
space:
mode:
Diffstat (limited to 'packages/libndsfpc/src/nds/arm7')
-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
4 files changed, 558 insertions, 0 deletions
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}