diff --git a/src/main/org/neoflock/NeoNucleus/NativeBindings.java b/src/main/org/neoflock/NeoNucleus/NativeBindings.java index 4c8cda3..e1f5aa9 100644 --- a/src/main/org/neoflock/NeoNucleus/NativeBindings.java +++ b/src/main/org/neoflock/NeoNucleus/NativeBindings.java @@ -19,11 +19,14 @@ public class NativeBindings { nn_Universe universe = nn_createUniverse(ctx); nn_Architecture arch = getLuaArch(); nn_EEPROM eeprom = new nn_EEPROM(2048, 2048, 1, 1, 1, 1, 1, 1); + eeprom.allocate(); nn_Component eepromCard = ncl_createEEPROM(universe, UUID.randomUUID().toString(), eeprom, "error('amog us')", false); + eeprom.free(); nn_Computer computer = nn_createComputer(universe, UUID.randomUUID().toString(), 4096, 100, 100); nn_setCallBudget(computer, 0); nn_setArchitecture(computer, arch); nn_addSupportedArchitecture(computer, arch); + nn_mountComponent(computer, eepromCard, 0, false); nn_Exit e = nn_tick(computer); if (e != nn_Exit.NN_OK) { System.out.println("NN tick error: " + nn_getError(computer)); @@ -35,26 +38,26 @@ public class NativeBindings { return; } nn_ComputerState state = nn_getComputerState(computer); - /*if(state == nn_Exit.NN_POWEROFF) break; - if(state == nn_Exit.NN_CRASHED) { - System.out.println("error: %s\n", nn_getError(c)); + if(state == nn_ComputerState.NN_POWEROFF) return; + if(state == nn_ComputerState.NN_CRASHED) { + System.out.println("error: " + nn_getError(computer)); return; } - if(state == nn_Exit.NN_CHARCH) { - System.out.println("new arch: %s\n", nn_getDesiredArchitecture(c).name); + if(state == nn_ComputerState.NN_CHARCH) { + System.out.println("new arch: " + nn_getDesiredArchitecture(computer).name); return; } - if(state == nn_Exit.NN_BLACKOUT) { - System.out.println("out of energy\n"); - goto cleanup; + if(state == nn_ComputerState.NN_BLACKOUT) { + System.out.println("out of energy"); + //goto cleanup; } - if(state == nn_Exit.NN_RESTART) { - System.out.println("restart requested\n"); + if(state == nn_ComputerState.NN_RESTART) { + System.out.println("restart requested"); nn_stopComputer(computer); //ncl_resetScreen(nn_getComponentState(screen)); nn_addIdleTime(computer, 1); - continue; - }*/ + + } //System.out.println(ctx.ptr); } public static native nn_Architecture getLuaArch(); diff --git a/src/main/org/neoflock/NeoNucleus/nn_ComputerState.java b/src/main/org/neoflock/NeoNucleus/nn_ComputerState.java index e7fc76b..fd2a7a3 100644 --- a/src/main/org/neoflock/NeoNucleus/nn_ComputerState.java +++ b/src/main/org/neoflock/NeoNucleus/nn_ComputerState.java @@ -1,5 +1,19 @@ package org.neoflock.NeoNucleus; -public class nn_ComputerState { - // TODO -} +public enum nn_ComputerState { + // the machine is running just fine + NN_RUNNING, + // machine is initializing. This is the state after createComputer but before the first nn_tick. + // It is a required state of various initialization functions. + NN_BOOTUP, + // the machine has powered off. + NN_POWEROFF, + // the machine demands being restarted. + NN_RESTART, + // the machine has crashed. RIP + NN_CRASHED, + // the machine ran out of energy. + NN_BLACKOUT, + // change architecture. + NN_CHARCH, +} \ No newline at end of file diff --git a/src/native/carbon.cpp b/src/native/carbon.cpp index 4fea826..cefb60c 100644 --- a/src/native/carbon.cpp +++ b/src/native/carbon.cpp @@ -5,6 +5,10 @@ #define CARBON_MAP_TO_NN_EXIT(enumcase) case enumcase:\ jfieldID id = env->GetFieldID(clazz, #enumcase, "Lorg.neoflock.NeoNucleus.nn_Exit;");\ return env->GetStaticObjectField(clazz, id); +#define CARBON_MAP_TO_NN_COMPUTERSTATE(enumcase) case enumcase:\ + jfieldID id = env->GetFieldID(clazz, #enumcase, "Lorg.neoflock.NeoNucleus.nn_ComputerState;");\ + return env->GetStaticObjectField(clazz, id); + // codename for NN JNI is Carbon because i needed something better than NN JNI bool Carbon::PointerBacked::SetPointer(JNIEnv * env, jobject obj, void* ptr) { jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "ptr", "J"); @@ -77,6 +81,24 @@ nn_Exit From_nn_Exit(JNIEnv* env, jobject a) { jint value = env->CallIntMethod(a, ordMID); return (nn_Exit) value; // this should be fine as long as the header and java side don't desync } +jobject Carbon::Map::To_nn_ComputerState(JNIEnv* env, nn_ComputerState a) { + jclass clazz = env->FindClass("org/neoflock/NeoComputers/nn_ComputerState"); + switch (a) { + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_RUNNING) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_BOOTUP) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_POWEROFF) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_RESTART) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_CRASHED) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_BLACKOUT) + CARBON_MAP_TO_NN_COMPUTERSTATE(NN_CHARCH) + } +} +nn_Exit From_nn_ComputerState(JNIEnv* env, jobject a) { + jclass clazz = env->FindClass("org/neoflock/NeoNucleus/nn_ComputerState"); + jmethodID ordMID = env->GetMethodID(clazz, "ordinal", "()I"); + jint value = env->CallIntMethod(a, ordMID); + return (nn_Exit) value; +} namespace Carbon::Exceptions { CARBON_EXCEPTION_FUNC(ThrowNullPtr, "java/lang/NullPointerException"); } \ No newline at end of file diff --git a/src/native/carbon.hpp b/src/native/carbon.hpp index 3093415..1590cd7 100644 --- a/src/native/carbon.hpp +++ b/src/native/carbon.hpp @@ -26,7 +26,8 @@ namespace Carbon { namespace Map { jobject To_nn_Exit(JNIEnv* env, nn_Exit a); nn_Exit From_nn_Exit(JNIEnv* env, jobject a); - + jobject To_nn_ComputerState(JNIEnv* env, nn_ComputerState a); + nn_ComputerState From_nn_ComputerState(JNIEnv* env, jobject a); } typedef struct JavaObjectTarget { // i might lowkey drop this struct diff --git a/src/native/main.cpp b/src/native/main.cpp index 64cbe28..759499c 100644 --- a/src/native/main.cpp +++ b/src/native/main.cpp @@ -135,8 +135,8 @@ JNIEXPORT jobject JNICALL Java_org_neoflock_NeoNucleus_NativeBindings_nn_1mountC (JNIEnv * env, jclass, jobject computer, jobject comp, jint slot, jboolean silent) { nn_Computer* nnPC = (nn_Computer*) Carbon::PointerBacked::GetPointer(env, computer); nn_Component* nnComp = (nn_Component*) Carbon::PointerBacked::GetPointer(env, comp); - NULLPTR_CHECK(nnPC, nn_Component); - NULLPTR_CHECK(nnComp, nn_Computer); + NULLPTR_CHECK(nnPC, nn_Computer); + NULLPTR_CHECK(nnComp, nn_Component); return Carbon::Map::To_nn_Exit(env, nn_mountComponent(nnPC, nnComp, slot, silent)); } @@ -169,3 +169,10 @@ JNIEXPORT jobject JNICALL Java_org_neoflock_NeoNucleus_NativeBindings_nn_1create env->ReleaseStringUTFChars(address, addr); return Carbon::InstantiateDefaultPBC(env, "org/neoflock/NeoNucleus/nn_Computer", computer); } + +JNIEXPORT jobject JNICALL Java_org_neoflock_NeoNucleus_NativeBindings_nn_1getComputerState + (JNIEnv * env, jclass, jobject computer) { + nn_Computer* nnPC = (nn_Computer*) Carbon::PointerBacked::GetPointer(env, computer); + NULLPTR_CHECK(nnPC, nn_Component); + return Carbon::Map::To_nn_ComputerState(env, nn_getComputerState(nnPC)); +} \ No newline at end of file