From 86cd9b98d47314bea170693fc40c3e80d835bfc9 Mon Sep 17 00:00:00 2001 From: Lephe Date: Thu, 19 Sep 2019 15:59:38 +0200 Subject: [PATCH] small improvements * Update TOTO list * Change the type of gint_vbr to comply with a new warning in GCC 9 * Add strcmp() --- TODO | 5 ++--- include/gint/std/string.h | 7 +++++-- src/core/setup.c | 2 +- src/std/string.c | 20 +++++++++++++------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 34bcdd2..2694055 100644 --- a/TODO +++ b/TODO @@ -13,13 +13,12 @@ Complementary elements on existing code. * topti: support unicode fonts * gray: find good values for more models than the Graph 35+E II * render: get rid of GINT_NEED_VRAM and #define vram gint_vram if you need -* dma: dma_memcpy() and dma_memset(), possibly requiring alignment * dma: maybe relax the 4-byte size constraint for dma_memset() -* core: try to leave add-in without reset in case of fatal exception +* core: try to leave add-in without reset in case of panic * topti: support Unicode fonts * hardware: fill in the HWMEM_FITTLB flag * keyboard: think of extended functions -* keyboard: add an intermediate-level API with some sort of IsKeyDown() +* keyboard: implement keydown() in an event-compliant way * cpg: spread spectrum on fxcg50 * bopti: blending modes for monochrome bitmaps (use topti assembler) * display: use more of topti's assembler in drect() diff --git a/include/gint/std/string.h b/include/gint/std/string.h index 1b90209..f16f90c 100644 --- a/include/gint/std/string.h +++ b/include/gint/std/string.h @@ -16,10 +16,13 @@ void *memset(void *dest, int byte, size_t n); /* strlen(): Length of a NUL-terminated string */ size_t strlen(char const *str); -/* strncpy(): Copy a string with a size limit*/ +/* strncpy(): Copy a string with a size limit */ char *strncpy(char *dst, char const *src, size_t n); -/* strcat(): Concatenation of src in dest*/ +/* strcat(): Concatenation a string to a pre-allocated space */ char *strcat(char *dest, const char *src); +/* strcmp(): Compare NUL-terminated strings */ +int strcmp(char const *s1, char const *s2); + #endif /* GINT_STD_STRING */ diff --git a/src/core/setup.c b/src/core/setup.c index a2b6efb..03216f7 100644 --- a/src/core/setup.c +++ b/src/core/setup.c @@ -10,7 +10,7 @@ #include /* VBR address, from the linker script */ -extern char gint_vbr; +extern char gint_vbr[]; /* System's VBR address */ GBSS static uint32_t system_vbr; /* Size of exception and TLB handler */ diff --git a/src/std/string.c b/src/std/string.c index 85bc175..0b771f7 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -6,24 +6,30 @@ #include #include -GWEAK size_t strlen(const char *str) +GWEAK size_t strlen(char const *str) { int len = 0; while(str[len]) len++; return len; } -GWEAK char *strncpy(char *dst, const char *src, size_t n) +GWEAK char *strncpy(char *dst, char const *src, size_t n) { size_t i = 0; while(i < n && (dst[i] = src[i])) i++; return dst; } -GWEAK char *strcat(char *dest, const char *src) +GWEAK char *strcat(char *dest, char const *src) { - unsigned long fin_dest = strlen(dest); - unsigned int i; - for (i = 0 ; i <= strlen(src) ; i++) dest[fin_dest + i] = src[i]; - return dest; + unsigned long fin_dest = strlen(dest); + unsigned int i; + for (i = 0 ; i <= strlen(src) ; i++) dest[fin_dest + i] = src[i]; + return dest; +} + +GWEAK int strcmp(char const *s1, char const *s2) +{ + while(*s1 && *s1 == *s2) s1++, s2++; + return *s1 - *s2; }