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

chore: support for BOSC in web

Created automatic inference of format from magic number.
Extracts BOS data from BOSC files to be used in web.
parent 26bb306d
No related branches found
No related tags found
1 merge request!53Support for BOSC (Boytacean Save Compressed) format
Pipeline #4776 passed
......@@ -720,7 +720,7 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
serializeState(): Uint8Array {
if (!this.gameBoy) throw new Error("Unable to serialize state");
return StateManager.save_wa(this.gameBoy, SaveStateFormat.Bos);
return StateManager.save_wa(this.gameBoy);
}
unserializeState(data: Uint8Array) {
......@@ -729,7 +729,7 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
}
buildState(index: number, data: Uint8Array): SaveState {
const state = StateManager.read_bos_wa(data);
const state = StateManager.read_bos_auto_wa(data);
return {
index: index,
timestamp: Number(state.timestamp_wa()),
......
......@@ -1669,6 +1669,36 @@ impl StateManager {
Ok(())
}
pub fn read_bos_auto(data: &[u8]) -> Result<BosState, Error> {
let data = &mut Cursor::new(data.to_vec());
let format = if BoscState::is_bosc(data) {
SaveStateFormat::Bosc
} else if BosState::is_bos(data) {
SaveStateFormat::Bos
} else if BessState::is_bess(data) {
return Err(Error::CustomError(String::from(
"Incompatible save state file format (BESS)",
)));
} else {
return Err(Error::CustomError(String::from(
"Unknown save state file format",
)));
};
match format {
SaveStateFormat::Bosc => {
let mut state = BoscState::default();
state.read(data);
Ok(state.bos)
}
SaveStateFormat::Bos => {
let mut state = BosState::default();
state.read(data);
Ok(state)
}
_ => unreachable!(),
}
}
pub fn read_bosc(data: &[u8]) -> Result<BoscState, Error> {
let data = &mut Cursor::new(data.to_vec());
let mut state = BoscState::default();
......@@ -1743,6 +1773,10 @@ impl StateManager {
Self::load(data, gb, format).map_err(|e| e.to_string())
}
pub fn read_bos_auto_wa(data: &[u8]) -> Result<BosState, String> {
Self::read_bos_auto(data).map_err(|e| e.to_string())
}
pub fn read_bosc_wa(data: &[u8]) -> Result<BoscState, String> {
Self::read_bosc(data).map_err(|e| e.to_string())
}
......
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