output binary for file output

This commit is contained in:
2025-10-23 21:59:33 +01:00
parent 73f22f5fce
commit c73127a634
7 changed files with 12 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
# RC2014 - Quazar OLED board # RC2014 - Quazar OLED board
This project provides MACRO-80 assembler code for `oled` program to drive OLED display for RC2014 by Quazar. It provides a Rust "script" to convert 128x32 black and white image to hex output suitable for the `oled` program. This project provides MACRO-80 assembler code for `oled` program for CP/M to drive OLED display for RC2014 by Quazar. It provides a Rust "script" to convert 128x32 black and white image to hex output suitable for the `oled` program.
## Compiling ## Compiling

BIN
compute.obm Normal file

Binary file not shown.

BIN
cpm.obm Normal file

Binary file not shown.

View File

@@ -8,6 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
image = { version = "0.25.8", default-features = false, features = ["png"] } image = { version = "0.25.8", default-features = false, features = ["png"] }
atty = { version = "0.2.14" }
*/ */
use image::GenericImageView; use image::GenericImageView;
@@ -15,7 +16,7 @@ use image::ImageReader;
use image::Pixel; use image::Pixel;
use std::env; use std::env;
use std::error::Error; use std::error::Error;
use std::io::{Error as IoError, ErrorKind}; use std::io::{stdout, Error as IoError, ErrorKind, Write};
/// Example script description /// Example script description
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
@@ -23,11 +24,11 @@ fn main() -> Result<(), Box<dyn Error>> {
ErrorKind::NotFound, ErrorKind::NotFound,
"expected PNG 128x32 file path", "expected PNG 128x32 file path",
))?; ))?;
println!("Loading {}", file); eprintln!("Loading {}", file);
let img = ImageReader::open(file)?.decode()?; let img = ImageReader::open(file)?.decode()?;
let (w, h) = img.dimensions(); let (w, h) = img.dimensions();
println!("Loaded file {}x{}", w, h); eprintln!("Loaded file {}x{}", w, h);
if w != 128 && h != 32 { if w != 128 && h != 32 {
return Err(Into::into(IoError::new( return Err(Into::into(IoError::new(
ErrorKind::InvalidData, ErrorKind::InvalidData,
@@ -35,6 +36,8 @@ fn main() -> Result<(), Box<dyn Error>> {
))); )));
} }
let out_hex = atty::is(atty::Stream::Stdout);
for row in 0..4 { for row in 0..4 {
for column in 0..128 { for column in 0..128 {
let mut byte = 0u8; let mut byte = 0u8;
@@ -48,7 +51,11 @@ fn main() -> Result<(), Box<dyn Error>> {
byte = byte | 128; byte = byte | 128;
} }
} }
print!("{:02X}", byte); if out_hex {
print!("{:02X}", byte);
} else {
stdout().write(&[byte]).unwrap();
}
} }
} }

BIN
toghxd.obm Normal file

Binary file not shown.

BIN
toghxdgr.obm Normal file

Binary file not shown.

BIN
zilog.obm Normal file

Binary file not shown.