From 12f9bb51c180c296441f49ded93cd75d3a7ad035 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 1 May 2022 18:53:11 -0300 Subject: [PATCH] feat: stub mode 1 and 2 --- src/cpu/thumb/data_transfer.zig | 2 +- src/ppu.zig | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/cpu/thumb/data_transfer.zig b/src/cpu/thumb/data_transfer.zig index 542ffee..d299908 100644 --- a/src/cpu/thumb/data_transfer.zig +++ b/src/cpu/thumb/data_transfer.zig @@ -25,7 +25,7 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn { const rb = opcode >> 3 & 0x7; const rd = opcode & 0x7; - const address = cpu.r[rb] + cpu.r[ro]; + const address = cpu.r[rb] +% cpu.r[ro]; if (T) { // Format 8 diff --git a/src/ppu.zig b/src/ppu.zig index f1e566c..6709fb9 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -135,6 +135,7 @@ pub const Ppu = struct { if (maybe_sprites) |sprite| { // Move on to the next sprite If its of a different priority if (sprite.priority() != prio) continue :sprite_loop; + if (sprite.attr0.rot_scaling.read()) continue :sprite_loop; // TODO: Affine Sprites var i: u9 = 0; 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(?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 => { const vram_base = width * @sizeOf(u16) * @as(usize, scanline); const fb_base = framebuf_pitch * @as(usize, scanline);