/// Creates a ROM image, generating the header and IPL3 from `args`. An optional
/// file system (FAT image) is appended to the ROM image if provided.
Creates a ROM image, generating the header and IPL3 from `args`. An optional
file system (FAT image) is appended to the ROM image if provided.
Creates a ROM image generating the header and IPL3 from ` args ` . An optional file system ( FAT image ) is appended to the ROM image if provided .
fn create_rom_image(
    path: PathBuf,
    args: &BuildArgs,
    entry_point: u32,
    program: Vec<u8>,
    fs: Option<Vec<u8>>,
) -> Result<(), BuildError> {
    use self::BuildError::*;
    let fs = if let Some(fs) = fs { fs } else { Vec::new() };
    let mut file =
        File::create(&path).map_err(|_| CreateFileError(path.to_string_lossy().to_string()))?;
    let header = N64Header::new(entry_point, &args.name, &program, &fs, &args.ipl3).to_vec();
    file.write_all(&header)
        .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    let ipl = args.ipl3.get_ipl();
    file.write_all(ipl)
        .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    file.write_all(&program)
        .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    let padding_length = (2 - (program.len() & 1)) & 1;
    let padding = [0; 1];
    file.write_all(&padding[0..padding_length])
        .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    file.write_all(&fs)
        .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    let rom_length = HEADER_SIZE + IPL_SIZE + program.len() + padding_length + fs.len();
    const ROM_SIZE: usize = PROGRAM_SIZE + HEADER_SIZE + IPL_SIZE;
    if rom_length < ROM_SIZE {
        let padding = std::iter::repeat(0)
            .take(ROM_SIZE - rom_length)
            .collect::<Vec<u8>>();
        file.write_all(&padding)
            .map_err(|_| WriteFileError(path.to_string_lossy().to_string()))?;
    }
    // TODO: Padding up to nearest 4 KB?
    Ok(())
}
fn create_rom_image ( path : PathBuf , args : & BuildArgs , entry_point : u32 , program : Vec < u8 > , fs : Option < Vec < u8 > > , ) -> Result < ( ) , BuildError > { use self :: BuildError :: * ; let fs = if let Some ( fs ) = fs { fs } else { Vec :: new ( ) } ; let mut file = File :: create ( & path ) . map_err ( | _ | CreateFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; let header = N64Header :: new ( entry_point , & args . name , & program , & fs , & args . ipl3 ) . to_vec ( ) ; file . write_all ( & header ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; let ipl = args . ipl3 . get_ipl ( ) ; file . write_all ( ipl ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; file . write_all ( & program ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; let padding_length = ( 2 - ( program . len ( ) & 1 ) ) & 1 ; let padding = [ 0 ; 1 ] ; file . write_all ( & padding [ 0 .. padding_length ] ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; file . write_all ( & fs ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; let rom_length = HEADER_SIZE + IPL_SIZE + program . len ( ) + padding_length + fs . len ( ) ; const ROM_SIZE : usize = PROGRAM_SIZE + HEADER_SIZE + IPL_SIZE ; if rom_length < ROM_SIZE { let padding = std :: iter :: repeat ( 0 ) . take ( ROM_SIZE - rom_length ) . collect :: < Vec < u8 > > ( ) ; file . write_all ( & padding ) . map_err ( | _ | WriteFileError ( path . to_string_lossy ( ) . to_string ( ) ) ) ? ; } // TODO: Padding up to nearest 4 KB? Ok ( ( ) ) }
Creates a ROM image, generating the header and IPL3 from `args`.
Creates a ROM image generating the header and IPL3 from ` args ` .
path
PathBuf
args
&BuildArgs
entry_point
u32
program
Vec<u8>
fs
Option<Vec<u8>>