From bb068def31fa7916e5005ca2be61e8839548a4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Thu, 7 Jul 2022 23:30:23 +0100 Subject: [PATCH] feat: small code refactor --- src/ppu.rs | 2 +- src/timer.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index c2073b2f..2c081774 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -503,7 +503,7 @@ impl Ppu { } pub fn ack_vblank(&mut self) { - self.int_vblank = false; + self.set_int_vblank(false); } /// Fills the frame buffer with pixels of the provided color, diff --git a/src/timer.rs b/src/timer.rs index 0169e9e8..c2f5883a 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -27,21 +27,22 @@ impl Timer { pub fn clock(&mut self, cycles: u8) { self.div_clock += cycles as u16; - self.tima_clock += cycles as u16; - if self.div_clock >= 256 { self.div = self.div.wrapping_add(1); self.div_clock = self.div_clock - 256; } - if self.tima_enabled && self.tima_clock >= self.tima_ratio { - if self.tima == 0xff { - self.int_tima = true; - self.tima = self.tma; - } + if self.tima_enabled { + self.tima_clock += cycles as u16; + if self.tima_clock >= self.tima_ratio { + if self.tima == 0xff { + self.int_tima = true; + self.tima = self.tma; + } - self.tima = self.tima.wrapping_add(1); - self.tima_clock = self.tima_clock - self.tima_ratio; + self.tima = self.tima.wrapping_add(1); + self.tima_clock = self.tima_clock - self.tima_ratio; + } } } @@ -84,6 +85,6 @@ impl Timer { } pub fn ack_tima(&mut self) { - self.int_tima = false; + self.set_int_tima(false); } } -- GitLab