chore: stub CPU HALTing

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-17 00:27:34 -04:00
parent 07343efdf3
commit f6c8d7ca07
2 changed files with 16 additions and 3 deletions

View File

@ -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 }),
}
}

View File

@ -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 {