fix saves

This commit is contained in:
Alex Janka 2023-03-02 18:30:44 +11:00
parent e3330a4df7
commit e0979f5049

View file

@ -1,7 +1,7 @@
use crate::processor::memory::Address; use crate::processor::memory::Address;
use std::{ use std::{
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::{Read, Write}, io::{Read, Seek, SeekFrom, Write},
path::PathBuf, path::PathBuf,
str::from_utf8_unchecked, str::from_utf8_unchecked,
}; };
@ -36,11 +36,13 @@ impl MaybeBufferedSram {
.create_new(true) .create_new(true)
.open(path) .open(path)
.unwrap(); .unwrap();
writer.set_len(length as u64).unwrap();
Some(writer) Some(writer)
} }
} else { } else {
None None
}; };
Self { Self {
buf, buf,
inner, inner,
@ -66,6 +68,7 @@ impl MaybeBufferedSram {
fn flush(&mut self) { fn flush(&mut self) {
if let Some(ref mut writer) = self.inner { if let Some(ref mut writer) = self.inner {
writer.seek(SeekFrom::Start(0)).unwrap();
writer.write_all(&self.buf).unwrap(); writer.write_all(&self.buf).unwrap();
} }
} }