diff --git a/lib/arm32 b/lib/arm32 index 580e7ba..bdc4bfc 160000 --- a/lib/arm32 +++ b/lib/arm32 @@ -1 +1 @@ -Subproject commit 580e7baca962dd73815bb4717db05b83d55fd58e +Subproject commit bdc4bfc6423f173e28d1ee8a4608d0d90e1da3f3 diff --git a/src/core/emu.zig b/src/core/emu.zig index de275cb..925fb5d 100644 --- a/src/core/emu.zig +++ b/src/core/emu.zig @@ -452,71 +452,91 @@ pub const debug = struct { ; }; - // FIXME: for now, assume ARM7 - pub const Wrapper = struct { - system: System, - scheduler: *Scheduler, + pub fn Wrapper(comptime proc: System.Process) type { + return struct { + system: System, + scheduler: *Scheduler, - pub fn init(system: System, scheduler: *Scheduler) @This() { - return .{ .system = system, .scheduler = scheduler }; - } + pub fn init(system: System, scheduler: *Scheduler) @This() { + return .{ .system = system, .scheduler = scheduler }; + } - pub fn interface(self: *@This(), allocator: Allocator) Interface { - return Interface.init(allocator, self); - } + pub fn interface(self: *@This(), allocator: Allocator) Interface { + return Interface.init(allocator, self); + } - // FIXME: What about ICTM? DTCM? - pub fn read(self: *const @This(), addr: u32) u8 { - return self.system.bus7.dbgRead(u8, addr); - } + pub fn read(self: *const @This(), addr: u32) u8 { + const arm = switch (proc) { + .nds7 => self.system.arm7tdmi, + .nds9 => self.system.arm946es, + }; - pub fn write(self: *@This(), addr: u32, value: u8) void { - self.system.bus7.dbgWrite(u8, addr, value); - } + return arm.dbgRead(u8, addr); + } - pub fn registers(self: *const @This()) *[16]u32 { - return &self.system.arm7tdmi.r; - } + pub fn write(self: *@This(), addr: u32, value: u8) void { + const arm = switch (proc) { + .nds7 => self.system.arm7tdmi, + .nds9 => self.system.arm946es, + }; - pub fn cpsr(self: *const @This()) u32 { - return self.system.arm7tdmi.cpsr.raw; - } + return arm.dbgWrite(u8, addr, value); + } - pub fn step(self: *@This()) void { - const scheduler = self.scheduler; - const system = self.system; + pub fn registers(self: *const @This()) *[16]u32 { + const arm = switch (proc) { + .nds7 => self.system.arm7tdmi, + .nds9 => self.system.arm946es, + }; - var did_step: bool = false; + return &arm.r; + } - // TODO: keep in lockstep with runFrame - while (true) { - if (did_step) break; + pub fn cpsr(self: *const @This()) u32 { + const arm = switch (proc) { + .nds7 => self.system.arm7tdmi, + .nds9 => self.system.arm946es, + }; - switch (isHalted(system)) { - .both => scheduler.tick = scheduler.peekTimestamp(), - inline else => |halt| { - if (!dma9.step(system.arm946es) and comptime halt != .arm9) { - system.arm946es.step(); - system.arm946es.step(); - } + return arm.cpsr.raw; + } - if (!dma7.step(system.arm7tdmi) and comptime halt != .arm7) { - system.arm7tdmi.step(); - did_step = true; - } - }, - } + pub fn step(self: *@This()) void { + const scheduler = self.scheduler; + const system = self.system; - if (scheduler.check()) |ev| { - const late = scheduler.tick - ev.tick; - scheduler.handle(system, ev, late); + var did_step: bool = false; + + // TODO: keep in lockstep with runFrame + while (true) { + if (did_step) break; + + switch (isHalted(system)) { + .both => scheduler.tick = scheduler.peekTimestamp(), + inline else => |halt| { + if (!dma9.step(system.arm946es) and comptime halt != .arm9) { + system.arm946es.step(); + system.arm946es.step(); + } + + if (!dma7.step(system.arm7tdmi) and comptime halt != .arm7) { + system.arm7tdmi.step(); + did_step = true; + } + }, + } + + if (scheduler.check()) |ev| { + const late = scheduler.tick - ev.tick; + scheduler.handle(system, ev, late); + } } } - } - }; + }; + } pub fn run(allocator: Allocator, system: System, scheduler: *Scheduler, should_quit: *AtomicBool) !void { - var wrapper = Wrapper.init(system, scheduler); + var wrapper = Wrapper(.nds7).init(system, scheduler); var emu_interface = wrapper.interface(allocator); defer emu_interface.deinit(); diff --git a/src/gdb.zig b/src/gdb.zig deleted file mode 100644 index e978ebe..0000000 --- a/src/gdb.zig +++ /dev/null @@ -1,42 +0,0 @@ -const std = @import("std"); -const Server = @import("gdbstub").Server; -const Interface = @import("gdbstub").Emulator; -const System = @import("core/emu.zig").System; -const Scheduler = @import("core/Scheduler.zig"); - -const Allocator = std.mem.Allocator; - -pub const TurboWrapper = struct { - system: System, - scheduler: *Scheduler, - - pub fn init(system: System, scheduler: *Scheduler) @This() { - return .{ .system = system, .scheduler = scheduler }; - } - - pub fn interface(self: *@This(), allocator: Allocator) Interface { - return Interface.init(allocator, self); - } - - pub fn read(self: *const @This(), addr: u32) u8 { - return self.cpu.bus.dbgRead(u8, addr); - } - - pub fn write(self: *@This(), addr: u32, value: u8) void { - self.cpu.bus.dbgWrite(u8, addr, value); - } - - pub fn registers(self: *const @This()) *[16]u32 { - return &self.cpu.r; - } - - pub fn cpsr(self: *const @This()) u32 { - return self.cpu.cpsr.raw; - } - - pub fn step(self: *@This()) void { - _ = self; - - @panic("TODO: Handle ARM7 and ARM9 lol"); - } -};