lots of random little fixes

This commit is contained in:
Blendi-Goose 2025-06-29 11:05:59 +02:00
parent 0c2727c9a7
commit 8f5cfb6be1
4 changed files with 33 additions and 28 deletions

View File

@ -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++;

View File

@ -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;

View File

@ -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();

View File

@ -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;