00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00037 #ifndef NDS_SYSTEM_INCLUDE
00038 #define NDS_SYSTEM_INCLUDE
00039 #include "ndstypes.h"
00041 #define REG_DISPSTAT (*(vu16*)0x04000004)
00042
00044 typedef enum
00045 {
00046 DISP_IN_VBLANK = BIT(0),
00047 DISP_IN_HBLANK = BIT(1),
00048 DISP_YTRIGGERED = BIT(2),
00049 DISP_VBLANK_IRQ = BIT(3),
00050 DISP_HBLANK_IRQ = BIT(4),
00051 DISP_YTRIGGER_IRQ = BIT(5)
00052 }DISP_BITS;
00053
00055 #define REG_VCOUNT (*(vu16*)0x4000006)
00056
00057
00059
00062 #define HALT_CR (*(vu16*)0x04000300)
00063
00065
00068 #define REG_POWERCNT *(vu16*)0x4000304
00069
00070
00071 static inline
00072
00073 void SetYtrigger(int Yvalue) {
00074 REG_DISPSTAT = (REG_DISPSTAT & 0x007F ) | (Yvalue << 8) | (( Yvalue & 0x100 ) >> 1) ;
00075 }
00076
00077 #define PM_ARM9_DIRECT BIT(16)
00078
00081 typedef enum
00082 {
00083 PM_SOUND_AMP = BIT(0) ,
00084 PM_SOUND_MUTE = BIT(1),
00085 PM_BACKLIGHT_BOTTOM = BIT(2),
00086 PM_BACKLIGHT_TOP = BIT(3) ,
00087 PM_SYSTEM_PWR = BIT(6) ,
00089 POWER_LCD = PM_ARM9_DIRECT | BIT(0),
00090 POWER_2D_A = PM_ARM9_DIRECT | BIT(1),
00091 POWER_MATRIX = PM_ARM9_DIRECT | BIT(2),
00092 POWER_3D_CORE = PM_ARM9_DIRECT | BIT(3),
00093 POWER_2D_B = PM_ARM9_DIRECT | BIT(9),
00094 POWER_SWAP_LCDS = PM_ARM9_DIRECT | BIT(15),
00095 POWER_ALL_2D = PM_ARM9_DIRECT | POWER_LCD | POWER_2D_A | POWER_2D_B,
00096 POWER_ALL = PM_ARM9_DIRECT | POWER_ALL_2D | POWER_3D_CORE | POWER_MATRIX
00097
00098 }PM_Bits;
00099
00100 void systemSleep(void);
00101
00102
00103
00104
00105
00106
00107 #ifdef ARM9
00108
00110
00115 void powerOn(int bits);
00116
00118
00123 void powerOff(int bits);
00124
00126
00129 void ledBlink(int bm);
00130
00131
00132 void systemMsgHandler(int bytes, void* user_data);
00133 void powerValueHandler(u32 value, void* data);
00134
00136 static inline void lcdSwap(void) { REG_POWERCNT ^= POWER_SWAP_LCDS; }
00137
00139 static inline void lcdMainOnTop(void) { REG_POWERCNT |= POWER_SWAP_LCDS; }
00140
00142 static inline void lcdMainOnBottom(void) { REG_POWERCNT &= ~POWER_SWAP_LCDS; }
00143
00145 static inline
00146 void systemShutDown() {
00147 powerOn(PM_SYSTEM_PWR);
00148 }
00149
00151
00154 void setVectorBase(int highVector);
00155
00156 typedef struct sysVectors_t {
00157 u32 reset;
00158 u32 undefined;
00159 u32 swi;
00160 u32 prefetch_abort;
00161 u32 data_abort;
00162 u32 fiq;
00163 } sysVectors;
00164
00165 extern sysVectors SystemVectors;
00166
00167 #endif
00168
00169
00170
00171
00172 #ifdef ARM7
00173
00175
00179 typedef enum {
00180 POWER_SOUND = BIT(0),
00181
00182 PM_CONTROL_REG = 0,
00183 PM_BATTERY_REG = 1,
00184 PM_AMPLIFIER_REG = 2,
00185 PM_READ_REGISTER = (1<<7),
00186 PM_AMP_OFFSET = 2,
00187 PM_GAIN_OFFSET = 3,
00188 PM_BACKLIGHT_LEVEL = 4,
00189 PM_GAIN_20 = 0,
00190 PM_GAIN_40 = 1,
00191 PM_GAIN_80 = 2,
00192 PM_GAIN_160 = 3,
00193 PM_AMP_ON = 1,
00194 PM_AMP_OFF = 0
00195 } ARM7_power;
00196
00198 #define PM_LED_CONTROL(m) ((m)<<4) // ?
00199
00200
00201 void installSystemFIFO(void);
00202
00203
00204 void systemSleep(void);
00205
00206 int sleepEnabled(void);
00207
00208
00209
00210
00211
00212
00213 int writePowerManagement(int reg, int command);
00214
00215 static inline
00216 int readPowerManagement(int reg) {
00217 return writePowerManagement((reg)|PM_READ_REGISTER, 0);
00218 }
00219
00220 static inline
00221 void powerOn(int bits) {
00222 REG_POWERCNT |= bits;
00223 }
00224
00225 static inline
00226 void powerOff(PM_Bits bits) {
00227 REG_POWERCNT &= ~bits;
00228 }
00229
00230 void readUserSettings();
00231 void systemShutDown();
00232
00233 #endif
00234
00236
00238 typedef enum {
00239 BACKLIGHT_LOW,
00240 BACKLIGHT_MED,
00241 BACKLIGHT_HIGH,
00242 BACKLIGHT_MAX
00243 } BACKLIGHT_LEVELS;
00244
00245
00246
00247
00249
00254 typedef struct tPERSONAL_DATA {
00255 u8 RESERVED0[2];
00256
00257 u8 theme;
00258 u8 birthMonth;
00259 u8 birthDay;
00260
00261 u8 RESERVED1[1];
00262
00263 s16 name[10];
00264 u16 nameLen;
00265
00266 s16 message[26];
00267 u16 messageLen;
00268
00269 u8 alarmHour;
00270 u8 alarmMinute;
00271
00272
00273 u8 RESERVED2[4];
00274
00275
00276 u16 calX1;
00277 u16 calY1;
00278 u8 calX1px;
00279 u8 calY1px;
00280
00281 u16 calX2;
00282 u16 calY2;
00283 u8 calX2px;
00284 u8 calY2px;
00285
00286 packed_struct {
00287 unsigned language : 3;
00288 unsigned gbaScreen : 1;
00289 unsigned defaultBrightness : 2;
00290 unsigned autoMode : 1;
00291 unsigned RESERVED1 : 2;
00292 unsigned settingsLost : 1;
00293 unsigned RESERVED2 : 6;
00294 } _user_data;
00295
00296 u16 RESERVED3;
00297 u32 rtcOffset;
00298 u32 RESERVED4;
00299 } PACKED PERSONAL_DATA ;
00300
00302 #define PersonalData ((PERSONAL_DATA*)0x2FFFC80)
00303
00304
00305 #define ARGV_MAGIC 0x5f617267
00306
00308
00313 struct __argv {
00314 int argvMagic;
00315 char *commandLine;
00316 int length;
00317 int argc;
00318 char **argv;
00319 };
00320
00322 #define __system_argv ((struct __argv *)0x02FFFE70)
00323
00324 #define BOOTSIG 0x62757473746F6F62ULL
00325
00326 struct __bootstub {
00327 u64 bootsig;
00328 VoidFn arm9reboot;
00329 VoidFn arm7reboot;
00330 u32 bootsize;
00331 };
00332
00333 typedef struct {
00334 u8 year;
00335 u8 month;
00336 u8 day;
00337
00338 u8 weekday;
00339 u8 hours;
00340 u8 minutes;
00341 u8 seconds;
00342 } RTCtime;
00343
00344 #ifdef ARM9
00345 void *memCached(void *address);
00346 void *memUncached(void *address);
00347 void resetARM7(u32 address);
00348 #endif
00349
00350 #ifdef ARM7
00351 void resetARM9(u32 address);
00352 #endif
00353
00354 #endif