From 5fe972a3a00254bf5aab6e3f5a07a8b18046b330 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 28 Apr 2024 21:17:27 -0600 Subject: [PATCH] gate GBA specific code behind a cargo feature so that it can build (badly) on a host machine. --- .cargo/config.toml | 6 +++--- Cargo.toml | 5 ++++- src/builtin_art/cga_8x8_thick.rs | 15 +++++++-------- src/lib.rs | 8 ++++++++ src/prelude.rs | 11 +++++------ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 9b9b1ce2..9a980fdd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,9 +1,9 @@ [build] -target = "thumbv4t-none-eabi" +#target = "thumbv4t-none-eabi" [unstable] -build-std = ["core"] -build-std-features = ["compiler-builtins-weak-intrinsics"] +#build-std = ["core"] +#build-std-features = ["compiler-builtins-weak-intrinsics"] [target.thumbv4t-none-eabi] runner = "mgba-qt" diff --git a/Cargo.toml b/Cargo.toml index bff7f570..823f1012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,15 @@ license = "Zlib OR Apache-2.0 OR MIT" [features] default = ["track_caller"] track_caller = [] +on_gba = [] [dependencies] voladdress = "1.3.0" bitfrob = "1" bracer = "0.1.2" -critical-section = { version = "1.1.2", features = ["restore-state-bool"], optional = true } +critical-section = { version = "1.1.2", features = [ + "restore-state-bool", +], optional = true } [profile.dev] opt-level = 3 diff --git a/src/builtin_art/cga_8x8_thick.rs b/src/builtin_art/cga_8x8_thick.rs index a6fbf894..ce6918e8 100644 --- a/src/builtin_art/cga_8x8_thick.rs +++ b/src/builtin_art/cga_8x8_thick.rs @@ -2,10 +2,7 @@ use core::mem::size_of_val; use voladdress::{Safe, VolRegion}; -use crate::{ - bios::{BitUnPack, BitUnpackInfo}, - video::{Tile4, Tile8}, -}; +use crate::video::{Tile4, Tile8}; macro_rules! glyph { ($name:ident = $id:expr) => { @@ -69,19 +66,20 @@ impl Cga8x8Thick { /// ## Panics /// * Requires at least 256 elements of space within the region. #[inline] + #[cfg(feature = "on_gba")] pub fn bitunpack_4bpp( self, b: VolRegion, offset_and_touch_zero: u32, ) { assert!(b.len() >= 256); let src = CGA_8X8_THICK.as_ptr(); let dest = b.index(0).as_usize() as *mut u32; - let info = BitUnpackInfo { + let info = crate::bios::BitUnpackInfo { src_byte_len: size_of_val(&CGA_8X8_THICK) as u16, src_elem_width: 1, dest_elem_width: 4, offset_and_touch_zero, }; - unsafe { BitUnPack(src.cast(), dest, &info) }; + unsafe { crate::bios::BitUnPack(src.cast(), dest, &info) }; } /// Bit unpacks the data (8bpp depth) to the location given. @@ -92,19 +90,20 @@ impl Cga8x8Thick { /// ## Panics /// * Requires at least 256 elements of space within the region. #[inline] + #[cfg(feature = "on_gba")] pub fn bitunpack_8bpp( self, b: VolRegion, offset_and_touch_zero: u32, ) { assert!(b.len() >= 256); let src = CGA_8X8_THICK.as_ptr(); let dest = b.index(0).as_usize() as *mut u32; - let info = BitUnpackInfo { + let info = crate::bios::BitUnpackInfo { src_byte_len: size_of_val(&CGA_8X8_THICK) as u16, src_elem_width: 1, dest_elem_width: 8, offset_and_touch_zero, }; - unsafe { BitUnPack(src.cast(), dest, &info) }; + unsafe { crate::bios::BitUnPack(src.cast(), dest, &info) }; } } diff --git a/src/lib.rs b/src/lib.rs index 4cd643c8..565f694c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![warn(clippy::missing_inline_in_public_items)] #![allow(clippy::let_and_return)] #![allow(clippy::result_unit_err)] +#![allow(unused_imports)] //#![warn(missing_docs)] //! A crate for GBA development. @@ -88,18 +89,25 @@ mod macros; +#[cfg(feature = "on_gba")] pub mod asm_runtime; +#[cfg(feature = "on_gba")] pub mod bios; pub mod builtin_art; #[cfg(feature = "critical-section")] mod critical_section; +#[cfg(feature = "on_gba")] pub mod dma; pub mod fixed; +#[cfg(feature = "on_gba")] pub mod gba_cell; pub mod interrupts; pub mod keys; +#[cfg(feature = "on_gba")] pub mod mem_fns; +#[cfg(feature = "on_gba")] pub mod mgba; +#[cfg(feature = "on_gba")] pub mod mmio; pub mod prelude; pub mod random; diff --git a/src/prelude.rs b/src/prelude.rs index f5761ded..45b30dc5 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,17 +1,16 @@ //! A module that just re-exports all the other modules of the crate. +#[cfg(feature = "on_gba")] +pub use crate::{ + asm_runtime::*, bios::*, dma::*, gba_cell::*, mgba::*, mmio::*, +}; + pub use crate::{ - asm_runtime::*, - bios::*, builtin_art::*, - dma::*, fixed::*, - gba_cell::*, include_aligned_bytes, interrupts::*, keys::*, - mgba::*, - mmio::*, sound::*, timers::*, video::{obj::*, *},