From 8f5cfb6be14ad27ed4e411e0ab85653e70d11dd9 Mon Sep 17 00:00:00 2001 From: Blendi-Goose <87442375+Blendi-Goose@users.noreply.github.com> Date: Sun, 29 Jun 2025 11:05:59 +0200 Subject: [PATCH] lots of random little fixes --- src/components/gpu.c | 3 +++ src/neonucleus.h | 2 +- src/testLuaArch.c | 18 ++++++++++-------- src/unicode.c | 38 +++++++++++++++++++------------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/components/gpu.c b/src/components/gpu.c index 7ccca6b..946be58 100644 --- a/src/components/gpu.c +++ b/src/components/gpu.c @@ -140,9 +140,12 @@ void nni_gpu_set(nni_gpu *gpu, void *_, nn_component *component, nn_computer *co return; } + printf("It is to print: %s\n", s); + int current = 0; while(s[current] != 0) { int codepoint = nn_unicode_codepointAt(s, current); + printf("char rendered: %i\n", codepoint); nn_setPixel(gpu->currentScreen, x, y, nni_gpu_makePixel(gpu, s + current)); if(isVertical) { y++; diff --git a/src/neonucleus.h b/src/neonucleus.h index 30aa124..851b513 100644 --- a/src/neonucleus.h +++ b/src/neonucleus.h @@ -536,7 +536,7 @@ nn_component *nn_addDrive(nn_computer *computer, nn_address address, int slot, n typedef struct nn_screen nn_screen; typedef struct nn_scrchr_t { - int codepoint; + unsigned int codepoint; int fg; int bg; bool isFgPalette; diff --git a/src/testLuaArch.c b/src/testLuaArch.c index dc21ebd..642e476 100644 --- a/src/testLuaArch.c +++ b/src/testLuaArch.c @@ -42,23 +42,25 @@ nn_computer *testLuaArch_getComputer(lua_State *L) { } static nn_value testLuaArch_getValue(lua_State *L, int index) { - if(lua_isinteger(L, index)) { - return nn_values_integer(lua_tointeger(L, index)); - } - if(lua_isnumber(L, index)) { - return nn_values_number(lua_tonumber(L, index)); - } - if(lua_isboolean(L, index)) { + int type = lua_type(L, index); + + if(type == LUA_TBOOLEAN) { return nn_values_boolean(lua_toboolean(L, index)); } if(lua_isnoneornil(L, index)) { return nn_values_nil(); } - if(lua_isstring(L, index)) { + if(type == LUA_TSTRING) { size_t l = 0; const char *s = lua_tolstring(L, index, &l); return nn_values_string(s, l); } + if(type == LUA_TNUMBER && lua_isnumber(L, index)) { + return nn_values_number(lua_tonumber(L, index)); + } + if(type == LUA_TNUMBER && lua_isinteger(L, index)) { + return nn_values_integer(lua_tointeger(L, index)); + } //TODO: bring it back once I make everything else not leak memory //luaL_argcheck(L, false, index, luaL_typename(L, index)); return nn_values_nil(); diff --git a/src/unicode.c b/src/unicode.c index c91465b..32746d6 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -103,22 +103,22 @@ size_t nn_unicode_len(const char *b) { unsigned int nn_unicode_codepointAt(const char *s, size_t byteOffset) { unsigned int point = 0; const unsigned char *b = (const unsigned char *)s + byteOffset; - const unsigned int subpartMask = 0b111111; + const unsigned char subpartMask = 0b111111; // look into nn_unicode_codepointToChar as well. if(b[0] <= 0x7F) { return b[0]; } else if((b[0] >> 5) == 0b110) { - point += b[0] & 0b11111; - point += (b[1] & subpartMask) << 5; + point += ((unsigned int)(b[0] & 0b11111)) << 6; + point += ((unsigned int)(b[1] & subpartMask)); } else if((b[0] >> 4) == 0b1110) { - point += b[0] & 0b1111; - point += (b[1] & subpartMask) << 4; - point += (b[2] & subpartMask) << 10; + point += ((unsigned int)(b[0] & 0b1111)) << 12; + point += ((unsigned int)(b[1] & subpartMask)) << 6; + point += ((unsigned int)(b[2] & subpartMask)); } else if((b[0] >> 3) == 0b11110) { - point += b[0] & 0b111; - point += (b[1] & subpartMask) << 3; - point += (b[2] & subpartMask) << 9; - point += (b[3] & subpartMask) << 15; + point += ((unsigned int)(b[0] & 0b111)) << 18; + point += ((unsigned int)(b[1] & subpartMask)) << 12; + point += ((unsigned int)(b[2] & subpartMask)) << 6; + point += ((unsigned int)(b[3] & subpartMask)); } return point; } @@ -146,17 +146,17 @@ const char *nn_unicode_codepointToChar(unsigned int codepoint, size_t *len) { if (codepointSize == 1) { buffer[0] = (char)codepoint; } else if (codepointSize == 2) { - buffer[0] = 0b11000000 + (codepoint & 0b11111); - buffer[1] = 0b10000000 + (codepoint >> 5); + buffer[0] = 0b11000000 + ((codepoint >> 6) & 0b11111); + buffer[1] = 0b10000000 + (codepoint & 0b111111); } else if (codepointSize == 3) { - buffer[0] = 0b11100000 + (codepoint & 0b1111); - buffer[1] = 0b10000000 + ((codepoint >> 4) & 0b111111); - buffer[2] = 0b10000000 + (codepoint >> 10); + buffer[0] = 0b11100000 + ((codepoint >> 12) & 0b1111); + buffer[1] = 0b10000000 + ((codepoint >> 6) & 0b111111); + buffer[2] = 0b10000000 + (codepoint & 0b111111); } else if (codepointSize == 4) { - buffer[0] = 0b11110000 + (codepoint & 0b111); - buffer[1] = 0b10000000 + ((codepoint >> 3) & 0b111111); - buffer[2] = 0b10000000 + ((codepoint >> 9) & 0b111111); - buffer[3] = 0b10000000 + (codepoint >> 15); + buffer[0] = 0b11110000 + ((codepoint >> 18) & 0b111); + buffer[1] = 0b10000000 + ((codepoint >> 12) & 0b111111); + buffer[2] = 0b10000000 + ((codepoint >> 6) & 0b111111); + buffer[3] = 0b10000000 + (codepoint & 0b111111); } return buffer;