#![no_std]
#![cfg_attr(test, no_main)]
#![cfg_attr(test, feature(custom_test_frameworks))]
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
#![cfg_attr(test, test_runner(agb::test_runner::test_runner))]
pub mod multi_typewriter;
pub mod renderer;
pub mod sprite_renderer;
pub mod typewriter;
extern crate alloc;
pub use gba_agb_font_loader::include_agb_font;
pub use gba_agb_font_eb;
pub mod prelude {
pub use crate::TextAlign;
pub use crate::TextFormat;
pub use crate::TextOverflow;
pub use crate::include_agb_font;
pub use crate::multi_typewriter::*;
pub use crate::renderer::*;
pub use crate::sprite_renderer::*;
pub use crate::typewriter::*;
pub use gba_agb_font_eb::prelude::*;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct TextFormat {
pub overflow: TextOverflow,
pub align: TextAlign,
pub clear: (u16, u16),
}
impl TextFormat {
pub const fn new(overflow: TextOverflow, align: TextAlign, clear: (u16, u16)) -> Self {
Self {
overflow,
align,
clear,
}
}
pub const fn wrapped(px: u16) -> Self {
Self::new(TextOverflow::Wrap(px, true), TextAlign::Left, (0, 0))
}
pub const fn hard_wrapped(px: u16) -> Self {
Self::new(TextOverflow::Wrap(px, false), TextAlign::Left, (0, 0))
}
pub const fn cutoff(px: u16) -> Self {
Self::new(TextOverflow::Cutoff(px), TextAlign::Left, (0, 0))
}
pub const fn centered(column_px: u16) -> Self {
Self::new(TextOverflow::Nothing, TextAlign::Center(column_px), (0, 0))
}
pub const fn right_aligned(column_px: u16) -> Self {
Self::new(TextOverflow::Nothing, TextAlign::Right(column_px), (0, 0))
}
pub const fn with_clear(mut self, width: u16, height: u16) -> Self {
self.clear = (width, height);
self
}
pub const fn with_align(mut self, align: TextAlign) -> Self {
self.align = align;
self
}
pub const fn with_overflow(mut self, overflow: TextOverflow) -> Self {
self.overflow = overflow;
self
}
}
impl Default for TextFormat {
#[inline]
fn default() -> Self {
Self {
clear: (0, 0),
align: TextAlign::default(),
overflow: TextOverflow::default(),
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum TextOverflow {
#[default]
Nothing,
Cutoff(u16),
Wrap(u16, bool),
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum TextAlign {
#[default]
Left,
Center(u16),
Right(u16),
}
#[allow(clippy::empty_loop)]
#[cfg(test)]
#[agb::entry]
fn main(mut _gba: agb::Gba) -> ! {
loop {}
}
#[unsafe(link_section = ".iwram")]
#[instruction_set(arm::a32)]
fn blit_pixel_row_arm(target: &mut u32, src: u32) {
if src == 0 {
return;
}
let hi = src & 0x8888_8888;
let lo = src & 0x7777_7777;
let set_nybbles = (hi | ((lo.wrapping_add(0x7777_7777)) & 0x8888_8888)) >> 3;
let mask = set_nybbles * 0xF;
*target = (*target & !mask) | src;
}