romdb fixes

This commit is contained in:
Mateusz Faderewski 2023-03-04 12:44:09 +01:00
parent 6dd64d1db1
commit 35f9ec029e
3 changed files with 19 additions and 17 deletions

View File

@ -180,6 +180,7 @@ impl From<n64::SaveType> for SaveType {
n64::SaveType::Sram => Self::Sram,
n64::SaveType::SramBanked => Self::SramBanked,
n64::SaveType::Flashram => Self::Flashram,
n64::SaveType::Sram128kB => Self::Sram,
}
}
}
@ -263,9 +264,9 @@ fn handle_upload_command(sn: Option<String>, args: &UploadArgs) -> Result<(), sc
let save: SaveType = if let Some(save_type) = args.save_type.clone() {
save_type
} else {
let (save_type, name) = n64::guess_save_type(&mut rom_file)?;
if let Some(name) = name {
println!("Detected ROM name: {name}");
let (save_type, title) = n64::guess_save_type(&mut rom_file)?;
if let Some(title) = title {
println!("ROM title: {title}");
};
save_type.into()
};

View File

@ -7,6 +7,7 @@ pub enum SaveType {
Sram,
SramBanked,
Flashram,
Sram128kB,
}
const HASH_CHUNK_LENGTH: usize = 256 * 1024;
@ -27,7 +28,7 @@ pub fn guess_save_type<T: Read + Seek>(
3 => SaveType::Sram,
4 => SaveType::SramBanked,
5 => SaveType::Flashram,
6 => SaveType::Sram,
6 => SaveType::Sram128kB,
_ => SaveType::None,
},
None,
@ -70,18 +71,15 @@ pub fn guess_save_type<T: Read + Seek>(
let database = ini::Ini::load_from_str(database_ini)
.expect("Error during mupen64plus.ini parse operation");
if let Some(section) = database.section(Some(hash)) {
if let Some(save_type) = section.get("SaveType") {
return Ok((
match save_type {
"Eeprom 4KB" => SaveType::Eeprom4k,
"Eeprom 16KB" => SaveType::Eeprom16k,
"SRAM" => SaveType::Sram,
"Flash RAM" => SaveType::Flashram,
_ => SaveType::None,
},
section.get("GoodName").map(|s| s.to_string()),
));
}
let save_type = section.get("SaveType").map_or(SaveType::None, |t| match t {
"Eeprom 4KB" => SaveType::Eeprom4k,
"Eeprom 16KB" => SaveType::Eeprom16k,
"SRAM" => SaveType::Sram,
"Flash RAM" => SaveType::Flashram,
_ => SaveType::None,
});
let title = section.get("GoodName").map(|s| s.to_string());
return Ok((save_type, title));
}
Ok((SaveType::None, None))

View File

@ -327,8 +327,9 @@ impl SC64 {
}
let mut pi_config = vec![0u8; 4];
reader.read(&mut pi_config)?;
reader.rewind()?;
reader.read(&mut pi_config)?;
let endian_swapper = match &pi_config[0..4] {
[0x37, 0x80, 0x40, 0x12] => {
@ -352,6 +353,8 @@ impl SC64 {
min(length, SDRAM_LENGTH)
};
reader.rewind()?;
self.memory_write_chunked(reader, SDRAM_ADDRESS, sdram_length, Some(endian_swapper))?;
self.command_config_set(Config::RomShadowEnable(rom_shadow_enabled.into()))?;