diff --git a/src/cpu/mode.rs b/src/cpu/mode.rs index f531a8c..3645b41 100644 --- a/src/cpu/mode.rs +++ b/src/cpu/mode.rs @@ -28,12 +28,37 @@ impl FromStr for Mode { fn from_str(s: &str) -> std::result::Result { match s.to_lowercase().as_str() { - "chip8" | "chip-8" => Ok(Mode::Chip8), - "schip" | "superchip" => Ok(Mode::SChip), - "xo-chip" | "xochip" => Ok(Mode::XOChip), - _ => Err(Error::InvalidMode { - mode: s.to_string(), - }), + "chip" | "chip8" | "chip-8" => Ok(Mode::Chip8), + "s" | "schip" | "superchip" | "super chip" => Ok(Mode::SChip), + "xo" | "xochip" | "xo-chip" => Ok(Mode::XOChip), + _ => Err(Error::InvalidMode { mode: s.into() }), + } + } +} + +impl AsRef for Mode { + fn as_ref(&self) -> &str { + match self { + Mode::Chip8 => "Chip-8", + Mode::SChip => "Super Chip", + Mode::XOChip => "XO-Chip", + } + } +} + +impl ToString for Mode { + fn to_string(&self) -> String { + self.as_ref().into() + } +} + +impl From for Mode { + fn from(value: usize) -> Self { + match value { + 0 => Self::Chip8, + 1 => Self::SChip, + 2 => Self::XOChip, + _ => Self::Chip8, } } }