Extract function

This commit is contained in:
Gwilym Inzani 2023-04-06 23:13:42 +01:00
parent 07318256e0
commit d278d50528

View file

@ -1,22 +1,29 @@
use std::{
fs,
error, fs,
io::{BufWriter, Write},
path::PathBuf,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mut output = BufWriter::new(fs::File::create("out.gba")?);
let path = PathBuf::from("tests/text_render");
let file_data = fs::read(path)?;
let file_data = file_data.as_slice();
let elf_file = elf::ElfBytes::<elf::endian::AnyEndian>::minimal_parse(file_data)?;
write_gba_file(file_data.as_slice(), &mut output)?;
output.flush()?;
Ok(())
}
fn write_gba_file<W: Write>(input: &[u8], output: &mut W) -> Result<(), Box<dyn error::Error>> {
let elf_file = elf::ElfBytes::<elf::endian::AnyEndian>::minimal_parse(input)?;
let section_headers = elf_file
.section_headers()
.expect("Expected section headers");
let mut output = BufWriter::new(fs::File::create("out.gba")?);
let mut header = gbafix::GBAHeader::default();
const GBA_START_ADDRESS: u64 = 0x8000000;
@ -64,7 +71,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
address += data.len() as u64;
}
output.flush()?;
Ok(())
}