chore(ppu): rename select method and variables
This commit is contained in:
parent
8a06fe9ff8
commit
0672c7346a
45
src/ppu.rs
45
src/ppu.rs
|
@ -211,21 +211,6 @@ impl Ppu {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// // Determine whether we need to enable sprite fetching
|
|
||||||
// let mut obj_attr = None;
|
|
||||||
|
|
||||||
// for attr in self.obj_buffer.iter().flatten() {
|
|
||||||
// if attr.x <= (self.x_pos + 8) {
|
|
||||||
// // self.fetcher.obj.resume(); TODO: Try running only when there's a sprite
|
|
||||||
// self.fetcher.bg.reset();
|
|
||||||
// self.fetcher.bg.pause();
|
|
||||||
// self.fifo.pause();
|
|
||||||
|
|
||||||
// obj_attr = Some(*attr);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if let Some(attr) = obj_attr {
|
if let Some(attr) = obj_attr {
|
||||||
match self.fetcher.obj.state {
|
match self.fetcher.obj.state {
|
||||||
TileNumber => {
|
TileNumber => {
|
||||||
|
@ -264,29 +249,28 @@ impl Ppu {
|
||||||
.zip(maybe_high)
|
.zip(maybe_high)
|
||||||
.expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
|
.expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
|
||||||
|
|
||||||
let pixel = TwoBitsPerPixel::from_bytes(high, low);
|
let tbpp = TwoBitsPerPixel::from_bytes(high, low);
|
||||||
|
|
||||||
let palette = match attr.flags.palette() {
|
let palette = match attr.flags.palette() {
|
||||||
ObjectPaletteId::Zero => self.monochrome.obj_palette_0,
|
ObjectPaletteId::Zero => self.monochrome.obj_palette_0,
|
||||||
ObjectPaletteId::One => self.monochrome.obj_palette_1,
|
ObjectPaletteId::One => self.monochrome.obj_palette_1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let num_to_add = 8 - self.fifo.object.len();
|
let start = ((self.x_pos + 8) - attr.x) as usize;
|
||||||
|
let end = 8 - self.fifo.object.len();
|
||||||
for i in 0..num_to_add {
|
|
||||||
let bit = 7 - i;
|
|
||||||
|
|
||||||
|
for x in start..end {
|
||||||
let priority = attr.flags.priority();
|
let priority = attr.flags.priority();
|
||||||
|
|
||||||
let shade = palette.colour(pixel.pixel(bit));
|
let shade = palette.shade(tbpp.shade_id(x));
|
||||||
|
|
||||||
let fifo_pixel = ObjectFifoPixel {
|
let fifo_info = ObjectFifoPixel {
|
||||||
shade,
|
shade,
|
||||||
palette,
|
palette,
|
||||||
priority,
|
priority,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.fifo.object.push_back(fifo_pixel);
|
self.fifo.object.push_back(fifo_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fetcher.bg.resume();
|
self.fetcher.bg.resume();
|
||||||
|
@ -711,14 +695,11 @@ impl PixelFetcher {
|
||||||
.zip(maybe_high)
|
.zip(maybe_high)
|
||||||
.expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
|
.expect("Low & High Bytes in TileBuilder were unexpectedly missing.");
|
||||||
|
|
||||||
let pixel = TwoBitsPerPixel::from_bytes(high, low);
|
let tbpp = TwoBitsPerPixel::from_bytes(high, low);
|
||||||
|
|
||||||
if fifo.background.is_empty() {
|
if fifo.background.is_empty() {
|
||||||
for i in 0..8 {
|
for x in 0..8 {
|
||||||
// Horizontally flip pixels
|
let shade = palette.shade(tbpp.shade_id(x));
|
||||||
let bit = 7 - i;
|
|
||||||
|
|
||||||
let shade = palette.colour(pixel.pixel(bit));
|
|
||||||
|
|
||||||
let fifo_pixel = BackgroundFifoPixel { shade };
|
let fifo_pixel = BackgroundFifoPixel { shade };
|
||||||
fifo.background.push_back(fifo_pixel);
|
fifo.background.push_back(fifo_pixel);
|
||||||
|
@ -735,12 +716,12 @@ impl PixelFetcher {
|
||||||
let y = attr.y.wrapping_sub(16);
|
let y = attr.y.wrapping_sub(16);
|
||||||
|
|
||||||
let line = if attr.flags.y_flip() {
|
let line = if attr.flags.y_flip() {
|
||||||
(obj_size - (line_y - y)) * 2
|
obj_size - (line_y - y)
|
||||||
} else {
|
} else {
|
||||||
(line_y - y) * 2
|
line_y - y
|
||||||
};
|
};
|
||||||
|
|
||||||
0x8000 + (attr.tile_index as u16 * 16) + line as u16
|
0x8000 + (attr.tile_index as u16 * 16) + (line as u16 * 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ bitfield! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackgroundPalette {
|
impl BackgroundPalette {
|
||||||
pub fn colour(&self, id: u8) -> GrayShade {
|
pub fn shade(&self, id: u8) -> GrayShade {
|
||||||
match id {
|
match id {
|
||||||
0b00 => self.i0_colour(),
|
0b00 => self.i0_colour(),
|
||||||
0b01 => self.i1_colour(),
|
0b01 => self.i1_colour(),
|
||||||
|
@ -267,7 +267,7 @@ bitfield! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectPalette {
|
impl ObjectPalette {
|
||||||
pub fn colour(&self, id: u8) -> Option<GrayShade> {
|
pub fn shade(&self, id: u8) -> Option<GrayShade> {
|
||||||
match id {
|
match id {
|
||||||
0b00 => None,
|
0b00 => None,
|
||||||
0b01 => Some(self.i1_colour()),
|
0b01 => Some(self.i1_colour()),
|
||||||
|
@ -310,7 +310,9 @@ impl TwoBitsPerPixel {
|
||||||
Self(higher, lower)
|
Self(higher, lower)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pixel(&self, bit: usize) -> u8 {
|
pub fn shade_id(&self, x: usize) -> u8 {
|
||||||
|
let bit = 7 - x;
|
||||||
|
|
||||||
let higher = self.0 >> bit;
|
let higher = self.0 >> bit;
|
||||||
let lower = self.1 >> bit;
|
let lower = self.1 >> bit;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue