From 0e51bd204ee843aac831837ecebf17fcf0aafd64 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Mon, 20 Sep 2021 01:31:03 -0300 Subject: [PATCH] chore: inline some functions --- src/bus.rs | 7 +++++++ src/cpu.rs | 2 ++ src/emu.rs | 9 ++++++--- src/joypad.rs | 2 ++ src/main.rs | 2 +- src/ppu.rs | 1 + 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index 1b7f4d8..bc26521 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -64,10 +64,12 @@ impl Bus { self.boot.is_some() } + #[inline] pub(crate) fn clock(&mut self) { self.tick(4); } + #[inline] fn tick(&mut self, limit: u8) { for _ in 0..limit { self.timer.tick(); @@ -83,6 +85,11 @@ impl Bus { self.oam_write_byte(dest_addr, byte); } } + + #[inline] + pub(crate) fn joyp_mut(&mut self) -> &mut Joypad { + &mut self.joypad + } } impl Bus { diff --git a/src/cpu.rs b/src/cpu.rs index 5b1ab1b..6694cbd 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -156,10 +156,12 @@ impl BusIo for Cpu { } impl Cpu { + #[inline] pub(crate) fn bus(&self) -> &Bus { &self.bus } + #[inline] pub(crate) fn bus_mut(&mut self) -> &mut Bus { &mut self.bus } diff --git a/src/emu.rs b/src/emu.rs index d62d787..a2d4c02 100644 --- a/src/emu.rs +++ b/src/emu.rs @@ -17,8 +17,8 @@ pub fn run_frame(emu: &mut Emulator, gamepad: &mut Gilrs, key: &WinitInputHelper if let Some(event) = gamepad.next_event() { joypad::handle_gamepad_input(emu.joyp_mut(), event); } - joypad::handle_keyboard_input(emu.joyp_mut(), key); + while elapsed < CYCLES_IN_FRAME { elapsed += emu.step(); } @@ -44,15 +44,18 @@ impl Emulator { } fn step(&mut self) -> Cycle { - self.cpu.step() + let cycles = self.cpu.step(); + self.timestamp += cycles; + cycles } fn load_cart(&mut self, rom: Vec) { self.cpu.bus_mut().load_cart(rom) } + #[inline] fn joyp_mut(&mut self) -> &mut Joypad { - &mut self.cpu.bus_mut().joypad + self.cpu.bus_mut().joyp_mut() } pub fn set_prod(&mut self, prod: SampleProducer) { diff --git a/src/joypad.rs b/src/joypad.rs index 06cc9f5..5c5bf88 100644 --- a/src/joypad.rs +++ b/src/joypad.rs @@ -110,6 +110,7 @@ impl ButtonEvent { } } +#[inline] pub fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { use winit::event::VirtualKeyCode; @@ -175,6 +176,7 @@ pub fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { } } +#[inline] pub fn handle_gamepad_input(pad: &mut Joypad, event: GamepadEvent) { use Button::*; use GamepadEventType::*; diff --git a/src/main.rs b/src/main.rs index 41c0b63..48a9a8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use winit::window::{Window, WindowBuilder}; use winit_input_helper::WinitInputHelper; const WINDOW_SCALE: usize = 3; -const AUDIO_ENABLED: bool = false; +const AUDIO_ENABLED: bool = true; fn main() -> Result<()> { let app = App::new(crate_name!()) diff --git a/src/ppu.rs b/src/ppu.rs index 4cc7491..51fe9b5 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -629,6 +629,7 @@ impl ObjectBuffer { self.len += 1; } + #[inline] fn iter_mut(&mut self) -> std::slice::IterMut<'_, Option> { self.inner.iter_mut() }