Skip to content
Snippets Groups Projects
Verified Commit 0c93aa69 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

fix: issue with the boot flag register

The wrong value was being store in 0xFF50.
parent 789a68c5
No related branches found
No related tags found
1 merge request!31System state save
Pipeline #3255 passed
...@@ -327,7 +327,13 @@ impl Mmu { ...@@ -327,7 +327,13 @@ impl Mmu {
0x4d => (false as u8) | ((self.speed as u8) << 7), 0x4d => (false as u8) | ((self.speed as u8) << 7),
// 0xFF50 - Boot active flag // 0xFF50 - Boot active flag
0x50 => u8::from(self.boot_active), 0x50 => {
if self.boot_active {
0x00
} else {
0xff
}
}
// 0xFF70 - SVBK: WRAM bank (CGB only) // 0xFF70 - SVBK: WRAM bank (CGB only)
0x70 => self.ram_bank & 0x07, 0x70 => self.ram_bank & 0x07,
...@@ -430,7 +436,7 @@ impl Mmu { ...@@ -430,7 +436,7 @@ impl Mmu {
} }
// 0xFF50 - Boot active flag // 0xFF50 - Boot active flag
0x50 => self.boot_active = false, 0x50 => self.boot_active = value == 0x00,
// 0xFF70 - SVBK: WRAM bank (CGB only) // 0xFF70 - SVBK: WRAM bank (CGB only)
0x70 => { 0x70 => {
......
...@@ -610,7 +610,12 @@ impl BeesCore { ...@@ -610,7 +610,12 @@ impl BeesCore {
buffer[1] = b' '; buffer[1] = b' ';
} }
buffer[2] = b' '; if gb.is_dmg() {
buffer[2] = b'0';
} else {
buffer[2] = b' ';
}
buffer[3] = b' '; buffer[3] = b' ';
String::from_utf8(Vec::from(buffer)).unwrap() String::from_utf8(Vec::from(buffer)).unwrap()
...@@ -877,20 +882,27 @@ impl Default for BeesMbc { ...@@ -877,20 +882,27 @@ impl Default for BeesMbc {
} }
} }
pub fn save_state_file(file_path: &str, gb: &mut GameBoy) { pub fn save_state_file(file_path: &str, gb: &mut GameBoy) -> Result<(), String> {
let mut file = File::create(file_path).unwrap(); let mut file = match File::create(file_path) {
let data = save_state(gb); Ok(file) => file,
Err(_) => return Err(format!("Failed to open file: {}", file_path)),
};
let data = save_state(gb)?;
file.write_all(&data).unwrap(); file.write_all(&data).unwrap();
Ok(())
} }
pub fn save_state(gb: &mut GameBoy) -> Vec<u8> { pub fn save_state(gb: &mut GameBoy) -> Result<Vec<u8>, String> {
let mut data: Vec<u8> = vec![]; let mut data: Vec<u8> = vec![];
BeesState::from_gb(gb).save(&mut data); BeesState::from_gb(gb).save(&mut data);
data Ok(data)
} }
pub fn load_state_file(file_path: &str, gb: &mut GameBoy) -> Result<(), String> { pub fn load_state_file(file_path: &str, gb: &mut GameBoy) -> Result<(), String> {
let mut file = File::open(file_path).unwrap(); let mut file = match File::open(file_path) {
Ok(file) => file,
Err(_) => return Err(format!("Failed to open file: {}", file_path)),
};
let mut data = vec![]; let mut data = vec![];
file.read_to_end(&mut data).unwrap(); file.read_to_end(&mut data).unwrap();
load_state(&data, gb)?; load_state(&data, gb)?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment