bus.rs: Debug print screen with drawille, if enabled
This commit is contained in:
parent
d12f3fe710
commit
4f6f91b69b
15
Cargo.toml
15
Cargo.toml
@ -6,8 +6,9 @@ authors = ["John Breaux"]
|
||||
license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["unstable"]
|
||||
default = ["unstable", "drawille"]
|
||||
unstable = []
|
||||
drawille = ["dep:drawille"]
|
||||
iced = ["dep:iced"]
|
||||
rhexdump = ["dep:rhexdump"]
|
||||
serde = ["dep:serde"]
|
||||
@ -26,12 +27,14 @@ overflow-checks = false
|
||||
|
||||
|
||||
[dependencies]
|
||||
gumdrop = "^0.8.1"
|
||||
drawille = {version = "0.3.0", optional = true}
|
||||
iced = {version = "0.8.0", optional = true}
|
||||
imperative-rs = "0.3.1"
|
||||
minifb = { version = "^0.24.0", features = ["wayland"] }
|
||||
owo-colors = "^3"
|
||||
rand = "^0.8.5"
|
||||
rhexdump = {version = "^0.1.1", optional = true }
|
||||
serde = { version = "^1.0", features = ["derive"], optional = true }
|
||||
|
||||
gumdrop = "^0.8.1"
|
||||
imperative-rs = "0.3.1"
|
||||
minifb = { version = "^0.24.0" }
|
||||
owo-colors = "^3"
|
||||
rand = "^0.8.5"
|
||||
thiserror = "^1.0.39"
|
||||
|
32
src/bus.rs
32
src/bus.rs
@ -324,15 +324,43 @@ impl Bus {
|
||||
pub fn print_screen(&self) -> Result<()> {
|
||||
const REGION: Region = Region::Screen;
|
||||
if let Some(screen) = self.get_region(REGION) {
|
||||
let len_log2 = screen.len().ilog2() / 2;
|
||||
#[allow(unused_variables)]
|
||||
let (width, height) = (2u32.pow(len_log2 - 1), 2u32.pow(len_log2));
|
||||
// draw with the drawille library, if available
|
||||
#[cfg(feature = "drawille")]
|
||||
{
|
||||
use drawille::Canvas;
|
||||
let mut canvas = Canvas::new(width * 8, height);
|
||||
let width = width * 8;
|
||||
screen
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(bytei, byte)| {
|
||||
(0..8)
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.filter_map(move |(biti, bit)| {
|
||||
if (byte << bit) & 0x80 != 0 {
|
||||
Some(bytei * 8 + biti)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.for_each(|index| canvas.set(index as u32 % (width), index as u32 / (width)));
|
||||
println!("{}", canvas.frame());
|
||||
}
|
||||
#[cfg(not(feature = "drawille"))]
|
||||
for (index, byte) in screen.iter().enumerate() {
|
||||
if index % 16 == 0 {
|
||||
if index % width as usize == 0 {
|
||||
print!("{index:03x}|");
|
||||
}
|
||||
print!(
|
||||
"{}",
|
||||
format!("{byte:08b}").replace('0', " ").replace('1', "█")
|
||||
);
|
||||
if index % 16 == 15 {
|
||||
if index % width as usize == width as usize - 1 {
|
||||
println!("|");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user