1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![no_std]
#![warn(missing_docs)]

//! Exports address values of the GBA memory map locations.
//!
//! Also, for some memory regions that are "blocks", const indexing functions
//! are provided.
//!
//! ## Crate Layout
//!
//! All info is exported at the crate root, but the various modules provide some
//! notes about the general usage of that portion of memory.

const fn const_bound_check(index: usize, bound: usize) -> usize {
  const ARRAY: [&str; 1] = ["index out of bounds"];
  ARRAY[(index >= bound) as usize];
  index
}

macro_rules! const_assert {
  ($expr:expr) => {
    const _: () = {
      #[allow(dead_code)]
      const FAILED_ASSERTION: [&str; 1] =
        [concat!("failed assertion: '", stringify!($expr), "' is false",)];
      #[allow(dead_code)]
      const CONDITION: bool = $expr;
      #[allow(dead_code)]
      const ASSERTION: &str = FAILED_ASSERTION[(!CONDITION) as usize];
    };
  };

  // This will let the user see a message
  ($expr:expr, $msg:literal) => {
    const _: () = {
      #[allow(dead_code)]
      const FAILED_ASSERTION: [&str; 1] = [concat!(
        "failed assertion: '",
        stringify!($expr),
        "' is false: ",
        $msg,
      )];
      #[allow(dead_code)]
      const CONDITION: bool = $expr;
      #[allow(dead_code)]
      const ASSERTION: &str = FAILED_ASSERTION[(!CONDITION) as usize];
    };
  };
}

pub mod ewram;
pub use ewram::*;

pub mod iwram;
pub use iwram::*;

pub mod io;
pub use io::*;

pub mod palram;
pub use palram::*;

pub mod vram;
pub use vram::*;

pub mod oam;
pub use oam::*;

pub mod rom;
pub use rom::*;

pub mod sram;
pub use sram::*;