2019-01-20 23:00:26 +00:00
|
|
|
; Prog8 internal library routines - always included by the compiler
|
2020-08-25 17:44:08 +00:00
|
|
|
; Generic machine independent 6502 code.
|
2019-01-20 23:00:26 +00:00
|
|
|
;
|
|
|
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
|
|
|
;
|
|
|
|
; indent format: TABS, size=8
|
|
|
|
|
|
|
|
|
2020-08-20 16:07:48 +00:00
|
|
|
read_byte_from_address_on_stack .proc
|
2019-07-28 21:37:33 +00:00
|
|
|
; -- read the byte from the memory address on the top of the stack, return in A (stack remains unchanged)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ldy P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
2020-08-20 22:17:28 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W2),y
|
2020-08-20 22:17:28 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
write_byte_to_address_on_stack .proc
|
|
|
|
; -- write the byte in A to the memory address on the top of the stack (stack remains unchanged)
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
|
|
|
sty P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ESTACK_HI+1,x
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
2020-08-20 22:17:28 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2019-07-28 21:37:33 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-08-11 14:01:37 +00:00
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
|
|
|
|
add_a_to_zpword .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
; -- add ubyte in A to the uword in P8ZP_SCRATCH_W1
|
2019-01-20 23:00:26 +00:00
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ZP_SCRATCH_W1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc +
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1
|
2019-01-20 23:00:26 +00:00
|
|
|
+ rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
pop_index_times_5 .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
neg_b .proc
|
2019-01-30 22:43:21 +00:00
|
|
|
lda #0
|
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
neg_w .proc
|
|
|
|
sec
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_HI+1,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
inv_word .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
eor #255
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
eor #255
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
not_byte .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
beq +
|
2019-01-30 22:43:21 +00:00
|
|
|
lda #1
|
|
|
|
+ eor #1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
not_word .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO + 1,x
|
|
|
|
ora P8ESTACK_HI + 1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
beq +
|
2019-01-30 22:43:21 +00:00
|
|
|
lda #1
|
|
|
|
+ eor #1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO + 1,x
|
2019-01-30 22:43:21 +00:00
|
|
|
lsr a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI + 1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:48:26 +00:00
|
|
|
bitand_b .proc
|
|
|
|
; -- bitwise and (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
and P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:48:26 +00:00
|
|
|
bitor_b .proc
|
|
|
|
; -- bitwise or (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:48:26 +00:00
|
|
|
bitxor_b .proc
|
|
|
|
; -- bitwise xor (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
eor P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:48:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
bitand_w .proc
|
|
|
|
; -- bitwise and (of 2 words)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
and P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+2,x
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
and P8ESTACK_HI+1,x
|
|
|
|
sta P8ESTACK_HI+2,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:48:26 +00:00
|
|
|
bitor_w .proc
|
|
|
|
; -- bitwise or (of 2 words)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+2,x
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
ora P8ESTACK_HI+1,x
|
|
|
|
sta P8ESTACK_HI+2,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:48:26 +00:00
|
|
|
bitxor_w .proc
|
|
|
|
; -- bitwise xor (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
eor P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+2,x
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
eor P8ESTACK_HI+1,x
|
|
|
|
sta P8ESTACK_HI+2,x
|
2019-02-23 21:48:26 +00:00
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:13:12 +00:00
|
|
|
and_b .proc
|
|
|
|
; -- logical and (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta P8ZP_SCRATCH_B1
|
|
|
|
lda P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ and P8ZP_SCRATCH_B1
|
2019-02-23 21:13:12 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:13:12 +00:00
|
|
|
or_b .proc
|
|
|
|
; -- logical or (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
|
|
|
+ inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:13:12 +00:00
|
|
|
xor_b .proc
|
|
|
|
; -- logical xor (of 2 bytes)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta P8ZP_SCRATCH_B1
|
|
|
|
lda P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ eor P8ZP_SCRATCH_B1
|
2019-02-23 21:13:12 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
and_w .proc
|
|
|
|
; -- logical and (word and word -> byte)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_HI+2,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta P8ZP_SCRATCH_B1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ora P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ and P8ZP_SCRATCH_B1
|
2019-02-23 21:13:12 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:13:12 +00:00
|
|
|
or_w .proc
|
|
|
|
; -- logical or (word or word -> byte)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_LO+1,x
|
|
|
|
ora P8ESTACK_HI+2,x
|
|
|
|
ora P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
|
|
|
+ inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2019-02-23 21:13:12 +00:00
|
|
|
xor_w .proc
|
|
|
|
; -- logical xor (word xor word -> byte)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
ora P8ESTACK_HI+2,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta P8ZP_SCRATCH_B1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ora P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
beq +
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
+ eor P8ZP_SCRATCH_B1
|
2019-02-23 21:13:12 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-02-23 21:13:12 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
|
|
|
|
abs_b .proc
|
|
|
|
; -- push abs(byte) on stack (as byte)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bmi neg_b
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
abs_w .proc
|
|
|
|
; -- push abs(word) on stack (as word)
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bmi neg_w
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
add_w .proc
|
|
|
|
; -- push word+word / uword+uword
|
|
|
|
inx
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
adc P8ESTACK_LO+1,x
|
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
adc P8ESTACK_HI+1,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
sub_w .proc
|
|
|
|
; -- push word-word
|
|
|
|
inx
|
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sbc P8ESTACK_LO,x
|
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sbc P8ESTACK_HI,x
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_byte .proc
|
|
|
|
; -- b*b->b (signed and unsigned)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
jsr math.multiply_bytes
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
mul_word .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ldy P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
jsr math.multiply_words
|
2019-03-31 16:04:19 +00:00
|
|
|
lda math.multiply_words.result
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-03-31 16:04:19 +00:00
|
|
|
lda math.multiply_words.result+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
idiv_b .proc
|
|
|
|
; signed division: use unsigned division and fix sign of result afterwards
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
eor P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
php ; save sign of result
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bpl +
|
|
|
|
eor #$ff
|
|
|
|
sec
|
|
|
|
adc #0 ; make num1 positive
|
|
|
|
+ tay
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bpl +
|
|
|
|
eor #$ff
|
|
|
|
sec
|
|
|
|
adc #0 ; make num2 positive
|
2020-08-27 18:47:22 +00:00
|
|
|
+ jsr math.divmod_ub_asm
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _remainder
|
|
|
|
tya
|
|
|
|
plp ; get sign of result
|
|
|
|
bpl +
|
|
|
|
eor #$ff
|
|
|
|
sec
|
|
|
|
adc #0 ; negate result
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_remainder .byte 0
|
|
|
|
.pend
|
|
|
|
|
|
|
|
idiv_ub .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
|
|
|
lda P8ESTACK_LO+1,x
|
2020-08-27 18:47:22 +00:00
|
|
|
jsr math.divmod_ub_asm
|
2019-01-20 23:00:26 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
idiv_w .proc
|
|
|
|
; signed division: use unsigned division and fix sign of result afterwards
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
eor P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
php ; save sign of result
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bpl +
|
|
|
|
jsr neg_w ; make value positive
|
|
|
|
+ inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bpl +
|
|
|
|
jsr neg_w ; make value positive
|
2020-08-25 17:44:08 +00:00
|
|
|
+ lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
jsr math.divmod_uw_asm
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
plp
|
|
|
|
bpl +
|
|
|
|
jmp neg_w ; negate result
|
|
|
|
+ rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
idiv_uw .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
jsr math.divmod_uw_asm
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
remainder_ub .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x ; right operand
|
|
|
|
lda P8ESTACK_LO+1,x ; left operand
|
2020-08-27 18:47:22 +00:00
|
|
|
jsr math.divmod_ub_asm
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
remainder_uw .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
jsr math.divmod_uw_asm
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W2
|
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
lda P8ZP_SCRATCH_W2+1
|
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
equal_w .proc
|
|
|
|
; -- are the two words on the stack identical?
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bne equal_b._equal_b_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
cmp P8ESTACK_HI+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bne equal_b._equal_b_false
|
|
|
|
beq equal_b._equal_b_true
|
|
|
|
.pend
|
|
|
|
|
|
|
|
notequal_b .proc
|
|
|
|
; -- are the two bytes on the stack different?
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2019-01-30 22:43:21 +00:00
|
|
|
beq equal_b._equal_b_false
|
|
|
|
bne equal_b._equal_b_true
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
notequal_w .proc
|
|
|
|
; -- are the two words on the stack different?
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
cmp P8ESTACK_HI+2,x
|
2019-01-30 22:43:21 +00:00
|
|
|
beq notequal_b
|
|
|
|
bne equal_b._equal_b_true
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
less_ub .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
less_b .proc
|
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
less_uw .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
cmp P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bne equal_b._equal_b_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
less_w .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
sbc P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
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?
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bne _equal_b_false
|
|
|
|
_equal_b_true lda #1
|
|
|
|
_equal_b_store inx
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
_equal_b_false lda #0
|
|
|
|
beq _equal_b_store
|
|
|
|
.pend
|
|
|
|
|
|
|
|
lesseq_ub .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2019-01-30 22:43:21 +00:00
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
lesseq_b .proc
|
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
lesseq_uw .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
cmp P8ESTACK_HI+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
bne equal_b._equal_b_true
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
lesseq_w .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sbc P8ESTACK_HI+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_ub .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
beq equal_b._equal_b_false
|
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_b .proc
|
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_uw .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
cmp P8ESTACK_HI+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bne equal_b._equal_b_false
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_true
|
|
|
|
bcs equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greater_w .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
cmp P8ESTACK_LO+2,x
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sbc P8ESTACK_HI+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi equal_b._equal_b_true
|
|
|
|
bpl equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greatereq_ub .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greatereq_b .proc
|
|
|
|
; see http://www.6502.org/tutorials/compare_beyond.html
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
2019-01-20 23:00:26 +00:00
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greatereq_uw .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
cmp P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
bne equal_b._equal_b_true
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bcs equal_b._equal_b_true
|
|
|
|
bcc equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
|
|
|
greatereq_w .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
cmp P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
sbc P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl equal_b._equal_b_true
|
|
|
|
bmi equal_b._equal_b_false
|
|
|
|
.pend
|
|
|
|
|
2020-03-13 01:05:15 +00:00
|
|
|
|
2020-08-22 13:09:54 +00:00
|
|
|
shiftleft_b .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-08-22 13:09:54 +00:00
|
|
|
bne +
|
|
|
|
rts
|
2020-08-25 17:44:08 +00:00
|
|
|
+ lda P8ESTACK_LO+1,x
|
2020-08-22 13:09:54 +00:00
|
|
|
- asl a
|
|
|
|
dey
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2020-08-22 13:09:54 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
shiftright_b .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-08-22 13:09:54 +00:00
|
|
|
bne +
|
|
|
|
rts
|
2020-08-25 17:44:08 +00:00
|
|
|
+ lda P8ESTACK_LO+1,x
|
2020-08-22 13:09:54 +00:00
|
|
|
- lsr a
|
|
|
|
dey
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2020-08-22 13:09:54 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-03-13 01:05:15 +00:00
|
|
|
orig_stackpointer .byte 0 ; stores the Stack pointer register at program start
|
|
|
|
|
|
|
|
func_exit .proc
|
|
|
|
; -- immediately exit the program with a return code in the A register
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
2020-03-13 01:05:15 +00:00
|
|
|
ldx orig_stackpointer
|
|
|
|
txs
|
|
|
|
rts ; return to original caller
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2019-03-05 22:10:00 +00:00
|
|
|
func_read_flags .proc
|
|
|
|
; -- put the processor status register on the stack
|
|
|
|
php
|
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-03-05 22:10:00 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
|
|
|
|
2019-03-16 18:25:47 +00:00
|
|
|
func_sqrt16 .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
2020-09-13 18:25:30 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2019-03-16 18:25:47 +00:00
|
|
|
ldy #$00 ; r = 0
|
|
|
|
ldx #$07
|
|
|
|
clc ; clear bit 16 of m
|
|
|
|
_loop
|
|
|
|
tya
|
|
|
|
ora _stab-1,x
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1 ; (r asl 8) | (d asl 7)
|
|
|
|
lda P8ZP_SCRATCH_W2+1
|
2019-03-16 18:25:47 +00:00
|
|
|
bcs _skip0 ; m >= 65536? then t <= m is always true
|
2020-08-25 17:44:08 +00:00
|
|
|
cmp P8ZP_SCRATCH_B1
|
2019-03-16 18:25:47 +00:00
|
|
|
bcc _skip1 ; t <= m
|
|
|
|
_skip0
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ZP_SCRATCH_B1
|
|
|
|
sta P8ZP_SCRATCH_W2+1 ; m = m - t
|
2019-03-16 18:25:47 +00:00
|
|
|
tya
|
|
|
|
ora _stab,x
|
|
|
|
tay ; r = r or d
|
|
|
|
_skip1
|
2020-08-25 17:44:08 +00:00
|
|
|
asl P8ZP_SCRATCH_W2
|
|
|
|
rol P8ZP_SCRATCH_W2+1 ; m = m asl 1
|
2019-03-16 18:25:47 +00:00
|
|
|
dex
|
|
|
|
bne _loop
|
2019-01-20 23:00:26 +00:00
|
|
|
|
2019-03-16 18:25:47 +00:00
|
|
|
; last iteration
|
|
|
|
bcs _skip2
|
2020-08-25 17:44:08 +00:00
|
|
|
sty P8ZP_SCRATCH_B1
|
|
|
|
lda P8ZP_SCRATCH_W2
|
2019-03-16 18:25:47 +00:00
|
|
|
cmp #$80
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W2+1
|
|
|
|
sbc P8ZP_SCRATCH_B1
|
2019-03-16 18:25:47 +00:00
|
|
|
bcc _skip3
|
|
|
|
_skip2
|
|
|
|
iny ; r = r or d (d is 1 here)
|
|
|
|
_skip3
|
2020-09-13 18:25:30 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2019-03-16 18:25:47 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-03-16 18:25:47 +00:00
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-03-16 18:25:47 +00:00
|
|
|
rts
|
|
|
|
_stab .byte $01,$02,$04,$08,$10,$20,$40,$80
|
|
|
|
.pend
|
2019-03-31 16:04:19 +00:00
|
|
|
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
func_sin8 .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
2019-11-27 21:36:59 +00:00
|
|
|
_sinecos8 .char trunc(127.0 * sin(range(256+64) * rad(360.0/256.0)))
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sin8u .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8u,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
2019-11-27 21:36:59 +00:00
|
|
|
_sinecos8u .byte trunc(128.0 + 127.5 * sin(range(256+64) * rad(360.0/256.0)))
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sin16 .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8lo,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8hi,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
|
2019-11-27 21:36:59 +00:00
|
|
|
_ := trunc(32767.0 * sin(range(256+64) * rad(360.0/256.0)))
|
2019-01-20 23:00:26 +00:00
|
|
|
_sinecos8lo .byte <_
|
|
|
|
_sinecos8hi .byte >_
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sin16u .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8ulo,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _sinecos8uhi,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
|
2019-11-27 21:36:59 +00:00
|
|
|
_ := trunc(32768.0 + 32767.5 * sin(range(256+64) * rad(360.0/256.0)))
|
2019-01-20 23:00:26 +00:00
|
|
|
_sinecos8ulo .byte <_
|
|
|
|
_sinecos8uhi .byte >_
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_cos8 .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin8._sinecos8+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_cos8u .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin8u._sinecos8u+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_cos16 .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin16._sinecos8lo+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin16._sinecos8hi+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_cos16u .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin16u._sinecos8ulo+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda func_sin16u._sinecos8uhi+64,y
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
peek_address .proc
|
2020-08-25 17:44:08 +00:00
|
|
|
; -- peek address on stack into P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_any_b .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x ; array size
|
2019-01-20 23:00:26 +00:00
|
|
|
_entry sta _cmp_mod+1 ; self-modifying code
|
|
|
|
jsr peek_address
|
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
bne _got_any
|
|
|
|
iny
|
|
|
|
_cmp_mod cpy #255 ; modified
|
|
|
|
bne -
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
_got_any lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_any_w .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x ; array size
|
2019-01-20 23:00:26 +00:00
|
|
|
asl a ; times 2 because of word
|
|
|
|
jmp func_any_b._entry
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_all_b .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x ; array size
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _cmp_mod+1 ; self-modifying code
|
|
|
|
jsr peek_address
|
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
beq _got_not_all
|
|
|
|
iny
|
|
|
|
_cmp_mod cpy #255 ; modified
|
|
|
|
bne -
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
_got_not_all lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_all_w .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x ; array size
|
2019-01-20 23:00:26 +00:00
|
|
|
asl a ; times 2 because of word
|
|
|
|
sta _cmp_mod+1 ; self-modifying code
|
|
|
|
jsr peek_address
|
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
bne +
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-11 14:01:37 +00:00
|
|
|
bne ++
|
2019-01-20 23:00:26 +00:00
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
+ iny
|
2019-08-11 14:01:37 +00:00
|
|
|
+ iny
|
2019-01-20 23:00:26 +00:00
|
|
|
_cmp_mod cpy #255 ; modified
|
|
|
|
bne -
|
|
|
|
lda #1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO+1,x
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_max_ub .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc +
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
+ dey
|
|
|
|
cpy #255
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_max_b .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #-128
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi +
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
+ dey
|
|
|
|
cpy #255
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_max_uw .proc
|
|
|
|
lda #0
|
|
|
|
sta _result_maxuw
|
|
|
|
sta _result_maxuw+1
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
_loop
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
cmp _result_maxuw+1
|
|
|
|
bcc _lesseq
|
|
|
|
bne _greater
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
cmp _result_maxuw
|
|
|
|
bcc _lesseq
|
2020-08-25 17:44:08 +00:00
|
|
|
_greater lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_maxuw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_maxuw+1
|
|
|
|
dey
|
|
|
|
_lesseq dey
|
|
|
|
dey
|
|
|
|
cpy #254
|
|
|
|
bne _loop
|
|
|
|
lda _result_maxuw
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _result_maxuw+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_result_maxuw .word 0
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_max_w .proc
|
2020-08-28 19:42:53 +00:00
|
|
|
lda #0
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_maxw
|
|
|
|
lda #$80
|
|
|
|
sta _result_maxw+1
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
_loop
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
cmp _result_maxw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
sbc _result_maxw+1
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi _lesseq
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_maxw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_maxw+1
|
|
|
|
dey
|
|
|
|
_lesseq dey
|
|
|
|
dey
|
|
|
|
cpy #254
|
|
|
|
bne _loop
|
|
|
|
lda _result_maxw
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _result_maxw+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_result_maxw .word 0
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
func_sum_b .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
|
|
|
sta P8ESTACK_HI,x
|
|
|
|
_loop lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
pha
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ESTACK_LO,x
|
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
; sign extend the high byte
|
|
|
|
pla
|
|
|
|
and #$80
|
|
|
|
beq +
|
|
|
|
lda #$ff
|
2020-08-25 17:44:08 +00:00
|
|
|
+ adc P8ESTACK_HI,x
|
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
cpy #255
|
|
|
|
bne _loop
|
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sum_ub .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-30 22:43:21 +00:00
|
|
|
- clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
bcc +
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
+ dey
|
|
|
|
cpy #255
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sum_uw .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
|
|
|
sta P8ESTACK_HI,x
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
iny
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ESTACK_LO,x
|
|
|
|
sta P8ESTACK_LO,x
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
adc P8ESTACK_HI,x
|
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
cpy #254
|
|
|
|
bne -
|
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_sum_w .proc
|
|
|
|
jmp func_sum_uw
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
pop_array_and_lengthmin1Y .proc
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dey ; length minus 1, for iteration
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2019-01-20 23:00:26 +00:00
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_min_ub .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #255
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
bcs +
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
+ dey
|
|
|
|
cpy #255
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
func_min_b .proc
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
lda #127
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl +
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_B1
|
2019-01-20 23:00:26 +00:00
|
|
|
+ dey
|
|
|
|
cpy #255
|
|
|
|
bne -
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_B1
|
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_min_uw .proc
|
|
|
|
lda #$ff
|
|
|
|
sta _result_minuw
|
|
|
|
sta _result_minuw+1
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
_loop
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
cmp _result_minuw+1
|
|
|
|
bcc _less
|
|
|
|
bne _gtequ
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
cmp _result_minuw
|
|
|
|
bcs _gtequ
|
2020-08-25 17:44:08 +00:00
|
|
|
_less lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_minuw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_minuw+1
|
|
|
|
dey
|
|
|
|
_gtequ dey
|
|
|
|
dey
|
|
|
|
cpy #254
|
|
|
|
bne _loop
|
|
|
|
lda _result_minuw
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _result_minuw+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_result_minuw .word 0
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_min_w .proc
|
|
|
|
lda #$ff
|
|
|
|
sta _result_minw
|
|
|
|
lda #$7f
|
|
|
|
sta _result_minw+1
|
|
|
|
jsr pop_array_and_lengthmin1Y
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
_loop
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
cmp _result_minw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
dey
|
|
|
|
sbc _result_minw+1
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bpl _gtequ
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_minw
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
sta _result_minw+1
|
|
|
|
dey
|
|
|
|
_gtequ dey
|
|
|
|
dey
|
|
|
|
cpy #254
|
|
|
|
bne _loop
|
|
|
|
lda _result_minw
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
lda _result_minw+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
_result_minw .word 0
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_rnd .proc
|
|
|
|
; -- put a random ubyte on the estack
|
|
|
|
jsr math.randbyte
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_rndw .proc
|
|
|
|
; -- put a random uword on the estack
|
|
|
|
jsr math.randword
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
tya
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ESTACK_HI,x
|
2019-01-20 23:00:26 +00:00
|
|
|
dex
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2019-03-31 16:04:19 +00:00
|
|
|
func_memcopy .proc
|
2019-01-20 23:00:26 +00:00
|
|
|
; note: clobbers A,Y
|
|
|
|
inx
|
2020-09-13 18:25:30 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
|
|
|
lda P8ESTACK_LO,x
|
2019-01-20 23:00:26 +00:00
|
|
|
tax
|
2019-01-22 23:19:29 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1), y
|
|
|
|
sta (P8ZP_SCRATCH_W2), y
|
2019-01-22 23:19:29 +00:00
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
2020-09-13 18:25:30 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2019-01-22 23:19:29 +00:00
|
|
|
inx
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-03-31 16:04:19 +00:00
|
|
|
func_memset .proc
|
2019-01-22 23:19:29 +00:00
|
|
|
; note: clobbers A,Y
|
|
|
|
inx
|
2020-09-13 18:25:30 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
ldy P8ESTACK_HI+1,x
|
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldx P8ZP_SCRATCH_B1
|
2019-01-22 23:19:29 +00:00
|
|
|
jsr memset
|
2020-09-13 18:25:30 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2019-01-22 23:19:29 +00:00
|
|
|
inx
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-03-31 16:04:19 +00:00
|
|
|
func_memsetw .proc
|
2019-01-22 23:19:29 +00:00
|
|
|
; note: clobbers A,Y
|
|
|
|
; -- fill memory from (SCRATCH_ZPWORD1) number of words in SCRATCH_ZPWORD2, with word value in AY.
|
|
|
|
|
|
|
|
inx
|
2020-09-13 18:25:30 +00:00
|
|
|
stx P8ZP_SCRATCH_REG
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+2,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
lda P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
ldy P8ESTACK_HI,x
|
2019-01-22 23:19:29 +00:00
|
|
|
jsr memsetw
|
2020-09-13 18:25:30 +00:00
|
|
|
ldx P8ZP_SCRATCH_REG
|
2019-01-20 23:00:26 +00:00
|
|
|
inx
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
2019-01-22 23:19:29 +00:00
|
|
|
|
2020-08-25 15:22:51 +00:00
|
|
|
strlen .proc
|
|
|
|
; -- put length of 0-terminated string in A/Y into A
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-08-25 15:22:51 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2020-08-25 15:22:51 +00:00
|
|
|
beq +
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ tya
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-22 23:19:29 +00:00
|
|
|
|
|
|
|
memcopy16_up .proc
|
|
|
|
; -- copy memory UP from (SCRATCH_ZPWORD1) to (SCRATCH_ZPWORD2) of length X/Y (16-bit, X=lo, Y=hi)
|
|
|
|
; clobbers register A,X,Y
|
2020-08-25 17:44:08 +00:00
|
|
|
source = P8ZP_SCRATCH_W1
|
|
|
|
dest = P8ZP_SCRATCH_W2
|
|
|
|
length = P8ZP_SCRATCH_B1 ; (and SCRATCH_ZPREG)
|
2019-01-22 23:19:29 +00:00
|
|
|
|
|
|
|
stx length
|
|
|
|
sty length+1
|
|
|
|
|
|
|
|
ldx length ; move low byte of length into X
|
|
|
|
bne + ; jump to start if X > 0
|
|
|
|
dec length ; subtract 1 from length
|
|
|
|
+ ldy #0 ; set Y to 0
|
|
|
|
- lda (source),y ; set A to whatever (source) points to offset by Y
|
|
|
|
sta (dest),y ; move A to location pointed to by (dest) offset by Y
|
|
|
|
iny ; increment Y
|
|
|
|
bne + ; if Y<>0 then (rolled over) then still moving bytes
|
|
|
|
inc source+1 ; increment hi byte of source
|
|
|
|
inc dest+1 ; increment hi byte of dest
|
|
|
|
+ dex ; decrement X (lo byte counter)
|
|
|
|
bne - ; if X<>0 then move another byte
|
|
|
|
dec length ; we've moved 255 bytes, dec length
|
|
|
|
bpl - ; if length is still positive go back and move more
|
|
|
|
rts ; done
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
memset .proc
|
|
|
|
; -- fill memory from (SCRATCH_ZPWORD1), length XY, with value in A.
|
|
|
|
; clobbers X, Y
|
2020-08-25 17:44:08 +00:00
|
|
|
stx P8ZP_SCRATCH_B1
|
2020-09-13 18:25:30 +00:00
|
|
|
sty _save_reg
|
2019-01-22 23:19:29 +00:00
|
|
|
ldy #0
|
2020-09-13 18:25:30 +00:00
|
|
|
ldx _save_reg
|
2019-01-22 23:19:29 +00:00
|
|
|
beq _lastpage
|
|
|
|
|
2020-08-25 17:44:08 +00:00
|
|
|
_fullpage sta (P8ZP_SCRATCH_W1),y
|
2019-01-22 23:19:29 +00:00
|
|
|
iny
|
|
|
|
bne _fullpage
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1 ; next page
|
2019-01-22 23:19:29 +00:00
|
|
|
dex
|
|
|
|
bne _fullpage
|
|
|
|
|
2020-08-25 17:44:08 +00:00
|
|
|
_lastpage ldy P8ZP_SCRATCH_B1
|
2019-01-22 23:19:29 +00:00
|
|
|
beq +
|
|
|
|
- dey
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-01-22 23:19:29 +00:00
|
|
|
bne -
|
|
|
|
|
|
|
|
+ rts
|
2020-09-13 18:25:30 +00:00
|
|
|
_save_reg .byte 0
|
2019-01-22 23:19:29 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
memsetw .proc
|
|
|
|
; -- fill memory from (SCRATCH_ZPWORD1) number of words in SCRATCH_ZPWORD2, with word value in AY.
|
|
|
|
; clobbers A, X, Y
|
|
|
|
sta _mod1+1 ; self-modify
|
|
|
|
sty _mod1b+1 ; self-modify
|
|
|
|
sta _mod2+1 ; self-modify
|
|
|
|
sty _mod2b+1 ; self-modify
|
2020-08-25 17:44:08 +00:00
|
|
|
ldx P8ZP_SCRATCH_W1
|
|
|
|
stx P8ZP_SCRATCH_B1
|
|
|
|
ldx P8ZP_SCRATCH_W1+1
|
2019-01-22 23:19:29 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
stx P8ZP_SCRATCH_REG ; second page
|
2019-01-22 23:19:29 +00:00
|
|
|
|
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
ldx P8ZP_SCRATCH_W2+1
|
2019-01-22 23:19:29 +00:00
|
|
|
beq _lastpage
|
|
|
|
|
|
|
|
_fullpage
|
|
|
|
_mod1 lda #0 ; self-modified
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ; first page
|
|
|
|
sta (P8ZP_SCRATCH_B1),y ; second page
|
2019-01-22 23:19:29 +00:00
|
|
|
iny
|
|
|
|
_mod1b lda #0 ; self-modified
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ; first page
|
|
|
|
sta (P8ZP_SCRATCH_B1),y ; second page
|
2019-01-22 23:19:29 +00:00
|
|
|
iny
|
|
|
|
bne _fullpage
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1 ; next page pair
|
|
|
|
inc P8ZP_SCRATCH_W1+1 ; next page pair
|
|
|
|
inc P8ZP_SCRATCH_B1+1 ; next page pair
|
|
|
|
inc P8ZP_SCRATCH_B1+1 ; next page pair
|
2019-01-22 23:19:29 +00:00
|
|
|
dex
|
|
|
|
bne _fullpage
|
|
|
|
|
2020-08-25 17:44:08 +00:00
|
|
|
_lastpage ldx P8ZP_SCRATCH_W2
|
2019-01-22 23:19:29 +00:00
|
|
|
beq _done
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
-
|
|
|
|
_mod2 lda #0 ; self-modified
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1), y
|
|
|
|
inc P8ZP_SCRATCH_W1
|
2019-01-22 23:19:29 +00:00
|
|
|
bne _mod2b
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1
|
2019-01-22 23:19:29 +00:00
|
|
|
_mod2b lda #0 ; self-modified
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1), y
|
|
|
|
inc P8ZP_SCRATCH_W1
|
2019-01-22 23:19:29 +00:00
|
|
|
bne +
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1
|
2019-01-22 23:19:29 +00:00
|
|
|
+ dex
|
|
|
|
bne -
|
|
|
|
_done rts
|
|
|
|
.pend
|
|
|
|
|
2019-08-17 21:32:26 +00:00
|
|
|
|
|
|
|
sort_ub .proc
|
|
|
|
; 8bit unsigned sort
|
|
|
|
; sorting subroutine coded by mats rosengren (mats.rosengren@esa.int)
|
2020-08-25 17:44:08 +00:00
|
|
|
; input: address of array to sort in P8ZP_SCRATCH_W1, length in P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
; first, put pointer BEFORE array
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
bne +
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_W1+1
|
|
|
|
+ dec P8ZP_SCRATCH_W1
|
|
|
|
_sortloop ldy P8ZP_SCRATCH_B1 ;start of subroutine sort
|
|
|
|
lda (P8ZP_SCRATCH_W1),y ;last value in (what is left of) sequence to be sorted
|
|
|
|
sta P8ZP_SCRATCH_REG ;save value. will be over-written by largest number
|
2019-08-17 21:32:26 +00:00
|
|
|
jmp _l2
|
|
|
|
_l1 dey
|
|
|
|
beq _l3
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_W2+1
|
2019-08-17 21:32:26 +00:00
|
|
|
bcc _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l2 sty P8ZP_SCRATCH_W2 ;index of potentially largest value
|
|
|
|
sta P8ZP_SCRATCH_W2+1 ;potentially largest value
|
2019-08-17 21:32:26 +00:00
|
|
|
jmp _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l3 ldy P8ZP_SCRATCH_B1 ;where the largest value shall be put
|
|
|
|
lda P8ZP_SCRATCH_W2+1 ;the largest value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put largest value in place
|
|
|
|
ldy P8ZP_SCRATCH_W2 ;index of free space
|
|
|
|
lda P8ZP_SCRATCH_REG ;the over-written value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put the over-written value in the free space
|
|
|
|
dec P8ZP_SCRATCH_B1 ;end of the shorter sequence still left
|
2019-08-17 21:32:26 +00:00
|
|
|
bne _sortloop ;start working with the shorter sequence
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-10-13 05:35:51 +00:00
|
|
|
|
2019-08-17 21:32:26 +00:00
|
|
|
sort_b .proc
|
|
|
|
; 8bit signed sort
|
|
|
|
; sorting subroutine coded by mats rosengren (mats.rosengren@esa.int)
|
2020-08-25 17:44:08 +00:00
|
|
|
; input: address of array to sort in P8ZP_SCRATCH_W1, length in P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
; first, put pointer BEFORE array
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
bne +
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_W1+1
|
|
|
|
+ dec P8ZP_SCRATCH_W1
|
|
|
|
_sortloop ldy P8ZP_SCRATCH_B1 ;start of subroutine sort
|
|
|
|
lda (P8ZP_SCRATCH_W1),y ;last value in (what is left of) sequence to be sorted
|
|
|
|
sta P8ZP_SCRATCH_REG ;save value. will be over-written by largest number
|
2019-08-17 21:32:26 +00:00
|
|
|
jmp _l2
|
|
|
|
_l1 dey
|
|
|
|
beq _l3
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_W2+1
|
2019-08-17 21:32:26 +00:00
|
|
|
bmi _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l2 sty P8ZP_SCRATCH_W2 ;index of potentially largest value
|
|
|
|
sta P8ZP_SCRATCH_W2+1 ;potentially largest value
|
2019-08-17 21:32:26 +00:00
|
|
|
jmp _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l3 ldy P8ZP_SCRATCH_B1 ;where the largest value shall be put
|
|
|
|
lda P8ZP_SCRATCH_W2+1 ;the largest value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put largest value in place
|
|
|
|
ldy P8ZP_SCRATCH_W2 ;index of free space
|
|
|
|
lda P8ZP_SCRATCH_REG ;the over-written value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put the over-written value in the free space
|
|
|
|
dec P8ZP_SCRATCH_B1 ;end of the shorter sequence still left
|
2019-08-17 21:32:26 +00:00
|
|
|
bne _sortloop ;start working with the shorter sequence
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
sort_uw .proc
|
|
|
|
; 16bit unsigned sort
|
|
|
|
; sorting subroutine coded by mats rosengren (mats.rosengren@esa.int)
|
2020-08-25 17:44:08 +00:00
|
|
|
; input: address of array to sort in P8ZP_SCRATCH_W1, length in P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
; first: subtract 2 of the pointer
|
2020-08-25 17:44:08 +00:00
|
|
|
asl P8ZP_SCRATCH_B1 ; *2 because words
|
|
|
|
lda P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
sec
|
|
|
|
sbc #2
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
bcs _sort_loop
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_W1+1
|
|
|
|
_sort_loop ldy P8ZP_SCRATCH_B1 ;start of subroutine sort
|
|
|
|
lda (P8ZP_SCRATCH_W1),y ;last value in (what is left of) sequence to be sorted
|
2019-08-17 21:32:26 +00:00
|
|
|
sta _work3 ;save value. will be over-written by largest number
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
sta _work3+1
|
|
|
|
dey
|
|
|
|
jmp _l2
|
2019-10-13 05:35:51 +00:00
|
|
|
_l1 dey
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
|
|
|
beq _l3
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
cmp P8ZP_SCRATCH_W2+1
|
2019-08-17 21:32:26 +00:00
|
|
|
bne +
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_W2
|
2019-08-17 21:32:26 +00:00
|
|
|
+ bcc _l1
|
|
|
|
_l2 sty _work1 ;index of potentially largest value
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_W2 ;potentially largest value
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
|
|
|
jmp _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l3 ldy P8ZP_SCRATCH_B1 ;where the largest value shall be put
|
|
|
|
lda P8ZP_SCRATCH_W2 ;the largest value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put largest value in place
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W2+1
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
ldy _work1 ;index of free space
|
|
|
|
lda _work3 ;the over-written value
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put the over-written value in the free space
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
|
|
|
lda _work3+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_B1 ;end of the shorter sequence still left
|
|
|
|
dec P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
bne _sort_loop ;start working with the shorter sequence
|
2019-10-13 05:35:51 +00:00
|
|
|
rts
|
2019-08-17 21:32:26 +00:00
|
|
|
_work1 .byte 0
|
|
|
|
_work3 .word 0
|
|
|
|
.pend
|
|
|
|
|
2019-10-13 05:35:51 +00:00
|
|
|
|
2019-08-17 21:32:26 +00:00
|
|
|
sort_w .proc
|
|
|
|
; 16bit signed sort
|
|
|
|
; sorting subroutine coded by mats rosengren (mats.rosengren@esa.int)
|
2020-08-25 17:44:08 +00:00
|
|
|
; input: address of array to sort in P8ZP_SCRATCH_W1, length in P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
; first: subtract 2 of the pointer
|
2020-08-25 17:44:08 +00:00
|
|
|
asl P8ZP_SCRATCH_B1 ; *2 because words
|
|
|
|
lda P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
sec
|
|
|
|
sbc #2
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2019-08-17 21:32:26 +00:00
|
|
|
bcs _sort_loop
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_W1+1
|
|
|
|
_sort_loop ldy P8ZP_SCRATCH_B1 ;start of subroutine sort
|
|
|
|
lda (P8ZP_SCRATCH_W1),y ;last value in (what is left of) sequence to be sorted
|
2019-08-17 21:32:26 +00:00
|
|
|
sta _work3 ;save value. will be over-written by largest number
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
sta _work3+1
|
|
|
|
dey
|
|
|
|
jmp _l2
|
2019-10-13 05:35:51 +00:00
|
|
|
_l1 dey
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
|
|
|
beq _l3
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp P8ZP_SCRATCH_W2
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ZP_SCRATCH_W2+1
|
2019-08-17 23:39:48 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
2019-10-13 05:35:51 +00:00
|
|
|
+ bmi _l1
|
2019-08-17 21:32:26 +00:00
|
|
|
_l2 sty _work1 ;index of potentially largest value
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_W2 ;potentially largest value
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
|
|
|
jmp _l1
|
2020-08-25 17:44:08 +00:00
|
|
|
_l3 ldy P8ZP_SCRATCH_B1 ;where the largest value shall be put
|
|
|
|
lda P8ZP_SCRATCH_W2 ;the largest value
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put largest value in place
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W2+1
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
ldy _work1 ;index of free space
|
|
|
|
lda _work3 ;the over-written value
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ;put the over-written value in the free space
|
2019-08-17 21:32:26 +00:00
|
|
|
iny
|
|
|
|
lda _work3+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 21:32:26 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
dec P8ZP_SCRATCH_B1 ;end of the shorter sequence still left
|
|
|
|
dec P8ZP_SCRATCH_B1
|
2019-08-17 21:32:26 +00:00
|
|
|
bne _sort_loop ;start working with the shorter sequence
|
2019-10-13 05:35:51 +00:00
|
|
|
rts
|
2019-08-17 21:32:26 +00:00
|
|
|
_work1 .byte 0
|
|
|
|
_work3 .word 0
|
2019-10-13 05:35:51 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2019-08-17 23:39:48 +00:00
|
|
|
reverse_b .proc
|
|
|
|
; --- reverse an array of bytes (in-place)
|
2020-08-25 17:44:08 +00:00
|
|
|
; inputs: pointer to array in P8ZP_SCRATCH_W1, length in A
|
|
|
|
_index_right = P8ZP_SCRATCH_W2
|
|
|
|
_index_left = P8ZP_SCRATCH_W2+1
|
|
|
|
_loop_count = P8ZP_SCRATCH_REG
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _loop_count
|
|
|
|
lsr _loop_count
|
|
|
|
sec
|
|
|
|
sbc #1
|
|
|
|
sta _index_right
|
|
|
|
lda #0
|
|
|
|
sta _index_left
|
|
|
|
_loop ldy _index_right
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pha
|
|
|
|
ldy _index_left
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_right
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pla
|
|
|
|
ldy _index_left
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _index_left
|
|
|
|
dec _index_right
|
|
|
|
dec _loop_count
|
|
|
|
bne _loop
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
reverse_f .proc
|
|
|
|
; --- reverse an array of floats
|
2020-08-25 17:44:08 +00:00
|
|
|
_left_index = P8ZP_SCRATCH_W2
|
|
|
|
_right_index = P8ZP_SCRATCH_W2+1
|
|
|
|
_loop_count = P8ZP_SCRATCH_REG
|
2019-08-17 23:39:48 +00:00
|
|
|
pha
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_REG
|
2020-03-11 22:08:08 +00:00
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
adc P8ZP_SCRATCH_REG ; *5 because float
|
2019-08-17 23:39:48 +00:00
|
|
|
sec
|
2020-03-11 22:08:08 +00:00
|
|
|
sbc #5
|
2019-08-17 23:39:48 +00:00
|
|
|
sta _right_index
|
2020-03-11 22:08:08 +00:00
|
|
|
lda #0
|
|
|
|
sta _left_index
|
2019-08-17 23:39:48 +00:00
|
|
|
pla
|
|
|
|
lsr a
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _loop_count
|
|
|
|
_loop ; push the left indexed float on the stack
|
2019-08-17 23:39:48 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
pha
|
2020-03-11 22:08:08 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pha
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pha
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pha
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
pha
|
|
|
|
; copy right index float to left index float
|
2019-08-17 23:39:48 +00:00
|
|
|
ldy _right_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _left_index
|
|
|
|
inc _right_index
|
|
|
|
ldy _right_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _left_index
|
|
|
|
inc _right_index
|
|
|
|
ldy _right_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _left_index
|
|
|
|
inc _right_index
|
2019-08-17 23:39:48 +00:00
|
|
|
ldy _right_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _left_index
|
2019-08-17 23:39:48 +00:00
|
|
|
inc _right_index
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _right_index
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _left_index
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
; pop the float off the stack into the right index float
|
|
|
|
ldy _right_index
|
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
dey
|
2020-03-11 22:08:08 +00:00
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
dey
|
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
dey
|
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
dey
|
|
|
|
pla
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _left_index
|
|
|
|
lda _right_index
|
|
|
|
sec
|
|
|
|
sbc #9
|
|
|
|
sta _right_index
|
|
|
|
dec _loop_count
|
2019-08-17 23:39:48 +00:00
|
|
|
bne _loop
|
|
|
|
rts
|
2020-03-11 22:08:08 +00:00
|
|
|
|
2019-08-17 23:39:48 +00:00
|
|
|
.pend
|
|
|
|
|
2019-10-13 05:35:51 +00:00
|
|
|
|
2019-08-17 23:39:48 +00:00
|
|
|
reverse_w .proc
|
|
|
|
; --- reverse an array of words (in-place)
|
2020-08-25 17:44:08 +00:00
|
|
|
; inputs: pointer to array in P8ZP_SCRATCH_W1, length in A
|
|
|
|
_index_first = P8ZP_SCRATCH_W2
|
|
|
|
_index_second = P8ZP_SCRATCH_W2+1
|
|
|
|
_loop_count = P8ZP_SCRATCH_REG
|
2019-08-17 23:39:48 +00:00
|
|
|
pha
|
|
|
|
asl a ; *2 because words
|
|
|
|
sec
|
|
|
|
sbc #2
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _index_first
|
2019-08-17 23:39:48 +00:00
|
|
|
lda #0
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _index_second
|
2019-08-17 23:39:48 +00:00
|
|
|
pla
|
|
|
|
lsr a
|
|
|
|
pha
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _loop_count
|
2019-08-17 23:39:48 +00:00
|
|
|
; first reverse the lsbs
|
2020-03-11 22:08:08 +00:00
|
|
|
_loop_lo ldy _index_first
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
pha
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_second
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_first
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
pla
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_second
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
inc _index_second
|
|
|
|
inc _index_second
|
|
|
|
dec _index_first
|
|
|
|
dec _index_first
|
|
|
|
dec _loop_count
|
2019-08-17 23:39:48 +00:00
|
|
|
bne _loop_lo
|
|
|
|
; now reverse the msbs
|
2020-03-11 22:08:08 +00:00
|
|
|
dec _index_second
|
|
|
|
inc _index_first
|
|
|
|
inc _index_first
|
|
|
|
inc _index_first
|
2019-08-17 23:39:48 +00:00
|
|
|
pla
|
2020-03-11 22:08:08 +00:00
|
|
|
sta _loop_count
|
|
|
|
_loop_hi ldy _index_first
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
pha
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_second
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_first
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-17 23:39:48 +00:00
|
|
|
pla
|
2020-03-11 22:08:08 +00:00
|
|
|
ldy _index_second
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-03-11 22:08:08 +00:00
|
|
|
dec _index_second
|
|
|
|
dec _index_second
|
|
|
|
inc _index_first
|
|
|
|
inc _index_first
|
|
|
|
dec _loop_count
|
2019-08-17 23:39:48 +00:00
|
|
|
bne _loop_hi
|
|
|
|
|
2019-10-13 05:35:51 +00:00
|
|
|
rts
|
2019-08-17 23:39:48 +00:00
|
|
|
.pend
|
2019-08-23 19:32:21 +00:00
|
|
|
|
2019-08-23 21:06:36 +00:00
|
|
|
ror2_mem_ub .proc
|
2019-08-23 19:32:21 +00:00
|
|
|
; -- in-place 8-bit ror of byte at memory location on stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2019-08-23 21:06:36 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-23 19:32:21 +00:00
|
|
|
lsr a
|
2019-08-23 21:06:36 +00:00
|
|
|
bcc +
|
2019-08-23 19:32:21 +00:00
|
|
|
ora #$80
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta (P8ZP_SCRATCH_W1),y
|
2019-08-23 19:32:21 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-10-13 05:35:51 +00:00
|
|
|
|
2019-08-23 21:06:36 +00:00
|
|
|
rol2_mem_ub .proc
|
2019-08-23 19:32:21 +00:00
|
|
|
; -- in-place 8-bit rol of byte at memory location on stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2019-08-23 21:06:36 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2019-08-23 19:32:21 +00:00
|
|
|
cmp #$80
|
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-08-23 19:32:21 +00:00
|
|
|
rts
|
|
|
|
.pend
|
2019-10-13 05:35:51 +00:00
|
|
|
|
2020-04-03 19:31:17 +00:00
|
|
|
rol_array_ub .proc
|
|
|
|
; -- rol a ubyte in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-04-03 19:31:17 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-04-02 22:03:42 +00:00
|
|
|
ror_array_ub .proc
|
|
|
|
; -- ror a ubyte in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-04-02 22:03:42 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
ror a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:04:42 +00:00
|
|
|
ror2_array_ub .proc
|
|
|
|
; -- ror2 (8-bit ror) a ubyte in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-04-03 19:04:42 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
lsr a
|
|
|
|
bcc +
|
|
|
|
ora #$80
|
2020-08-25 17:44:08 +00:00
|
|
|
+ sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:17:52 +00:00
|
|
|
rol2_array_ub .proc
|
|
|
|
; -- rol2 (8-bit rol) a ubyte in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x
|
2020-04-03 19:17:52 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
cmp #$80
|
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-02 22:03:42 +00:00
|
|
|
ror_array_uw .proc
|
|
|
|
; -- ror a uword in an array (index and array address on stack)
|
|
|
|
php
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-04-02 22:03:42 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2020-04-02 22:03:42 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
plp
|
|
|
|
ror a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
ror a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-02 22:03:42 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:31:17 +00:00
|
|
|
rol_array_uw .proc
|
|
|
|
; -- rol a uword in an array (index and array address on stack)
|
|
|
|
php
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-04-03 19:31:17 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
plp
|
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:31:17 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:17:52 +00:00
|
|
|
rol2_array_uw .proc
|
|
|
|
; -- rol2 (16-bit rol) a uword in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-04-03 19:17:52 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
asl a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
rol a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
bcc +
|
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
adc #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:17:52 +00:00
|
|
|
+ rts
|
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:04:42 +00:00
|
|
|
ror2_array_uw .proc
|
|
|
|
; -- ror2 (16-bit ror) a uword in an array (index and array address on stack)
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-04-03 19:04:42 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2020-04-03 19:04:42 +00:00
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
lsr a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
dey
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
ror a
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
bcc +
|
|
|
|
iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
ora #$80
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-04-03 19:04:42 +00:00
|
|
|
+ rts
|
|
|
|
.pend
|
2020-06-05 21:19:06 +00:00
|
|
|
|
2020-08-20 16:07:48 +00:00
|
|
|
|
2020-06-05 21:19:06 +00:00
|
|
|
strcpy .proc
|
2020-10-04 15:47:57 +00:00
|
|
|
; copy a string (must be 0-terminated) from A/Y to (P8ZP_SCRATCH_W1)
|
2020-06-05 21:19:06 +00:00
|
|
|
; it is assumed the target string is large enough.
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
2020-06-05 21:19:06 +00:00
|
|
|
ldy #$ff
|
|
|
|
- iny
|
2020-08-25 17:44:08 +00:00
|
|
|
lda (P8ZP_SCRATCH_W2),y
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2020-06-05 21:19:06 +00:00
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
.pend
|
2020-08-20 16:07:48 +00:00
|
|
|
|
|
|
|
|
2020-06-05 21:19:06 +00:00
|
|
|
func_leftstr .proc
|
|
|
|
; leftstr(source, target, length) with params on stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
2020-06-05 21:19:06 +00:00
|
|
|
tay ; length
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
2020-06-05 21:19:06 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2020-06-05 21:19:06 +00:00
|
|
|
lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2020-06-05 21:19:06 +00:00
|
|
|
- dey
|
|
|
|
cpy #$ff
|
|
|
|
bne +
|
|
|
|
rts
|
2020-08-25 17:44:08 +00:00
|
|
|
+ lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2020-06-05 21:19:06 +00:00
|
|
|
jmp -
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_rightstr .proc
|
|
|
|
; rightstr(source, target, length) with params on stack
|
|
|
|
; make place for the 4 parameters for substr()
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
; X-> .
|
|
|
|
; x+1 -> length of segment
|
|
|
|
; x+2 -> start index
|
|
|
|
; X+3 -> target LO+HI
|
|
|
|
; X+4 -> source LO+HI
|
|
|
|
; original parameters:
|
|
|
|
; x+5 -> original length LO
|
|
|
|
; x+6 -> original targetLO + HI
|
|
|
|
; x+7 -> original sourceLO + HI
|
|
|
|
; replicate paramters:
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO+5,x
|
|
|
|
sta P8ESTACK_LO+1,x
|
|
|
|
lda P8ESTACK_LO+6,x
|
|
|
|
sta P8ESTACK_LO+3,x
|
|
|
|
lda P8ESTACK_HI+6,x
|
|
|
|
sta P8ESTACK_HI+3,x
|
|
|
|
lda P8ESTACK_LO+7,x
|
|
|
|
sta P8ESTACK_LO+4,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI+7,x
|
|
|
|
sta P8ESTACK_HI+4,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2020-06-05 21:19:06 +00:00
|
|
|
; determine string length
|
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
2020-06-05 21:19:06 +00:00
|
|
|
beq +
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ tya
|
|
|
|
sec
|
2020-08-25 17:44:08 +00:00
|
|
|
sbc P8ESTACK_LO+1,x ; start index = strlen - segment length
|
|
|
|
sta P8ESTACK_LO+2,x
|
2020-06-05 21:19:06 +00:00
|
|
|
jsr func_substr
|
|
|
|
; unwind original params
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
func_substr .proc
|
|
|
|
; substr(source, target, start, length) with params on stack
|
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
ldy P8ESTACK_LO,x ; length
|
2020-06-05 21:19:06 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x ; start
|
|
|
|
sta P8ZP_SCRATCH_B1
|
2020-06-05 21:19:06 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W2+1
|
2020-06-05 21:19:06 +00:00
|
|
|
inx
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ESTACK_LO,x
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
lda P8ESTACK_HI,x
|
|
|
|
sta P8ZP_SCRATCH_W1+1
|
2020-06-05 21:19:06 +00:00
|
|
|
; adjust src location
|
|
|
|
clc
|
2020-08-25 17:44:08 +00:00
|
|
|
lda P8ZP_SCRATCH_W1
|
|
|
|
adc P8ZP_SCRATCH_B1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-06-05 21:19:06 +00:00
|
|
|
bcc +
|
2020-08-25 17:44:08 +00:00
|
|
|
inc P8ZP_SCRATCH_W1+1
|
2020-06-05 21:19:06 +00:00
|
|
|
+ lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2020-06-05 21:19:06 +00:00
|
|
|
jmp _startloop
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_W1),y
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
2020-06-05 21:19:06 +00:00
|
|
|
_startloop dey
|
|
|
|
cpy #$ff
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
|
|
|
|
.pend
|