This commit is contained in:
2026-05-01 22:40:51 +03:00
parent d1e2f6c770
commit 08d1751016
9 changed files with 82 additions and 27 deletions

11
.gitignore vendored
View File

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

3
.gitmodules vendored
View File

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

60
Makefile Normal file
View File

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

0
build/.gitkeep Normal file
View File

1
data/moirai Submodule

Submodule data/moirai added at b2f75735a1

View File

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

View File

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

View File

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

View File

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