mirror of
https://github.com/irmen/prog8.git
synced 2024-09-05 20:29:08 +00:00
140 lines
3.1 KiB
Plaintext
140 lines
3.1 KiB
Plaintext
; IL65 internal library routines
|
|
;
|
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
|
; ;
|
|
; indent format: TABS, size=8
|
|
|
|
|
|
~ il65_lib_zp {
|
|
; note: separate block so the 64tass assembler can remove this when no zp restore is required
|
|
|
|
%asm {
|
|
|
|
; ---- store the Zeropage in a backup area
|
|
save_zeropage
|
|
sei
|
|
ldx #2
|
|
- lda $00,x
|
|
sta zp_backup,x
|
|
inx
|
|
bne -
|
|
cli
|
|
rts
|
|
|
|
restore_zeropage
|
|
php
|
|
pha
|
|
txa
|
|
pha
|
|
sei
|
|
|
|
lda $a0 ; save the current jiffy clock
|
|
sta zp_backup+$a0
|
|
lda $a1
|
|
sta zp_backup+$a1
|
|
lda $a2
|
|
sta zp_backup+$a2
|
|
|
|
ldx #2
|
|
- lda zp_backup-2,x
|
|
sta $00,x
|
|
inx
|
|
bne -
|
|
cli
|
|
pla
|
|
tax
|
|
pla
|
|
plp
|
|
rts
|
|
|
|
zp_backup .fill 256, 0
|
|
|
|
}
|
|
}
|
|
|
|
|
|
~ il65_lib {
|
|
; note: the following ZP scratch registers must be the same as in c64lib
|
|
memory .byte SCRATCH_ZP1 = $02 ; scratch register #1 in ZP
|
|
memory .byte SCRATCH_ZP2 = $03 ; scratch register #2 in ZP
|
|
memory .word SCRATCH_ZPWORD1 = $fb ; scratch word in ZP ($fb/$fc)
|
|
memory .word SCRATCH_ZPWORD2 = $fd ; scratch word in ZP ($fd/$fe)
|
|
|
|
|
|
%asm {
|
|
; ---- jmp (indirect) routines for register pairs containing the indirect address
|
|
jsr_indirect_nozpuse_AX
|
|
sta jsr_indirect_tmp
|
|
stx jsr_indirect_tmp+1
|
|
jmp (jsr_indirect_tmp)
|
|
jsr_indirect_nozpuse_AY
|
|
sta jsr_indirect_tmp
|
|
sty jsr_indirect_tmp+1
|
|
jmp (jsr_indirect_tmp)
|
|
jsr_indirect_nozpuse_XY
|
|
stx jsr_indirect_tmp
|
|
sty jsr_indirect_tmp+1
|
|
jmp (jsr_indirect_tmp)
|
|
jsr_indirect_tmp
|
|
.byte 0, 0
|
|
|
|
|
|
jsr_indirect_AX
|
|
sta SCRATCH_ZP1
|
|
stx SCRATCH_ZP2
|
|
jmp (SCRATCH_ZP1)
|
|
jsr_indirect_AY
|
|
sta SCRATCH_ZP1
|
|
sty SCRATCH_ZP2
|
|
jmp (SCRATCH_ZP1)
|
|
jsr_indirect_XY
|
|
stx SCRATCH_ZP1
|
|
sty SCRATCH_ZP2
|
|
jmp (SCRATCH_ZP1)
|
|
|
|
|
|
; copy memory UP from (SCRATCH_ZPWORD1) to (SCRATCH_ZPWORD2) of length X/Y (16-bit, X=lo, Y=hi)
|
|
; clobbers register A,X,Y
|
|
memcopy16_up
|
|
source = SCRATCH_ZPWORD1
|
|
dest = SCRATCH_ZPWORD2
|
|
length = SCRATCH_ZP1 ; (and SCRATCH_ZP2)
|
|
|
|
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 ; weve moved 255 bytes, dec length
|
|
bpl - ; if length is still positive go back and move more
|
|
rts ; done
|
|
|
|
|
|
; copy memory UP from (SCRATCH_ZPWORD1) to (AY) with length X (0 = 256)
|
|
; destination must not overlap, or be before start, then overlap is possible.
|
|
; clobbers A, X, Y
|
|
|
|
memcopy
|
|
sta SCRATCH_ZPWORD2
|
|
sty SCRATCH_ZPWORD2+1
|
|
ldy #0
|
|
- lda (SCRATCH_ZPWORD1),y
|
|
sta (SCRATCH_ZPWORD2),y
|
|
iny
|
|
dex
|
|
bne -
|
|
rts
|
|
|
|
}
|
|
}
|