-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.c
197 lines (166 loc) · 3.45 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
/**
* 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];
volatile int unts = 0;
volatile int unts_proc = 0;
uint32_t effect = 0;
uint32_t last_effect = 0;
mm_word myEventHandler( mm_word msg, mm_word param )
{
switch( msg )
{
case MMCB_SONGMESSAGE:
if(param != 3) {
unts = param;
unts_proc = 0;
}
else {
effect++;
}
break;
}
}
void fadeout(int t, int b) {
uint16_t* master_bright = (uint16_t*)(0x400006C);
uint16_t* master_bright_sub = (u16*)(0x400106C);
if( t > b-16 ) {
uint16_t val = 18-(b-t);
memset( master_bright, (1<<7) | val, 2 );
memset( master_bright_sub, (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 );
}
}
int32_t fadet = 0;
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;
uint8_t *wram=(uint8_t *)0x3000000;
// memset(wram,0,128*96);
mmInitDefault( "nitro:/zik/music.bin" );
mmLoad( MOD_MUSIC );
mmStart( MOD_MUSIC, MM_PLAY_ONCE );
mmSetEventHandler( myEventHandler );
// palflip_init();
effect1_init();
// effect6_init();
// effect7_init();
// effect5_init();
// effect1_init();
// t = 1340;
while( 1 ) {
if(unts != 0 && unts_proc == 1) {
unts = 0;
}
if(0) {
// effect7_update(t);
// effect6_update(t);
// effect1_update(t);
// palflip_update(t);
}
else {
if(effect == 0) {
effect1_update(t);
}
if(effect == 1 && last_effect == 0) {
last_effect++;
effect1_destroy();
effect7_init();
}
if(effect == 1) {
effect7_update(t);
}
if(effect == 2 && last_effect == 1) {
last_effect++;
effect7_destroy();
effect5_init();
}
if(effect == 2) {
effect5_update(t);
}
if(effect == 3 && last_effect == 2) {
last_effect++;
effect5_destroy();
effect6_init();
}
if(effect == 3) {
effect6_update(t);
}
if(effect == 4 && last_effect == 3) {
last_effect++;
effect6_destroy();
palflip_init();
}
if(effect == 4) {
palflip_update(t);
}
if(effect == 5 && last_effect == 4) {
last_effect++;
fadet = t;
}
if(fadet > 0 && t <= fadet + 16) {
fadeout(t,fadet + 16);
}
if(effect == 6 && t > fadet + 16 ) {
swiWaitForVBlank();
}
}
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++; }