big progress on baremetal

This commit is contained in:
2025-07-09 18:07:27 +02:00
parent 6159339545
commit 779d5a0c19
16 changed files with 166 additions and 111 deletions

View File

@@ -1,5 +1,4 @@
#include "../neonucleus.h"
#include <string.h>
void nn_drive_destroy(void *_, nn_component *component, nn_drive *drive) {
if(!nn_decRef(&drive->refc)) return;

View File

@@ -1,5 +1,4 @@
#include "../neonucleus.h"
#include <string.h>
void nn_fs_destroy(void *_, nn_component *component, nn_filesystem *fs) {
if(!nn_decRef(&fs->refc)) return;
@@ -9,12 +8,12 @@ void nn_fs_destroy(void *_, nn_component *component, nn_filesystem *fs) {
}
}
bool nn_fs_illegalPath(const char *path) {
nn_bool_t nn_fs_illegalPath(const char *path) {
// absolute disaster
const char *illegal = "\"\\:*?<>|";
for(size_t i = 0; illegal[i] != '\0'; i++) {
if(strchr(path, illegal[i]) != NULL) return true;
if(nn_strchr(path, illegal[i]) != NULL) return true;
}
return false;
}
@@ -271,7 +270,7 @@ void nn_fs_list(nn_filesystem *fs, void *_, nn_component *component, nn_computer
// operation succeeded
nn_value arr = nn_values_array(alloc, fileCount);
for(size_t i = 0; i < fileCount; i++) {
nn_values_set(arr, i, nn_values_string(alloc, files[i], strlen(files[i])));
nn_values_set(arr, i, nn_values_string(alloc, files[i], nn_strlen(files[i])));
nn_deallocStr(alloc, files[i]);
}
nn_dealloc(alloc, files, sizeof(char *) * fileCount);
@@ -310,7 +309,7 @@ void nn_fs_close(nn_filesystem *fs, void *_, nn_component *component, nn_compute
nn_value fdValue = nn_getArgument(computer, 0);
size_t fd = nn_toInt(fdValue);
bool closed = fs->close(component, fs->userdata, fd);
nn_bool_t closed = fs->close(component, fs->userdata, fd);
nn_return(computer, nn_values_boolean(closed));
// do not ask where it comes from, balance is hard
@@ -331,7 +330,7 @@ void nn_fs_write(nn_filesystem *fs, void *_, nn_component *component, nn_compute
return;
}
bool closed = fs->write(component, fs->userdata, fd, buf, len);
nn_bool_t closed = fs->write(component, fs->userdata, fd, buf, len);
nn_return(computer, nn_values_boolean(closed));
// do not ask where it comes from, balance is hard
@@ -368,11 +367,11 @@ void nn_fs_read(nn_filesystem *fs, void *_, nn_component *component, nn_computer
nn_fs_seekCost(fs, nn_fs_countChunks(fs, readLen, component), component, computer);
}
bool nn_fs_validWhence(const char *s) {
nn_bool_t nn_fs_validWhence(const char *s) {
return
strcmp(s, "set") == 0 ||
strcmp(s, "cur") == 0 ||
strcmp(s, "end") == 0;
nn_strcmp(s, "set") == 0 ||
nn_strcmp(s, "cur") == 0 ||
nn_strcmp(s, "end") == 0;
}
void nn_fs_seek(nn_filesystem *fs, void *_, nn_component *component, nn_computer *computer) {

View File

@@ -8,12 +8,12 @@ typedef struct nni_gpu {
nn_gpuControl ctrl;
int currentFg;
int currentBg;
bool isFgPalette;
bool isBgPalette;
nn_bool_t isFgPalette;
nn_bool_t isBgPalette;
// TODO: think about buffers and stuff
} nni_gpu;
bool nni_samePixel(nn_scrchr_t a, nn_scrchr_t b) {
nn_bool_t nni_samePixel(nn_scrchr_t a, nn_scrchr_t b) {
return
a.codepoint == b.codepoint &&
a.fg == b.fg &&
@@ -23,7 +23,7 @@ bool nni_samePixel(nn_scrchr_t a, nn_scrchr_t b) {
;
}
bool nni_inBounds(nni_gpu *gpu, int x, int y) {
nn_bool_t nni_inBounds(nni_gpu *gpu, int x, int y) {
if(gpu->currentScreen == NULL) return false;
return
x >= 0 &&
@@ -77,7 +77,7 @@ void nni_gpu_bind(nni_gpu *gpu, void *_, nn_component *component, nn_computer *c
nn_setCError(computer, "bad argument #1 (address expected)");
return;
}
bool reset = false;
nn_bool_t reset = false;
if(resetVal.tag == NN_VALUE_BOOL) reset = nn_toBoolean(resetVal);
nn_component *c = nn_findComponent(computer, (nn_address)addr);
@@ -124,7 +124,7 @@ void nni_gpu_set(nni_gpu *gpu, void *_, nn_component *component, nn_computer *co
int x = nn_toInt(nn_getArgument(computer, 0)) - 1;
int y = nn_toInt(nn_getArgument(computer, 1)) - 1;
const char *s = nn_toCString(nn_getArgument(computer, 2));
bool isVertical = nn_toBoolean(nn_getArgument(computer, 3));
nn_bool_t isVertical = nn_toBoolean(nn_getArgument(computer, 3));
if(s == NULL) {
nn_setCError(computer, "bad argument #3 (string expected in set)");
@@ -201,7 +201,7 @@ void nni_gpu_setResolution(nni_gpu *gpu, void *_, nn_component *component, nn_co
int w = nn_toInt(nn_getArgument(computer, 0));
int h = nn_toInt(nn_getArgument(computer, 1));
bool changed = w != lw || h != lh;
nn_bool_t changed = w != lw || h != lh;
if(w <= 0) w = 1;
if(h <= 0) h = 1;
@@ -224,7 +224,7 @@ void nni_gpu_setResolution(nni_gpu *gpu, void *_, nn_component *component, nn_co
void nni_gpu_setBackground(nni_gpu *gpu, void *_, nn_component *component, nn_computer *computer) {
if(gpu->currentScreen == NULL) return;
int color = nn_toInt(nn_getArgument(computer, 0));
bool isPalette = nn_toBoolean(nn_getArgument(computer, 1));
nn_bool_t isPalette = nn_toBoolean(nn_getArgument(computer, 1));
if(isPalette && (color < 0 || color >= gpu->currentScreen->paletteColors)) {
nn_setCError(computer, "invalid palette index");
@@ -256,7 +256,7 @@ void nni_gpu_getBackground(nni_gpu *gpu, void *_, nn_component *component, nn_co
void nni_gpu_setForeground(nni_gpu *gpu, void *_, nn_component *component, nn_computer *computer) {
if(gpu->currentScreen == NULL) return;
int color = nn_toInt(nn_getArgument(computer, 0));
bool isPalette = nn_toBoolean(nn_getArgument(computer, 1));
nn_bool_t isPalette = nn_toBoolean(nn_getArgument(computer, 1));
if(isPalette && (color < 0 || color >= gpu->currentScreen->paletteColors)) {
nn_setCError(computer, "invalid palette index");

View File

@@ -173,35 +173,35 @@ nn_scrchr_t nn_getPixel(nn_screen *screen, int x, int y) {
return screen->buffer[x + y * screen->maxWidth];
}
bool nn_isDirty(nn_screen *screen) {
nn_bool_t nn_isDirty(nn_screen *screen) {
return screen->isDirty;
}
void nn_setDirty(nn_screen *screen, bool dirty) {
void nn_setDirty(nn_screen *screen, nn_bool_t dirty) {
screen->isDirty = dirty;
}
bool nn_isPrecise(nn_screen *screen) {
nn_bool_t nn_isPrecise(nn_screen *screen) {
return screen->isPrecise;
}
void nn_setPrecise(nn_screen *screen, bool precise) {
void nn_setPrecise(nn_screen *screen, nn_bool_t precise) {
screen->isPrecise = precise;
}
bool nn_isTouchModeInverted(nn_screen *screen) {
nn_bool_t nn_isTouchModeInverted(nn_screen *screen) {
return screen->isTouchModeInverted;
}
void nn_setTouchModeInverted(nn_screen *screen, bool touchModeInverted) {
void nn_setTouchModeInverted(nn_screen *screen, nn_bool_t touchModeInverted) {
screen->isTouchModeInverted = touchModeInverted;
}
bool nn_isOn(nn_screen *buffer) {
nn_bool_t nn_isOn(nn_screen *buffer) {
return buffer->isOn;
}
void nn_setOn(nn_screen *buffer, bool on) {
void nn_setOn(nn_screen *buffer, nn_bool_t on) {
buffer->isOn = on;
}
@@ -310,9 +310,9 @@ void nn_getStd8BitPalette(int color[256]) {
}
static int nni_4bit_colors[16];
static bool nni_4bit_did = false;
static nn_bool_t nni_4bit_did = false;
static int nni_8bit_colors[256];
static bool nni_8bit_did = false;
static nn_bool_t nni_8bit_did = false;
int nn_mapDepth(int color, int depth) {
if(depth == 1) {

View File

@@ -21,10 +21,10 @@ typedef struct nn_screen {
int *palette;
int aspectRatioWidth;
int aspectRatioHeight;
bool isOn;
bool isTouchModeInverted;
bool isPrecise;
bool isDirty;
nn_bool_t isOn;
nn_bool_t isTouchModeInverted;
nn_bool_t isPrecise;
nn_bool_t isDirty;
nn_address keyboards[NN_MAX_SCREEN_KEYBOARDS];
size_t keyboardCount;
} nn_screen;