77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
#[macro_use] extern crate failure;
|
|
extern crate crossbeam_channel;
|
|
extern crate ferretro;
|
|
extern crate sdl2;
|
|
extern crate serde;
|
|
extern crate serde_bytes;
|
|
extern crate ascii;
|
|
|
|
use structopt::StructOpt;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use ferretro_synced::emulator::emulator::MyEmulator;
|
|
use ferretro_synced::emulator::libretro_memory_map::LibRetroMemoryMap;
|
|
use ferretro_synced::sync::game::{SyncableGame, KnownGames, read_game_name, create_game};
|
|
use ferretro_synced::sync::comms::CommunicationSettings;
|
|
|
|
pub fn main() -> failure::Fallible<()> {
|
|
let opt: Opt = Opt::from_args();
|
|
let mut emu = MyEmulator::new(&opt.core, &opt.system);
|
|
emu.load_game(&opt.rom);
|
|
|
|
// memory map should be ready after init & loading game.
|
|
//let memory_map = emu.memory_map.as_ref().expect("Memory map was not set by emulator core, cannot continue.");
|
|
|
|
match (&opt.state) {
|
|
Some(s) => emu.load_state(s),
|
|
None => ()
|
|
}
|
|
|
|
let comms_settings = CommunicationSettings {
|
|
connection: "ws://127.0.0.1:8765".to_string()
|
|
};
|
|
|
|
|
|
if let Err(e) = attempt_to_start_sync(&mut emu, comms_settings) {
|
|
println!("Error trying to start sync: {:?}", e);
|
|
}
|
|
|
|
emu.run();
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn attempt_to_start_sync(emu: &mut MyEmulator, comms_settings: CommunicationSettings) -> Result<(), failure::Error> {
|
|
match &emu.game_info {
|
|
Some(game_info) => match read_game_name(&game_info.game_name) {
|
|
Some(which_game) => match &emu.memory_map {
|
|
Some(memory_map) => {
|
|
let synced_game = create_game(which_game, comms_settings, memory_map);
|
|
emu.begin_sync(synced_game);
|
|
Ok(())
|
|
},
|
|
None => Err(format_err!("Memory map has not been set"))
|
|
},
|
|
None => Err(format_err!("Unrecognized game {}", game_info.game_name))
|
|
},
|
|
None => Err(format_err!("Couldn't get game metadata"))
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(StructOpt)]
|
|
struct Opt {
|
|
/// Core module to use.
|
|
#[structopt(short, long, parse(from_os_str))]
|
|
core: PathBuf,
|
|
/// ROM to load using the core.
|
|
#[structopt(short, long, parse(from_os_str))]
|
|
rom: PathBuf,
|
|
/// System directory, often containing BIOS files
|
|
#[structopt(short, long, parse(from_os_str))]
|
|
system: Option<PathBuf>,
|
|
/// Serialized game state to load
|
|
#[structopt(long, parse(from_os_str))]
|
|
state: Option<PathBuf>,
|
|
}
|