Advertisement
glokyfull

maketable in dc.w

Jul 3rd, 2022
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.     static int nbval=0;
  5.  
  6.  
  7. void printvalue(int* buffer,int nbval)
  8. {
  9.     for (int i=0;i<nbval;i++)
  10.     {
  11.         printf("%d ",buffer[i]);
  12.     }
  13. }
  14. double convRad(int index,int max)
  15. {
  16.     return (index*2.0*3.14159265358979/max);
  17. }
  18.  
  19. void addtodc(int value)
  20. {
  21.    
  22.     if (nbval==0)
  23.     {
  24.         printf("\t\tdc.w %d",value);
  25.     }
  26.     else if (nbval==7)
  27.     {
  28.         printf(",%d\n",value);
  29.        
  30.     }
  31.     else
  32.     {
  33.         printf(",%d",value);
  34.     }
  35.     nbval++;
  36.     nbval&=7;
  37. }
  38. void flushdc()
  39. {
  40.     if (nbval!=0)
  41.     {
  42.         printf("\n");
  43.     }
  44.     nbval=0;
  45. }
  46. void paragraphe(const char* label)
  47. {
  48.     printf("\n%s:",label);
  49.     printf("\n");
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55.     paragraphe("cos900");
  56.     for (int i=0;i<900;i++)
  57.     {
  58.         addtodc((int)(32766.0*cos(convRad(i,900))));   
  59.     }
  60.     flushdc();
  61.    
  62.     paragraphe("sin900");
  63.     for (int i=0;i<900;i++)
  64.     {
  65.         addtodc((int)(32766.0*sin(convRad(i,900))));
  66.     }
  67.     flushdc();
  68.    
  69.     paragraphe("sinsin900");
  70.     for (int i=0;i<900;i++)
  71.     {
  72.         addtodc((int)(32766.0* sin( 3.14159265358979* sin(convRad(i,900)))   ));
  73.     }
  74.     flushdc();
  75.  
  76.     paragraphe("cossin900");
  77.     for (int i=0;i<900;i++)
  78.     {
  79.         addtodc((int)(32766.0* cos( 3.14159265358979* sin(convRad(i,900)))   ));
  80.     }
  81.     flushdc();
  82.     return 0;
  83. }
  84. /*
  85.  compilation:   gcc -o toto thiscode.c -lm
  86.  execution:     ./toto>newfile.s
  87.  
  88. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement