A2osX/SYS/KERNEL.S.MATH.txt

148 lines
2.8 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
*/--------------------------------------
2017-10-27 14:56:46 +00:00
* # FAdd,FSub,FMult,FDiv,FPwr
* Return X+Y, X-Y, X*Y, X/Y, X^Y
2018-06-18 15:48:00 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-06-18 15:48:00 +00:00
* `>PUSHF X (float)`
* `>PUSHF Y (float)`
* `>SYSCALL fadd`
* `>SYSCALL fsub`
* `>SYSCALL fmult`
* `>SYSCALL fdiv`
* `>SYSCALL fpwr`
2018-06-14 15:31:36 +00:00
* **Out:**
2018-06-18 15:48:00 +00:00
* 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
2017-10-27 14:56:46 +00:00
.HS 2C BIT ABS
K.FPwr ldx #ROM.PWR
2018-06-14 15:31:36 +00:00
phx
jsr MATH.PullFAC
jsr MATH.PullARG
2018-06-14 15:31:36 +00:00
plx
2017-10-27 14:56:46 +00:00
bra MATH.Go
*/--------------------------------------
2017-10-27 14:56:46 +00:00
* # Log,Sqr,Exp,Cos,Sin,Tan,ATan
* Return Log(x), Sqr(x), E^X, Cos(x), Sin(X), Tan(x), ATan(x)
2018-06-18 15:48:00 +00:00
* ## 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
2018-06-14 15:31:36 +00:00
* **In:**
2018-06-18 15:48:00 +00:00
* `>PUSHF x (Float)`
* `>SYSCALL log`
2018-06-14 15:31:36 +00:00
* **Out:**
2018-06-13 15:18:08 +00:00
* On stack (Float)
*\--------------------------------------
2017-10-27 14:56:46 +00:00
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
2018-06-14 15:31:36 +00:00
2017-10-27 14:56:46 +00:00
phx
jsr MATH.PullFAC
2018-06-14 15:31:36 +00:00
plx
bra MATH.Go
*/--------------------------------------
2018-06-18 15:48:00 +00:00
* # float
2018-06-13 15:18:08 +00:00
* Return 'floated' long
2018-06-18 15:48:00 +00:00
* ## C
* `float f = (float)12345678;
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-06-18 15:48:00 +00:00
* `>PUSHL X` (long)
2018-06-14 15:31:36 +00:00
* **Out:**
2018-06-18 15:48:00 +00:00
* On stack (float)
*\--------------------------------------
2018-06-13 15:18:08 +00:00
K.Float >PULLW FAC+1
>PULLW FAC+3
stz FAC.SIGN
lda #$A0
sta FAC Exp=32
ldx #ROM.LTOF
2018-06-14 15:31:36 +00:00
MATH.Go jsr GP.ROMCALL
lda pStack
sec
sbc #5
sta pStack
sta FORPNT
lda pStack+1
sta FORPNT+1
2018-06-13 15:18:08 +00:00
ldx #ROM.GETFAC
jsr GP.ROMCALL
2017-10-27 14:56:46 +00:00
clc
rts
*/--------------------------------------
2018-06-18 15:48:00 +00:00
* # lrintf
* Return float rounded into a long
* ## C
* `long int lrintf (float x);`
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-06-18 15:48:00 +00:00
* `>PUSHF x`
* `>SYSCALL lrintf`
2018-06-14 15:31:36 +00:00
* **Out:**
2018-06-13 15:18:08 +00:00
* On stack (long)
*\--------------------------------------
2018-06-18 15:48:00 +00:00
K.lrintf jsr MATH.PullFAC
2018-06-13 15:18:08 +00:00
ldx #ROM.QINT
2018-06-13 15:18:08 +00:00
jsr GP.ROMCALL
2017-10-27 14:56:46 +00:00
2018-06-13 15:18:08 +00:00
>PUSHW FAC+1
>PUSHW FAC+3
2018-06-22 14:59:24 +00:00
clc
rts
2017-10-27 14:56:46 +00:00
*--------------------------------------
2018-06-13 15:18:08 +00:00
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
2017-10-27 14:56:46 +00:00
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.MATH
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM