Support running/profiling ISX files

This commit is contained in:
2025-09-06 01:21:25 -04:00
parent db482b5c21
commit f7f112f7c1
5 changed files with 130 additions and 5 deletions
+11 -4
View File
@@ -7,7 +7,7 @@ use std::{
sync::Arc,
};
use crate::emulator::{SimId, game_info::GameInfo};
use crate::emulator::{SimId, game_info::GameInfo, shrooms_vb_util::rom_from_isx};
pub struct Cart {
pub file_path: PathBuf,
@@ -20,8 +20,9 @@ pub struct Cart {
impl Cart {
pub fn load(file_path: &Path, sim_id: SimId) -> Result<Self> {
let rom = fs::read(file_path)?;
let (rom, info) =
try_parse_elf(file_path, &rom).unwrap_or_else(|| (rom, GameInfo::empty(file_path)));
let (rom, info) = try_parse_isx(file_path, &rom)
.or_else(|| try_parse_elf(file_path, &rom))
.unwrap_or_else(|| (rom, GameInfo::empty(file_path)));
let mut sram_file = File::options()
.read(true)
@@ -60,6 +61,12 @@ impl Cart {
}
}
fn try_parse_isx(file_path: &Path, data: &[u8]) -> Option<(Vec<u8>, GameInfo)> {
let rom = rom_from_isx(data)?;
let info = GameInfo::from_isx(file_path, data);
Some((rom, info))
}
fn try_parse_elf(file_path: &Path, data: &[u8]) -> Option<(Vec<u8>, GameInfo)> {
use object::read::elf::FileHeader;
let program = match object::FileKind::parse(data).ok()? {
@@ -73,7 +80,7 @@ fn try_parse_elf(file_path: &Path, data: &[u8]) -> Option<(Vec<u8>, GameInfo)> {
}
_ => return None,
};
let info = GameInfo::new(file_path, data).unwrap_or_else(|_| GameInfo::empty(file_path));
let info = GameInfo::from_elf(file_path, data).unwrap_or_else(|_| GameInfo::empty(file_path));
Some((program, info))
}