1use serde::{Deserialize, Serialize};
2
3use crate::interface::Color;
4
5const DEFAULT_DMG_PALETTE: [Color; 4] = [
6 Color::new(255, 255, 255),
7 Color::new(170, 170, 170),
8 Color::new(85, 85, 85),
9 Color::new(0, 0, 0),
10];
11
12pub struct Config {
13 pub model: Model,
14 pub dmg_palette: [Color; 4],
15 pub boot_roms: BootRoms,
16}
17
18#[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
19pub enum Model {
20 Auto,
21 Dmg,
22 Sgb,
23 Sgb2,
24 Cgb,
25 Agb,
26}
27
28impl Model {
29 pub fn is_cgb(&self) -> bool {
30 match self {
31 Model::Cgb | Model::Agb => true,
32 Model::Sgb | Model::Sgb2 | Model::Dmg => false,
33 Model::Auto => panic!(),
34 }
35 }
36}
37
38#[derive(Default, Clone)]
39pub struct BootRoms {
40 pub dmg: Option<Vec<u8>>,
41 pub cgb: Option<Vec<u8>>,
42 pub sgb: Option<Vec<u8>>,
43 pub sgb2: Option<Vec<u8>>,
44 pub agb: Option<Vec<u8>>,
45}
46
47impl BootRoms {
48 pub fn get(&self, model: Model) -> Option<&[u8]> {
49 match model {
50 Model::Dmg => self.dmg.as_deref(),
51 Model::Cgb => self.cgb.as_deref(),
52 Model::Sgb => self.sgb.as_deref(),
53 Model::Sgb2 => self.sgb2.as_deref(),
54 Model::Agb => self.agb.as_deref(),
55 Model::Auto => panic!(),
56 }
57 }
58}
59
60impl Default for Config {
61 fn default() -> Self {
62 Self {
63 model: Model::Auto,
64 dmg_palette: DEFAULT_DMG_PALETTE,
65 boot_roms: Default::default(),
66 }
67 }
68}
69
70impl Config {
71 pub fn set_model(mut self, model: Model) -> Self {
72 self.model = model;
73 self
74 }
75 pub fn set_dmg_palette(mut self, palette: &[Color; 4]) -> Self {
76 self.dmg_palette = *palette;
77 self
78 }
79 pub fn set_boot_rom(mut self, boot_roms: BootRoms) -> Self {
80 self.boot_roms = boot_roms;
81 self
82 }
83}