Skip to content

Commit

Permalink
gate GBA specific code behind a cargo feature so that it can build (b…
Browse files Browse the repository at this point in the history
…adly) on a host machine.
  • Loading branch information
Lokathor committed Apr 29, 2024
1 parent e71148b commit 5fe972a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/builtin_art/cga_8x8_thick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<Tile4, Safe, Safe>, 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.
Expand All @@ -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<Tile8, Safe, Safe>, 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) };
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -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::*, *},
Expand Down

0 comments on commit 5fe972a

Please sign in to comment.