2018-09-15 14:21:05 +00:00
|
|
|
; Prog8 internal library routines - always included by the compiler
|
2017-12-30 12:34:52 +00:00
|
|
|
;
|
2018-01-08 02:31:23 +00:00
|
|
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
2018-01-13 13:17:18 +00:00
|
|
|
;
|
2017-12-30 12:34:52 +00:00
|
|
|
; indent format: TABS, size=8
|
|
|
|
|
|
|
|
|
2018-09-15 14:21:05 +00:00
|
|
|
~ prog8_lib {
|
2018-12-06 23:08:22 +00:00
|
|
|
; @TODO move all this assembly to a real .asm file instead and include that...
|
2018-12-14 22:15:44 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
|
2017-12-30 19:03:19 +00:00
|
|
|
; note: the following ZP scratch registers must be the same as in c64lib
|
2018-12-06 23:08:22 +00:00
|
|
|
memory ubyte SCRATCH_ZPB1 = $02 ; scratch byte 1 in ZP
|
|
|
|
memory ubyte SCRATCH_ZPREG = $03 ; scratch register in ZP
|
2018-12-16 02:38:17 +00:00
|
|
|
memory ubyte SCRATCH_ZPREGX = $fa ; temp storage for X register (stack pointer)
|
2018-10-21 21:03:15 +00:00
|
|
|
memory uword SCRATCH_ZPWORD1 = $fb ; scratch word in ZP ($fb/$fc)
|
|
|
|
memory uword SCRATCH_ZPWORD2 = $fd ; scratch word in ZP ($fd/$fe)
|
2018-12-06 00:26:38 +00:00
|
|
|
const uword ESTACK_LO = $ce00
|
|
|
|
const uword ESTACK_HI = $cf00
|
2017-12-30 12:34:52 +00:00
|
|
|
|
|
|
|
|
2018-08-12 23:30:33 +00:00
|
|
|
%asm {{
|
2017-12-30 12:34:52 +00:00
|
|
|
|
2018-10-21 21:03:15 +00:00
|
|
|
; 16-bit rotate right (as opposed to the 6502's usual 17-bit rotate with carry)
|
|
|
|
; the word is placed in SCRATCH_ZPWORD1
|
2018-12-06 23:08:22 +00:00
|
|
|
ror2_word .proc
|
2018-10-21 21:03:15 +00:00
|
|
|
lsr SCRATCH_ZPWORD1+1
|
|
|
|
ror SCRATCH_ZPWORD1
|
2018-02-03 00:44:14 +00:00
|
|
|
bcc +
|
2018-10-21 21:03:15 +00:00
|
|
|
lda SCRATCH_ZPWORD1+1
|
|
|
|
ora #$80
|
|
|
|
sta SCRATCH_ZPWORD1+1
|
2018-02-04 21:00:08 +00:00
|
|
|
+ rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-02-04 21:00:08 +00:00
|
|
|
|
2018-10-23 23:39:52 +00:00
|
|
|
|
|
|
|
|
2018-12-06 00:26:38 +00:00
|
|
|
; @todo: implement stubs!
|
2018-10-25 21:17:10 +00:00
|
|
|
; @todo: move float operations to their own library (only included when floats are enabled)
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
ub2float .proc
|
2018-12-12 00:13:13 +00:00
|
|
|
; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y
|
|
|
|
; clobbers A, Y
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
sta SCRATCH_ZPWORD2
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
ldy SCRATCH_ZPB1
|
|
|
|
jsr c64.FREADUY
|
|
|
|
_fac_to_mem ldx SCRATCH_ZPWORD2
|
|
|
|
ldy SCRATCH_ZPWORD2+1
|
|
|
|
jsr c64.MOVMF
|
|
|
|
ldx SCRATCH_ZPREGX
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
b2float .proc
|
2018-12-12 00:13:13 +00:00
|
|
|
; -- convert byte in SCRATCH_ZPB1 to float at address A/Y
|
|
|
|
; clobbers A, Y
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
sta SCRATCH_ZPWORD2
|
|
|
|
sty SCRATCH_ZPWORD2+1
|
|
|
|
lda SCRATCH_ZPB1
|
|
|
|
jsr c64.FREADSA
|
|
|
|
jmp ub2float._fac_to_mem
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-26 22:34:42 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
uw2float .proc
|
2018-12-12 00:13:13 +00:00
|
|
|
; -- convert uword in SCRATCH_ZPWORD1 to float at address A/Y
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
sta SCRATCH_ZPWORD2
|
|
|
|
sty SCRATCH_ZPWORD2+1
|
|
|
|
lda SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
|
|
|
jsr c64flt.GIVUAYFAY
|
|
|
|
jmp ub2float._fac_to_mem
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
w2float .proc
|
2018-12-12 00:13:13 +00:00
|
|
|
; -- convert word in SCRATCH_ZPWORD1 to float at address A/Y
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
sta SCRATCH_ZPWORD2
|
|
|
|
sty SCRATCH_ZPWORD2+1
|
|
|
|
ldy SCRATCH_ZPWORD1
|
|
|
|
lda SCRATCH_ZPWORD1+1
|
|
|
|
jsr c64.GIVAYF
|
|
|
|
jmp ub2float._fac_to_mem
|
2018-12-16 02:38:17 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_b2float .proc
|
|
|
|
; -- b2float operating on the stack
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.FREADSA
|
|
|
|
jmp push_fac1_as_result
|
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_w2float .proc
|
|
|
|
; -- w2float operating on the stack
|
|
|
|
inx
|
|
|
|
ldy ESTACK_LO,x
|
|
|
|
lda ESTACK_HI,x
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.GIVAYF
|
|
|
|
jmp push_fac1_as_result
|
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_ub2float .proc
|
|
|
|
; -- ub2float operating on the stack
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
tay
|
|
|
|
jsr c64.FREADUY
|
|
|
|
jmp push_fac1_as_result
|
|
|
|
.pend
|
|
|
|
|
|
|
|
stack_uw2float .proc
|
|
|
|
; -- uw2float operating on the stack
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
ldy ESTACK_HI,x
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64flt.GIVUAYFAY
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-26 22:34:42 +00:00
|
|
|
|
2018-12-16 02:38:17 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
push_float .proc
|
2018-12-06 00:26:38 +00:00
|
|
|
; ---- push mflpt5 in A/Y onto stack
|
|
|
|
; (taking 3 stack positions = 6 bytes of which 1 is padding)
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
ldy #0
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
sta ESTACK_LO,x
|
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
sta ESTACK_HI,x
|
|
|
|
dex
|
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
sta ESTACK_LO,x
|
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
sta ESTACK_HI,x
|
|
|
|
dex
|
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
sta ESTACK_LO,x
|
|
|
|
dex
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-02 22:53:09 +00:00
|
|
|
|
2018-12-13 00:19:43 +00:00
|
|
|
|
|
|
|
add_a_to_zpword .proc
|
|
|
|
; -- add ubyte in A to the uword in SCRATCH_ZPWORD1
|
2018-12-14 22:15:44 +00:00
|
|
|
clc
|
|
|
|
adc SCRATCH_ZPWORD1
|
2018-12-13 00:19:43 +00:00
|
|
|
sta SCRATCH_ZPWORD1
|
2018-12-14 22:15:44 +00:00
|
|
|
bvc +
|
|
|
|
inc SCRATCH_ZPWORD1+1
|
|
|
|
+ rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
pop_index_times_5 .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
sta SCRATCH_ZPB1
|
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
2018-12-14 22:15:44 +00:00
|
|
|
adc SCRATCH_ZPB1 ; A*=5
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
push_float_from_indexed_var .proc
|
|
|
|
; -- push the float from the array at A/Y with index on stack, onto the stack.
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
jsr pop_index_times_5
|
2018-12-13 00:19:43 +00:00
|
|
|
jsr add_a_to_zpword
|
2018-12-14 22:15:44 +00:00
|
|
|
lda SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
2018-12-13 00:19:43 +00:00
|
|
|
jmp push_float
|
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
pop_float .proc
|
|
|
|
; ---- pops mflpt5 from stack to memory A/Y
|
2018-12-06 00:26:38 +00:00
|
|
|
; (frees 3 stack positions = 6 bytes of which 1 is padding)
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
ldy #4
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
2018-12-06 23:08:22 +00:00
|
|
|
sta (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
dey
|
|
|
|
inx
|
|
|
|
lda ESTACK_HI,x
|
2018-12-06 23:08:22 +00:00
|
|
|
sta (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
dey
|
|
|
|
lda ESTACK_LO,x
|
2018-12-06 23:08:22 +00:00
|
|
|
sta (SCRATCH_ZPWORD1),y
|
|
|
|
dey
|
|
|
|
inx
|
2018-12-06 00:26:38 +00:00
|
|
|
lda ESTACK_HI,x
|
2018-12-06 23:08:22 +00:00
|
|
|
sta (SCRATCH_ZPWORD1),y
|
2018-12-06 00:26:38 +00:00
|
|
|
dey
|
2018-12-06 23:08:22 +00:00
|
|
|
lda ESTACK_LO,x
|
|
|
|
sta (SCRATCH_ZPWORD1),y
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-02 22:53:09 +00:00
|
|
|
|
2018-12-16 02:38:17 +00:00
|
|
|
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 c64.MOVFM
|
|
|
|
.pend
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
pop_float_to_indexed_var .proc
|
2018-12-14 22:15:44 +00:00
|
|
|
; -- pop the float on the stack, to the memory in the array at A/Y indexed by the byte on stack
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
jsr pop_index_times_5
|
|
|
|
jsr add_a_to_zpword
|
|
|
|
lda SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
|
|
|
jmp pop_float
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
copy_float .proc
|
2018-12-06 00:26:38 +00:00
|
|
|
; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1,
|
|
|
|
; into the 5 bytes pointed to by A/Y. Clobbers Y.
|
|
|
|
sta SCRATCH_ZPWORD2
|
|
|
|
sty SCRATCH_ZPWORD2+1
|
|
|
|
ldy #0
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
|
|
|
sta (SCRATCH_ZPWORD2),y
|
2018-12-06 00:26:38 +00:00
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
|
|
|
sta (SCRATCH_ZPWORD2),y
|
2018-12-06 00:26:38 +00:00
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
|
|
|
sta (SCRATCH_ZPWORD2),y
|
2018-12-06 00:26:38 +00:00
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
|
|
|
sta (SCRATCH_ZPWORD2),y
|
2018-12-06 00:26:38 +00:00
|
|
|
iny
|
2018-12-06 23:08:22 +00:00
|
|
|
lda (SCRATCH_ZPWORD1),y
|
|
|
|
sta (SCRATCH_ZPWORD2),y
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
inc_var_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- add 1 to float pointed to by A/Y
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.MOVFM
|
|
|
|
lda #<c64.FL_FONE
|
|
|
|
ldy #>c64.FL_FONE
|
|
|
|
jsr c64.FADD
|
|
|
|
ldx SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
|
|
|
jsr c64.MOVMF
|
|
|
|
ldx SCRATCH_ZPREGX
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
dec_var_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- subtract 1 from float pointed to by A/Y
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
sty SCRATCH_ZPWORD1+1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
lda #<c64.FL_FONE
|
|
|
|
ldy #>c64.FL_FONE
|
|
|
|
jsr c64.MOVFM
|
|
|
|
lda SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
|
|
|
jsr c64.FSUB
|
|
|
|
ldx SCRATCH_ZPWORD1
|
|
|
|
ldy SCRATCH_ZPWORD1+1
|
|
|
|
jsr c64.MOVMF
|
|
|
|
ldx SCRATCH_ZPREGX
|
2018-10-23 23:39:52 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-13 00:19:43 +00:00
|
|
|
pop_2_floats_f2_in_fac1 .proc
|
|
|
|
; -- pop 2 floats from stack, load the second one in FAC1
|
|
|
|
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 c64.MOVFM
|
|
|
|
.pend
|
|
|
|
|
|
|
|
fmath_float1 .fill 5 ; storage for a mflpt5 value
|
|
|
|
fmath_float2 .fill 5 ; storage for a mflpt5 value
|
|
|
|
|
|
|
|
push_fac1_as_result .proc
|
|
|
|
; -- push the float in FAC1 onto the stack, and return from calculation
|
|
|
|
ldx #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr c64.MOVMF
|
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
ldx SCRATCH_ZPREGX
|
|
|
|
jmp push_float
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
div_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- push f1/f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2018-12-16 02:38:17 +00:00
|
|
|
stx SCRATCH_ZPREGX
|
2018-12-13 00:19:43 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr c64.FDIV
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
add_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- push f1+f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2018-12-16 02:38:17 +00:00
|
|
|
stx SCRATCH_ZPREGX
|
2018-12-13 00:19:43 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr c64.FADD
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
sub_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- push f1-f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2018-12-16 02:38:17 +00:00
|
|
|
stx SCRATCH_ZPREGX
|
2018-12-13 00:19:43 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr c64.FSUB
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
mul_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- push f1*f2 on stack
|
|
|
|
jsr pop_2_floats_f2_in_fac1
|
2018-12-16 02:38:17 +00:00
|
|
|
stx SCRATCH_ZPREGX
|
2018-12-13 00:19:43 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
|
|
|
jsr c64.FMULT
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-23 23:39:52 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
neg_f .proc
|
2018-12-13 00:19:43 +00:00
|
|
|
; -- push -flt back on stack
|
2018-12-16 02:38:17 +00:00
|
|
|
jsr pop_float_fac1
|
2018-12-13 00:19:43 +00:00
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.NEGOP
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-10-25 21:17:10 +00:00
|
|
|
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
add_w .proc
|
2018-12-14 22:15:44 +00:00
|
|
|
; -- push word+word
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "addw check correctness"
|
2018-12-14 22:15:44 +00:00
|
|
|
inx
|
|
|
|
clc
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
adc ESTACK_LO+1,x
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
lda ESTACK_HI,x
|
|
|
|
adc ESTACK_HI+1,x
|
|
|
|
sta ESTACK_HI+1,x
|
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
add_uw .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "add_uw check correctness"
|
2018-12-14 22:15:44 +00:00
|
|
|
inx
|
|
|
|
clc
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
adc ESTACK_LO+1,x
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
lda ESTACK_HI,x
|
|
|
|
adc ESTACK_HI+1,x
|
|
|
|
sta ESTACK_HI+1,x
|
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-11-20 23:02:02 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
sub_w .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts ; @todo inline?
|
2018-12-06 23:08:22 +00:00
|
|
|
.warn "not implemented"
|
|
|
|
.pend
|
|
|
|
|
|
|
|
sub_uw .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts ; @todo inline?
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "sub_w not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-11-20 23:02:02 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
mul_b .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "mul_b not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_ub .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "mul_ub not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_w .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "mul_w not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_uw .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "mul_uw not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-11-20 23:02:02 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
div_b .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "div_b not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
div_ub .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "div_ub not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
div_w .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "div_w not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
div_uw .proc
|
2018-11-20 23:02:02 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "div_uw not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-11-20 23:02:02 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
remainder_b .proc
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "remainder_b not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
remainder_ub .proc
|
2018-12-10 23:09:37 +00:00
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x ; right operand
|
|
|
|
sta SCRATCH_ZPB1
|
|
|
|
lda ESTACK_LO+1,x ; left operand
|
|
|
|
- cmp SCRATCH_ZPB1
|
|
|
|
bcc +
|
|
|
|
sbc SCRATCH_ZPB1
|
|
|
|
jmp -
|
|
|
|
+ sta ESTACK_LO+1,x
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
remainder_w .proc
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "remainder_w not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
remainder_uw .proc
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "remainder_uw not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
equal_w .proc
|
2018-12-07 23:27:12 +00:00
|
|
|
; -- are the two words on the stack identical?
|
2018-12-09 02:46:02 +00:00
|
|
|
; @todo optimize according to http://www.6502.org/tutorials/compare_beyond.html
|
2018-12-08 17:08:46 +00:00
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
cmp ESTACK_HI+2,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
beq equal_b._equal_b_true
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-07 23:27:12 +00:00
|
|
|
notequal_b .proc
|
|
|
|
; -- are the two bytes on the stack different?
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
eor ESTACK_LO+1,x
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
notequal_w .proc
|
|
|
|
; -- are the two words on the stack different?
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO,x
|
|
|
|
eor ESTACK_LO+1,x
|
|
|
|
beq +
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
rts
|
|
|
|
+ lda ESTACK_HI,x
|
|
|
|
eor ESTACK_HI+1,x
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
less_ub .proc
|
2018-12-08 17:08:46 +00:00
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
less_b .proc
|
2018-12-09 02:46:02 +00:00
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
sec
|
|
|
|
sbc ESTACK_LO+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
less_uw .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_HI+2,x
|
|
|
|
cmp ESTACK_HI+1,x
|
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
less_w .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
lda ESTACK_HI+2,x
|
|
|
|
sbc ESTACK_HI+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
equal_b .proc
|
|
|
|
; -- are the two bytes on the stack identical?
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bne _equal_b_false
|
|
|
|
_equal_b_true lda #1
|
|
|
|
_equal_b_store inx
|
|
|
|
sta ESTACK_LO+1,x
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-09 15:16:46 +00:00
|
|
|
_equal_b_false lda #0
|
|
|
|
beq _equal_b_store
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
lesseq_ub .proc
|
2018-12-08 17:08:46 +00:00
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bcc equal_b._equal_b_true
|
2018-12-09 15:16:46 +00:00
|
|
|
beq equal_b._equal_b_true ; @todo optimize by flipping comparison
|
2018-12-08 17:08:46 +00:00
|
|
|
bcs equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
lesseq_b .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
clc
|
|
|
|
sbc ESTACK_LO+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
lesseq_uw .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
cmp ESTACK_HI+2,x
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
bne equal_b._equal_b_true
|
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
2018-12-08 17:08:46 +00:00
|
|
|
.pend
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
lesseq_w .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
sbc ESTACK_HI+2,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greater_ub .proc
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
beq equal_b._equal_b_false
|
2018-12-09 15:16:46 +00:00
|
|
|
bcs equal_b._equal_b_true ; @todo optimize by flipping comparison?
|
2018-12-08 17:08:46 +00:00
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_b .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
clc
|
|
|
|
sbc ESTACK_LO+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
2018-12-08 17:08:46 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_uw .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
cmp ESTACK_HI+2,x
|
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greater_w .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
sbc ESTACK_HI+2,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greatereq_ub .proc
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greatereq_b .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
sec
|
|
|
|
sbc ESTACK_LO+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greatereq_uw .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_HI+2,x
|
|
|
|
cmp ESTACK_HI+1,x
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
bne equal_b._equal_b_true
|
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greatereq_w .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
lda ESTACK_LO+2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
lda ESTACK_HI+2,x
|
|
|
|
sbc ESTACK_HI+1,x
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
equal_f .proc
|
|
|
|
; -- are the two mflpt5 numbers on the stack identical?
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
lda ESTACK_LO-3,x
|
|
|
|
cmp ESTACK_LO,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_LO-2,x
|
|
|
|
cmp ESTACK_LO+1,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_LO-1,x
|
|
|
|
cmp ESTACK_LO+2,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_HI-2,x
|
|
|
|
cmp ESTACK_HI+1,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
lda ESTACK_HI-1,x
|
|
|
|
cmp ESTACK_HI+2,x
|
|
|
|
bne equal_b._equal_b_false
|
|
|
|
beq equal_b._equal_b_true
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-08 17:08:46 +00:00
|
|
|
|
|
|
|
notequal_f .proc
|
|
|
|
; -- are the two mflpt5 numbers on the stack different?
|
|
|
|
jsr equal_f
|
|
|
|
eor #1 ; invert the result
|
|
|
|
sta ESTACK_LO+1,x
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-08 17:08:46 +00:00
|
|
|
|
|
|
|
less_f .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; -- is f1 < f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #255
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-09 15:16:46 +00:00
|
|
|
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
lesseq_f .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; -- 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
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-08 17:08:46 +00:00
|
|
|
greater_f .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; -- is f1 > f2?
|
|
|
|
jsr compare_floats
|
|
|
|
cmp #1
|
|
|
|
beq compare_floats._return_true
|
|
|
|
bne compare_floats._return_false
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-04 21:30:35 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
greatereq_f .proc
|
2018-12-09 15:16:46 +00:00
|
|
|
; -- 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
|
2018-12-16 02:38:17 +00:00
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
2018-12-09 15:16:46 +00:00
|
|
|
jsr pop_float
|
2018-12-16 02:38:17 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
2018-12-09 15:16:46 +00:00
|
|
|
jsr pop_float
|
2018-12-16 02:38:17 +00:00
|
|
|
lda #<fmath_float1
|
|
|
|
ldy #>fmath_float1
|
2018-12-09 15:16:46 +00:00
|
|
|
jsr c64.MOVFM ; fac1 = flt1
|
2018-12-16 02:38:17 +00:00
|
|
|
lda #<fmath_float2
|
|
|
|
ldy #>fmath_float2
|
2018-12-09 15:16:46 +00:00
|
|
|
stx SCRATCH_ZPREG
|
|
|
|
jsr c64.FCOMP ; A = flt1 compared with flt2 (0=equal, 1=flt1>flt2, 255=flt1<flt2)
|
|
|
|
ldx SCRATCH_ZPREG
|
|
|
|
rts
|
|
|
|
_return_false lda #0
|
|
|
|
_return_result sta ESTACK_LO,x
|
|
|
|
dex
|
2018-12-04 21:30:35 +00:00
|
|
|
rts
|
2018-12-09 15:16:46 +00:00
|
|
|
_return_true lda #1
|
|
|
|
bne _return_result
|
|
|
|
.pend
|
2018-12-08 17:08:46 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
func_sin .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
; -- push sin(f) back onto stack
|
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.SIN
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_cos .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
; -- push cos(f) back onto stack
|
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.COS
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_abs .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "abs not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_acos .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "acos not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_asin .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "asin not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_tan .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
; -- push tan(f) back onto stack
|
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.TAN
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_atan .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "atan not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_ln .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "ln not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_log2 .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "log2 not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_log10 .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "log10 not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sqrt .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
jsr c64.SQR
|
|
|
|
jmp push_fac1_as_result
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_rad .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
; -- convert degrees to radians (d * pi / 180)
|
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
lda #<_pi_div_180
|
|
|
|
ldy #>_pi_div_180
|
|
|
|
jsr c64.FMULT
|
|
|
|
jmp push_fac1_as_result
|
|
|
|
_pi_div_180 .byte 123, 14, 250, 53, 18 ; pi / 180
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_deg .proc
|
2018-12-16 02:38:17 +00:00
|
|
|
; -- convert radians to degrees (d * (1/ pi * 180))
|
|
|
|
jsr pop_float_fac1
|
|
|
|
stx SCRATCH_ZPREGX
|
|
|
|
lda #<_one_over_pi_div_180
|
|
|
|
ldy #>_one_over_pi_div_180
|
|
|
|
jsr c64.FMULT
|
|
|
|
jmp push_fac1_as_result
|
|
|
|
_one_over_pi_div_180 .byte 134, 101, 46, 224, 211 ; 1 / (pi * 180)
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_round .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "round not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_floor .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "floor not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_ceil .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "ceil not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_max .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "max not implemented--what does it max over???"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_min .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "min not implemented--what does it min over???"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_avg .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "avg not implemented--what does it avg over???"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sum .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "sum not implemented--what does it sum over???"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_any .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "any not implemented--of what does it do any?"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_all .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "all not implemented--of what does it do all?"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
2018-12-16 12:58:18 +00:00
|
|
|
func_len_str .proc
|
|
|
|
; -- push length of 0-terminated string on stack
|
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
sta SCRATCH_ZPWORD1+1
|
|
|
|
ldy #0
|
|
|
|
- lda (SCRATCH_ZPWORD1),y
|
|
|
|
beq +
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ tya
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_len_strp .proc
|
|
|
|
; -- push length of pascal-string on stack
|
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
sta SCRATCH_ZPWORD1
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
sta SCRATCH_ZPWORD1+1
|
|
|
|
ldy #0
|
|
|
|
lda (SCRATCH_ZPWORD1),y ; first byte is length
|
|
|
|
sta ESTACK_LO+1,x
|
|
|
|
rts
|
|
|
|
.pend
|
2018-12-06 00:26:38 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
func_rnd .proc
|
2018-12-06 00:26:38 +00:00
|
|
|
; -- put a random ubyte on the estack
|
|
|
|
jsr math.randbyte
|
|
|
|
sta ESTACK_LO,x
|
|
|
|
dex
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-06 00:26:38 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
func_rndw .proc
|
2018-12-06 00:26:38 +00:00
|
|
|
; -- put a random uword on the estack
|
|
|
|
jsr math.randword
|
|
|
|
sta ESTACK_LO,x
|
|
|
|
tya
|
|
|
|
sta ESTACK_HI,x
|
|
|
|
dex
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-06 00:26:38 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
func_rndf .proc
|
2018-12-06 00:26:38 +00:00
|
|
|
; -- put a random floating point value on the stack
|
2018-12-06 23:08:22 +00:00
|
|
|
stx SCRATCH_ZPREG
|
|
|
|
lda #1
|
|
|
|
jsr c64.FREADSA
|
|
|
|
jsr c64.RND ; rng into fac1
|
2018-12-06 00:26:38 +00:00
|
|
|
ldx #<_rndf_rnum5
|
|
|
|
ldy #>_rndf_rnum5
|
2018-12-12 00:13:13 +00:00
|
|
|
jsr c64.MOVMF ; fac1 to mem X/Y
|
2018-12-06 23:08:22 +00:00
|
|
|
ldx SCRATCH_ZPREG
|
2018-12-06 00:26:38 +00:00
|
|
|
lda #<_rndf_rnum5
|
|
|
|
ldy #>_rndf_rnum5
|
|
|
|
jmp push_float
|
|
|
|
_rndf_rnum5 .fill 5
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
2018-12-06 00:26:38 +00:00
|
|
|
|
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
func_str2byte .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "str2byte not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
2018-12-10 23:09:37 +00:00
|
|
|
; @todo python code for a str-to-ubyte function that doesn't use the basic rom:
|
|
|
|
;def str2ubyte(s, slen):
|
|
|
|
; hundreds_map = {
|
|
|
|
; 0: 0,
|
|
|
|
; 1: 100,
|
|
|
|
; 2: 200
|
|
|
|
; }
|
|
|
|
; digitvalue = 0
|
|
|
|
; result = 0
|
|
|
|
; if slen==0:
|
|
|
|
; return digitvalue
|
|
|
|
; digitvalue = ord(s[slen-1])-48
|
|
|
|
; slen -= 1
|
|
|
|
; if slen==0:
|
|
|
|
; return digitvalue
|
|
|
|
; result = digitvalue
|
|
|
|
; digitvalue = 10 * (ord(s[slen-1])-48)
|
|
|
|
; result += digitvalue
|
|
|
|
; slen -= 1
|
|
|
|
; if slen==0:
|
|
|
|
; return result
|
|
|
|
; digitvalue = hundreds_map[ord(s[slen-1])-48]
|
|
|
|
; result += digitvalue
|
|
|
|
; return result
|
|
|
|
|
2018-12-12 00:13:13 +00:00
|
|
|
func_str2ubyte .proc
|
|
|
|
jmp func_str2uword
|
|
|
|
.pend
|
2018-12-06 23:08:22 +00:00
|
|
|
|
2018-12-10 23:09:37 +00:00
|
|
|
func_str2uword .proc
|
|
|
|
;-- convert string (address on stack) to uword number
|
|
|
|
lda ESTACK_LO+1,x
|
|
|
|
sta $22
|
|
|
|
lda ESTACK_HI+1,x
|
|
|
|
sta $23
|
|
|
|
jsr _strlen2233
|
|
|
|
tya
|
|
|
|
stx SCRATCH_ZPREG
|
|
|
|
jsr c64.FREADSTR ; string to fac1
|
|
|
|
jsr c64.GETADR ; fac1 to unsigned word in Y/A
|
|
|
|
ldx SCRATCH_ZPREG
|
|
|
|
sta ESTACK_HI+1,x
|
|
|
|
tya
|
|
|
|
sta ESTACK_LO+1,x
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-10 23:09:37 +00:00
|
|
|
_strlen2233
|
|
|
|
;-- return the length of the (zero-terminated) string at $22/$23, in Y
|
|
|
|
ldy #0
|
|
|
|
- lda ($22),y
|
|
|
|
beq +
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ rts
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
2018-12-10 23:09:37 +00:00
|
|
|
func_str2word .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "str2word not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_str2float .proc
|
2018-10-25 21:17:10 +00:00
|
|
|
rts
|
2018-12-16 02:38:17 +00:00
|
|
|
.warn "str2float not implemented"
|
2018-12-06 23:08:22 +00:00
|
|
|
.pend
|
|
|
|
|
2018-10-25 21:17:10 +00:00
|
|
|
|
2018-08-12 23:30:33 +00:00
|
|
|
}}
|
2017-12-30 12:34:52 +00:00
|
|
|
}
|