Compare commits

..

No commits in common. "db012c7f4b83671fb76de6a512383fefefd4d7a3" and "9973dc8714d84f473aa604cd74dc3656f9d76d5f" have entirely different histories.

2 changed files with 24 additions and 13 deletions

View File

@ -468,15 +468,6 @@ impl Channel1 {
// If this bit is set, a trigger event occurs // If this bit is set, a trigger event occurs
if self.freq_hi.initial() { if self.freq_hi.initial() {
if self.is_dac_enabled() {
self.enabled = true;
}
// Length behaviour during trigger event
if self.length_timer == 0 {
self.length_timer = 64;
}
// Envelope Behaviour during trigger event // Envelope Behaviour during trigger event
self.period_timer = self.envelope.period(); self.period_timer = self.envelope.period();
self.current_volume = self.envelope.init_vol(); self.current_volume = self.envelope.init_vol();
@ -484,15 +475,25 @@ impl Channel1 {
// Sweep behaviour during trigger event // Sweep behaviour during trigger event
let sweep_period = self.sweep.period(); let sweep_period = self.sweep.period();
let sweep_shift = self.sweep.shift_count(); let sweep_shift = self.sweep.shift_count();
self.shadow_freq = self.frequency(); self.shadow_freq = self.frequency();
self.sweep_timer = if sweep_period == 0 { 8 } else { sweep_period }; self.sweep_timer = if sweep_period == 0 { 8 } else { sweep_period };
self.sweep_enabled = sweep_period != 0 || sweep_shift != 0; if sweep_period != 0 || sweep_shift != 0 {
self.sweep_enabled = true;
}
if sweep_shift != 0 { if sweep_shift != 0 {
let _ = self.calc_sweep_freq(); let _ = self.calc_sweep_freq();
} }
// Length behaviour during trigger event
if self.length_timer == 0 {
self.length_timer = 64;
}
if self.is_dac_enabled() {
self.enabled = true;
}
} }
} }

View File

@ -4,6 +4,7 @@ use gb::{AudioSPSC, Cycle, GB_HEIGHT, GB_WIDTH};
use gilrs::Gilrs; use gilrs::Gilrs;
use pixels::{PixelsBuilder, SurfaceTexture}; use pixels::{PixelsBuilder, SurfaceTexture};
use rodio::{OutputStream, Sink}; use rodio::{OutputStream, Sink};
use std::time::{Duration, Instant};
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::{Event, VirtualKeyCode}; use winit::event::{Event, VirtualKeyCode};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
@ -70,7 +71,6 @@ fn main() -> Result<()> {
let (prod, cons) = spsc.init(); let (prod, cons) = spsc.init();
let sink = Sink::try_new(&stream_handle)?; let sink = Sink::try_new(&stream_handle)?;
sink.append(cons); sink.append(cons);
sink.set_volume(0.1); // TODO: Is this the right way to go about this?
game_boy.apu_mut().attach_producer(prod); game_boy.apu_mut().attach_producer(prod);
std::thread::spawn(move || { std::thread::spawn(move || {
@ -78,6 +78,8 @@ fn main() -> Result<()> {
}); });
} }
let mut start = Instant::now();
let frame_time = Duration::from_secs_f64(1.0 / 59.73); // 59.73 Hz on Host
let mut cycle_count: Cycle = Default::default(); let mut cycle_count: Cycle = Default::default();
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
@ -102,7 +104,15 @@ fn main() -> Result<()> {
pixels.resize_surface(size.width, size.height); pixels.resize_surface(size.width, size.height);
} }
let mut diff = Instant::now() - start;
while diff.subsec_nanos() < frame_time.subsec_nanos() {
if cycle_count < gb::emu::CYCLES_IN_FRAME {
cycle_count += gb::emu::run_frame(&mut game_boy, &mut gamepad, &input); cycle_count += gb::emu::run_frame(&mut game_boy, &mut gamepad, &input);
}
diff = Instant::now() - start;
}
start = Instant::now();
if cycle_count >= gb::emu::CYCLES_IN_FRAME { if cycle_count >= gb::emu::CYCLES_IN_FRAME {
cycle_count %= gb::emu::CYCLES_IN_FRAME; cycle_count %= gb::emu::CYCLES_IN_FRAME;