use std::sync::mpsc::{channel, Receiver, Sender}; use async_ringbuf::AsyncHeapConsumer; use gb_emu_lib::{ connect::{AudioOutput, EmulatorMessage, EmulatorOptions, NoCamera, RomFile}, EmulatorCore, }; pub struct TestEmulator { pub core: EmulatorCore<[u8; 4], NoCamera>, pub sender: Sender>, pub audio_rx: AsyncHeapConsumer<[f32; 2]>, pub serial_rx: Receiver, } pub fn emulator_setup(rom_file: RomFile) -> Result { let (sender, receiver) = channel::>(); let (rom, camera) = rom_file .load(gb_emu_lib::connect::SramType::None, NoCamera::default()) .map_err(|_e| String::from("Error reading ROM: {_e:?}"))?; let (audio_output, audio_rx) = AudioOutput::new( 48000., 1, gb_emu_lib::connect::DownsampleType::ZeroOrderHold, ); // let (tx_to_gameboy, rx_from_test) = channel::(); let (tx_to_test, serial_rx) = channel::(); let options = EmulatorOptions::new(None, rom, audio_output) .with_no_output(true) .with_serial_target(gb_emu_lib::connect::SerialTarget::Custom { rx: None, tx: Some(tx_to_test), }) .with_cgb_bootrom(Some(RomFile::Raw( include_bytes!("../../../sameboy-bootroms/cgb_boot.bin").to_vec(), ))) .with_dmg_bootrom(Some(RomFile::Raw( include_bytes!("../../../sameboy-bootroms/dmg_boot.bin").to_vec(), ))); let core = EmulatorCore::init(true, receiver, options, camera); sender .send(EmulatorMessage::Start) .map_err(|_e| String::from("Error sending message: {_e:?}"))?; Ok(TestEmulator { core, sender, audio_rx, serial_rx, }) }