gb-emu/lib/src/connect/mod.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2023-02-26 11:56:45 +11:00
pub use crate::processor::memory::mmio::joypad::JoypadState;
2023-03-03 18:08:28 +11:00
use async_ringbuf::{AsyncHeapConsumer, AsyncHeapProducer, AsyncHeapRb};
use futures::executor;
2023-03-02 10:20:50 +11:00
2023-03-02 11:29:54 +11:00
pub enum EmulatorMessage {
Stop,
}
2023-03-06 17:23:46 +11:00
pub enum RomFile {
Path(String),
Raw(Vec<u8>),
}
2023-03-02 10:20:50 +11:00
pub trait Renderer {
fn prepare(&mut self, width: usize, height: usize);
fn display(&mut self, buffer: &[u32]);
fn set_title(&mut self, _title: String) {}
fn latest_joypad_state(&mut self) -> JoypadState;
fn set_rumble(&mut self, _rumbling: bool) {}
}
2023-03-03 18:08:28 +11:00
pub struct AudioOutput {
pub sample_rate: u32,
pub send_rb: AsyncHeapProducer<f32>,
}
impl AudioOutput {
pub fn new(sample_rate: u32) -> (Self, AsyncHeapConsumer<f32>) {
let rb_len = sample_rate as usize / 60;
let rb = AsyncHeapRb::<f32>::new(rb_len);
let (mut send_rb, rx) = rb.split();
executor::block_on(send_rb.push_iter(vec![0.; rb_len - 1].into_iter())).unwrap();
(
Self {
sample_rate,
send_rb,
},
rx,
)
}
}