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

  1. '  Tutorial program MATMULT5.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.     MulAbility=Dsp_RequestUniqueAbility
  10. DEFSNG a-c
  11.  
  12. SUB InitMult
  13. SHARED MultHandle,MulAbility
  14. MultHandle=Dsp_InqSubrAbility(MulAbility)
  15.     IF MultHandle=0 THEN
  16.         OPEN "MATMULT5.B56" FOR INPUT AS #1
  17.         a$=INPUT$(LOF(1),#1)
  18.         MultHandle=Dsp_LoadSubroutine(SADD(a$),LOF(1)\3,MulAbility)
  19.         IF Multhandle=0 THEN 
  20.             PRINT "Can't load subroutine"
  21.         END IF
  22.     END IF
  23. END SUB
  24.  
  25. SUB Mult(a(2),b(2),c(2))
  26. SHARED MultHandle
  27. InitMult
  28. DIM a1&(N-1,N-1),b1&(N-1,N-1),c1&(N-1,N*2-1)
  29. ' First we need to convert the values to fixed point
  30. FOR i=0 TO N-1
  31.     FOR j=0 TO N-1
  32.         a1&(i,j)=&h800000*a(i,j)
  33.         b1&(i,j)=&h800000*b(i,j)
  34.     NEXT j
  35. NEXT i
  36.  
  37.     IF Dsp_RunSubroutine(Multhandle) THEN
  38.         PRINT "Can't run subroutine"
  39.         STOP
  40.     END IF
  41. Dsp_BlkUnpacked VARPTR(a1&(0,0)),N*N,0,0
  42. Dsp_BlkUnpacked VARPTR(b1&(0,0)),N*N,0,0
  43. ' the c1& array should now contain pairs of integer and fractional parts
  44.  
  45. FOR i=0 TO N-1
  46.     FOR j=0 TO N-1
  47.         Dsp_BlkUnpacked 0,0,VARPTR(c1&(i,j*2)),2
  48.         c(i,j)=c1&(i,j*2)*2+c1&(i,j*2+1)/&h800000
  49.     NEXT j
  50. NEXT i
  51.  
  52. END SUB
  53.  
  54. DIM a(N-1,N-1),b(N-1,N-1),c(N-1,N-1)
  55.  
  56. FOR i=0 TO N-1
  57.     FOR j=0 TO N-1
  58.         a(i,j)=RND
  59.         b(i,j)=RND
  60.     NEXT j
  61. NEXT i
  62.  
  63. showmat a()
  64. showmat b()
  65.  
  66. Mult a(),b(),c()
  67.  
  68. showmat c()
  69. STOP -1
  70.  
  71. SUB showmat(c(2))
  72. FOR j= 0 TO N-1
  73.     FOR i=0 TO N-1
  74.         PRINT c(i,j),
  75.     NEXT i
  76.     PRINT
  77. NEXT j
  78. PRINT
  79.  
  80. END SUB
  81.