From 433ef4aa31668bbf6debf79cd9cc4a972cfae6de Mon Sep 17 00:00:00 2001 From: ionut Date: Fri, 1 May 2026 02:14:21 +0300 Subject: [PATCH] mineos and halyde support --- src/machine.lua | 11 +++++++- src/main.c | 66 +++++++++++++++++++++++++++++++----------------- src/neonucleus.c | 2 +- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/machine.lua b/src/machine.lua index 0d8dea4..df605b8 100644 --- a/src/machine.lua +++ b/src/machine.lua @@ -187,6 +187,7 @@ end function computer.pullSignal(timeout) timeout = timeout or math.huge + timeout = math.max(timeout, 0.05) local deadline = computer.uptime() + timeout while true do if computer.uptime() >= deadline then return end @@ -350,7 +351,15 @@ sandbox = { os = { clock = os.clock, - date = os.date, + date = function(a, b, ...) + if type(a) == "number" then + a = math.floor(a) + end + if type(b) == "number" then + b = math.floor(b) + end + return os.date(a, b, ...) + end, difftime = os.difftime, time = os.time, }, diff --git a/src/main.c b/src/main.c index 3c4cbfa..e7d0a20 100644 --- a/src/main.c +++ b/src/main.c @@ -393,7 +393,8 @@ int main(int argc, char **argv) { char mainfspath[NN_MAX_PATH]; snprintf(mainfspath, NN_MAX_PATH, "data/%s", mainDir); nn_Component *managedfs = ncl_createFilesystem(u, NULL, mainfspath, &mainfsconf, true); - nn_Component *tmpfs = ncl_createTmpFS(u, NULL, &nn_defaultTmpFS, NCL_FILECOST_DEFAULT, false); + //nn_Component *tmpfs = ncl_createTmpFS(u, NULL, &nn_defaultTmpFS, NCL_FILECOST_DEFAULT, false); + nn_Component *tmpfs = ncl_createFilesystem(u, NULL, "/tmp", &mainfsconf, false); nn_Component *testingfs = ncl_createTmpFS(u, NULL, &nn_defaultFilesystems[3], NCL_FILECOST_DEFAULT, false); //nn_Component *testingfs = ncl_createFilesystem(u, NULL, "test", &nn_defaultFilesystems[3], false); @@ -431,7 +432,7 @@ int main(int argc, char **argv) { ncl_setCLabel(testFlash, "Flash Storage"); size_t ramTotal = 0; - ramTotal += nn_ramSizes[5]; + ramTotal += 4 * nn_ramSizes[5]; SetExitKey(KEY_NULL); @@ -457,8 +458,8 @@ int main(int argc, char **argv) { double nextSecond = 0; double wattage = 0; - nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[3]); - nn_Component *gpuCard = ncl_createGPU(u, NULL, &nn_defaultGPUs[3]); + nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[2]); + nn_Component *gpuCard = ncl_createGPU(u, NULL, &nn_defaultGPUs[2]); nn_Component *keyboard = nn_createComponent( u, "mainKB", "keyboard"); @@ -479,12 +480,12 @@ int main(int argc, char **argv) { nn_setArchitecture(c, &arch); nn_addSupportedArchitecture(c, &arch); - //nn_setTmpAddress(c, nn_getComponentAddress(tmpfs)); + nn_setTmpAddress(c, nn_getComponentAddress(tmpfs)); nn_mountComponent(c, wrappedC, 255, false); nn_mountComponent(c, screen, -1, false); nn_mountComponent(c, ocelotCard, -1, false); - //nn_mountComponent(c, tmpfs, -1, false); + nn_mountComponent(c, tmpfs, -1, false); nn_mountComponent(c, keyboard, -1, false); nn_mountComponent(c, eepromCard, 0, false); nn_mountComponent(c, managedfs, 1, false); @@ -492,24 +493,22 @@ int main(int argc, char **argv) { nn_mountComponent(c, testingfs, 3, false); nn_mountComponent(c, testDrive, 4, false); nn_mountComponent(c, testFlash, 5, false); + int ltx = 0, lty = 0; while(true) { if(WindowShouldClose()) break; BeginDrawing(); ClearBackground(BLACK); - // drawing the screen + // drawing the screen + screen events { + const char *scraddr = nn_getComponentAddress(screen); ncl_ScreenState *scrbuf = nn_getComponentState(screen); ncl_lockScreen(scrbuf); size_t scrw, scrh; ncl_getScreenViewport(scrbuf, &scrw, &scrh); ncl_ScreenFlags scrflags = ncl_getScreenFlags(scrbuf); - if((scrflags & NCL_SCREEN_ON) == 0) { - ncl_unlockScreen(scrbuf); - goto skipDrawScreen; - } int cheight = GetScreenHeight() / scrh; if(cheight != ncl_cellHeight(gc)) { @@ -521,25 +520,46 @@ int main(int argc, char **argv) { int offY = (GetScreenHeight() - cheight * scrh) / 2; double scrbright = ncl_getScreenBrightness(scrbuf); - for(int y = 1; y <= scrh; y++) { - for(int x = 1; x <= scrw; x++) { - ncl_Pixel p = ncl_getScreenPixel(scrbuf, x, y); - Vector2 pos = { - offX + (x - 1) * cwidth, - offY + (y - 1) * cheight, - }; - ncl_needGlyph(gc, p.codepoint); - DrawRectangle(pos.x, pos.y, cwidth, cheight, ne_processColor(p.bgColor, scrbright)); - if(p.codepoint != 0) { - ncl_drawGlyph(gc, p.codepoint, pos, cheight, ne_processColor(p.fgColor, scrbright)); + if(scrflags & NCL_SCREEN_ON) { + for(int y = 1; y <= scrh; y++) { + for(int x = 1; x <= scrw; x++) { + ncl_Pixel p = ncl_getScreenPixel(scrbuf, x, y); + Vector2 pos = { + offX + (x - 1) * cwidth, + offY + (y - 1) * cheight, + }; + ncl_needGlyph(gc, p.codepoint); + DrawRectangle(pos.x, pos.y, cwidth, cheight, ne_processColor(p.bgColor, scrbright)); + if(p.codepoint != 0) { + ncl_drawGlyph(gc, p.codepoint, pos, cheight, ne_processColor(p.fgColor, scrbright)); + } } } } DrawRectangleLines(offX, offY, cwidth * scrw, cheight * scrh, WHITE); ncl_unlockScreen(scrbuf); ncl_flushGlyphs(gc); + + int tx = (double)(GetMouseX() - offX) / cwidth + 1; + int ty = (double)(GetMouseY() - offY) / cheight + 1; + + if(tx >= 1 && ty >= 1 && tx <= scrw && ty <= scrh) { + // we only care about left click here + if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + nn_pushTouch(c, scraddr, tx, ty, 0, player); + } + if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { + nn_pushDrop(c, scraddr, tx, ty, 0, player); + } + if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { + if(ltx != tx || lty != ty) { + ltx = tx; + lty = ty; + nn_pushDrag(c, scraddr, tx, ty, 0, player); + } + } + } } -skipDrawScreen:; int statY = 10; if(sand.buf != NULL) { diff --git a/src/neonucleus.c b/src/neonucleus.c index 751130e..898432a 100644 --- a/src/neonucleus.c +++ b/src/neonucleus.c @@ -3406,7 +3406,7 @@ nn_Exit nn_pushDrag(nn_Computer *computer, const char *screenAddress, double x, nn_Exit nn_pushDrop(nn_Computer *computer, const char *screenAddress, double x, double y, int button, const char *player) { if(!nn_hasUser(computer, player)) return NN_OK; - nn_Exit err = nn_pushstring(computer, "drag"); + nn_Exit err = nn_pushstring(computer, "drop"); if(err) return err; err = nn_pushstring(computer, screenAddress); if(err) return err;