-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.c
411 lines (365 loc) · 8.06 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/**
* 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 "Field.h"
#include "HeartField.h"
#include "ARM.h"
// Sound!
#include <maxmod9.h>
#include "music.h"
volatile uint32_t t;
volatile uint32_t toff;
volatile uint32_t scur;
volatile uint32_t ecur;
volatile uint32_t blockload;
volatile uint32_t fadesub;
static void vblank();
extern int tempImage;
// void fadeout(int t, int b) {
// uint16_t* love_coloured_master_bright = (uint16_t*)(0x400006C);
// if( t > b-16 ) {
// uint16_t val = 18-(b-t);
// memset( love_coloured_master_bright, (1<<7) | val, 2 );
// }
// else if(t > b) {
// memset( love_coloured_master_bright, (1<<7) | 16, 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 );
// }
// }
uint16_t* master_bright = (uint16_t*)(0x400006C);
uint16_t* master_bright_sub = (uint16_t*)(0x400106C);
void fadeinout(int t, int s, int e) {
// if( t < s+32 ) {
// int16_t val = (s+32)-t;
// if(val > 15) {
// val = 15;
// }
// memset( master_bright, (1<<7) | val, 2 );
// }
// else if(t < e - 16) {
// memset( master_bright, (1<<7) | 0, 2 );
// }
// else if( t < e ) {
// int16_t val = 16-(e-t);
// memset( master_bright, (1<<7) | val, 2 );
// }
// else {
// memset( master_bright, (1<<7) | 16, 2 );
// }
scur = s;
ecur = e;
}
void fadeinoutsub(int t2, int scur, int ecur) {
if( t2 <= scur ) {
memset( master_bright_sub, (1<<7) | 16, 2 );
} else if( t2 < scur+20 ) {
int16_t val = (scur+20)-t2;
if(val > 15) {
val = 15;
}
memset( master_bright_sub, (1<<7) | val, 2 );
}
else if(t2 < ecur - 16) {
memset( master_bright_sub, (1<<7) | 0, 2 );
}
else if( t2 < ecur ) {
int16_t val = 16-(ecur-t2);
memset( master_bright_sub, (1<<7) | val, 2 );
}
else {
memset( master_bright_sub, (1<<7) | 16, 2 );
}
}
// EFFECTS:
// Sub:
// 0: Subscreen whopper. PERMAUSES VRAM C don't use that.
// Main:
// Metaballs: Metaballs
// 1: ECG
// 2: Greets
// 3: Ribbons
// Field: Raymarching
// TODO:
// Starfield?
// Tunnel?
// Vectorballs?
// Intro effect with title (and names?)
// Outro effect with "loves you / vote for us damnit"
// 80ms / row
// 0.08s / row
// 12.5 rows / s
// 60 frames / second
// 4.8 frames / row
// 0.208333333333333 rows / frame
volatile int unts = 0;
volatile int unts_proc = 0;
mm_word myEventHandler( mm_word msg, mm_word param )
{
switch( msg )
{
case MMCB_SONGMESSAGE:
unts = param;
unts_proc = 0;
break;
}
}
int main()
{
// Turn on everything.
POWCNT1 = POWCNT1_ALL_SWAP;
irqEnable( IRQ_VBLANK );
irqSet(IRQ_VBLANK,vblank);
ClaimWRAM();
t = 0;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
memset( master_bright_sub, (1<<7) | 16, 2 );
// Init NitroFS for data loading.
nitroFSInitAdv( BINARY_NAME );
tempImage = malloc(256*256*2);
#ifdef DEBUG
// consoleDemoInit();
// iprintf( "Debug mode.\n" );
#endif
// Main loop
// #define EFFECT_DEBUG
#ifdef EFFECT_DEBUG
effect0_init();
effect2_init();
// InitField();
// InitHeartField();
metaballs_precompute();
#else
// effect3_init();
// effect3_destroy();
effect0_init();
metaballs_precompute();
preloadSprites();
// LATER TODO: Init intro
effect7_init();
#endif
uint8_t *wram=(uint8_t *)0x3000000;
// memset(wram,0,128*96);
mmInitDefault( "nitro:/zik/music.bin" );
mmLoad( MOD_WIENERLONG );
mmStart( MOD_WIENERLONG, MM_PLAY_ONCE );
mmSetEventHandler( myEventHandler );
int next_effect_init = 0;
toff = t;
while( 1 ) { // TODO duration
#define DUR (64.0 * 2.0 * (4.8))
//#define DUR (60*4)
#ifdef EFFECT_DEBUG
effect0_update(t-toff);
// // RunHeartField(t);
effect2_update(t);
blockload = 0;
// RunField(t);
// // metaballs_update(t);
// if( t == 16*20+30 ) {
// effect0_change(1);
// }
#else
if( t - toff < 2*DUR ) {
effect7_update(t);
fadeinout(t-toff,0,2*DUR);
fadeinoutsub(t-toff,1*DUR,200*DUR);
blockload = 0;
}
else if(t - toff < 3*DUR) {
if(next_effect_init < 1) {
effect0_change(0);
fadeinout(t-toff,2*DUR,3*DUR);
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
next_effect_init++;
effect7_destroy();
effect4_init();
effect4_update(t);
blockload = 0;
}
effect4_update(t);
}
else if(t - toff < 4*DUR) {
if(next_effect_init < 2) {
effect0_change(1);
fadeinout(t-toff,3*DUR,4*DUR);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect4_destroy();
effect3_init();
effect3_update(t);
blockload = 0;
}
effect3_update(t);
}
else if(t - toff < 5*DUR) {
if(next_effect_init < 3) {
effect0_change(2);
fadeinout(t-toff,4*DUR,5*DUR);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect3_destroy();
metaballs_init();
blockload = 0;
}
metaballs_update(t);
}
else if(t - toff < 6*DUR) {
if(next_effect_init < 4) {
effect0_change(3);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
metaballs_destroy();
InitHeartField();
RunHeartField(t);
blockload = 0;
}
RunHeartField(t);
fadeinout(t-toff,5*DUR,6*DUR);
}
else if(t - toff < 8*DUR) {
if(next_effect_init < 5) {
effect0_change(4);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
// No stop heart field.
effect2_init();
effect2_update(t);
blockload = 0;
}
effect2_update(t);
fadeinout(t-toff,6*DUR,8*DUR);
}
else if(t - toff < 9*DUR) {
if(next_effect_init < 6) {
effect0_change(5);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect2_destroy();
effect6_init();
effect6_update(t);
blockload = 0;
}
effect6_update(t);
fadeinout(t-toff,8*DUR,9*DUR);
}
else if(t - toff < 10*DUR) {
if(next_effect_init < 7) {
effect0_change(6);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect6_destroy();
effect1_init();
effect1_update(t);
blockload = 0;
}
effect1_update(t);
fadeinout(t-toff,9*DUR,10*DUR);
}
else if(t - toff < 12*DUR) {
if(next_effect_init < 8) {
effect0_change(7);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect1_destroy();
InitField();
RunField(t);
RunField(t);
blockload = 0;
}
if(t - toff > 11*DUR && unts == 1) {
RunField(t+1200);
}
else {
RunField(t);
}
fadeinout(t-toff,10*DUR,12*DUR);
}
else if(t - toff < 13*DUR) {
if(next_effect_init < 9) {
effect0_change(8);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
StopField();
effect7_init_2();
effect7_update(t);
blockload = 0;
}
effect7_update(t);
fadeinout(t-toff,12*DUR,13*DUR);
}
else {
if(next_effect_init < 10) {
effect0_change(9);
next_effect_init++;
blockload = 1;
memset( master_bright, (1<<7) | 16, 2 );
effect7_init_3();
effect7_update(t);
blockload = 0;
}
effect7_update(t);
fadeinout(t-toff,13*DUR,14*DUR);
fadeinoutsub(t-toff,0,14*DUR);
}
#endif
swiWaitForVBlank();
}
POWCNT1 = POWCNT1_ALL;
for(;;);
return 0;
}
static void vblank() {
t++;
uint32_t t2 = t - toff;
if( t2 <= scur || blockload ) {
memset( master_bright, (1<<7) | 16, 2 );
} else if( t2 < scur+20 ) {
int16_t val = (scur+20)-t2;
if(val > 15) {
val = 15;
}
memset( master_bright, (1<<7) | val, 2 );
}
else if(t2 < ecur - 16) {
memset( master_bright, (1<<7) | 0, 2 );
}
else if( t2 < ecur ) {
int16_t val = 16-(ecur-t2);
memset( master_bright, (1<<7) | val, 2 );
}
else {
memset( master_bright, (1<<7) | 16, 2 );
}
effect0_update(t-toff);
}