1 | /*--------------------------------------------------------------------------------- |
---|
2 | |
---|
3 | initSystem.c -- Code for initialising the DS |
---|
4 | |
---|
5 | Copyright (C) 2007 |
---|
6 | Dave Murphy (WinterMute) |
---|
7 | |
---|
8 | This software is provided 'as-is', without any express or implied |
---|
9 | warranty. In no event will the authors be held liable for any |
---|
10 | damages arising from the use of this software. |
---|
11 | |
---|
12 | Permission is granted to anyone to use this software for any |
---|
13 | purpose, including commercial applications, and to alter it and |
---|
14 | redistribute it freely, subject to the following restrictions: |
---|
15 | |
---|
16 | 1. The origin of this software must not be misrepresented; you |
---|
17 | must not claim that you wrote the original software. If you use |
---|
18 | this software in a product, an acknowledgment in the product |
---|
19 | documentation would be appreciated but is not required. |
---|
20 | |
---|
21 | 2. Altered source versions must be plainly marked as such, and |
---|
22 | must not be misrepresented as being the original software. |
---|
23 | |
---|
24 | 3. This notice may not be removed or altered from any source |
---|
25 | distribution. |
---|
26 | |
---|
27 | ---------------------------------------------------------------------------------*/ |
---|
28 | #include <nds/jtypes.h> |
---|
29 | #include <nds/system.h> |
---|
30 | #include <nds/memory.h> |
---|
31 | #include <nds/timers.h> |
---|
32 | #include <nds/dma.h> |
---|
33 | #include <nds/ipc.h> |
---|
34 | #include <nds/arm9/video.h> |
---|
35 | |
---|
36 | #include <time.h> |
---|
37 | |
---|
38 | /* |
---|
39 | * Prototypes |
---|
40 | * |
---|
41 | * NOTE: Called from start.S |
---|
42 | */ |
---|
43 | void initSystem(void); |
---|
44 | |
---|
45 | extern time_t *punixTime; |
---|
46 | |
---|
47 | //--------------------------------------------------------------------------------- |
---|
48 | // Reset the DS registers to sensible defaults |
---|
49 | //--------------------------------------------------------------------------------- |
---|
50 | void initSystem(void) { |
---|
51 | //--------------------------------------------------------------------------------- |
---|
52 | register int i; |
---|
53 | |
---|
54 | //clear out ARM9 DMA channels |
---|
55 | for (i=0; i<4; i++) { |
---|
56 | DMA_CR(i) = 0; |
---|
57 | DMA_SRC(i) = 0; |
---|
58 | DMA_DEST(i) = 0; |
---|
59 | TIMER_CR(i) = 0; |
---|
60 | TIMER_DATA(i) = 0; |
---|
61 | } |
---|
62 | |
---|
63 | VRAM_CR = 0x80808080; |
---|
64 | VRAM_E_CR = 0x80; |
---|
65 | VRAM_F_CR = 0x80; |
---|
66 | VRAM_G_CR = 0x80; |
---|
67 | VRAM_H_CR = 0x80; |
---|
68 | VRAM_I_CR = 0x80; |
---|
69 | |
---|
70 | (*(vu32*)0x027FFE04) = 0; // temporary variable |
---|
71 | PALETTE[0] = 0xFFFF; |
---|
72 | dmaFillWords((void*)0x027FFE04, PALETTE+1, (2*1024)-2); |
---|
73 | dmaFillWords((void*)0x027FFE04, OAM, 2*1024); |
---|
74 | dmaFillWords((void*)0x027FFE04, (void*)0x04000000, 0x56); //clear main display registers |
---|
75 | dmaFillWords((void*)0x027FFE04, (void*)0x04001000, 0x56); //clear sub display registers |
---|
76 | dmaFillWords((void*)0x027FFE04, VRAM, 656*1024); |
---|
77 | |
---|
78 | REG_DISPSTAT = 0; |
---|
79 | videoSetMode(0); |
---|
80 | videoSetModeSub(0); |
---|
81 | VRAM_A_CR = 0; |
---|
82 | VRAM_B_CR = 0; |
---|
83 | VRAM_C_CR = 0; |
---|
84 | VRAM_D_CR = 0; |
---|
85 | VRAM_E_CR = 0; |
---|
86 | VRAM_F_CR = 0; |
---|
87 | VRAM_G_CR = 0; |
---|
88 | VRAM_H_CR = 0; |
---|
89 | VRAM_I_CR = 0; |
---|
90 | VRAM_CR = 0x03000000; |
---|
91 | |
---|
92 | punixTime = (time_t*)&IPC->unixTime; |
---|
93 | |
---|
94 | } |
---|