2020-03-10 21:03:24 +00:00
|
|
|
; --- low level floating point assembly routines for the C64
|
|
|
|
|
2020-09-05 00:05:28 +00:00
|
|
|
FL_ONE_const .byte 129 ; 1.0
|
|
|
|
FL_ZERO_const .byte 0,0,0,0,0 ; 0.0
|
2020-12-21 22:22:02 +00:00
|
|
|
FL_LOG2_const .byte $80, $31, $72, $17, $f8 ; log(2)
|
|
|
|
|
2020-09-05 00:05:28 +00:00
|
|
|
|
2020-09-13 18:38:50 +00:00
|
|
|
floats_store_reg .byte 0 ; temp storage
|
|
|
|
|
2020-08-23 18:25:00 +00:00
|
|
|
|
2020-03-10 21:03:24 +00:00
|
|
|
ub2float .proc
|
|
|
|
; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y
|
|
|
|
; clobbers A, Y
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy P8ZP_SCRATCH_B1
|
2020-08-29 21:55:26 +00:00
|
|
|
lda #0
|
|
|
|
jsr GIVAYF
|
2020-08-25 17:44:08 +00:00
|
|
|
_fac_to_mem ldx P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ZP_SCRATCH_W2+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr MOVMF
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
b2float .proc
|
|
|
|
; -- convert byte in SCRATCH_ZPB1 to float at address A/Y
|
|
|
|
; clobbers A, Y
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
lda P8ZP_SCRATCH_B1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr FREADSA
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
uw2float .proc
|
|
|
|
; -- convert uword in SCRATCH_ZPWORD1 to float at address A/Y
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
lda P8ZP_SCRATCH_W1
|
|
|
|
ldy P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr GIVUAYFAY
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
w2float .proc
|
|
|
|
; -- convert word in SCRATCH_ZPWORD1 to float at address A/Y
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy P8ZP_SCRATCH_W1
|
|
|
|
lda P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr GIVAYF
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
2020-11-19 21:58:38 +00:00
|
|
|
|
|
|
|
cast_from_uw .proc
|
|
|
|
; -- uword in A/Y into float var at (P8ZP_SCRATCH_W2)
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr GIVUAYFAY
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
cast_from_w .proc
|
|
|
|
; -- word in A/Y into float var at (P8ZP_SCRATCH_W2)
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr GIVAYFAY
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
cast_from_ub .proc
|
|
|
|
; -- ubyte in Y into float var at (P8ZP_SCRATCH_W2)
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FREADUY
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
cast_from_b .proc
|
|
|
|
; -- byte in A into float var at (P8ZP_SCRATCH_W2)
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FREADSA
|
|
|
|
jmp ub2float._fac_to_mem
|
|
|
|
.pend
|
|
|
|
|
|
|
|
cast_as_uw_into_ya .proc ; also used for float 2 ub
|
|
|
|
; -- cast float at A/Y to uword into Y/A
|
|
|
|
jsr MOVFM
|
2020-11-26 00:52:48 +00:00
|
|
|
jmp cast_FAC1_as_uw_into_ya
|
|
|
|
.pend
|
|
|
|
|
|
|
|
cast_as_w_into_ay .proc ; also used for float 2 b
|
|
|
|
; -- cast float at A/Y to word into A/Y
|
|
|
|
jsr MOVFM
|
|
|
|
jmp cast_FAC1_as_w_into_ay
|
|
|
|
.pend
|
|
|
|
|
|
|
|
cast_FAC1_as_uw_into_ya .proc ; also used for float 2 ub
|
|
|
|
; -- cast fac1 to uword into Y/A
|
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-11-19 21:58:38 +00:00
|
|
|
jsr GETADR ; into Y/A
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-11-26 00:52:48 +00:00
|
|
|
cast_FAC1_as_w_into_ay .proc ; also used for float 2 b
|
|
|
|
; -- cast fac1 to word into A/Y
|
2020-11-19 21:58:38 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr AYINT
|
|
|
|
ldy $64
|
|
|
|
lda $65
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-03-10 21:03:24 +00:00
|
|
|
stack_b2float .proc
|
|
|
|
; -- b2float operating on the stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr FREADSA
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_w2float .proc
|
|
|
|
; -- w2float operating on the stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
|
|
|
lda P8ESTACK_HI,x
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr GIVAYF
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_ub2float .proc
|
|
|
|
; -- ub2float operating on the stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
tay
|
2020-08-29 21:55:26 +00:00
|
|
|
lda #0
|
|
|
|
jsr GIVAYF
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_uw2float .proc
|
|
|
|
; -- uw2float operating on the stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_HI,x
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr GIVUAYFAY
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_float2w .proc ; also used for float2b
|
2020-11-09 00:18:22 +00:00
|
|
|
jsr pop_float_fac1
|
2020-11-15 16:34:27 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr AYINT
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
lda $64
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2020-03-10 21:03:24 +00:00
|
|
|
lda $65
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_float2uw .proc ; also used for float2ub
|
2020-11-09 00:18:22 +00:00
|
|
|
jsr pop_float_fac1
|
2020-11-15 16:34:27 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr GETADR
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2020-03-10 21:03:24 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
push_float .proc
|
|
|
|
; ---- push mflpt5 in A/Y onto stack
|
|
|
|
; (taking 3 stack positions = 6 bytes of which 1 is padding)
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ESTACK_HI,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ESTACK_HI,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
pop_float .proc
|
|
|
|
; ---- pops mflpt5 from stack to memory A/Y
|
|
|
|
; (frees 3 stack positions = 6 bytes of which 1 is padding)
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
ldy #4
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-10 21:03:24 +00:00
|
|
|
dey
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-10 21:03:24 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-10 21:03:24 +00:00
|
|
|
dey
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-10 21:03:24 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
pop_float_fac1 .proc
|
|
|
|
; -- pops float from stack into FAC1
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr pop_float
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jmp MOVFM
|
|
|
|
.pend
|
|
|
|
|
|
|
|
copy_float .proc
|
2022-01-09 15:18:13 +00:00
|
|
|
; -- copies the 5 bytes of the mflt value pointed to by P8ZP_SCRATCH_W1,
|
2020-03-10 21:03:24 +00:00
|
|
|
; into the 5 bytes pointed to by A/Y. Clobbers A,Y.
|
2022-01-09 15:18:13 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
inc_var_f .proc
|
|
|
|
; -- add 1 to float pointed to by A/Y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr MOVFM
|
2020-09-05 00:05:28 +00:00
|
|
|
lda #<FL_ONE_const
|
|
|
|
ldy #>FL_ONE_const
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr FADD
|
2020-08-25 17:44:08 +00:00
|
|
|
ldx P8ZP_SCRATCH_W1
|
|
|
|
ldy P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr MOVMF
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
dec_var_f .proc
|
|
|
|
; -- subtract 1 from float pointed to by A/Y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-09-05 00:05:28 +00:00
|
|
|
lda #<FL_ONE_const
|
|
|
|
ldy #>FL_ONE_const
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr MOVFM
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W1
|
|
|
|
ldy P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr FSUB
|
2020-08-25 17:44:08 +00:00
|
|
|
ldx P8ZP_SCRATCH_W1
|
|
|
|
ldy P8ZP_SCRATCH_W1+1
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr MOVMF
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
pop_2_floats_f2_in_fac1 .proc
|
|
|
|
; -- pop 2 floats from stack, load the second one in FAC1 as well
|
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
|
|
|
jsr pop_float
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr pop_float
|
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
|
|
|
jmp MOVFM
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
fmath_float1 .byte 0,0,0,0,0 ; storage for a mflpt5 value
|
|
|
|
fmath_float2 .byte 0,0,0,0,0 ; storage for a mflpt5 value
|
|
|
|
|
2020-10-30 22:02:20 +00:00
|
|
|
|
|
|
|
push_fac1 .proc
|
2020-11-05 00:26:45 +00:00
|
|
|
; -- push the float in FAC1 onto the stack
|
2020-10-30 22:02:20 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-11-05 00:26:45 +00:00
|
|
|
_internal ldx #<fmath_float1
|
2020-03-10 21:03:24 +00:00
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr MOVMF
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
2020-09-13 18:42:55 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jmp push_float
|
|
|
|
.pend
|
|
|
|
|
|
|
|
div_f .proc
|
|
|
|
; -- push f1/f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr FDIV
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
add_f .proc
|
|
|
|
; -- push f1+f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr FADD
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
sub_f .proc
|
|
|
|
; -- push f1-f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr FSUB
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_f .proc
|
|
|
|
; -- push f1*f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2020-09-13 18:42:55 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr FMULT
|
2020-11-05 00:26:45 +00:00
|
|
|
jmp push_fac1._internal
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
neg_f .proc
|
2020-09-29 01:58:17 +00:00
|
|
|
; -- toggle the sign bit on the stack
|
2020-09-29 19:08:45 +00:00
|
|
|
lda P8ESTACK_HI+3,x
|
2020-09-29 01:58:17 +00:00
|
|
|
eor #$80
|
2020-09-29 19:08:45 +00:00
|
|
|
sta P8ESTACK_HI+3,x
|
2020-09-29 01:58:17 +00:00
|
|
|
rts
|
2020-03-10 21:03:24 +00:00
|
|
|
.pend
|
|
|
|
|
2020-11-23 23:35:30 +00:00
|
|
|
var_fac1_less_f .proc
|
|
|
|
; -- is the float in FAC1 < the variable AY?
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #255
|
|
|
|
beq +
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
+ lda #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
var_fac1_lesseq_f .proc
|
|
|
|
; -- is the float in FAC1 <= the variable AY?
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #0
|
|
|
|
beq +
|
|
|
|
cmp #255
|
|
|
|
beq +
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
+ lda #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
var_fac1_greater_f .proc
|
|
|
|
; -- is the float in FAC1 > the variable AY?
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #1
|
|
|
|
beq +
|
|
|
|
lda #0
|
2021-03-18 00:14:22 +00:00
|
|
|
rts
|
|
|
|
+ lda #1
|
|
|
|
rts
|
2020-11-23 23:35:30 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
var_fac1_greatereq_f .proc
|
|
|
|
; -- is the float in FAC1 >= the variable AY?
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #0
|
|
|
|
beq +
|
|
|
|
cmp #1
|
|
|
|
beq +
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
+ lda #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
var_fac1_notequal_f .proc
|
|
|
|
; -- are the floats numbers in FAC1 and the variable AY *not* identical?
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
and #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-11-22 12:56:23 +00:00
|
|
|
vars_equal_f .proc
|
|
|
|
; -- are the mflpt5 numbers in P8ZP_SCRATCH_W1 and AY identical?
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _false
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _false
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _false
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _false
|
|
|
|
iny
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _false
|
|
|
|
lda #1
|
|
|
|
rts
|
|
|
|
_false lda #0
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-03-10 21:03:24 +00:00
|
|
|
equal_f .proc
|
|
|
|
; -- are the two mflpt5 numbers on the stack identical?
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO-3,x
|
|
|
|
cmp P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
bne _equals_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO-2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2020-03-10 21:03:24 +00:00
|
|
|
bne _equals_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO-1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2020-03-10 21:03:24 +00:00
|
|
|
bne _equals_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI-2,x
|
|
|
|
cmp P8ESTACK_HI+1,x
|
2020-03-10 21:03:24 +00:00
|
|
|
bne _equals_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI-1,x
|
|
|
|
cmp P8ESTACK_HI+2,x
|
2020-03-10 21:03:24 +00:00
|
|
|
bne _equals_false
|
|
|
|
_equals_true lda #1
|
|
|
|
_equals_store inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
_equals_false lda #0
|
|
|
|
beq _equals_store
|
|
|
|
.pend
|
|
|
|
|
|
|
|
notequal_f .proc
|
|
|
|
; -- are the two mflpt5 numbers on the stack different?
|
|
|
|
jsr equal_f
|
|
|
|
eor #1 ; invert the result
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-11-22 14:05:45 +00:00
|
|
|
vars_less_f .proc
|
|
|
|
; -- is float in AY < float in P8ZP_SCRATCH_W2 ?
|
|
|
|
jsr MOVFM
|
|
|
|
lda P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ZP_SCRATCH_W2+1
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #255
|
|
|
|
bne +
|
|
|
|
lda #1
|
|
|
|
rts
|
|
|
|
+ lda #0
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
vars_lesseq_f .proc
|
|
|
|
; -- is float in AY <= float in P8ZP_SCRATCH_W2 ?
|
|
|
|
jsr MOVFM
|
|
|
|
lda P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ZP_SCRATCH_W2+1
|
|
|
|
stx P8ZP_SCRATCH_REG
|
|
|
|
jsr FCOMP
|
|
|
|
ldx P8ZP_SCRATCH_REG
|
|
|
|
cmp #255
|
|
|
|
bne +
|
|
|
|
- lda #1
|
|
|
|
rts
|
|
|
|
+ cmp #0
|
|
|
|
beq -
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-03-10 21:03:24 +00:00
|
|
|
less_f .proc
|
|
|
|
; -- is f1 < f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #255
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
lesseq_f .proc
|
|
|
|
; -- is f1 <= f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #255
|
|
|
|
beq compare_floats._return_true
|
|
|
|
cmp #0
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_f .proc
|
|
|
|
; -- is f1 > f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #1
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greatereq_f .proc
|
|
|
|
; -- is f1 >= f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #1
|
|
|
|
beq compare_floats._return_true
|
|
|
|
cmp #0
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
compare_floats .proc
|
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
|
|
|
jsr pop_float
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr pop_float
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr MOVFM ; fac1 = flt1
|
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
2020-08-25 17:44:08 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
jsr FCOMP ; A = flt1 compared with flt2 (0=equal, 1=flt1>flt2, 255=flt1<flt2)
|
2020-08-25 17:44:08 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2020-03-10 21:03:24 +00:00
|
|
|
rts
|
|
|
|
_return_false lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
_return_result sta P8ESTACK_LO,x
|
2020-03-10 21:03:24 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_return_true lda #1
|
|
|
|
bne _return_result
|
|
|
|
.pend
|
|
|
|
|
2020-10-30 22:02:20 +00:00
|
|
|
set_array_float_from_fac1 .proc
|
|
|
|
; -- set the float in FAC1 in the array (index in A, array in P8ZP_SCRATCH_W1)
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
|
|
|
adc P8ZP_SCRATCH_B1
|
|
|
|
ldy P8ZP_SCRATCH_W1+1
|
|
|
|
clc
|
|
|
|
adc P8ZP_SCRATCH_W1
|
|
|
|
bcc +
|
|
|
|
iny
|
|
|
|
+ stx floats_store_reg
|
|
|
|
tax
|
|
|
|
jsr MOVMF
|
|
|
|
ldx floats_store_reg
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 20:44:10 +00:00
|
|
|
|
|
|
|
set_0_array_float .proc
|
2020-10-19 21:57:00 +00:00
|
|
|
; -- set a float in an array to zero (index in A, array in P8ZP_SCRATCH_W1)
|
|
|
|
sta P8ZP_SCRATCH_B1
|
2020-04-03 20:44:10 +00:00
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
2020-10-19 21:57:00 +00:00
|
|
|
adc P8ZP_SCRATCH_B1
|
2020-04-03 20:44:10 +00:00
|
|
|
tay
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 20:44:10 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 20:44:10 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 20:44:10 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 20:44:10 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 20:44:10 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
set_array_float .proc
|
2020-10-19 21:57:00 +00:00
|
|
|
; -- set a float in an array to a value (index in A, float in P8ZP_SCRATCH_W1, array in P8ZP_SCRATCH_W2)
|
|
|
|
sta P8ZP_SCRATCH_B1
|
2020-04-03 20:44:10 +00:00
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
2020-10-19 21:57:00 +00:00
|
|
|
adc P8ZP_SCRATCH_B1
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ZP_SCRATCH_W2+1
|
2020-04-03 20:44:10 +00:00
|
|
|
bcc +
|
|
|
|
iny
|
|
|
|
+ jmp copy_float
|
|
|
|
; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1,
|
|
|
|
; into the 5 bytes pointed to by A/Y. Clobbers A,Y.
|
|
|
|
.pend
|
2020-06-17 19:41:38 +00:00
|
|
|
|
|
|
|
|
2022-01-09 00:33:30 +00:00
|
|
|
equal_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
beq _true
|
|
|
|
bne _false
|
|
|
|
_true lda #1
|
|
|
|
sta P8ESTACK_LO,x
|
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_false lda #0
|
|
|
|
sta P8ESTACK_LO,x
|
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
notequal_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
bne equal_zero._true
|
|
|
|
beq equal_zero._false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
beq equal_zero._false
|
|
|
|
bpl equal_zero._true
|
|
|
|
jmp equal_zero._false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
less_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
bmi equal_zero._true
|
|
|
|
jmp equal_zero._false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greaterequal_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
bpl equal_zero._true
|
|
|
|
jmp equal_zero._false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
lessequal_zero .proc
|
|
|
|
jsr floats.pop_float_fac1
|
|
|
|
jsr floats.SIGN
|
|
|
|
beq equal_zero._true
|
|
|
|
bmi equal_zero._true
|
|
|
|
jmp equal_zero._false
|
|
|
|
.pend
|