Add main structure of Emulator & Chip8 crate

This commit is contained in:
arnaucube
2020-10-17 22:41:23 +02:00
parent b7a6dac788
commit 755a772036
7 changed files with 182 additions and 0 deletions

59
src/main.rs Normal file
View File

@@ -0,0 +1,59 @@
use clap::{App, Arg};
use chip8::Chip8;
struct SdlEmulator {
w: usize,
h: usize,
zoom: usize,
chip8: Chip8,
}
impl SdlEmulator {
fn new(w: usize, h: usize, zoom: usize) -> SdlEmulator {
let mut c = Chip8::new();
SdlEmulator {
w,
h,
zoom,
chip8: c,
}
}
fn draw_graphics(&mut self) {
// TODO
}
fn set_keys(&mut self) {
// TODO
}
}
fn main() {
let matches = App::new("chip8-rs")
.version("0.0.1")
.about("chip8 emulator")
.arg(
Arg::with_name("file")
.short("f")
.long("file")
.takes_value(true)
.help("File path of the rom to load"),
)
.get_matches();
let file = matches.value_of("file");
let file = match file {
Some(file) => file,
_ => panic!("Please specify file path of the rom to load"),
};
println!("{:?}", file);
let mut e = SdlEmulator::new(64, 32, 8);
loop {
e.chip8.emulate_cycle();
if e.chip8.draw_flag {
e.draw_graphics();
}
e.set_keys();
// delay
}
}