1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 19:29:37 +00:00

Added code to handle the special case of a zero-length move.

Added more tests of memcpy() and memmove().
This commit is contained in:
Greg King 2015-11-02 17:04:46 -05:00
parent 281dc33e5a
commit 8180ac20d3
3 changed files with 34 additions and 16 deletions

View File

@ -4,7 +4,7 @@
; block-copy instructions. ; block-copy instructions.
; ;
; 2003-08-20, Ullrich von Bassewitz ; 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); ; void* __fastcall__ memcpy (void* dest, const void* src, size_t size);
; ;
@ -16,7 +16,7 @@
.export _memcpy .export _memcpy
.export memcpy_increment, memcpy_transfer, memcpy_getparams .export memcpy_increment, memcpy_transfer, memcpy_getparams
.import popax .import incsp2, popax
.importzp sp, ptr1, ptr2, ptr3 .importzp sp, ptr1, ptr2, ptr3
@ -68,12 +68,23 @@ memcpy_transfer:
memcpy_getparams: memcpy_getparams:
sta ptr3 sta ptr3
stx ptr3+1 ; save size 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 sta ptr1
stx ptr1+1 ; save src 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 ldy #1 ; save dest
lda (sp),y ; get high byte lda (sp),y ; get high byte
@ -85,10 +96,10 @@ memcpy_getparams:
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
; The transfer instructions use inline arguments. ; 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 .data
transfer: transfer:
tii $FFFF, $FFFF, $0001 tii $FFFF, $FFFF, $0001
jmp popax ; get pointer; and, return it as result jmp popax ; get pointer; return it as result

View File

@ -1,3 +1,4 @@
.PHONY: all clean test
all: conio.pce all: conio.pce
@ -5,9 +6,7 @@ conio.pce: conio.c
../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce
clean: clean:
$(RM) conio.pce $(RM) conio.o conio.pce conio.map
$(RM) conio.map
test: conio.pce test: conio.pce
mednafen -force_module pce conio.pce mednafen -force_module pce conio.pce

View File

@ -1,4 +1,3 @@
#include <conio.h> #include <conio.h>
#include <time.h> #include <time.h>
#include <joystick.h> #include <joystick.h>
@ -13,7 +12,7 @@ void main(void)
int i, j; int i, j;
clock_t clk; clock_t clk;
char* p; char* p;
unsigned char xsize, ysize, n; unsigned char xsize, ysize, n, nn;
joy_install(&joy_static_stddrv); joy_install(&joy_static_stddrv);
@ -40,11 +39,12 @@ void main(void)
gotoxy(0, 16 + i); gotoxy(0, 16 + i);
p = malloc(16); p = malloc(16);
memcpy(p, "0123456789abcdef", 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[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] 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); gotoxy(0,ysize - 1);
for (i = 0; i < xsize; ++i) { for (i = 0; i < xsize; ++i) {
@ -108,14 +108,22 @@ void main(void)
} }
gotoxy(xsize - 10, 3); gotoxy(xsize - 10, 3);
j = (n >> 5) & 1; nn = (n >> 5) & 1;
revers(j); revers(nn);
cputc(j ? 'R' : ' '); cputc(nn ? 'R' : ' ');
cputs(" revers"); cputs(" revers");
revers(0); 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(); waitvblank();
++n; ++n;
} }
for(;;);
} }