Skip to content

Commit

Permalink
fix build on zig 0.14.0-dev.2851+b074fb7dd
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmichaud committed Jan 24, 2025
1 parent 47ffa18 commit b12fa8f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zig-cache
zig-out
.zig-cache
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub fn setup_wasm(b: *std.Build, optimize: std.builtin.Mode) void {
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.root_source_file = .{ .path = "src/zpz-wasm.zig" },
.root_source_file = b.path("src/zpz-wasm.zig"),
});
lib.entry = .disabled;
lib.addIncludePath(.{ .path = "./chips/" });
lib.addIncludePath(b.path("./chips/"));
lib.addCSourceFiles(.{ .files = &.{"src/chips-impl.c"} });
// We need the libc because of the use of #include <string> memset in `chips`
lib.linkLibC(); // better than linkSystemLibrary("c") for cross-compilation
Expand Down Expand Up @@ -51,11 +51,11 @@ pub fn build(b: *std.Build) void {
.name = "zpz6128",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/zpz-native.zig" },
.root_source_file = b.path("src/zpz-native.zig"),
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "./chips/" });
exe.addIncludePath(b.path("./chips/"));
exe.addCSourceFiles(.{ .files = &.{"src/chips-impl.c"} });
exe.linkSystemLibrary("SDL2");
exe.linkLibC(); // better than linkSystemLibrary("c") for cross-compilation
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/zpz-native.zig" },
.root_source_file = b.path("src/zpz-native.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
4 changes: 2 additions & 2 deletions src/io-adapter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chips = @import("chips-decl.zig").chips;
pub const IOAdapter = struct {
handle_event_fn: *const fn (*IOAdapter, *chips.cpc_t, *bool, *bool, *bool) void,
display_fn: *const fn (*IOAdapter, [*]c_uint, usize, usize) anyerror!void,
get_timestamp: *const fn (*IOAdapter) u64,
get_timestamp_fn: *const fn (*IOAdapter) u64,

pub fn handle_event(adapter: *IOAdapter, cpc: *chips.cpc_t, running: *bool, ctrl: *bool, shift: *bool) void {
adapter.handle_event_fn(adapter, cpc, running, ctrl, shift);
Expand All @@ -15,6 +15,6 @@ pub const IOAdapter = struct {
}

pub fn get_timestamp(adapter: *IOAdapter) u64 {
try adapter.get_timestamp(adapter);
try adapter.get_timestamp_fn(adapter);
}
};
4 changes: 2 additions & 2 deletions src/zpz-native.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn main() anyerror!void {
const frame_time: usize = 16;

while (!emulator.stopped) {
const then: usize = adapter.interface.get_timestamp(&adapter.interface);
const then: usize = adapter.interface.get_timestamp_fn(&adapter.interface);
adapter.interface.handle_event(&emulator.cpc, &emulator.stopped, &emulator.ctrl, &emulator.shift);
_ = chips.cpc_exec(&emulator.cpc, frame_time * 1000); // This in CPC micro-seconds

Expand All @@ -116,7 +116,7 @@ pub fn main() anyerror!void {
// The micro seconds parameter provided to cpc_exec is in CPC time.
// 16ms in CPC time is, of course, way quicker than in real time.
// So we need to wait a little.
const now = adapter.interface.get_timestamp(&adapter.interface);
const now = adapter.interface.get_timestamp_fn(&adapter.interface);
const delay: usize = frame_time - @min(now - then, frame_time);
if (delay > 0) {
std.time.sleep(delay * 1000000); // in nanoseconds
Expand Down

0 comments on commit b12fa8f

Please sign in to comment.