diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..4866ada --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "rlnt.keep-a-changelog" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4ca20bc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "editor.rulers": [80,120], + "rust-client.channel": "nightly", + "rust-client.autoStartRls": true, + "rust-client.disableRustup": false, + "rust-client.engine": "rls", + "rust-client.updateOnStartup": true, + "rust.rust-analyzer.releaseTag": "nightly" +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d96b28a..ba80f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Complete **userspace** bindings to: * the [Control Library] + * the [Display Library] + * the *threading* part of the [Thread Manager Library] + * the *semaphore* part of the [Thread Manager Library] +- Partial **userspace** bindings to: + * the *event flags* part of the [Thread Manager Library] +- Complete documentation for: + * the [Type Defines] + * the [System Parameters Defines] + * the [Display Library] + * the [Control Library] + * the [Random Number Library] +- Partial documentation for: + * the *event flags* part of the [Thread Manager Library] + +### Removed +- `SceUVector4` & `SceUMatrix4` structures from `types` (not present in types.h). +- `SceUnion32` & `SceUnion64` & `SceUnion128` union from `types` (not present in types.h) ### Fixed - Fix `i32` being used instead of `u32` as `psp2_sys::types::SceUInt` -[Control Library]: https://docs.vitasdk.org/group__SceCtrlUser.html +### Changed +- Type of variable used by `size` parameter of `ctrl::sceKernelGetRandomNumber` function. (`SceSize` instead of `u32`) +- Type of variable used by `port` variable in struct `SceCtrlPortInfo` (`u8` instead of `SceCtrlExternalInputMode`) +- Type of variable used by `r`, `g`, `b` parameters of `ctrl::sceCtrlSetLightBar` function. (`SceUInt8` instead of `u8`) +- Type of variable used by `batt` parameters of `ctrl::sceCtrlGetBatteryInfo` function. (`SceUInt8` instead of `u8`) ## [v0.2.2] - 2018-09-12 @@ -42,14 +63,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * the *threading* part of the [Thread Manager Library] * the *semaphore* part of the [Thread Manager Library] -[Random Number Library]: https://docs.vitasdk.org/group__SceRngUser.html -[Device Control Library]: https://docs.vitasdk.org/group__SceDevCtlUser.html -[Directory Entries Library]: https://docs.vitasdk.org/group__SceDirEntUser.html -[File Control Library]: https://docs.vitasdk.org/group__SceFcntlUser.html -[File Status Library]: https://docs.vitasdk.org/group__SceStatUser.html -[C Standard Library]: https://docs.vitasdk.org/group__SceCLibUser.html -[Thread Manager Library]: https://docs.vitasdk.org/group__SceThreadMgrUser.html - ## [v0.1.1] - 2018-07-04 ### Changed @@ -73,14 +86,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - A basic README with links to other `vita-rust` projects. - This CHANGELOG file. -[Common Dialog Library]: https://docs.vitasdk.org/group__SceCommonDialogUser.html -[Message Dialog Library]: https://docs.vitasdk.org/group__SceMessageDialogUser.html -[GPU Graphics Library]: https://docs.vitasdk.org/group__SceGxmUser.html -[System Parameters Defines]: https://docs.vitasdk.org/group__SceSystemParamUser.html -[System Memory Library]: https://docs.vitasdk.org/group__SceSysmemUser.html -[Thread Manager Library]: https://docs.vitasdk.org/group__SceThreadMgrUser.html -[Type Defines]: https://docs.vitasdk.org/group__SceTypesUser.html - [Unreleased]: https://github.com/vita-rust/psp2-sys/compare/v0.2.2...HEAD [v0.2.2]: https://github.com/vita-rust/psp2-sys/compare/v0.2.1...v0.2.2 @@ -88,3 +93,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [v0.2.0]: https://github.com/vita-rust/psp2-sys/compare/v0.1.1...v0.2.0 [v0.1.1]: https://github.com/vita-rust/psp2-sys/compare/v0.1.0...v0.1.1 [v0.1.0]: https://github.com/vita-rust/psp2-sys/compare/147a58f...v0.1.0 + + +[Control Library]: https://docs.vitasdk.org/group__SceCtrlUser.html +[Display Library]: https://docs.vitasdk.org/group__SceDisplayUser.html +[Random Number Library]: https://docs.vitasdk.org/group__SceRngUser.html +[Device Control Library]: https://docs.vitasdk.org/group__SceDevCtlUser.html +[Directory Entries Library]: https://docs.vitasdk.org/group__SceDirEntUser.html +[File Control Library]: https://docs.vitasdk.org/group__SceFcntlUser.html +[File Status Library]: https://docs.vitasdk.org/group__SceStatUser.html +[C Standard Library]: https://docs.vitasdk.org/group__SceCLibUser.html +[Common Dialog Library]: https://docs.vitasdk.org/group__SceCommonDialogUser.html +[Message Dialog Library]: https://docs.vitasdk.org/group__SceMessageDialogUser.html +[GPU Graphics Library]: https://docs.vitasdk.org/group__SceGxmUser.html +[System Parameters Defines]: https://docs.vitasdk.org/group__SceSystemParamUser.html +[System Memory Library]: https://docs.vitasdk.org/group__SceSysmemUser.html +[Thread Manager Library]: https://docs.vitasdk.org/group__SceThreadMgrUser.html +[Type Defines]: https://docs.vitasdk.org/group__SceTypesUser.html diff --git a/COPYING b/COPYING index 7702d6c..a7123fa 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,4 @@ +Copyright (c) 2021 Gabriel GRONDIN Copyright (c) 2018 Martin Larralde (martin.larralde@ens-cachan.fr) Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/Cargo.toml b/Cargo.toml index 039fd0b..9d5b33e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,16 @@ [package] name = "psp2-sys" version = "0.2.2" -authors = ["Martin Larralde "] +authors = [ + "Martin Larralde ", + "Gabriel GRONDIN " +] edition = "2018" license = "MIT" description = "Unsafe Rust FFI bindings to the psp2 headers" repository = "https://github.com/vita-rust/psp2-sys" readme = "README.md" -keywords = ["ps-vita", "psp2"] +keywords = ["psvita", "ps vita", "ps-vita", "psp2"] categories = ["no-std", "external-ffi-bindings", "os", "hardware-support"] exclude = ["ci/travis/setup.sh", "Makefile.toml"] diff --git a/src/ctrl.rs b/src/ctrl.rs index bca0a2f..fa85b1d 100644 --- a/src/ctrl.rs +++ b/src/ctrl.rs @@ -1,3 +1,8 @@ +//! SCE Controls + +use crate::types::SceUInt8; + +/// Error codes enumeration. #[repr(u32)] pub enum SceCtrlErrorCode { SCE_CTRL_ERROR_INVALID_ARG = 0x80340001, @@ -8,6 +13,14 @@ pub enum SceCtrlErrorCode { SCE_CTRL_ERROR_FATAL = 0x803400FF, } +/// Enumeration for the digital controller buttons. +/// +/// Notes : +/// > L1/R1/L3/R3 only can bind using [sceCtrlPeekBufferPositiveExt2] and [sceCtrlReadBufferPositiveExt2] +/// +/// > Values bigger than 0x00010000 can be intercepted only with shell privileges +/// +/// > Vita's L Trigger and R Trigger are mapped to L1 and R1 when using [sceCtrlPeekBufferPositiveExt2] and [sceCtrlReadBufferPositiveExt2] #[repr(C)] pub enum SceCtrlButtons { /// Select button. @@ -28,12 +41,10 @@ pub enum SceCtrlButtons { SCE_CTRL_LEFT = 0x00000080, /// Left trigger. SCE_CTRL_LTRIGGER = 0x00000100, - // /// L2 button. - // SCE_CTRL_L2 = SCE_CTRL_LTRIGGER, + // SCE_CTRL_L2 : defined in [SceCtrlButtons] Implementation /// Right trigger. SCE_CTRL_RTRIGGER = 0x00000200, - // /// R2 button. - // SCE_CTRL_R2 = SCE_CTRL_RTRIGGER, + // SCE_CTRL_R2 : Defined in [SceCtrlButtons] Implementation /// L1 button. SCE_CTRL_L1 = 0x00000400, /// R1 button. @@ -48,8 +59,7 @@ pub enum SceCtrlButtons { SCE_CTRL_SQUARE = 0x00008000, /// Input not available because intercercepted by another application SCE_CTRL_INTERCEPTED = 0x00010000, - // /// Playstation (Home) button. - // SCE_CTRL_PSBUTTON = SCE_CTRL_INTERCEPTED, + // SCE_CTRL_PSBUTTON : Defined in [SceCtrlButtons] Implementation /// Headphone plugged in. SCE_CTRL_HEADPHONE = 0x00080000, /// Volume up button. @@ -60,6 +70,17 @@ pub enum SceCtrlButtons { SCE_CTRL_POWER = 0x40000000, } +/// Implementation for [SceCtrlButtons] : Fixing missing enum variant +impl SceCtrlButtons { + /// L2 button. + pub const SCE_CTRL_L2: SceCtrlButtons = SceCtrlButtons::SCE_CTRL_LTRIGGER; + /// R2 button. + pub const SCE_CTRL_R2: SceCtrlButtons = SceCtrlButtons::SCE_CTRL_RTRIGGER; + /// Playstation (Home) button. + pub const SCE_CTRL_PSBUTTON: SceCtrlButtons = SceCtrlButtons::SCE_CTRL_INTERCEPTED; +} + +/// Enumeration for the controller types. #[repr(u8)] pub enum SceCtrlExternalInputMode { /// Unpaired controller @@ -74,58 +95,61 @@ pub enum SceCtrlExternalInputMode { SCE_CTRL_TYPE_DS4 = 8, } +/// Controller mode. #[repr(C)] pub enum SceCtrlPadInputMode { /// Digital buttons only. SCE_CTRL_MODE_DIGITAL = 0, /// Digital buttons + Analog support. SCE_CTRL_MODE_ANALOG = 1, - /// Same as ::SCE_CTRL_MODE_ANALOG, but with larger range for analog sticks. + /// Same as [SCE_CTRL_MODE_ANALOG](crate::ctrl::SceCtrlPadInputMode::SCE_CTRL_MODE_ANALOG), but with larger range for analog sticks. SCE_CTRL_MODE_ANALOG_WIDE = 2, } +/// Returned controller data #[repr(C)] pub struct SceCtrlData { /// The current read frame. pub timeStamp: u64, - /** Bit mask containing zero or more of ::SceCtrlButtons. */ + /// Bit mask containing zero or more of [SceCtrlButtons]. pub buttons: u32, - /** Left analogue stick, X axis. */ + /// Left analogue stick, X axis. pub lx: u8, - /** Left analogue stick, Y axis. */ + /// Left analogue stick, Y axis. pub ly: u8, - /** Right analogue stick, X axis. */ + /// Right analogue stick, X axis. pub rx: u8, - /** Right analogue stick, Y axis. */ + /// Right analogue stick, Y axis. pub ry: u8, - /** Up button */ + /// Up button pub up: u8, - /** Right button */ + /// Right button pub right: u8, - /** Down button */ + /// Down button pub down: u8, - /** Left button */ + /// Left button pub left: u8, - /** Left trigger (L2) */ + /// Left trigger (L2) pub lt: u8, - /** Right trigger (R2) */ + /// Right trigger (R2) pub rt: u8, - /** Left button (L1) */ + /// Left button (L1) pub l1: u8, - /** Right button (R1) */ + /// Right button (R1) pub r1: u8, - /** Triangle button */ + /// Triangle button pub triangle: u8, /// Circle button pub circle: u8, - /** Cross button */ + /// Cross button pub cross: u8, - /** Square button */ + /// Square button pub square: u8, - /** Reserved. */ + /// Reserved. _reserved: [u8; 4], } +/// Structure to pass as argument to [sceCtrlSetRapidFire] #[repr(C)] pub struct SceCtrlRapidFireRule { pub Mask: u32, @@ -136,37 +160,194 @@ pub struct SceCtrlRapidFireRule { pub Break: u32, } +/// Structure to pass as argument to [sceCtrlSetActuator] #[repr(C)] pub struct SceCtrlActuator { + /// Vibration strength of the small motor pub small: u8, + /// Vibration strength of the large motor pub large: u8, + /// Unknown unk: [u8; 6], } +/// Structure to pass as argument to [sceCtrlGetControllerPortInfo] #[repr(C)] pub struct SceCtrlPortInfo { - pub port: [SceCtrlExternalInputMode; 5], + /// Controller type of each port (See [SceCtrlExternalInputMode]) + pub port: [u8; 5], + /// Unknown unk: [u8; 11], } #[cfg_attr(not(feature = "dox"), link(kind = "static", name = "SceCtrl_stub"))] extern "C" { + /// Set the controller mode + /// + /// ### Parameters + /// * `mode` - One of [SceCtrlPadInputMode]. + /// + /// Returns he previous mode, < 0 on error. pub fn sceCtrlSetSamplingMode(mode: SceCtrlPadInputMode) -> i32; + + /// Set the controller extend mode + /// + /// ### Parameters + /// * `mode` - One of [SceCtrlPadInputMode]. + /// + /// Returns the previous mode, < 0 on error. pub fn sceCtrlSetSamplingModeExt(mode: SceCtrlPadInputMode) -> i32; + + /// Get the current controller mode + /// + /// ### Parameters + /// * `pMode` (out) - Return value, see [SceCtrlPadInputMode]. + /// + /// Returns the previous mode, < 0 on error. pub fn sceCtrlGetSamplingMode(pMode: *mut SceCtrlPadInputMode) -> i32; + + /// Get the controller state information (polling, positive logic) + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlPeekBufferPositive(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Get the controller state information (polling, positive logic) + /// + /// This function will bind L/R trigger value to L1/R1 instead of LTRIGGER/RTRIGGER. + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlPeekBufferPositiveExt2(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Get the controller state information (polling, negative logic) + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlPeekBufferNegative(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Get the controller state information (blocking, positive logic) + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlReadBufferPositive(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Get the controller extended state information (blocking, positive logic) + /// + /// This function will bind L/R trigger value to L1/R1 instead of LTRIGGER/RTRIGGER. + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlReadBufferPositiveExt2(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Get the controller state information (blocking, negative logic) + /// + /// ### Parameters + /// * `port` - use 0. + /// * `*pad_data` (out) - see [SceCtrlData]. + /// * `count` - Buffers count. Up to 64 buffers can be requested. + /// + /// Returns buffers count, between 1 and 'count'. < 0 on error. pub fn sceCtrlReadBufferNegative(port: i32, pad_data: *mut SceCtrlData, count: i32) -> i32; + + /// Set rules for button rapid fire + /// + /// ### Parameters + /// * `port` - use 0. + /// * `idx` - rule index between 0-15. + /// * `pRule` - structure [SceCtrlRapidFireRule]. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlSetRapidFire(port: i32, idx: i32, pRule: *const SceCtrlRapidFireRule); + + /// Clear rules for button rapid fire + /// + /// Parameters + /// * `port` - use 0. + /// * `idx` - rule index between 0-15. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlClearRapidFire(port: i32, idx: i32) -> i32; + + /// Control the actuator (vibrate) on paired controllers + /// + /// Parameters + /// * `port` - use 1 for the first paired controller, etc. + /// * `state` - see [SceCtrlActuator]. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlSetActuator(port: i32, pState: *const SceCtrlActuator) -> i32; - pub fn sceCtrlSetLightBar(port: i32, r: u8, g: u8, b: u8) -> i32; + + /// Control the light bar on paired controllers + /// + /// Parameters + /// * `port` - use 1 for the first paired controller, etc. + /// * `r` - red intensity. + /// * `g` - green intensity. + /// * `b` - blue intensity. + /// + /// Returns 0 on success, < 0 on error. + pub fn sceCtrlSetLightBar(port: i32, r: SceUInt8, g: SceUInt8, b: SceUInt8) -> i32; + + /// Get controller port information. + /// + /// Parameters + /// * `info` (out) - see [SceCtrlPortInfo]. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlGetControllerPortInfo(info: *mut SceCtrlPortInfo) -> i32; - pub fn sceCtrlGetBatteryInfo(port: i32, batt: *mut u8) -> i32; + + /// Get controller battery information + /// + /// Parameters + /// * `port` - use 1 for the first paired controller, etc. + /// * `batt` (out) - battery level, between 0-5, 0xEE charging, 0xEF charged. + /// + /// Returns 0 on success, < 0 on error. + pub fn sceCtrlGetBatteryInfo(port: i32, batt: *mut SceUInt8) -> i32; + + /// Sets intercept + /// + /// If true, allows the current thread to intercept controls. + /// The use case might be, for example, a game plugin that wishes to + /// capture input without having the input sent to the game thread. + /// + /// Parameters + /// * `intercept` - Boolean value. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlSetButtonIntercept(intercept: i32) -> i32; + + /// Gets intercept + /// + /// Parameters + /// * `intercept` (out) - Boolean value. + /// + /// Returns 0 on success, < 0 on error. pub fn sceCtrlGetButtonIntercept(intercept: *mut i32) -> i32; + + /// Check if multi controller is supported + /// + /// Returns 1 if yes, 0 if no. pub fn sceCtrlIsMultiControllerSupported() -> i32; } diff --git a/src/display.rs b/src/display.rs index 5d1f284..69bf38f 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,6 +1,8 @@ -use crate::types::SceSize; -use crate::types::SceUID; +//! SCE Display +use crate::types::{SceSize, SceUID}; + +/// SCE Display Error Codes #[repr(u32)] pub enum SceDisplayErrorCode { SCE_DISPLAY_ERROR_OK = 0, @@ -16,53 +18,160 @@ pub enum SceDisplayErrorCode { SCE_DISPLAY_ERROR_NO_OUTPUT_SIGNAL = 0x80290009, } +/// SCE Display Pixel Format #[repr(i32)] pub enum SceDisplayPixelFormat { SCE_DISPLAY_PIXELFORMAT_A8B8G8R8 = 0x00000000, } +/// SCE Display Set Buffer Sync #[repr(i32)] pub enum SceDisplaySetBufSync { + /// Buffer change effective immediately SCE_DISPLAY_SETBUF_IMMEDIATE = 0, + /// Buffer change effective next frame SCE_DISPLAY_SETBUF_NEXTFRAME = 1, } +/// Structure used with [sceDisplaySetFrameBuf] to set/update framebuffer +/// +/// Original screen resolution is 960x544, but the following resolutions can +/// also be supplied as width and height : 480x272, 640x368, 720x408 +/// +/// > Note: This structure is returned by [sceDisplayGetFrameBuf]. #[repr(C)] pub struct SceDisplayFrameBuf { - pub size: SceSize, // sizeof(SceDisplayFrameBuf) - pub base: *mut crate::void, // Pointer to framebuffer - pub pitch: u32, // pitch pixels - pub pixelformat: u32, // pixel format (one of ::SceDisplayPixelFormat) - pub width: u32, // framebuffer width - pub height: u32, // framebuffer height + /// sizeof([SceDisplayFrameBuf]) + pub size: SceSize, + /// Pointer to framebuffer + pub base: *mut crate::void, + /// Pitch pixels + pub pitch: u32, + /// Pixel format (one of [SceDisplayPixelFormat]) + pub pixelformat: u32, + /// Framebuffer width + pub width: u32, + /// Framebuffer height + pub height: u32, } -#[cfg_attr( - not(feature = "dox"), - link(kind = "static", name = "SceDisplay_stub") -)] +#[cfg_attr(not(feature = "dox"), link(kind = "static", name = "SceDisplay_stub"))] extern "C" { + /// Set/Update framebuffer parameters + /// + /// ### Parameters + /// * `pParam` (out) - Pointer to a [SceDisplayFrameBuf] structure. + /// * `sync` - One of [SceDisplaySetBufSync]. + /// + /// Returns 0 on success, < 0 on error. + /// + /// > Note: If NULL is provided as pParam pointer, output is blacked out. pub fn sceDisplaySetFrameBuf( pParam: *const SceDisplayFrameBuf, sync: SceDisplaySetBufSync, ) -> i32; + + /// Get current framebuffer parameters + /// + /// ### Parameters + /// * `pParam` (out) - Pointer to a [SceDisplayFrameBuf] structure which + /// will receive framebuffer parameters. + /// * `sync` - One of [SceDisplaySetBufSync]. + /// + /// Returns 0 on success, < 0 on error. pub fn sceDisplayGetFrameBuf( pParam: *mut SceDisplayFrameBuf, sync: SceDisplaySetBufSync, ) -> i32; + + /// Primary display index pub fn sceDisplayGetPrimaryHead() -> i32; + + /// Get current number of fps for the current screen mode + /// + /// ### Parameters + /// * `pFps` (out) - Pointer to a float variable to store current number of + /// fps. + /// + /// Returns 0 on success, < 0 on error. + /// + /// > Note: This function returns a theoretical value, this might not be + /// the exact frame rate. pub fn sceDisplayGetRefreshRate(pFps: *mut f32) -> i32; + + /// Get maximum framebuffer resolution + /// + /// ### Parameters + /// * `width` (out) - Maximum width. + /// * `height` (out) - Maximum height. + /// + /// Returns 0 on success, < 0 on error. pub fn sceDisplayGetMaximumFrameBufResolution(width: *mut i32, height: *mut i32) -> i32; + + /// Number of vertical blank pulses up to now pub fn sceDisplayGetVcount() -> i32; + + /// Number of vertical blank pulses up to now for a display + /// + /// ### Parameters + /// * `display` - Display index. pub fn sceDisplayGetVcountInternal(display: i32) -> i32; + + /// Wait for vertical blank start pub fn sceDisplayWaitVblankStart() -> i32; + + /// Wait for vertical blank start with callback pub fn sceDisplayWaitVblankStartCB() -> i32; + + /// Wait for vertical blank start after specified number of vertical + /// periods + /// + /// ### Parameters + /// * `vcount` - Number of vertical periods before waiting for vertical + /// blank start. pub fn sceDisplayWaitVblankStartMulti(vcount: u32) -> i32; + + /// Wait for vertical blank start with callback after specified number of + /// vertical periods + /// + /// ### Parameters + /// * `vcount` - Number of vertical periods before waiting for vertical + /// blank start. pub fn sceDisplayWaitVblankStartMultiCB(vcount: u32) -> i32; + + /// Wait for vertical blank start since last update of framebuffer pub fn sceDisplayWaitSetFrameBuf() -> i32; + + /// Wait for vertical blank start with callback since last update of + /// framebuffer pub fn sceDisplayWaitSetFrameBufCB() -> i32; + + /// Wait for vertical blank start after specified number of vertical + /// periods since last update of framebuffer + /// + /// ### Parameters + /// * `vcount` - Number of vertical periods before waiting for vertical + /// blank start. pub fn sceDisplayWaitSetFrameBufMulti(vcount: u32) -> i32; + + /// Wait for vertical blank start with callback after specified number of + /// vertical periods since last update of framebuffer + /// + /// ### Parameters + /// * `vcount` - Number of vertical periods before waiting for vertical + /// blank start. pub fn sceDisplayWaitSetFrameBufMultiCB(vcount: u32) -> i32; + + /// Register callback to be used at each vertical blank start + /// + /// ### Parameters + /// * `uid` - Callback UID. pub fn sceDisplayRegisterVblankStartCallback(uid: SceUID) -> i32; + + /// Unregister callback used at each vertical blank start + /// + /// ### Parameters + /// * `uid` - Callback UID. pub fn sceDisplayUnregisterVblankStartCallback(uid: SceUID) -> i32; + } diff --git a/src/kernel/clib.rs b/src/kernel/clib.rs index a3366f9..2ec8895 100644 --- a/src/kernel/clib.rs +++ b/src/kernel/clib.rs @@ -21,6 +21,14 @@ extern "C" { pub fn sceClibVsnprintf(s: *mut u8, size: SceSize, format: *const u8, ap: va_list) -> i32; pub fn sceClibMemset(s: *mut crate::void, c: i32, n: SceSize) -> *mut crate::void; - pub fn sceClibMemcpy(dest: *mut crate::void, src: *const crate::void, n: SceSize) -> *mut crate::void; - pub fn sceClibMemmove(dest: *mut crate::void, src: *const crate::void, n: SceSize) -> *mut crate::void; + pub fn sceClibMemcpy( + dest: *mut crate::void, + src: *const crate::void, + n: SceSize, + ) -> *mut crate::void; + pub fn sceClibMemmove( + dest: *mut crate::void, + src: *const crate::void, + n: SceSize, + ) -> *mut crate::void; } diff --git a/src/kernel/rng.rs b/src/kernel/rng.rs index 7f8e049..5ca124b 100644 --- a/src/kernel/rng.rs +++ b/src/kernel/rng.rs @@ -1,7 +1,15 @@ +use crate::types::SceSize; + #[cfg_attr( not(feature = "dox"), link(kind = "static", name = "SceLibKernel_stub") )] extern "C" { - pub fn sceKernelGetRandomNumber(output: *mut crate::void, size: u32); + /// Fills the output buffer with random data. + /// + /// * `output` (out) - Output buffer + /// * `size` - Size of the output buffer, 64 bytes maximum + /// + /// Returns 0 on success, < 0 on error. + pub fn sceKernelGetRandomNumber(output: *mut crate::void, size: SceSize); } diff --git a/src/kernel/threadmgr.rs b/src/kernel/threadmgr.rs index b5eeb13..0bacf87 100644 --- a/src/kernel/threadmgr.rs +++ b/src/kernel/threadmgr.rs @@ -1,73 +1,77 @@ -use crate::types::SceSize; -use crate::types::SceUID; -use crate::types::SceUInt; -use crate::types::SceUInt32; -use crate::types::SceUInt64; +use crate::types::{SceInt32, SceSize, SceUID, SceUInt, SceUInt32, SceUInt64}; +/// 64-bit system clock type type SceKernelSysClock = SceUInt64; -// Mutexes - -#[repr(C)] -pub struct SceKernelMutexOptParam { - pub size: SceSize, - pub ceilingPriority: i32, -} - -#[repr(C)] -pub struct SceKernelMutexInfo { - pub size: SceSize, - pub mutexId: SceUID, - pub name: [u8; 32], - pub attr: SceUInt, - pub initCount: i32, - pub currentCount: i32, - pub currentOwnerId: SceUID, - pub numWaitThreads: i32, -} - -#[repr(i32)] -pub enum SceKernelMutexAttribute { - SCE_KERNEL_MUTEX_ATTR_RECURSIVE = 0x02, -} - // Threads type SceKernelThreadEntry = extern "C" fn(SceSize, *mut crate::void) -> i32; +/// Additional options used when creating threads. #[repr(C)] pub struct SceKernelThreadOptParam { + /// Size of the [SceKernelThreadOptParam] structure. pub size: SceSize, + /// Attributes pub attr: SceUInt32, } +/// Structure to hold the status information for a thread +/// +/// See [sceKernelGetThreadInfo] #[repr(C)] pub struct SceKernelThreadInfo { + /// Size of the structure pub size: SceSize, + /// The UID of the process where the thread belongs pub processId: SceUID, + /// Nul terminated name of the thread pub name: [u8; 32], - pub attr: SceUInt, - pub status: i32, + /// Thread attributes + pub attr: SceUInt32, + /// Thread status + pub status: SceUInt32, + /// Thread entry point pub entry: SceKernelThreadEntry, + /// Thread stack pointer pub stack: *mut crate::void, - pub stackSize: i32, - pub initPriority: i32, - pub currentPriority: i32, - pub initCpuAffinityMask: i32, - pub currentCpuAffinityMask: i32, - pub currentCpuId: i32, - pub lastExecutedCpuId: i32, - pub waitType: i32, + /// Thread stack size + pub stackSize: SceInt32, + /// Initial priority + pub initPriority: SceInt32, + /// Current priority + pub currentPriority: SceInt32, + /// Initial CPU affinity mask + pub initCpuAffinityMask: SceInt32, + /// Current CPU affinity mask + pub currentCpuAffinityMask: SceInt32, + /// Current CPU ID + pub currentCpuId: SceInt32, + /// Last executed CPU ID + pub lastExecutedCpuId: SceInt32, + /// Wait type + pub waitType: SceUInt32, + /// Wait id pub waitId: SceUID, - pub exitStatus: i32, + /// Exit status of the thread + pub exitStatus: SceInt32, + /// Number of clock cycles run pub runClocks: SceKernelSysClock, - pub intrPreemptCount: SceUInt, - pub threadPreemptCount: SceUInt, - pub threadReleaseCount: SceUInt, - pub fNotifyCallback: SceUID, - pub reserved: i32, + /// Interrupt preemption count + pub intrPreemptCount: SceUInt32, + /// Thread preemption count + pub threadPreemptCount: SceUInt32, + /// Thread release count + pub threadReleaseCount: SceUInt32, + /// Number of CPUs to which the thread is moved + pub changeCpuCount: SceInt32, + /// Function notify callback UID + pub fNotifyCallback: SceInt32, + /// Reserved + pub reserved: SceInt32, } +/// "Nested" Struct for [SceKernelThreadRunStatus] #[repr(C)] pub struct SceKernelThreadCpuInfo { pub processId: SceUID, @@ -75,39 +79,54 @@ pub struct SceKernelThreadCpuInfo { pub priority: i32, } +/// Statistics about a running thread. +/// +/// See [sceKernelGetThreadRunStatus] #[repr(C)] pub struct SceKernelThreadRunStatus { pub size: SceSize, + /// See [SceKernelThreadCpuInfo] pub cpuInfo: [SceKernelThreadCpuInfo; 4], } #[repr(i32)] pub enum SceThreadStatus { + /// SCE Thread Running SCE_THREAD_RUNNING = 1, + /// SCE Thread Ready SCE_THREAD_READY = 2, - SCE_THREAD_WAITING = 4, - SCE_THREAD_SUSPEND = 8, - SCE_THREAD_STOPPED = 16, - SCE_THREAD_KILLED = 32, + /// SCE Thread Standby + SCE_THREAD_STANDBY = 4, + /// Sce Thread Wating + SCE_THREAD_WAITING = 8, + // SCE_THREAD_SUSPEND : Defined in [SceThreadStatus] Implementation + /// SCE Thread Dormant + SCE_THREAD_DORMANT = 16, + // SCE_THREAD_STOPPED : Defined in [SceThreadStatus] Implementation + /// SCE Thread Deleted - Thread manager has killed the thread (stack overflow) + SCE_THREAD_DELETED = 32, + // SCE_THREAD_KILLED = 32, + /// SCE Thread Dead + SCE_THREAD_DEAD = 64, + /// SCE Thread Stagnant + SCE_THREAD_STAGNANT = 128, + /// SCE Thread Suspended + SCE_THREAD_SUSPENDED = 256, } -// Semaphores - -#[repr(C)] -pub struct SceKernelSemaOptParam { - size: SceSize, +/// Implementation for [SceThreadStatus] : Fixing missing enum variant +impl SceThreadStatus { + /// SCE Thread Suspended (Compatibility) + pub const SCE_THREAD_SUSPEND: SceThreadStatus = SceThreadStatus::SCE_THREAD_WAITING; + /// SCE Thread Stopped (Compatibility) + pub const SCE_THREAD_STOPPED: SceThreadStatus = SceThreadStatus::SCE_THREAD_DORMANT; + /// SCE Thread Killed (Compatibility) + pub const SCE_THREAD_KILLED: SceThreadStatus = SceThreadStatus::SCE_THREAD_DELETED; } -#[repr(C)] -pub struct SceKernelSemaInfo { - pub size: SceSize, - pub semaId: SceUID, - pub name: [u8; 32], - pub attr: SceUInt, - pub initCount: i32, - pub currentCount: i32, - pub maxCount: i32, - pub numWaitThreads: i32, +#[repr(i32)] +pub enum SceKernelMutexAttribute { + SCE_KERNEL_MUTEX_ATTR_RECURSIVE = 0x02, } #[cfg_attr( @@ -115,27 +134,26 @@ pub struct SceKernelSemaInfo { link(kind = "static", name = "SceLibKernel_stub") )] extern "C" { - - // Mutexes - - pub fn sceKernelCreateMutex( - name: *const u8, - attr: SceUInt, - initCount: i32, - option: *mut SceKernelMutexOptParam, - ) -> SceUID; - pub fn sceKernelOpenMutex(name: *const u8) -> i32; - pub fn sceKernelCloseMutex(mutexid: SceUID) -> i32; - pub fn sceKernelDeleteMutex(mutexid: SceUID) -> i32; - pub fn sceKernelLockMutex(mutexid: SceUID, lockCount: i32, timeout: *mut u32) -> i32; - pub fn sceKernelLockMutexCB(mutexid: SceUID, lockCount: i32, timeout: *mut u32) -> i32; - pub fn sceKernelTryLockMutex(mutexid: SceUID, lockCount: i32) -> i32; - pub fn sceKernelUnlockMutex(mutexid: SceUID, unlockCount: i32) -> i32; - pub fn sceKernelCancelMutex(mutexid: SceUID, lockCount: i32, numWaitThreads: *mut i32) -> i32; - pub fn sceKernelGetMutexInfo(mutexid: SceUID, info: *mut SceKernelMutexInfo) -> i32; - - // Threads - + //! Threads function + /// Create a thread + /// + /// ### Parameters + /// * `name` - An arbitrary thread name. + /// * `entry` - The thread function to run when started. + /// * `initPriority` - The initial priority of the thread. Less if higher + /// priority. + /// * `stackSize` - The size of the initial stack. + /// * `attr` - The thread attributes, zero or more of ::SceThreadAttributes (???). + /// * `cpuAffinityMask` - The CPU affinity mask. + /// * `option` - Additional options specified by [SceKernelThreadOptParam]. + /// + /// Returns UID of the created thread, or an error code. + /// + /// ### Example + /// ```rust + /// let thid: SceUID; + /// thid = sceKernelCreateThread("my_thread", threadFunc, 0x10000100, 0x10000, 0, 0, 0x0); + /// ``` pub fn sceKernelCreateThread( name: *const u8, entry: SceKernelThreadEntry, @@ -145,24 +163,221 @@ extern "C" { cpuAffinityMask: i32, option: *const SceKernelThreadOptParam, ) -> SceUID; + + /// Delete a thread + /// + /// ### Parameters + /// * `thid` - UID of the thread to be deleted. + /// + /// Returns < 0 on error. pub fn sceKernelDeleteThread(thid: SceUID) -> i32; + + /// Start a created thread + /// + /// ### Parameters + /// * `thid` - Thread id from [sceKernelCreateThread]. + /// * `arglen` - Length of the data pointed to by argp, in bytes. + /// * `argp` - Pointer to the arguments. pub fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: *mut crate::void) -> i32; + + /// Exit a thread + /// + /// ### Parameters + /// * `status` - Exit status. + pub fn sceKernelExitThread(status: i32) -> i32; + + /// Exit a thread and delete itself + /// + /// ### Parameters + /// * `status` - Exit status + pub fn sceKernelExitDeleteThread(status: i32) -> i32; + + /// Wait until a thread has ended + /// + /// ### Parameters + /// * `thid` - Id of the thread to wait for. + /// * `stat` - Exit status. + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Returns < 0 on error. pub fn sceKernelWaitThreadEnd(thid: SceUID, stat: *mut i32, timeout: *mut SceUInt) -> i32; + + /// Wait until a thread has ended and handle callbacks if necessary + /// + /// ### Parameters + /// * `thid` - Id of the thread to wait for. + /// * `stat` - Exit status. + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Returns < 0 on error. pub fn sceKernelWaitThreadEndCB(thid: SceUID, stat: *mut i32, timeout: *mut SceUInt) -> i32; + + /// Delay the current thread by a specified number of microseconds + /// + /// ### Parameters + /// * `delay` - Delay in microseconds. + /// + /// ### Example + /// ```rust + /// sceKernelDelayThread(1000000); // Delay for a second + /// ``` pub fn sceKernelDelayThread(delay: SceUInt) -> i32; + + /// Delay the current thread by a specified number of microseconds and + /// handle any callbacks + /// + /// ### Parameters + /// * `delay` - Delay in microseconds. + /// + /// ### Example + /// ```rust + /// sceKernelDelayThread(1000000); // Delay for a second + /// ``` pub fn sceKernelDelayThreadCB(delay: SceUInt) -> i32; + + /// Modify the attributes of the current thread + /// + /// * `unknown` - Set to 0. + /// * `attr` - The thread attributes to modify. One of + /// ::SceThreadAttributes (???). + /// + /// Returns < 0 on error. pub fn sceKernelChangeCurrentThreadAttr(unknown: i32, attr: SceUInt) -> i32; + + /// Change the threads current priority. + /// + /// ### Parameters + /// * `thid` - The ID of the thread (from [sceKernelCreateThread] or + /// [sceKernelGetThreadId]). + /// * `priority` - The new priority (the lower the number the higher the + /// priority). + /// + /// Returns 0 if successful, otherwise the error code. + /// + /// ### Example + /// ```rust + /// let thid: SceUID = sceKernelGetThreadId(); + /// sceKernelChangeThreadPriority(thid, 16); // Change priority of current thread to 16 + /// ``` pub fn sceKernelChangeThreadPriority(thid: SceUID, priority: i32) -> i32; + + /// Get the current thread Id + /// + /// Returns the thread id of the calling thread. pub fn sceKernelGetThreadId() -> SceUID; + + /// Get the current priority of the thread you are in + /// + /// Returns The current thread priority. pub fn sceKernelGetThreadCurrentPriority() -> i32; - pub fn sceKernelGetThreadExitStatus(thid: SceUID) -> i32; + + /// Get the exit status of a thread + /// + /// # Parameters + /// * `thid` - The UID of the thread to check. + /// * `status` (out) - Status out pointer. + /// + /// Returns the exit status. + pub fn sceKernelGetThreadExitStatus(thid: SceUID, status: *mut i32) -> i32; + + /// Check the thread stack? + /// + /// Returns unknown. pub fn sceKernelCheckThreadStack() -> i32; + + /// Get the free stack size for a thread + /// + /// # Parmameters + /// * `thid` - The thread ID. Seem to take current thread if set to 0. + /// + /// Returns the free size. pub fn sceKernelGetThreadStackFreeSize(thid: SceUID) -> i32; + + /// Get the status information for the specified thread + /// + /// # Parameters + /// * `thid` - Id of the thread to get status. + /// * `info` - Pointer to the info structure to receive the data. + /// > Note: The structures size field should be set to + /// sizeof(SceKernelThreadInfo) before calling this function. + /// + /// Returns 0 if successful, otherwise the error code. + /// + /// ### Example + /// ```no_run rust + /// let status: SceKernelThreadInfo; + /// status.size = sizeof(SceKernelThreadInfo); + /// if(sceKernelGetThreadInfo(thid, &status) == 0) { + /// Do something... + /// } + /// ``` pub fn sceKernelGetThreadInfo(thid: SceUID, info: *mut SceKernelThreadInfo) -> i32; + + /// Retrive the runtime status of a thread + /// + /// # Parameters + /// * `thid` - UID of the thread to retrieve status. + /// * `status` - Pointer to a [SceKernelThreadRunStatus] struct to receive + /// the runtime status. + /// + /// @return 0 if successful, otherwise the error code. pub fn sceKernelGetThreadRunStatus(thid: SceUID, status: *mut SceKernelThreadRunStatus) -> i32; +} + +// Semaphores - // Semaphores +/// Additional options used when creating semaphores +#[repr(C)] +pub struct SceKernelSemaOptParam { + /// Size of the [SceKernelSemaOptParam] structure + size: SceSize, +} +/// Current state of a semaphore +/// +/// See [sceKernelGetSemaInfo]. +#[repr(C)] +pub struct SceKernelSemaInfo { + /// Size of the [SceKernelSemaInfo] structure + pub size: SceSize, + /// The UID of the semaphore + pub semaId: SceUID, + /// NULL-terminated name of the semaphore + pub name: [u8; 32], + /// Attributes + pub attr: SceUInt, + /// The initial count the semaphore was created with + pub initCount: i32, + /// The current count + pub currentCount: i32, + /// The maximum count + pub maxCount: i32, + /// The number of threads waiting on the semaphore + pub numWaitThreads: i32, +} + +#[cfg_attr( + not(feature = "dox"), + link(kind = "static", name = "SceLibKernel_stub") +)] +extern "C" { + //! Semaphores + /// Creates a new semaphore + /// + /// ### Parameters + /// * `name` - Specifies the name of the sema. + /// * `attr` - Sema attribute flags (normally set to 0). + /// * `initVal` - Sema initial value. + /// * `maxVal` - Sema maximum value. + /// * `option` - Sema options (normally set to 0). + /// + /// Returns a semaphore id. + /// + /// ### Example + /// ``` + /// let semaid: SceUID; + /// semaid = sceKernelCreateSema("MySema", 0, 1, 1, 0x0); + /// ``` pub fn sceKernelCreateSema( name: *const u8, attr: SceUInt, @@ -170,12 +385,378 @@ extern "C" { maxVal: i32, option: *mut SceKernelSemaOptParam, ) -> SceUID; + + /// Destroy a semaphore + /// + /// ### Parameters + /// * `semaid` - The semaid returned from a previous create call. + /// + /// Returns the value 0 if it's successful, otherwise -1. pub fn sceKernelDeleteSema(semaid: SceUID) -> i32; + + /// Send a signal to a semaphore + /// + /// ### Parameters + /// * `semaid` - The sema id returned from ::sceKernelCreateSema. + /// * `signal` - The amount to signal the sema (i.e. if 2 then increment + /// the sema by 2). + /// + /// Returns < 0 On error. + /// + /// ### Example + /// ```rust + /// sceKernelSignalSema(semaid, 1); // Signal the sema + /// ``` pub fn sceKernelSignalSema(semaid: SceUID, signal: i32) -> i32; + + /// Lock a semaphore + /// + /// ### Parameters + /// * `semaid` - The sema id returned from ::sceKernelCreateSema. + /// * `signal` - The value to wait for (i.e. if 1 then wait till reaches a + /// signal state of 1). + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Returns < 0 on error. + /// + /// ### Example + /// ```rust + /// sceKernelWaitSema(semaid, 1, 0); + /// ``` pub fn sceKernelWaitSema(semaid: SceUID, signal: i32, timeout: *mut SceUInt) -> i32; + + /// Lock a semaphore and handle callbacks if necessary + /// + /// ### Parameters + /// * `semaid` - The sema id returned from ::sceKernelCreateSema + /// * `signal` - The value to wait for (i.e. if 1 then wait till reaches a + /// signal state of 1). + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Returns < 0 on error. + /// + /// ### Example + /// ```rust + /// sceKernelWaitSemaCB(semaid, 1, 0); + /// ``` pub fn sceKernelWaitSemaCB(semaid: SceUID, signal: i32, timeout: *mut SceUInt) -> i32; + + /// Poll a semaphore + /// + /// * `semaid` - UID of the semaphore to poll. + /// * `signal` - The value to test for. + /// + /// Returns < 0 on error. pub fn sceKernelPollSema(semaid: SceUID, signal: i32) -> i32; + + /// Cancels a semaphore + /// + /// ### Parameters + /// * `semaid` - The sema id returned from ::sceKernelCreateSema. + /// * `setCount` - The new lock count of the semaphore. + /// * `numWaitThreads` - Number of threads waiting for the semaphore. + /// + /// Returns < 0 on error. pub fn sceKernelCancelSema(semaid: SceUID, setCount: i32, numWaitThreads: *mut i32) -> i32; + + /// Retrieve information about a semaphore + /// + /// ### Parameters + /// * `semaid` - UID of the semaphore to retrieve info for. + /// * `info` - Pointer to a ::SceKernelSemaInfo struct to receive the info. + /// + /// Returns < 0 on error. pub fn sceKernelGetSemaInfo(semaid: SceUID, info: *mut SceKernelSemaInfo) -> i32; +} + +// Mutexes + +/// Additional options used when creating mutexes +#[repr(C)] +pub struct SceKernelMutexOptParam { + /// Size of the [SceKernelMutexOptParam] structure + pub size: SceSize, + pub ceilingPriority: i32, +} + +/// Current state of a mutex +/// +/// See [sceKernelGetMutexInfo]. +#[repr(C)] +pub struct SceKernelMutexInfo { + /// Size of the ::SceKernelMutexInfo structure + pub size: SceSize, + /// The UID of the mutex + pub mutexId: SceUID, + /// NULL-terminated name of the mutex + pub name: [u8; 32], + /// Attributes + pub attr: SceUInt, + /// The initial count the mutex was created with + pub initCount: i32, + /// The current count + pub currentCount: i32, + /// The UID of the current owner of the mutex + pub currentOwnerId: SceUID, + /// The number of threads waiting on the mutex + pub numWaitThreads: i32, +} + +#[cfg_attr( + not(feature = "dox"), + link(kind = "static", name = "SceLibKernel_stub") +)] +extern "C" { + //! Mutexes + + /// Creates a new mutex + /// + /// ### Parameters + /// * `name` - Specifies the name of the mutex. + /// * `attr` - Mutex attribute flags (normally set to 0). + /// * `initCount` - Mutex initial value. + /// * `option` - Mutex options (normally set to 0). + /// + /// Returns a mutex id. + /// + /// ### Example + /// ```rust + /// mutexid: SceUID; + /// mutexid = sceKernelCreateMutex("MyMutex", 0, 1, 0x0); + /// ``` + pub fn sceKernelCreateMutex( + name: *const u8, + attr: SceUInt, + initCount: i32, + option: *mut SceKernelMutexOptParam, + ) -> SceUID; + + /// Destroy a mutex + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// + /// Returns the value 0 if it's successful, otherwise -1. + pub fn sceKernelDeleteMutex(mutexid: SceUID) -> i32; + + /// Open a mutex + /// + /// ### Parameters + /// * `name` - The name of the mutex to open. + /// + /// Returns the value 0 if it's successful, otherwise -1. + pub fn sceKernelOpenMutex(name: *const u8) -> i32; + + /// Close a mutex + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// + /// Returns the value 0 if it's successful, otherwise -1. + pub fn sceKernelCloseMutex(mutexid: SceUID) -> i32; + + /// Lock a mutex + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// * `lockCount` - The value to increment to the lock count of the mutex. + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Returns < 0 on error. + pub fn sceKernelLockMutex(mutexid: SceUID, lockCount: i32, timeout: *mut u32) -> i32; + + /// Lock a mutex and handle callbacks if necessary. + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// * `lockCount` - The value to increment to the lock count of the mutex. + /// * `timeout` - Timeout in microseconds (assumed). + /// + /// Retuns < 0 on error. + pub fn sceKernelLockMutexCB(mutexid: SceUID, lockCount: i32, timeout: *mut u32) -> i32; + + /// Try to lock a mutex (non-blocking) + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// * `lockCount` - The value to increment to the lock count of the mutex. + /// + /// Returns < 0 on error. + pub fn sceKernelTryLockMutex(mutexid: SceUID, lockCount: i32) -> i32; + + /// Try to unlock a mutex (non-blocking) + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// * `unlockCount` - The value to decrement to the lock count of the mutex. + /// + /// Returns < 0 on error. + pub fn sceKernelUnlockMutex(mutexid: SceUID, unlockCount: i32) -> i32; + + /// Cancels a mutex + /// + /// ### Parameters + /// * `mutexid` - The mutex id returned from [sceKernelCreateMutex]. + /// * `newCount` - The new lock count of the mutex. + /// * `numWaitThreads` - Number of threads waiting for the mutex. + /// + /// Returns < 0 on error. + pub fn sceKernelCancelMutex(mutexid: SceUID, lockCount: i32, numWaitThreads: *mut i32) -> i32; + + /// Retrieve information about a mutex. + /// + /// ### Parameters + /// * `mutexid` - UID of the mutex to retrieve info for. + /// * `info` - Pointer to a [SceKernelMutexInfo] struct to receive the info. + /// + /// Returns < 0 on error. + pub fn sceKernelGetMutexInfo(mutexid: SceUID, info: *mut SceKernelMutexInfo) -> i32; +} + +// Event Flags + +/// Structure to hold event flag information +#[repr(C)] +pub struct SceKernelEventFlagInfo { + size: SceSize, + /// Needs confirmation + evfId: SceUID, + name: [u8; 32], + attr: SceUInt, + initPattern: SceUInt, + currentPattern: SceUInt, + numWaitThreads: i32, +} + +#[repr(C)] +pub struct SceKernelEventFlagOptParam { + size: SceSize, +} + +#[repr(C)] +pub enum SceEventFlagAttributes { + /// Waiting threads queued on a FIFO basis + SCE_EVENT_THREAD_FIFO = 0, + /// Waiting threads queued on priority basis + SCE_EVENT_THREAD_PRIO = 0x00002000, + /// Event flag can only be waited upon by one thread + /// SCE_EVENT_WAITSINGLE : Defined in [SceEventFlagAttributes] Implementation. + /// Event flag can be waited upon by multiple threads + SCE_EVENT_WAITMULTIPLE = 0x00001000, + /// Event flag can be accessed by sceKernelOpenEventFlag / sceKernelCloseEventFlag + SCE_EVENT_OPENABLE = 0x00000080, +} + +impl SceEventFlagAttributes { + pub const SCE_EVENT_WAITSINGLE: SceEventFlagAttributes = + SceEventFlagAttributes::SCE_EVENT_THREAD_FIFO; +} + +#[repr(C)] +pub enum SceEventFlagWaitTypes { + /// Wait for all bits in the pattern to be set + SCE_EVENT_WAITAND = 0, + /// Wait for one or more bits in the pattern to be set + SCE_EVENT_WAITOR = 1, + /// Clear all the bits when it matches + SCE_EVENT_WAITCLEAR = 2, + /// Clear the wait pattern when it matches + SCE_EVENT_WAITCLEAR_PAT = 4, +} + +#[cfg_attr( + not(feature = "dox"), + link(kind = "static", name = "SceLibKernel_stub") +)] +extern "C" { + //! Event Flags + + /// Create an event flag + /// + /// ### Parameters + /// * `name` - The name of the event flag. + /// * `attr` - Attributes from ::SceEventFlagAttributes. + /// * `bits` - Initial bit pattern. + /// * `opt` - Options, set to NULL. + /// + /// Returns < 0 on error. >= 0 event flag id. + /// + /// ### Example + /// ```rust + /// evid: SceUID; + /// evid = sceKernelCreateEventFlag("wait_event", 0, 0, 0x0); + /// ``` + pub fn sceKernelCreateEventFlag( + name: *const u8, + attr: i32, + bits: i32, + opt: *mut SceKernelEventFlagOptParam, + ) -> SceUID; + + /// Set an event flag bit pattern + /// + /// ### Parameters + /// * `evid` - The event id returned by [sceKernelCreateEventFlag]. + /// * `bits` - The bit pattern to set. + /// + /// Returns < 0 on error. + pub fn sceKernelSetEventFlag(evid: SceUID, bits: u32) -> i32; + + /// Clear a event flag bit pattern + /// + /// ### Parameters + /// * `evid` - The event id returned by [sceKernelCreateEventFlag]. + /// * `bits` - The bits to clean. + /// + /// Returns < 0 on error. + pub fn sceKernelClearEventFlag(evid: SceUID, bits: u32) -> i32; + + /// Poll an event flag for a given bit pattern + /// + /// ### Parameters + /// * `evid` - The event id returned by [sceKernelCreateEventFlag]. + /// * `bits` - The bit pattern to poll for. + /// * `wait` - Wait type, one or more of [SceEventFlagWaitTypes] or'ed + /// together. + /// * `outBits` - The bit pattern that was matched. + /// + /// Returns < 0 on error. + pub fn sceKernelPollEventFlag(evid: SceUID, bits: u32, wait: u32, outBits: *mut u32) -> i32; + + /// Wait for an event flag for a given bit pattern + /// + /// ### Parameters + /// * `evid` - The event id returned by [sceKernelCreateEventFlag]. + /// * `bits` - The bit pattern to poll for. + /// * `wait` - Wait type, one or more of [SceEventFlagWaitTypes] or'ed + /// together. + /// * `outBits` - The bit pattern that was matched. + /// * `timeout` - Timeout in microseconds. + /// Returns < 0 on error + pub fn sceKernelWaitEventFlag( + evid: SceUID, + bits: u32, + wait: u32, + outBits: *mut u32, + timeout: *mut SceUInt, + ) -> i32; + /// Wait for an event flag for a given bit pattern with callback + /// + /// ### Parameters + /// * `evid` - The event id returned by [sceKernelCreateEventFlag]. + /// * `bits` - The bit pattern to poll for. + /// * `wait` - Wait type, one or more of [SceEventFlagWaitTypes] or'ed + /// together. + /// * `outBits` - The bit pattern that was matched. + /// * `timeout` - Timeout in microseconds. + /// + /// Returns < 0 on error + pub fn sceKernelWaitEventFlagCB( + evid: SceUID, + bits: u32, + wait: u32, + outBits: *mut u32, + timeout: *mut SceUInt, + ) -> i32; } diff --git a/src/system_param.rs b/src/system_param.rs index fa02cd5..20d6fea 100644 --- a/src/system_param.rs +++ b/src/system_param.rs @@ -1,3 +1,6 @@ +//! SCE System Parameters + +/// System Parameter ID #[repr(u32)] pub enum SceSystemParamId { /// Language settings @@ -18,6 +21,7 @@ pub enum SceSystemParamId { SCE_SYSTEM_PARAM_ID_MAX_VALUE = 0xFFFFFFFF, } +/// Language Settings #[repr(u32)] pub enum SceSystemParamLang { /// Japanese @@ -64,6 +68,7 @@ pub enum SceSystemParamLang { SCE_SYSTEM_PARAM_LANG_MAX_VALUE = 0xFFFFFFFF, } +/// Assignment of enter button #[repr(u32)] pub enum SceSystemParamEnterButtonAssign { SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE, @@ -71,17 +76,26 @@ pub enum SceSystemParamEnterButtonAssign { SCE_SYSTEM_PARAM_ENTER_BUTTON_MAX_VALUE = 0xFFFFFFFF, } +// Username +/// Max size of username pub const SCE_SYSTEM_PARAM_USERNAME_MAXSIZE: usize = 17; +/// Date display format #[repr(C)] pub enum SceSystemParamDateFormat { + /// Year/Month/Day SCE_SYSTEM_PARAM_DATE_FORMAT_YYYYMMDD, + /// Day/Month/Year SCE_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY, + /// Month/Day/Year SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY, } +/// Time display format #[repr(C)] pub enum SceSystemParamTimeFormat { + /// 12-hour clock SCE_SYSTEM_PARAM_TIME_FORMAT_12HR, + /// 24-hour clock SCE_SYSTEM_PARAM_TIME_FORMAT_24HR, } diff --git a/src/types.rs b/src/types.rs index 5510fdf..24d7344 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,3 +1,5 @@ +//! SCE Types + pub type SceChar8 = i8; pub type SceUChar8 = u8; @@ -7,6 +9,9 @@ pub type SceUInt8 = u8; pub type SceShort16 = i16; pub type SceUShort16 = u16; +pub type SceInt16 = i16; +pub type SceUInt16 = u16; + pub type SceInt32 = i32; pub type SceUInt32 = u32; @@ -90,6 +95,7 @@ pub struct SceIVector4 { w: SceInt, } +/* #[derive(Copy, Clone, Debug)] #[repr(C)] pub struct SceUVector4 { @@ -98,6 +104,8 @@ pub struct SceUVector4 { z: SceUInt, w: SceUInt, } +*/ +// Missing from types.h ! #[derive(Copy, Clone, Debug)] #[repr(C)] @@ -147,6 +155,7 @@ pub struct SceIMatrix4 { w: SceIVector4, } +/* #[derive(Copy, Clone, Debug)] #[repr(C)] pub struct SceUMatrix4 { @@ -155,6 +164,8 @@ pub struct SceUMatrix4 { z: SceUVector4, w: SceUVector4, } +*/ +// Missing from types.h ! #[derive(Copy, Clone, Debug)] #[repr(C)] @@ -192,6 +203,7 @@ pub struct SceFPlane { d: SceFloat, } +/* #[derive(Copy, Clone)] #[repr(C)] pub union SceUnion32 { @@ -204,7 +216,10 @@ pub union SceUnion32 { f: f32, p: *mut crate::void, } +*/ +// Missing from types.h ! +/* #[derive(Copy, Clone)] #[repr(C)] pub union SceUnion64 { @@ -220,7 +235,10 @@ pub union SceUnion64 { fv: SceFVector2, iv: SceIVector2, } +*/ +// Missing from types.h ! +/* #[derive(Copy, Clone)] #[repr(C)] pub union SceUnion128 { @@ -239,6 +257,8 @@ pub union SceUnion128 { fc: SceFColor, iv: SceIVector4, } +*/ +// Missing from types.h ! #[derive(Copy, Clone, Debug)] #[repr(C)] @@ -252,11 +272,20 @@ pub struct SceDateTime { microsecond: u32, } +/// Mode for I/O funuctions pub type SceMode = i32; +/// Offset type pub type SceOff = SceInt64; +/// UIDs are used to describe many different kernel objects pub type SceUID = i32; +/// Process ID pub type ScePID = i32; +/// Current running process ID is always 0 +pub const SCE_KERNEL_PROCESS_ID_SELF: usize = 0; +/// Names are used to describe object names pub type SceName = *mut u8; +/// Maximum length for kernel object names +pub const SCE_UID_NAMELEN: usize = 31;