home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_9 / issue_06 / pocketbook / calc3a / ADDON.OPL next >
Text File  |  1995-12-17  |  5KB  |  199 lines

  1. rem ----------------------------------------
  2. rem ADDON V1.5
  3. rem ----------------------------------------
  4. rem Example code to create external math
  5. rem functions for application Calc3a.
  6. rem (c) Alfa Computing 1995
  7. rem email@ 100735.331@compuserve.com
  8. rem SWreg id : 7171 (Calc3a)
  9. rem ----------------------------------------
  10. rem To have access to these external math
  11. rem functions:
  12. rem - add your own functions to this file
  13. rem - register them by adding them to
  14. rem   procedure "register:"
  15. rem - compile this file
  16. rem - make sure this file is placed in
  17. rem   an \OPD directory
  18. rem - start Calc3a application
  19. rem - enter number(s)
  20. rem - press diamond key
  21. rem - enter hotkey
  22. rem
  23. rem ----------------------------------------
  24. rem Procedures available for interfacing
  25. rem with Calc3a application:
  26. rem
  27. rem PROC RegFunc:(key$,func$)
  28. rem Register your function to the Calc3a
  29. rem application. 
  30. rem key$  - single character hotkey (a..z, A..Z)
  31. rem func$ - function name to link to hotkey
  32. rem         do not contain ":" in function
  33. rem         name.
  34. rem The number of functions to register is 
  35. rem limited to 52.
  36. rem
  37. rem PROC GetStatX:(Elm%)
  38. rem Get X-element Elm% from statistic memory 
  39. rem Available in SD and LR mode
  40. rem
  41. rem PROC SetStatX:(Elm%,Value)
  42. rem Set X-element Elm% in statistic memory
  43. rem Available in SD and LR mode
  44. rem
  45. rem PROC GetStatY:(Elm%)
  46. rem Get Y-element Elm% from statistic memory
  47. rem Only available in LR mode
  48. rem
  49. rem PROC SetStatY:(Elm%,Value)
  50. rem Set Y-element Elm% in statistic memory
  51. rem Only available in LR mode
  52. rem
  53. rem PROC GetElm%:
  54. rem Number of elements in statistic memory
  55. rem
  56. rem PROC SetRes:(Result)
  57. rem Send result to calculator
  58. rem
  59. rem PROC GetRes:
  60. rem Get last result from calculator
  61. rem
  62. rem GetOp1:
  63. rem Get operand 1
  64. rem
  65. rem GetOp2:
  66. rem Get operand 2
  67. rem
  68. rem NOTE : only characters a..z and A..Z are 
  69. rem        allowed for in function names.
  70.  
  71. rem ----------------------------------------
  72. rem This procedure must always be in the
  73. rem addon file and will be called during the
  74. rem initialisation of Calc3a. It registers
  75. rem all math functions and hotkeys to the
  76. rem program
  77.  
  78. PROC Register:
  79.         RegFunc:("v","VecLen")
  80.         RegFunc:("p","PolyLen")
  81.         RegFunc:("k","KeyCode")
  82.         RegFunc:("g","gLog")
  83.         RegFunc:("d","dBlist")
  84. ENDP
  85.  
  86. rem ----------------------------------------
  87. rem Example : Length of polyline (defined
  88. rem           by XY co-ordinates) in statistic
  89. rem           memory. Calculator must be in LR
  90. rem           mode to perform this calculation.
  91.  
  92. PROC PolyLen:
  93.         LOCAL length,i%,x1,y1,x2,y2
  94.  
  95.         rem Number of co-ordinate pairs must
  96.         rem be two or more.
  97.         IF GetElm%:<=1
  98.                 RETURN
  99.         ENDIF
  100.  
  101.         rem Calculate length of polyline
  102.         i%=1
  103.         WHILE i%<GetElm%:
  104.                 rem Get vector
  105.                 x1=GetStatX:(i%)
  106.                 y1=GetStatY:(i%)                
  107.                 x2=GetStatX:(i%+1)
  108.                 y2=GetStatY:(i%+1)                
  109.                 length=length+SQR((x2-x1)**2+(y2-y1)**2)
  110.                 i%=i%+1
  111.         ENDWH
  112.  
  113.         rem Send result to calculator
  114.         SetRes:(length)
  115. ENDP
  116.  
  117. rem ----------------------------------------
  118. rem Example : Calculate length of vector
  119. rem           from point 0,0 to point x,y
  120. rem           x and y must be entered by the user:
  121. rem           e.g. 10<,>5<diamond><v>
  122.  
  123. PROC VecLen:
  124.         LOCAL x,y,length
  125.         
  126.         rem store operand 1 in x
  127.         x=GetOp1:
  128.         rem store operand 2 in y
  129.         y=GetOp2:
  130.         length=SQR(x**2+y**2)
  131.  
  132.         rem Send result to calculator
  133.         SetRes:(length)
  134. ENDP
  135.  
  136. rem ----------------------------------------
  137. rem Example : Determine key code
  138.  
  139. PROC KeyCode:
  140.         LOCAL k%,km%
  141.         
  142.         BUSY "Press any key"
  143.         k%=GET
  144.         km%=KMOD
  145.         BUSY OFF
  146.         GIPRINT "KEY="+GEN$(k%,3)+"  KMOD="+GEN$(km%,3)
  147. ENDP
  148.  
  149. rem ----------------------------------------
  150. rem Example : g-BASE logarithm of x
  151.  
  152. PROC gLog:
  153.     LOCAL r,a,g
  154.  
  155.     g=GetOp1:
  156.     a=GetOp2:
  157.     IF (g<=0) OR (a<=0)
  158.         RETURN
  159.     ENDIF
  160.  
  161.     r=log(a)/log(g)
  162.     rem Send result to calculator
  163.     SetRes:(r)
  164. ENDP
  165.  
  166. rem ----------------------------------------
  167. rem Example : Add dB numbers in stat memory
  168.  
  169. PROC dBlist:
  170.         LOCAL total,i%
  171.  
  172.         rem Number of dB numbers must
  173.         rem be two or more.
  174.         IF GetElm%:<=1
  175.                 SetRes:(GetStatX:(1))
  176.                 RETURN
  177.         ENDIF
  178.  
  179.         rem Calculate total
  180.         i%=1
  181.         WHILE i%<=GetElm%:
  182.                 rem get number
  183.                 total=total+(10**(GetStatX:(i%)/10))
  184.                 i%=i%+1
  185.         ENDWH
  186.  
  187.         rem Calculate total of energetic 
  188.         rem values
  189.         IF total>0
  190.                 total=10*LOG(total)
  191.         ELSE
  192.                 total=0
  193.         ENDIF
  194.  
  195.         rem Send result to calculator
  196.         SetRes:(total)
  197. ENDP
  198.  
  199.