Compare commits
No commits in common. "b5fae7c071af4844707da30e57c85a6c6f76fe46" and "3b3eb52c48ed52b8831a3facf9e997361f3091ea" have entirely different histories.
b5fae7c071
...
3b3eb52c48
67
src/ppu.zig
67
src/ppu.zig
|
@ -306,7 +306,7 @@ pub const Ppu = struct {
|
|||
self.aff_bg[n - 2].y_latch.? += self.aff_bg[n - 2].pd; // PD is added to BGxY
|
||||
}
|
||||
|
||||
fn drawBackground(self: *Self, comptime n: u2) void {
|
||||
fn drawBackround(self: *Self, comptime n: u2) void {
|
||||
// A Tile in a charblock is a byte, while a Screen Entry is a halfword
|
||||
|
||||
const char_base = 0x4000 * @as(u32, self.bg[n].cnt.char_base.read());
|
||||
|
@ -330,59 +330,6 @@ pub const Ppu = struct {
|
|||
|
||||
const x = hofs + i;
|
||||
|
||||
const win0 = self.dispcnt.win_enable.read() & 1 == 1;
|
||||
const win1 = (self.dispcnt.win_enable.read() >> 1) & 1 == 1;
|
||||
const winObj = self.dispcnt.obj_win_enable.read();
|
||||
|
||||
if (win0 or win1 or winObj) blk: {
|
||||
// Window is enabled
|
||||
const win0_in = (self.win.in.w0_bg.read() >> n) & 1 == 1;
|
||||
const win1_in = (self.win.in.w1_bg.read() >> n) & 1 == 1;
|
||||
const win_out = (self.win.out.out_bg.read() >> n) & 1 == 1;
|
||||
|
||||
if (win0) {
|
||||
const h = self.win.h[0];
|
||||
const v = self.win.v[0];
|
||||
|
||||
const y1 = v.y1.read();
|
||||
const y2 = if (y1 > v.y2.read()) 160 else std.math.min(160, v.y2.read());
|
||||
|
||||
if (y1 <= y and y < y2) {
|
||||
// Within Y bounds
|
||||
const x1 = h.x1.read();
|
||||
const x2 = if (x1 > h.x2.read()) 240 else std.math.min(240, h.x2.read());
|
||||
|
||||
// Within X and & bounds, render Win0 Pixel
|
||||
if (x1 <= x and x < x2) {
|
||||
if (win0_in) break :blk else continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (win1) {
|
||||
const h = self.win.h[1];
|
||||
const v = self.win.v[1];
|
||||
|
||||
const y1 = v.y1.read();
|
||||
const y2 = if (y1 > v.y2.read()) 160 else std.math.min(160, v.y2.read());
|
||||
|
||||
if (y1 <= y and y < y2) {
|
||||
// Within Y bounds
|
||||
const x1 = h.x1.read();
|
||||
const x2 = if (x1 > h.x2.read()) 240 else std.math.min(240, h.x2.read());
|
||||
|
||||
// Within X and & bounds, render Win1 Pixel
|
||||
if (x1 <= x and x < x2) {
|
||||
if (win1_in) break :blk else continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If not Win0 nor Win1 and WinOut isn't enabled,
|
||||
// then don't render this pixel
|
||||
if (!win_out) continue;
|
||||
}
|
||||
|
||||
// Grab the Screen Entry from VRAM
|
||||
const entry_addr = screen_base + tilemapOffset(size, x, y);
|
||||
const entry = @bitCast(ScreenEntry, self.vram.read(u16, entry_addr));
|
||||
|
@ -433,10 +380,10 @@ pub const Ppu = struct {
|
|||
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.drawBackground(0);
|
||||
if (layer == self.bg[1].cnt.priority.read() and bg_enable >> 1 & 1 == 1) self.drawBackground(1);
|
||||
if (layer == self.bg[2].cnt.priority.read() and bg_enable >> 2 & 1 == 1) self.drawBackground(2);
|
||||
if (layer == self.bg[3].cnt.priority.read() and bg_enable >> 3 & 1 == 1) self.drawBackground(3);
|
||||
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);
|
||||
if (layer == self.bg[2].cnt.priority.read() and bg_enable >> 2 & 1 == 1) self.drawBackround(2);
|
||||
if (layer == self.bg[3].cnt.priority.read() and bg_enable >> 3 & 1 == 1) self.drawBackround(3);
|
||||
}
|
||||
|
||||
// Copy Drawn Scanline to Frame Buffer
|
||||
|
@ -461,8 +408,8 @@ pub const Ppu = struct {
|
|||
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.drawBackground(0);
|
||||
if (layer == self.bg[1].cnt.priority.read() and bg_enable >> 1 & 1 == 1) self.drawBackground(1);
|
||||
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);
|
||||
if (layer == self.bg[2].cnt.priority.read() and bg_enable >> 2 & 1 == 1) self.drawAffineBackground(2);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue