This commit is contained in:
Lokathor 2022-10-09 12:32:14 -06:00
parent 335d8c0455
commit 342d8fc25a
2 changed files with 11 additions and 21 deletions

View file

@ -63,7 +63,7 @@ extern "C" fn main() -> ! {
{ {
// get our tile data into memory. // get our tile data into memory.
Cga8x8Thick.bitunpack_to_4bpp(CHARBLOCK0_4BPP, 0); Cga8x8Thick.bitunpack_4bpp(CHARBLOCK0_4BPP, 0);
} }
{ {

View file

@ -9,30 +9,16 @@ use crate::{
/// The CGA [Code Page 437][cp437] type face, with thick lines. /// The CGA [Code Page 437][cp437] type face, with thick lines.
/// ///
/// There's 256 tiles, packed down to 1bpp. To decompress this into 4bpp tile /// There's 256 tiles, packed down to 1bpp.
/// data you can call [`BitUnPack`](crate::bios::BitUnPack) as follows: ///
/// To easily decompress this you can use the [`Cga8x8Thick`] type, which
/// provides a safe helper method:
/// ///
/// ```no_run /// ```no_run
/// # use gba::prelude::*; /// # use gba::prelude::*;
/// # use core::mem::size_of_val; /// Cga8x8Thick.bitunpack_4bpp(CHARBLOCK0_4BPP, 0);
/// let src = CGA_8X8_THICK.as_ptr().cast::<u8>();
///
/// let dest = CHARBLOCK0_4BPP.index(0).as_usize() as *mut u32;
///
/// let info = BitUnpackInfo {
/// src_byte_len: size_of_val(&CGA_8X8_THICK) as u16,
/// src_elem_width: 1,
/// dest_elem_width: 4,
/// offset_and_touch_zero: 0,
/// };
///
/// unsafe { BitUnPack(src, dest, &info) };
/// ``` /// ```
/// ///
/// * You can use `dest_elem_width: 8` if you want 8bpp tile data.
/// * If you want the "opaque" pixels to be a palette index other than 1 you can
/// use an appropriate offset value.
///
/// I am not a lawyer, but type faces are not protected by copyright in the USA. /// I am not a lawyer, but type faces are not protected by copyright in the USA.
/// The copyright status of font faces [varies by country][wp]. If it matters, /// The copyright status of font faces [varies by country][wp]. If it matters,
/// CGA was first released in 1981. This 8x8 version comes from the [Dwarf /// CGA was first released in 1981. This 8x8 version comes from the [Dwarf
@ -145,8 +131,12 @@ pub static CGA_8X8_THICK: [u32; 512] = [
pub struct Cga8x8Thick; pub struct Cga8x8Thick;
impl Cga8x8Thick { impl Cga8x8Thick {
/// Bit unpacks the data (4bpp depth) to the location given.
///
/// * `offset_and_touch_zero`: Works like the [`BitUnpackInfo`] field. By
/// default you should usually pass 0 here.
#[inline] #[inline]
pub fn bitunpack_to_4bpp( pub fn bitunpack_4bpp(
self, b: VolBlock<Tile4, Safe, Safe, 512>, offset_and_touch_zero: u32, self, b: VolBlock<Tile4, Safe, Safe, 512>, offset_and_touch_zero: u32,
) { ) {
let src = CGA_8X8_THICK.as_ptr(); let src = CGA_8X8_THICK.as_ptr();