chore(ppu): refactor reset behaviour in fetchers
and other components like window_stat and the window line counter
This commit is contained in:
parent
705194eced
commit
fd2b64496c
72
src/ppu.rs
72
src/ppu.rs
|
@ -85,9 +85,14 @@ impl Ppu {
|
||||||
// Done with rendering this frame,
|
// Done with rendering this frame,
|
||||||
// we can reset the ppu x_pos and fetcher state now
|
// we can reset the ppu x_pos and fetcher state now
|
||||||
self.x_pos = 0;
|
self.x_pos = 0;
|
||||||
|
|
||||||
self.fetch.hblank_reset();
|
self.fetch.hblank_reset();
|
||||||
|
self.window_stat.hblank_reset();
|
||||||
self.obj_buffer.clear();
|
self.obj_buffer.clear();
|
||||||
|
|
||||||
|
self.fifo.back.clear();
|
||||||
|
self.fifo.obj.clear();
|
||||||
|
|
||||||
self.stat.set_mode(PpuMode::HBlank);
|
self.stat.set_mode(PpuMode::HBlank);
|
||||||
} else if self.control.lcd_enabled() {
|
} else if self.control.lcd_enabled() {
|
||||||
// Only Draw when the LCD Is Enabled
|
// Only Draw when the LCD Is Enabled
|
||||||
|
@ -118,6 +123,8 @@ impl Ppu {
|
||||||
|
|
||||||
// Reset Window Line Counter in Fetcher
|
// Reset Window Line Counter in Fetcher
|
||||||
self.fetch.vblank_reset();
|
self.fetch.vblank_reset();
|
||||||
|
// Reset WY=LY coincidence flag
|
||||||
|
self.window_stat.vblank_reset();
|
||||||
|
|
||||||
if self.stat.vblank_int() {
|
if self.stat.vblank_int() {
|
||||||
// Enable Vblank LCDStat Interrupt
|
// Enable Vblank LCDStat Interrupt
|
||||||
|
@ -161,7 +168,6 @@ impl Ppu {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scan_state.reset();
|
self.scan_state.reset();
|
||||||
self.window_stat.set_coincidence(false);
|
|
||||||
|
|
||||||
self.stat.set_mode(PpuMode::OamScan);
|
self.stat.set_mode(PpuMode::OamScan);
|
||||||
}
|
}
|
||||||
|
@ -637,15 +643,13 @@ struct PixelFetcher {
|
||||||
|
|
||||||
impl PixelFetcher {
|
impl PixelFetcher {
|
||||||
pub fn hblank_reset(&mut self) {
|
pub fn hblank_reset(&mut self) {
|
||||||
self.back.window_line.hblank_reset();
|
self.back.hblank_reset();
|
||||||
|
self.obj.hblank_reset();
|
||||||
self.back.tile = Default::default();
|
|
||||||
self.back.state = Default::default();
|
|
||||||
self.x_pos = 0;
|
self.x_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vblank_reset(&mut self) {
|
pub fn vblank_reset(&mut self) {
|
||||||
self.back.window_line.vblank_reset();
|
self.back.vblank_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bg_tile_num_addr(
|
fn bg_tile_num_addr(
|
||||||
|
@ -745,9 +749,7 @@ impl PixelFetcher {
|
||||||
trait Fetcher {
|
trait Fetcher {
|
||||||
fn next(&mut self, state: FetcherState);
|
fn next(&mut self, state: FetcherState);
|
||||||
fn reset(&mut self);
|
fn reset(&mut self);
|
||||||
fn pause(&mut self);
|
fn hblank_reset(&mut self);
|
||||||
fn resume(&mut self);
|
|
||||||
fn is_enabled(&self) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -758,6 +760,24 @@ struct BackgroundFetcher {
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BackgroundFetcher {
|
||||||
|
fn pause(&mut self) {
|
||||||
|
self.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resume(&mut self) {
|
||||||
|
self.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_enabled(&self) -> bool {
|
||||||
|
self.enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vblank_reset(&mut self) {
|
||||||
|
self.window_line.vblank_reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Fetcher for BackgroundFetcher {
|
impl Fetcher for BackgroundFetcher {
|
||||||
fn next(&mut self, state: FetcherState) {
|
fn next(&mut self, state: FetcherState) {
|
||||||
self.state = state
|
self.state = state
|
||||||
|
@ -768,17 +788,12 @@ impl Fetcher for BackgroundFetcher {
|
||||||
self.tile = Default::default();
|
self.tile = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause(&mut self) {
|
fn hblank_reset(&mut self) {
|
||||||
self.enabled = false;
|
self.reset();
|
||||||
}
|
self.window_line.hblank_reset();
|
||||||
|
|
||||||
fn resume(&mut self) {
|
|
||||||
self.enabled = true;
|
self.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_enabled(&self) -> bool {
|
|
||||||
self.enabled
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BackgroundFetcher {
|
impl Default for BackgroundFetcher {
|
||||||
|
@ -796,7 +811,6 @@ impl Default for BackgroundFetcher {
|
||||||
struct ObjectFetcher {
|
struct ObjectFetcher {
|
||||||
state: FetcherState,
|
state: FetcherState,
|
||||||
tile: TileBuilder,
|
tile: TileBuilder,
|
||||||
enabled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fetcher for ObjectFetcher {
|
impl Fetcher for ObjectFetcher {
|
||||||
|
@ -807,19 +821,11 @@ impl Fetcher for ObjectFetcher {
|
||||||
fn reset(&mut self) {
|
fn reset(&mut self) {
|
||||||
self.state = Default::default();
|
self.state = Default::default();
|
||||||
self.tile = Default::default();
|
self.tile = Default::default();
|
||||||
self.enabled = Default::default();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause(&mut self) {
|
fn hblank_reset(&mut self) {
|
||||||
self.enabled = false;
|
self.state = Default::default();
|
||||||
}
|
self.tile = Default::default();
|
||||||
|
|
||||||
fn resume(&mut self) {
|
|
||||||
self.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_enabled(&self) -> bool {
|
|
||||||
self.enabled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,4 +1019,12 @@ impl WindowStatus {
|
||||||
pub fn set_coincidence(&mut self, value: bool) {
|
pub fn set_coincidence(&mut self, value: bool) {
|
||||||
self.coincidence = value;
|
self.coincidence = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hblank_reset(&mut self) {
|
||||||
|
self.should_draw = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vblank_reset(&mut self) {
|
||||||
|
self.coincidence = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue