2021-01-07 00:56:31 +00:00
|
|
|
; 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
|
|
|
|
|
2020-11-21 18:09:02 +00:00
|
|
|
|
|
|
|
read_byte_from_address_on_stack .proc
|
|
|
|
; -- read the byte from the memory address on the top of the stack, return in A (stack remains unchanged)
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ldy P8ESTACK_HI+1,x
|
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W2),y
|
|
|
|
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)
|
|
|
|
ldy P8ESTACK_LO+1,x
|
|
|
|
sty P8ZP_SCRATCH_W2
|
|
|
|
ldy P8ESTACK_HI+1,x
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
|
|
|
ldy #0
|
|
|
|
sta (P8ZP_SCRATCH_W2),y
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
|
|
|
2020-10-28 21:56:13 +00:00
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
|
|
|
|
2020-11-21 22:46:18 +00:00
|
|
|
reg_less_uw .proc
|
|
|
|
; AY < P8ZP_SCRATCH_W2?
|
|
|
|
cpy P8ZP_SCRATCH_W2+1
|
|
|
|
bcc _true
|
|
|
|
bne _false
|
|
|
|
cmp P8ZP_SCRATCH_W2
|
|
|
|
bcc _true
|
|
|
|
_false lda #0
|
|
|
|
rts
|
|
|
|
_true lda #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
|
|
|
|
2020-11-21 22:46:18 +00:00
|
|
|
reg_less_w .proc
|
|
|
|
; -- AY < P8ZP_SCRATCH_W2?
|
2020-11-30 00:53:44 +00:00
|
|
|
cmp P8ZP_SCRATCH_W2
|
2020-11-21 22:46:18 +00:00
|
|
|
tya
|
|
|
|
sbc P8ZP_SCRATCH_W2+1
|
|
|
|
bvc +
|
|
|
|
eor #$80
|
|
|
|
+ bmi _true
|
2020-11-30 00:53:44 +00:00
|
|
|
lda #0
|
2020-11-21 22:46:18 +00:00
|
|
|
rts
|
2020-11-30 00:53:44 +00:00
|
|
|
_true lda #1
|
2020-11-21 22:46:18 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
|
|
|
|
2020-11-21 22:46:18 +00:00
|
|
|
reg_lesseq_uw .proc
|
|
|
|
; AY <= P8ZP_SCRATCH_W2?
|
|
|
|
cpy P8ZP_SCRATCH_W2+1
|
|
|
|
beq +
|
|
|
|
bcc _true
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
+ cmp P8ZP_SCRATCH_W2
|
|
|
|
bcc _true
|
|
|
|
beq _true
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
_true lda #1
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
|
|
|
|
2020-11-21 22:46:18 +00:00
|
|
|
reg_lesseq_w .proc
|
2020-12-01 01:09:48 +00:00
|
|
|
; -- P8ZP_SCRATCH_W2 <= AY ? (note: order different from other routines)
|
|
|
|
cmp P8ZP_SCRATCH_W2
|
|
|
|
tya
|
|
|
|
sbc P8ZP_SCRATCH_W2+1
|
2020-11-21 22:46:18 +00:00
|
|
|
bvc +
|
|
|
|
eor #$80
|
2020-12-01 01:09:48 +00:00
|
|
|
+ bpl +
|
2020-11-30 01:12:49 +00:00
|
|
|
lda #0
|
2020-11-21 22:46:18 +00:00
|
|
|
rts
|
2020-12-01 01:09:48 +00:00
|
|
|
+ lda #1
|
2020-11-21 22:46:18 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2019-01-20 23:00:26 +00:00
|
|
|
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
|
2020-11-30 23:07:06 +00:00
|
|
|
+ bmi equal_b._equal_b_false
|
|
|
|
bpl equal_b._equal_b_true
|
2019-01-20 23:00:26 +00:00
|
|
|
.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
|
|
|
|
|
|
|
|
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
memcopy16_up .proc
|
|
|
|
; -- copy memory UP from (P8ZP_SCRATCH_W1) to (P8ZP_SCRATCH_W2) of length X/Y (16-bit, X=lo, Y=hi)
|
|
|
|
; clobbers register A,X,Y
|
|
|
|
source = P8ZP_SCRATCH_W1
|
|
|
|
dest = P8ZP_SCRATCH_W2
|
|
|
|
length = P8ZP_SCRATCH_B1 ; (and SCRATCH_ZPREG)
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
stx length
|
|
|
|
sty length+1
|
2019-03-31 16:04:19 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
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
|
2020-10-28 22:13:53 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
memset .proc
|
|
|
|
; -- fill memory from (P8ZP_SCRATCH_W1), length XY, with value in A.
|
|
|
|
; clobbers X, Y
|
|
|
|
stx P8ZP_SCRATCH_B1
|
|
|
|
sty _save_reg
|
|
|
|
ldy #0
|
|
|
|
ldx _save_reg
|
|
|
|
beq _lastpage
|
2020-10-28 22:13:53 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
_fullpage sta (P8ZP_SCRATCH_W1),y
|
|
|
|
iny
|
|
|
|
bne _fullpage
|
|
|
|
inc P8ZP_SCRATCH_W1+1 ; next page
|
|
|
|
dex
|
|
|
|
bne _fullpage
|
2020-10-28 22:13:53 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
_lastpage ldy P8ZP_SCRATCH_B1
|
|
|
|
beq +
|
|
|
|
- dey
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
|
|
|
bne -
|
2020-10-28 22:13:53 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
+ rts
|
|
|
|
_save_reg .byte 0
|
2020-10-28 22:13:53 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
memsetw .proc
|
|
|
|
; -- fill memory from (P8ZP_SCRATCH_W1) number of words in P8ZP_SCRATCH_W2, 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
|
|
|
|
ldx P8ZP_SCRATCH_W1
|
|
|
|
stx P8ZP_SCRATCH_B1
|
|
|
|
ldx P8ZP_SCRATCH_W1+1
|
|
|
|
inx
|
|
|
|
stx P8ZP_SCRATCH_REG ; second page
|
2020-10-28 22:13:53 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
ldy #0
|
|
|
|
ldx P8ZP_SCRATCH_W2+1
|
|
|
|
beq _lastpage
|
2019-01-20 23:00:26 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
_fullpage
|
|
|
|
_mod1 lda #0 ; self-modified
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ; first page
|
|
|
|
sta (P8ZP_SCRATCH_B1),y ; second page
|
|
|
|
iny
|
|
|
|
_mod1b lda #0 ; self-modified
|
|
|
|
sta (P8ZP_SCRATCH_W1),y ; first page
|
|
|
|
sta (P8ZP_SCRATCH_B1),y ; second page
|
|
|
|
iny
|
|
|
|
bne _fullpage
|
|
|
|
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
|
2020-11-03 21:42:59 +00:00
|
|
|
dex
|
2020-11-05 21:27:50 +00:00
|
|
|
bne _fullpage
|
2019-01-20 23:00:26 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
_lastpage ldx P8ZP_SCRATCH_W2
|
|
|
|
beq _done
|
2019-01-20 23:00:26 +00:00
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
ldy #0
|
|
|
|
-
|
|
|
|
_mod2 lda #0 ; self-modified
|
|
|
|
sta (P8ZP_SCRATCH_W1), y
|
|
|
|
inc P8ZP_SCRATCH_W1
|
|
|
|
bne _mod2b
|
|
|
|
inc P8ZP_SCRATCH_W1+1
|
|
|
|
_mod2b lda #0 ; self-modified
|
|
|
|
sta (P8ZP_SCRATCH_W1), y
|
|
|
|
inc P8ZP_SCRATCH_W1
|
|
|
|
bne +
|
|
|
|
inc P8ZP_SCRATCH_W1+1
|
|
|
|
+ dex
|
|
|
|
bne -
|
|
|
|
_done rts
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
ror2_mem_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- in-place 8-bit ror of byte at memory location in AY
|
2020-11-05 21:27:50 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-11-05 21:27:50 +00:00
|
|
|
ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
lsr a
|
|
|
|
bcc +
|
|
|
|
ora #$80
|
|
|
|
+ sta (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
rol2_mem_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- in-place 8-bit rol of byte at memory location in AY
|
2020-11-05 21:27:50 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2020-11-05 21:27:50 +00:00
|
|
|
ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
cmp #$80
|
|
|
|
rol a
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
rol_array_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- rol a ubyte in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
2020-11-05 21:27:50 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
ldy _arg_index
|
2020-11-05 21:27:50 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
rol a
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
ror_array_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- ror a ubyte in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
ldy _arg_index
|
2020-11-05 21:27:50 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
ror a
|
|
|
|
sta (P8ZP_SCRATCH_W1),y
|
2019-01-20 23:00:26 +00:00
|
|
|
rts
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
ror2_array_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- ror2 (8-bit ror) a ubyte in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
2020-11-05 21:27:50 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
ldy _arg_index
|
2020-11-05 21:27:50 +00:00
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
lsr a
|
|
|
|
bcc +
|
|
|
|
ora #$80
|
|
|
|
+ sta (P8ZP_SCRATCH_W1),y
|
|
|
|
rts
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2019-01-20 23:00:26 +00:00
|
|
|
.pend
|
|
|
|
|
2020-11-05 21:27:50 +00:00
|
|
|
rol2_array_ub .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- rol2 (8-bit rol) a ubyte in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
2020-11-06 22:51:39 +00:00
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
ldy _arg_index
|
2020-08-25 17:44:08 +00:00
|
|
|
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
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2020-04-03 19:17:52 +00:00
|
|
|
.pend
|
|
|
|
|
2020-04-02 22:03:42 +00:00
|
|
|
ror_array_uw .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- ror a uword in an array
|
2020-04-02 22:03:42 +00:00
|
|
|
php
|
2020-11-06 22:51:39 +00:00
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
lda _arg_index
|
2020-04-02 22:03:42 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
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
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2020-04-02 22:03:42 +00:00
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:31:17 +00:00
|
|
|
rol_array_uw .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- rol a uword in an array
|
2020-04-03 19:31:17 +00:00
|
|
|
php
|
2020-11-06 22:51:39 +00:00
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
lda _arg_index
|
2020-04-03 19:31:17 +00:00
|
|
|
asl a
|
|
|
|
tay
|
2020-08-25 17:44:08 +00:00
|
|
|
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
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2020-04-03 19:31:17 +00:00
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:17:52 +00:00
|
|
|
rol2_array_uw .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- rol2 (16-bit rol) a uword in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
lda _arg_index
|
2020-04-03 19:17:52 +00:00
|
|
|
asl a
|
|
|
|
tay
|
2020-08-25 17:44:08 +00:00
|
|
|
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
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2020-04-03 19:17:52 +00:00
|
|
|
.pend
|
|
|
|
|
2020-04-03 19:04:42 +00:00
|
|
|
ror2_array_uw .proc
|
2020-11-06 22:51:39 +00:00
|
|
|
; -- ror2 (16-bit ror) a uword in an array
|
|
|
|
lda _arg_target
|
|
|
|
ldy _arg_target+1
|
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
lda _arg_index
|
2020-04-03 19:04:42 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
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
|
2020-11-06 22:51:39 +00:00
|
|
|
_arg_target .word 0
|
|
|
|
_arg_index .byte 0
|
2020-04-03 19:04:42 +00:00
|
|
|
.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-12-14 16:20:16 +00:00
|
|
|
; returns the length of the string that was copied in Y.
|
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-11-06 21:59:56 +00:00
|
|
|
strcmp_expression .proc
|
2020-11-10 20:48:28 +00:00
|
|
|
; -- compare strings, result in A
|
|
|
|
lda _arg_s2
|
|
|
|
ldy _arg_s2+1
|
2020-11-06 21:59:56 +00:00
|
|
|
sta P8ZP_SCRATCH_W2
|
|
|
|
sty P8ZP_SCRATCH_W2+1
|
2020-11-10 20:48:28 +00:00
|
|
|
lda _arg_s1
|
|
|
|
ldy _arg_s1+1
|
2020-11-06 21:59:56 +00:00
|
|
|
jmp strcmp_mem
|
2020-11-10 20:48:28 +00:00
|
|
|
_arg_s1 .word 0
|
|
|
|
_arg_s2 .word 0
|
2020-11-06 21:59:56 +00:00
|
|
|
.pend
|
|
|
|
|
2020-08-20 16:07:48 +00:00
|
|
|
|
2020-10-15 23:12:20 +00:00
|
|
|
strcmp_mem .proc
|
2020-10-16 23:30:49 +00:00
|
|
|
; -- compares strings in s1 (AY) and s2 (P8ZP_SCRATCH_W2).
|
2020-10-15 23:12:20 +00:00
|
|
|
; Returns -1,0,1 in A, depeding on the ordering. Clobbers Y.
|
2021-01-07 00:56:31 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
|
|
|
_loop ldy #0
|
|
|
|
lda (P8ZP_SCRATCH_W1),y
|
|
|
|
bne +
|
|
|
|
lda (P8ZP_SCRATCH_W2),y
|
|
|
|
bne _return_minusone
|
|
|
|
beq _return
|
|
|
|
+ lda (P8ZP_SCRATCH_W2),y
|
|
|
|
sec
|
|
|
|
sbc (P8ZP_SCRATCH_W1),y
|
|
|
|
bmi _return_one
|
|
|
|
bne _return_minusone
|
|
|
|
inc P8ZP_SCRATCH_W1
|
|
|
|
bne +
|
|
|
|
inc P8ZP_SCRATCH_W1+1
|
|
|
|
+ inc P8ZP_SCRATCH_W2
|
|
|
|
bne _loop
|
|
|
|
inc P8ZP_SCRATCH_W2+1
|
|
|
|
bne _loop
|
2020-10-15 23:12:20 +00:00
|
|
|
_return_one
|
2021-01-07 00:56:31 +00:00
|
|
|
lda #1
|
|
|
|
_return rts
|
2020-10-15 23:12:20 +00:00
|
|
|
_return_minusone
|
2021-01-07 00:56:31 +00:00
|
|
|
lda #-1
|
|
|
|
rts
|
|
|
|
.pend
|
2020-11-24 21:26:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
sign_extend_stack_byte .proc
|
|
|
|
; -- sign extend the (signed) byte on the stack to full 16 bits
|
|
|
|
lda P8ESTACK_LO+1,x
|
|
|
|
ora #$7f
|
|
|
|
bmi +
|
|
|
|
lda #0
|
|
|
|
+ sta P8ESTACK_HI+1,x
|
|
|
|
rts
|
|
|
|
.pend
|
|
|
|
|
|
|
|
|
|
|
|
sign_extend_AY_byte .proc
|
|
|
|
; -- sign extend the (signed) byte in AY to full 16 bits
|
|
|
|
pha
|
|
|
|
and #$80
|
|
|
|
beq +
|
|
|
|
ldy #$ff
|
|
|
|
pla
|
|
|
|
rts
|
|
|
|
+ ldy #0
|
|
|
|
pla
|
|
|
|
rts
|
|
|
|
.pend
|