diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index b46b591..7922f20 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -1,6 +1,6 @@ -use ctru::gfx::Screen; use ctru::prelude::*; use ctru::services::cam::{Cam, CamOutputFormat, CamShutterSoundType, CamSize, Camera}; +use ctru::services::gfx::Screen; use ctru::services::gspgpu::FramebufferFormat; use std::time::Duration; diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 74a94eb..3bfeadc 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -16,7 +16,7 @@ fn main() { let gfx = Gfx::init().unwrap(); #[cfg(all(feature = "romfs", romfs_exists))] - let _romfs = ctru::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::init().unwrap(); FileExplorer::init(&apt, &hid, &gfx).run(); } diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index dfdc028..171838b 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -1,5 +1,5 @@ -use ctru::gfx::{Screen, Side, TopScreen3D}; use ctru::prelude::*; +use ctru::services::gfx::{Screen, Side, TopScreen3D}; /// See `graphics-bitmap.rs` for details on how the image is generated. /// diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index b6842f1..5421e9b 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -1,5 +1,5 @@ -use ctru::gfx::Screen as _; use ctru::prelude::*; +use ctru::services::gfx::Screen; /// Ferris image taken from and scaled down to 320x240px. /// To regenerate the data, you will need to install `imagemagick` and run this diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index 45a7add..965cb6d 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -13,7 +13,7 @@ fn main() { // This never fails as `ctru-rs` examples inherit all of the `ctru` features, // but it might if a normal user application wasn't setup correctly if #[cfg(all(feature = "romfs", romfs_exists))] { - let _romfs = ctru::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::init().unwrap(); let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap(); println!("Contents of test-file.txt: \n{f}\n"); diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index cfd15ea..c0a8765 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -3,7 +3,7 @@ use std::default::Default; use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole}; -use crate::gfx::Screen; +use crate::services::gfx::Screen; static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) }; diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 8dd8abf..2db6c22 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -62,31 +62,11 @@ fn panic_hook_setup() { pub mod applets; pub mod console; pub mod error; -pub mod gfx; pub mod linear; pub mod mii; pub mod prelude; pub mod services; -cfg_if::cfg_if! { - if #[cfg(all(feature = "romfs", romfs_exists))] { - pub mod romfs; - } else { - pub mod romfs { - //! The RomFS folder has not been detected and/or the `romfs` feature has not been enabled. - //! - //! Configure the path in Cargo.toml (the default path is "romfs"). Paths are relative to the - //! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of - //! your package. - //! - //! ```toml - //! [package.metadata.cargo-3ds] - //! romfs_dir = "romfs" - //! ``` - } - } -} - #[cfg(test)] mod test_runner; diff --git a/ctru-rs/src/prelude.rs b/ctru-rs/src/prelude.rs index 27196f9..74faa41 100644 --- a/ctru-rs/src/prelude.rs +++ b/ctru-rs/src/prelude.rs @@ -1,3 +1,2 @@ pub use crate::console::Console; -pub use crate::gfx::Gfx; -pub use crate::services::{hid::KeyPad, soc::Soc, Apt, Hid}; +pub use crate::services::{gfx::Gfx, hid::KeyPad, soc::Soc, Apt, Hid}; diff --git a/ctru-rs/src/gfx.rs b/ctru-rs/src/services/gfx.rs similarity index 99% rename from ctru-rs/src/gfx.rs rename to ctru-rs/src/services/gfx.rs index fd439a0..457f94d 100644 --- a/ctru-rs/src/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -57,7 +57,7 @@ pub trait Screen: private::Sealed { /// Gets the framebuffer format fn get_framebuffer_format(&self) -> FramebufferFormat { - unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()).into() } + unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() } /// Change the framebuffer format diff --git a/ctru-rs/src/services/gspgpu.rs b/ctru-rs/src/services/gspgpu.rs index 1357fad..73fb77d 100644 --- a/ctru-rs/src/services/gspgpu.rs +++ b/ctru-rs/src/services/gspgpu.rs @@ -3,29 +3,31 @@ use std::convert::From; #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum Event { - Psc0, - Psc1, - VBlank0, - VBlank1, - PPF, - P3D, - DMA, + Psc0 = ctru_sys::GSPGPU_EVENT_PSC0, + Psc1 = ctru_sys::GSPGPU_EVENT_PSC1, + VBlank0 = ctru_sys::GSPGPU_EVENT_VBlank0, + VBlank1 = ctru_sys::GSPGPU_EVENT_VBlank1, + PPF = ctru_sys::GSPGPU_EVENT_PPF, + P3D = ctru_sys::GSPGPU_EVENT_P3D, + DMA = ctru_sys::GSPGPU_EVENT_DMA, } -/// The different framebuffer formats supported by the 3DS +/// Framebuffer formats supported by the 3DS #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum FramebufferFormat { /// RGBA8. 4 bytes per pixel - Rgba8, + Rgba8 = ctru_sys::GSP_RGBA8_OES, /// BGR8. 3 bytes per pixel - Bgr8, + Bgr8 = ctru_sys::GSP_BGR8_OES, /// RGB565. 2 bytes per pixel - Rgb565, + Rgb565 = ctru_sys::GSP_RGB565_OES, /// RGB5A1. 2 bytes per pixel - Rgb5A1, + Rgb5A1 = ctru_sys::GSP_RGB5_A1_OES, /// RGBA4. 2 bytes per pixel - Rgba4, + Rgba4 = ctru_sys::GSP_RGBA4_OES, } impl FramebufferFormat { diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 5abf93a..6b9e115 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -10,6 +10,7 @@ pub mod apt; pub mod cam; pub mod cfgu; pub mod fs; +pub mod gfx; pub mod gspgpu; pub mod hid; pub mod ndsp; @@ -18,6 +19,25 @@ mod reference; pub mod soc; pub mod sslc; +cfg_if::cfg_if! { + if #[cfg(all(feature = "romfs", romfs_exists))] { + pub mod romfs; + } else { + pub mod romfs { + //! The RomFS folder has not been detected and/or the `romfs` feature has not been enabled. + //! + //! Configure the path in Cargo.toml (the default path is "romfs"). Paths are relative to the + //! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of + //! your package. + //! + //! ```toml + //! [package.metadata.cargo-3ds] + //! romfs_dir = "romfs" + //! ``` + } + } +} + pub use self::apt::Apt; pub use self::hid::Hid; diff --git a/ctru-rs/src/romfs.rs b/ctru-rs/src/services/romfs.rs similarity index 97% rename from ctru-rs/src/romfs.rs rename to ctru-rs/src/services/romfs.rs index e601898..fd022e8 100644 --- a/ctru-rs/src/romfs.rs +++ b/ctru-rs/src/services/romfs.rs @@ -1,3 +1,5 @@ +//! Read-Only Memory FileSystem +//! //! This module only gets compiled if the configured RomFS directory is found and the `romfs` //! feature is enabled. //! diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 8b3f117..00634f6 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -6,10 +6,7 @@ use std::io; use test::{ColorConfig, OutputFormat, TestDescAndFn, TestFn, TestOpts}; -use crate::console::Console; -use crate::gfx::Gfx; -use crate::services::hid::{Hid, KeyPad}; -use crate::services::Apt; +use crate::prelude::*; /// A custom runner to be used with `#[test_runner]`. This simple implementation /// runs all tests in series, "failing" on the first one to panic (really, the