dots: more size optimization

This commit is contained in:
Vince Weaver 2023-12-01 08:22:04 -05:00
parent 085689df38
commit 65091783da
4 changed files with 40 additions and 31 deletions

View File

@ -61,7 +61,7 @@ dots_minimal.o: dots_minimal.c
dots_6502: dots_6502.o ../gr-sim.a
$(CC) -o dots_6502 dots_6502.o ../gr-sim.a $(LFLAGS) $(SDL_LIBS)
dots_6502.o: dots_6502.c
dots_6502.o: dots_6502.c sin256.h
$(CC) $(CFLAGS) $(SDL_INCLUDE) -c dots_6502.c

View File

@ -220,9 +220,9 @@ int main(int argc,char **argv) {
// dot[i].x=isin(f*11)*40;
// dot[i].y=icos(f*13)*10-dropper;
// dot[i].z=isin(f*17)*40;
dot_x[i]=isin(f*2)*32; // 8
dot_y[i]=icos(f*4)*8-dropper; // 16
dot_z[i]=isin(f*4)*32; // 16
dot_x[i]=isin(f*2)*32*2; // 8
dot_y[i]=icos(f*4)*8*2-dropper; // 16
dot_z[i]=isin(f*4)*32*2; // 16
dot_yadd[i]=0;
}
/* bouncing ring */
@ -231,9 +231,9 @@ int main(int argc,char **argv) {
// dot[i].y=dropper;
// dot[i].z=isin(f*15)*55;
// dot[i].yadd=-260;
dot_x[i]=icos(f*4)*48; // 16
dot_x[i]=icos(f*4)*48*2; // 16
dot_y[i]=dropper;
dot_z[i]=isin(f*4)*48; // 16
dot_z[i]=isin(f*4)*48*2; // 16
dot_yadd[i]=-260;
}
/* fountain */
@ -243,10 +243,10 @@ int main(int argc,char **argv) {
// dot[i].y=8000;
// dot[i].z=isin(f*66)*a;
// dot[i].yadd=-300;
a=sin256[(frame>>2)&255]/8;
dot_x[i]=icos(f*16)*a; // 64
a=sin256[(frame>>2)&255]*2/8;
dot_x[i]=icos(f*16)*2*a; // 64
dot_y[i]=8000;
dot_z[i]=isin(f*16)*a; // 64
dot_z[i]=isin(f*16)*2*a; // 64
dot_yadd[i]=-300;
}
/* swirling */
@ -262,13 +262,13 @@ int main(int argc,char **argv) {
printf("rot=%d\n",rot);
rotcos=icos(rot)*64; rotsin=isin(rot)*64;
rotcos=icos(rot)*128; rotsin=isin(rot)*128;
rots+=1;
if(frame>1357) {
rot+=rota/64/4;
rota--;
} else rot=isin(rots>>2);
} else rot=isin(rots>>2)*2;
f++;
gravity=grav;

View File

@ -2,6 +2,9 @@
#include <math.h>
int generate_1024=0;
//double sin_max=256.0;
double sin_max=128.0;
int main(int argc, char **argv) {
@ -12,16 +15,22 @@ int main(int argc, char **argv) {
printf("int16_t sin1024[]={\n");
for(i=0;i<1024;i++) {
angle=(i/1024.0)*(2.0*3.1415926535897932384);
s=sin(angle)*256.0;
s=sin(angle)*sin_max;
printf("%d,",(int)s);
if (i%16==15) printf("\n");
}
printf("};\n");
} else {
printf("int16_t sin256[]={\n");
if (sin_max<200) {
printf("int8_t sin256[]={\n");
}
else {
printf("int16_t sin256[]={\n");
}
for(i=0;i<256;i++) {
angle=(i/256.0)*(2.0*3.1415926535897932384);
s=sin(angle)*256.0;
s=sin(angle)*sin_max;
if ( ((int)s)>=((int)sin_max) ) s=s-1;
printf("%d,",(int)s);
if (i%16==15) printf("\n");
}

View File

@ -1,18 +1,18 @@
int16_t sin256[]={
0,6,12,18,25,31,37,43,49,56,62,68,74,80,86,92,
97,103,109,115,120,126,131,136,142,147,152,157,162,167,171,176,
181,185,189,193,197,201,205,209,212,216,219,222,225,228,231,234,
236,238,241,243,244,246,248,249,251,252,253,254,254,255,255,255,
256,255,255,255,254,254,253,252,251,249,248,246,244,243,241,238,
236,234,231,228,225,222,219,216,212,209,205,201,197,193,189,185,
181,176,171,167,162,157,152,147,142,136,131,126,120,115,109,103,
97,92,86,80,74,68,62,56,49,43,37,31,25,18,12,6,
0,-6,-12,-18,-25,-31,-37,-43,-49,-56,-62,-68,-74,-80,-86,-92,
-97,-103,-109,-115,-120,-126,-131,-136,-142,-147,-152,-157,-162,-167,-171,-176,
-181,-185,-189,-193,-197,-201,-205,-209,-212,-216,-219,-222,-225,-228,-231,-234,
-236,-238,-241,-243,-244,-246,-248,-249,-251,-252,-253,-254,-254,-255,-255,-255,
-256,-255,-255,-255,-254,-254,-253,-252,-251,-249,-248,-246,-244,-243,-241,-238,
-236,-234,-231,-228,-225,-222,-219,-216,-212,-209,-205,-201,-197,-193,-189,-185,
-181,-176,-171,-167,-162,-157,-152,-147,-142,-136,-131,-126,-120,-115,-109,-103,
-97,-92,-86,-80,-74,-68,-62,-56,-49,-43,-37,-31,-25,-18,-12,-6,
int8_t sin256[]={
0,3,6,9,12,15,18,21,24,28,31,34,37,40,43,46,
48,51,54,57,60,63,65,68,71,73,76,78,81,83,85,88,
90,92,94,96,98,100,102,104,106,108,109,111,112,114,115,117,
118,119,120,121,122,123,124,124,125,126,126,127,127,127,127,127,
127,127,127,127,127,127,126,126,125,124,124,123,122,121,120,119,
118,117,115,114,112,111,109,108,106,104,102,100,98,96,94,92,
90,88,85,83,81,78,76,73,71,68,65,63,60,57,54,51,
48,46,43,40,37,34,31,28,24,21,18,15,12,9,6,3,
0,-3,-6,-9,-12,-15,-18,-21,-24,-28,-31,-34,-37,-40,-43,-46,
-48,-51,-54,-57,-60,-63,-65,-68,-71,-73,-76,-78,-81,-83,-85,-88,
-90,-92,-94,-96,-98,-100,-102,-104,-106,-108,-109,-111,-112,-114,-115,-117,
-118,-119,-120,-121,-122,-123,-124,-124,-125,-126,-126,-127,-127,-127,-127,-127,
-128,-127,-127,-127,-127,-127,-126,-126,-125,-124,-124,-123,-122,-121,-120,-119,
-118,-117,-115,-114,-112,-111,-109,-108,-106,-104,-102,-100,-98,-96,-94,-92,
-90,-88,-85,-83,-81,-78,-76,-73,-71,-68,-65,-63,-60,-57,-54,-51,
-48,-46,-43,-40,-37,-34,-31,-28,-24,-21,-18,-15,-12,-9,-6,-3,
};