mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 19:01:30 +11:00
aligned bytes, Closes: https://github.com/rust-console/gba/issues/79
This commit is contained in:
parent
b9420b9cbf
commit
39c48bc462
|
@ -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
1
examples/foo.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo_
|
|
@ -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());
|
||||||
|
|
||||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -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)
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue