; 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);
;
.export _memcpy
.export memcpy_increment, memcpy_transfer, memcpy_getparams
- .import popax
+ .import incsp2, popax
.importzp sp, ptr1, ptr2, ptr3
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
; ----------------------------------------------------------------------
; 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
-
#include <conio.h>
#include <time.h>
#include <joystick.h>
int i, j;
clock_t clk;
char* p;
- unsigned char xsize, ysize, n;
+ unsigned char xsize, ysize, n, nn;
joy_install(&joy_static_stddrv);
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) {
}
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(;;);
}