mirror of
https://github.com/cc65/cc65.git
synced 2024-10-19 16:24:46 +00:00
408 lines
6.7 KiB
ArmAsm
408 lines
6.7 KiB
ArmAsm
|
|
.import __ctof
|
|
.import __utof
|
|
.import __itof
|
|
.import __stof
|
|
|
|
; 8bit signed -> float
|
|
.export afloat
|
|
afloat:
|
|
jmp __ctof
|
|
|
|
; 8bit unsigned -> float
|
|
.export aufloat
|
|
aufloat:
|
|
jmp __utof
|
|
|
|
; 16bit signed -> float
|
|
.export axfloat
|
|
axfloat:
|
|
jmp __itof
|
|
|
|
; 16bit unsigned -> float
|
|
.export axufloat
|
|
axufloat:
|
|
jmp __stof
|
|
|
|
; FIXME: this might be more accurate when done directly in one step (but the
|
|
; kernal can not do this for 32bit)
|
|
; 32bit signed -> float
|
|
.importzp sreg, tmp1
|
|
.import pusheax
|
|
|
|
.export eaxfloat
|
|
eaxfloat:
|
|
|
|
sta tmp1
|
|
|
|
lda sreg
|
|
pha
|
|
lda sreg+1
|
|
pha
|
|
|
|
; get lower 16bit
|
|
lda tmp1
|
|
|
|
; convert lower 16 bit
|
|
jsr __stof
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; / 65536
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
|
|
jsr __fdiv
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; get higher 16bit
|
|
pla
|
|
tax
|
|
pla
|
|
; convert higher 16 bit
|
|
jsr __itof
|
|
|
|
jsr __fadd
|
|
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; * 65536
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
|
|
jmp __fmul
|
|
|
|
; FIXME: this might be more accurate when done directly in one step (but the
|
|
; kernal can not do this for 32bit)
|
|
; 32bit unsigned -> float
|
|
.importzp sreg, tmp1
|
|
.import pusheax
|
|
|
|
.export eaxufloat
|
|
eaxufloat:
|
|
|
|
sta tmp1
|
|
|
|
lda sreg
|
|
pha
|
|
lda sreg+1
|
|
pha
|
|
|
|
; get lower 16bit
|
|
lda tmp1
|
|
|
|
; convert lower 16 bit
|
|
jsr __stof
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; / 65536
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
|
|
jsr __fdiv
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; get higher 16bit
|
|
pla
|
|
tax
|
|
pla
|
|
; convert higher 16 bit
|
|
jsr __stof
|
|
|
|
jsr __fadd
|
|
|
|
jsr pusheax ; push eax to stack
|
|
|
|
; * 65536
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
|
|
jmp __fmul
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
.import __ftoi
|
|
|
|
; float -> 16bit int
|
|
.export feaxint
|
|
feaxint:
|
|
jmp __ftoi
|
|
|
|
; FIXME: this might be more accurate when done directly in one step (but the
|
|
; kernal can not do this for 32bit)
|
|
; float -> 32bit int
|
|
.importzp tmp1, tmp2
|
|
.export feaxlong
|
|
feaxlong:
|
|
|
|
jsr pusheax
|
|
|
|
; primary = primary / 65536
|
|
jsr pusheax ; push eax to stack
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
jsr __fdiv ; primary / TOS
|
|
; convert result to int and save
|
|
jsr __ftoi
|
|
sta tmp1
|
|
stx tmp2
|
|
; convert back to float
|
|
jsr __stof
|
|
; primary = primary * 65536
|
|
jsr pusheax ; push eax to stack
|
|
ldx #$00
|
|
lda #$80
|
|
sta sreg
|
|
lda #$47
|
|
sta sreg+1
|
|
jsr __fmul ; primary * TOS
|
|
; substract the result from the total number to get the rest
|
|
jsr __fsub
|
|
; convert rest to int
|
|
jsr __ftoi
|
|
|
|
ldy tmp2
|
|
sty sreg+1
|
|
ldy tmp1
|
|
sty sreg
|
|
rts
|
|
|
|
;--------------------------------------------------------------
|
|
.import __fnot
|
|
.import __fneg
|
|
|
|
; binary negate (not) for the ! operator. returns a bool!
|
|
.export fbnegeax
|
|
.import bnegax
|
|
fbnegeax:
|
|
; FIXME: why does this not work with __fnot?
|
|
jsr __ftoi
|
|
jmp bnegax
|
|
|
|
.if 0 = 1
|
|
.export fnegeax
|
|
fnegeax:
|
|
jmp __fneg
|
|
.endif
|
|
|
|
;--------------------------------------------------------------
|
|
; math ops
|
|
|
|
.import __fadd
|
|
.import __fsub
|
|
.import __fdiv
|
|
.import __fmul
|
|
|
|
; Primary = TOS + Primary (like tosaddeax)
|
|
.export ftosaddeax
|
|
ftosaddeax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
|
|
; FAC: ieee float is in A/X/sreg/sreg+1
|
|
jmp __fadd
|
|
|
|
.export ftossubeax
|
|
ftossubeax:
|
|
jmp __fsub
|
|
.export ftosdiveax
|
|
ftosdiveax:
|
|
jmp __fdiv
|
|
.export ftosmuleax
|
|
ftosmuleax:
|
|
jmp __fmul
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
.import __fcmp
|
|
|
|
; test for equal
|
|
.export ftoseqeax
|
|
ftoseqeax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #0
|
|
beq @equal
|
|
lda #0
|
|
tax
|
|
rts
|
|
@equal:
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
|
|
; test for not equal
|
|
.export ftosneeax
|
|
ftosneeax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #0
|
|
beq @equal
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
@equal:
|
|
lda #0
|
|
tax
|
|
rts
|
|
|
|
; Test for greater than
|
|
.export ftosgteax
|
|
ftosgteax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #255
|
|
bne @biggerorequal
|
|
; less
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
@biggerorequal:
|
|
lda #0
|
|
tax
|
|
rts
|
|
|
|
; Test for less than
|
|
.export ftoslteax
|
|
ftoslteax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #1
|
|
beq @bigger
|
|
lda #0
|
|
tax
|
|
rts
|
|
@bigger:
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
|
|
; Test for greater than or equal to
|
|
.export ftosgeeax
|
|
ftosgeeax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #1
|
|
beq @bigger
|
|
; less than or equal
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
@bigger:
|
|
lda #0
|
|
tax
|
|
rts
|
|
|
|
; Test for less than or equal to
|
|
.export ftosleeax
|
|
ftosleeax:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jsr __fcmp
|
|
; a=0 (==) / a=1 (>) / a=255 (<)
|
|
cmp #255
|
|
beq @smaller
|
|
; greater than or equal
|
|
ldx #0
|
|
lda #1
|
|
rts
|
|
@smaller:
|
|
lda #0
|
|
tax
|
|
rts
|
|
|
|
;--------------------------------------------------------------
|
|
; math.h
|
|
|
|
.import __fpow
|
|
.import __fsin
|
|
.import __fcos
|
|
.import __flog
|
|
.import __fexp
|
|
.import __fsqr
|
|
.import __ftan
|
|
.import __fatn
|
|
.import __fabs
|
|
.import __fround
|
|
.import __fint
|
|
|
|
.export _powf
|
|
_powf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
; arg1: (sp),y (y=0..3)
|
|
jmp __fpow
|
|
|
|
.export _sinf
|
|
_sinf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fsin
|
|
|
|
.export _cosf
|
|
_cosf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fcos
|
|
|
|
.export _logf
|
|
_logf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __flog
|
|
|
|
.export _expf
|
|
_expf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fexp
|
|
|
|
.export _sqrtf
|
|
_sqrtf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fsqr
|
|
|
|
.export _tanf
|
|
_tanf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __ftan
|
|
|
|
.export _atanf
|
|
_atanf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fatn
|
|
|
|
.export _fabsf
|
|
_fabsf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fabs
|
|
|
|
.export _roundf
|
|
_roundf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fround
|
|
|
|
.export _truncf
|
|
_truncf:
|
|
; arg0: a/x/sreg/sreg+1
|
|
jmp __fint
|