NEW
  AUTO 3,1
*/--------------------------------------
* # FAdd,FSub,FMult,FDiv,FPwr
* Return X+Y, X-Y, X*Y, X/Y, X^Y
* ## ASM
* **In:**
* `>PUSHF X (float)`
* `>PUSHF Y (float)`
* `>SYSCALL fadd`
* `>SYSCALL fsub`
* `>SYSCALL fmult`
* `>SYSCALL fdiv`
* `>SYSCALL fpwr`
* ## RETURN VALUE
*  On stack (float)
*\--------------------------------------
K.FAdd			ldx #ROM.FADD
				.HS 2C					BIT ABS
K.FSub			ldx #ROM.FSUB
				.HS 2C					BIT ABS
K.FMult			ldx #ROM.FMULT
				.HS 2C					BIT ABS
K.FDiv			ldx #ROM.FDIV
				.HS 2C					BIT ABS
K.FPwr			ldx #ROM.PWR

				phx
				jsr MATH.PullFAC
				jsr MATH.PullARG
				
				plx
				jmp GP.RomCallPushFAC
*/--------------------------------------
* # Log,Sqr,Exp,Cos,Sin,Tan,ATan
* Return Log(x), Sqr(x), E^X, Cos(x), Sin(X), Tan(x), ATan(x)
* ## C
* `float log ( float x);`
* `float sqr ( float x);`
* `float exp ( float x);`
* `float cos ( float x);`
* `float sin ( float x);`
* `float tan ( float x);`
* `float atan ( float x);`
* ## ASM
* **In:**
* `>PUSHF x (Float)`
* `>SYSCALL log`
* ## RETURN VALUE
*  On stack (Float)
*\--------------------------------------
K.Log			ldx #ROM.LOG
				.HS 2C					BIT ABS
K.Sqr			ldx #ROM.SQR
				.HS 2C					BIT ABS
K.Exp			ldx #ROM.EXP
				.HS 2C					BIT ABS
K.Cos			ldx #ROM.COS
				.HS 2C					BIT ABS
K.Sin			ldx #ROM.SIN
				.HS 2C					BIT ABS
K.Tan			ldx #ROM.TAN
				.HS 2C					BIT ABS
K.ATan			ldx #ROM.ATAN

				phx
				jsr MATH.PullFAC
				
				plx
				jmp GP.RomCallPushFAC
*/--------------------------------------
* # float
* Return 'floated' long
* ## C
* `float f = (float)12345678;
* ## ASM
* **In:**
*  `>PUSHL X` (long)
* ## RETURN VALUE
*  On stack (float)
*\--------------------------------------
K.Float			ldx #4

.1				>PULLB FAC,x			Reverse Order
				dex
				bne .1
				
				stz	FAC.SIGN
				lda #$A0
				sta FAC					Exp=32
				
				ldx #ROM.LTOF

				jmp GP.RomCallPushFAC
*/--------------------------------------
* # lrintf
* Return float rounded into a long
* ## C
* `long int lrintf (float x);`
* ## ASM
* **In:**
* `>PUSHF x`
* `>SYSCALL lrintf`
* ## RETURN VALUE
*  On stack (long)
*\--------------------------------------
K.lrintf		jsr MATH.PullFAC
				
				ldx #ROM.QINT
				jsr GP.ROMCALL	

				ldx #0
				
.1				>PUSHB FAC+1,x
				inx
				cpx #4
				bne .1

				clc
				rts				
*--------------------------------------
MATH.PullARG	ldx #ROM.SETARG
				.HS 2C					BIT ABS
MATH.PullFAC	ldx #ROM.SETFAC
				
				>LDYA pStack
				>STYA INDEX
				jsr GP.ROMCALL
				
				lda pStack
				clc
				adc #5
				sta pStack
				rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.MATH
LOAD USR/SRC/SYS/KERNEL.S
ASM
