aboutsummaryrefslogtreecommitdiff
path: root/src/desktop/load_save.rs
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-05-22 00:07:30 +0200
committerAstatin <[email protected]>2025-05-22 00:07:30 +0200
commit4fce95c86e12f91e127605d440118e1b6a64208b (patch)
tree729ff48e04be1c6fef42a45afb17c0d0a2259ec1 /src/desktop/load_save.rs
parent9a8e4117be8d30109229600346e7d9561c52a3e3 (diff)
Save wram,vram,io,hram with X button + move big arrays to Heap
Diffstat (limited to 'src/desktop/load_save.rs')
-rw-r--r--src/desktop/load_save.rs55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/desktop/load_save.rs b/src/desktop/load_save.rs
index dfe2083..5c3a123 100644
--- a/src/desktop/load_save.rs
+++ b/src/desktop/load_save.rs
@@ -1,10 +1,13 @@
+use crate::io::{Audio, LoadSave, Serial};
+use crate::state::GBState;
use std::fs::File;
-use std::io::{Write, Read};
-use crate::io::LoadSave;
+use std::io::{Read, Write};
+#[derive(Debug)]
pub struct FSLoadSave {
rom_file: String,
save_file: String,
+ state_file: Option<String>,
}
impl FSLoadSave {
@@ -12,8 +15,14 @@ impl FSLoadSave {
Self {
rom_file: rom_file.into(),
save_file: save_file.into(),
+ state_file: None,
}
}
+
+ pub fn state_file(mut self, state_file: impl Into<String>) -> Self {
+ self.state_file = Some(state_file.into());
+ self
+ }
}
impl LoadSave for FSLoadSave {
@@ -66,4 +75,46 @@ impl LoadSave for FSLoadSave {
Ok(())
}
+
+ fn save_state<S: Serial, A: Audio>(&self, state: &GBState<S, A>) {
+ if let Some(state_file) = &self.state_file {
+ {
+ let mut vram_dump_file = File::create(format!("{}.vram", state_file)).unwrap();
+
+ for addr in 0x8000..0xa000 {
+ vram_dump_file
+ .write_all(format!("{:02X} ", state.mem.r(addr).unwrap()).as_bytes());
+ }
+ }
+
+ {
+ let mut wram_dump_file = File::create(format!("{}.wram", state_file)).unwrap();
+
+ for addr in 0xc000..0xe000 {
+ wram_dump_file
+ .write_all(format!("{:02X} ", state.mem.r(addr).unwrap()).as_bytes());
+ }
+ }
+
+ {
+ let mut io_dump_file = File::create(format!("{}.io", state_file)).unwrap();
+
+ for addr in 0xff00..0xff80 {
+ io_dump_file
+ .write_all(format!("{:02X} ", state.mem.r(addr).unwrap()).as_bytes());
+ }
+ }
+
+ {
+ let mut hram_dump_file = File::create(format!("{}.hram", state_file)).unwrap();
+
+ for addr in 0xff80..=0xffff {
+ hram_dump_file
+ .write_all(format!("{:02X} ", state.mem.r(addr).unwrap()).as_bytes());
+ }
+ }
+ } else {
+ panic!("{:?}", self)
+ }
+ }
}