Compare commits

...

3 Commits

Author SHA1 Message Date
KillTheGoblin
905a5a25fa started hologram 2025-07-25 23:28:29 +02:00
KillTheGoblin
3d9340e81f REMOVED HARD DRIVE!!! 2025-07-25 22:35:27 +02:00
IonutParau
8f2b4519e2 bugfixes 2025-07-25 19:34:51 +02:00
6 changed files with 108 additions and 32 deletions

View File

@ -14,7 +14,6 @@
- `data` component (with error correction codes and maybe synthesizing audio) - `data` component (with error correction codes and maybe synthesizing audio)
- `redstone` component - `redstone` component
- `internet` component - `internet` component
- `disk_drive` component
- `computer.getDeviceInfo()`, and subsequently, component device information - `computer.getDeviceInfo()`, and subsequently, component device information
- `computer.beep(frequency?: number, duration?: number, volume?: number)`, frequency between 20 and 2000 Hz, duration up to 5 seconds, volume from 0 to 1. - `computer.beep(frequency?: number, duration?: number, volume?: number)`, frequency between 20 and 2000 Hz, duration up to 5 seconds, volume from 0 to 1.

View File

@ -547,8 +547,8 @@ void nni_gpu_copy(nni_gpu *gpu, void *_, nn_component *component, nn_computer *c
// prevent DoS // prevent DoS
if(x < 0) x = 0; if(x < 0) x = 0;
if(y < 0) y = 0; if(y < 0) y = 0;
if(w > gpu->currentScreen->width - x) w = gpu->currentScreen->width - x; if(w > gpu->currentScreen->width) w = gpu->currentScreen->width;
if(h > gpu->currentScreen->height - y) y = gpu->currentScreen->height - y; if(h > gpu->currentScreen->height) y = gpu->currentScreen->height;
int changes = 0, clears = 0; int changes = 0, clears = 0;

View File

@ -0,0 +1,6 @@
#include "hologram.h"
void nn_hologram_clear() {
}

38
src/components/hologram.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef NN_HOLOGRAM_H
#define NN_HOLOGRAM_H
#include "../neonucleus.h"
typedef struct nn_hologram {
nn_Context ctx;
nn_guard *lock;
nn_refc refc;
int pallette_len;
int* pallette_array;
int width_x;
int width_z;
int height;
float minScale;
float maxScale;
float scale;
int depth;
float min_translationX;
float max_translationX;
float translationX;
float min_translationY;
float max_translationY;
float translationY;
float min_translationZ;
float max_translationZ;
float translationZ;
int* grid; // I don't know what to call this
} nn_hologram;
#endif

View File

@ -175,8 +175,8 @@ nn_filesystemControl ne_fs_ctrl = {
.removeFilesPerTick = 16, .removeFilesPerTick = 16,
.createFilesPerTick = 16, .createFilesPerTick = 16,
.readHeatPerByte = 0.0000015, .readHeatPerByte = 0.00000015,
.writeHeatPerByte = 0.000015, .writeHeatPerByte = 0.0000015,
.removeHeat = 0.035, .removeHeat = 0.035,
.createHeat = 0.045, .createHeat = 0.045,
@ -233,6 +233,7 @@ void *ne_fs_open(nn_address address, const char *path, const char *mode, nn_erro
if(f == NULL) { if(f == NULL) {
nn_error_write(err, strerror(errno)); nn_error_write(err, strerror(errno));
} }
setvbuf(f, NULL, _IONBF, BUFSIZ);
return f; return f;
} }
@ -246,8 +247,13 @@ bool ne_fs_write(nn_address addr, FILE *f, const char *buf, size_t len, nn_error
} }
size_t ne_fs_read(nn_address addr, FILE *f, char *buf, size_t required, nn_errorbuf_t err) { size_t ne_fs_read(nn_address addr, FILE *f, char *buf, size_t required, nn_errorbuf_t err) {
if(feof(f)) return 0; nn_size_t len = 0;
return fread(buf, sizeof(char), required, f); while(true) {
if(feof(f)) break;
if(len >= required) break;
len += fread(buf + len, 1, required - len, f);
}
return len;
} }
size_t ne_fs_seek(nn_address addr, FILE *f, const char *whence, int off, nn_errorbuf_t err) { size_t ne_fs_seek(nn_address addr, FILE *f, const char *whence, int off, nn_errorbuf_t err) {
@ -258,7 +264,9 @@ size_t ne_fs_seek(nn_address addr, FILE *f, const char *whence, int off, nn_erro
if(strcmp(whence, "end") == 0) { if(strcmp(whence, "end") == 0) {
w = SEEK_END; w = SEEK_END;
} }
fseek(f, w, off); if(fseek(f, off, w) != 0) {
nn_error_write(err, strerror(errno));
}
return ftell(f); return ftell(f);
} }
@ -603,6 +611,13 @@ typedef struct ne_pressedKey {
bool repeat; bool repeat;
} ne_pressedKey; } ne_pressedKey;
void ne_log(void *_, void *__, nn_component *component, nn_computer *computer) {
const char *s = nn_toCString(nn_getArgument(computer, 0));
if(s) {
printf("Sandbox: %s\n", s);
}
}
int main() { int main() {
printf("Setting up universe\n"); printf("Setting up universe\n");
nn_Context ctx = nn_libcContext(); nn_Context ctx = nn_libcContext();
@ -618,11 +633,17 @@ int main() {
assert(arch != NULL && "Loading architecture failed"); assert(arch != NULL && "Loading architecture failed");
// 1MB of RAM, 16 components max // 1MB of RAM, 16 components max
nn_computer *computer = nn_newComputer(universe, "testMachine", arch, NULL, 1*1024*1024, 16); nn_computer *computer = nn_newComputer(universe, "testMachine", arch, NULL, 4*1024*1024, 16);
nn_setEnergyInfo(computer, 5000, 5000); nn_setEnergyInfo(computer, 5000, 5000);
nn_setCallBudget(computer, 1*1024*1024); nn_setCallBudget(computer, 1*1024*1024);
nn_addSupportedArchitecture(computer, arch); nn_addSupportedArchitecture(computer, arch);
// sandbox shit
nn_componentTable *sandboxTable = nn_newComponentTable(&alloc, "sandbox", NULL, NULL, NULL);
nn_defineMethod(sandboxTable, "log", ne_log, "log(msg: string) - Basic logging");
nn_newComponent(computer, NULL, -1, sandboxTable, NULL);
nn_eepromTable genericEEPROMTable = { nn_eepromTable genericEEPROMTable = {
.userdata = "luaBios.lua", .userdata = "luaBios.lua",
.deinit = NULL, .deinit = NULL,
@ -746,28 +767,6 @@ int main() {
nn_addGPU(computer, NULL, 3, &gpuCtrl); nn_addGPU(computer, NULL, 3, &gpuCtrl);
nn_networkControl modemCtrl = {
.energyPerFullPacket = 5,
.heatPerFullPacket = 8,
.packetBytesPerTick = 16384,
};
nn_address networkAddr = "lan";
nn_debugLoopbackNetworkOpts opts = {
.isWireless = true,
.maxPacketSize = 8192,
.maxOpenPorts = 16,
.maxValues = 8,
.maxStrength = 400,
.computer = computer,
.address = networkAddr,
};
nn_modem *modem = nn_debugLoopbackModem(&ctx, opts, modemCtrl);
nn_addModem(computer, networkAddr, 12, modem);
SetConfigFlags(FLAG_WINDOW_RESIZABLE); SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "emulator"); InitWindow(800, 600, "emulator");
@ -813,6 +812,16 @@ int main() {
} }
if (keycode != 0) { if (keycode != 0) {
if(keycode == KEY_ENTER) {
unicode = '\r';
}
if(keycode == KEY_BACKSPACE) {
unicode = '\b';
}
if(keycode == KEY_TAB) {
unicode = '\t';
}
release_check_list[release_check_ptr].keycode = keycode; release_check_list[release_check_ptr].keycode = keycode;
release_check_list[release_check_ptr].charcode = unicode; release_check_list[release_check_ptr].charcode = unicode;
release_check_list[release_check_ptr].repeat = false; release_check_list[release_check_ptr].repeat = false;

View File

@ -1047,7 +1047,31 @@ nn_bool_t nn_destroyDiskDrive(nn_diskDrive *diskDrive);
nn_component *nn_addDiskDrive(nn_computer *computer, nn_address address, int slot, nn_diskDrive *diskDrive); nn_component *nn_addDiskDrive(nn_computer *computer, nn_address address, int slot, nn_diskDrive *diskDrive);
#ifdef __cplusplus typedef struct nn_hologram nn_hologram;
nn_hologram *nn_newHologram(nn_Context *context, int pallette_len, int width_x, int width_z, int height, int depth);
nn_guard *nn_getHologramLock(nn_hologram *hologram);
void nn_retainHologram(nn_hologram *hologram);
nn_bool_t nn_destroyHologram(nn_hologram *hologram);
nn_component *nn_addHologram(nn_computer *computer, nn_address address, int slot, nn_hologram *hologram);
int nn_XYZtoIndex(int x, int y, int z);
void nn_hologram_clear(nn_hologram *hologram);
int nn_hologram_get(nn_hologram *hologram, int x, int y, int z);
void nn_hologram_set(nn_hologram *hologram, int x, int y, int z, int value);
void nn_hologram_fill(nn_hologram *hologram, int x, int z, int minY, int maxY, int value);
void nn_hologram_copy(nn_hologram *hologram, int x, int z, int sx, int sz, int tx, int tz);
float nn_hologram_getScale(nn_hologram *hologram);
void nn_hologram_setScale(nn_hologram *hologram, float value);
void nn_hologram_getTranslation(nn_hologram *hologram, int *x, int *y, int *z);
void nn_hologram_setTranslation(nn_hologram *hologram, int x, int y, int z);
int nn_hologram_maxDepth(nn_hologram *hologram);
int nn_hologram_getPaletteColor(nn_hologram *hologram, int index);
int nn_hologram_setPaletteColor(nn_hologram *hologram, int index, int value);
#ifdef __cplusplus // c++ sucks
} }
#endif #endif