move tests to unit_tests to clean up individual files

adds start of font characters
This commit is contained in:
2024-10-27 12:08:22 -04:00
parent e29ac45c84
commit 1694157e27
31 changed files with 1797 additions and 1524 deletions
+83
View File
@@ -0,0 +1,83 @@
use std::fs::File;
use std::io;
use std::io::{BufReader, Read};
use clap::{Arg, Command, ArgAction, ValueEnum};
#[derive(Debug)]
struct CliArgs {
input: String,
}
fn main() {
println!("Taxation is Theft!");
// Set up the command line arguments
let matches = Command::new("my_program")
.about("Processes an input file and outputs it with a specified bit width")
.arg(
Arg::new("input")
.help("The input file to process")
.required(true)
.index(1),
)
.get_matches();
// Parse the command-line arguments
let args = CliArgs {
input: matches.get_one::<String>("input").unwrap().to_string(),
};
// Use the parsed arguments
println!("Input file: {}", args.input);
// behave like a shift register and load each character from the file 1 by 1.
let results = read_file_to_bools(&args.input);
for result in results.unwrap().bytes() {
print!("0x{:02x}, ", result.unwrap());
}
}
fn read_file_to_bools(file_path: &str) -> io::Result<Vec<u8>> {
// Open the file
let file = File::open(file_path)?;
let mut reader = BufReader::new(file);
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes)?;
let mut output = Vec::new();
let mut current_byte = 0u8;
let mut bit_index = 0;
for &byte in &bytes {
// Convert ASCII character '1' or '0' to boolean, skip any other characters
let bit = match byte {
b'1' => true,
b'0' => false,
_ => continue, // Skip non-'1' or '0' characters
};
// Set the appropriate bit in the current byte
if bit {
current_byte |= 1 << (7 - bit_index); // Set the bit at the correct position
}
bit_index += 1;
// Once we have filled 8 bits, push the byte and reset
if bit_index == 8 {
output.push(current_byte);
current_byte = 0;
bit_index = 0;
}
}
// If there are remaining bits, push the last byte (it will be partially filled)
if bit_index > 0 {
output.push(current_byte);
}
Ok(output)
}