diff --git a/src/Bus.zig b/src/Bus.zig index 37c8d7e..5b8e912 100644 --- a/src/Bus.zig +++ b/src/Bus.zig @@ -60,6 +60,10 @@ pub fn deinit(self: Self) void { self.ppu.deinit(); } +pub fn attach(self: *Self, cpu: *Arm7tdmi) void { + self.cpu = cpu; +} + pub fn handleDMATransfers(self: *Self) void { while (self.isDmaRunning()) { if (self.dma._1.step(self)) continue; diff --git a/src/cpu.zig b/src/cpu.zig index 665b840..06e8871 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -80,7 +80,7 @@ pub const Arm7tdmi = struct { binary_log: bool, pub fn init(alloc: Allocator, sched: *Scheduler, paths: FilePaths) !Self { - var cpu: Arm7tdmi = .{ + return Self{ .r = [_]u32{0x00} ** 16, .sched = sched, .bus = try Bus.init(alloc, sched, paths), @@ -93,8 +93,6 @@ pub const Arm7tdmi = struct { .log_buf = undefined, .binary_log = false, }; - cpu.bus.cpu = &cpu; - return cpu; } pub fn deinit(self: Self) void { diff --git a/src/main.zig b/src/main.zig index 90a8266..3cad404 100644 --- a/src/main.zig +++ b/src/main.zig @@ -80,6 +80,8 @@ pub fn main() anyerror!void { const paths = .{ .bios = bios_path, .rom = rom_path, .save = save_path }; var cpu = try Arm7tdmi.init(alloc, &scheduler, paths); defer cpu.deinit(); + + cpu.bus.attach(&cpu); cpu.fastBoot(); // Initialize SDL Audio