git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 82d5bf7a125f8144a133b9cb7c44bd0d51a9b359
parent 753bed93cf954191a60a1769fbc330e238022d38
Author: Toxa <untoxa@mail.ru>
Date:   Sun, 28 Nov 2021 18:45:02 +0300

memcmp() implementation

Diffstat:
Mgbdk-lib/include/asm/gbz80/string.h13+++++++++++++
Mgbdk-lib/include/asm/z80/string.h13+++++++++++++
Mgbdk-lib/libc/asm/gbz80/Makefile2+-
Agbdk-lib/libc/asm/gbz80/_memcmp.s46++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/asm/z80/Makefile2+-
Agbdk-lib/libc/asm/z80/memcmp.s39+++++++++++++++++++++++++++++++++++++++
6 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/gbdk-lib/include/asm/gbz80/string.h b/gbdk-lib/include/asm/gbz80/string.h @@ -128,4 +128,17 @@ int strncmp(const char *s1, const char *s2, int n); */ char *strncpy(char *s1, const char *s2, int n); +/** Compares buffers + + @param buf1 First buffer to compare + @param buf2 Second buffer to compare + @param count Buffer length + + Returns: + \li > 0 if __buf1__ > __buf2__ + \li 0 if __buf1__ == __buf2__ + \li < 0 if __buf1__ < __buf2__ +*/ +int memcmp(const void *buf1, const void *buf2, size_t count) OLDCALL; + #endif diff --git a/gbdk-lib/include/asm/z80/string.h b/gbdk-lib/include/asm/z80/string.h @@ -128,4 +128,17 @@ int strncmp(const char *s1, const char *s2, int n) NONBANKED; */ char *strncpy(char *s1, const char *s2, int n) NONBANKED; +/** Compares buffers + + @param buf1 First buffer to compare + @param buf2 Second buffer to compare + @param count Buffer length + + Returns: + \li > 0 if __buf1__ > __buf2__ + \li 0 if __buf1__ == __buf2__ + \li < 0 if __buf1__ < __buf2__ +*/ +int memcmp(const void *buf1, const void *buf2, size_t count) __z88dk_callee; + #endif diff --git a/gbdk-lib/libc/asm/gbz80/Makefile b/gbdk-lib/libc/asm/gbz80/Makefile @@ -7,7 +7,7 @@ THIS = gbz80 ASSRC = __sdcc_call_hl.s abs.s mul.s div.s shift.s crt0_rle.s \ itoa.s strlen.s reverse.s labs.s ltoa.s \ setjmp.s atomic_flag_test_and_set.s \ - _memcpy.s _memset.s _strcmp.s _strcpy.s \ + _memcpy.s _memset.s _strcmp.s _strcpy.s _memcmp.s \ rand.s arand.s \ bcd.s diff --git a/gbdk-lib/libc/asm/gbz80/_memcmp.s b/gbdk-lib/libc/asm/gbz80/_memcmp.s @@ -0,0 +1,45 @@ + .module strcmp + + .area _HOME + +; int memcmp(const void *buf1, const void *buf2, size_t count) +_memcmp:: + lda hl,7(sp) + ld a,(hl-) + ld b, a + ld a,(hl-) + ld c, a + ld a,(hl-) + ld d, a + ld a,(hl-) + ld e, a + ld a,(hl-) + ld l,(hl) + ld h,a + + inc b + inc c + jr 3$ + +1$: + ld a,(de) + sub (hl) ; s1[i]==s2[i]? + jr nz, 2$ ; -> Different + + inc de + inc hl +3$: + dec c + jr nz, 1$ + dec b + jr nz, 1$ + + ld de, #0 + ret + +2$: + ld de,#-1 + ret c + + ld de,#1 + ret + diff --git a/gbdk-lib/libc/asm/z80/Makefile b/gbdk-lib/libc/asm/z80/Makefile @@ -10,7 +10,7 @@ ASSRC = __strreverse.s strcpy.s strlen.s \ mul.s mulchar.s \ __itoa.s __ltoa.s \ __uitobcd.s __ultobcd.s \ - memcpy.s memmove.s memset.s \ + memcpy.s memmove.s memset.s memcmp.s \ setjmp.s \ abs.s \ rand.s arand.s \ diff --git a/gbdk-lib/libc/asm/z80/memcmp.s b/gbdk-lib/libc/asm/z80/memcmp.s @@ -0,0 +1,38 @@ + .module strcmp + + .area _HOME + +; int memcmp(const void *buf1, const void *buf2, size_t count) +_memcmp:: + pop hl + pop de + pop bc + ex (sp), hl + ex de, hl + + inc d + inc e + jr 3$ + +1$: + ld a,(bc) + sub (hl) ; s1[i]==s2[i]? + jr nz, 2$ ; -> Different + + inc bc + inc hl +3$: + dec e + jr nz, 1$ + dec d + jr nz, 1$ + + ld hl, #0 + ret + +2$: + ld hl,#-1 + ret c + + ld hl,#1 + ret +

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.