ferretro/src/main.rs

49 lines
1.4 KiB
Rust
Raw Normal View History

2019-11-04 09:14:16 +01:00
extern crate failure;
extern crate libloading;
#[allow(non_camel_case_types, non_upper_case_globals, non_snake_case, dead_code)]
mod libretro_ffi;
2019-11-04 09:14:16 +01:00
mod libretro_loading;
mod libretro_convert;
mod libretro_wrapper;
use std::ffi::CStr;
use std::path::PathBuf;
use structopt::StructOpt;
use crate::libretro_convert::Handler;
struct Foo;
impl Handler for Foo {
fn video_refresh(&mut self, data: &[u8], width: u32, height: u32, pitch: u32) {
println!("video_refresh {}x{}", width, height);
}
}
#[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,
}
2019-11-04 09:14:16 +01:00
fn main() -> failure::Fallible<()> {
let opt: Opt = Opt::from_args();
let lib = libloading::Library::new(&opt.core)?;
2019-11-04 09:14:16 +01:00
let retro = libretro_loading::LibretroApi::from_library(&lib)?;
let wrapper = libretro_wrapper::LibretroWrapper::from(retro);
let mut foo = Foo{};
wrapper.register_handler(&mut foo);
println!("api version: {}", wrapper.as_ref().api_version());
println!("name: {}", unsafe { CStr::from_ptr(wrapper.as_ref().get_system_info().library_name) }.to_string_lossy());
wrapper.as_ref().init();
wrapper.as_ref().load_game(Some(&opt.rom), None, None);
wrapper.as_ref().run();
2019-11-04 09:14:16 +01:00
Ok(())
}