mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
fixed bug in memcopy
This commit is contained in:
parent
90271d0dcd
commit
f34f9329f1
@ -500,19 +500,23 @@ sys {
|
|||||||
asmsub memcopy(uword source @R0, uword target @R1, uword count @AY) clobbers(A,X,Y) {
|
asmsub memcopy(uword source @R0, uword target @R1, uword count @AY) clobbers(A,X,Y) {
|
||||||
%asm {{
|
%asm {{
|
||||||
ldx cx16.r0
|
ldx cx16.r0
|
||||||
stx P8ZP_SCRATCH_W1
|
stx P8ZP_SCRATCH_W1 ; source in ZP
|
||||||
ldx cx16.r0+1
|
ldx cx16.r0+1
|
||||||
stx P8ZP_SCRATCH_W1+1
|
stx P8ZP_SCRATCH_W1+1
|
||||||
ldx cx16.r1
|
ldx cx16.r1
|
||||||
stx P8ZP_SCRATCH_W2
|
stx P8ZP_SCRATCH_W2 ; target in ZP
|
||||||
ldx cx16.r1+1
|
ldx cx16.r1+1
|
||||||
stx P8ZP_SCRATCH_W2+1
|
stx P8ZP_SCRATCH_W2+1
|
||||||
cpy #0
|
cpy #0
|
||||||
bne _longcopy
|
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
|
lda P8ZP_SCRATCH_W1
|
||||||
bne +
|
bne +
|
||||||
dec P8ZP_SCRATCH_W1+1
|
dec P8ZP_SCRATCH_W1+1
|
||||||
@ -521,18 +525,19 @@ _remainder
|
|||||||
bne +
|
bne +
|
||||||
dec P8ZP_SCRATCH_W2+1
|
dec P8ZP_SCRATCH_W2+1
|
||||||
+ dec P8ZP_SCRATCH_W2
|
+ 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
|
dey
|
||||||
bne -
|
bne -
|
||||||
rts
|
rts
|
||||||
|
|
||||||
_longcopy
|
_longcopy
|
||||||
sta P8ZP_SCRATCH_B1 ; lsb(count) = remainder
|
sta P8ZP_SCRATCH_B1 ; lsb(count) = remainder in last page
|
||||||
tya
|
tya
|
||||||
tax ; x = num pages (1+)
|
tax ; x = num pages (1+)
|
||||||
ldy #0
|
ldy #0
|
||||||
- lda (P8ZP_SCRATCH_W1),y ; copy a page at a time
|
- lda (P8ZP_SCRATCH_W1),y
|
||||||
sta (P8ZP_SCRATCH_W2),y
|
sta (P8ZP_SCRATCH_W2),y
|
||||||
iny
|
iny
|
||||||
bne -
|
bne -
|
||||||
@ -541,7 +546,8 @@ _longcopy
|
|||||||
dex
|
dex
|
||||||
bne -
|
bne -
|
||||||
ldy P8ZP_SCRATCH_B1
|
ldy P8ZP_SCRATCH_B1
|
||||||
jmp _remainder
|
bne _copyshort
|
||||||
|
rts
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- fix sys.memcopy()
|
|
||||||
- allow uwordpointer[index] syntax -> transform into @(uwordpointer+index) allow index to be >255!
|
- allow uwordpointer[index] syntax -> transform into @(uwordpointer+index) allow index to be >255!
|
||||||
- add offsetof() to get the byte offset of struct members
|
- add offsetof() to get the byte offset of struct members
|
||||||
- add any2(), all2(), max2(), min2(), reverse2(), sum2(), sort2() that take (array, startindex, length) arguments
|
- add any2(), all2(), max2(), min2(), reverse2(), sum2(), sort2() that take (array, startindex, length) arguments
|
||||||
|
@ -8,26 +8,33 @@ main {
|
|||||||
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte[] sarray = [11,22,33]
|
; TODO test memcopy
|
||||||
ubyte[] tarray = [0,0,0]
|
; counts: 0, 1, 2, 254, 255, 256, 257, 512, 1000
|
||||||
|
|
||||||
uword target = &tarray
|
uword buffer=memory("buffer",1000)
|
||||||
uword source = &sarray
|
uword ones=memory("ones",1000)
|
||||||
ubyte bb
|
|
||||||
@(target) = @(source)
|
|
||||||
target++
|
|
||||||
source++
|
|
||||||
@(target) = @(source)
|
|
||||||
target++
|
|
||||||
source++
|
|
||||||
@(target) = @(source)
|
|
||||||
target++
|
|
||||||
source++
|
|
||||||
|
|
||||||
for bb in tarray {
|
sys.memset(buffer, 1000, '.')
|
||||||
txt.print_ub(bb)
|
@(buffer) = '<'
|
||||||
txt.chrout('\n')
|
@(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++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user