feat: stub mode 1 and 2

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-05-01 18:53:11 -03:00
parent 41558c9103
commit 12f9bb51c1
2 changed files with 48 additions and 1 deletions

View File

@ -25,7 +25,7 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
const rb = opcode >> 3 & 0x7; const rb = opcode >> 3 & 0x7;
const rd = opcode & 0x7; const rd = opcode & 0x7;
const address = cpu.r[rb] + cpu.r[ro]; const address = cpu.r[rb] +% cpu.r[ro];
if (T) { if (T) {
// Format 8 // Format 8

View File

@ -135,6 +135,7 @@ pub const Ppu = struct {
if (maybe_sprites) |sprite| { if (maybe_sprites) |sprite| {
// Move on to the next sprite If its of a different priority // Move on to the next sprite If its of a different priority
if (sprite.priority() != prio) continue :sprite_loop; if (sprite.priority() != prio) continue :sprite_loop;
if (sprite.attr0.rot_scaling.read()) continue :sprite_loop; // TODO: Affine Sprites
var i: u9 = 0; var i: u9 = 0;
px_loop: while (i < sprite.width) : (i += 1) { px_loop: while (i < sprite.width) : (i += 1) {
@ -302,6 +303,52 @@ pub const Ppu = struct {
std.mem.set(?u16, &self.scanline_buf, null); std.mem.set(?u16, &self.scanline_buf, null);
std.mem.set(?Sprite, &self.scanline_sprites, null); std.mem.set(?Sprite, &self.scanline_sprites, null);
}, },
0x1 => {
const fb_base = framebuf_pitch * @as(usize, scanline);
if (obj_enable) self.fetchSprites();
var layer: usize = 0;
while (layer < 4) : (layer += 1) {
self.drawSprites(@truncate(u2, layer));
if (layer == self.bg[0].cnt.priority.read() and bg_enable & 1 == 1) self.drawBackround(0);
if (layer == self.bg[1].cnt.priority.read() and bg_enable >> 1 & 1 == 1) self.drawBackround(1);
// TODO: Implement Affine BG2
}
// Copy Drawn Scanline to Frame Buffer
// If there are any nulls present in self.scanline_buf it means that no background drew a pixel there, so draw backdrop
for (self.scanline_buf) |maybe_px, i| {
const bgr555 = if (maybe_px) |px| px else self.palette.getBackdrop();
std.mem.copy(u8, self.framebuf[fb_base + i * @sizeOf(u32) ..][0..4], &intToBytes(u32, toRgba8888(bgr555)));
}
// Reset Current Scanline Pixel Buffer and list of fetched sprites
// in prep for next scanline
std.mem.set(?u16, &self.scanline_buf, null);
std.mem.set(?Sprite, &self.scanline_sprites, null);
},
0x2 => {
const fb_base = framebuf_pitch * @as(usize, scanline);
if (obj_enable) self.fetchSprites();
var layer: usize = 0;
while (layer < 4) : (layer += 1) {
self.drawSprites(@truncate(u2, layer));
// TODO: Implement Affine BG2, BG3
}
// Copy Drawn Scanline to Frame Buffer
// If there are any nulls present in self.scanline_buf it means that no background drew a pixel there, so draw backdrop
for (self.scanline_buf) |maybe_px, i| {
const bgr555 = if (maybe_px) |px| px else self.palette.getBackdrop();
std.mem.copy(u8, self.framebuf[fb_base + i * @sizeOf(u32) ..][0..4], &intToBytes(u32, toRgba8888(bgr555)));
}
// Reset Current Scanline Pixel Buffer and list of fetched sprites
// in prep for next scanline
std.mem.set(?u16, &self.scanline_buf, null);
std.mem.set(?Sprite, &self.scanline_sprites, null);
},
0x3 => { 0x3 => {
const vram_base = width * @sizeOf(u16) * @as(usize, scanline); const vram_base = width * @sizeOf(u16) * @as(usize, scanline);
const fb_base = framebuf_pitch * @as(usize, scanline); const fb_base = framebuf_pitch * @as(usize, scanline);