From 606f9b959ac831a6a7121c9fb0b82f3c46b25ccc Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:21 -0300 Subject: [PATCH] chore: stub CPU HALTing --- src/bus/io.zig | 3 +++ src/cpu.zig | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bus/io.zig b/src/bus/io.zig index c9b0722..f9892b6 100644 --- a/src/bus/io.zig +++ b/src/bus/io.zig @@ -11,6 +11,7 @@ pub const Io = struct { ime: bool, ie: InterruptEnable, irq: InterruptRequest, + is_halted: bool, keyinput: KeyInput, @@ -20,6 +21,7 @@ pub const Io = struct { .ie = .{ .raw = 0x0000 }, .irq = .{ .raw = 0x0000 }, .keyinput = .{ .raw = 0x03FF }, + .is_halted = false, }; } }; @@ -209,6 +211,7 @@ pub fn read8(bus: *const Bus, addr: u32) u8 { pub fn write8(self: *Bus, addr: u32, byte: u8) void { switch (addr) { 0x0400_0208 => self.io.ime = byte & 1 == 1, + 0x0400_0301 => self.io.is_halted = byte >> 7 & 1 == 0, // TODO: Implement Stop? else => std.debug.panic("[I/0:8] tried to write 0x{X:} to 0x{X:}", .{ byte, addr }), } } diff --git a/src/cpu.zig b/src/cpu.zig index 2302963..db5517c 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -52,6 +52,7 @@ const arm_lut: [0x1000]ArmInstrFn = armPopulate(); const thumb_lut: [0x400]ThumbInstrFn = thumbPopulate(); const enable_logging = @import("main.zig").enable_logging; +const log = std.log.scoped(.Arm7Tdmi); pub const Arm7tdmi = struct { const Self = @This(); @@ -245,14 +246,23 @@ pub const Arm7tdmi = struct { } pub fn step(self: *Self) u64 { + if (self.bus.io.is_halted) { + // const ie = self.bus.io.ie.raw; + // const irq = self.bus.io.irq.raw; + + // if (ie & irq != 0) self.bus.io.is_halted = false; + + // log.warn("FIXME: Enable GBA HALTing", .{}); + } + if (self.cpsr.t.read()) { const opcode = self.thumbFetch(); - if (enable_logging) if (self.log_file) |file| self.log(file, opcode); + if (enable_logging) if (self.log_file) |file| self.debug_log(file, opcode); thumb_lut[thumbIdx(opcode)](self, self.bus, opcode); } else { const opcode = self.fetch(); - if (enable_logging) if (self.log_file) |file| self.log(file, opcode); + if (enable_logging) if (self.log_file) |file| self.debug_log(file, opcode); if (checkCond(self.cpsr, @truncate(u4, opcode >> 28))) { arm_lut[armIdx(opcode)](self, self.bus, opcode); @@ -278,7 +288,7 @@ pub const Arm7tdmi = struct { return self.r[15] + 4; } - fn log(self: *const Self, file: *const File, opcode: u32) void { + fn debug_log(self: *const Self, file: *const File, opcode: u32) void { if (self.binary_log) { self.skyLog(file) catch unreachable; } else {