1 | /*--------------------------------------------------------------------------------- |
---|
2 | $Id$ |
---|
3 | |
---|
4 | Power control, keys, and HV clock registers |
---|
5 | |
---|
6 | Copyright (C) 2005 |
---|
7 | Jason Rogers (dovoto) |
---|
8 | Dave Murphy (WinterMute) |
---|
9 | |
---|
10 | This software is provided 'as-is', without any express or implied |
---|
11 | warranty. In no event will the authors be held liable for any |
---|
12 | damages arising from the use of this software. |
---|
13 | |
---|
14 | Permission is granted to anyone to use this software for any |
---|
15 | purpose, including commercial applications, and to alter it and |
---|
16 | redistribute it freely, subject to the following restrictions: |
---|
17 | |
---|
18 | 1. The origin of this software must not be misrepresented; you |
---|
19 | must not claim that you wrote the original software. If you use |
---|
20 | this software in a product, an acknowledgment in the product |
---|
21 | documentation would be appreciated but is not required. |
---|
22 | |
---|
23 | 2. Altered source versions must be plainly marked as such, and |
---|
24 | must not be misrepresented as being the original software. |
---|
25 | |
---|
26 | 3. This notice may not be removed or altered from any source |
---|
27 | distribution. |
---|
28 | |
---|
29 | ---------------------------------------------------------------------------------*/ |
---|
30 | |
---|
31 | //! NDS hardware definitions. |
---|
32 | /*! \file system.h |
---|
33 | |
---|
34 | These definitions are usually only touched during |
---|
35 | the initialization of the program. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef NDS_SYSTEM_INCLUDE |
---|
39 | #define NDS_SYSTEM_INCLUDE |
---|
40 | |
---|
41 | //! LCD status register. |
---|
42 | #define REG_DISPSTAT (*(vu16*)0x04000004) |
---|
43 | |
---|
44 | //! The display currently in a vertical blank. |
---|
45 | #define DISP_IN_VBLANK BIT(0) |
---|
46 | |
---|
47 | //! The display currently in a horizontal blank. |
---|
48 | #define DISP_IN_HBLANK BIT(1) |
---|
49 | |
---|
50 | //! Current scanline and %DISP_Y match. |
---|
51 | #define DISP_YTRIGGERED BIT(2) |
---|
52 | |
---|
53 | //! Interrupt on vertical blank. |
---|
54 | #define DISP_VBLANK_IRQ BIT(3) |
---|
55 | |
---|
56 | //! Interrupt on horizontal blank. |
---|
57 | #define DISP_HBLANK_IRQ BIT(4) |
---|
58 | |
---|
59 | //! Interrupt when current scanline and %DISP_Y match. |
---|
60 | #define DISP_YTRIGGER_IRQ BIT(5) |
---|
61 | |
---|
62 | static inline |
---|
63 | void SetYtrigger(int Yvalue) { |
---|
64 | REG_DISPSTAT = (REG_DISPSTAT & 0x007F ) | (Yvalue << 8) | (( Yvalue & 0x100 ) >> 2) ; |
---|
65 | } |
---|
66 | |
---|
67 | //! Current display scanline. |
---|
68 | #define REG_VCOUNT (*(vu16*)0x4000006) |
---|
69 | |
---|
70 | |
---|
71 | //! Halt control register. |
---|
72 | /*! Writing 0x40 to HALT_CR activates GBA mode. |
---|
73 | %HALT_CR can only be accessed via the BIOS. |
---|
74 | */ |
---|
75 | #define HALT_CR (*(vuint16*)0x04000300) |
---|
76 | |
---|
77 | //! Power control register. |
---|
78 | /*! This register controls what hardware should |
---|
79 | be turned on or off. |
---|
80 | */ |
---|
81 | #define REG_POWERCNT *(vu16*)0x4000304 |
---|
82 | |
---|
83 | //! Turns on specified hardware. |
---|
84 | /*! This function should only be called after %powerSET. |
---|
85 | |
---|
86 | \param on What to power on. |
---|
87 | */ |
---|
88 | static inline |
---|
89 | void powerON(int on) { REG_POWERCNT |= on;} |
---|
90 | |
---|
91 | //! Turns on only the specified hardware. |
---|
92 | /*! Use this function to power on basic hardware types you |
---|
93 | wish to use throughout your program. |
---|
94 | |
---|
95 | \param on What to power on. |
---|
96 | */ |
---|
97 | static inline void powerSET(int on) { REG_POWERCNT = on;} |
---|
98 | |
---|
99 | //! Turns off the specified hardware. |
---|
100 | /*! \param off What to power off. |
---|
101 | */ |
---|
102 | static inline void powerOFF(int off) { REG_POWERCNT &= ~off;} |
---|
103 | |
---|
104 | #ifdef ARM9 |
---|
105 | #ifdef DOXYGEN |
---|
106 | //! Power-controlled hardware devices accessable to the ARM9. |
---|
107 | /*! Used with %powerON, %powerSET, and %powerOFF functions. |
---|
108 | Note that these should only be used when programming for |
---|
109 | the ARM9. Trying to boot up these hardware devices via |
---|
110 | the ARM7 would lead to unexpected results. |
---|
111 | */ |
---|
112 | enum ARM9_power |
---|
113 | { |
---|
114 | POWER_LCD, //!< Controls the power for both LCD screens. |
---|
115 | POWER_2D_A, //!< Controls the power for the main 2D core. |
---|
116 | POWER_MATRIX, //!< Controls the power for the 3D matrix. |
---|
117 | POWER_3D_CORE, //!< Controls the power for the main 3D core. |
---|
118 | POWER_2D_B, //!< Controls the power for the sub 2D core. |
---|
119 | POWER_SWAP_LCDS, //!< Controls which screen should use the main core. |
---|
120 | }; |
---|
121 | #else |
---|
122 | #define POWER_LCD BIT(0) |
---|
123 | #define POWER_2D_A BIT(1) |
---|
124 | #define POWER_MATRIX BIT(2) |
---|
125 | #define POWER_3D_CORE BIT(3) |
---|
126 | #define POWER_2D_B BIT(9) |
---|
127 | #define POWER_SWAP_LCDS BIT(15) |
---|
128 | #endif /* DOXYGEN */ |
---|
129 | |
---|
130 | //! Enables power to all hardware required for 2D video. |
---|
131 | #define POWER_ALL_2D (POWER_LCD |POWER_2D_A |POWER_2D_B) |
---|
132 | |
---|
133 | //! Enables power to all hardware required for 3D video. |
---|
134 | #define POWER_ALL (POWER_ALL_2D | POWER_3D_CORE | POWER_MATRIX) |
---|
135 | |
---|
136 | //! Switches the screens. |
---|
137 | static inline void lcdSwap(void) { REG_POWERCNT ^= POWER_SWAP_LCDS; } |
---|
138 | |
---|
139 | //! Forces the main core to display on the top. |
---|
140 | static inline void lcdMainOnTop(void) { REG_POWERCNT |= POWER_SWAP_LCDS; } |
---|
141 | |
---|
142 | //! Forces the main core to display on the bottom. |
---|
143 | static inline void lcdMainOnBottom(void) { REG_POWERCNT &= ~POWER_SWAP_LCDS; } |
---|
144 | #endif |
---|
145 | |
---|
146 | #ifdef ARM7 |
---|
147 | #ifdef DOXYGEN |
---|
148 | //! Power-controlled hardware devices accessable to the ARM7. |
---|
149 | /*! Note that these should only be used when programming for |
---|
150 | the ARM7. Trying to boot up these hardware devices via |
---|
151 | the ARM9 would lead to unexpected results. |
---|
152 | */ |
---|
153 | enum ARM7_power |
---|
154 | { |
---|
155 | POWER_SOUND, //!< Controls the power for the sound controller. |
---|
156 | POWER_UNKNOWN, //!< Controls the power for an unknown device. |
---|
157 | }; |
---|
158 | #else |
---|
159 | #define POWER_SOUND BIT(0) |
---|
160 | #define POWER_UNKNOWN BIT(1) |
---|
161 | #endif /* DOXYGEN */ |
---|
162 | |
---|
163 | void readUserSettings(void); |
---|
164 | |
---|
165 | #endif /* ARM7 */ |
---|
166 | |
---|
167 | //! User's DS settings. |
---|
168 | /*! \struct tPERSONAL_DATA |
---|
169 | |
---|
170 | Defines the structure the DS firmware uses for transfer |
---|
171 | of the user's settings to the booted program. |
---|
172 | */ |
---|
173 | typedef struct tPERSONAL_DATA { |
---|
174 | u8 RESERVED0[2]; //!< ??? (0x05 0x00). |
---|
175 | |
---|
176 | u8 theme; //!< The user's theme color (0-15). |
---|
177 | u8 birthMonth; //!< The user's birth month (1-12). |
---|
178 | u8 birthDay; //!< The user's birth day (1-31). |
---|
179 | |
---|
180 | u8 RESERVED1[1]; //!< ??? |
---|
181 | |
---|
182 | s16 name[10]; //!< The user's name in UTF-16 format. |
---|
183 | u16 nameLen; //!< The length of the user's name in characters. |
---|
184 | |
---|
185 | s16 message[26]; //!< The user's message. |
---|
186 | u16 messageLen; //!< The length of the user's message in characters. |
---|
187 | |
---|
188 | u8 alarmHour; //!< What hour the alarm clock is set to (0-23). |
---|
189 | u8 alarmMinute; //!< What minute the alarm clock is set to (0-59). |
---|
190 | //0x027FFCD3 alarm minute |
---|
191 | |
---|
192 | u8 RESERVED2[4]; //!< ??? |
---|
193 | //0x027FFCD4 ?? |
---|
194 | |
---|
195 | u16 calX1; //!< Touchscreen calibration: first X touch |
---|
196 | u16 calY1; //!< Touchscreen calibration: first Y touch |
---|
197 | u8 calX1px; //!< Touchscreen calibration: first X touch pixel |
---|
198 | u8 calY1px; //!< Touchscreen calibration: first X touch pixel |
---|
199 | |
---|
200 | u16 calX2; //!< Touchscreen calibration: second X touch |
---|
201 | u16 calY2; //!< Touchscreen calibration: second Y touch |
---|
202 | u8 calX2px; //!< Touchscreen calibration: second X touch pixel |
---|
203 | u8 calY2px; //!< Touchscreen calibration: second Y touch pixel |
---|
204 | |
---|
205 | packed_struct { |
---|
206 | unsigned language : 3; //!< User's language. |
---|
207 | unsigned gbaScreen : 1; //!< GBA screen selection (lower screen if set, otherwise upper screen). |
---|
208 | unsigned defaultBrightness : 2; //!< Brightness level at power on, dslite. |
---|
209 | unsigned autoMode : 1; //!< The DS should boot from the DS cart or GBA cart automatically if one is inserted. |
---|
210 | unsigned RESERVED1 : 2; //!< ??? |
---|
211 | unsigned settingsLost : 1; //!< User Settings Lost (0=Normal, 1=Prompt/Settings Lost) |
---|
212 | unsigned RESERVED2 : 6; //!< ??? |
---|
213 | } _user_data; |
---|
214 | |
---|
215 | u16 RESERVED3; |
---|
216 | u32 rtcOffset; |
---|
217 | u32 RESERVED4; |
---|
218 | } PACKED PERSONAL_DATA ; |
---|
219 | |
---|
220 | //! Key input register. |
---|
221 | /*! On the ARM9, the hinge "button," the touch status, and the |
---|
222 | X and Y buttons cannot be accessed directly. |
---|
223 | */ |
---|
224 | #define REG_KEYINPUT (*(vuint16*)0x04000130) |
---|
225 | |
---|
226 | //! Key input control register. |
---|
227 | #define REG_KEYCNT (*(vuint16*)0x04000132) |
---|
228 | |
---|
229 | //! Default location for the user's personal data (see %PERSONAL_DATA). |
---|
230 | #define PersonalData ((PERSONAL_DATA*)0x27FFC80) |
---|
231 | |
---|
232 | //! argv structure |
---|
233 | /*! \struct __argv |
---|
234 | |
---|
235 | structure used to set up argc/argv on the DS |
---|
236 | |
---|
237 | */ |
---|
238 | struct __argv { |
---|
239 | int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid |
---|
240 | char *commandLine; //!< base address of command line, set of null terminated strings |
---|
241 | int length; //!< total length of command line |
---|
242 | }; |
---|
243 | |
---|
244 | //! Default location for the libnds argv structure. |
---|
245 | #define libnds_argv ((struct __argv *)0x027FFF70) |
---|
246 | |
---|
247 | // argv struct magic number |
---|
248 | #define argvMagic 0x5f617267 |
---|
249 | |
---|
250 | #endif |
---|