home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / asms.arc / TO320.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-13  |  2.3 KB  |  98 lines

  1. /*     */
  2. #include <stdio.h>
  3. #include <process.h>
  4.     int *storage[8],k,count;
  5.     unsigned i;
  6. #define    CONTROL 0x34
  7. #define    CONT2 0xb4
  8.     unsigned prt0,cntrlpt,prt1,prt2;
  9. main(argc,argv)
  10. int argc;
  11. char *argv[];
  12. {
  13.  
  14.     unsigned div,outport;
  15.     int value,baseio,seg320;
  16.     char name[20],buffer[24],*malloc();
  17.     float trate,osc,rate;
  18.     FILE *fp;
  19.     for(k=0;k<6;k++) storage[k]=(int *)malloc(0x8000);
  20.     clark: do {
  21.         printf("Input desired sample rate in Hz ");
  22.         scanf( "%f",&rate);
  23.     } while ( (rate < 80.0 ) || (rate > 40000.1));
  24.     /* count gives you the oscillator "divisor" just as in SIO's */
  25.     osc=6.25e+6;
  26.     count = 6.25e+6/rate;
  27.     if ( count == 0 ) count =1;
  28.     if ( count == 1 ) count =2;
  29.     trate = osc /(float)count;
  30.     printf("\nRate = %lf ",trate);
  31.     /* set timers for desired sampling rate */
  32.     control_timer(count,osc,&trate);
  33.     baseio=0x300;
  34.     seg320=0xd000;
  35.     inp(baseio+7);   /* halt */
  36.         /* Load the fft and square routines */
  37.     spawnl(P_WAIT,"intel",argv[0],"send","d000","300","0",NULL);
  38.     printf("\nSource File Name ? ");
  39.                     scanf("%s",name);
  40.                     if( (fp =fopen(name,"rb")) == NULL )
  41.                         { 
  42.                             printf("file open error\n");
  43.                          exit();
  44.                          }
  45.     for (k=0;k<6;k++)
  46.         fread(storage[k],2,0x4000,fp);       /* read the file into array */
  47.     printf("\nOutput Port (0,1,2,4 for D/A) ? ");
  48.     scanf("%d",&outport);
  49.     inp(baseio+6);
  50.     for (k=0;k<6;k++) {
  51.         empbuf(baseio,k);               /* send to the 320 */    
  52.     }
  53.     inp(baseio+7);
  54.     fclose(fp);
  55. }                        
  56.  
  57. empbuf(baseio,which)
  58. int baseio,which;
  59. {
  60.     int jj,kk,porto;
  61.     jj=-1;
  62.     porto=baseio+4;
  63.     for (kk=0;kk<0x4000;kk++) {
  64.         while (inp(porto)==jj) {};
  65.         jj=inp(baseio+4);
  66.         outp(baseio,(*(storage[which]+kk)&0xff));
  67.         outp(baseio+1,((*(storage[which]+kk)>>8)&0xff));
  68.     }
  69. }
  70. control_timer(cnt,osc,trate)
  71. long cnt;
  72. float *trate,osc;
  73. {
  74.     int ctl,cth;
  75.     /* tell board timer info coming */
  76.     outp(cntrlpt ,CONTROL);
  77.     /* count is timing divisor */
  78.     ctl = cnt & 0xff;    /* lo byte */
  79.     cth = ( cnt >> 8 ) & 0xff;/* hi byte */
  80.     /* control timer 0 */
  81.     outp(prt0 , ctl);
  82.     outp(prt0 , cth);
  83.     /* control timer 2 */
  84.     outp(cntrlpt , CONT2);
  85.     outp(prt2 , ctl);
  86.     outp(prt2 , cth);
  87.     /* compute new sampling rate  for output on screen*/
  88.     *trate = osc/(float)cnt;
  89. }
  90.  
  91. ci()
  92. {
  93.     int kbhit(),getch(),j;
  94.     while (kbhit()==0) {};
  95.       j=getch();
  96. }
  97.  
  98.