mineos and halyde support

This commit is contained in:
2026-05-01 02:14:21 +03:00
parent 27056d8a76
commit 433ef4aa31
3 changed files with 54 additions and 25 deletions

View File

@@ -187,6 +187,7 @@ end
function computer.pullSignal(timeout) function computer.pullSignal(timeout)
timeout = timeout or math.huge timeout = timeout or math.huge
timeout = math.max(timeout, 0.05)
local deadline = computer.uptime() + timeout local deadline = computer.uptime() + timeout
while true do while true do
if computer.uptime() >= deadline then return end if computer.uptime() >= deadline then return end
@@ -350,7 +351,15 @@ sandbox = {
os = { os = {
clock = os.clock, 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, difftime = os.difftime,
time = os.time, time = os.time,
}, },

View File

@@ -393,7 +393,8 @@ int main(int argc, char **argv) {
char mainfspath[NN_MAX_PATH]; char mainfspath[NN_MAX_PATH];
snprintf(mainfspath, NN_MAX_PATH, "data/%s", mainDir); snprintf(mainfspath, NN_MAX_PATH, "data/%s", mainDir);
nn_Component *managedfs = ncl_createFilesystem(u, NULL, mainfspath, &mainfsconf, true); 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_createTmpFS(u, NULL, &nn_defaultFilesystems[3], NCL_FILECOST_DEFAULT, false);
//nn_Component *testingfs = ncl_createFilesystem(u, NULL, "test", &nn_defaultFilesystems[3], 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"); ncl_setCLabel(testFlash, "Flash Storage");
size_t ramTotal = 0; size_t ramTotal = 0;
ramTotal += nn_ramSizes[5]; ramTotal += 4 * nn_ramSizes[5];
SetExitKey(KEY_NULL); SetExitKey(KEY_NULL);
@@ -457,8 +458,8 @@ int main(int argc, char **argv) {
double nextSecond = 0; double nextSecond = 0;
double wattage = 0; double wattage = 0;
nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[3]); nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[2]);
nn_Component *gpuCard = ncl_createGPU(u, NULL, &nn_defaultGPUs[3]); nn_Component *gpuCard = ncl_createGPU(u, NULL, &nn_defaultGPUs[2]);
nn_Component *keyboard = nn_createComponent( nn_Component *keyboard = nn_createComponent(
u, "mainKB", "keyboard"); u, "mainKB", "keyboard");
@@ -479,12 +480,12 @@ int main(int argc, char **argv) {
nn_setArchitecture(c, &arch); nn_setArchitecture(c, &arch);
nn_addSupportedArchitecture(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, wrappedC, 255, false);
nn_mountComponent(c, screen, -1, false); nn_mountComponent(c, screen, -1, false);
nn_mountComponent(c, ocelotCard, -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, keyboard, -1, false);
nn_mountComponent(c, eepromCard, 0, false); nn_mountComponent(c, eepromCard, 0, false);
nn_mountComponent(c, managedfs, 1, 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, testingfs, 3, false);
nn_mountComponent(c, testDrive, 4, false); nn_mountComponent(c, testDrive, 4, false);
nn_mountComponent(c, testFlash, 5, false); nn_mountComponent(c, testFlash, 5, false);
int ltx = 0, lty = 0;
while(true) { while(true) {
if(WindowShouldClose()) break; if(WindowShouldClose()) break;
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
// drawing the screen // drawing the screen + screen events
{ {
const char *scraddr = nn_getComponentAddress(screen);
ncl_ScreenState *scrbuf = nn_getComponentState(screen); ncl_ScreenState *scrbuf = nn_getComponentState(screen);
ncl_lockScreen(scrbuf); ncl_lockScreen(scrbuf);
size_t scrw, scrh; size_t scrw, scrh;
ncl_getScreenViewport(scrbuf, &scrw, &scrh); ncl_getScreenViewport(scrbuf, &scrw, &scrh);
ncl_ScreenFlags scrflags = ncl_getScreenFlags(scrbuf); ncl_ScreenFlags scrflags = ncl_getScreenFlags(scrbuf);
if((scrflags & NCL_SCREEN_ON) == 0) {
ncl_unlockScreen(scrbuf);
goto skipDrawScreen;
}
int cheight = GetScreenHeight() / scrh; int cheight = GetScreenHeight() / scrh;
if(cheight != ncl_cellHeight(gc)) { if(cheight != ncl_cellHeight(gc)) {
@@ -521,25 +520,46 @@ int main(int argc, char **argv) {
int offY = (GetScreenHeight() - cheight * scrh) / 2; int offY = (GetScreenHeight() - cheight * scrh) / 2;
double scrbright = ncl_getScreenBrightness(scrbuf); double scrbright = ncl_getScreenBrightness(scrbuf);
for(int y = 1; y <= scrh; y++) { if(scrflags & NCL_SCREEN_ON) {
for(int x = 1; x <= scrw; x++) { for(int y = 1; y <= scrh; y++) {
ncl_Pixel p = ncl_getScreenPixel(scrbuf, x, y); for(int x = 1; x <= scrw; x++) {
Vector2 pos = { ncl_Pixel p = ncl_getScreenPixel(scrbuf, x, y);
offX + (x - 1) * cwidth, Vector2 pos = {
offY + (y - 1) * cheight, 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)); ncl_needGlyph(gc, p.codepoint);
if(p.codepoint != 0) { DrawRectangle(pos.x, pos.y, cwidth, cheight, ne_processColor(p.bgColor, scrbright));
ncl_drawGlyph(gc, p.codepoint, pos, cheight, ne_processColor(p.fgColor, 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); DrawRectangleLines(offX, offY, cwidth * scrw, cheight * scrh, WHITE);
ncl_unlockScreen(scrbuf); ncl_unlockScreen(scrbuf);
ncl_flushGlyphs(gc); 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; int statY = 10;
if(sand.buf != NULL) { if(sand.buf != NULL) {

View File

@@ -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) { 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; 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; if(err) return err;
err = nn_pushstring(computer, screenAddress); err = nn_pushstring(computer, screenAddress);
if(err) return err; if(err) return err;