feat: impelemnt BG0,1,2CNT and IF

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-13 03:23:09 -04:00
parent aca7fc9a60
commit b238a3e8f3
1 changed files with 52 additions and 2 deletions

View File

@ -10,8 +10,19 @@ pub const Io = struct {
dispstat: DisplayStatus, dispstat: DisplayStatus,
vcount: VCount, vcount: VCount,
/// Read / Write /// Read / Write
bg0cnt: BackgroundControl,
/// Read / Write
bg1cnt: BackgroundControl,
/// Read / Write
bg2cnt: BackgroundControl,
/// Read / Write
bg3cnt: BackgroundControl,
/// Read / Write
ime: bool, ime: bool,
ie: InterruptEnable, ie: InterruptEnable,
/// Read / Write
irq: InterruptRequest,
keyinput: KeyInput, keyinput: KeyInput,
pub fn init() Self { pub fn init() Self {
@ -19,8 +30,13 @@ pub const Io = struct {
.dispcnt = .{ .raw = 0x0000 }, .dispcnt = .{ .raw = 0x0000 },
.dispstat = .{ .raw = 0x0000 }, .dispstat = .{ .raw = 0x0000 },
.vcount = .{ .raw = 0x0000 }, .vcount = .{ .raw = 0x0000 },
.bg0cnt = .{ .raw = 0x0000 },
.bg1cnt = .{ .raw = 0x0000 },
.bg2cnt = .{ .raw = 0x0000 },
.bg3cnt = .{ .raw = 0x0000 },
.ime = false, .ime = false,
.ie = .{ .raw = 0x0000 }, .ie = .{ .raw = 0x0000 },
.irq = .{ .raw = 0x0000 },
.keyinput = .{ .raw = 0x03FF }, .keyinput = .{ .raw = 0x03FF },
}; };
} }
@ -61,7 +77,9 @@ pub const Io = struct {
switch (addr) { switch (addr) {
0x0400_0000 => self.dispcnt.raw = halfword, 0x0400_0000 => self.dispcnt.raw = halfword,
0x0400_0004 => self.dispstat.raw = halfword, 0x0400_0004 => self.dispstat.raw = halfword,
0x0400_0008 => self.bg0cnt.raw = halfword,
0x0400_0200 => self.ie.raw = halfword, 0x0400_0200 => self.ie.raw = halfword,
0x0400_0202 => self.irq.raw = halfword,
0x0400_0208 => self.ime = halfword & 1 == 1, 0x0400_0208 => self.ime = halfword & 1 == 1,
else => std.debug.panic("[I/O:16] tried to write 0x{X:} to 0x{X:}", .{ halfword, addr }), else => std.debug.panic("[I/O:16] tried to write 0x{X:} to 0x{X:}", .{ halfword, addr }),
} }
@ -77,8 +95,11 @@ pub const Io = struct {
}; };
} }
pub fn write8(_: *Self, addr: u32, byte: u8) void { pub fn write8(self: *Self, addr: u32, byte: u8) void {
std.debug.panic("[I/0:8] tried to write 0x{X:} to 0x{X:}", .{ byte, addr }); switch (addr) {
0x0400_0208 => self.ime = byte & 1 == 1,
else => std.debug.panic("[I/0:8] tried to write 0x{X:} to 0x{X:}", .{ byte, addr }),
}
} }
}; };
@ -148,3 +169,32 @@ const KeyInput = extern union {
shoulder_l: Bit(u16, 9), shoulder_l: Bit(u16, 9),
raw: u16, raw: u16,
}; };
const BackgroundControl = extern union {
bg_priority: Bitfield(u16, 0, 2),
char_base: Bitfield(u16, 2, 2),
mosaic_enable: Bit(u16, 6),
palette_type: Bit(u16, 7),
screen_base: Bitfield(u16, 8, 5),
display_overflow: Bit(u16, 13),
screen_size: Bitfield(u16, 14, 2),
raw: u16,
};
const InterruptRequest = extern union {
vblank: Bit(u16, 0),
hblank: Bit(u16, 1),
coincidence: Bit(u16, 2),
tim0_overflow: Bit(u16, 3),
tim1_overflow: Bit(u16, 4),
tim2_overflow: Bit(u16, 5),
tim3_overflow: Bit(u16, 6),
serial: Bit(u16, 7),
dma0: Bit(u16, 8),
dma1: Bit(u16, 9),
dma2: Bit(u16, 10),
dma3: Bit(u16, 11),
keypad: Bit(u16, 12),
game_pak: Bit(u16, 13),
raw: u16,
};