first commit

This commit is contained in:
2026-05-25 21:33:48 -03:00
commit ad9176d909
42 changed files with 5788 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public interface ComponentHandler {
// TODO
}

View File

@@ -0,0 +1,7 @@
package org.neoflock.NeoNucleus;
public sealed class ComponentState extends PointerBackedClass permits ncl_ScreenState {
// TODO
// opaque class, you'll need to cast it to do anything
protected ComponentState() {}
}

View File

@@ -0,0 +1,6 @@
package org.neoflock.NeoNucleus;
public interface ManuallyAllocated {
boolean allocate();
boolean free();
}

View File

@@ -0,0 +1,135 @@
package org.neoflock.NeoNucleus;
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();
//System.out.println(ctx.ptr);
}
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);
}

View File

@@ -0,0 +1,10 @@
package org.neoflock.NeoNucleus;
public class PointerBackedClass {
private long ptr;
/*public static PointerBackedClass createFromPointer(long ptr) {
PointerBackedClass clazz = new PointerBackedClass();
clazz.ptr = ptr;
return clazz;
}*/
}

View File

@@ -0,0 +1,3 @@
package org.neoflock.NeoNucleus;
public record Resolution(long width, long height) {}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
/*public class ncl_GlyphCache {
}*/

View File

@@ -0,0 +1,21 @@
package org.neoflock.NeoNucleus;
/*
typedef struct ncl_Pixel {
// 0xRRGGBB format
unsigned int fgColor;
// 0xRRGGBB format
unsigned int bgColor;
// the codepoint
nn_codepoint codepoint;
} ncl_Pixel;
*/
public class ncl_Pixel {
public final int fgColor;
public final int bgColor;
public final int codepoint;
public ncl_Pixel(int fgColor, int bgColor, int codepoint) {
this.fgColor = fgColor;
this.bgColor = bgColor;
this.codepoint = codepoint;
}
}

View File

@@ -0,0 +1,17 @@
package org.neoflock.NeoNucleus;
/*public enum ncl_ScreenFlags {
NCL_SCREEN_ON(1<<0),
NCL_SCREEN_PRECISE(1<<1),
NCL_SCREEN_TOUCHINVERTED(1<<2);
public final int value;
private ncl_ScreenFlags(int flag) {
this.value = flag;
}
}*/
public class ncl_ScreenFlags {
public static final int NCL_SCREEN_ON = 1<<0;
public static final int NCL_SCREEN_PRECISE = 1<<1;
public static final int NCL_SCREEN_TOUCHINVERTED = 1<<2;
}

View File

@@ -0,0 +1,4 @@
package org.neoflock.NeoNucleus;
// opaque type, not much to do here
public final class ncl_ScreenState extends ComponentState {}

View File

@@ -0,0 +1,21 @@
package org.neoflock.NeoNucleus;
import java.util.function.Function;
public final class nn_Architecture extends PointerBackedClass implements ManuallyAllocated {
public final String name;
public final Function<String, Integer> handler;
public nn_Architecture(String name, Function<String, Integer> handler) { // string is a placeholder; please fix
this.name = name;
this.handler = handler;
}
private int handleNative() { // i aint gonna be trying to call that Function from jni man
return handler.apply("placeholder");
}
public native boolean allocate();
public native boolean free();
}

View File

@@ -0,0 +1,48 @@
package org.neoflock.NeoNucleus;
/* const char *CLASS;
const char *DESC;
const char *VENDOR;
const char *PRODUCT;
const char *VERSION;
const char *SERIAL;
const char *CAPACITY;
const char *SIZE;
const char *CLOCK;
const char *WIDTH; */
public class nn_CommonDeviceInfo {
public final String CLASS;
public final String DESC;
public final String VENDOR;
public final String PRODUCT;
public final String VERSION;
public final String SERIAL;
public final String CAPACITY;
public final String SIZE;
public final String CLOCK;
public final String WIDTH;
public nn_CommonDeviceInfo(
String CLASS,
String DESC,
String VENDOR,
String PRODUCT,
String VERSION,
String SERIAL,
String CAPACITY,
String SIZE,
String CLOCK,
String WIDTH
) {
this.CLASS = CLASS;
this.DESC = DESC;
this.VENDOR = VENDOR;
this.PRODUCT = PRODUCT;
this.VERSION = VERSION;
this.SERIAL = SERIAL;
this.CAPACITY = CAPACITY;
this.SIZE = SIZE;
this.CLOCK = CLOCK;
this.WIDTH = WIDTH;
}
}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public final class nn_Component extends PointerBackedClass {
private nn_Component() {}
}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public class nn_Computer {
// TODO
}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public class nn_ComputerState {
// TODO
}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public class nn_Context extends PointerBackedClass {
public native void free();
}

View File

@@ -0,0 +1,54 @@
package org.neoflock.NeoNucleus;
/*
typedef struct nn_EEPROM {
// the maximum capacity of the EEPROM
size_t size;
// the maximum capacity of the EEPROM's associated data
size_t dataSize;
// the energy cost of reading an EEPROM
double readEnergyCost;
// the energy cost of reading an EEPROM's associated data
double readDataEnergyCost;
// the energy cost of writing to an EEPROM
double writeEnergyCost;
// the energy cost of writing to an EEPROM's associated data
double writeDataEnergyCost;
// idle time added when writing code
double writeDelay;
// idle time added when writing data
double writeDataDelay;
} nn_EEPROM;
*/
public class nn_EEPROM extends PointerBackedClass implements ManuallyAllocated {
public final long size;
public final long dataSize;
public final double readEnergyCost;
public final double readDataEnergyCost;
public final double writeEnergyCost;
public final double writeDataEnergyCost;
public final double writeDelay;
public final double writeDataDelay;
public nn_EEPROM(
long size,
long dataSize,
double readEnergyCost,
double readDataEnergyCost,
double writeEnergyCost,
double writeDataEnergyCost,
double writeDelay,
double writeDataDelay
) {
this.size = size;
this.dataSize = dataSize;
this.readEnergyCost = readEnergyCost;
this.readDataEnergyCost = readDataEnergyCost;
this.writeEnergyCost = writeEnergyCost;
this.writeDataEnergyCost = writeDataEnergyCost;
this.writeDelay = writeDelay;
this.writeDataDelay = writeDataDelay;
}
@Override
public native boolean allocate();
@Override
public native boolean free();
}

View File

@@ -0,0 +1,6 @@
package org.neoflock.NeoNucleus;
public class nn_Environment {
public String a;
// TODO
}

View File

@@ -0,0 +1,18 @@
package org.neoflock.NeoNucleus;
public enum nn_Exit {
// no error
NN_OK,
// out of memory.
NN_ENOMEM,
// over the limit. For example, adding too many architectures to a machine.
NN_ELIMIT,
// internal stack underflow when managing the stack.
NN_EBELOWSTACK,
// internal stack overflow when carrying values.
NN_ENOSTACK,
// bad invocation, error message stored in computer state
NN_EBADCALL,
// bad state, the function was called at the wrong time
NN_EBADSTATE,
}

View File

@@ -0,0 +1,16 @@
package org.neoflock.NeoNucleus;
public class nn_Method {
public final String name;
public final String doc;
public final byte flags;
public nn_Method(
String name,
String doc,
byte flags
) {
this.name = name;
this.doc = doc;
this.flags = flags;
}
}

View File

@@ -0,0 +1,5 @@
package org.neoflock.NeoNucleus;
public class nn_Universe extends PointerBackedClass {
}