home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_10 / DEVPAC56.ZIP / MATMULT3.C < prev    next >
C/C++ Source or Header  |  1993-12-20  |  2KB  |  84 lines

  1. /* Devpac DSP example code MATMULT1.C */
  2. /* for Lattice C                      */
  3. /* (c) Copyright HiSoft 1993          */
  4. /* All rights reserved                */
  5.  
  6. /* Note that this uses different data to the other C examples as
  7.    the same input data that is used by the BASIC equivalent
  8.    is embedded in the DSP program.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <osbind.h>
  13.  
  14. #define N 4
  15. #define DSP_CODE_FILE "MATMULT3.P56"
  16. typedef char DSP_WORD[3];
  17. typedef float MATRIX[N][N];
  18.  
  19.  
  20. void showmat(MATRIX c)
  21. {
  22. int i,j;
  23.     for    (j=0;j<N;j++)
  24.     {
  25.         for    (i=0;i<N;i++)
  26.             printf("%f\t",c[i][j]);
  27.         printf("\n");
  28.     }
  29.     printf("\n");
  30. }
  31.  
  32. int main(void)
  33. {
  34. DSP_WORD *dsp_prog;
  35. FILE * fp;
  36. long prog_size;
  37. int abil;
  38. MATRIX c;
  39. long c1[N][N*2];
  40. int i,j;
  41.  
  42.     if (Dsp_Lock())
  43.         {
  44.             printf("DSP already in use\n");
  45.             return 10;
  46.         }
  47.     
  48.     if (Dsp_Reserve(0x40+N*N,0x1000+N*N*3))
  49.         {
  50.             printf("Can't reserve enough DSP RAM\n");
  51.             Dsp_Unlock();
  52.             return 10;
  53.         }
  54.  
  55. /* Now open the DSP file */
  56.     fp=fopen(DSP_CODE_FILE,"rb");
  57.     if (fp==NULL)
  58.         {
  59.             printf("Can't open file " DSP_CODE_FILE "\n");
  60.             Dsp_Unlock();
  61.             return 10;
  62.         }
  63.     
  64. /* Now read the DSP file into dsp_prog with the size in dsp words in prog_size */    
  65.     fseek(fp,0,SEEK_END);
  66.     prog_size=ftell(fp)/sizeof(DSP_WORD);
  67.     fseek(fp,0,SEEK_SET);
  68.     dsp_prog=malloc(prog_size*sizeof(DSP_WORD));
  69.     fread(dsp_prog,sizeof(DSP_WORD),prog_size,fp);
  70.     fclose(fp);
  71.  
  72.     abil=Dsp_RequestUniqueAbility();
  73.     Dsp_ExecProg(dsp_prog,prog_size,abil);
  74.     Dsp_BlkUnpacked(0,0,&(c1[0][0]),N*N*2);
  75.  
  76.     for    (i=0;i<N;i++)
  77.         for    (j=0;j<N;j++)
  78.             c[i][j]=c1[i][j*2]+(float)(c1[i][j*2+1])/0x800000;
  79.     
  80.     showmat(c);
  81.     Dsp_Unlock();
  82.     return    0;
  83. }
  84.