From 01278ca83f5d80751c5bd4e66577091f5beb1864 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 30 Oct 2021 10:28:20 +0900 Subject: [PATCH] chore: reduce size of public interface --- src/apu.rs | 2 +- src/bus.rs | 15 ++++++++++----- src/cpu.rs | 2 +- src/emu.rs | 2 +- src/instruction.rs | 8 ++++---- src/joypad.rs | 4 ++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/apu.rs b/src/apu.rs index 91249ea..5ed8d2b 100644 --- a/src/apu.rs +++ b/src/apu.rs @@ -437,7 +437,7 @@ impl Channel1 { } /// 0xFF12 | NR12 - Channel 1 Volume Envelope - pub fn envelope(&self) -> u8 { + pub(crate) fn envelope(&self) -> u8 { u8::from(self.envelope) } diff --git a/src/bus.rs b/src/bus.rs index 8d60b36..7df3c11 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -19,12 +19,12 @@ pub struct Bus { ppu: Ppu, work_ram: WorkRam, var_ram: VariableWorkRam, - pub(crate) timer: Timer, + timer: Timer, int: Interrupt, - pub(crate) apu: Apu, + apu: Apu, high_ram: HighRam, serial: Serial, - pub(crate) joypad: Joypad, + joypad: Joypad, } impl Default for Bus { @@ -103,6 +103,11 @@ impl Bus { self.cart.as_mut() } + #[inline] + pub(crate) fn apu_mut(&mut self) -> &mut Apu { + &mut self.apu + } + #[inline] pub fn ppu(&self) -> &Ppu { &self.ppu @@ -110,7 +115,7 @@ impl Bus { } impl Bus { - pub fn oam_read_byte(&self, addr: u16) -> u8 { + pub(crate) fn oam_read_byte(&self, addr: u16) -> u8 { match addr { 0x0000..=0x7FFF => { // 16KB ROM bank 00 (ends at 0x3FFF) @@ -157,7 +162,7 @@ impl Bus { } } - pub fn oam_write_byte(&mut self, addr: u16, byte: u8) { + pub(crate) fn oam_write_byte(&mut self, addr: u16, byte: u8) { self.ppu.oam.write_byte(addr, byte); } } diff --git a/src/cpu.rs b/src/cpu.rs index 1dd10f2..c63901f 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -103,7 +103,7 @@ impl Cpu { /// routine. /// /// Handle HALT and interrupts. - pub fn step(&mut self) -> Cycle { + pub(crate) fn step(&mut self) -> Cycle { // Log instructions // if self.reg.pc > 0xFF { // let out = std::io::stdout(); diff --git a/src/emu.rs b/src/emu.rs index 2f8c27c..7459b32 100644 --- a/src/emu.rs +++ b/src/emu.rs @@ -90,7 +90,7 @@ impl Emulator { } pub fn set_prod(&mut self, prod: SampleProducer) { - self.cpu.bus_mut().apu.attach_producer(prod) + self.cpu.bus_mut().apu_mut().attach_producer(prod) } pub fn title(&self) -> &str { diff --git a/src/instruction.rs b/src/instruction.rs index ebbdcf5..ad8a291 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -1893,7 +1893,7 @@ mod table { } impl Group1RegisterPair { - pub fn as_register_pair(&self) -> RegisterPair { + pub(crate) fn as_register_pair(&self) -> RegisterPair { use Group1RegisterPair::*; match self { @@ -1927,7 +1927,7 @@ mod table { } impl Group2RegisterPair { - pub fn as_register_pair(&self) -> RegisterPair { + pub(crate) fn as_register_pair(&self) -> RegisterPair { use Group2RegisterPair::*; match self { @@ -1961,7 +1961,7 @@ mod table { } impl Group3RegisterPair { - pub fn as_register_pair(&self) -> RegisterPair { + pub(crate) fn as_register_pair(&self) -> RegisterPair { use Group3RegisterPair::*; match self { @@ -2003,7 +2003,7 @@ mod table { } impl Register { - pub fn cpu_register(&self) -> CpuRegister { + pub(crate) fn cpu_register(&self) -> CpuRegister { use Register::*; match self { diff --git a/src/joypad.rs b/src/joypad.rs index c2bd98c..28479e0 100644 --- a/src/joypad.rs +++ b/src/joypad.rs @@ -111,7 +111,7 @@ impl ButtonEvent { } #[inline] -pub fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { +pub(crate) fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { use winit::event::VirtualKeyCode; // TODO: What do I have to do to get a match statement here? @@ -177,7 +177,7 @@ pub fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { } #[inline] -pub fn handle_gamepad_input(pad: &mut Joypad, event: GamepadEvent) { +pub(crate) fn handle_gamepad_input(pad: &mut Joypad, event: GamepadEvent) { use Button::*; use GamepadEventType::*;