simple core info querying

This commit is contained in:
lifning 2021-12-14 03:14:10 -08:00
parent b2c2c93537
commit 768dfb75bb
5 changed files with 52 additions and 13 deletions

View File

@ -0,0 +1,12 @@
use ferretro_base::retro::loading::LibretroApi;
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
for core_path in std::env::args().skip(1) {
println!("{}:", core_path);
let lib = libloading::Library::new(&core_path)?;
let api = LibretroApi::from_library(lib)?;
let info = api.get_system_info();
println!("\t{} {} {:?}", info.library_name, info.library_version, info.valid_extensions);
}
Ok(())
}

View File

@ -4,6 +4,7 @@ use std::os::raw::{c_char, c_void};
use std::path::Path; use std::path::Path;
use libloading; use libloading;
use crate::prelude::SystemInfo2;
use super::ffi::*; use super::ffi::*;
@ -143,11 +144,11 @@ impl LibretroApi {
unsafe { (&self.core_api.retro_api_version)() as u32 } unsafe { (&self.core_api.retro_api_version)() as u32 }
} }
/// Gets statically known system info. Can be called at any time, even before retro_init(). /// Gets statically known system info. Can be called at any time, even before retro_init().
pub fn get_system_info(&self) -> SystemInfo { pub fn get_system_info(&self) -> SystemInfo2 {
unsafe { unsafe {
let mut info = ::std::mem::zeroed::<SystemInfo>(); let mut info = ::std::mem::zeroed::<SystemInfo>();
(&self.core_api.retro_get_system_info)(&mut info); (&self.core_api.retro_get_system_info)(&mut info);
info SystemInfo2::from(&info)
} }
} }
/// Gets information about system audio/video timings and geometry. /// Gets information about system audio/video timings and geometry.

View File

@ -2,12 +2,24 @@ use core::convert::{TryFrom, TryInto};
use core::mem::size_of; use core::mem::size_of;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::os::raw::{c_uint}; use std::os::raw::{c_char, c_uint};
use std::slice::from_raw_parts; use std::slice::from_raw_parts;
use super::constants::*; use super::constants::*;
use super::ffi::*; use super::ffi::*;
fn delimited_cstr(cstr: *const c_char, delim: char) -> Vec<String> {
if cstr.is_null() {
Vec::new()
} else {
unsafe { CStr::from_ptr(cstr) }
.to_string_lossy()
.split(delim)
.map(str::to_string)
.collect()
}
}
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum VideoFrame<'a> { pub enum VideoFrame<'a> {
XRGB1555 { data: &'a [u16], width: c_uint, height: c_uint, pitch_u16: usize }, XRGB1555 { data: &'a [u16], width: c_uint, height: c_uint, pitch_u16: usize },
@ -124,6 +136,26 @@ impl<D> TryFrom<(D, c_uint)> for InputDeviceId
} }
} }
pub struct SystemInfo2 {
pub library_name: String,
pub library_version: String,
pub valid_extensions: Vec<String>,
pub need_fullpath: bool,
pub block_extract: bool,
}
impl From<&SystemInfo> for SystemInfo2 {
fn from(info: &SystemInfo) -> Self {
SystemInfo2 {
library_name: unsafe { CStr::from_ptr(info.library_name) }.to_string_lossy().to_string(),
library_version: unsafe { CStr::from_ptr(info.library_version) }.to_string_lossy().to_string(),
valid_extensions: delimited_cstr(info.valid_extensions, '|'),
need_fullpath: info.need_fullpath,
block_extract: info.block_extract,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Variable2 { pub struct Variable2 {
pub key: String, pub key: String,
@ -145,7 +177,7 @@ impl From<&Variable> for Variable2 {
.get(1) .get(1)
.unwrap_or(&"") .unwrap_or(&"")
.split('|') .split('|')
.map(String::from) .map(str::to_string)
.collect(); .collect();
Variable2 { Variable2 {
key, key,
@ -268,11 +300,7 @@ impl From<&SubsystemRomInfo> for SubsystemRomInfo2 {
description: unsafe { CStr::from_ptr(sri.desc) } description: unsafe { CStr::from_ptr(sri.desc) }
.to_string_lossy() .to_string_lossy()
.to_string(), .to_string(),
valid_extensions: unsafe { CStr::from_ptr(sri.valid_extensions) } valid_extensions: delimited_cstr(sri.valid_extensions, '|'),
.to_string_lossy()
.split('|')
.map(str::to_string)
.collect(),
need_fullpath: sri.need_fullpath, need_fullpath: sri.need_fullpath,
block_extract: sri.block_extract, block_extract: sri.block_extract,
required: sri.required, required: sri.required,

View File

@ -1,6 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use std::ffi::CStr;
use std::path::Path; use std::path::Path;
use sdl2::Sdl; use sdl2::Sdl;
@ -108,7 +107,7 @@ impl RetroComponent for SimpleSdl2CanvasComponent {
let sys_info = retro.get_system_info(); let sys_info = retro.get_system_info();
let title = format!( let title = format!(
"{} - {} - ferretro SDL", "{} - {} - ferretro SDL",
unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy(), sys_info.library_name,
rom.file_stem().unwrap_or_default().to_string_lossy(), rom.file_stem().unwrap_or_default().to_string_lossy(),
); );
self.canvas.window_mut().set_title(&title)?; self.canvas.window_mut().set_title(&title)?;

View File

@ -1,6 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use std::ffi::CStr;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::path::Path; use std::path::Path;
@ -97,7 +96,7 @@ impl RetroComponent for SimpleSdl2OpenglComponent {
let sys_info = retro.get_system_info(); let sys_info = retro.get_system_info();
let title = format!( let title = format!(
"{} - {} - ferretro SDL GL", "{} - {} - ferretro SDL GL",
unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy(), sys_info.library_name,
rom.file_stem().unwrap_or_default().to_string_lossy(), rom.file_stem().unwrap_or_default().to_string_lossy(),
); );
self.canvas.window_mut().set_title(&title)?; self.canvas.window_mut().set_title(&title)?;