From: Greg King Date: Mon, 2 Nov 2015 22:04:46 +0000 (-0500) Subject: Added code to handle the special case of a zero-length move. X-Git-Tag: V2.16~204^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F225%2Fhead;p=cc65 Added code to handle the special case of a zero-length move. Added more tests of memcpy() and memmove(). --- diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s index b06dad645..e3b7bde34 100644 --- a/libsrc/pce/memcpy.s +++ b/libsrc/pce/memcpy.s @@ -4,7 +4,7 @@ ; block-copy instructions. ; ; 2003-08-20, Ullrich von Bassewitz -; 2015-10-11, Greg King +; 2015-11-02, Greg King ; ; void* __fastcall__ memcpy (void* dest, const void* src, size_t size); ; @@ -16,7 +16,7 @@ .export _memcpy .export memcpy_increment, memcpy_transfer, memcpy_getparams - .import popax + .import incsp2, popax .importzp sp, ptr1, ptr2, ptr3 @@ -68,12 +68,23 @@ memcpy_transfer: memcpy_getparams: sta ptr3 stx ptr3+1 ; save size + ora ptr3+1 + bne @L1 - jsr popax +; The size is zero; copy nothing; just return the dest address. +; (The HuC6280's transfer instructions can't copy $0000 bytes; +; they would copy $10000 [64K] bytes instead.) + + ply ; drop return address + plx + jsr incsp2 ; drop src address + jmp popax ; get pointer; return it as result + +@L1: jsr popax sta ptr1 stx ptr1+1 ; save src -; (Direct stack access is four cycles faster [total cycle count].) +; (Direct stack access is six cycles faster [total cycle count].) ldy #1 ; save dest lda (sp),y ; get high byte @@ -85,10 +96,10 @@ memcpy_getparams: ; ---------------------------------------------------------------------- ; The transfer instructions use inline arguments. -; Therefore, we must build the instruction in the DATA segment. +; Therefore, we must build the instruction, in the DATA segment. .data transfer: tii $FFFF, $FFFF, $0001 - jmp popax ; get pointer; and, return it as result + jmp popax ; get pointer; return it as result diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile index 1fee199fd..9a4dd7506 100644 --- a/testcode/lib/pce/Makefile +++ b/testcode/lib/pce/Makefile @@ -1,3 +1,4 @@ +.PHONY: all clean test all: conio.pce @@ -5,9 +6,7 @@ conio.pce: conio.c ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce clean: - $(RM) conio.pce - $(RM) conio.map + $(RM) conio.o conio.pce conio.map test: conio.pce mednafen -force_module pce conio.pce - diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index d22fe58ee..a4bd63b15 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -1,4 +1,3 @@ - #include #include #include @@ -13,7 +12,7 @@ void main(void) int i, j; clock_t clk; char* p; - unsigned char xsize, ysize, n; + unsigned char xsize, ysize, n, nn; joy_install(&joy_static_stddrv); @@ -40,11 +39,12 @@ void main(void) gotoxy(0, 16 + i); p = malloc(16); memcpy(p, "0123456789abcdef", 16); - cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + cprintf("alloc'ed at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] ); } + memcpy(p, main, 0); /* test that a zero length doesn't copy 64K */ gotoxy(0,ysize - 1); for (i = 0; i < xsize; ++i) { @@ -108,14 +108,22 @@ void main(void) } gotoxy(xsize - 10, 3); - j = (n >> 5) & 1; - revers(j); - cputc(j ? 'R' : ' '); + nn = (n >> 5) & 1; + revers(nn); + cputc(nn ? 'R' : ' '); cputs(" revers"); revers(0); + if ((n & 0x1f) == 0x00) { + nn = p[15]; + ((char*)memmove(p + 1, p, 15))[-1] = nn; + gotoxy(22, 19); + cprintf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", + p[0],p[1],p[ 2],p[ 3],p[ 4],p[ 5],p[ 6],p[ 7], + p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); + } + waitvblank(); ++n; } - for(;;); }