-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
72 lines (59 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
mod cartridge;
mod console;
mod cpu;
mod debug;
mod display;
mod joypad;
mod memory;
mod memory_utils;
mod opcodes;
mod ppu;
mod registers;
mod utils;
use std::path::Path;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use std::env;
fn main() -> Result<(), String> {
let args: Vec<String> = env::args().collect();
assert!(args.len() > 1);
let debug = args.len() > 2 && args[2] == "--debug";
let rom_path = args[1].clone();
let (stx, srx) = mpsc::channel();
// TODO: don't set up the debugger if not debugging
let (rth_send, rth_recv) = mpsc::channel();
let (htr_send, htr_recv) = mpsc::channel();
let mut debugger_remote = debug::DebuggerRemote::new(rth_send, htr_recv);
thread::spawn(move || {
let mut console = console::Console::new(Path::new(&rom_path), stx, debug);
let mut debugger_host = debug::DebuggerHost::new(rth_recv, htr_send);
'running: loop {
if debug {
debugger_host.update(&mut console);
}
if !console.tick() {
break 'running;
}
}
});
'looping: loop {
let signal = srx.try_recv();
match signal {
Ok(signal) => match signal {
console::ConsoleSignal::Quit => break 'looping,
},
Err(error) => match error {
mpsc::TryRecvError::Empty => {}
mpsc::TryRecvError::Disconnected => {
break 'looping;
}
},
}
if debug {
debugger_remote.update();
}
thread::sleep(Duration::from_millis(100));
}
return Ok(());
}