diff --git a/src/common.zig b/src/common.zig index f099bd2..eae3deb 100644 --- a/src/common.zig +++ b/src/common.zig @@ -1,8 +1,3 @@ -const std = @import("std"); - -var gpa = std.heap.GeneralPurposeAllocator(.{}){}; -pub const GeneralAllocator = gpa.allocator(); - pub const addr_t = u32; pub const byte_t = u8; pub const word_t = u16; diff --git a/src/dreamcast.zig b/src/dreamcast.zig index e5d0e26..75f84b3 100644 --- a/src/dreamcast.zig +++ b/src/dreamcast.zig @@ -755,10 +755,10 @@ pub const Dreamcast = struct { }; test "boot" { - var dc = try Dreamcast.create(common.GeneralAllocator); + var dc = try Dreamcast.create(std.testing.allocator); defer { dc.deinit(); - common.GeneralAllocator.destroy(dc); + std.testing.allocator.destroy(dc); } _ = try dc.tick(1); // mov 0x0F,R3 @@ -927,10 +927,10 @@ test "boot" { } test "IP.bin" { - var dc = try Dreamcast.create(common.GeneralAllocator); + var dc = try Dreamcast.create(std.testing.allocator); defer { dc.deinit(); - common.GeneralAllocator.destroy(dc); + std.testing.allocator.destroy(dc); } // Example IP.bin file @@ -946,10 +946,10 @@ test "IP.bin" { } test "IP.bin init boot" { - var dc = try Dreamcast.create(common.GeneralAllocator); + var dc = try Dreamcast.create(std.testing.allocator); defer { dc.deinit(); - common.GeneralAllocator.destroy(dc); + std.testing.allocator.destroy(dc); } dc.skip_bios(); @@ -968,10 +968,10 @@ test "IP.bin init boot" { // Loads a binary at 0x8C080000, set R14 to 1, and executes it until R14 == 0 (success condition) fn load_and_test_binary(comptime filename: []const u8) !void { - var dc = try Dreamcast.create(common.GeneralAllocator); + var dc = try Dreamcast.create(std.testing.allocator); defer { dc.deinit(); - common.GeneralAllocator.destroy(dc); + std.testing.allocator.destroy(dc); } const bin_file = try std.fs.cwd().openFile("./test/bin/" ++ filename, .{}); diff --git a/src/holly.zig b/src/holly.zig index 90b4cb3..59607c1 100644 --- a/src/holly.zig +++ b/src/holly.zig @@ -1753,7 +1753,7 @@ pub const Holly = struct { if (volume.triangle_count > 0) { const config = self.get_region_array_data_config(); if (@as(u32, @bitCast(config.opaque_modifier_volume_pointer)) == @as(u32, @bitCast(config.translucent_modifier_volume_pointer))) { - // Both lists are actually the same, we'll add it twice for convience. + // Both lists are actually the same, we'll add it twice for convenience. self.ta_current_lists().opaque_modifier_volumes.append(volume.*) catch unreachable; self.ta_current_lists().translucent_modifier_volumes.append(volume.*) catch unreachable; } else { diff --git a/src/main.zig b/src/main.zig index 3f2b253..815fc56 100644 --- a/src/main.zig +++ b/src/main.zig @@ -152,12 +152,14 @@ const AvailableHacks = [_]struct { name: []const u8, hacks: []const Hack }{ var EnabledHacks: ?[]const Hack = null; pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + var allocator = gpa.allocator(); defer { // Cleanup temprary directory, if it exists std.fs.cwd().deleteTree(Deecy.TmpDirPath) catch |err| std.log.err("Failed to delete temporary directory ('" ++ Deecy.TmpDirPath ++ "'): {s}", .{@errorName(err)}); } - var d = try Deecy.create(common.GeneralAllocator); + var d = try Deecy.create(allocator); defer d.destroy(); var dc = d.dc; @@ -167,7 +169,7 @@ pub fn main() !void { var gdi_path: ?[]const u8 = null; var default_vmu = true; - var vmu_path = std.ArrayList(u8).init(common.GeneralAllocator); + var vmu_path = std.ArrayList(u8).init(allocator); defer vmu_path.deinit(); try vmu_path.appendSlice("./userdata/vmu_default.bin"); @@ -176,7 +178,7 @@ pub fn main() !void { var force_stop = false; var force_render = false; // Enable to re-render every time and help capturing with RenderDoc (will mess with framebuffer emulation). - var args = try std.process.argsWithAllocator(common.GeneralAllocator); + var args = try std.process.argsWithAllocator(allocator); defer args.deinit(); while (args.next()) |arg| { if (std.mem.eql(u8, arg, "-b")) { @@ -220,7 +222,7 @@ pub fn main() !void { } } - dc.maple.ports[0].subperipherals[0] = .{ .VMU = try MapleModule.VMU.init(common.GeneralAllocator, vmu_path.items) }; + dc.maple.ports[0].subperipherals[0] = .{ .VMU = try MapleModule.VMU.init(allocator, vmu_path.items) }; if (binary_path) |path| { try dc.set_region(.USA); @@ -265,8 +267,8 @@ pub fn main() !void { const header_size: u32 = dc.gdrom.disk.?.tracks.items[2].header_size(); const first_read_name = dc.gdrom.disk.?.tracks.items[2].data[0x60 + header_size .. 0x70 + header_size]; const name_end = std.mem.indexOfScalar(u8, first_read_name, 0x20) orelse first_read_name.len; - var first_read: []u8 = try common.GeneralAllocator.alloc(u8, name_end + 2); - defer common.GeneralAllocator.free(first_read); + var first_read: []u8 = try allocator.alloc(u8, name_end + 2); + defer allocator.free(first_read); @memcpy(first_read[0..name_end], first_read_name[0..name_end]); @memcpy(first_read[name_end .. name_end + 2], ";1"); _ = try dc.gdrom.disk.?.load_file(first_read, dc.ram[0x00010000..]);