1use crate::config::{CommonConfig, PcEngineConfig}; 2use crate::mainloop::create::{CreatableEmulator, ReadInputResult}; 3use crate::mainloop::{CreatedEmulator, NativeDebugFn, create, file_name_no_ext}; 4use crate::{NativeEmulator, NativeEmulatorResult, extensions}; 5use jgenesis_common::frontend::SaveWriter; 6use jgenesis_native_config::common::WindowSize; 7use jgenesis_native_config::input::mappings::ButtonMappingVec; 8use pce_core::api::PcEngineEmulator; 9 10pub type NativePcEngineEmulator = NativeEmulator<PcEngineEmulator>; 11 12impl CreatableEmulator for PcEngineEmulator { 13 type NativeConfig = PcEngineConfig; 14 type CreateInput = Vec<u8>; 15 16 fn read_create_input( 17 config: &Self::NativeConfig, 18 ) -> NativeEmulatorResult<ReadInputResult<Self::CreateInput>> { 19 create::read_rom_file(&config.common.rom_file_path, extensions::PC_ENGINE) 20 } 21 22 fn create( 23 input: ReadInputResult<Self::CreateInput>, 24 config: &Self::NativeConfig, 25 save_writer: &mut impl SaveWriter, 26 ) -> NativeEmulatorResult<CreatedEmulator<Self>> { 27 let emulator = PcEngineEmulator::create(input.input, config.emulator_config, save_writer); 28 29 let rom_title = file_name_no_ext(&input.rom_path)?; 30 let window_title = format!("pce - {rom_title}"); 31 32 let default_window_size = WindowSize::new_pce( 33 config.common.initial_window_size, 34 config.emulator_config.aspect_ratio, 35 config.emulator_config.crop_overscan, 36 ); 37 38 Ok(CreatedEmulator { emulator, window_title, default_window_size }) 39 } 40 41 fn common_config(config: &Self::NativeConfig) -> &CommonConfig { 42 &config.common 43 } 44 45 fn emulator_config(config: &Self::NativeConfig) -> &Self::Config { 46 &config.emulator_config 47 } 48 49 fn input_mappings(config: &Self::NativeConfig) -> ButtonMappingVec<'_, Self::Button> { 50 config.inputs.to_mapping_vec() 51 } 52 53 fn turbo_input_mappings(config: &Self::NativeConfig) -> ButtonMappingVec<'_, Self::Button> { 54 config.inputs.to_turbo_mapping_vec() 55 } 56 57 fn debug_fn() -> Option<NativeDebugFn<Self>> { 58 Some(|| { 59 jgenesis_debugger_frontend::partial_clone_debug_fn( 60 jgenesis_debugger_frontend::pce::render_fn(), 61 ) 62 }) 63 } 64}