home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_10 / DEVPAC56.ZIP / MATMULT4.BAS < prev    next >
BASIC Source File  |  1993-12-20  |  1KB  |  83 lines

  1. '  Tutorial program MATMULT4.BAS supplied with DevpacDSP
  2. '  (c) Copyright HiSoft 1993
  3. '  All rights reserved
  4.  
  5. DEFINT a-z
  6. REM    $NOFNSINLIBS
  7. LIBRARY "falcon"
  8. CONST n=4
  9. DEFSNG a-c
  10.  
  11.  
  12. SUB Mult(a(2),b(2),c(2))
  13.  
  14. DIM a1&(N-1,N-1),b1&(N-1,N-1),c1&(N-1,N*2-1)
  15. ' First we need to convert the values to fixed point
  16. FOR i=0 TO N-1
  17.     FOR j=0 TO N-1
  18.         a1&(i,j)=&h800000*a(i,j)
  19.         b1&(i,j)=&h800000*b(i,j)
  20.     NEXT j
  21. NEXT i
  22.  
  23. IF Dsp_lock THEN
  24.         PRINT "DSP is already in use"
  25.         STOP
  26. END IF
  27. IF Dsp_reserve(&h40+N*N,&h1000+N*N*2) THEN
  28.     PRINT "Can't reserve enough DSP RAM"
  29.     STOP
  30. END IF
  31.  
  32. abil=Dsp_RequestUniqueAbility
  33.  
  34. ' load the progran
  35. OPEN "matmult4.p56" FOR INPUT AS #1
  36. progsize&=LOF(1)\3
  37. buffer$=INPUT$(progsize&*3,#1)
  38. CLOSE #1
  39. 'now run the program
  40.     Dsp_Execprog SADD(buffer$),progsize&,abil
  41.  
  42. ' send the data
  43. Dsp_BlkUnpacked VARPTR(a1&(0,0)),N*N,0,0
  44. Dsp_BlkUnpacked VARPTR(b1&(0,0)),N*N,0,0
  45. Dsp_BlkUnpacked 0,0,VARPTR(c1&(0,0)),N*N*2
  46. ' the c1& array should now contain pairs of integer and fractional parts
  47. Dsp_Unlock
  48. ' now convert them to floating point
  49. FOR i=0 TO N-1
  50.     FOR j=0 TO N-1
  51.     c(i,j)=c1&(i,j*2)*2+c1&(i,j*2+1)/&h800000
  52.     NEXT j
  53. NEXT i
  54.  
  55. END SUB
  56.  
  57. DIM a(N-1,N-1),b(N-1,N-1),c(N-1,N-1)
  58.  
  59. FOR i=0 TO N-1
  60.     FOR j=0 TO N-1
  61.         a(i,j)=RND
  62.         b(i,j)=RND
  63.     NEXT j
  64. NEXT i
  65.  
  66. showmat a()
  67. showmat b()
  68.  
  69. Mult a(),b(),c()
  70.  
  71. showmat c()
  72.  
  73. SUB showmat(c(2))
  74. FOR j= 0 TO N-1
  75.     FOR i=0 TO N-1
  76.         PRINT c(i,j),
  77.     NEXT i
  78.     PRINT
  79. NEXT j
  80. PRINT
  81.  
  82. END SUB
  83.