fixed bug in memcopy

This commit is contained in:
Irmen de Jong 2021-01-23 19:49:53 +01:00
parent 90271d0dcd
commit f34f9329f1
3 changed files with 41 additions and 29 deletions

View File

@ -500,19 +500,23 @@ sys {
asmsub memcopy(uword source @R0, uword target @R1, uword count @AY) clobbers(A,X,Y) {
%asm {{
ldx cx16.r0
stx P8ZP_SCRATCH_W1
stx P8ZP_SCRATCH_W1 ; source in ZP
ldx cx16.r0+1
stx P8ZP_SCRATCH_W1+1
ldx cx16.r1
stx P8ZP_SCRATCH_W2
stx P8ZP_SCRATCH_W2 ; target in ZP
ldx cx16.r1+1
stx P8ZP_SCRATCH_W2+1
cpy #0
bne _longcopy
; copy <= 255
tay
_remainder
; copy <= 255 bytes
tay
bne _copyshort
rts ; nothing to copy
_copyshort
; decrease source and target pointers so we can simply index by Y
lda P8ZP_SCRATCH_W1
bne +
dec P8ZP_SCRATCH_W1+1
@ -521,18 +525,19 @@ _remainder
bne +
dec P8ZP_SCRATCH_W2+1
+ dec P8ZP_SCRATCH_W2
- lda (P8ZP_SCRATCH_W1), y
sta (P8ZP_SCRATCH_W2), y
- lda (P8ZP_SCRATCH_W1),y
sta (P8ZP_SCRATCH_W2),y
dey
bne -
rts
_longcopy
sta P8ZP_SCRATCH_B1 ; lsb(count) = remainder
sta P8ZP_SCRATCH_B1 ; lsb(count) = remainder in last page
tya
tax ; x = num pages (1+)
ldy #0
- lda (P8ZP_SCRATCH_W1),y ; copy a page at a time
- lda (P8ZP_SCRATCH_W1),y
sta (P8ZP_SCRATCH_W2),y
iny
bne -
@ -541,7 +546,8 @@ _longcopy
dex
bne -
ldy P8ZP_SCRATCH_B1
jmp _remainder
bne _copyshort
rts
}}
}

View File

@ -2,7 +2,6 @@
TODO
====
- fix sys.memcopy()
- allow uwordpointer[index] syntax -> transform into @(uwordpointer+index) allow index to be >255!
- add offsetof() to get the byte offset of struct members
- add any2(), all2(), max2(), min2(), reverse2(), sum2(), sort2() that take (array, startindex, length) arguments

View File

@ -8,26 +8,33 @@ main {
sub start() {
ubyte[] sarray = [11,22,33]
ubyte[] tarray = [0,0,0]
; TODO test memcopy
; counts: 0, 1, 2, 254, 255, 256, 257, 512, 1000
uword target = &tarray
uword source = &sarray
ubyte bb
@(target) = @(source)
target++
source++
@(target) = @(source)
target++
source++
@(target) = @(source)
target++
source++
uword buffer=memory("buffer",1000)
uword ones=memory("ones",1000)
for bb in tarray {
txt.print_ub(bb)
txt.chrout('\n')
sys.memset(buffer, 1000, '.')
@(buffer) = '<'
@(buffer+255) = '>'
@(buffer+256) = '<'
@(buffer+511) = '>'
@(buffer+512) = '<'
@(buffer+767) = '>'
@(buffer+768) = '<'
@(buffer+999) = '!'
sys.memset(ones, 1000, '*')
txt.clear_screen()
txt.print("\n\n\n\n\n\n\n\n\n")
sys.memcopy(ones, buffer, 999)
uword scr = $0400
uword ix
for ix in 0 to 999 {
@(scr) = @(buffer+ix)
scr++
}
}
}