use crate::processor::memory::mmio::gpu::Colour; pub use crate::processor::memory::mmio::joypad::{JoypadButtons, JoypadState}; pub use crate::{HEIGHT, WIDTH}; use async_ringbuf::{AsyncHeapConsumer, AsyncHeapProducer, AsyncHeapRb}; use futures::executor; pub enum EmulatorMessage { Stop, } pub enum RomFile { Path(String), Raw(Vec), } #[cfg(feature = "async")] pub trait Renderer>: Send { fn prepare(&mut self, width: usize, height: usize); fn display(&mut self, buffer: &[Format]); fn set_title(&mut self, _title: String) {} fn latest_joypad_state(&mut self) -> JoypadState; fn set_rumble(&mut self, _rumbling: bool) {} } #[cfg(not(feature = "async"))] pub trait Renderer> { fn prepare(&mut self, width: usize, height: usize); fn display(&mut self, buffer: &[Format]); fn set_title(&mut self, _title: String) {} fn latest_joypad_state(&mut self) -> JoypadState; fn set_rumble(&mut self, _rumbling: bool) {} } pub struct AudioOutput { pub sample_rate: f32, pub send_rb: AsyncHeapProducer<[f32; 2]>, pub wait_for_output: bool, } impl AudioOutput { pub fn new( sample_rate: f32, wait_for_output: bool, frames_to_buffer: usize, ) -> (Self, AsyncHeapConsumer<[f32; 2]>) { let (mut output, rx) = Self::new_unfilled(sample_rate, wait_for_output, frames_to_buffer); executor::block_on( output .send_rb .push_iter(vec![[0.; 2]; output.send_rb.free_len() - 1].into_iter()), ) .unwrap(); (output, rx) } pub fn new_unfilled( sample_rate: f32, wait_for_output: bool, frames_to_buffer: usize, ) -> (Self, AsyncHeapConsumer<[f32; 2]>) { let rb_len = (sample_rate as usize / 60) * frames_to_buffer; let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len); let (send_rb, rx) = rb.split(); ( Self { sample_rate, send_rb, wait_for_output, }, rx, ) } }