From 90aa01d2050e7391e0f333ea47436e972dbbe18f Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 13 Oct 2022 20:19:39 -0600 Subject: [PATCH] make the default cga font easier to unpack. --- Cargo.toml | 2 +- examples/hello.rs | 2 +- src/builtin_art/cga_8x8_thick.rs | 33 +++++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f7ec989..3a85a92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "Zlib OR Apache-2.0 OR MIT" [dependencies] bitfrob = "0.2.3" -voladdress = "1.0.2" +voladdress = { version = "1.1", features = ["experimental_volregion"] } [profile.dev] opt-level = 3 diff --git a/examples/hello.rs b/examples/hello.rs index b3f4902..94ee975 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -63,7 +63,7 @@ extern "C" fn main() -> ! { { // get our tile data into memory. - Cga8x8Thick.bitunpack_4bpp(CHARBLOCK0_4BPP, 0); + Cga8x8Thick.bitunpack_4bpp(CHARBLOCK0_4BPP.as_region().sub_slice(..256), 0); } { diff --git a/src/builtin_art/cga_8x8_thick.rs b/src/builtin_art/cga_8x8_thick.rs index 6fc7241..4e67d84 100644 --- a/src/builtin_art/cga_8x8_thick.rs +++ b/src/builtin_art/cga_8x8_thick.rs @@ -1,10 +1,10 @@ use core::mem::size_of_val; -use voladdress::{Safe, VolBlock}; +use voladdress::{Safe, VolRegion}; use crate::{ bios::{BitUnPack, BitUnpackInfo}, - video::Tile4, + video::{Tile4, Tile8}, }; /// The CGA [Code Page 437][cp437] type face, with thick lines. @@ -135,10 +135,14 @@ impl Cga8x8Thick { /// /// * `offset_and_touch_zero`: Works like the [`BitUnpackInfo`] field. By /// default you should usually pass 0 here. + /// + /// ## Panics + /// * Requires at least 256 elements of space within the region. #[inline] pub fn bitunpack_4bpp( - self, b: VolBlock, offset_and_touch_zero: u32, + self, b: VolRegion, offset_and_touch_zero: u32, ) { + assert!(b.len() >= 256); let src = CGA_8X8_THICK.as_ptr(); let dest = b.index(0).as_usize() as *mut u32; let info = BitUnpackInfo { @@ -149,4 +153,27 @@ impl Cga8x8Thick { }; unsafe { BitUnPack(src.cast(), dest, &info) }; } + + /// Bit unpacks the data (8bpp depth) to the location given. + /// + /// * `offset_and_touch_zero`: Works like the [`BitUnpackInfo`] field. By + /// default you should usually pass 0 here. + /// + /// ## Panics + /// * Requires at least 256 elements of space within the region. + #[inline] + pub fn bitunpack_8bpp( + self, b: VolRegion, offset_and_touch_zero: u32, + ) { + assert!(b.len() >= 256); + let src = CGA_8X8_THICK.as_ptr(); + let dest = b.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: 8, + offset_and_touch_zero, + }; + unsafe { BitUnPack(src.cast(), dest, &info) }; + } }