summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src/nds/system.inc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/libndsfpc/src/nds/system.inc')
-rw-r--r--packages/libndsfpc/src/nds/system.inc218
1 files changed, 147 insertions, 71 deletions
diff --git a/packages/libndsfpc/src/nds/system.inc b/packages/libndsfpc/src/nds/system.inc
index bfc498109f..d2d440d25d 100644
--- a/packages/libndsfpc/src/nds/system.inc
+++ b/packages/libndsfpc/src/nds/system.inc
@@ -41,89 +41,112 @@
{$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}
+
+type
+ DISP_BITS = cint;
const
+ DISP_IN_VBLANK : DISP_BITS = (1 shl 0);
+ DISP_IN_HBLANK : DISP_BITS = (1 shl 1);
+ DISP_YTRIGGERED : DISP_BITS = (1 shl 2);
+ DISP_VBLANK_IRQ : DISP_BITS = (1 shl 3);
+ DISP_HBLANK_IRQ : DISP_BITS = (1 shl 4);
+ DISP_YTRIGGER_IRQ : DISP_BITS = (1 shl 5);
+
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 SetYtrigger(Yvalue: cint); inline;
-procedure powerSET(Aon: cint); inline;
-begin
- REG_POWERCNT^ := Aon;
-end;
+const
+ PM_ARM9_DIRECT = (1 shl 16);
-procedure powerOFF(off: cint); inline;
-begin
- REG_POWERCNT^ := REG_POWERCNT^ and (not off);
-end;
-{$endif NDS_IMPLEMENTATION}
+type
+ PM_Bits = cint;
+const
+ PM_SOUND_AMP : PM_Bits = (1 shl 0);
+ PM_SOUND_MUTE : PM_Bits = (1 shl 1);
+ PM_BACKLIGHT_BOTTOM : PM_Bits = (1 shl 2);
+ PM_BACKLIGHT_TOP : PM_Bits = (1 shl 3);
+ PM_SYSTEM_PWR : PM_Bits = (1 shl 6);
+
+ POWER_LCD : PM_Bits = PM_ARM9_DIRECT or (1 shl 0);
+ POWER_2D_A : PM_Bits = PM_ARM9_DIRECT or (1 shl 1);
+ POWER_MATRIX : PM_Bits = PM_ARM9_DIRECT or (1 shl 2);
+ POWER_3D_CORE : PM_Bits = PM_ARM9_DIRECT or (1 shl 3);
+ POWER_2D_B : PM_Bits = PM_ARM9_DIRECT or (1 shl 9);
+ POWER_SWAP_LCDS: PM_Bits = PM_ARM9_DIRECT or (1 shl 15);
+ POWER_ALL_2D : PM_Bits = PM_ARM9_DIRECT or (1 shl 0) or (1 shl 1) or (1 shl 9);
+ POWER_ALL : PM_Bits = PM_ARM9_DIRECT or (1 shl 0) or (1 shl 1) or (1 shl 9) or (1 shl 3) or (1 shl 2);
+procedure sleep(); cdecl; external;
{$ifdef ARM9}
-{$ifdef NDS_INTERFACE}
-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 NDS_INTERFACE}
+procedure powerOn(bits: PM_Bits); cdecl; external;
+procedure powerOff(bits: PM_Bits); cdecl; external;
+procedure ledBlink(bm: PM_LedBlinkMode); cdecl; external;
-{$ifdef NDS_IMPLEMENTATION}
-procedure lcdSwap(); inline;
-begin
- REG_POWERCNT^ := REG_POWERCNT^ xor POWER_SWAP_LCDS;
-end;
+procedure systemMsgHandler(bytes: cint; user_data: pointer); cdecl; external;
+procedure powerValueHandler(value: cuint32; data: pointer); cdecl; external;
+procedure lcdSwap(); inline;
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}
+
+
+procedure setVectorBase(highVector: cint); cdecl; external;
+
+type
+ sysVectors_t = packed record
+ reset: cuint32;
+ undefined: cuint32;
+ swi: cuint32;
+ prefetch_abort: cuint32;
+ data_abort: cuint32;
+ fiq: cuint32;
+ end;
+ sysVectors = sysVectors_t;
+ PsysVectors = ^sysVectors;
+
+var
+ SystemVectors: sysVectors; cvar; external;
+
{$endif ARM9}
+
{$ifdef ARM7}
-{$ifdef NDS_INTERFACE}
+type
+ ARM7_power = cint;
const
- POWER_SOUND = (1 shl 0);
- POWER_UNKNOWN = (1 shl 1);
+ POWER_SOUND : ARM7_power = (1 shl 0);
+ PM_CONTROL_REG : ARM7_power = 0;
+ PM_BATTERY_REG : ARM7_power = 1;
+ PM_AMPLIFIER_REG: ARM7_power = 2;
+ PM_READ_REGISTER: ARM7_power = (1 shl 7);
+ PM_AMP_OFFSET : ARM7_power = 2;
+ PM_GAIN_OFFSET : ARM7_power = 3;
+ PM_GAIN_20 : ARM7_power = 0;
+ PM_GAIN_40 : ARM7_power = 1;
+ PM_GAIN_80 : ARM7_power = 2;
+ PM_GAIN_160 : ARM7_power = 3;
+ PM_AMP_ON : ARM7_power = 1;
+ PM_AMP_OFF : ARM7_power = 0;
+
+function PM_LED_CONTROL(m: cint): cint; inline;
+
+procedure installSystemFIFO(); cdecl; external;
+procedure systemSleep(); cdecl; external;
+function sleepEnabled(): cint; cdecl; external;
+function writePowerManagement(reg, command: cint): cint; cdecl; external;
+
+function readPowerManagement(reg: cint): cint; inline;
+
+procedure powerOn(bits: PM_Bits); inline;
+procedure powerOff(bits: PM_Bits); inline;
procedure readUserSettings(); cdecl; external;
-{$endif NDS_INTERFACE}
{$endif ARM7}
-
-{$ifdef NDS_INTERFACE}
type
tPERSONAL_DATA = bitpacked record
RESERVED0: array [0..1] of cuint8;
@@ -161,7 +184,7 @@ type
gbaScreen: 0..1;
defaultBrightness: 0..2;
autoMode: 0..1;
- RESERVED4: 0..1;
+ RESERVED1: 0..2;
settingsLost: 0..1;
RESERVED2: 0..6;
end;
@@ -179,28 +202,81 @@ const
type
+ ppcchar = ^pcchar;
__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
+ argc: integer;
+ argv: ppcchar;
end;
Targv = __argv;
Pargv = ^Targv;
const
- libnds_argv: Pargv = pointer($027FFF70);
- argvMagic = $5f617267;
+ __system_argv: Pargv = pointer($027FFF70);
+ ARGV_MAGIC = $5f617267;
+
+
+type
+ RTCtime = packed record
+ year: cuint8; // add 2000 to get 4 digit year
+ month: cuint8; // 1 to 12
+ day: cuint8; // 1 to (days in month)
+ weekday: cuint8; // day of week
+ hours: cuint8; // 0 to 11 for AM, 52 to 63 for PM
+ minutes: cuint8; // 0 to 59
+ seconds: cuint8; // 0 to 59
+ padding: cuint8;
+ end;
+
{$endif NDS_INTERFACE}
+{$ifdef NDS_IMPLEMENTATION}
-{$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}
+begin
+ REG_DISPSTAT^ := (REG_DISPSTAT^ and $007F ) or (Yvalue shl 8) or (( Yvalue and $100 ) shr 1);
+end;
+
+{$ifdef ARM9}
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;
-{$endif ARM9}
-{$endif NDS_INTERFACE}
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS));
+end;
+{$endif ARM9}
+
+
+{$ifdef ARM7}
+function PM_LED_CONTROL(m: cint): cint; inline;
+begin
+ result := (m) shl 4;
+end;
+
+function readPowerManagement(reg: cint): cint; inline;
+begin
+ result := writePowerManagement(reg or PM_READ_REGISTER, 0);
+end;
+
+procedure powerOn(bits: PM_Bits); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ or bits;
+end;
+
+procedure powerOff(bits: PM_Bits); inline;
+begin
+ REG_POWERCNT^ := REG_POWERCNT^ and not bits;
+end;
+{$endif ARM7}
+{$endif NDS_IMPLEMENTATION}
+