00001 #ifndef _PA_GENERAL
00002 #define _PA_GENERAL
00003
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007
00008 #include <PA_IPC.h>
00009
00010
00011 #include <nds.h>
00012 #include <nds/memory.h>
00013 #include <nds/bios.h>
00014 #include <malloc.h>
00015
00016 #include <stdarg.h>
00017 #include <string.h>
00018
00019
00020 extern u8 PA_Screen;
00021
00022 typedef struct {
00023 u8 NoIdea;
00024 u8 Year;
00025 u8 Month;
00026 u8 Day;
00027 u8 NoIdea2;
00028 u8 Hour;
00029 u8 Minutes;
00030 u8 Seconds;
00031 u8 FPS, Frames, OldSeconds;
00032 } RTC;
00033 extern RTC PA_RTC;
00034
00035 extern inline void PA_WaitForVBL(void);
00036
00037 extern s16 PA_ScreenSpace;
00038
00039 #define BG_GFX1 0x6000000
00040 #define BG_GFX2 0x6200000
00041 #define SPRITE_GFX1 0x6400000
00042 #define SPRITE_GFX2 0x6600000
00043
00044
00045
00046 #define REG_DMA3SRC *(volatile u32*)0x040000D4
00047 #define REG_DMA3DST *(volatile u32*)0x040000D8
00048 #define REG_DMA3CNT *(volatile u32*)0x040000DC
00049 #define DMA_ON 0x80000000
00050 #define DMA_NOW 0x00000000
00051 #define DMA_16 0x00000000
00052 #define DMA_32 0x04000000
00053 #define DMA_16NOW (DMA_ON | DMA_NOW | DMA_16)
00054 #define DMA_32NOW (DMA_ON | DMA_NOW | DMA_32)
00055 #define DMA_Copy(source, dest, count, mode) {REG_DMA3SRC = (u32)source; REG_DMA3DST = (u32)dest; REG_DMA3CNT = (count) | (mode);}
00056
00057 #define DMA_Clear(dest, count, mode) {REG_DMA3SRC = (u32)Blank; REG_DMA3DST = (u32)dest; REG_DMA3CNT = (count) | (mode);}
00058
00059 #define DMA_Force(ulVal,dest, count, mode) {REG_DMA3SRC=(u32)&ulVal; REG_DMA3DST = (u32)dest; REG_DMA3CNT = (count) |(mode) | DMA_SRC_FIX;}
00060
00061
00062 #define BACKLIGHT(screen) BIT(2+screen)
00063
00064 #define ALWAYSINLINE __attribute__((always_inline)) static inline
00065
00066
00067
00068
00069
00070
00071
00072
00073 #define _REG8 *(volatile u16 *)
00074 #define _REG16 *(volatile u16 *)
00075 #define _REG32 *(volatile u32 *)
00076
00077
00078 #define SWITCH_SCREENS (1<<15)
00079
00080
00081
00082 #define N_HBLS 263
00083
00084
00085
00094
00095 extern u32 Blank[130000>>2];
00096
00097 extern volatile PA_IPCType PA_IPC;
00098
00099
00100
00101
00103
00105
00106 #define SIZEOF_8BIT(x) (sizeof(x))
00107 #define SIZEOF_16BIT(x) (sizeof(x)>>1)
00108 #define SIZEOF_32BIT(x) (sizeof(x)>>2)
00109
00110
00111
00112
00113 #define CODE_IN_IWRAM __attribute__ ((section (".iwram"), long_call))
00114 #define IN_IWRAM __attribute__ ((section (".iwram")))
00115 #define CODE_IN_EWRAM __attribute__ ((section (".ewram"), long_call))
00116 #define IN_EWRAM __attribute__ ((section (".ewram")))
00117 #define PACKED __attribute__ ((packed))
00118
00119
00120
00121
00122
00123
00124
00125
00126 void PA_jpeg_GetImageSize(char* name, int* width, int* height);
00127 void PA_jpeg_BltImage(char* name, u16* vram, int output_width, int output_height);
00128
00129 extern const s16 PA_SIN[512];
00130
00131
00132
00133 typedef struct {
00134 u8 Color;
00135 u8 BdayMonth;
00136 u8 BdayDay;
00137 u8 AlarmHour;
00138 u8 AlarmMinute;
00139 u8 Name[21];
00140 u8 NameLength;
00141 u8 Message[53];
00142 u8 MessageLength;
00143 u8 Language;
00144 } infos;
00145 extern infos PA_UserInfo;
00146
00147 #define INFO_COLOR *(u8*)0x027FFC82
00148 #define INFO_BDAY_MONTH *(u8*)0x027FFC83
00149 #define INFO_BDAY_DAY *(u8*)0x027FFC84
00150 #define INFO_ALARM_HOUR *(u8*)0x027FFCD2
00151 #define INFO_ALARM_MINUTE *(u8*)0x027FFCD3
00152 #define INFO_NAME *(u8*)0x027FFC86
00153 #define INFO_NAME_LENGTH *(u8*)0x027FFC9A
00154 #define INFO_MESSAGE *(u8*)0x027FFC9C
00155 #define INFO_MESSAGE_LENGTH *(u8*)0x027FFCD0
00156 #define INFO_LANGUAGE *(u8*)(0x027FFCE4)
00157
00158
00170 void PA_Init(void);
00171
00172
00178 void PA_Init2D(void);
00179
00180
00181
00193 extern inline void PA_SetVideoMode(u8 screen, u8 mode) {
00194 (*(vuint32*)(0x04000000 + (0x1000 * screen))) &= ~7;
00195 (*(vuint32*)(0x04000000 + (0x1000 * screen))) |= mode;
00196 }
00197
00198
00199
00205 void PA_UpdateUserInfo(void);
00206
00207
00213 void PA_UpdateRTC(void);
00214
00215
00223 void PA_LoadSplash(void);
00224
00225
00231 void PA_NeoSplash(void);
00232
00233
00234
00240 extern inline void PA_WaitForVBL(void){
00241 PA_RTC.Frames++;
00242 swiWaitForVBlank();
00243 }
00244
00245
00246
00252 extern inline void PA_SwitchScreens(void) {
00253 POWER_CR ^= SWITCH_SCREENS;
00254 PA_Screen = !PA_Screen;
00255 }
00256
00257
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00280 #define PA_LidClosed() (IPC->buttons>>7)
00281
00282
00288 extern inline u8 PA_CheckLid(void) {
00289
00290 if (!PA_LidClosed()) return 0;
00291 else {
00292 u16 power_cr = POWER_CR;
00293 POWER_CR = 0;
00294
00295
00296 while(PA_LidClosed()) PA_WaitForVBL();
00297
00298
00299 POWER_CR = power_cr;
00300 return 1;
00301 }
00302
00303 }
00304
00305
00317 #define PA_CloseLidSound(channel, close_sound){\
00318 if(PA_LidClosed()){\
00319 PA_PlaySimpleSound(channel, close_sound);\
00320 PA_WaitFor(!PA_SoundChannelIsBusy(channel)); \
00321 PA_CheckLid(); \
00322 }}
00323
00324
00339 #define PA_CloseLidSound2(channel, close_sound, open_sound){\
00340 if(PA_LidClosed()){\
00341 PA_PlaySimpleSound(channel, close_sound);\
00342 PA_WaitFor(!PA_SoundChannelIsBusy(channel)); \
00343 PA_CheckLid(); \
00344 PA_PlaySimpleSound(channel, open_sound); \
00345 PA_WaitFor(!PA_SoundChannelIsBusy(channel)); \
00346 }}
00347
00348
00349
00350
00351
00363 extern inline void PA_SetScreenLight(u8 screen, u8 light){
00364 IPC->aux &= ~(1<<(2+screen));
00365 IPC->aux |= light<<(2+screen);
00366 }
00367
00368
00380 extern inline void PA_SetLedBlink(u8 blink, u8 speed){
00381 IPC->aux &= ~(3<<4);
00382 IPC->aux |= ((blink&1) + ((speed&1)<<1))<<4;
00383 }
00384
00385
00395 #define PA_WaitFor(something) {PA_WaitForVBL(); while(!(something)){PA_WaitForVBL(); }}
00396
00397
00406 extern inline void PA_SetDSLBrightness(u8 level){
00407 PA_IPC.Sound[16].Busy = (1<<7) | level;
00408 }
00409
00410
00411
00412
00413
00415
00416
00417 void PA_Nothing(void);
00418
00419
00420 #ifdef __cplusplus
00421 }
00422 #endif
00423 #endif
00424
00425
00426