Compare commits
No commits in common. "ac0486be1be4a78181b951cef618d61b950d616a" and "be2dfb379afb69135981323ae9304f5cca737847" have entirely different histories.
ac0486be1b
...
be2dfb379a
|
@ -14,7 +14,7 @@ pub const Io = struct {
|
|||
ie: InterruptEnable,
|
||||
irq: InterruptRequest,
|
||||
postflg: PostFlag,
|
||||
haltcnt: HaltControl,
|
||||
is_halted: bool,
|
||||
|
||||
keyinput: KeyInput,
|
||||
|
||||
|
@ -23,9 +23,9 @@ pub const Io = struct {
|
|||
.ime = false,
|
||||
.ie = .{ .raw = 0x0000 },
|
||||
.irq = .{ .raw = 0x0000 },
|
||||
.postflg = .{ .raw = 0x00 },
|
||||
.keyinput = .{ .raw = 0x03FF },
|
||||
.postflg = .FirstBoot,
|
||||
.haltcnt = .Execute,
|
||||
.is_halted = false,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -33,9 +33,9 @@ pub const Io = struct {
|
|||
pub fn read32(bus: *const Bus, addr: u32) u32 {
|
||||
return switch (addr) {
|
||||
0x0400_0000 => bus.ppu.dispcnt.raw,
|
||||
0x0400_0004 => @as(u32, bus.ppu.vcount.raw) << 16 | bus.ppu.dispstat.raw,
|
||||
0x0400_0006 => @as(u32, bus.ppu.bg[0].cnt.raw) << 16 | bus.ppu.vcount.raw,
|
||||
0x0400_0200 => @as(u32, bus.io.irq.raw) << 16 | bus.io.ie.raw,
|
||||
0x0400_0004 => bus.ppu.dispstat.raw,
|
||||
0x0400_0006 => bus.ppu.vcount.raw,
|
||||
0x0400_0200 => bus.io.ie.raw,
|
||||
0x0400_0208 => @boolToInt(bus.io.ime),
|
||||
0x0400_00C4 => failed_read("Tried to read word from DMA1CNT", .{}),
|
||||
0x0400_00D0 => failed_read("Tried to read word from DMA2CNT", .{}),
|
||||
|
@ -78,10 +78,7 @@ pub fn write32(bus: *Bus, addr: u32, word: u32) void {
|
|||
0x0400_00C0 => log.warn("Wrote 0x{X:0>8} to DMA1DAD", .{word}),
|
||||
0x0400_00C8 => log.warn("Wrote 0x{X:0>8} to DMA2SAD", .{word}),
|
||||
0x0400_00CC => log.warn("Wrote 0x{X:0>8} to DMA2DAD", .{word}),
|
||||
0x0400_0200 => {
|
||||
bus.io.ie.raw = @truncate(u16, word);
|
||||
bus.io.irq.raw &= ~@truncate(u16, word >> 16);
|
||||
},
|
||||
0x0400_0200 => bus.io.ie.raw = @truncate(u16, word),
|
||||
0x0400_0204 => log.warn("Wrote 0x{X:0>8} to WAITCNT", .{word}),
|
||||
0x0400_0208 => bus.io.ime = word & 1 == 1,
|
||||
else => std.debug.panic("Tried to write 0x{X:0>8} to 0x{X:0>8}", .{ word, addr }),
|
||||
|
@ -95,7 +92,6 @@ pub fn read16(bus: *const Bus, addr: u32) u16 {
|
|||
0x0400_0006 => bus.ppu.vcount.raw,
|
||||
0x0400_0130 => bus.io.keyinput.raw,
|
||||
0x0400_0200 => bus.io.ie.raw,
|
||||
0x0400_0202 => bus.io.irq.raw,
|
||||
0x0400_0208 => @boolToInt(bus.io.ime),
|
||||
0x0400_0102 => failed_read("Tried to read halfword from TM0CNT_H", .{}),
|
||||
0x0400_0106 => failed_read("Tried to read halfword from TM1CNT_H", .{}),
|
||||
|
@ -110,10 +106,7 @@ pub fn write16(bus: *Bus, addr: u32, halfword: u16) void {
|
|||
switch (addr) {
|
||||
0x0400_0000 => bus.ppu.dispcnt.raw = halfword,
|
||||
0x0400_0004 => bus.ppu.dispstat.raw = halfword,
|
||||
0x0400_0008 => bus.ppu.bg[0].cnt.raw = halfword,
|
||||
0x0400_000A => bus.ppu.bg[1].cnt.raw = halfword,
|
||||
0x0400_000C => bus.ppu.bg[2].cnt.raw = halfword,
|
||||
0x0400_000E => bus.ppu.bg[3].cnt.raw = halfword,
|
||||
0x0400_0008...0x0400_000F => bus.ppu.bg[addr & 0x3].cnt.raw = halfword,
|
||||
0x0400_0010 => bus.ppu.bg[0].hofs.raw = halfword, // TODO: Don't write out every HOFS / VOFS?
|
||||
0x0400_0012 => bus.ppu.bg[0].vofs.raw = halfword,
|
||||
0x0400_0014 => bus.ppu.bg[1].hofs.raw = halfword,
|
||||
|
@ -169,7 +162,7 @@ pub fn read8(bus: *const Bus, addr: u32) u8 {
|
|||
0x0400_0000 => @truncate(u8, bus.ppu.dispcnt.raw),
|
||||
0x0400_0004 => @truncate(u8, bus.ppu.dispstat.raw),
|
||||
0x0400_0200 => @truncate(u8, bus.io.ie.raw),
|
||||
0x0400_0300 => @enumToInt(bus.io.postflg),
|
||||
0x0400_0300 => bus.io.postflg.raw,
|
||||
0x0400_0006 => @truncate(u8, bus.ppu.vcount.raw),
|
||||
0x0400_0089 => failed_read("Tried to read (high) byte from SOUNDBIAS", .{}),
|
||||
else => std.debug.panic("Tried to read byte from 0x{X:0>8}", .{addr}),
|
||||
|
@ -178,10 +171,8 @@ pub fn read8(bus: *const Bus, addr: u32) u8 {
|
|||
|
||||
pub fn write8(self: *Bus, addr: u32, byte: u8) void {
|
||||
switch (addr) {
|
||||
0x0400_0004 => self.ppu.dispstat.raw = (self.ppu.dispstat.raw & 0xFF00) | byte,
|
||||
0x0400_0005 => self.ppu.dispstat.raw = (@as(u16, byte) << 8) | (self.ppu.dispstat.raw & 0xFF),
|
||||
0x0400_0208 => self.io.ime = byte & 1 == 1,
|
||||
0x0400_0301 => self.io.haltcnt = if (byte >> 7 & 1 == 0) .Halt else std.debug.panic("TODO: Implement STOP", .{}),
|
||||
0x0400_0301 => self.io.is_halted = byte >> 7 & 1 == 0, // TODO: Implement Stop?
|
||||
0x0400_0063 => log.warn("Tried to write 0x{X:0>2} to SOUND1CNT_H (high)", .{byte}),
|
||||
0x0400_0065 => log.warn("Tried to write 0x{X:0>2} to SOUND1CNT_X (high)", .{byte}),
|
||||
0x0400_0069 => log.warn("Tried to write 0x{X:0>2} to SOUND2CNT_L (high)", .{byte}),
|
||||
|
@ -201,16 +192,10 @@ fn failed_read(comptime format: []const u8, args: anytype) u8 {
|
|||
}
|
||||
|
||||
/// Read / Write
|
||||
pub const PostFlag = enum(u1) {
|
||||
FirstBoot = 0,
|
||||
FurtherBoots = 1,
|
||||
};
|
||||
|
||||
/// Write Only
|
||||
pub const HaltControl = enum {
|
||||
Halt,
|
||||
Stop,
|
||||
Execute,
|
||||
pub const PostFlag = extern union {
|
||||
/// 0 if First Boot, 1 if a Reset has been done
|
||||
not_first_boot: Bit(u8, 0),
|
||||
raw: u8,
|
||||
};
|
||||
|
||||
/// Read / Write
|
||||
|
|
|
@ -247,7 +247,7 @@ pub const Arm7tdmi = struct {
|
|||
|
||||
pub fn step(self: *Self) u64 {
|
||||
// If we're halted, the cpu is disabled
|
||||
if (self.bus.io.haltcnt == .Halt) return 1;
|
||||
if (self.bus.io.is_halted) return 1;
|
||||
|
||||
if (self.cpsr.t.read()) {
|
||||
const opcode = self.thumbFetch();
|
||||
|
@ -270,7 +270,7 @@ pub const Arm7tdmi = struct {
|
|||
const should_handle = self.bus.io.ie.raw & self.bus.io.irq.raw;
|
||||
|
||||
if (should_handle != 0) {
|
||||
self.bus.io.haltcnt = .Execute;
|
||||
self.bus.io.is_halted = false;
|
||||
// log.info("An Interrupt was Fired!", .{});
|
||||
|
||||
// Either IME is not true or I in CPSR is true
|
||||
|
|
Loading…
Reference in New Issue