From fed7e6d8aaeb59f0d82489c525037d7b51ac111e Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 8 Oct 2023 16:38:53 -0500 Subject: [PATCH] chore: rename struct --- src/core/emu.zig | 8 ++++---- src/core/nds7/Bus.zig | 13 ++++++------- src/core/nds7/io.zig | 6 +++--- src/core/nds9/Bus.zig | 12 ++++++------ src/core/nds9/io.zig | 6 +++--- src/main.zig | 10 +++++----- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/core/emu.zig b/src/core/emu.zig index 208e806..d1b57dd 100644 --- a/src/core/emu.zig +++ b/src/core/emu.zig @@ -1,7 +1,6 @@ const std = @import("std"); const Header = @import("cartridge.zig").Header; -const SharedIo = @import("io.zig").Io; const Scheduler = @import("Scheduler.zig"); const Allocator = std.mem.Allocator; @@ -90,13 +89,14 @@ pub fn runFrame(scheduler: *Scheduler, system: System) void { } // FIXME: Perf win to allocating on the stack instead? -pub const SharedContext = struct { +pub const SharedCtx = struct { const MiB = 0x100000; const KiB = 0x400; + pub const Io = @import("io.zig").Io; const Vram = @import("ppu.zig").Vram; - io: *SharedIo, + io: *Io, main: *[4 * MiB]u8, wram: *Wram, vram: *Vram, @@ -112,7 +112,7 @@ pub const SharedContext = struct { const ctx = .{ .io = blk: { - const io = try allocator.create(SharedIo); + const io = try allocator.create(Io); io.* = .{}; break :blk io; diff --git a/src/core/nds7/Bus.zig b/src/core/nds7/Bus.zig index f5f1e92..8bd25d7 100644 --- a/src/core/nds7/Bus.zig +++ b/src/core/nds7/Bus.zig @@ -2,8 +2,7 @@ const std = @import("std"); const io = @import("io.zig"); const Scheduler = @import("../Scheduler.zig"); -const SharedIo = @import("../io.zig").Io; -const SharedContext = @import("../emu.zig").SharedContext; +const SharedCtx = @import("../emu.zig").SharedCtx; const Wram = @import("../emu.zig").Wram; const Vram = @import("../ppu.zig").Vram; const forceAlign = @import("../emu.zig").forceAlign; @@ -23,18 +22,18 @@ wram: *[64 * KiB]u8, vram: *Vram, io: io.Io, -pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() { +pub fn init(allocator: Allocator, scheduler: *Scheduler, ctx: SharedCtx) !@This() { const wram = try allocator.create([64 * KiB]u8); errdefer allocator.destroy(wram); @memset(wram, 0); return .{ - .main = shared_ctx.main, - .wram_shr = shared_ctx.wram, - .vram = shared_ctx.vram, + .main = ctx.main, + .wram_shr = ctx.wram, + .vram = ctx.vram, .wram = wram, .scheduler = scheduler, - .io = io.Io.init(shared_ctx.io), + .io = io.Io.init(ctx.io), }; } diff --git a/src/core/nds7/io.zig b/src/core/nds7/io.zig index 7d55468..639b6ba 100644 --- a/src/core/nds7/io.zig +++ b/src/core/nds7/io.zig @@ -4,15 +4,15 @@ const Bitfield = @import("bitfield").Bitfield; const Bit = @import("bitfield").Bit; const Bus = @import("Bus.zig"); -const SharedIo = @import("../io.zig").Io; +const SharedCtx = @import("../emu.zig").SharedCtx; const masks = @import("../io.zig").masks; const log = std.log.scoped(.nds7_io); pub const Io = struct { - shared: *SharedIo, + shared: *SharedCtx.Io, - pub fn init(io: *SharedIo) @This() { + pub fn init(io: *SharedCtx.Io) @This() { return .{ .shared = io }; } }; diff --git a/src/core/nds9/Bus.zig b/src/core/nds9/Bus.zig index cfeb86d..6427118 100644 --- a/src/core/nds9/Bus.zig +++ b/src/core/nds9/Bus.zig @@ -3,7 +3,7 @@ const io = @import("io.zig"); const Ppu = @import("../ppu.zig").Ppu; const Scheduler = @import("../Scheduler.zig"); -const SharedContext = @import("../emu.zig").SharedContext; +const SharedCtx = @import("../emu.zig").SharedCtx; const Wram = @import("../emu.zig").Wram; const forceAlign = @import("../emu.zig").forceAlign; @@ -22,16 +22,16 @@ ppu: Ppu, scheduler: *Scheduler, -pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() { +pub fn init(allocator: Allocator, scheduler: *Scheduler, ctx: SharedCtx) !@This() { const dots_per_cycle = 3; // ARM946E-S runs twice as fast as the ARM7TDMI scheduler.push(.{ .nds9 = .draw }, 256 * dots_per_cycle); return .{ - .main = shared_ctx.main, - .wram = shared_ctx.wram, - .ppu = try Ppu.init(allocator, shared_ctx.vram), + .main = ctx.main, + .wram = ctx.wram, + .ppu = try Ppu.init(allocator, ctx.vram), .scheduler = scheduler, - .io = io.Io.init(shared_ctx.io), + .io = io.Io.init(ctx.io), }; } diff --git a/src/core/nds9/io.zig b/src/core/nds9/io.zig index ccf0bac..cc42958 100644 --- a/src/core/nds9/io.zig +++ b/src/core/nds9/io.zig @@ -4,7 +4,7 @@ const Bitfield = @import("bitfield").Bitfield; const Bit = @import("bitfield").Bit; const Bus = @import("Bus.zig"); -const SharedIo = @import("../io.zig").Io; +const SharedCtx = @import("../emu.zig").SharedCtx; const masks = @import("../io.zig").masks; const sext = @import("../../util.zig").sext; @@ -12,7 +12,7 @@ const sext = @import("../../util.zig").sext; const log = std.log.scoped(.nds9_io); pub const Io = struct { - shared: *SharedIo, + shared: *SharedCtx.Io, /// POWCNT1 - Graphics Power Control /// Read / Write @@ -25,7 +25,7 @@ pub const Io = struct { div: Divisor = .{}, sqrt: SquareRootUnit = .{}, - pub fn init(io: *SharedIo) @This() { + pub fn init(io: *SharedCtx.Io) @This() { return .{ .shared = io }; } }; diff --git a/src/main.zig b/src/main.zig index 3b9e559..043de31 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,7 +4,7 @@ const clap = @import("zig-clap"); const emu = @import("core/emu.zig"); const Ui = @import("platform.zig").Ui; -const SharedContext = @import("core/emu.zig").SharedContext; +const SharedCtx = @import("core/emu.zig").SharedCtx; const System = @import("core/emu.zig").System; const Scheduler = @import("core/Scheduler.zig"); @@ -34,8 +34,8 @@ pub fn main() !void { const rom_file = try std.fs.cwd().openFile(rom_path, .{}); defer rom_file.close(); - const shared_ctx = try SharedContext.init(allocator); - defer shared_ctx.deinit(allocator); + const ctx = try SharedCtx.init(allocator); + defer ctx.deinit(allocator); var scheduler = try Scheduler.init(allocator); defer scheduler.deinit(); @@ -47,8 +47,8 @@ pub fn main() !void { var cp15 = System.Cp15{}; - var bus7 = try System.Bus7.init(allocator, &scheduler, shared_ctx); - var bus9 = try System.Bus9.init(allocator, &scheduler, shared_ctx); + var bus7 = try System.Bus7.init(allocator, &scheduler, ctx); + var bus9 = try System.Bus9.init(allocator, &scheduler, ctx); var arm7tdmi = System.Arm7tdmi.init(IScheduler.init(&scheduler), IBus.init(&bus7)); var arm946es = System.Arm946es.init(IScheduler.init(&scheduler), IBus.init(&bus9), ICoprocessor.init(&cp15));