Browse Source

First commit

master
Stephen 3 months ago
commit
b384b57c88
6 changed files with 63 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +5
    -0
      Cargo.lock
  3. +11
    -0
      Cargo.toml
  4. +5
    -0
      README.md
  5. +2
    -0
      rustfmt.toml
  6. +39
    -0
      src/main.rs

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
/target

+ 5
- 0
Cargo.lock View File

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bitsplit"
version = "0.1.0"

+ 11
- 0
Cargo.toml View File

@ -0,0 +1,11 @@
[package]
name = "bitsplit"
version = "0.1.0"
authors = ["Stephen <webmaster@scd31.com>"]
edition = "2018"
description = "A program that splits an input file into 2 files, where the lower/even bytes end up in one file and the upper/odd bytes end up in another. Useful for programming systems with a 16-bit data bus width that consists of 2 8-bit ROMs."
repository = "https://git.scd31.com/stephen/bitsplit"
license = "MIT"
readme = "README.md"
[dependencies]

+ 5
- 0
README.md View File

@ -0,0 +1,5 @@
# bitsplit
A program that splits an input file into 2 files, where the lower/even bytes end up in one file and the upper/odd bytes end up in another. Useful for programming systems with a 16-bit data bus width that consists of 2 8-bit ROMs.
Written for use with my 68000 single board computer.

+ 2
- 0
rustfmt.toml View File

@ -0,0 +1,2 @@
tab_spaces = 4
hard_tabs = true

+ 39
- 0
src/main.rs View File

@ -0,0 +1,39 @@
use std::env;
use std::fs;
use std::io::Write;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 4 {
eprintln!(
"Usage: {} in_file lower_bytes_out higher_bytes_out",
args[0]
);
return;
}
// Read in binary file
let original_bytes = fs::read(&args[1]).expect("Could not read input file");
let mut lower_bytes = Vec::new();
let mut upper_bytes = Vec::new();
for i in 0..original_bytes.len() {
if i % 2 == 0 {
lower_bytes.push(original_bytes[i]);
} else {
upper_bytes.push(original_bytes[i]);
}
}
let mut lower_file = fs::File::create(&args[2]).expect("Could not create lower bytes file");
lower_file
.write_all(&lower_bytes)
.expect("Could not write lower bytes file");
let mut upper_file = fs::File::create(&args[3]).expect("Could not create upper bytes file");
upper_file
.write_all(&upper_bytes)
.expect("Could not write upper bytes file");
}

Loading…
Cancel
Save