diff --git a/build.zig b/build.zig
index 57369de..ca15d3b 100644
--- a/build.zig
+++ b/build.zig
@@ -15,40 +15,21 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
- _ = b.addModule("gdbstub", .{
- .source_file = .{ .path = "src/lib.zig" },
- .dependencies = &.{},
- });
+ _ = b.addModule("gdbstub", .{ .root_source_file = .{ .path = "src/lib.zig" } });
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
- const lib_tests = b.addTest(.{
+ const tests = b.addTest(.{
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
- const run_lib_tests = b.addRunArtifact(lib_tests);
+ const run_tests = b.addRunArtifact(tests);
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests");
- test_step.dependOn(&run_lib_tests.step);
-}
-
-pub fn module(b: *std.Build) *std.Build.Module {
- return b.createModule(.{
- .source_file = .{ .path = path("/src/lib.zig") },
- .dependencies = &.{},
- });
-}
-
-// https://github.com/MasterQ32/SDL.zig/blob/4d565b54227b862c1540719e0e21a36d649e87d5/build.zig#L114-L120
-fn path(comptime suffix: []const u8) []const u8 {
- if (suffix[0] != '/') @compileError("relToPath requires an absolute path!");
- return comptime blk: {
- const root_dir = std.fs.path.dirname(@src().file) orelse ".";
- break :blk root_dir ++ suffix;
- };
+ test_step.dependOn(&run_tests.step);
}
diff --git a/build.zig.zon b/build.zig.zon
index 32dc07f..edfba5d 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,5 +1,10 @@
.{
.name = "zba-gdbstub",
.version = "0.1.0",
+ .paths = .{
+ "build.zig",
+ "build.zig.zon",
+ "src",
+ },
.dependencies = .{},
}
diff --git a/src/Packet.zig b/src/Packet.zig
index 55e7116..a0f56dd 100644
--- a/src/Packet.zig
+++ b/src/Packet.zig
@@ -237,7 +237,7 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
const ret = try allocator.alloc(u8, len);
ret[0] = if (ret.len < length) 'l' else 'm';
- std.mem.copy(u8, ret[1..], state.target_xml[offset..]);
+ @memcpy(ret[1..], state.target_xml[offset..]);
return .{ .alloc = ret };
} else {
@@ -264,7 +264,7 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
const ret = try allocator.alloc(u8, len);
ret[0] = if (ret.len < length) 'l' else 'm';
- std.mem.copy(u8, ret[1..], state.memmap_xml[offset..]);
+ @memcpy(ret[1..], state.memmap_xml[offset..]);
return .{ .alloc = ret };
}
diff --git a/src/Server.zig b/src/Server.zig
index e5eef0a..d430eff 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -2,7 +2,6 @@ const std = @import("std");
const Packet = @import("Packet.zig");
const Emulator = @import("lib.zig").Emulator;
-const Atomic = std.atomic.Atomic;
const Allocator = std.mem.Allocator;
const Server = std.net.StreamServer;
const Connection = Server.Connection;
@@ -11,50 +10,6 @@ const Self = @This();
const log = std.log.scoped(.Server);
const port: u16 = 2424;
-// TODO: move to ZBA
-// pub const target: []const u8 =
-// \\
-// \\ armv4t
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// ;
-
-// // Game Pak SRAM isn't included
-// // TODO: Can i be more specific here?
-// pub const memory_map: []const u8 =
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// \\
-// ;
-
// FIXME: Shouldn't this be a Packet Struct?
pkt_cache: ?[]const u8 = null,
@@ -97,7 +52,7 @@ const Action = union(enum) {
nack,
};
-pub fn run(self: *Self, allocator: Allocator, quit: *Atomic(bool)) !void {
+pub fn run(self: *Self, allocator: Allocator, quit: *std.atomic.Value(bool)) !void {
var buf: [Packet.max_len]u8 = undefined;
var client = try self.socket.accept();
diff --git a/src/test.zig b/src/test.zig
index 4039238..3d9e0ae 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -7,6 +7,49 @@ const Server = @import("Server.zig");
const Allocator = std.mem.Allocator;
const BarebonesEmulator = struct {
+
+ // I have this ARMv4T and GBA memory map xml lying around so we'll reuse it here
+ const target: []const u8 =
+ \\
+ \\ armv4t
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ ;
+
+ const memory_map: []const u8 =
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ \\
+ ;
+
r: [16]u32 = [_]u32{0} ** 16,
pub fn interface(self: *@This(), allocator: Allocator) Emulator {
@@ -57,13 +100,16 @@ test Server {
}
}.inner;
- var server = try Server.init(iface);
+ var server = try Server.init(
+ iface,
+ .{ .target = BarebonesEmulator.target, .memory_map = BarebonesEmulator.memory_map },
+ );
defer server.deinit(allocator);
const t = try std.Thread.spawn(.{}, clientFn, .{server.socket.listen_address});
defer t.join();
- var should_quit = std.atomic.Atomic(bool).init(false);
+ var should_quit = std.atomic.Value(bool).init(false);
try server.run(std.testing.allocator, &should_quit);
}