-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.c
235 lines (204 loc) · 4.25 KB
/
Main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* JBDS main entry point
*/
#include <nds.h>
#include <stdio.h>
#include <nds/ndstypes.h>
#include <nds/interrupts.h>
#include <string.h>
// Utilities to make development easier
#include "Utils.h"
// NitroFS access
#include "nitrofs.h"
// Effects!
#include "effects.h"
#include "Truchet.h"
#include "Radial.h"
#include "Tunnel.h"
#include "Pens.h"
#include "ARM.h"
// Sound!
#include <maxmod9.h>
#include "music.h"
volatile uint32_t t;
static void vblank();
static PenFrame pens[60*60*3];
extern int tempImage;
extern int cubemode;
extern int showmode;
uint8_t ATTR_DTCM dtcm_buffer[12288];
void fadeout(int t, int b) {
uint16_t* master_bright = (uint16_t*)(0x400006C);
if( t > b-16 ) {
uint16_t val = 18-(b-t);
memset( master_bright, (1<<7) | val, 2 );
}
// else {
// memset( master_bright, (1<<7) | 15, 2 );
// }
}
void fadein(int t, int b) {
uint16_t* master_bright = (uint16_t*)(0x400006C);
if( t < b+16 ) {
uint16_t val = (b+17-t);
memset( master_bright, (1<<7) | val, 2 );
}
else {
memset( master_bright, (1<<7) | 0, 2 );
}
}
int main()
{
// Turn on everything.
POWCNT1 = POWCNT1_ALL_SWAP;
irqEnable( IRQ_VBLANK );
irqSet(IRQ_VBLANK,vblank);
// ClaimWRAM();
// Init NitroFS for data loading.
nitroFSInitAdv( BINARY_NAME );
tempImage = malloc(256*256*2);
#ifdef DEBUG
//consoleDemoInit();
//iprintf( "Debug mode.\n" );
#endif
t = 0;
// Main loop
InitPensOnSecondaryScreen(false);
//InitTruchet(t);
InitRadial();
// effect0_init();
// effect2_init();
uint8_t *wram=(uint8_t *)0x3000000;
// memset(wram,0,128*96);
if(!LoadPenData(pens,sizeof(pens)/sizeof(*pens),"fat:/rainbows.pen"))
if(!LoadPenData(pens,sizeof(pens)/sizeof(*pens),"nitro:/rainbows.pen"))
ClearPenData(pens,sizeof(pens)/sizeof(*pens));
mmInitDefault( "nitro:/zik/music.bin" );
mmLoad( MOD_RAINBOWS_CLN );
mmStart( MOD_RAINBOWS_CLN, MM_PLAY_ONCE );
while( t<140*60 ) {
RunPens(pens,sizeof(pens)/sizeof(*pens),t);
scanKeys();
// uint32_t keys=keysHeld();
// if(keys&KEY_A) {
// SavePenData(pens,sizeof(pens)/sizeof(*pens),"fat:/rainbows.pen");
// LoadPenData(pens,sizeof(pens)/sizeof(*pens),"fat:/rainbows.pen");
// }
// RunTunnel(t);
if(0) {
effect0_update(t);
}
else {
if( t < 16*60+30 ) {
RunRadial(t,dtcm_buffer);
fadeout(t,16*60+30);
if( t >= 16*60+30-2 ) {
StopRadial();
cubemode = 0;
effect6_init();
}
}
else if(t < 27*60) {
effect6_update(t);
fadein(t,16*60+30);
fadeout(t,27*60);
if( t >= 27*60-3 ) {
effect6_destroy();
effect2_init();
}
}
else if( t < 37*60 ) {
effect2_update(t);
fadein(t,27*60);
fadeout(t,37*60);
if( t >= 37*60-3 ) {
effect2_destroy();
effect1_init();
}
}
else if( t < 47*60 ) {
effect1_update(t);
fadein(t,37*60);
fadeout(t,47*60);
if( t >= 47*60-2 ) {
cubemode = 1;
effect1_destroy();
effect6_init();
}
}
else if( t < 57*60 ) {
effect6_update(t);
fadein(t,47*60-5);
fadeout(t,57*60);
if( t >= 57*60-4 ) {
effect6_destroy();
showmode = 1;
InitTunnel();
}
}
else if( t < 68*60 ) {
RunTunnel(t);
fadein(t,57*60-5);
fadeout(t,68*60);
if( t >= 68*60-2 ) {
showmode = 1;
effect4_init();
}
}
else if( t < 73*60 ) {
effect4_update(t);
fadein(t,68*60-5);
fadeout(t,73*60);
if( t >= 73*60-2 ) {
effect4_destroy();
showmode = 0;
effect4_init();
}
}
else if( t < 78*60 ) {
effect4_update(t);
fadein(t,73*60-5);
fadeout(t,78*60);
if( t >= 78*60-2 ) {
effect4_destroy();
effect0_init();
}
}
else if( t < 88*60 ) {
effect0_update(t);
fadein(t,78*60-5);
fadeout(t,88*60);
if( t >= 88*60-4 ) {
effect0_destroy();
effect5_init();
}
}
else if( t < 108*60 ) {
effect5_update(t);
fadein(t,88*60);
fadeout(t,108*60);
if( t == 108*60-1 ) {
effect5_destroy();
}
}
else if( t < 129*60 ) {
Truchet(t);
fadein(t,108*60);
if( t >= 129*60-2 ) {
effect7_init();
}
}
else {
effect7_update(t);
}
}
swiWaitForVBlank();
}
// Superstitious save.
// SavePenData(pens,sizeof(pens)/sizeof(*pens),"fat:/rainbows.pen");
// LoadPenData(pens,sizeof(pens)/sizeof(*pens),"fat:/rainbows.pen");
POWCNT1 = POWCNT1_ALL;
for(;;);
return 0;
}
static void vblank() { t++; }