Skip to content

Commit cf397fa

Browse files
messed things up rather than solve something
trying to get the best frame rendering time
1 parent 96dbeda commit cf397fa

3 files changed

Lines changed: 215 additions & 59 deletions

File tree

arm9/include/player.h

Lines changed: 191 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,24 @@ const u16 FlipnoteColors[4] =
9393
0xFCE1 // Blue
9494
};
9595

96-
void buildLayer(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *diffing)
96+
struct decodeType
9797
{
98-
if((*diffing))
98+
int i, k;
99+
u8 first_byte_header;
100+
s8 tX, tY;
101+
bool diffing;
102+
};
103+
104+
void buildLayer(struct decodeType* dt)
105+
{
106+
/*if(dt->diffing)
99107
{
100108
memcpy(layerA,layer,LAYER_SIZE);
101-
}
109+
}*/
102110
for(u16 y=0;y<192;y++)
103111
{
104112
u16 yy=y<<5;
105-
switch((ppm_AnimationData[(*i)+(y>>2)]>>((y&0x3)<<1)) & 0x3)
113+
switch((ppm_AnimationData[dt->i+(y>>2)]>>((y&0x3)<<1)) & 0x3)
106114
{
107115
case 0:
108116
{
@@ -112,12 +120,24 @@ void buildLayer(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *dif
112120
}
113121
case 3:
114122
{
115-
for(u16 c=0;c<32;c++)
123+
for(u16 c=32;c--;)
116124
{
117-
u8 chunk=ppm_AnimationData[(*k)++];
118-
for(u8 b=0;b<8;b++)
119-
layer[yy] ^= ((-(u8)((chunk>>b)&1) ^ layer[yy]) & (1<<b));
120-
yy++;
125+
/**
126+
NIL, blindly translating from pixel-plotting to
127+
bit setting on buffer array:
128+
129+
u8 chunk=ppm_AnimationData[dt->k++];
130+
for(int b=0;b<8;b++)
131+
layer[yy] ^= (-(u8)((chunk>>b)&1) ^ layer[yy]) & (1<<b);
132+
yy++;
133+
134+
Hmm, I don't know why, this seems a lil bit costy.
135+
Let's see what can actually replace it:
136+
*/
137+
/******************************/
138+
layer[yy++] = ppm_AnimationData[dt->k++];
139+
/******************************/
140+
/** Yes, I am THAT dumb =))) **/
121141
}
122142
break;
123143
}
@@ -135,17 +155,17 @@ void buildLayer(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *dif
135155

136156
__DECODETYPE_1_2__: ;
137157

138-
u32 bytes=ppm_AnimationData[(*k)++]<<24;
139-
bytes|=ppm_AnimationData[(*k)++]<<16;
140-
bytes|=ppm_AnimationData[(*k)++]<<8;
141-
bytes|=ppm_AnimationData[(*k)++];
158+
u32 bytes=ppm_AnimationData[dt->k++]<<24;
159+
bytes|=ppm_AnimationData[dt->k++]<<16;
160+
bytes|=ppm_AnimationData[dt->k++]<<8;
161+
bytes|=ppm_AnimationData[dt->k++];
142162
for(;bytes;)
143163
{
144164
if(bytes & 0x80000000)
145165
{
146-
u8 chunk=ppm_AnimationData[(*k)++];
147-
for(int b=0;b<8;b++)
148-
layer[yy] ^= (-(u8)((chunk>>b)&1) ^ layer[yy]) & (1<<b);
166+
/******************************/
167+
layer[yy] = ppm_AnimationData[dt->k++];
168+
/******************************/
149169
}
150170
bytes<<=1;
151171
yy++;
@@ -154,60 +174,190 @@ void buildLayer(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *dif
154174
}
155175
}
156176
}
157-
if((*diffing))
177+
/*if(dt->diffing)
158178
{
159179
for(u16 y=0;y<192;y++)
160180
{
161-
if(y<(*tY)) continue;
162-
if(y-(*tY)>=192) break;
163-
u16 BL=y<<5,BA=(y-(*tY))<<5;
181+
if(y<dt->tY) continue;
182+
if(y-dt->tY>=192) break;
183+
u16 BL=y<<5,BA=(y-dt->tY)<<5;
164184
for(u8 c=0;c<32;c++)
165185
for(u8 b=0;b<8;b++)
166186
{
167187
u8 x=8*c+b;
168-
if(x<(*tX)) continue;
169-
if(x-(*tX)>=256) break;
170-
u8 dx=(x-(*tX));
188+
if(x<dt->tX) continue;
189+
if(x-dt->tX>=256) break;
190+
u8 dx=(x-dt->tX);
171191
layer[BL+c]^= ((bool)(layerA[BA+(dx>>3)]&(1<<(dx&0x7))))<<b;
172192
}
173193
}
174-
}
194+
}*/
175195
}
176196

177-
/* [ vBlank Op ] Because minimum flipnote frame rate is 30 fps (so a frame each 2 vBlanks)
197+
/* [ vBlank Op ] Because maximum flipnote frame rate is 30 fps (so a frame each 2 vBlanks)
178198
I decided render each of the two layers on a separate vBlank
179199
Hope this will minimize the chances of missing vBlanks, which could cause
180200
synchronization troubles
181201
*/
182202

183-
void playerNextFrameVBlank0(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *diffing)
203+
void playerNextFrameVBlank0(struct decodeType* dt)
184204
{
185-
(*i)=ppm_OffsetTable[PlayerFrameIndex];
186-
(*first_byte_header)=ppm_AnimationData[(*i)++];
187-
(*tX)=0,(*tY)=0; // translate parameters
188-
(*diffing)=!((*first_byte_header) & 0b10000000);
189-
if((*first_byte_header) & 0b01100000)
205+
dt->i=ppm_OffsetTable[PlayerFrameIndex];
206+
dt->first_byte_header=ppm_AnimationData[dt->i++];
207+
dt->tX=0,dt->tY=0; // translate parameters
208+
dt->diffing=!(dt->first_byte_header & 0b10000000);
209+
if(dt->first_byte_header & 0b01100000)
190210
{
191-
(*tX)=ppm_AnimationData[(*i)++];
192-
(*tY)=ppm_AnimationData[(*i)++];
211+
dt->tX=ppm_AnimationData[dt->i++];
212+
dt->tY=ppm_AnimationData[dt->i++];
193213
}
194214

195215
layer=layer1;
196-
(*k)=(*i)+0x60;
197-
buildLayer(i, k, first_byte_header, tX, tY, diffing);
216+
dt->k=dt->i+0x60;
217+
buildLayer(dt);
198218
}
199219

200-
void playerNextFrameVBlank1(int *i, int *k, u8 *first_byte_header, s8 *tX, s8 *tY, bool *diffing)
220+
void playerNextFrameVBlank1(struct decodeType* dt)
201221
{
202222
layer=layer2;
203-
(*i)+=0x30;
204-
buildLayer(i, k, first_byte_header, tX, tY, diffing);
223+
dt->i+=0x30;
224+
buildLayer(dt);
225+
226+
u16 paperColor = (dt->first_byte_header & 1);
227+
u16 layer1Color = (dt->first_byte_header>>1) & 0x3;
228+
if(layer1Color<2)
229+
layer1Color = 1-paperColor;
230+
u16 layer2Color = (dt->first_byte_header>>3) & 0x3;
231+
if(layer2Color<2)
232+
layer2Color = 1-paperColor;
233+
paperColor=FlipnoteColors[paperColor];
234+
layer1Color=FlipnoteColors[layer1Color];
235+
layer2Color=FlipnoteColors[layer2Color];
236+
237+
for(u16 y=0,yy=0;y<192;y++)
238+
{
239+
//u16 yy=(y<<5);
240+
for(u8 c=32;c--;yy++)
241+
{
242+
for(u8 b=0;b<8;b++)
243+
{
244+
u16 p=(yy<<3)+b;
245+
if(layer1[yy]&(1<<b))
246+
mainGFX[p]=layer1Color;
247+
else
248+
mainGFX[p]=(layer2[yy]&(1<<b))?layer2Color:paperColor;
249+
}
250+
}
251+
}
252+
253+
playerSwapBuffers();
254+
PlayerFrameIndex++;
255+
if(PlayerFrameIndex==ppmHead_FrameCount)
256+
{
257+
PlayerFrameIndex=0;
258+
}
259+
}
260+
261+
void playerNextFrame()
262+
{
263+
int i=ppm_OffsetTable[PlayerFrameIndex];
264+
u8 first_byte_header=ppm_AnimationData[i++];
265+
s8 tX=0,tY=0; // translate parameters
266+
bool diffing=!(first_byte_header & 0b10000000);
267+
if(first_byte_header & 0b01100000)
268+
{
269+
tX=ppm_AnimationData[i++];
270+
tY=ppm_AnimationData[i++];
271+
}
272+
273+
layer=layer1;
274+
int k=i+0x60;
275+
276+
__LBL__BUILD_LAYER__:
277+
if(diffing)
278+
{
279+
memcpy(layerA,layer,LAYER_SIZE);
280+
}
281+
for(u16 y=0;y<192;y++)
282+
{
283+
u16 yy=y<<5;
284+
switch((ppm_AnimationData[i+(y>>2)]>>((y&0x3)<<1)) & 0x3)
285+
{
286+
case 0:
287+
{
288+
for(u8 _i=0;_i<32;_i++)
289+
layer[yy++]=0;
290+
break;
291+
}
292+
case 3:
293+
{
294+
for(u16 c=0;c<32;c++)
295+
{
296+
layer[yy++]=ppm_AnimationData[k++];
297+
}
298+
break;
299+
}
300+
case 2:
301+
{
302+
// Fill line
303+
for(int _i=0; _i<32; layer[yy+(_i++)]=0xFF);
304+
goto __DECODETYPE_1_2__;
305+
}
306+
307+
case 1:
308+
{
309+
// Clear line
310+
for(int _i=0; _i<32; layer[yy+(_i++)]=0);
311+
312+
__DECODETYPE_1_2__: ;
313+
314+
u32 bytes=ppm_AnimationData[k++]<<24;
315+
bytes|=ppm_AnimationData[k++]<<16;
316+
bytes|=ppm_AnimationData[k++]<<8;
317+
bytes|=ppm_AnimationData[k++];
318+
for(;bytes;)
319+
{
320+
if(bytes & 0x80000000)
321+
{
322+
layer[yy]=ppm_AnimationData[k++];
323+
}
324+
bytes<<=1;
325+
yy++;
326+
}
327+
break;
328+
}
329+
}
330+
}
331+
if(diffing)
332+
{
333+
for(u16 y=0;y<192;y++)
334+
{
335+
if(y<tY) continue;
336+
if(y-tY>=192) break;
337+
u16 BL=y<<5,BA=(y-tY)<<5;
338+
for(u8 c=0;c<32;c++)
339+
for(u8 b=0;b<8;b++)
340+
{
341+
u8 x=8*c+b;
342+
if(x<tX) continue;
343+
if(x-tX>=256) break;
344+
u8 dx=(x-tX);
345+
layer[BL+c]^= ((bool)(layerA[BA+(dx>>3)]&(1<<(dx&0x7))))<<b;
346+
}
347+
}
348+
}
349+
if(layer==layer1)
350+
{
351+
layer=layer2;
352+
i+=0x30;
353+
goto __LBL__BUILD_LAYER__;
354+
}
205355

206-
u16 paperColor = ((*first_byte_header) & 1);
207-
u16 layer1Color = ((*first_byte_header)>>1) & 0x3;
356+
u16 paperColor = (first_byte_header & 1);
357+
u16 layer1Color = (first_byte_header>>1) & 0x3;
208358
if(layer1Color<2)
209359
layer1Color = 1-paperColor;
210-
u16 layer2Color = ((*first_byte_header)>>3) & 0x3;
360+
u16 layer2Color = (first_byte_header>>3) & 0x3;
211361
if(layer2Color<2)
212362
layer2Color = 1-paperColor;
213363
paperColor=FlipnoteColors[paperColor];

arm9/include/vars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ bool PlayerThumbnailNeedsRedraw = false;
4848

4949
u16 PlayerFrameIndex=0;
5050

51-
const u8 frameTime[9]= { 0, 120, 60, 30, 15, 10, 5, 3, 2 };
51+
struct decodeType dt;
5252

5353
#endif // FSPDS_VARS_H_INCLUDED

arm9/source/main.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#include "player.h"
66
#include "tabsystem.h"
77

8+
time_t rawTime;
9+
10+
void clockUpdater()
11+
{
12+
rawTime++;
13+
}
14+
815
int main(int argc, char ** argv)
916
{
1017
initConsole();
@@ -25,14 +32,12 @@ int main(int argc, char ** argv)
2532
playerClear();
2633
displayThumbnail();
2734

28-
35+
time(&rawTime);
36+
timerStart(0,ClockDivider_1024,TIMER_FREQ_1024(1),clockUpdater);
2937
u16 counter=0;
30-
int iPos, kPos;
31-
u8 first_byte_header;
32-
s8 tX=0,tY=0; // translate parameters
33-
bool diffing;
34-
while(1)
38+
while(1)
3539
{
40+
swiWaitForVBlank();
3641
scanKeys();
3742
uint32 input=keysDown();
3843
if(input == 0)
@@ -66,22 +71,23 @@ int main(int argc, char ** argv)
6671

6772
if(PlayerState==PLAYING)
6873
{
69-
if(counter==0) // vBlankOp
70-
{
71-
playerNextFrameVBlank0(&iPos,&kPos,&first_byte_header,&tX,&tY,&diffing);
72-
}
73-
else if(counter==1)
74+
//playerNextFrame();
75+
//counter++;
76+
/*if(counter==1)
7477
{
75-
playerNextFrameVBlank1(&iPos,&kPos,&first_byte_header,&tX,&tY,&diffing);
78+
playerNextFrameVBlank0(&dt);
7679
}
77-
counter++;
78-
if(counter==frameTime[ppm_FramePlaybackSpeed])
80+
else*/ //if(counter==2)
7981
{
80-
counter=0;
82+
//playerNextFrameVBlank1(&dt);
83+
//playerNextFrame();
84+
//counter=0;
8185
}
86+
//playerNextFrameVBlank0(&dt);
87+
//swiWaitForVBlank();
88+
//playerNextFrameVBlank1(&dt);
89+
playerNextFrame();
8290
}
83-
else counter=0;
84-
swiWaitForVBlank();
8591
}
8692

8793
return 0;

0 commit comments

Comments
 (0)