*------------------------------------------------------------------
* mathtrans.a: PDC library interface to motorola floating point
* transient library base library supplied by Commodore.
* Maintenance Notes:
* 06Jun89 - Created by Jal
* 28May90 - Modifications by TETISOFT
* 16Jan91 - TetiSoft commented out saving of A6 with ';'
*           since HCC does not use it as local stack pointer.
*           Changed Alert Code, since we have Intuition open,
*           we can use text instead of numbers.
*
*------------------------------------------------------------------

;AG_OpenLib	equ	$00030000
;AO_MathLib	equ	$00008005
bias		SET	-30

libref	MACRO
_LVO\1	EQU	bias
bias	SET	bias-6
	ENDM

*------------------------------------------------------------------
* Note: these *Must* be in the same order as the
* mathtrans_lib.fd file.
*------------------------------------------------------------------

	libref	SPAtan
	libref	SPSin
	libref	SPCos
	libref	SPTan
	libref	SPSincos
	libref	SPSinh
	libref	SPCosh
	libref	SPTanh
	libref	SPExp
	libref	SPLog
	libref	SPPow
	libref	SPSqrt
	libref	SPTieee
	libref	SPFieee
	libref	SPAsin
	libref	SPAcos
	libref	SPLog10

;	XREF	_Alert
	XREF	_DisplayAlert

	XREF	_exit
	XREF	_OpenLibrary
	XREF	_CloseLibrary
	XREF	__MathTransClose

	XDEF	_MathTransBase

*------------------------------------------------------------------

	DATA

MATHName		DC.B	'mathtrans.library',0

	EVEN
AlertString:
	DC.W	120	; x-Offset
	DC.B	20	; y-Offset
	DC.B	'Could not open mathtrans.library.',0
	DC.B	1	; another Text follows...
	DC.B	0,120	; x
	DC.B	40	; y
	DC.B	'Press a mouse button to exit.',0,0

	BSS

MathTransBase		DS.L	1
_MathTransBase		DS.L	1

	CODE

*------------------------------------------------------------------
*	Close the MathTrans library if we opened it.
*------------------------------------------------------------------
MathTransClose:
	move.l	MathTransBase,-(sp)
	jsr	_CloseLibrary
	addq	#4,sp
	rts

*------------------------------------------------------------------
*	Open the MathTrans library
*------------------------------------------------------------------

.fpopen:
	movem.l	D0-D1/A0-A1,-(sp)	; save temporary registers
	pea	0			; any version will do....
	pea	MATHName		; Load the name of library
	jsr	_OpenLibrary		; Open the library
	addq	#8,sp
	move.l	D0,_MathTransBase	; Save the return code
	bne.s	1$			; If non-zero then OK

;	pea	0			; Parameter for Alert.
;	pea	AG_OpenLib!AO_MathLib	; Signal an error
;	jsr	_Alert
;	addq	#8,sp

	pea	60		; Height
	pea	AlertString
	pea	0		; RECOVERY_ALERT
	jsr	_DisplayAlert
	lea	12(sp),sp

	pea	100			;	push return code
	jsr	_exit			;	and exit
1$:
	move.l	D0,MathTransBase
	move.l	#MathTransClose,__MathTransClose
	movem.l	(sp)+,D0-D1/A0-A1		; restore temporaries
	rts

*------------------------------------------------------------------
*	Do the MathTrans function
*------------------------------------------------------------------

.fpdo:
	tst.l	_MathTransBase
	bne.s	1$
	jsr	.fpopen
1$:
	movem.l	8(sp),D0
;	movem.l	A6,-(sp)
	move.l	_MathTransBase,A6	

; TetiSoft We changed the stack frame...
;	add.l	4(sp),A6
	add.l	(sp),A6

	jsr	(A6)
;	movem.l	(sp)+,A6
	addq	#4,sp		; Chuck function offset.
	rts

*------------------------------------------------------------------
* atan:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_atan
_atan:
	pea	_LVOSPAtan
	jmp	.fpdo

*------------------------------------------------------------------
* sin:	Input double (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_sin
_sin:
	pea	_LVOSPSin
	jmp	.fpdo

*------------------------------------------------------------------
* cos:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_cos
_cos:
	pea	_LVOSPCos
	jmp	.fpdo

*------------------------------------------------------------------
* tan:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_tan
_tan:
	pea	_LVOSPTan
	jmp	.fpdo

*------------------------------------------------------------------
* sinh:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_sinh
_sinh:
	pea	_LVOSPSinh
	jmp	.fpdo

*------------------------------------------------------------------
* cosh:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_cosh
_cosh:
	pea	_LVOSPCosh
	jmp	.fpdo

*------------------------------------------------------------------
* tanh:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_tanh
_tanh:
	pea	_LVOSPTanh
	jmp	.fpdo

*------------------------------------------------------------------
* exp:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_exp
_exp:
	pea	_LVOSPExp
	jmp	.fpdo

*------------------------------------------------------------------
* log:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_log
_log:
	pea	_LVOSPLog
	jmp	.fpdo

*------------------------------------------------------------------
* pow:	pow(exp, power) : Output D0
*------------------------------------------------------------------
	XDEF	_pow
_pow:
	movem.l	12(sp),D1
	pea	_LVOSPPow
	jmp	.fpdo

*------------------------------------------------------------------
* sqrt:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_sqrt
_sqrt:
	pea	_LVOSPSqrt
	jmp	.fpdo

*------------------------------------------------------------------
* asin:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_asin
_asin:
	pea	_LVOSPAsin
	jmp	.fpdo

*------------------------------------------------------------------
* acos:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_acos
_acos:
	pea	_LVOSPAcos
	jmp	.fpdo

*------------------------------------------------------------------
* log10:	Input (on stack): Output D0
*------------------------------------------------------------------
	XDEF	_log10
_log10:
	pea	_LVOSPLog10
	jmp	.fpdo

	END
