main.rs 1.13 KB
Newer Older
1
extern crate rustn64;
2
3
4
5
6
7
8
9
10
extern crate clap;

use std::fs::File;
use std::io::Read;
use std::path::Path;
use clap::{App, Arg};

use rustn64::PifRom;
use rustn64::n64::Cart;
11

Arthur Carlsson's avatar
Arthur Carlsson committed
12
fn main() {
13
14
15
  let matches = App::new("RustN64")
    .version(env!("CARGO_PKG_VERSION"))
    .author("Arthur Carlsson <arthur@kiron.net>")
Arthur Carlsson's avatar
Arthur Carlsson committed
16
    .about("A Nintendo 64 emulator written in Rust")
17
18
19
20
    .arg(Arg::with_name("PIF")
      .help("The PIF ROM file to use")
      .short("p")
      .long("pif")
21
      .use_delimiter(false)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
      .takes_value(true)
      .required(true))
    .arg(Arg::with_name("ROM")
      .help("The ROM file to use")
      .use_delimiter(false)
      .required(true)
      .index(1))
    .get_matches();

  let pif = read_bin(matches.value_of("PIF").unwrap());
  let rom = read_bin(matches.value_of("ROM").unwrap());

  PifRom::new(pif);
  Cart::new(rom);
}

fn read_bin<P: AsRef<Path>>(path: P) -> Vec<u8> {
  let mut buf = vec![0];

  match File::open(path.as_ref()).and_then(|mut f| f.read_to_end(&mut buf)) {
    Ok(_) => buf,
    Err(e) => {
      println!("Failed to load \"{}\": {}", path.as_ref().display(), e);
      std::process::exit(1);
    }
  }
Arthur Carlsson's avatar
Arthur Carlsson committed
48
}