diff --git a/Cargo.lock b/Cargo.lock index d8729ff..0acb9c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -538,6 +538,14 @@ dependencies = [ "gl_generator", ] +[[package]] +name = "letsplay_libretro_sys" +version = "0.1.0-alpha0" +dependencies = [ + "cc", + "libretro-sys", +] + [[package]] name = "letsplay_retro_frontend" version = "0.1.0-alpha0" @@ -545,9 +553,9 @@ dependencies = [ "anyhow", "cc", "letsplay_core", + "letsplay_libretro_sys", "libc", "libloading", - "libretro-sys", "serde", "thiserror", "toml", diff --git a/Cargo.toml b/Cargo.toml index 80c753e..c75f061 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "crates/letsplay_av_ffmpeg", # Libretro frontend library + "crates/letsplay_libretro_sys", "crates/letsplay_retro_frontend", "crates/retrodemo", diff --git a/crates/letsplay_libretro_sys/Cargo.toml b/crates/letsplay_libretro_sys/Cargo.toml new file mode 100644 index 0000000..25712e6 --- /dev/null +++ b/crates/letsplay_libretro_sys/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "letsplay_libretro_sys" +description = "Selective updates on top of the libretro-sys crate (which was last updated 2016)" +publish.workspace = true +version.workspace = true +edition.workspace = true + +[dependencies] +libretro-sys = "0.1.1" + +[build-dependencies] +cc = "1.0.99" diff --git a/crates/letsplay_retro_frontend/src/libretro_sys_new.rs b/crates/letsplay_libretro_sys/src/lib.rs similarity index 83% rename from crates/letsplay_retro_frontend/src/libretro_sys_new.rs rename to crates/letsplay_libretro_sys/src/lib.rs index 3ce7abe..5d7749d 100644 --- a/crates/letsplay_retro_frontend/src/libretro_sys_new.rs +++ b/crates/letsplay_libretro_sys/src/lib.rs @@ -1,11 +1,14 @@ //! Selective additional (2019+) updates on top of the existing libretro_sys crate. +//! This was created since newer cores do use this stuff; it's annoying, but meh. +//! Maybe later on we can rid ourselves of a 2016 crate and just bindgen off libretro +//! directly; for now, this is fine enough. pub use libretro_sys::*; use std::ffi; /// This "button" represents a bitmask that describes the state of all [DEVICE_JOYPAD] button constants, /// rather than the state of a single button. -pub const DEVICE_ID_JOYPAD_MASK: libc::c_uint = 256; +pub const DEVICE_ID_JOYPAD_MASK: ffi::c_uint = 256; /// Defines overrides which modify frontend handling of specific content file types. /// An array of [SystemContentInfoOverride] is passed to [RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE] diff --git a/crates/letsplay_retro_frontend/Cargo.toml b/crates/letsplay_retro_frontend/Cargo.toml index cb3142d..e4d690e 100644 --- a/crates/letsplay_retro_frontend/Cargo.toml +++ b/crates/letsplay_retro_frontend/Cargo.toml @@ -8,7 +8,7 @@ edition.workspace = true [dependencies] libc.workspace = true libloading.workspace = true -libretro-sys = "0.1.1" +letsplay_libretro_sys.path = "../letsplay_libretro_sys" thiserror.workspace = true anyhow.workspace = true diff --git a/crates/letsplay_retro_frontend/src/frontend/callbacks.rs b/crates/letsplay_retro_frontend/src/frontend/callbacks.rs index 10e1351..aefb1a1 100644 --- a/crates/letsplay_retro_frontend/src/frontend/callbacks.rs +++ b/crates/letsplay_retro_frontend/src/frontend/callbacks.rs @@ -1,5 +1,5 @@ //! Callbacks for libretro -use crate::libretro_sys_new::*; +use letsplay_libretro_sys::*; use crate::{frontend::*, libretro_log, util}; use std::ffi; diff --git a/crates/letsplay_retro_frontend/src/frontend/frontend_impl.rs b/crates/letsplay_retro_frontend/src/frontend/frontend_impl.rs index 1f7c7a1..c44150c 100644 --- a/crates/letsplay_retro_frontend/src/frontend/frontend_impl.rs +++ b/crates/letsplay_retro_frontend/src/frontend/frontend_impl.rs @@ -1,6 +1,6 @@ use super::CoreVariable; use crate::input_devices::InputDevice; -use crate::libretro_sys_new::*; +use letsplay_libretro_sys::*; use crate::result::{Error, Result}; use ffi::CString; use libloading::Library; @@ -272,13 +272,13 @@ impl Frontend { // Let's sanity check the libretro API version against bindings to make sure we can actually use this core. // If we can't, then fail the load. let api_version = (core_api.retro_api_version)(); - if api_version != libretro_sys::API_VERSION { + if api_version != letsplay_libretro_sys::API_VERSION { error!( "Core {} has invalid API version {api_version}; refusing to continue loading", path.as_ref().display() ); return Err(Error::InvalidLibRetroAPI { - expected: libretro_sys::API_VERSION, + expected: letsplay_libretro_sys::API_VERSION, got: api_version, }); } diff --git a/crates/letsplay_retro_frontend/src/input_devices/analog_retropad.rs b/crates/letsplay_retro_frontend/src/input_devices/analog_retropad.rs index 583b1f6..9fef824 100644 --- a/crates/letsplay_retro_frontend/src/input_devices/analog_retropad.rs +++ b/crates/letsplay_retro_frontend/src/input_devices/analog_retropad.rs @@ -1,5 +1,3 @@ -use crate::libretro_sys_new; - use super::{InputDevice, RetroPad}; // private helper type for packaging up the stick data @@ -45,7 +43,7 @@ impl AnalogRetroPad { impl InputDevice for AnalogRetroPad { fn device_type(&self) -> u32 { - libretro_sys_new::DEVICE_ANALOG + letsplay_libretro_sys::DEVICE_ANALOG } fn device_type_compatible(&self, id: u32) -> bool { @@ -54,7 +52,7 @@ impl InputDevice for AnalogRetroPad { true } else { // Check for the analog type - id == libretro_sys_new::DEVICE_ANALOG + id == letsplay_libretro_sys::DEVICE_ANALOG } } @@ -68,14 +66,14 @@ impl InputDevice for AnalogRetroPad { // Nasty but you can blame libretro. let fallback = self.pad.get_index(0, id); return match index { - libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT => match id { - libretro_sys_new::DEVICE_ID_ANALOG_X => self.left_stick.x, - libretro_sys_new::DEVICE_ID_ANALOG_Y => self.left_stick.y, + letsplay_libretro_sys::DEVICE_INDEX_ANALOG_LEFT => match id { + letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.left_stick.x, + letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.left_stick.y, _ => fallback, }, - libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT => match id { - libretro_sys_new::DEVICE_ID_ANALOG_X => self.right_stick.x, - libretro_sys_new::DEVICE_ID_ANALOG_Y => self.right_stick.y, + letsplay_libretro_sys::DEVICE_INDEX_ANALOG_RIGHT => match id { + letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.right_stick.x, + letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.right_stick.y, _ => fallback, }, @@ -97,15 +95,15 @@ impl InputDevice for AnalogRetroPad { }; match index { - libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT => match id { - libretro_sys_new::DEVICE_ID_ANALOG_X => self.left_stick.x = pressure, - libretro_sys_new::DEVICE_ID_ANALOG_Y => self.left_stick.y = pressure, + letsplay_libretro_sys::DEVICE_INDEX_ANALOG_LEFT => match id { + letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.left_stick.x = pressure, + letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.left_stick.y = pressure, _ => {} }, - libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT => match id { - libretro_sys_new::DEVICE_ID_ANALOG_X => self.right_stick.x = pressure, - libretro_sys_new::DEVICE_ID_ANALOG_Y => self.right_stick.y = pressure, + letsplay_libretro_sys::DEVICE_INDEX_ANALOG_RIGHT => match id { + letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.right_stick.x = pressure, + letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.right_stick.y = pressure, _ => {} }, diff --git a/crates/letsplay_retro_frontend/src/input_devices/mouse.rs b/crates/letsplay_retro_frontend/src/input_devices/mouse.rs index 4250fff..d8c4183 100644 --- a/crates/letsplay_retro_frontend/src/input_devices/mouse.rs +++ b/crates/letsplay_retro_frontend/src/input_devices/mouse.rs @@ -1,6 +1,5 @@ //! Mouse use super::InputDevice; -use crate::libretro_sys_new; /// Implementation of the [InputDevice] trait for the Libretro mouse. pub struct Mouse { @@ -21,7 +20,7 @@ impl Mouse { impl InputDevice for Mouse { fn device_type(&self) -> u32 { - libretro_sys_new::DEVICE_MOUSE + letsplay_libretro_sys::DEVICE_MOUSE } fn device_type_compatible(&self, id: u32) -> bool { diff --git a/crates/letsplay_retro_frontend/src/input_devices/retropad.rs b/crates/letsplay_retro_frontend/src/input_devices/retropad.rs index afe32eb..16a665e 100644 --- a/crates/letsplay_retro_frontend/src/input_devices/retropad.rs +++ b/crates/letsplay_retro_frontend/src/input_devices/retropad.rs @@ -1,6 +1,6 @@ //! RetroPad use super::InputDevice; -use crate::libretro_sys_new; +use letsplay_libretro_sys; /// Implementation of the [InputDevice] trait for the Libretro /// RetroPad; which is essentially a standard PS1 controller, @@ -45,7 +45,7 @@ impl RetroPad { impl InputDevice for RetroPad { fn device_type(&self) -> u32 { - libretro_sys_new::DEVICE_JOYPAD + letsplay_libretro_sys::DEVICE_JOYPAD } fn device_type_compatible(&self, id: u32) -> bool { @@ -55,7 +55,7 @@ impl InputDevice for RetroPad { fn get_index(&self, index: u32, id: u32) -> i16 { return match index { 0 => { - if id == libretro_sys_new::DEVICE_ID_JOYPAD_MASK { + if id == letsplay_libretro_sys::DEVICE_ID_JOYPAD_MASK { return self.button_mask(); } diff --git a/crates/letsplay_retro_frontend/src/lib.rs b/crates/letsplay_retro_frontend/src/lib.rs index 3887031..bd5aa45 100644 --- a/crates/letsplay_retro_frontend/src/lib.rs +++ b/crates/letsplay_retro_frontend/src/lib.rs @@ -2,13 +2,12 @@ mod libretro_log; -pub mod libretro_sys_new; - pub mod input_devices; -pub mod util; +mod util; pub mod frontend; pub mod result; // re-export some of our useful interface pub use frontend::{CoreVariable, Frontend, FrontendInterface}; +pub use result::*; diff --git a/crates/letsplay_retro_frontend/src/libretro_log.rs b/crates/letsplay_retro_frontend/src/libretro_log.rs index b1fd00e..b79d4a5 100644 --- a/crates/letsplay_retro_frontend/src/libretro_log.rs +++ b/crates/letsplay_retro_frontend/src/libretro_log.rs @@ -1,4 +1,4 @@ -use crate::libretro_sys_new::*; +use letsplay_libretro_sys::*; use std::ffi; use tracing::*; diff --git a/crates/letsplay_retro_frontend/src/util.rs b/crates/letsplay_retro_frontend/src/util.rs index 95655f8..77aee93 100644 --- a/crates/letsplay_retro_frontend/src/util.rs +++ b/crates/letsplay_retro_frontend/src/util.rs @@ -1,4 +1,4 @@ -use crate::libretro_sys_new::*; +use letsplay_libretro_sys::*; pub fn bytes_per_pixel_from_libretro(pf: PixelFormat) -> u32 { match pf {