From 4fce95c86e12f91e127605d440118e1b6a64208b Mon Sep 17 00:00:00 2001 From: Astatin Date: Thu, 22 May 2025 00:07:30 +0200 Subject: Save wram,vram,io,hram with X button + move big arrays to Heap --- src/desktop/load_save.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'src/desktop/load_save.rs') 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, } 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) -> 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(&self, state: &GBState) { + 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) + } + } } -- cgit v1.2.3-70-g09d2