 NAM SCIENT (STRUBAL +)
*
 CMN RUNSTK,80
 CMN ACCUM1,2
 CMN ACCUM2,2
 CMN ACCUM3,2
 CMN ACCUM4,2
 CMN ACCUM5,9
 CMN ADRTO,2
 CMN ADRFM,2
*
 ENT SIN
 ENT COS
 ENT TAN
 ENT ASIN
 ENT ACOS
 ENT ATAN
 ENT LOG10
 ENT NATLOG
 ENT TENEXP
 ENT FEXP
 ENT XTOY
*
 EXT FTAREG
 EXT FTCREG
 EXT FFDREG
 EXT FADD
 EXT FSUB
 EXT FMUL
 EXT FDIV
 EXT FIX
 EXT FLOAT
 EXT FABS
 EXT FNEG
 EXT FSIGN
 EXT ASCII
 EXT ILLERR
 EXT FCOMPR
 EXT MOVER
*
* DATA TABLES
*
COSCON FDB $8000
 FDB $4999
 FDB $9999
 FDB $6300
 FCB $00
 FDB $4001
 FDB $4166
 FDB $6641
 FDB $8000
 FCB $00
 FDB $C002
 FDB $1388
 FDB $8397
 FDB $0000
 FCB $00
 FDB $4004
 FDB $2476
 FDB $0900
 FDB $0000
 FCB $00
 FDB $C006
 FDB $2605
 FDB $0000
 FDB $0000
 FCB $00
*
TWOPI FDB $0001
 FDB $6283
 FDB $1853
 FDB $0600
 FCB $00
PIOV2 FDB $0001
 FDB $1570
 FDB $7963
 FDB $2700
 FCB $00
*
ATNCON FDB $8000
 FDB $3333
 FDB $3145
 FDB $2800
 FCB $00
 FDB $0000
 FDB $1999
 FDB $3550
 FDB $8500
 FCB $00
 FDB $8000
 FDB $1420
 FDB $8899
 FDB $4400
 FCB $00
 FDB $0000
 FDB $1065
 FDB $6263
 FDB $9300
 FCB $00
 FDB $C001
 FDB $7528
 FDB $9640
 FDB $0000
 FCB $00
 FDB $4001
 FDB $4290
 FDB $9613
 FDB $8000
 FCB $00
 FDB $C001
 FDB $1616
 FDB $5736
 FDB $7000
 FCB $00
 FDB $4002
 FDB $2866
 FDB $2257
 FDB $0000
 FCB $00
*
ASNCON FDB $0000
 FDB $1666
 FDB $6666
 FDB $6666
 FCB $67
 FDB $4001
 FDB $7500
 FDB $0000
 FDB $0000
 FCB $00
 FDB $4001
 FDB $4464
 FDB $2857
 FDB $0000
 FCB $00
 FDB $4001
 FDB $3038
 FDB $1944
 FDB $0000
 FCB $00
 FDB $4001
 FDB $2237
 FDB $2159
 FDB $0000
 FCB $00
 FDB $4001
 FDB $1735
 FDB $2764
 FDB $0000
 FCB $00
 FDB $4001
 FDB $1396
 FDB $4844
 FDB $0000
 FCB $00
 FDB $4001
 FDB $1155
 FDB $1801
 FDB $0000
 FCB $00
 FDB $4002
 FDB $9761
 FDB $6100
 FDB $0000
 FCB $00
 FDB $4002
 FDB $8390
 FDB $3360
 FDB $0000
 FCB $00
*
ONE FDB $0001
 FDB $1000
 FDB $0000
 FDB $0000
 FCB $00
*
INFIN FDB $0255
 FDB $9999
 FDB $9999
 FDB $9999
 FCB $99
*
LNCON FDB $0001
 FDB $2302
 FDB $5850
 FDB $9300
 FCB $00
*
LOGE FDB $0000
 FDB $4342
 FDB $9448
 FDB $2000
 FCB $00
*
C255 FDB $0003
 FDB $2550
 FDB $0000
 FDB $0000
 FCB $00
*
TCON1 FDB $0000
 FDB $5000
 FDB $0000
 FDB $0000
 FCB $00
 FDB $4001
 FDB $4166
 FDB $6666
 FDB $6666
 FCB $67
 FDB $4002
 FDB $1388
 FDB $8890
 FDB $0000
 FCB $00
 FDB $4004
 FDB $2480
 FDB $2000
 FDB $0000
 FCB $00
 FDB $4006
 FDB $2760
 FDB $0000
 FDB $0000
 FCB $00
*
TCON2 FDB $0000
 FDB $1666
 FDB $6666
 FDB $6666
 FCB $67
 FDB $4002
 FDB $8333
 FDB $3333
 FDB $3333
 FCB $33
 FDB $4003
 FDB $1984
 FDB $1300
 FDB $0000
 FCB $00
 FDB $4005
 FDB $2756
 FDB $0000
 FDB $0000
 FCB $00
 FDB $4007
 FDB $2500
 FDB $0000
 FDB $0000
 FCB $00
*
LOGCON FDB $0000
 FDB $8685
 FDB $8896
 FDB $3800
 FCB $00
 FDB $0000
 FDB $2895
 FDB $2965
 FDB $4600
 FCB $00
 FDB $0000
 FDB $1737
 FDB $1779
 FDB $2800
 FCB $00
 FDB $0000
 FDB $1240
 FDB $8413
 FDB $7700
 FCB $00
 FDB $4001
 FDB $9650
 FDB $9884
 FDB $8800
 FCB $00
 FDB $4001
 FDB $7896
 FDB $2633
 FDB $0700
 FCB $00
 FDB $4001
 FDB $6681
 FDB $4535
 FDB $6800
 FCB $00
 FDB $4001
 FDB $5790
 FDB $5930
 FDB $9200
 FCB $00
 FDB $4001
 FDB $5109
 FDB $3468
 FDB $4600
 FCB $00
 FDB $4001
 FDB $4571
 FDB $5208
 FDB $6200
 FCB $00
 FDB $4001
 FDB $4136
 FDB $1379
 FDB $2300
 FCB $00
 FDB $4001
 FDB $3776
 FDB $4737
 FDB $5600
 FCB $00
*
THREE FDB $0001
 FDB $3000
 FDB $0000
 FDB $0000
 FCB $00
*
LOGOF3 FDB $0000
 FDB $4771
 FDB $2125
 FDB $4900
 FCB $00
*
* FACTOR EXTRACTION SUBROUTINE
*
EXTRCT LDX ARGPNT
 JSR FTCREG
 LDX CONPNT
 JSR FTAREG
 JSR FDIV
 LDX #FTEMP
 JSR FFDREG
 LDX #FTEMP
 JSR FIX
 STX IFACT
 STX ACCUM1
 LDX #FTEMP
 JSR FLOAT
 LDX #FTEMP
 JSR FTAREG
 LDX CONPNT
 JSR FTCREG
 JSR FMUL
 LDX #FTEMP
 JSR FFDREG
 LDX #FTEMP
 JSR FTCREG
 LDX ARGPNT
 JSR FTAREG
 JSR FSUB
 RTS
ARGPNT RMB 2
CONPNT RMB 2
FTEMP RMB 9
IFACT RMB 2
*
* SERIES EXPANSION ROUNTINE
*
SERIES STX ARGSAV
 JSR FTCREG
 LDX ARGSAV
 JSR FTAREG
 JSR FMUL
 LDX #FTEMP
 JSR FFDREG
 LDX #POWER
 CLR 0,X
 JSR FSIGN
SER2 LDX #POWER
 JSR FTAREG
 LDX #FTEMP
 JSR FTCREG
 JSR FMUL
 LDX #POWER
 JSR FFDREG
 LDX ANGLE
 LDAA ANGLE
 LDAB ANGLE+1
 ADDB #9
 ADCA #0
 STAA ANGLE
 STAB ANGLE+1
 JSR FTAREG
 LDX #POWER
 JSR FTCREG
 JSR FMUL
 LDX #STEMP
 JSR FFDREG
 LDX #SUM
 JSR FTAREG
 LDX #STEMP
 JSR FTCREG
 JSR FADD
 LDX #SUM
 JSR FFDREG
 DEC TERMS
 BNE SER2
 RTS
POWER RMB 9
STEMP RMB 9
SUM RMB 9
ARGSAV RMB 2
TERMS RMB 1
ANGLE RMB 2
RETURN RMB 2
SINVAL RMB 9
COSVAL RMB 9
CRET RMB 2
CCRET RMB 2
COSTMP RMB 9
SIGN RMB  1
ASIGN RMB 1
FLAG RMB 1
*
* TANGENT FUNCTION
*
TAN STX RETURN
 STX ADRFM
 LDX #SINVAL
 STX ADRTO
 LDAB #9
 JSR MOVER
 LDX RETURN
 STX ADRFM
 LDX #COSVAL
 STX ADRTO
 LDAB #9
 JSR MOVER
 LDX #COSVAL
 JSR COS
 LDX #SINVAL
 JSR SIN
 LDX #SINVAL
 JSR FTCREG
 LDX #COSVAL
 JSR FTAREG
 JSR FDIV
 LDX RETURN
 JMP FFDREG
*
* COSINE FUNCTION
*
COS STX CRET
 JSR FABS
 STX ARGPNT
 LDX #TWOPI
 STX CONPNT
 JSR EXTRCT
 LDX #COSTMP
 JSR FFDREG
 LDAA COSTMP
 BITA #$20
 BEQ COS2
 LDX #ONE
 BRA COS5
COS2 LDX #COSTMP
 STX ARGPNT
 LDX #PIOV2
 STX CONPNT
 JSR EXTRCT
 LDX #COSTMP
 JSR FFDREG
 LDAA IFACT+1
 BITA #1
 BEQ COS3
 LDX #COSTMP
 JSR FTCREG
 LDX #PIOV2
 JSR FTAREG
 JSR FSUB
 LDX #COSTMP
 JSR FFDREG
COS3 LDAA #5
 STAA TERMS
 LDX #COSCON
 STX ANGLE
 LDX #SUM
 CLR 0,X
 JSR FSIGN
 LDX #COSTMP
 JSR SERIES
 LDX #COSTMP
 JSR FFDREG
 LDAA IFACT+1
 BEQ COS4
 CMPA #3
 BEQ COS4
 LDX #COSTMP
 JSR FNEG
COS4 LDX #COSTMP
COS5 STX ADRFM
 LDX CRET
 STX ADRTO
 LDAB #9
 JMP MOVER
*
* SINE FUNCTION
*
SIN STX CRET
 JSR FTCREG
 LDX #PIOV2
 JSR FTAREG
 JSR FSUB
 LDX CRET
 JSR FFDREG
 LDX CRET
 JMP COS
*
* INVERSE-TANGENT FUNCTION
*
ATAN STX CRET
 LDAA 0,X
 CLR FLAG
 BITA #$20
 BEQ ATAN2
 RTS
ATAN2 STAA SIGN
 JSR FABS
 STX ACCUM1
 LDX #ONE
 JSR FCOMPR
 BGE ATAN3
 COM FLAG
 LDX #ONE
 JSR FTCREG
 LDX CRET
 JSR FTAREG
 JSR FDIV
 LDX CRET
 JSR FFDREG
ATAN3 LDAA #8
 STAA TERMS
 LDX #ATNCON
 STX ANGLE
 LDX #SUM
 CLR 0,X
 JSR FSIGN
 LDX CRET
 JSR SERIES
 LDX #SINVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTCREG
 LDX CRET
 JSR FTAREG
 JSR FMUL
 LDX #SINVAL
 JSR FFDREG
 TST FLAG
 BEQ ATAN4
 LDX #PIOV2
 JSR FTAREG
 LDX #SINVAL
 JSR FTCREG
 JSR FSUB
 LDX #SINVAL
 JSR FFDREG
ATAN4  LDX #SINVAL
 TST SIGN
 BPL ATAN5
 JSR FNEG
ATAN5 JMP COS5
*
* INVERSE-COSINE FUNCTION
*
ACOS STX CCRET
 LDAA 0,X
 STAA ASIGN
 JSR ASIN
 LDAA ASIGN
 BMI ACOS2
 LDX #PIOV2
 JSR FTAREG
 LDX CCRET
 JSR FTCREG
 JSR FSUB
 BRA ACOS3
ACOS2 LDX CCRET
 JSR FTAREG
 LDX #PIOV2
 JSR FTCREG
 JSR FADD
ACOS3 LDX CCRET
 JMP FFDREG
*
* INVERSE-SINE FUNCTION
*
ASIN STX CRET
 LDAA 0,X
 BITA #$20
 BEQ ASIN2
 RTS
ASIN2 STAA SIGN
 STX ACCUM1
 JSR FABS
 LDX #ONE
 JSR FCOMPR
 BPL ASIN3
 JSR ILLERR
ASIN3 LDAA #10
 STAA TERMS
 LDX #ASNCON
 STX ANGLE
 LDX #SUM
 CLR 0,X
 JSR FSIGN
 LDX CRET
 JSR SERIES
 LDX #SINVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTCREG
 LDX CRET
 JSR FTAREG
 JSR FMUL
 LDX #SINVAL
 JSR FFDREG
 JMP ATAN4
*
* NATURAL LOGARITHM FUNCTION
*
NATLOG BSR LOG10
 LDX CRET
 JSR FTAREG
 LDX #LNCON
  JSR FTCREG
 JSR FMUL
 JMP LOG15
*
* BASE-10 LOGARITHM FUNCTION
*
LOG10 STX CRET
 LDAA 0,X
 BPL LOG2
 JSR ILLERR
LOG2 BITA #$20
 BEQ LOG3
 LDX #INFIN
 JSR FNEG
 JMP COS5
LOG3 LDX #0
 STX COSTMP
 STX COSTMP+2
 STX COSTMP+4
 STX COSTMP+6
 STX COSTMP+8
 BITA #$40
 BEQ LOG4
 LDAB #$80
 STAB COSTMP
LOG4 LDAB #3
 ANDA #$F
 BNE LOG5
 DECB
 BRA LOG6
LOG5 ASLA
 ASLA
 ASLA
 ASLA
 STAA COSTMP+2
LOG6 LDX CRET
 LDAA 1,X
 ANDA #$F0
 CMPB #3
 BNE LOG7
 LSRA
 LSRA
 LSRA
 LSRA
 ORAA COSTMP+2
LOG61 STAA COSTMP+2
 BRA LOG8
LOG7 TSTA
 BNE LOG61
 DECB
LOG8 LDAA 1,X
 ANDA #$F
 CMPB #3
 BNE LOG9
 ASLA
 ASLA
 ASLA
 ASLA
 STAA COSTMP+3
 BRA LOG12
LOG9 CMPB #2
 BNE LOG101
 ORAA COSTMP+2
 STAA COSTMP+2
 BRA LOG12
LOG101 TSTA
 BNE LOG11
 LDAA #$20
 STAA COSTMP
 BRA LOG13
LOG11 ASLA
 ASLA
 ASLA
 ASLA
 STAA COSTMP+2
LOG12 STAB COSTMP+1
LOG13 LDX CRET
 CLR 0,X
 CLR 1,X
 JSR FTAREG
 LDX #THREE
 JSR FTCREG
 JSR FMUL
 LDX CRET
 JSR FFDREG
 LDX CRET
 JSR FTAREG
 LDX #ONE
 JSR FTCREG
 JSR FSUB
 LDX #SINVAL
 JSR FFDREG
LOG14 LDX CRET
 JSR FTAREG
 LDX #ONE
 JSR FTCREG
 JSR FADD
 LDX #COSVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTCREG
 LDX #COSVAL
 JSR FTAREG
 JSR FDIV
 LDX #SINVAL
 JSR FFDREG
 LDX #LOGCON
 STX ADRFM
 LDX #SUM
 STX ADRTO
 LDAB #9
 JSR MOVER
 LDX #LOGCON+9
 STX ANGLE
 LDAB #11
 STAB TERMS
 LDX #SINVAL
 JSR SERIES
 LDX #COSVAL
 JSR FFDREG
 LDX #COSVAL
 JSR FTCREG
 LDX #SINVAL
 JSR FTAREG
 JSR FMUL
 LDX #SINVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTAREG
 LDX #COSTMP
 JSR FTCREG
 JSR FADD
 LDX #COSTMP
 JSR FFDREG
 LDX #COSTMP
 JSR FTAREG
 LDX #LOGOF3
 JSR FTCREG
 JSR FSUB
LOG15 LDX CRET
 JMP FFDREG
*
* EXPONENTIAL FUNCTIONS
*
FEXP STX CRET
 JSR FTAREG
 LDX #LOGE
 JSR FTCREG
 JSR FMUL
 LDX CRET
 JSR FFDREG
 LDX CRET
TENEXP STX CRET
 LDAA 0,X
 BITA #$20
 BEQ TEN2
 LDX #ONE
 JMP COS5
TEN2 STAA SIGN
 JSR FABS
 STX ACCUM1
 LDX #COSTMP
 CLR 0,X
 JSR FSIGN
 LDX #ONE
 JSR FCOMPR
 BLE *+5
 JMP TEN4
 LDX CRET
 STX ACCUM1
 LDX #C255
 JSR FCOMPR
 BGE TEN3
 TST SIGN
 BPL TEN21
 LDX CRET
 LDAA #$20
 STAA 0,X
 JMP FSIGN
TEN21 LDX #INFIN
 JSR FABS
 JMP COS5
TEN3 LDX CRET
 JSR FIX
 STX IFACT
 INX
 STX ACCUM3
 CLRA
 LDAB ACCUM3+1
TEN31 SUBB #100
 BCS *+5
 INCA
 BRA TEN31
 STAA COSTMP
 CLRA
 ADDB #100
TEN32 SUBB #10
 BCS *+5
 INCA
 BRA TEN32
 ADDB #10
 ASLA
 ASLA
 ASLA
 ASLA
 ABA
 STAA COSTMP+1
TEN33 LDX IFACT
 STX ACCUM1
 LDX #SINVAL
 JSR FLOAT
 LDX CRET
 JSR FTAREG
 LDX #SINVAL
 JSR FTCREG
 JSR FSUB
 LDX CRET
 JSR FFDREG
 LDX CRET
 LDAA 0,X
 BITA #$20
 BEQ TEN4
 JMP TEN41
TEN4 LDX #SUM
 CLR 0,X
 JSR FSIGN
 LDX CRET
 JSR FTAREG
 LDX #LNCON
 JSR FTCREG
 JSR FMUL
 LDX CRET
 JSR FFDREG
 LDAB #5
 STAB TERMS
 LDX #TCON1
 STX ANGLE
 LDX CRET
 JSR SERIES
 LDX #SINVAL
 JSR FFDREG
 LDX #SUM
 CLR 0,X
 JSR FSIGN
 LDAB #5
 STAB TERMS
 LDX #TCON2
 STX ANGLE
 LDX CRET
 JSR SERIES
 LDX #COSVAL
 JSR FFDREG
 LDX #COSVAL
 JSR FTAREG
 LDX CRET
 JSR FTCREG
 JSR FMUL
 LDX #COSVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTAREG
 LDX #COSVAL
 JSR FTCREG
 JSR FADD
 LDX #SINVAL
 JSR FFDREG
 LDX #SINVAL
 JSR FTAREG
 LDX #COSTMP
 JSR FTCREG
 JSR FMUL
 LDX #COSTMP
 JSR FFDREG
TEN41 TST SIGN
 BPL TEN5
 LDX #COSTMP
 JSR FTAREG
 LDX #ONE
 JSR FTCREG
 JSR FDIV
 LDX #COSTMP
 JSR FFDREG
TEN5 LDX #COSTMP
 JMP COS5
*
* POWER FUNCTION
*
XTOY STX CCRET
 JSR LOG10
 LDX ACCUM1
 JSR FTAREG
 LDX CCRET
 JSR FTCREG
 JSR FMUL
 LDX CCRET
 JSR FFDREG
 LDX CCRET
 JMP TENEXP
*
 END
