feat(bus): implement Palette RAM and DISPSTAT

This commit is contained in:
2022-01-04 03:29:56 -06:00
parent 8b9a80b279
commit 5ea888f68c
3 changed files with 69 additions and 12 deletions

View File

@@ -4,10 +4,12 @@ const Allocator = std.mem.Allocator;
pub const Ppu = struct {
vram: Vram,
palette: Palette,
pub fn init(alloc: Allocator) !@This() {
return @This(){
.vram = try Vram.init(alloc),
.palette = try Palette.init(alloc),
};
}
@@ -16,6 +18,44 @@ pub const Ppu = struct {
}
};
const Palette = struct {
buf: []u8,
alloc: Allocator,
fn init(alloc: Allocator) !@This() {
return @This(){
.buf = try alloc.alloc(u8, 0x400),
.alloc = alloc,
};
}
fn deinit(self: *@This()) void {
self.alloc.free(self.buf);
}
pub inline fn get32(self: *const @This(), idx: usize) u32 {
return (@as(u32, self.get16(idx + 2)) << 16) | @as(u32, self.get16(idx));
}
pub inline fn set32(self: *@This(), idx: usize, word: u32) void {
self.set16(idx + 2, @truncate(u16, word >> 16));
self.set16(idx, @truncate(u16, word));
}
pub inline fn get16(self: *const @This(), idx: usize) u16 {
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
}
pub inline fn set16(self: *@This(), idx: usize, halfword: u16) void {
self.buf[idx + 1] = @truncate(u8, halfword >> 8);
self.buf[idx] = @truncate(u8, halfword);
}
pub inline fn get8(self: *const @This(), idx: usize) u8 {
return self.buf[idx];
}
};
const Vram = struct {
buf: []u8,
alloc: Allocator,