Skip to content
Snippets Groups Projects
Verified Commit 63f47c86 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: better reset of APU and Timer

Support for set of video, audio and timer.
Now with support for toggling audio in the SDL version.
parent 1336a3af
No related branches found
No related tags found
No related merge requests found
Pipeline #2321 passed
...@@ -162,6 +162,11 @@ impl Emulator { ...@@ -162,6 +162,11 @@ impl Emulator {
); );
} }
pub fn toggle_audio(&mut self) {
let apu_enabled = self.system.get_apu_enabled();
self.system.set_apu_enabled(!apu_enabled);
}
pub fn toggle_palette(&mut self) { pub fn toggle_palette(&mut self) {
self.system self.system
.ppu() .ppu()
...@@ -225,6 +230,10 @@ impl Emulator { ...@@ -225,6 +230,10 @@ impl Emulator {
keycode: Some(Keycode::B), keycode: Some(Keycode::B),
.. ..
} => self.benchmark(Benchmark::default()), } => self.benchmark(Benchmark::default()),
Event::KeyDown {
keycode: Some(Keycode::T),
..
} => self.toggle_audio(),
Event::KeyDown { Event::KeyDown {
keycode: Some(Keycode::P), keycode: Some(Keycode::P),
.. ..
......
...@@ -128,6 +128,56 @@ impl Apu { ...@@ -128,6 +128,56 @@ impl Apu {
} }
} }
pub fn reset(&mut self) {
self.ch1_timer = 0;
self.ch1_sequence = 0;
self.ch1_envelope_sequence = 0;
self.ch1_envelope_enabled = false;
self.ch1_sweep_sequence = 0;
self.ch1_output = 0;
self.ch1_sweep_slope = 0x0;
self.ch1_sweep_increase = false;
self.ch1_sweep_pace = 0x0;
self.ch1_length_timer = 0x0;
self.ch1_wave_duty = 0x0;
self.ch1_pace = 0x0;
self.ch1_direction = 0x0;
self.ch1_volume = 0x0;
self.ch1_wave_length = 0x0;
self.ch1_length_stop = false;
self.ch1_enabled = false;
self.ch2_timer = 0;
self.ch2_sequence = 0;
self.ch2_envelope_sequence = 0;
self.ch2_envelope_enabled = false;
self.ch2_output = 0;
self.ch2_length_timer = 0x0;
self.ch2_wave_duty = 0x0;
self.ch2_pace = 0x0;
self.ch2_direction = 0x0;
self.ch2_volume = 0x0;
self.ch2_wave_length = 0x0;
self.ch2_length_stop = false;
self.ch2_enabled = false;
self.ch3_timer = 0;
self.ch3_position = 0;
self.ch3_output = 0;
self.ch3_dac = false;
self.ch3_length_timer = 0x0;
self.ch3_output_level = 0x0;
self.ch3_wave_length = 0x0;
self.ch3_length_stop = false;
self.ch3_enabled = false;
self.sequencer = 0;
self.sequencer_step = 0;
self.output_timer = 0;
self.clear_audio_buffer()
}
pub fn clock(&mut self, cycles: u8) { pub fn clock(&mut self, cycles: u8) {
// @TODO the performance here requires improvement // @TODO the performance here requires improvement
for _ in 0..cycles { for _ in 0..cycles {
......
...@@ -77,13 +77,14 @@ impl GameBoy { ...@@ -77,13 +77,14 @@ impl GameBoy {
Self { Self {
cpu, cpu,
ppu_enabled: true, ppu_enabled: true,
apu_enabled: false, apu_enabled: true,
timer_enabled: true, timer_enabled: true,
} }
} }
pub fn reset(&mut self) { pub fn reset(&mut self) {
self.ppu().reset(); self.ppu().reset();
self.apu().reset();
self.mmu().reset(); self.mmu().reset();
self.cpu.reset(); self.cpu.reset();
} }
...@@ -254,6 +255,30 @@ impl GameBoy { ...@@ -254,6 +255,30 @@ impl GameBoy {
pub fn get_compilation_time(&self) -> String { pub fn get_compilation_time(&self) -> String {
String::from(COMPILATION_TIME) String::from(COMPILATION_TIME)
} }
pub fn get_ppu_enabled(&self) -> bool {
self.ppu_enabled
}
pub fn set_ppu_enabled(&mut self, value: bool) {
self.ppu_enabled = value;
}
pub fn get_apu_enabled(&self) -> bool {
self.apu_enabled
}
pub fn set_apu_enabled(&mut self, value: bool) {
self.apu_enabled = value;
}
pub fn get_timer_enabled(&self) -> bool {
self.apu_enabled
}
pub fn set_timer_enabled(&mut self, value: bool) {
self.timer_enabled = value;
}
} }
/// Gameboy implementations that are meant with performance /// Gameboy implementations that are meant with performance
......
...@@ -27,6 +27,18 @@ impl Timer { ...@@ -27,6 +27,18 @@ impl Timer {
} }
} }
pub fn reset(&mut self) {
self.div = 0;
self.tima = 0;
self.tma = 0;
self.tac = 0x0;
self.div_clock = 0;
self.tima_clock = 0;
self.tima_enabled = false;
self.tima_ratio = 1024;
self.int_tima = false;
}
pub fn clock(&mut self, cycles: u8) { pub fn clock(&mut self, cycles: u8) {
self.div_clock += cycles as u16; self.div_clock += cycles as u16;
while self.div_clock >= 256 { while self.div_clock >= 256 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment