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); eeprom.allocate(); System.out.println("we live"); eeprom.free(); System.out.println("about to double 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) public static native nn_Universe nn_createUniverse(nn_Context ctx); // nn_Component *nn_createComponent(nn_Universe *universe, const char *address, const char *type) public static native nn_Component nn_createComponent(nn_Universe universe, String address, String type); public static native nn_Exit nn_setComponentMethods(nn_Component component, nn_Method[] methods); // void nn_setComponentHandler(nn_Component *c, nn_ComponentHandler *handler) public static native void nn_setComponentHandler(nn_Component component, ComponentHandler handler); // nn_Exit nn_mountComponent(nn_Computer *c, nn_Component *comp, int slot, bool silent) public static native nn_Exit nn_mountComponent(nn_Computer c, nn_Component comp, int slot, boolean silent); // nn_Component *ncl_createEEPROM(nn_Universe *universe, const char *address, const nn_EEPROM *eeprom, const char *code, size_t codelen, bool isReadonly) public static native nn_Component ncl_createEEPROM(nn_Universe universe, String address, nn_EEPROM eeprom, String code, boolean isReadonly); // nn_Computer *nn_createComputer(nn_Universe *universe, void *userdata, const char *address, size_t totalMemory, size_t maxComponents, size_t maxDevices) public static native nn_Computer nn_createComputer(nn_Universe universe, String address, long totalMemory, long maxComponents, long maxDevices); // void nn_setComputerEnvironment(nn_Computer *computer, nn_Environment env) public static native void nn_setComputerEnvironment(nn_Computer computer, nn_Environment env); // void nn_setCallBudget(nn_Computer *computer, double budget) public static native void nn_setCallBudget(nn_Computer computer, double budget); // void nn_setTotalEnergy(nn_Computer *computer, double maxEnergy) public static native void nn_setTotalEnergy(nn_Computer computer, double maxEnergy); // void nn_setArchitecture(nn_Computer *computer, const nn_Architecture *arch) public static native void nn_setArchitecture(nn_Computer computer, nn_Architecture arch); // nn_Exit nn_addSupportedArchitecture(nn_Computer *computer, const nn_Architecture *arch) public static native nn_Exit nn_addSupportedArchitecture(nn_Computer computer, nn_Architecture arch); // nn_Exit nn_setTmpAddress(nn_Computer *computer, const char *address) /** * address is copied. * It can be NULL if you wish to have no tmp address. * It can fail due to out-of-memory errors. */ public static native nn_Exit nn_setTmpAddress(nn_Computer computer, String address); // const char *nn_getComponentAddress(nn_Component *c) public static native String nn_getComponentAddress(nn_Component c); // nn_Exit nn_addCommonDeviceInfo(nn_Computer *computer, const char *addr, nn_CommonDeviceInfo info) public static native nn_Exit nn_addCommonDeviceInfo(nn_Computer computer, String addr, nn_CommonDeviceInfo info); // it doesn't really make sense to implement nn_clearCommonDeviceInfo, so it wont be. // void *nn_getComponentState(nn_Component *c) public static native ComponentState nn_getComponentState(nn_Component c); // void ncl_lockScreen(ncl_ScreenState *state) public static native void ncl_lockScreen(ncl_ScreenState state); // void ncl_getScreenViewport(const ncl_ScreenState *state, size_t *width, size_t *height) public static native Resolution ncl_getScreenViewport(ncl_ScreenState state); // void ncl_setScreenViewport(ncl_ScreenState *state, size_t width, size_t height) public static native void ncl_setScreenViewport(ncl_ScreenState state, long width, long height); // ncl_ScreenFlags ncl_getScreenFlags(const ncl_ScreenState *state) public static native ncl_ScreenFlags ncl_getScreenFlags(ncl_ScreenState state); // int ncl_cellHeight(ncl_GlyphCache *gc) //public static native int ncl_cellHeight(ncl_GlyphCache gc); // void ncl_destroyGlyphCache(ncl_GlyphCache *gc) //public static native void ncl_destroyGlyphCache(ncl_GlyphCache gc); // ncl_GlyphCache *ncl_createGlyphCache(const char *fontPath, int fontSize) //public static native ncl_GlyphCache ncl_createGlyphCache(String fontPath, int fontSize); // int ncl_cellWidth(ncl_GlyphCache *gc) //public static native int ncl_cellWidth(ncl_GlyphCache gc); // double ncl_getScreenBrightness(ncl_ScreenState *state) public static native double ncl_getScreenBrightness(ncl_ScreenState state); // ncl_Pixel ncl_getScreenPixel(const ncl_ScreenState *state, int x, int y) public static native ncl_Pixel ncl_getScreenPixel(ncl_ScreenState state, int x, int y); // void ncl_needGlyph(ncl_GlyphCache *gc, nn_codepoint cp) /** * @param gc * @param cp an nn_codepoint */ //public static native void ncl_needGlyph(ncl_GlyphCache gc, int cp); // void ncl_drawGlyph(ncl_GlyphCache *gc, nn_codepoint cp, Vector2 pos, float size, Color tint) //public static native void ncl_drawGlyph(ncl_GlyphCache gc, int cp, Vector2 pos, float size, Color tint); // void ncl_unlockScreen(ncl_ScreenState *state) public static native void ncl_unlockScreen(ncl_ScreenState state); // nn_Exit nn_pushTouch(nn_Computer *computer, const char *screenAddress, double x, double y, int button, const char *player) public static native nn_Exit nn_pushTouch(nn_Computer computer, String screenAddress, double x, double y, int button, String player); // nn_Exit nn_pushDrop(nn_Computer *computer, const char *screenAddress, double x, double y, int button, const char *player) public static native nn_Exit nn_pushDrop(nn_Computer computer, String screenAddress, double x, double y, int button, String player); // nn_Exit nn_pushDrag(nn_Computer *computer, const char *screenAddress, double x, double y, int button, const char *player) public static native nn_Exit nn_pushDrag(nn_Computer computer, String screenAddress, double x, double y, int button, String player); // nn_Exit nn_pushScroll(nn_Computer *computer, const char *screenAddress, double x, double y, double direction, const char *player) public static native nn_Exit nn_pushScroll(nn_Computer computer, String screenAddress, double x, double y, double direction, String player); // size_t nn_getUsedMemory(nn_Computer *computer) public static native long nn_getUsedMemory(nn_Computer computer); // size_t nn_getTotalMemory(nn_Computer *computer) public static native long nn_getTotalMemory(nn_Computer computer); // nn_Exit nn_pushClipboard(nn_Computer *computer, const char *keyboardAddress, const char *clipboard, const char *player) public static native nn_Exit nn_pushClipboard(nn_Computer computer, String keyboardAddress, String clipboard, String player); // nn_Exit nn_pushKeyDown(nn_Computer *computer, const char *keyboardAddress, nn_codepoint charcode, int keycode, const char *player) public static native nn_Exit nn_pushKeyDown(nn_Computer computer, String keyboardAddress, int charcode, int keycode, String player); // nn_Exit nn_pushKeyUp(nn_Computer *computer, const char *keyboardAddress, nn_codepoint charcode, int keycode, const char *player) public static native nn_Exit nn_pushKeyUp(nn_Computer computer, String keyboardAddress, int charcode, int keycode, String player); // void nn_clearstack(nn_Computer *computer) public static native nn_Exit nn_clearstack(nn_Computer computer); // bool nn_removeEnergy(nn_Computer *computer, double energy) public static native boolean nn_removeEnergy(nn_Computer computer, double energy); // nn_Exit nn_tickSynchronized(nn_Computer *computer) public static native nn_Exit nn_tickSynchronized(nn_Computer computer); // double ncl_getScreenEnergyUsage(ncl_ScreenState *state) public static native double ncl_getScreenEnergyUsage(ncl_ScreenState state); // void nn_resetIdleTime(nn_Computer *computer) public static native void nn_resetIdleTime(nn_Computer computer); // nn_Exit nn_tick(nn_Computer *computer) public static native nn_Exit nn_tick(nn_Computer computer); // nn_ComputerState nn_getComputerState(nn_Computer *computer) public static native nn_ComputerState nn_getComputerState(nn_Computer computer); // const char *nn_getError(nn_Computer *computer) public static native String nn_getError(nn_Computer computer); // nn_Architecture nn_getDesiredArchitecture(nn_Computer *computer) public static native nn_Architecture nn_getDesiredArchitecture(nn_Computer computer); // void nn_stopComputer(nn_Computer *computer) public static native void nn_stopComputer(nn_Computer computer); // void ncl_resetScreen(ncl_ScreenState *state) public static native void ncl_resetScreen(ncl_ScreenState state); // void nn_addIdleTime(nn_Computer *computer, double time) public static native void nn_addIdleTime(nn_Computer computer, double time); // void nn_destroyComputer(nn_Computer *computer) public static native void nn_destroyComputer(nn_Computer computer); // void nn_dropComponent(nn_Component *c) public static native void nn_dropComponent(nn_Component c); // void nn_destroyUniverse(nn_Universe *universe) public static native void nn_destroyUniverse(nn_Universe universe); }