58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
// let's try to write our own, awesome emulator.
|
|
// gameboy (color?)
|
|
|
|
use std::path::Path;
|
|
use std::io;
|
|
use std::io::Read;
|
|
use std::io::Write;
|
|
use std::fs;
|
|
use std::env;
|
|
|
|
mod cartridge;
|
|
mod cpu;
|
|
mod display;
|
|
mod interconnect;
|
|
mod sound;
|
|
mod timer;
|
|
mod serial;
|
|
mod mbc;
|
|
|
|
|
|
fn main() {
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() < 3 || args.len() > 4 {
|
|
println!("Usage: {} bios game [savefile]", args[0]);
|
|
} else {
|
|
let bios_path = &args[1];
|
|
let rom_path = &args[2];
|
|
let mut save_file: Option<String> = None;
|
|
if args.len() == 4 {
|
|
save_file = Some(args[3].clone());
|
|
}
|
|
|
|
let bios = read_file(&bios_path).unwrap();
|
|
let rom = read_file(&rom_path).unwrap();
|
|
|
|
// Now we need to execute commands
|
|
let interconnect = interconnect::Interconnect::new(bios, rom, save_file);
|
|
let mut cpu = cpu::CPU::new(interconnect);
|
|
|
|
loop {
|
|
cpu.run();
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn read_file<P: AsRef<Path>>(rom_path: P) -> Result<Box<[u8]>, io::Error> {
|
|
let mut file = try!(fs::File::open(rom_path));
|
|
let mut buf = Vec::new();
|
|
try!(file.read_to_end(&mut buf));
|
|
Ok(buf.into_boxed_slice())
|
|
}
|
|
|
|
pub fn write_file<P: AsRef<Path>>(path: P, data: &Box<[u8]>) -> Result<(), io::Error> {
|
|
let mut file = try!(fs::File::create(path));
|
|
try!(file.write(&data));
|
|
Ok(())
|
|
}
|