From b57df3d2a7d8cd36e6f2fb353e85d03a96177880 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 4 May 2021 22:55:34 -0500 Subject: [PATCH] chore(ppu): rename Pixel to Pixels Since the Pixel struct represents 8 pixels in a 2BPP format, I felt like the name of the type needed to represent this --- src/ppu.rs | 14 +++++++------- src/ppu/registers.rs | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index b0bd7f2..6f9e662 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -6,7 +6,7 @@ use std::convert::TryInto; use registers::{ BackgroundPalette, GrayShade, LCDControl, LCDStatus, ObjectFlags, ObjectPalette, - ObjectPaletteId, Pixel, PpuMode, RenderPriority, TileDataAddress, + ObjectPaletteId, Pixels, PpuMode, RenderPriority, TileDataAddress, }; mod registers; @@ -246,19 +246,19 @@ impl Ppu { .zip(maybe_high) .expect("Low & High Bytes in TileBuilder were unexpectedly missing."); - let tbpp = Pixel::from_bytes(high, low); + let tbpp = Pixels::from_bytes(high, low); let palette = match attr.flags.palette() { ObjectPaletteId::Zero => self.monochrome.obj_palette_0, ObjectPaletteId::One => self.monochrome.obj_palette_1, }; - let start = ((self.x_pos + 8) - attr.x) as usize; - let end = start + (8 - self.fifo.object.len()); + let end = Pixels::PIXEL_COUNT - self.fifo.object.len(); + let start = Pixels::PIXEL_COUNT - end; let x_flip = attr.flags.x_flip(); - for i in start..end { + for i in start..Pixels::PIXEL_COUNT { let x = if x_flip { 7 - i } else { i }; let priority = attr.flags.priority(); @@ -708,10 +708,10 @@ impl PixelFetcher { .zip(maybe_high) .expect("Low & High Bytes in TileBuilder were unexpectedly missing."); - let tbpp = Pixel::from_bytes(high, low); + let tbpp = Pixels::from_bytes(high, low); if fifo.background.is_empty() { - for x in 0..8 { + for x in 0..Pixels::PIXEL_COUNT { let shade = palette.shade(tbpp.shade_id(x)); let fifo_info = BackgroundFifoInfo { shade }; diff --git a/src/ppu/registers.rs b/src/ppu/registers.rs index 9ae50c6..f169ebd 100644 --- a/src/ppu/registers.rs +++ b/src/ppu/registers.rs @@ -303,9 +303,11 @@ impl From for u8 { } } -pub struct Pixel(u8, u8); +pub struct Pixels(u8, u8); + +impl Pixels { + pub const PIXEL_COUNT: usize = 8; -impl Pixel { pub fn from_bytes(higher: u8, lower: u8) -> Self { Self(higher, lower) }