home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / hce.lha / HCE / LibSource / clib / Math / src / mathbas.a < prev    next >
Encoding:
Text File  |  1992-09-02  |  4.5 KB  |  253 lines

  1. *------------------------------------------------------------------
  2. * math.asm: ZC library interface to Motorola fast floating point
  3. * library supplied by Commodore.
  4. * Maintenance Notes:
  5. * 06Jun89 - Created by Jal
  6. * 27May90 - Modifications by TETISOFT
  7. * 16Jan91 - TetiSoft commented out saving of A6 with ';'
  8. *           since HCC does not use it as local stack pointer.
  9. *           Changed Alert Code, since we have Intuition open,
  10. *           we can use text instead of numbers.
  11. *
  12. *
  13. *------------------------------------------------------------------
  14.  
  15. ;AG_OpenLib    equ    $00030000
  16. ;AO_MathLib    equ    $00008005
  17.  
  18. bias    SET    -30
  19.  
  20. libref    MACRO
  21. _LVO\1    EQU    bias
  22. bias    SET    bias-6
  23.     ENDM
  24.  
  25. *------------------------------------------------------------------
  26. * Note: these *Must* be in the same order as the mathbas_lib.fd
  27. * file.
  28. *------------------------------------------------------------------
  29.  
  30.     libref    SPFix
  31.     libref    SPFlt
  32.     libref    SPCmp
  33.     libref    SPTst
  34.     libref    SPAbs
  35.     libref    SPNeg
  36.     libref    SPAdd
  37.     libref    SPSub
  38.     libref    SPMul
  39.     libref    SPDiv
  40.     libref    SPFloor    ; needs release 1.2+
  41.     libref    SPCeil    ; needs release 1.2+
  42.  
  43. ;    XREF    _Alert
  44.     XREF    _DisplayAlert
  45.  
  46.     XREF    _exit
  47.     XREF    _OpenLibrary
  48.     XREF    _CloseLibrary
  49.     XREF    __MathBaseClose
  50.  
  51.     XDEF    _MathBase
  52.  
  53. *------------------------------------------------------------------
  54.  
  55.     DATA
  56.  
  57. MATHName    DC.B    'mathffp.library',0
  58.  
  59.     EVEN
  60. AlertString:
  61.     DC.W    120    ; x-Offset
  62.     DC.B    20    ; y-Offset
  63.     DC.B    'Could not open mathffp.library.',0
  64.     DC.B    1    ; another Text follows...
  65.     DC.B    0,120    ; x
  66.     DC.B    40    ; y
  67.     DC.B    'Press a mouse button to exit.',0,0
  68.  
  69.     BSS
  70.  
  71. MathBase    DS.L    1
  72. _MathBase    DS.L    1
  73.  
  74.     CODE
  75.  
  76. *
  77. *    Called at exit if we opened the MathBase library.
  78. *
  79.  
  80. MathBaseClose:
  81.     move.l    MathBase,-(sp)
  82.     jsr    _CloseLibrary
  83.     addq    #4,sp
  84.     rts
  85.  
  86. *
  87. *    Make sure the MathBase is loaded correctly
  88. *
  89.  
  90. .flopen:
  91.     movem.l    D0-D1/A0-A1,-(sp)    ; save temporary registers
  92.     pea    0            ; any version will do....
  93.     pea    MATHName        ; Load the name of library
  94.     jsr    _OpenLibrary        ; Open the library
  95.     addq    #8,sp
  96.     move.l    D0,_MathBase        ; Save the return code
  97.     bne.s    1$            ; If non-zero then OK
  98.  
  99. ;    pea    0            ; Parameter for Alert.
  100. ;    pea    AG_OpenLib!AO_MathLib    ; Signal an error.
  101. ;    jsr    _Alert
  102. ;    addq    #8,sp
  103.  
  104.     pea    60        ; Height
  105.     pea    AlertString
  106.     pea    0        ; RECOVERY_ALERT
  107.     jsr    _DisplayAlert
  108.     lea    12(sp),sp
  109.  
  110.     pea    100            ; push return code
  111.     jsr    _exit            ; and exit
  112. 1$:
  113.     move.l    D0,MathBase        ; A private copy
  114.     move.l    #MathBaseClose,__MathBaseClose
  115.     movem.l    (sp)+,D0-D1/A0-A1    ; restore temporaries
  116.     rts
  117.  
  118. *-------------------------------------------------------------------
  119. * Do a one or two parameter MathBase function.
  120. *-------------------------------------------------------------------
  121. .fldo2:
  122.     move.l    12(sp),D1
  123. .fldo1:
  124.     move.l    8(sp),D0
  125.     tst.l    _MathBase
  126.     bne.s    1$
  127.     jsr    .flopen
  128. 1$:
  129. ;    movem.l    A6,-(sp)
  130.     move.l    _MathBase,A6    
  131.  
  132. ; TetiSoft We changed the stack frame...
  133. ;    add.l    4(sp),A6
  134.     add.l    (sp),A6
  135.  
  136.     jsr    (A6)
  137. ;    movem.l    (sp)+,A6
  138.     addq    #4,sp        ; unstack the function offset.
  139.     rts
  140.  
  141. *********************************************************************
  142. *
  143. *    multiply
  144. *
  145.     XDEF    fpmul
  146.     XDEF    _fpmul
  147. fpmul:
  148. _fpmul:
  149.     pea    _LVOSPMul
  150.     jmp    .fldo2
  151.  
  152. *********************************************************************
  153. *
  154. *    divide
  155. *
  156.     XDEF    fpdiv
  157.     XDEF    _fpdiv
  158. fpdiv:
  159. _fpdiv:
  160.     pea    _LVOSPDiv
  161.     jmp    .fldo2
  162.  
  163. *********************************************************************
  164. *
  165. *    add
  166. *
  167.     XDEF    fpadd
  168.     XDEF    _fpadd
  169. fpadd:
  170. _fpadd:
  171.     pea    _LVOSPAdd
  172.     jmp    .fldo2
  173.  
  174. *********************************************************************
  175. *
  176. *    subtract
  177. *
  178.     XDEF    fpsub
  179.     XDEF    _fpsub
  180. fpsub:
  181. _fpsub:
  182.     pea    _LVOSPSub
  183.     jmp    .fldo2
  184.  
  185. *********************************************************************
  186. *
  187. *    negate
  188. *
  189.     XDEF    fpneg
  190.     XDEF    _fpneg
  191. fpneg:
  192. _fpneg:
  193.     pea    _LVOSPNeg
  194.     jmp    .fldo1
  195.  
  196. *********************************************************************
  197. *
  198. *    compare
  199. *
  200.     XDEF    fpcmp
  201.     XDEF    _fpcmp
  202. fpcmp:
  203. _fpcmp:
  204.     pea    _LVOSPCmp
  205.     jmp    .fldo2
  206.  
  207. *********************************************************************
  208. *
  209. *    convert long to float
  210. *
  211.     XDEF    _fpltof
  212. _fpltof:
  213.     pea    _LVOSPFlt
  214.     jmp    .fldo1
  215.  
  216. *********************************************************************
  217. *
  218. *    Convert float to long
  219. *
  220.     XDEF    _fpftol
  221. _fpftol:
  222.     pea    _LVOSPFix
  223.     jmp    .fldo1
  224.  
  225. *********************************************************************
  226. *
  227. *    Implement the fabs function.:
  228. *
  229.     XDEF    _fabs
  230. _fabs:
  231.     pea    _LVOSPAbs
  232.     jmp    .fldo1
  233.  
  234. *********************************************************************
  235. *
  236. *    Implement the floor function.:
  237. *
  238.     XDEF    _floor
  239. _floor:
  240.     pea    _LVOSPFloor
  241.     jmp    .fldo1
  242.  
  243. *********************************************************************
  244. *
  245. *    Implement the ceil function.:
  246. *
  247.     XDEF    _ceil
  248. _ceil:
  249.     pea    _LVOSPCeil
  250.     jmp    .fldo1
  251.  
  252.     END
  253.