separated out rnd.s and trig.s

This commit is contained in:
Michael Steil 2008-10-13 00:11:02 +00:00
parent f7dfa9d068
commit aa1b5377ae
3 changed files with 303 additions and 263 deletions

266
msbasic.s
View File

@ -4805,6 +4805,9 @@ RTS3:
.include "float.s"
.include "rnd.s"
.include "trig.s"
@ -4814,269 +4817,6 @@ RTS3:
.ifndef KBD
CONRND1:
.byte $98,$35,$44,$7A
CONRND2:
.byte $68,$28,$B1,$46
.endif
RND:
.ifdef KBD
ldx #$10
jsr SIGN
beq LFC26
bmi LFC10
lda $87
ldy $88
LFBFA:
sta FAC+2
sty FAC+1
LFBFE:
asl a
asl a
eor FAC+2
asl a
eor FAC+1
asl a
asl a
asl a
asl a
eor FAC+1
asl a
rol FAC+2
rol FAC+1
LFC10:
lda FAC+2
dex
bne LFBFE
sta $87
sta FAC+3
lda FAC+1
sta $88
lda #$80
sta FAC
stx FACSIGN
jmp NORMALIZE_FAC2
LFC26:
ldy $03CA
lda $03C7
ora #$01
GOMOVMF:
bne LFBFA
.byte $F0
.else
jsr SIGN
.ifdef CONFIG_CBM_ALL
bmi L3F01
bne LDF63
lda ENTROPY
sta FAC+1
lda ENTROPY+4
sta FAC+2
lda ENTROPY+1
sta FAC+3
lda ENTROPY+5
sta FAC+4
jmp LDF88
LDF63:
.else
tax
bmi L3F01
.endif
lda #<RNDSEED
ldy #$00
jsr LOAD_FAC_FROM_YA
.ifndef CONFIG_CBM_ALL
txa
beq L3EDA
.endif
lda #<CONRND1
ldy #>CONRND1
jsr FMULT
lda #<CONRND2
ldy #>CONRND2
jsr FADD
L3F01:
ldx FAC_LAST
lda FAC+1
sta FAC_LAST
stx FAC+1
.ifdef CONFIG_CBM_ALL
ldx FAC+2
lda FAC+3
sta FAC+2
stx FAC+3
LDF88:
.endif
lda #$00
sta FACSIGN
lda FAC
sta FACEXTENSION
lda #$80
sta FAC
jsr NORMALIZE_FAC2
ldx #RNDSEED
ldy #$00
GOMOVMF:
jmp STORE_FAC_AT_YX_ROUNDED
.endif
SIN_COS_TAN_ATN:
COS:
lda #<CON_PI_HALF
ldy #>CON_PI_HALF
jsr FADD
SIN:
jsr COPY_FAC_TO_ARG_ROUNDED
lda #<CON_PI_DOUB
ldy #>CON_PI_DOUB
ldx ARGSIGN
jsr DIV
jsr COPY_FAC_TO_ARG_ROUNDED
jsr INT
lda #$00
sta STRNG1
jsr FSUBT
lda #<QUARTER
ldy #>QUARTER
jsr FSUB
lda FACSIGN
pha
bpl SIN1
jsr FADDH
lda FACSIGN
bmi L3F5B
lda CPRMASK
eor #$FF
sta CPRMASK
SIN1:
jsr NEGOP
L3F5B:
lda #<QUARTER
ldy #>QUARTER
jsr FADD
pla
bpl L3F68
jsr NEGOP
L3F68:
lda #<POLY_SIN
ldy #>POLY_SIN
jmp POLYNOMIAL_ODD
TAN:
jsr STORE_FAC_IN_TEMP1_ROUNDED
lda #$00
sta CPRMASK
jsr SIN
ldx #TEMP3
ldy #$00
jsr GOMOVMF
lda #TEMP1+(5-BYTES_FP)
ldy #$00
jsr LOAD_FAC_FROM_YA
lda #$00
sta FACSIGN
lda CPRMASK
jsr TAN1
lda #TEMP3
ldy #$00
jmp FDIV
TAN1:
pha
jmp SIN1
.ifdef CONFIG_SMALL
CON_PI_HALF:
.byte $81,$49,$0F,$DB
CON_PI_DOUB:
.byte $83,$49,$0F,$DB
QUARTER:
.byte $7F,$00,$00,$00
POLY_SIN:
.byte $04,$86,$1E,$D7,$FB,$87,$99,$26
.byte $65,$87,$23,$34,$58,$86,$A5,$5D
.byte $E1,$83,$49,$0F,$DB
.else
CON_PI_HALF:
.byte $81,$49,$0F,$DA,$A2
CON_PI_DOUB:
.byte $83,$49,$0F,$DA,$A2
QUARTER:
.byte $7F,$00,$00,$00,$00
POLY_SIN:
.byte $05,$84,$E6,$1A,$2D,$1B,$86,$28
.byte $07,$FB,$F8,$87,$99,$68,$89,$01
.byte $87,$23,$35,$DF,$E1,$86,$A5,$5D
.byte $E7,$28,$83,$49,$0F,$DA,$A2
.ifndef CONFIG_CBM_ALL
MICROSOFT:
.byte $A6,$D3,$C1,$C8,$D4,$C8,$D5,$C4
.byte $CE,$CA
.endif
.ifdef CBM2
MICROSOFT:
.byte $A1,$54,$46,$8F,$13,$8F,$52,$43
.byte $89,$CD
.endif
.endif
ATN:
lda FACSIGN
pha
bpl L3FDB
jsr NEGOP
L3FDB:
lda FAC
pha
cmp #$81
bcc L3FE9
lda #<CON_ONE
ldy #>CON_ONE
jsr FDIV
L3FE9:
lda #<POLY_ATN
ldy #>POLY_ATN
jsr POLYNOMIAL_ODD
pla
cmp #$81
bcc L3FFC
lda #<CON_PI_HALF
ldy #>CON_PI_HALF
jsr FSUB
L3FFC:
pla
bpl L4002
jmp NEGOP
L4002:
rts
POLY_ATN:
.ifdef CONFIG_SMALL
.byte $08
.byte $78,$3A,$C5,$37
.byte $7B,$83,$A2,$5C
.byte $7C,$2E,$DD,$4D
.byte $7D,$99,$B0,$1E
.byte $7D,$59,$ED,$24
.byte $7E,$91,$72,$00
.byte $7E,$4C,$B9,$73
.byte $7F,$AA,$AA,$53
.byte $81,$00,$00,$00
.else
.byte $0B
.byte $76,$B3,$83,$BD,$D3
.byte $79,$1E,$F4,$A6,$F5
.byte $7B,$83,$FC,$B0,$10
.byte $7C,$0C,$1F,$67,$CA
.byte $7C,$DE,$53,$CB,$C1
.byte $7D,$14,$64,$70,$4C
.byte $7D,$B7,$EA,$51,$7A
.byte $7D,$63,$30,$88,$7E
.byte $7E,$92,$44,$99,$3A
.byte $7E,$4C,$CC,$91,$C7
.byte $7F,$AA,$AA,$AA,$13
.byte $81,$00,$00,$00,$00
.ifdef KIM
.byte $00 ; XXX
.endif
.endif
RAMSTART1:
GENERIC_CHRGET:
inc TXTPTR

105
rnd.s Normal file
View File

@ -0,0 +1,105 @@
.ifdef KBD
RND:
ldx #$10
jsr SIGN
beq LFC26
bmi LFC10
lda $87
ldy $88
LFBFA:
sta FAC+2
sty FAC+1
LFBFE:
asl a
asl a
eor FAC+2
asl a
eor FAC+1
asl a
asl a
asl a
asl a
eor FAC+1
asl a
rol FAC+2
rol FAC+1
LFC10:
lda FAC+2
dex
bne LFBFE
sta $87
sta FAC+3
lda FAC+1
sta $88
lda #$80
sta FAC
stx FACSIGN
jmp NORMALIZE_FAC2
LFC26:
ldy $03CA
lda $03C7
ora #$01
GOMOVMF:
bne LFBFA
.byte $F0
.else
CONRND1:
.byte $98,$35,$44,$7A
CONRND2:
.byte $68,$28,$B1,$46
RND:
jsr SIGN
.ifdef CONFIG_CBM_ALL
bmi L3F01
bne LDF63
lda ENTROPY
sta FAC+1
lda ENTROPY+4
sta FAC+2
lda ENTROPY+1
sta FAC+3
lda ENTROPY+5
sta FAC+4
jmp LDF88
LDF63:
.else
tax
bmi L3F01
.endif
lda #<RNDSEED
ldy #>RNDSEED
jsr LOAD_FAC_FROM_YA
.ifndef CONFIG_CBM_ALL
txa
beq L3EDA
.endif
lda #<CONRND1
ldy #>CONRND1
jsr FMULT
lda #<CONRND2
ldy #>CONRND2
jsr FADD
L3F01:
ldx FAC_LAST
lda FAC+1
sta FAC_LAST
stx FAC+1
.ifdef CONFIG_CBM_ALL
ldx FAC+2
lda FAC+3
sta FAC+2
stx FAC+3
LDF88:
.endif
lda #$00
sta FACSIGN
lda FAC
sta FACEXTENSION
lda #$80
sta FAC
jsr NORMALIZE_FAC2
ldx #<RNDSEED
ldy #>RNDSEED
GOMOVMF:
jmp STORE_FAC_AT_YX_ROUNDED
.endif

195
trig.s Normal file
View File

@ -0,0 +1,195 @@
SIN_COS_TAN_ATN:
; ----------------------------------------------------------------------------
; "COS" FUNCTION
; ----------------------------------------------------------------------------
COS:
lda #<CON_PI_HALF
ldy #>CON_PI_HALF
jsr FADD
; ----------------------------------------------------------------------------
; "SIN" FUNCTION
; ----------------------------------------------------------------------------
SIN:
jsr COPY_FAC_TO_ARG_ROUNDED
lda #<CON_PI_DOUB
ldy #>CON_PI_DOUB
ldx ARGSIGN
jsr DIV
jsr COPY_FAC_TO_ARG_ROUNDED
jsr INT
lda #$00
sta STRNG1
jsr FSUBT
; ----------------------------------------------------------------------------
; (FAC) = ANGLE AS A FRACTION OF A FULL CIRCLE
;
; NOW FOLD THE RANGE INTO A QUARTER CIRCLE
;
; <<< THERE ARE MUCH SIMPLER WAYS TO DO THIS >>>
; ----------------------------------------------------------------------------
lda #<QUARTER
ldy #>QUARTER
jsr FSUB
lda FACSIGN
pha
bpl SIN1
jsr FADDH
lda FACSIGN
bmi L3F5B
lda CPRMASK
eor #$FF
sta CPRMASK
; ----------------------------------------------------------------------------
; IF FALL THRU, RANGE IS 0...1/2
; IF BRANCH HERE, RANGE IS 0...1/4
; ----------------------------------------------------------------------------
SIN1:
jsr NEGOP
; ----------------------------------------------------------------------------
; IF FALL THRU, RANGE IS -1/2...0
; IF BRANCH HERE, RANGE IS -1/4...0
; ----------------------------------------------------------------------------
L3F5B:
lda #<QUARTER
ldy #>QUARTER
jsr FADD
pla
bpl L3F68
jsr NEGOP
L3F68:
lda #<POLY_SIN
ldy #>POLY_SIN
jmp POLYNOMIAL_ODD
; ----------------------------------------------------------------------------
; "TAN" FUNCTION
;
; COMPUTE TAN(X) = SIN(X) / COS(X)
; ----------------------------------------------------------------------------
TAN:
jsr STORE_FAC_IN_TEMP1_ROUNDED
lda #$00
sta CPRMASK
jsr SIN
ldx #TEMP3
ldy #$00
jsr GOMOVMF
lda #TEMP1+(5-BYTES_FP)
ldy #$00
jsr LOAD_FAC_FROM_YA
lda #$00
sta FACSIGN
lda CPRMASK
jsr TAN1
lda #TEMP3
ldy #$00
jmp FDIV
TAN1:
pha
jmp SIN1
; ----------------------------------------------------------------------------
.ifdef CONFIG_SMALL
CON_PI_HALF:
.byte $81,$49,$0F,$DB
CON_PI_DOUB:
.byte $83,$49,$0F,$DB
QUARTER:
.byte $7F,$00,$00,$00
POLY_SIN:
.byte $04,$86,$1E,$D7,$FB,$87,$99,$26
.byte $65,$87,$23,$34,$58,$86,$A5,$5D
.byte $E1,$83,$49,$0F,$DB
.else
CON_PI_HALF:
.byte $81,$49,$0F,$DA,$A2
CON_PI_DOUB:
.byte $83,$49,$0F,$DA,$A2
QUARTER:
.byte $7F,$00,$00,$00,$00
POLY_SIN:
.byte $05,$84,$E6,$1A,$2D,$1B,$86,$28
.byte $07,$FB,$F8,$87,$99,$68,$89,$01
.byte $87,$23,$35,$DF,$E1,$86,$A5,$5D
.byte $E7,$28,$83,$49,$0F,$DA,$A2
.ifndef CONFIG_CBM_ALL
MICROSOFT:
.byte $A6,$D3,$C1,$C8,$D4,$C8,$D5,$C4
.byte $CE,$CA
.endif
.ifdef CBM2
MICROSOFT:
.byte $A1,$54,$46,$8F,$13,$8F,$52,$43
.byte $89,$CD
.endif
.endif
; ----------------------------------------------------------------------------
; "ATN" FUNCTION
; ----------------------------------------------------------------------------
ATN:
lda FACSIGN
pha
bpl L3FDB
jsr NEGOP
L3FDB:
lda FAC
pha
cmp #$81
bcc L3FE9
lda #<CON_ONE
ldy #>CON_ONE
jsr FDIV
; ----------------------------------------------------------------------------
; 0 <= X <= 1
; 0 <= ATN(X) <= PI/8
; ----------------------------------------------------------------------------
L3FE9:
lda #<POLY_ATN
ldy #>POLY_ATN
jsr POLYNOMIAL_ODD
pla
cmp #$81
bcc L3FFC
lda #<CON_PI_HALF
ldy #>CON_PI_HALF
jsr FSUB
L3FFC:
pla
bpl L4002
jmp NEGOP
L4002:
rts
; ----------------------------------------------------------------------------
POLY_ATN:
.ifdef CONFIG_SMALL
.byte $08
.byte $78,$3A,$C5,$37
.byte $7B,$83,$A2,$5C
.byte $7C,$2E,$DD,$4D
.byte $7D,$99,$B0,$1E
.byte $7D,$59,$ED,$24
.byte $7E,$91,$72,$00
.byte $7E,$4C,$B9,$73
.byte $7F,$AA,$AA,$53
.byte $81,$00,$00,$00
.else
.byte $0B
.byte $76,$B3,$83,$BD,$D3
.byte $79,$1E,$F4,$A6,$F5
.byte $7B,$83,$FC,$B0,$10
.byte $7C,$0C,$1F,$67,$CA
.byte $7C,$DE,$53,$CB,$C1
.byte $7D,$14,$64,$70,$4C
.byte $7D,$B7,$EA,$51,$7A
.byte $7D,$63,$30,$88,$7E
.byte $7E,$92,$44,$99,$3A
.byte $7E,$4C,$CC,$91,$C7
.byte $7F,$AA,$AA,$AA,$13
.byte $81,$00,$00,$00,$00
.ifdef KIM
.byte $00 ; XXX
.endif
.endif