use crate::errors::lpanic;
#[derive(Clone, Debug)]
pub enum PlatformArch {
#[cfg(feature = "chip8-raw")]
ChipEightRaw,
#[cfg(feature = "chip8")]
ChipEight,
}
#[derive(Clone, Debug)]
pub enum PlatformTarget {
#[cfg(feature = "rawbin")]
RawBinary,
}
#[derive(Clone, Debug)]
pub struct Platform {
pub arch: PlatformArch,
pub target: PlatformTarget,
}
impl Platform {
pub fn from_platform_info(arch: &str, target: &str) -> Self {
Platform {
arch: match arch.to_lowercase().as_str() {
#[cfg(feature = "chip8-raw")]
"chipeightraw" | "chip8raw" | "c8r" | "chip8r" => PlatformArch::ChipEightRaw,
#[cfg(feature = "chip8")]
"chipeight" | "chip8" | "c8" => PlatformArch::ChipEight,
_ => lpanic("unsupported arch"),
},
target: match target.to_lowercase().as_str() {
#[cfg(feature = "rawbin")]
"bin" | "binary" | "raw" | "rawbin" | "rawbinary" => PlatformTarget::RawBinary,
_ => lpanic("unsupported target"),
},
}
}
pub fn from_platform_double(t: &str) -> Self {
let n: Vec<String> = t.split('-').map(|x| x.to_string()).collect();
Self::from_platform_info(&n[0], &n[1])
}
pub fn get_endianness(&self) -> bool {
match self.arch {
#[cfg(feature = "chip8")]
PlatformArch::ChipEight => false,
#[cfg(feature = "chip8-raw")]
PlatformArch::ChipEightRaw => false,
}
}
}