This commit is contained in:
Lokathor 2022-10-18 09:44:23 -06:00
parent b9420b9cbf
commit 39c48bc462
6 changed files with 31 additions and 5 deletions

View file

@ -3,6 +3,8 @@
* **0.9.1:** * **0.9.1:**
* Adds some randomization support directly into the crate. * Adds some randomization support directly into the crate.
* Added more methods to the `Fixed` type. * Added more methods to the `Fixed` type.
* Adds an `include_aligned_bytes!` macro to pull in compile time data that's
aligned to 4.
* **0.9.0:** * **0.9.0:**
* **MSRV:** The crate now requires `compiler_builtins-0.1.81` to build. You * **MSRV:** The crate now requires `compiler_builtins-0.1.81` to build. You
will need a Nightly from 2022-10-15 or later. will need a Nightly from 2022-10-15 or later.

1
examples/foo.txt Normal file
View file

@ -0,0 +1 @@
foo_

View file

@ -2,10 +2,7 @@
#![no_main] #![no_main]
use core::fmt::Write; use core::fmt::Write;
use gba::{ use gba::prelude::*;
mgba::{MgbaBufferedLogger, MgbaMessageLevel},
prelude::*,
};
#[panic_handler] #[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! { fn panic_handler(info: &core::panic::PanicInfo) -> ! {
@ -15,6 +12,9 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
loop {} loop {}
} }
#[allow(dead_code)]
const FOO_: Align4<[u8; 4]> = include_aligned_bytes!("foo.txt");
#[link_section = ".ewram"] #[link_section = ".ewram"]
static FRAME_KEYS: GbaCell<KeyInput> = GbaCell::new(KeyInput::new()); static FRAME_KEYS: GbaCell<KeyInput> = GbaCell::new(KeyInput::new());

View file

@ -101,3 +101,24 @@ pub mod random;
pub mod sound; pub mod sound;
pub mod timers; pub mod timers;
pub mod video; pub mod video;
/// Wraps a value to be aligned to a minimum of 4.
///
/// If the size of the value held is already a multiple of 4 then this will be
/// the same size as the wrapped value. Otherwise the compiler will add
/// sufficient padding bytes on the end to make the size a multiple of 4.
#[repr(C, align(4))]
pub struct Align4<T>(pub T);
/// As [`include_bytes!`] but the value is wrapped in [`Align4`]
///
/// ## Panics
/// * The included number of bytes must be a multiple of 4.
#[macro_export]
macro_rules! include_aligned_bytes {
($file:expr $(,)?) => {{
let LONG_NAME_THAT_DOES_NOT_CLASH = *include_bytes!($file);
assert!(LONG_NAME_THAT_DOES_NOT_CLASH.len() % 4 == 0);
Align4(LONG_NAME_THAT_DOES_NOT_CLASH)
}};
}

View file

@ -2,5 +2,6 @@
pub use crate::{ pub use crate::{
asm_runtime::*, bios::*, builtin_art::*, dma::*, fixed::*, gba_cell::*, asm_runtime::*, bios::*, builtin_art::*, dma::*, fixed::*, gba_cell::*,
interrupts::*, keys::*, mmio::*, sound::*, timers::*, video::*, include_aligned_bytes, interrupts::*, keys::*, mgba::*, mmio::*, sound::*,
timers::*, video::*, Align4,
}; };

View file

@ -124,6 +124,7 @@ pub trait Gen32 {
} }
impl Gen32 for Lcg32 { impl Gen32 for Lcg32 {
#[inline]
fn next_u32(&mut self) -> u32 { fn next_u32(&mut self) -> u32 {
Lcg32::next_u32(self) Lcg32::next_u32(self)
} }