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
use anyhow::Result;
use retroboy_sdl2::App;
use retroboy_sdl2::{SdlContext, SdlInitInfo};

pub enum EmulatorType {
    Chip8,
}

pub fn run(emulator: EmulatorType, rom_path: &str) -> Result<()> {
    match emulator {
        EmulatorType::Chip8 => {
            run_chip8(rom_path)?;
        }
    }
    Ok(())
}

pub fn run_chip8(rom_path: &str) -> Result<()> {
    let rom = std::fs::read(rom_path)?;

    let mut app = retroboy_chip8::EmulatorApp::default();
    app.emulator.load_rom(&rom);
    let width = app.width();
    let height = app.height();
    let scale = app.scale();
    let init_info = SdlInitInfo::builder()
        .width(width)
        .height(height)
        .scale(scale)
        .title("RetroBoy Chip-8".to_string())
        .build();
    SdlContext::run(init_info, app)?;
    Ok(())
}