47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use ascii::AsAsciiStr;
|
|
|
|
pub enum GamePlatform {
|
|
GameBoyColor,
|
|
SuperNintendo,
|
|
Genesis
|
|
}
|
|
|
|
pub struct GameInfo {
|
|
pub platform: GamePlatform,
|
|
pub core_name: String,
|
|
pub game_name: String,
|
|
}
|
|
|
|
fn core_to_platform(core_name: &str) -> GamePlatform {
|
|
match core_name.to_lowercase().as_str() {
|
|
"gambatte" => GamePlatform::GameBoyColor,
|
|
"bsnes" => GamePlatform::SuperNintendo,
|
|
"genesis plus gx" => GamePlatform::Genesis,
|
|
"higan (super famicom accuracy)" => GamePlatform::SuperNintendo,
|
|
_ => panic!(format!("unknown core {}", core_name))
|
|
}
|
|
}
|
|
|
|
pub fn get_game_info(core_name: &str, data: &[u8]) -> Result<GameInfo, failure::Error> {
|
|
let platform = core_to_platform(&core_name);
|
|
|
|
let game_name = match &platform {
|
|
GamePlatform::GameBoyColor => data.slice_ascii(0x134..0x143)?.to_string()
|
|
.trim_end_matches("\0").to_string(), // remove nulls at end
|
|
|
|
GamePlatform::SuperNintendo => data.slice_ascii(0x7fc0..0x7fd5)?.to_string()
|
|
.trim_end_matches("\0").to_string(), // remove nulls at end
|
|
|
|
GamePlatform::Genesis => data.slice_ascii(0x120..0x150)?.to_string()
|
|
.split(" ")
|
|
.filter(|w| w.len() > 0)
|
|
.collect::<Vec<&str>>()
|
|
.join(" "), // remove duplicate spaces
|
|
};
|
|
|
|
Ok(GameInfo {
|
|
platform,
|
|
core_name: String::from(core_name),
|
|
game_name,
|
|
})
|
|
} |