From 55bcdf37342d782c723166de54ff031d09b1281f Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Wed, 15 Oct 2025 19:32:21 -0700 Subject: Clear framebuffer to pink --- src/string.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/string.c (limited to 'src/string.c') diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..4801154 --- /dev/null +++ b/src/string.c @@ -0,0 +1,59 @@ +#include + +#include + +void* memcpy(void* dst, const void* src, size_t count) { + // TODO: Can probably use better implementations based on hw instruction set. + uint32_t* dst32 = (uint32_t*)dst; + const uint32_t* src32 = (uint32_t*)src; + for(; count >= 4; count -= 4) { + *dst32++ = *src32++; + } + uint8_t* dst8 = (uint8_t*)dst32; + const uint8_t* src8 = (uint8_t*)src32; + for(; count != 0; count--) { + *dst8++ = *src8++; + } + return dst8; +} + +static int count_digits_u(unsigned int x) { + int count = 0; + for(; x != 0; x /= 10, count++); + return count; +} + +char* utoa(unsigned int x, char* buffer, size_t size) { + if (size > 0) { + const int num_digits = count_digits_u(x); + size_t i = 0; + while ((x != 0) && ((i+1) < size)) { + const unsigned int digit = x % 10; + x /= 10; + buffer[num_digits-1 - i++] = '0' + digit; + } + buffer[i] = 0; + } + return buffer; +} + +char* ptoa(const void* ptr, char* buffer, size_t size) { + if (size > 2) { + size_t i = 0; + buffer[i++] = '0'; + buffer[i++] = 'x'; + uintptr_t x = (uintptr_t)ptr; + const int num_digits = count_digits_u(x); + while ((x != 0) && (i < size)) { + const unsigned int digit = x % 16; + x /= 16; + const char hex = (digit < 10) ? ('0' + digit) : ('a' + (digit-10)); + buffer[num_digits-1+2 - i++] = hex; + } + buffer[i] = 0; + } else if (size > 0) { + buffer[0] = 0; + } + return buffer; +} + -- cgit v1.2.3