one_fpga/
runner.rs

1use std::collections::BTreeMap;
2use std::path::PathBuf;
3
4use crate::core::{Bios, Rom};
5
6/// The type of core to launch.
7#[derive(Debug, Clone)]
8pub enum CoreType {
9    /// Don't launch a new core, keep the current one running.
10    Current,
11
12    /// Launch a core from an RBF file.
13    RbfFile(PathBuf),
14
15    /// Launch the menu core.
16    Menu,
17}
18
19#[derive(Debug, Clone)]
20pub enum Slot {
21    File(PathBuf),
22    Memory(PathBuf, Vec<u8>),
23}
24
25#[derive(Debug, Clone)]
26pub struct CoreLaunchInfo<T> {
27    pub core: CoreType,
28    pub rom: Option<Rom>,
29    pub bios: Vec<Bios>,
30    pub files: BTreeMap<usize, Slot>,
31    pub save_state: Vec<Slot>,
32
33    pub data: T,
34}
35
36impl CoreLaunchInfo<()> {
37    fn new(core_loader: CoreType) -> Self {
38        Self {
39            core: core_loader,
40            rom: None,
41            bios: Default::default(),
42            files: Default::default(),
43            save_state: Default::default(),
44            data: (),
45        }
46    }
47
48    pub fn rbf(rbf_path: PathBuf) -> Self {
49        Self::new(CoreType::RbfFile(rbf_path))
50    }
51
52    pub fn menu() -> Self {
53        Self::new(CoreType::Menu)
54    }
55
56    pub fn current() -> Self {
57        Self::new(CoreType::Current)
58    }
59}
60
61impl<T> CoreLaunchInfo<T> {
62    pub fn with_rom(mut self, rom: Rom) -> Self {
63        self.rom = Some(rom);
64        self
65    }
66
67    pub fn with_file(mut self, slot: usize, content: Slot) -> Self {
68        self.files.insert(slot, content);
69        self
70    }
71
72    pub fn with_save_state(mut self, content: Slot) -> Self {
73        self.save_state.push(content);
74        self
75    }
76
77    pub fn with_data<U>(self, data: U) -> CoreLaunchInfo<U> {
78        CoreLaunchInfo {
79            core: self.core,
80            rom: self.rom,
81            bios: self.bios,
82            files: self.files,
83            save_state: self.save_state,
84            data,
85        }
86    }
87}