diff --git a/src/main/org/neoflock/NeoNucleus/NativeBindings.java b/src/main/org/neoflock/NeoNucleus/NativeBindings.java index 0434cd7..4c8cda3 100644 --- a/src/main/org/neoflock/NeoNucleus/NativeBindings.java +++ b/src/main/org/neoflock/NeoNucleus/NativeBindings.java @@ -1,19 +1,63 @@ package org.neoflock.NeoNucleus; +import java.util.UUID; + public class NativeBindings { static { System.loadLibrary("neonucleusjni"); } public static void main(String[] args) { //nn_Context ctx = nn_initContext(); - nn_EEPROM eeprom = new nn_EEPROM(100, 200, 300, 400, 0, 0, 0, 0); + /*nn_EEPROM eeprom = new nn_EEPROM(100, 200, 300, 400, 0, 0, 0, 0); eeprom.allocate(); System.out.println("we live"); eeprom.free(); System.out.println("about to double free"); - eeprom.free(); + eeprom.free();*/ + nn_Context ctx = nn_initContext(); + nn_initPalettes(); + nn_Universe universe = nn_createUniverse(ctx); + nn_Architecture arch = getLuaArch(); + nn_EEPROM eeprom = new nn_EEPROM(2048, 2048, 1, 1, 1, 1, 1, 1); + nn_Component eepromCard = ncl_createEEPROM(universe, UUID.randomUUID().toString(), eeprom, "error('amog us')", false); + 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_Exit e = nn_tick(computer); + if (e != nn_Exit.NN_OK) { + System.out.println("NN tick error: " + nn_getError(computer)); + return; + } + e = nn_tickSynchronized(computer); + if (e != nn_Exit.NN_OK) { + System.out.println("NN synchronized tick error: " + nn_getError(computer)); + 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)); + return; + } + if(state == nn_Exit.NN_CHARCH) { + System.out.println("new arch: %s\n", nn_getDesiredArchitecture(c).name); + return; + } + if(state == nn_Exit.NN_BLACKOUT) { + System.out.println("out of energy\n"); + goto cleanup; + } + if(state == nn_Exit.NN_RESTART) { + System.out.println("restart requested\n"); + nn_stopComputer(computer); + //ncl_resetScreen(nn_getComponentState(screen)); + nn_addIdleTime(computer, 1); + continue; + }*/ //System.out.println(ctx.ptr); } + public static native nn_Architecture getLuaArch(); public static native nn_Context nn_initContext(); public static native void nn_initPalettes(); // nn_Universe *nn_createUniverse(nn_Context *ctx, void *userdata) diff --git a/src/native/main.cpp b/src/native/main.cpp index 8a9ea38..64cbe28 100644 --- a/src/native/main.cpp +++ b/src/native/main.cpp @@ -2,6 +2,7 @@ #include #include "neonucleus.h" #include "ncomplib.h" +#include #include "carbon.hpp" @@ -161,7 +162,7 @@ JNIEXPORT jobject JNICALL Java_org_neoflock_NeoNucleus_NativeBindings_nn_1create (JNIEnv * env, jclass, jobject universe, jstring address, jlong totalMemory, jlong maxComponents, jlong maxDevices) { nn_Universe* nnUni = (nn_Universe*) Carbon::PointerBacked::GetPointer(env, universe); NULLPTR_CHECK(nnUni, nn_Universe); - + const char * addr = env->GetStringUTFChars(address, NULL); // TODO: computer jni userdata lol nn_Computer* computer = nn_createComputer(nnUni, NULL, addr, totalMemory, maxComponents, maxDevices);