Added dummy audio device to disable audio while still simulating the devices

This commit is contained in:
transistor 2022-09-29 19:55:12 -07:00
parent 9e3b75f9fd
commit 82644db3fc
7 changed files with 402 additions and 421 deletions

779
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,4 +6,8 @@ members = [
"emulator/frontends/minifb",
"tests/harte_tests"
]
exclude = [
"emulator/frontends/pixels",
"emulator/frontends/macroquad",
]
default-members = ["emulator/frontends/minifb"]

View File

@ -8,5 +8,5 @@ pub mod audio;
pub use self::keys::Key;
pub use self::controllers::{ControllerDevice, ControllerEvent};
pub use self::traits::{Host, Tty, WindowUpdater, ControllerUpdater, KeyboardUpdater, Audio, BlitableSurface, HostData};
pub use self::traits::{Host, Tty, WindowUpdater, ControllerUpdater, KeyboardUpdater, Audio, BlitableSurface, HostData, DummyAudio};

View File

@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex, MutexGuard};
use crate::error::Error;
use crate::host::keys::Key;
use crate::host::gfx::Frame;
use crate::host::controllers::{ControllerDevice, ControllerEvent};
pub trait Host {
@ -36,6 +37,7 @@ pub trait Tty {
pub trait WindowUpdater: Send {
fn get_size(&mut self) -> (u32, u32);
fn get_frame(&mut self) -> Result<Frame, Error>;
fn update_frame(&mut self, width: u32, height: u32, bitmap: &mut [u32]);
}
@ -85,3 +87,19 @@ impl<T: Copy> HostData<T> {
}
}
pub struct DummyAudio();
impl Audio for DummyAudio {
fn samples_per_second(&self) -> usize {
48000
}
fn space_available(&self) -> usize {
4800
}
fn write_samples(&mut self, _buffer: &[f32]) {}
fn flush(&mut self) {}
}

View File

@ -1,7 +1,7 @@
[package]
name = "moa_common"
version = "0.1.0"
edition = "2018"
edition = "2021"
[features]
tty = ["nix"]
@ -9,6 +9,6 @@ audio = ["cpal"]
[dependencies]
moa_core = { path = "../../core" }
nix = { version = "0.23", optional = true }
cpal = { version = "0.13", optional = true }
nix = { version = "0.25", optional = true }
cpal = { version = "0.14", optional = true }

View File

@ -1,7 +1,7 @@
[package]
name = "moa_minifb"
version = "0.1.0"
edition = "2018"
edition = "2021"
default-run = "moa-genesis"
[dependencies]

View File

@ -1,4 +1,5 @@
use std::mem;
use std::rc::Rc;
use std::cell::RefCell;
@ -17,20 +18,27 @@ use crate::peripherals::coprocessor::{CoprocessorCoordinator, CoprocessorBankReg
pub struct SegaGenesisOptions {
pub rom: String,
pub rom_data: Option<Vec<u8>>,
}
impl SegaGenesisOptions {
pub fn new() -> Self {
Self {
rom: "".to_string(),
rom_data: None,
}
}
}
pub fn build_genesis<H: Host>(host: &mut H, options: SegaGenesisOptions) -> Result<System, Error> {
pub fn build_genesis<H: Host>(host: &mut H, mut options: SegaGenesisOptions) -> Result<System, Error> {
let mut system = System::new();
let rom = MemoryBlock::load(&options.rom).unwrap();
let rom = if options.rom_data.is_some() {
let data = mem::take(&mut options.rom_data).unwrap();
MemoryBlock::new(data)
} else {
MemoryBlock::load(&options.rom).unwrap()
};
//let mut rom = MemoryBlock::load("binaries/genesis/GenTestV3.0.bin").unwrap();
//let mut rom = MemoryBlock::load("binaries/genesis/HDRV_Genesis_Test_v1_4.bin").unwrap();
//let mut rom = MemoryBlock::load("binaries/genesis/ComradeOj's tiny demo.bin").unwrap();