From 4a28c8943e564e1d4c0a16300deb95259a029796 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Tue, 8 Jul 2025 21:18:28 +0200 Subject: [PATCH] basic hashing --- build.zig | 20 +++++++++++++++++--- src/components/eeprom.c | 9 +++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/build.zig b/build.zig index 5beff09..9a94825 100644 --- a/build.zig +++ b/build.zig @@ -1,7 +1,19 @@ const std = @import("std"); 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.addCSourceFiles(.{ @@ -23,6 +35,8 @@ fn addEngineSources(c: *std.Build.Step.Compile) void { "src/components/keyboard.c", }, }); + + c.addIncludePath(b.path("src")); } const LuaVersion = enum { @@ -87,7 +101,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - addEngineSources(engineStatic); + addEngineSources(b, engineStatic, target, optimize); const engineShared = b.addSharedLibrary(.{ .name = getSharedEngineName(os), @@ -95,7 +109,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - addEngineSources(engineShared); + addEngineSources(b, engineShared, target, optimize); const engineStep = b.step("engine", "Builds the engine as a static library"); engineStep.dependOn(&engineStatic.step); diff --git a/src/components/eeprom.c b/src/components/eeprom.c index f77644d..8f2abaa 100644 --- a/src/components/eeprom.c +++ b/src/components/eeprom.c @@ -153,7 +153,6 @@ void nn_eeprom_makeReadonly(nn_eeprom *eeprom, void *_, nn_component *component, eeprom->makeReadonly(component, eeprom->userdata); } -// TODO: make good void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component, nn_computer *computer) { size_t cap = eeprom->getDataSize(component, eeprom->userdata); 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) { return; } - size_t sum = 0; - for(size_t i = 0; i < len; i++) { - sum += buf[i]; - } + char hash[4] = {1, 0, 0, 1}; + nn_data_crc32(buf, len, hash); 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); }