aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 2e5c80cf4e8ac07a720ae8176a23fc6f5426c5a7 (plain)
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
73
74
75
76
77
pub mod audio;
pub mod consts;
pub mod desktop;
pub mod display;
pub mod interrupts_timers;
pub mod io;
pub mod mmio;
pub mod opcodes;
pub mod state;

use crate::desktop::input::{Gamepad, GamepadRecorder, GamepadReplay, Keyboard};
use crate::desktop::load_save::FSLoadSave;
use crate::io::Input;
use clap::Parser;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    /// The gameboy rom file
    rom: String,

    /// Setting uses more battery and set the CPU to 100% but could sometimes solve inconsistent timing.
    #[arg(long)]
    loop_lock_timing: bool,

    #[arg(long)]
    fifo_input: Option<String>,

    #[arg(long)]
    fifo_output: Option<String>,

    #[arg(long)]
    record_input: Option<String>,

    #[arg(long)]
    replay_input: Option<String>,

    #[arg(short, long, default_value_t = false)]
    keyboard: bool,

    #[arg(short, long, default_value_t = 1.0)]
    speed: f32,

    #[arg(short, long, default_value_t = false)]
    debug: bool,
}

fn main() {
    let cli = Cli::parse();

    println!("Starting {:?}...", &cli.rom);

    let serial = desktop::serial::UnconnectedSerial {};
    let window = desktop::window::DesktopWindow::new().unwrap();

    let mut gamepad: Box<dyn Input> = if let Some(record_file) = cli.replay_input {
        Box::new(GamepadReplay::new(record_file))
    } else if cli.keyboard {
        Box::new(Keyboard::new(window.keys.clone()))
    } else {
        Box::new(Gamepad::new())
    };

    if let Some(record_file) = cli.record_input {
        gamepad = Box::new(GamepadRecorder::new(gamepad, record_file));
    };

    io::Gameboy::<_, _, _, desktop::audio::RodioAudio, _>::new(
        gamepad,
        window,
        serial,
        FSLoadSave::new(&cli.rom, format!("{}.sav", &cli.rom))
            .state_file(format!("{}.dump", &cli.rom)),
        cli.speed as f64,
    )
    .start();
}