gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit ea63fae0c98585312e3799688ea574de3c33627d parent f0ce233a6f126adf05ed4cac70683f5f949676b5 Author: Toxa <untoxa@mail.ru> Date: Sat, 19 Dec 2020 23:38:30 +0300 memset/memcpy minor enhancements Diffstat:
| M | gbdk-lib/include/string.h | 12 | ++++++------ |
| M | gbdk-lib/libc/asm/gbz80/_memcpy.s | 66 | +++++++++++++++++++++++++++++------------------------------------- |
| M | gbdk-lib/libc/asm/gbz80/_memset.s | 50 | ++++++++++++++++++++++++-------------------------- |
| M | gbdk-lib/libc/asm/gbz80/reverse.s | 2 | +- |
| M | gbdk-lib/libc/asm/gbz80/strlen.s | 2 | +- |
5 files changed, 61 insertions(+), 71 deletions(-)
diff --git a/gbdk-lib/include/string.h b/gbdk-lib/include/string.h @@ -17,7 +17,7 @@ @return A pointer to dest */ -char *strcpy(char *dest, const char *src) NONBANKED; +char *strcpy(char *dest, const char *src) NONBANKED __preserves_regs(b, c); /** Compares strings @@ -29,7 +29,7 @@ char *strcpy(char *dest, const char *src) NONBANKED; \li 0 if __s1__ == __s2__ \li < 0 if __s1__ < __s2__ */ -int strcmp(const char *s1, const char *s2) NONBANKED; +int strcmp(const char *s1, const char *s2) NONBANKED __preserves_regs(b, c); /** Copies n bytes from memory area src to memory area dest. @@ -39,7 +39,7 @@ int strcmp(const char *s1, const char *s2) NONBANKED; @param src Buffer to copy from @param len Number of Bytes to copy */ -void *memcpy(void *dest, const void *src, size_t len) NONBANKED; +void *memcpy(void *dest, const void *src, size_t len) NONBANKED __preserves_regs(b, c); /** Fills the memory region __s__ with __n__ bytes using value __c__ @@ -47,7 +47,7 @@ void *memcpy(void *dest, const void *src, size_t len) NONBANKED; @param c char value to fill with (truncated from int) @param n Number of bytes to fill */ -void *memset (void *s, int c, size_t n); +void *memset (void *s, int c, size_t n) NONBANKED __preserves_regs(b, c); /** Reverses the characters in a string @@ -59,7 +59,7 @@ void *memset (void *s, int c, size_t n); Returns: Pointer to __s__ */ -char *reverse(char *s); +char *reverse(char *s) __preserves_regs(b, c); /** Concatenate Strings. Appends string __s2__ to the end of string __s1__ @@ -80,7 +80,7 @@ char *strcat(char *s1, const char *s2) NONBANKED; Returns: Length of string not including the terminating `\0' character. */ -int strlen(const char *s) NONBANKED; +int strlen(const char *s) NONBANKED __preserves_regs(b, c); /**Concatenate at most __n__ characters from string __s2__ onto the end of __s1__. diff --git a/gbdk-lib/libc/asm/gbz80/_memcpy.s b/gbdk-lib/libc/asm/gbz80/_memcpy.s @@ -1,44 +1,48 @@ .area _BASE ; void *memcpy(void *dest, const void *source, int count) -.memcpy:: - push bc - jr .memcpy_cont ___memcpy:: _memcpy:: - push bc - lda hl,9(sp) + lda hl,7(sp) ld a,(hl-) ld d, a ld a,(hl-) - ld e,a + ld e,a ; de == count + or d + jr z, 6$ + + push bc ; preserve bc (smallc convention) + ld a,(hl-) ld b,a ld a,(hl-) - ld c,a + ld c,a ; bc == source ld a,(hl-) ld l,(hl) - ld h,a -.memcpy_cont: - push hl - - ld a, e - and #0xfc - or d - jr z,3$ - - push de + ld h,a ; hl == dest srl d rr e + jr nc,4$ + ld a,(bc) ; copy one byte + ld (hl+),a + inc bc +4$: srl d rr e - + jr nc,5$ + ld a,(bc) ; copy two bytes + ld (hl+),a + inc bc + ld a,(bc) + ld (hl+),a + inc bc +5$: inc d inc e jr 2$ 1$: - ld a,(bc) + ld a,(bc) ; copy four bytes ld (hl+),a inc bc ld a,(bc) @@ -55,23 +59,11 @@ _memcpy:: jr nz,1$ dec d jr nz,1$ - - pop de 3$: - srl e - jr nc,4$ - ld a,(bc) - ld (hl+),a - inc bc -4$: - srl e - jr nc,5$ - ld a,(bc) - ld (hl+),a - inc bc - ld a,(bc) - ld (hl+),a -5$: - pop de - pop bc + pop bc ; restore bc +6$: + lda hl,2(sp) ; return dest + ld a,(hl+) + ld e,a + ld d,(hl) ret diff --git a/gbdk-lib/libc/asm/gbz80/_memset.s b/gbdk-lib/libc/asm/gbz80/_memset.s @@ -5,29 +5,33 @@ _memset:: lda hl,7(sp) ld a,(hl-) ld d, a - or (hl) - ret z ld a,(hl-) ld e, a + or d + jr z,6$ + dec hl ld a,(hl-) - push af + push af ld a,(hl-) ld l,(hl) ld h,a pop af -.memset:: - push bc - - ld c,e - srl d - rr e - srl d - rr e - - inc d - inc e - jr 2$ + + srl d + rr e + jr nc,4$ + ld (hl+),a +4$: + srl d + rr e + jr nc,5$ + ld (hl+),a + ld (hl+),a +5$: + inc d + inc e + jr 2$ 1$: ld (hl+),a ld (hl+),a @@ -38,15 +42,9 @@ _memset:: jr nz,1$ dec d jr nz,1$ - - srl c - jr nc, 4$ - ld (hl+),a -4$: - srl c - jr nc, 5$ - ld (hl+),a - ld (hl+),a -5$: - pop bc +6$: + lda hl,2(sp) + ld a,(hl+) + ld e,a + ld d,(hl) ret diff --git a/gbdk-lib/libc/asm/gbz80/reverse.s b/gbdk-lib/libc/asm/gbz80/reverse.s @@ -28,7 +28,7 @@ .module reverse - .area _CODE + .area _BASE _reverse:: lda HL, 2(SP) diff --git a/gbdk-lib/libc/asm/gbz80/strlen.s b/gbdk-lib/libc/asm/gbz80/strlen.s @@ -28,7 +28,7 @@ .module strlen - .area _CODE + .area _BASE _strlen:: lda HL, 2(SP)
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.