basic hashing

This commit is contained in:
IonutParau 2025-07-08 21:18:28 +02:00
parent b7ca7f78c1
commit 4a28c8943e
2 changed files with 20 additions and 9 deletions

View File

@ -1,7 +1,19 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
fn addEngineSources(c: *std.Build.Step.Compile) void { fn addEngineSources(b: *std.Build, c: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const dataMod = b.createModule(.{
.root_source_file = b.path("src/data.zig"),
.target = target,
.optimize = optimize,
});
const zigObj = b.addObject(.{
.name = "zig_wrappers",
.root_module = dataMod,
.pic = true,
});
c.addObject(zigObj);
c.linkLibC(); // we need a libc c.linkLibC(); // we need a libc
c.addCSourceFiles(.{ c.addCSourceFiles(.{
@ -23,6 +35,8 @@ fn addEngineSources(c: *std.Build.Step.Compile) void {
"src/components/keyboard.c", "src/components/keyboard.c",
}, },
}); });
c.addIncludePath(b.path("src"));
} }
const LuaVersion = enum { const LuaVersion = enum {
@ -87,7 +101,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize, .optimize = optimize,
}); });
addEngineSources(engineStatic); addEngineSources(b, engineStatic, target, optimize);
const engineShared = b.addSharedLibrary(.{ const engineShared = b.addSharedLibrary(.{
.name = getSharedEngineName(os), .name = getSharedEngineName(os),
@ -95,7 +109,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize, .optimize = optimize,
}); });
addEngineSources(engineShared); addEngineSources(b, engineShared, target, optimize);
const engineStep = b.step("engine", "Builds the engine as a static library"); const engineStep = b.step("engine", "Builds the engine as a static library");
engineStep.dependOn(&engineStatic.step); engineStep.dependOn(&engineStatic.step);

View File

@ -153,7 +153,6 @@ void nn_eeprom_makeReadonly(nn_eeprom *eeprom, void *_, nn_component *component,
eeprom->makeReadonly(component, eeprom->userdata); eeprom->makeReadonly(component, eeprom->userdata);
} }
// TODO: make good
void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component, nn_computer *computer) { void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component, nn_computer *computer) {
size_t cap = eeprom->getDataSize(component, eeprom->userdata); size_t cap = eeprom->getDataSize(component, eeprom->userdata);
nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(computer)); nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(computer));
@ -166,13 +165,11 @@ void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component,
if(len < 0) { if(len < 0) {
return; return;
} }
size_t sum = 0; char hash[4] = {1, 0, 0, 1};
for(size_t i = 0; i < len; i++) { nn_data_crc32(buf, len, hash);
sum += buf[i];
}
nn_dealloc(alloc, buf, cap); nn_dealloc(alloc, buf, cap);
nn_return_string(computer, (void *)&sum, sizeof(sum)); nn_return_string(computer, hash, sizeof(hash));
nn_eeprom_readCost(component, len); nn_eeprom_readCost(component, len);
} }