support swapped roms
This commit is contained in:
parent
3f2a49eb21
commit
e1e19e76ab
30
src/main.rs
30
src/main.rs
@ -4,10 +4,38 @@ use std::fs;
|
||||
mod device;
|
||||
mod ui;
|
||||
|
||||
fn swap_rom(contents: Vec<u8>) -> Vec<u8> {
|
||||
let test = u32::from_be_bytes(contents[0..4].try_into().unwrap());
|
||||
if test == 0x80371240 {
|
||||
// z64
|
||||
return contents;
|
||||
} else if test == 0x37804012 {
|
||||
// v64
|
||||
let mut data: Vec<u8> = vec![0; contents.len()];
|
||||
for i in (0..contents.len()).step_by(2) {
|
||||
let temp = u16::from_ne_bytes(contents[i..i + 2].try_into().unwrap());
|
||||
data[i..i + 2].copy_from_slice(&temp.to_be_bytes());
|
||||
}
|
||||
return data;
|
||||
} else if test == 0x40123780 {
|
||||
// n64
|
||||
let mut data: Vec<u8> = vec![0; contents.len()];
|
||||
for i in (0..contents.len()).step_by(4) {
|
||||
let temp = u32::from_ne_bytes(contents[i..i + 4].try_into().unwrap());
|
||||
data[i..i + 4].copy_from_slice(&temp.to_be_bytes());
|
||||
}
|
||||
return data;
|
||||
} else {
|
||||
panic!("unknown rom format")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let file_path = &args[1];
|
||||
let contents = fs::read(file_path).expect("Should have been able to read the file");
|
||||
let mut contents = fs::read(file_path).expect("Should have been able to read the file");
|
||||
|
||||
contents = swap_rom(contents);
|
||||
|
||||
let mut device = device::Device::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user