-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffect6.c
248 lines (208 loc) · 5.89 KB
/
effect6.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
// AO Cubes
#include <nds.h>
#include "DS3D/Utils.h"
#include "DS3D/DS3D.h"
#include "VoxelBlock.h"
#include "Hardware.h"
#include "Loader.h"
#include "RainbowTable.h"
int cubemode = 1;
// Cap/flip
void capflip() {
if( cubemode == 1 ) {
int capsrc;
capsrc=DISPCAPCNT_SRC_A_3D;
VRAMCNT_A = VRAMCNT_A_LCDC;
DISPCAPCNT=DISPCAPCNT_WRITE_VRAM_A|DISPCAPCNT_SIZE_256x192
|capsrc|DISPCAPCNT_SRC_A|DISPCAPCNT_ENABLE;
s16* bg = (u16*)(VRAM_A_OFFS_0K);
s16* img = (u16*)(VRAM_LCDC_A);
u16 tmp;
for( int i = 0; i < 256*192; i+=3 ) {
tmp = img[256*192-i];
bg[i] = tmp <= 0x7FFF ? 0xFFFF : tmp;
}
}
}
VoxelBlock block;
VoxelBlock block2;
u16 aocubepal[512];
void effect6_init() {
DISPCNT_A=DISPCNT_MODE_5|DISPCNT_3D|DISPCNT_BG0_ON|DISPCNT_BG3_ON|DISPCNT_ON;
VRAMCNT_A = VRAMCNT_A_LCDC;
int dx = icos(128)/26.5;
int dy = isin(128)/26.5;
BG2PA_B = dx;
BG2PB_B = dy;
BG2PC_B = -dy;
BG2PD_B = dx;
BG2X_B = 4000;
BG2Y_B = 10000;
// Set up voxelcubes
VRAMCNT_D=VRAMCNT_D_LCDC;
VRAMCNT_F=VRAMCNT_F_LCDC;
loadVRAMIndirect( "nitro:/textures.pal4", VRAM_LCDC_D,16384);
for(int i=0;i<16;i++) VRAM_LCDC_F[i]=MakeRGB15(i+16,i+16,i+16);
VRAMCNT_D=VRAMCNT_D_TEXTURE_OFFS_0K;
VRAMCNT_F=VRAMCNT_F_TEXTURE_PALETTE_SLOT_0;
DSInit3D();
DSViewport(0,0,255,191);
DSSetControl(DS_TEXTURING|DS_ANTIALIAS);
DSClearParams(26,26,26,0,63);
DSSetPaletteOffset(0,DS_TEX_FORMAT_PAL4);
DSMatrixMode(DS_PROJECTION);
DSLoadIdentity();
DSPerspectivef(100,256.0/192.0,1,1024);
InitVoxelBlock(&block,17,17,64,NULL);
InitVoxelBlock(&block2,3,3,3,NULL);
// Background
VRAMCNT_B = VRAMCNT_B_BG_VRAM_A_OFFS_0K;
VRAMCNT_C = VRAMCNT_C_BG_VRAM_A_OFFS_128K;
BG3CNT_A = BGxCNT_EXTENDED_BITMAP_8 | BGxCNT_BITMAP_SIZE_256x256 | BGxCNT_OVERFLOW_TRANSPARENT | BGxCNT_BITMAP_BASE_0K;
BG3CNT_A = (BG3CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_0;
BG3PA_A = (1 << 8);
BG3PB_A = 0;
BG3PC_A = 0;
BG3PD_A = (1 << 8);
BG3X_A = 0;
BG3Y_A = 0;
if( cubemode == 0 ) {
load8bVRAMIndirect( "nitro:/gfx/aocubes.img.bin", VRAM_A_OFFS_0K,256*192*2);
loadVRAMIndirect( "nitro:/gfx/aocubes.pal.bin", PALRAM_A,256*2);
loadVRAMIndirect( "nitro:/gfx/aocubes.pal.bin", aocubepal,256*2);
}
else {
uint16_t* bg = VRAM_A_OFFS_128K;
for( int i = 0; i < 256*256; i++ ) {
bg[i] = 0;
}
load8bVRAMIndirect( "nitro:/gfx/svatg.img.bin", VRAM_A_OFFS_128K,256*256);
loadVRAMIndirect( "nitro:/gfx/svatg.pal.bin", PALRAM_A,256*2);
}
if( cubemode == 1 ) {
// Other version.
s16* bg = (u16*)(VRAM_A_OFFS_0K);
for( int i = 0; i < 256*192; i++ ) {
u16 c = ((i+1)%3) == 0 ? 5 : 0;
c = ((i+2)%3) == 0 ? 26 : 23;
bg[i] = 0|(int)(c*0.5)<<5|c|0x8000;
}
DISPCNT_A |= DISPCNT_BG3_ON | DISPCNT_BG2_ON;
BG3CNT_A = BGxCNT_EXTENDED_BITMAP_16 | BGxCNT_BITMAP_SIZE_256x256 | BGxCNT_OVERFLOW_WRAP | BGxCNT_BITMAP_BASE_0K;
BG3CNT_A = (BG3CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_1;
BG0CNT_A = (BG0CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_2;
BG3PA_A = dx;
BG3PB_A = dy;
BG3PC_A = -dx;
BG3PD_A = dy;
BG3X_A = 0;
BG3Y_A = 0;
// Background
BG2CNT_A = BGxCNT_EXTENDED_BITMAP_8 | BGxCNT_BITMAP_SIZE_256x256 | BGxCNT_OVERFLOW_WRAP | BGxCNT_BITMAP_BASE_128K;
BG2CNT_A = (BG2CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_0;
BG2PA_A = (1 << 8);
BG2PB_A = 0;
BG2PC_A = 0;
BG2PD_A = (1 << 8);
BG2X_A = 0;
BG2Y_A = -31500;
int dx = icos(128)/26.5;
int dy = isin(128)/26.5;
BG3PA_A=dx;
BG3PB_A=dy;
BG3PC_A=-dy;
BG3PD_A=dx;
BG3X_A=-128*dx-92*dy+(128<<8)+7000;
BG3Y_A=+128*dy-92*dx+(92<<8)+5000;
}
}
void voxelSpiral(int t) {
// Kludge
static int lt = 0;
lt++;
t = lt;
static uint8_t ri = 0;
DSMatrixMode(DS_POSITION);
DSLoadIdentity();
// Cross
for( int i = 0; i < 3; i++ ) {
SetVoxelAt(&block2,i,1,1,rainbowTable[ri]|0x8000);
SetVoxelAt(&block2,1,i,1,rainbowTable[(ri+10)%255]|0x8000);
SetVoxelAt(&block2,1,1,i,rainbowTable[(ri+30)%255]|0x8000);
}
RefreshVoxelBlock(&block2);
// Move blocks
if(t%4==0) {
ScrollVoxelBlockByZ(&block);
}
// Spiral rainbows
float dxp = (icos((t-3)<<3)>>9);
float dyp = (isin((t-3)<<3)>>9);
float dx = (icos(t<<3)>>9);
float dy = (isin(t<<3)>>9);
u16 c = rainbowTable[++ri]|0x8000;
u16 d = rainbowTable[(ri+40)%255]|0x8000;
u16 e = rainbowTable[(ri+90)%255]|0x8000;
u16 f = rainbowTable[(ri+170)%255]|0x8000;
for( int i = 0; i < 3; i++ ) {
SetVoxelAt(&block,i+8+dxp,8+dyp,0,0);
SetVoxelAt(&block,i+8+dx,8+dy,0,c);
SetVoxelAt(&block,i+8+dyp,8-dxp,0,0);
SetVoxelAt(&block,i+8+dy,8-dx,0,d);
SetVoxelAt(&block,i+8-dxp,8-dyp,0,0);
SetVoxelAt(&block,i+8-dx,8-dy,0,e);
SetVoxelAt(&block,i+8-dyp,8+dxp,0,0);
SetVoxelAt(&block,i+8-dy,8+dx,0,f);
}
for( int i = -1; i < 2; i+=2 ) {
SetVoxelAt(&block,9+dxp,i+8+dyp,0,0);
SetVoxelAt(&block,9+dx,i+8+dy,0,c);
SetVoxelAt(&block,9+dyp,i+8-dxp,0,0);
SetVoxelAt(&block,9+dy,i+8-dx,0,d);
SetVoxelAt(&block,9-dxp,i+8-dyp,0,0);
SetVoxelAt(&block,9-dx,i+8-dy,0,e);
SetVoxelAt(&block,9-dyp,i+8+dxp,0,0);
SetVoxelAt(&block,9-dy,i+8+dx,0,f);
}
RefreshVoxelBlock(&block);
// Move things
DSTranslatef(0,0,200);
DSRotateZi(-t<<2);
DSScalef(8,8,8);
DSTranslatef32(DSf32(0),DSf32(0),((t&3)<<10)-DSf32(33));
DrawVoxelBlock(&block);
DSTranslatef32(DSf32(0),DSf32(0),-((t&3)<<10)+DSf32(2));
DSRotateYi(512+t<<4);
DSRotateXi(256-t<<3);
DSRotateZi(-t<<2);
DrawVoxelBlock(&block2);
DSSwapBuffers(0);
}
void objectShow(int t) {
static uint8_t ri = 0;
DSMatrixMode(DS_POSITION);
DSLoadIdentity();
DSSwapBuffers(0);
}
uint8_t effect6_update( uint32_t t ) {
capflip();
voxelSpiral(t);
if( cubemode != 1 ) {
static u16 colpal[25];
u16 col;
for( int i = 0; i < 25; i++ ) {
s16 val = (isin(t*53*2)>>9)+10;
col = aocubepal[i];
col = col & 0x1F;
col = col + val;
col = col <= 31 ? col : 31;
col = (int)(col*0.8) | (int)(col*0.9) << 5 | col << 10;
colpal[i] = col;
}
dmaCopyHalfWords( 0, colpal, PALRAM_A, 2*25 );
}
return 0;
}
void effect6_destroy() {
CleanupVoxelBlock(&block);
}