From 08d1751016d0d0cfdf0d30075997530428a3f426 Mon Sep 17 00:00:00 2001 From: ionut Date: Fri, 1 May 2026 22:40:51 +0300 Subject: [PATCH] Makefile --- .gitignore | 11 +++++++++ .gitmodules | 3 +++ Makefile | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ build/.gitkeep | 0 data/moirai | 1 + src/luaarch.c | 7 ++++-- src/main.c | 5 ++-- src/neonucleus.c | 10 -------- src/neonucleus.h | 12 ---------- 9 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 Makefile create mode 100644 build/.gitkeep create mode 160000 data/moirai diff --git a/.gitignore b/.gitignore index 3cd73c0..f8e22bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,16 @@ +# Zig stuff .zig-cache/ zig-out/ +# Data dir !data/.gitkeep +# Makefile build +build/* +!build/.gitkeep +# VScode slop .vscode/ +# Random logs some tools may output *.log +# Makefile output +/neonucleus +/libneonucleus.so +/libneonucleus.a diff --git a/.gitmodules b/.gitmodules index f0a124a..0a3a2d4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ path = foreign/lua52 url = https://github.com/lua/lua branch = v5-2 +[submodule "data/moirai"] + path = data/moirai + url = https://gitea.codersquack.nl/NeoFlock/moirai diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6d6dc3d --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +BIN=neonucleus +DYNLIB=libneonucleus.so +LIB=libneonucleus.a + +CC=cc +OPT=-O3 +SANITIZE= +DEBUG= +NNFLAGS= +CFLAGS=-fPIC $(OPT) $(SANITIZE) $(DEBUG) $(NNFLAGS) + +LD=$(CC) +LDFLAGS=$(OPT) $(DEBUG) + +AR=ar +RANLIB=ranlib + +LINKRAYLIB=-lraylib +INCLUA=-I /usr/include/lua5.3 +LINKLUA=-llua5.3 +LINKLIBM=-lm +LINKLIBC= + +BUILD_DIR=build +SRC_DIR=src + +$(BUILD_DIR)/neonucleus.o: $(SRC_DIR)/neonucleus.c $(SRC_DIR)/neonucleus.h + $(CC) -o $(BUILD_DIR)/neonucleus.o -c $(SRC_DIR)/neonucleus.c $(CFLAGS) + +$(BUILD_DIR)/ncomplib.o: $(SRC_DIR)/ncomplib.c $(SRC_DIR)/ncomplib.h + $(CC) -o $(BUILD_DIR)/ncomplib.o -c $(SRC_DIR)/ncomplib.c $(CFLAGS) + +nn: $(BUILD_DIR)/neonucleus.o $(BUILD_DIR)/ncomplib.o + +$(BUILD_DIR)/luaarch.o: $(SRC_DIR)/luaarch.c $(SRC_DIR)/machine.lua + $(CC) -o $(BUILD_DIR)/luaarch.o -c $(SRC_DIR)/luaarch.c $(CFLAGS) $(INCLUA) + +$(BUILD_DIR)/glyphcache.o: $(SRC_DIR)/glyphcache.c $(SRC_DIR)/glyphcache.h + $(CC) -o $(BUILD_DIR)/glyphcache.o -c $(SRC_DIR)/glyphcache.c $(CFLAGS) + +$(BUILD_DIR)/main.o: $(SRC_DIR)/main.c $(SRC_DIR)/minBIOS.lua + $(CC) -o $(BUILD_DIR)/main.o -c $(SRC_DIR)/main.c $(CFLAGS) $(INCLUA) + +bin: nn $(BUILD_DIR)/main.o $(BUILD_DIR)/luaarch.o $(BUILD_DIR)/glyphcache.o + $(LD) $(LDFLAGS) -o $(BIN) $(BUILD_DIR)/neonucleus.o $(BUILD_DIR)/ncomplib.o $(BUILD_DIR)/main.o $(BUILD_DIR)/glyphcache.o $(BUILD_DIR)/luaarch.o $(LINKLIBC) $(LINKLIBM) $(LINKRAYLIB) $(LINKLUA) + +lib: nn + $(AR) rc $(LIB) $(BUILD_DIR)/neonucleus.o $(BUILD_DIR)/ncomplib.o + $(RANLIB) $(LIB) + +dynlib: nn + $(LD) $(LDFLAGS) -o $(DYNLIB) -shared $(BUILD_DIR)/neonucleus.o $(BUILD_DIR)/ncomplib.o $(LINKLIBM) $(LINKLIBC) + +all: bin lib dynlib + +cleancache: + rm -rf $(BUILD_DIR)/*.o + +clean: + rm -rf $(BIN) $(DYNLIB) $(LIB) diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/moirai b/data/moirai new file mode 160000 index 0000000..b2f7573 --- /dev/null +++ b/data/moirai @@ -0,0 +1 @@ +Subproject commit b2f75735a17a5ad62f4c7d296bdeffcfe3879013 diff --git a/src/luaarch.c b/src/luaarch.c index 807a643..f20ccf6 100644 --- a/src/luaarch.c +++ b/src/luaarch.c @@ -651,15 +651,18 @@ static nn_Exit luaArch_handler(nn_ArchitectureRequest *req) { nn_Computer *computer = req->computer; luaArch *arch = req->localState; nn_Context *ctx = nn_getComputerContext(computer); + // the memory scale, used to give Lua extra memory in 64-bit systems + // due to it also using more memory. + double memScale = sizeof(void *) > 4 ? 1.8 : 1; switch(req->action) { case NN_ARCH_FREEMEM: - req->freeMemory = arch->freeMem / nn_getMemoryScale(computer); + req->freeMemory = arch->freeMem / memScale; return NN_OK; case NN_ARCH_INIT: // wrapped in a block to prevent L from leaking, because L is common in Lua code so it may be used by mistake { arch = nn_alloc(ctx, sizeof(*arch)); - arch->freeMem = nn_getTotalMemory(computer) * nn_getMemoryScale(computer); + arch->freeMem = nn_getTotalMemory(computer) * memScale; arch->computer = computer; #if LUA_VERSION_NUM >= 505L lua_State *L = lua_newstate(luaArch_alloc, arch, rand()); diff --git a/src/main.c b/src/main.c index 95dd01a..ece174f 100644 --- a/src/main.c +++ b/src/main.c @@ -447,6 +447,7 @@ int main(int argc, char **argv) { nn_Component *testDrive = ncl_createDrive(u, NULL, &nn_defaultDrives[3], testDriveData, strlen(testDriveData), false); nn_Component *testFlash = ncl_createFlash(u, NULL, &nn_defaultSSDs[3], testDriveData, strlen(testDriveData), false); + ncl_setCLabel(eepromCard, "EEPROM"); ncl_setCLabel(managedfs, "Main Filesystem"); ncl_setCLabel(testingfs, "Secondary Filesystem"); ncl_setCLabel(testDrive, "Unmanaged Storage"); @@ -454,6 +455,7 @@ int main(int argc, char **argv) { size_t ramTotal = 0; ramTotal += 4 * nn_ramSizes[5]; + //ramTotal += nn_ramSizes[0]; SetExitKey(KEY_NULL); @@ -495,9 +497,6 @@ int main(int argc, char **argv) { } nn_setCallBudget(c, 0); - // default for 64-bit - if(sizeof(void *) > 4) nn_setMemoryScale(c, 1.8); - nn_setArchitecture(c, &arch); nn_addSupportedArchitecture(c, &arch); diff --git a/src/neonucleus.c b/src/neonucleus.c index 2835d8e..651d5c6 100644 --- a/src/neonucleus.c +++ b/src/neonucleus.c @@ -1056,7 +1056,6 @@ typedef struct nn_Computer { size_t signalCount; size_t userCount; double idleTimestamp; - double memoryScale; nn_Beep beep; nn_Value callstack[NN_MAX_STACK]; char errorBuffer[NN_MAX_ERROR_SIZE]; @@ -1180,7 +1179,6 @@ nn_Computer *nn_createComputer(nn_Universe *universe, void *userdata, const char c->signalCount = 0; c->userCount = 0; c->idleTimestamp = 0; - c->memoryScale = 1; // set to empty string c->errorBuffer[0] = '\0'; nn_clearComputerBeep(c); @@ -1447,14 +1445,6 @@ void nn_setEnergyHandler(nn_Computer *computer, void *energyState, nn_EnergyHand computer->energyHandler = handler; } -void nn_setMemoryScale(nn_Computer *computer, double scale) { - computer->memoryScale = scale; -} - -double nn_getMemoryScale(nn_Computer *computer) { - return computer->memoryScale; -} - size_t nn_getTotalMemory(nn_Computer *computer) { return computer->totalMemory; } diff --git a/src/neonucleus.h b/src/neonucleus.h index a24f266..46fc672 100644 --- a/src/neonucleus.h +++ b/src/neonucleus.h @@ -451,18 +451,6 @@ const char *nn_getComputerAddress(nn_Computer *computer); nn_Universe *nn_getComputerUniverse(nn_Computer *computer); nn_Context *nn_getUniverseContext(nn_Universe *universe); nn_Context *nn_getComputerContext(nn_Computer *computer); -// Sets the memory scale, which defaults to 1. -// For context, OC will set the memory scale to 1.8 on 64-bit systems by default. -// This scale affects how much real-world memory an amount of VM actually takes up. -// This means if the total memory is 4 MiB, and the scale is set to 2, the computer can take up to 8MiB of actual RAM. -// However, nn_getTotalMemory() will still return 4 MiB. -// The architecture is meant to ensure that the reported free memory is also scaled. As in, the real-world free memory -// is divided by this scale to ensure it is within the correct range. -// It is undefined behavior to change the memory scale *after* the first call to nn_tick(). -// Some architectures may ignore this, if they are very low-level and thus -// do not have any implicit changes of sizes between 32-bit and 64-bit. -void nn_setMemoryScale(nn_Computer *computer, double scale); -double nn_getMemoryScale(nn_Computer *computer); // Returns the memory usage limit of the computer. size_t nn_getTotalMemory(nn_Computer *computer);