PageRenderTime 56ms CodeModel.GetById 18ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

/packages/libndsfpc/src/nds/system.inc

https://github.com/slibre/freepascal
Pascal | 305 lines | 212 code | 66 blank | 27 comment | 0 complexity | 02bb1faf775b5eeb3379eb7b498994a7 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
  1{$ifdef NDS_INTERFACE}
  2const
  3  REG_DISPSTAT	: pcuint16 = pointer($04000004);
  4  
  5type
  6  DISP_BITS = cint;
  7const
  8  DISP_IN_VBLANK    : DISP_BITS = (1 shl 0);
  9  DISP_IN_HBLANK    : DISP_BITS = (1 shl 1);
 10  DISP_YTRIGGERED   : DISP_BITS = (1 shl 2);
 11  DISP_VBLANK_IRQ   : DISP_BITS = (1 shl 3);
 12  DISP_HBLANK_IRQ   : DISP_BITS = (1 shl 4);
 13  DISP_YTRIGGER_IRQ : DISP_BITS = (1 shl 5);
 14
 15  REG_VCOUNT		: pcuint16 = pointer($04000006);
 16  HALT_CR       : pcuint16 = pointer($04000300);
 17  REG_POWERCNT  : pcuint16 = pointer($04000304);
 18  REG_DSIMODE		: pcuint32 = pointer($04004000);  
 19
 20procedure SetYtrigger(Yvalue: cint); inline;
 21
 22const
 23  PM_ARM9_DIRECT = (1 shl 16);
 24
 25type
 26  PM_Bits = cint;
 27const
 28	PM_SOUND_AMP         : PM_Bits = (1 shl 0);
 29	PM_SOUND_MUTE        : PM_Bits = (1 shl 1);
 30	PM_BACKLIGHT_BOTTOM  : PM_Bits = (1 shl 2);
 31	PM_BACKLIGHT_TOP     : PM_Bits = (1 shl 3);
 32	PM_SYSTEM_PWR        : PM_Bits = (1 shl 6);
 33
 34	POWER_LCD      : PM_Bits = PM_ARM9_DIRECT or (1 shl 0);
 35	POWER_2D_A     : PM_Bits = PM_ARM9_DIRECT or (1 shl 1);
 36	POWER_MATRIX   : PM_Bits = PM_ARM9_DIRECT or (1 shl 2);
 37	POWER_3D_CORE  : PM_Bits = PM_ARM9_DIRECT or (1 shl 3);
 38	POWER_2D_B     : PM_Bits = PM_ARM9_DIRECT or (1 shl 9);
 39	POWER_SWAP_LCDS: PM_Bits = PM_ARM9_DIRECT or (1 shl 15);
 40//	POWER_ALL_2D   : PM_Bits = PM_ARM9_DIRECT or POWER_LCD or POWER_2D_A or POWER_2D_B;
 41	POWER_ALL_2D   : PM_Bits = (1 shl 16) or (1 shl 0) or (1 shl 1) or (1 shl 9);
 42//	POWER_ALL      : PM_Bits = PM_ARM9_DIRECT or POWER_ALL_2D or POWER_3D_CORE or POWER_MATRIX;
 43	POWER_ALL      : PM_Bits = (1 shl 16) or (1 shl 0) or (1 shl 1) or (1 shl 9) or (1 shl 3) or (1 shl 2);
 44
 45//procedure SystemSleep(); cdecl; external;
 46procedure ledBlink(bm: cint); cdecl; external;
 47
 48{$ifdef ARM9}
 49procedure SystemSleep(); cdecl; external;
 50procedure powerOn(bits: cint); cdecl; external;
 51procedure powerOff(bits: cint); cdecl; external;
 52
 53procedure systemMsgHandler(bytes: cint; user_data: pointer); cdecl; external;
 54procedure systemValueHandler(value: cuint32; data: pointer); cdecl; external;
 55
 56procedure lcdSwap(); inline; 
 57procedure lcdMainOnTop(); inline; 
 58procedure lcdMainOnBottom(); inline; 
 59
 60procedure systemShutDown(); inline;
 61
 62function getBatteryLevel(): cuint32; cdecl; external;
 63
 64procedure setVectorBase(highVector: cint); cdecl; external;
 65
 66type 
 67  sysVectors_t = packed record
 68    reset: cuint32;
 69    undefined: cuint32;
 70    swi: cuint32;
 71    prefetch_abort: cuint32;
 72    data_abort: cuint32;
 73    fiq: cuint32;
 74  end; 
 75  sysVectors = sysVectors_t;
 76  PsysVectors = ^sysVectors;
 77
 78var
 79  SystemVectors: sysVectors; cvar; external;
 80
 81//void setSDcallback(void(*callback)(int));
 82procedure setSDcallback(callback: pointer); cdecl; external; // ??
 83
 84// Helper functions for heap size
 85//! returns current start of heap space
 86function getHeapStart(): pcuint8; cdecl; external;
 87//! returns current end of heap space
 88function getHeapEnd(): pcuint8; cdecl; external;
 89//! returns current heap limit
 90function getHeapLimit(): pcuint8; cdecl; external;
 91
 92{$endif ARM9}
 93
 94
 95{$ifdef ARM7}
 96type
 97  ARM7_power = cint;
 98const
 99  POWER_SOUND         : ARM7_power = (1 shl 0);
100  PM_CONTROL_REG      : ARM7_power = 0;
101  PM_BATTERY_REG      : ARM7_power = 1;
102  PM_AMPLIFIER_REG    : ARM7_power = 2;
103  PM_READ_REGISTER    : ARM7_power = (1 shl 7);
104  PM_AMP_OFFSET       : ARM7_power = 2;
105  PM_GAIN_OFFSET      : ARM7_power = 3;
106  PM_BACKLIGHT_LEVEL  : ARM7_power = 4;
107  PM_GAIN_20          : ARM7_power = 0;
108  PM_GAIN_40          : ARM7_power = 1;
109  PM_GAIN_80          : ARM7_power = 2;
110  PM_GAIN_160         : ARM7_power = 3;
111  PM_AMP_ON           : ARM7_power = 1;
112  PM_AMP_OFF          : ARM7_power = 0;
113
114function PM_LED_CONTROL(m: cint): cint; inline;
115
116procedure installSystemFIFO(); cdecl; external;
117procedure systemSleep(); cdecl; external;
118function sleepEnabled(): cint; cdecl; external;
119function writePowerManagement(reg, command: cint): cint; cdecl; external;
120
121function readPowerManagement(reg: cint): cint; inline; 
122
123procedure powerOn(bits: cint); inline;
124procedure powerOff(bits: cint); inline;
125procedure readUserSettings(); cdecl; external;
126procedure systemShutDown(); cdecl; external;
127{$endif ARM7}
128
129
130type
131  BACKLIGHT_LEVELS = cint;
132const
133	BACKLIGHT_LOW  : BACKLIGHT_LEVELS = 0;
134	BACKLIGHT_MED  : BACKLIGHT_LEVELS = 1;
135	BACKLIGHT_HIGH : BACKLIGHT_LEVELS = 2;
136	BACKLIGHT_MAX  : BACKLIGHT_LEVELS = 3;	
137
138type
139  tPERSONAL_DATA = bitpacked record
140    RESERVED0: array [0..1] of cuint8;
141    
142    theme: cuint8;
143    birthMonth: cuint8;
144    birthDay: cuint8;
145    
146    RESERVED1: array [0..0] of cuint8;
147    
148    name: array [0..9] of cint16;
149    nameLen: cuint16;
150    
151    message: array [0..25] of cint16;
152    messageLen: cuint16;
153    
154    alarmHour: cuint8;
155    alarmMinute: cuint8;
156    
157    RESERVED2: array [0..3] of cuint8;
158    
159    calX1: cuint16;
160    calY1: cuint16;
161    calX1px: cuint8;
162    calY1px: cuint8;
163    
164    calX2: cuint16;
165    calY2: cuint16;
166    calX2px: cuint8;
167    calY2px: cuint8;
168    
169  
170    _user_data: packed record
171      language: 0..3;
172      gbaScreen: 0..1;
173      defaultBrightness: 0..2;
174      autoMode: 0..1;
175      RESERVED5: 0..2;
176	    settingsLost: 0..1;	
177	    RESERVED6: 0..6;
178    end;
179    RESERVED3: cuint16;
180    rtcOffset: cuint32;
181    RESERVED4: cuint32;
182  end; 
183  PERSONAL_DATA = tPERSONAL_DATA;
184  PPERSONAL_DATA = ^tPERSONAL_DATA;
185
186const
187  PersonalData  : PPERSONAL_DATA = pointer($2FFFC80);
188
189type
190  RTCtime = packed record
191    year: cuint8;        // add 2000 to get 4 digit year
192    month: cuint8;       // 1 to 12
193    day: cuint8;         // 1 to (days in month)
194    weekday: cuint8;     // day of week
195    hours: cuint8;       // 0 to 11 for AM, 52 to 63 for PM
196    minutes: cuint8;     // 0 to 59
197    seconds: cuint8;     // 0 to 59
198//    padding: cuint8;
199  end;
200
201const
202  ARGV_MAGIC = $5f617267;
203
204type 
205  ppcchar = ^pcchar;
206  __argv = record 
207    argvMagic: cint;		  // argv magic number, set to 0x5f617267 ('_arg') if valid 
208    commandLine: pcchar;	// base address of command line, set of null terminated strings
209    length: cint;			    // total length of command line
210    argc: integer;
211    argv: ppcchar;    
212    dummy: cint;          // internal use
213    host: cuint32;        // internal use, host ip for dslink 
214  end;
215  Targv = __argv;
216  Pargv = ^Targv;
217
218const
219  __system_argv: Pargv = pointer($02FFFE70);
220
221const
222  BOOTSIG = $62757473746F6F62; // ULL?
223
224
225type
226  __bootstub = packed record      // packed ?
227    bootsig: 	cuint64;
228    arm9reboot: VoidFn;
229    arm7reboot: VoidFn;
230    bootsize: cuint32;
231  end;
232
233
234{$ifdef ARM9}
235//procedure memCached(address: pointer); cdecl; external;
236function memCached(address: pointer): pointer; cdecl; external;
237//procedure memUncached(address: pointer); cdecl; external;
238function memUncached(address: pointer): pointer; cdecl; external;
239procedure resetARM7(address: cuint32); cdecl; external;
240{$endif ARM9}
241
242{$ifdef ARM7}
243procedure resetARM9(address: cuint32); cdecl; external;
244{$endif ARM7}
245
246{$endif NDS_INTERFACE}
247
248
249
250
251{$ifdef NDS_IMPLEMENTATION}
252
253procedure SetYtrigger(Yvalue: cint); inline;
254begin
255  REG_DISPSTAT^ := (REG_DISPSTAT^ and $007F ) or (Yvalue shl 8) or (( Yvalue and $100 ) shr 1);
256end;
257
258{$ifdef ARM9}
259procedure lcdSwap(); inline; 
260begin
261  REG_POWERCNT^ := REG_POWERCNT^ xor POWER_SWAP_LCDS; 
262end;
263
264procedure lcdMainOnTop(); inline; 
265begin
266  REG_POWERCNT^ := REG_POWERCNT^ or cint(POWER_SWAP_LCDS); 
267end;
268
269procedure lcdMainOnBottom(); inline; 
270begin
271  REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS)); 
272end;
273
274procedure systemShutDown(); inline;
275begin
276  powerOn(PM_SYSTEM_PWR);
277end;
278
279{$endif ARM9}
280
281
282{$ifdef ARM7}
283function PM_LED_CONTROL(m: cint): cint; inline;
284begin
285  result := (m) shl 4;
286end;
287
288function readPowerManagement(reg: cint): cint; inline; 
289begin
290	result := writePowerManagement(reg or PM_READ_REGISTER, 0);
291end;
292
293procedure powerOn(bits: cint); inline;
294begin
295	REG_POWERCNT^ := REG_POWERCNT^ or bits;
296end;
297
298procedure powerOff(bits: cint); inline;
299begin
300	REG_POWERCNT^ := REG_POWERCNT^ and not bits;
301end;
302{$endif ARM7}
303
304{$endif NDS_IMPLEMENTATION}
305