Fix "watch rom" feature not actually reloading
This commit is contained in:
parent
5d86ceddd7
commit
9824e8f475
|
|
@ -265,7 +265,8 @@ impl Emulator {
|
|||
} else if let Some(cart) = self.carts[index].as_mut()
|
||||
&& cart.is_watching()
|
||||
{
|
||||
cart.restart_watching();
|
||||
cart.reload()?;
|
||||
sim.load_cart(cart.rom.clone(), cart.sram.clone())?;
|
||||
}
|
||||
let mut profiling = false;
|
||||
if let Some(profiler) = self.profilers[sim_id.to_index()].as_ref()
|
||||
|
|
|
|||
|
|
@ -22,10 +22,7 @@ pub struct Cart {
|
|||
|
||||
impl Cart {
|
||||
pub fn load(file_path: &Path, sim_id: SimId, watch: bool) -> Result<Self> {
|
||||
let rom = fs::read(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 (rom, info) = Self::read_rom(file_path)?;
|
||||
|
||||
let mut sram_file = File::options()
|
||||
.read(true)
|
||||
|
|
@ -66,6 +63,16 @@ impl Cart {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn reload(&mut self) -> Result<()> {
|
||||
let (rom, info) = Self::read_rom(&self.file_path)?;
|
||||
self.rom = rom;
|
||||
self.info = Arc::new(info);
|
||||
if self.is_watching() {
|
||||
self.restart_watching();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save_sram(&mut self) -> Result<()> {
|
||||
self.sram_file.seek(SeekFrom::Start(0))?;
|
||||
self.sram_file.write_all(&self.sram)?;
|
||||
|
|
@ -92,6 +99,14 @@ impl Cart {
|
|||
self.changed = Arc::new(AtomicBool::new(false));
|
||||
self.watcher = None;
|
||||
}
|
||||
|
||||
fn read_rom(file_path: &Path) -> Result<(Vec<u8>, GameInfo)> {
|
||||
let rom = fs::read(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)));
|
||||
Ok((rom, info))
|
||||
}
|
||||
}
|
||||
|
||||
fn build_watcher(file_path: &Path, changed: Arc<AtomicBool>) -> Option<notify::RecommendedWatcher> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue