Skip to content

Commit

Permalink
Remove common.GeneralAllocator
Browse files Browse the repository at this point in the history
  • Loading branch information
Senryoku committed Nov 29, 2024
1 parent 5b45e75 commit 61fc457
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
5 changes: 0 additions & 5 deletions src/common.zig
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/dreamcast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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, .{});
Expand Down
2 changes: 1 addition & 1 deletion src/holly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");

Expand All @@ -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")) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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..]);
Expand Down

0 comments on commit 61fc457

Please sign in to comment.