chore(ppu): fix logic error in shifter

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-05-05 20:24:09 -05:00
parent 6575eb5531
commit f6cf5393b6
1 changed files with 23 additions and 25 deletions

View File

@ -293,13 +293,11 @@ impl Ppu {
match self.fetcher.bg.state { match self.fetcher.bg.state {
TileNumber => { TileNumber => {
let x_pos = self.fetcher.x_pos; let x_pos = self.fetcher.x_pos;
let window = self.window_stat.should_draw();
let addr = self.fetcher.bg_tile_num_addr( let addr =
&self.control, self.fetcher
&self.pos, .bg_tile_num_addr(&self.control, &self.pos, x_pos, window);
x_pos,
self.window_stat.should_draw(),
);
let id = self.read_byte(addr); let id = self.read_byte(addr);
self.fetcher.bg.tile.with_id(id); self.fetcher.bg.tile.with_id(id);
@ -309,11 +307,11 @@ impl Ppu {
} }
ToLowByteSleep => self.fetcher.bg.next(TileLowByte), ToLowByteSleep => self.fetcher.bg.next(TileLowByte),
TileLowByte => { TileLowByte => {
let addr = self.fetcher.bg_byte_low_addr( let window = self.window_stat.should_draw();
&self.control,
&self.pos, let addr = self
self.window_stat.should_draw(), .fetcher
); .bg_byte_low_addr(&self.control, &self.pos, window);
let low = self.read_byte(addr); let low = self.read_byte(addr);
self.fetcher.bg.tile.with_low_byte(low); self.fetcher.bg.tile.with_low_byte(low);
@ -322,11 +320,11 @@ impl Ppu {
} }
ToHighByteSleep => self.fetcher.bg.next(TileHighByte), ToHighByteSleep => self.fetcher.bg.next(TileHighByte),
TileHighByte => { TileHighByte => {
let addr = self.fetcher.bg_byte_low_addr( let window = self.window_stat.should_draw();
&self.control,
&self.pos, let addr = self
self.window_stat.should_draw(), .fetcher
); .bg_byte_low_addr(&self.control, &self.pos, window);
let high = self.read_byte(addr + 1); let high = self.read_byte(addr + 1);
self.fetcher.bg.tile.with_high_byte(high); self.fetcher.bg.tile.with_high_byte(high);
@ -340,9 +338,10 @@ impl Ppu {
SendToFifoTwo => { SendToFifoTwo => {
let palette = &self.monochrome.bg_palette; let palette = &self.monochrome.bg_palette;
self.fetcher.send_to_fifo(&mut self.fifo, palette); self.fetcher.send_to_fifo(&mut self.fifo, palette);
self.fetcher.x_pos += 1;
// FIXME: Should this be equivalent to a reset?
self.fetcher.bg.next(TileNumber); self.fetcher.bg.next(TileNumber);
self.fetcher.bg.tile = Default::default();
} }
} }
} }
@ -396,12 +395,13 @@ impl Ppu {
if self.window_stat.coincidence() if self.window_stat.coincidence()
&& self.control.window_enabled() && self.control.window_enabled()
&& self.x_pos >= self.pos.window_x - 7 && self.x_pos >= self.pos.window_x - 7
&& !self.window_stat.should_draw()
{ {
self.window_stat.set_should_draw(true); if !self.window_stat.should_draw() {
self.fetcher.bg.reset(); self.window_stat.set_should_draw(true);
self.fifo.background.clear(); self.fetcher.bg.reset();
self.fetcher.x_pos = 0; self.fifo.background.clear();
self.fetcher.x_pos = 0;
}
} else { } else {
self.window_stat.set_should_draw(false); self.window_stat.set_should_draw(false);
} }
@ -706,7 +706,7 @@ impl PixelFetcher {
tile_data_addr + offset as u16 tile_data_addr + offset as u16
} }
fn send_to_fifo(&mut self, fifo: &mut FifoRenderer, palette: &BackgroundPalette) { fn send_to_fifo(&self, fifo: &mut FifoRenderer, palette: &BackgroundPalette) {
let maybe_low = self.bg.tile.low; let maybe_low = self.bg.tile.low;
let maybe_high = self.bg.tile.high; let maybe_high = self.bg.tile.high;
@ -724,8 +724,6 @@ impl PixelFetcher {
fifo.background.push_back(fifo_info); fifo.background.push_back(fifo_info);
} }
} }
self.x_pos += 1;
} }
pub fn get_obj_low_addr(attr: &ObjectAttribute, pos: &ScreenPosition, size: ObjectSize) -> u16 { pub fn get_obj_low_addr(attr: &ObjectAttribute, pos: &ScreenPosition, size: ObjectSize) -> u16 {