diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index f30da824b..96719b84e 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -823,16 +823,61 @@ sys { asmsub memcopy(uword source @R0, uword target @R1, uword count @AY) clobbers(A,X,Y) { ; note: can't be inlined because is called from asm as well + ; also: doesn't use cx16 ROM routine so this always works even when ROM is not banked in. %asm {{ - sta cx16.r2 - sty cx16.r2+1 - jmp cx16.memory_copy + cpy #0 + bne _longcopy + + ; copy <= 255 bytes + tay + bne _copyshort + rts ; nothing to copy + +_copyshort + ; decrease source and target pointers so we can simply index by Y + lda cx16.r0 + bne + + dec cx16.r0+1 ++ dec cx16.r0 + lda cx16.r1 + bne + + dec cx16.r1+1 ++ dec cx16.r1 + +- lda (cx16.r0),y + sta (cx16.r1),y + dey + bne - + rts + +_longcopy + pha ; lsb(count) = remainder in last page + tya + tax ; x = num pages (1+) + ldy #0 +- lda (cx16.r0),y + sta (cx16.r1),y + iny + bne - + inc cx16.r0+1 + inc cx16.r1+1 + dex + bne - + ply + bne _copyshort + rts }} } - inline asmsub memset(uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers(A,X,Y) { + asmsub memset(uword mem @R0, uword numbytes @R1, ubyte value @A) clobbers(A,X,Y) { %asm {{ - jsr cx16.memory_fill + ldy cx16.r0 + sty P8ZP_SCRATCH_W1 + ldy cx16.r0+1 + sty P8ZP_SCRATCH_W1+1 + ldx cx16.r1 + ldy cx16.r1+1 + jmp prog8_lib.memset }} } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 86f439448..3a7b1ac67 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,8 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- move memcopy() logic to prog8_lib and call this from sys.memcopy() the same for all targets (so cx16 now also works when kernal is disabled!) -- same for memset() - get rid of RAW_LOAD_ADDRESS and make specifying the load address for RAW launcher mode required ... @@ -12,7 +10,7 @@ For next release Need help with ^^^^^^^^^^^^^^ - c128 target: various machine specific things (free zp locations, how banking works, getting the floating point routines working, ...) -- other targets such as Atari 800XL: all required details about the machine, I have no clue whatsoever +- atari target: more details details about the machine, fixing library routines. I have no clue whatsoever. - see the :ref:`portingguide` for details on what information is needed. diff --git a/examples/test.p8 b/examples/test.p8 index 0aa8d4b90..421e1eedd 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,11 +1,48 @@ -%launcher none +%import textio +%zeropage kernalsafe main { sub start() { - uword @shared names_buffer = memory("filenames", 200, 0) + ubyte[20] array1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] + ubyte[20] array2 = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2] - do { - ubyte @shared char = '*' - } until true + sys.set_irqd() + + cx16.rombank(9) + sys.memset(array1, 20, 255) + + cx16.rombank(0) + ubyte ii + for ii in array1 { + txt.print_ubhex(ii, false) + txt.spc() + } + txt.nl() + for ii in array2 { + txt.print_ubhex(ii, false) + txt.spc() + } + txt.nl() + + cx16.rombank(9) + sys.memset(array1, 20, 255) + array2=array1 + + cx16.rombank(0) + for ii in array1 { + txt.print_ubhex(ii, false) + txt.spc() + } + txt.nl() + for ii in array2 { + txt.print_ubhex(ii, false) + txt.spc() + } + txt.nl() + + cx16.rombank(4) + + repeat { + } } }