-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
51 lines (42 loc) · 1.04 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
48
49
50
51
use crate::cpu::CPU;
use minifb::{Scale, Window, WindowOptions};
mod cpu;
mod keypad;
const WIDTH: usize = 64;
const HEIGHT: usize = 32;
pub struct Chip8 {
pub cpu: CPU,
pub buffer: Vec<u32>,
pub rom: Vec<u8>,
pub stop: bool,
}
fn main() {
let mut chip8 = Chip8 {
cpu: CPU::new(),
buffer: vec![0; WIDTH * HEIGHT],
rom: Vec::<u8>::new(),
stop: false,
};
let mut window = Window::new(
"Chip-8rs",
WIDTH,
HEIGHT,
WindowOptions {
scale: Scale::X16,
..WindowOptions::default()
},
)
.expect("Window creation error");
window.limit_update_rate(None);
let rom_path = std::env::args().nth(1).expect("No ROM was provided!");
if let Ok(ins) = std::fs::read(rom_path) {
chip8.rom = ins;
}
while window.is_open() {
if !chip8.stop && !chip8.rom.is_empty() {
chip8.cpu.run(&chip8.rom, &mut chip8.buffer, &mut window);
chip8.stop = true;
}
window.update();
}
}