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

fix: cargo fmt

parent 707da981
No related branches found
No related tags found
1 merge request!31System state save
Pipeline #3278 passed
...@@ -10,6 +10,7 @@ use boytacean::{ ...@@ -10,6 +10,7 @@ use boytacean::{
ppu::{DISPLAY_HEIGHT, DISPLAY_WIDTH, FRAME_BUFFER_SIZE, XRGB8888_SIZE}, ppu::{DISPLAY_HEIGHT, DISPLAY_WIDTH, FRAME_BUFFER_SIZE, XRGB8888_SIZE},
rom::Cartridge, rom::Cartridge,
state::StateManager, state::StateManager,
warnln,
}; };
use consts::{ use consts::{
REGION_NTSC, RETRO_API_VERSION, RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_B, REGION_NTSC, RETRO_API_VERSION, RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_B,
...@@ -36,7 +37,7 @@ struct LibRetroInfo { ...@@ -36,7 +37,7 @@ struct LibRetroInfo {
name: &'static str, name: &'static str,
version: &'static str, version: &'static str,
name_s: String, name_s: String,
version_s: String version_s: String,
} }
static mut EMULATOR: Option<GameBoy> = None; static mut EMULATOR: Option<GameBoy> = None;
...@@ -46,7 +47,7 @@ static mut INFO: LibRetroInfo = LibRetroInfo { ...@@ -46,7 +47,7 @@ static mut INFO: LibRetroInfo = LibRetroInfo {
name: "", name: "",
version: "", version: "",
name_s: String::new(), name_s: String::new(),
version_s: String::new() version_s: String::new(),
}; };
static mut PENDING_CYCLES: u32 = 0_u32; static mut PENDING_CYCLES: u32 = 0_u32;
...@@ -379,21 +380,31 @@ pub extern "C" fn retro_serialize_size() -> usize { ...@@ -379,21 +380,31 @@ pub extern "C" fn retro_serialize_size() -> usize {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_serialize(data: *mut c_void, size: usize) { pub extern "C" fn retro_serialize(data: *mut c_void, size: usize) -> bool {
debugln!("retro_serialize()"); debugln!("retro_serialize()");
let instance = unsafe { EMULATOR.as_mut().unwrap() }; let instance = unsafe { EMULATOR.as_mut().unwrap() };
let state = StateManager::save(instance).unwrap(); let state = StateManager::save(instance).unwrap();
if state.len() > size {
warnln!(
"Invalid state size needed {} bytes, got {} bytes",
state.len(),
size
);
return false;
}
unsafe { unsafe {
ptr::copy_nonoverlapping(state.as_ptr(), data as *mut u8, size); ptr::copy_nonoverlapping(state.as_ptr(), data as *mut u8, state.len());
} }
true
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_unserialize(data: *const c_void, size: usize) { pub extern "C" fn retro_unserialize(data: *const c_void, size: usize) -> bool {
debugln!("retro_unserialize()"); debugln!("retro_unserialize()");
let instance = unsafe { EMULATOR.as_mut().unwrap() }; let instance = unsafe { EMULATOR.as_mut().unwrap() };
let state = unsafe { from_raw_parts(data as *const u8, size) }; let state = unsafe { from_raw_parts(data as *const u8, size) };
StateManager::load(state, instance).unwrap(); StateManager::load(state, instance).unwrap();
true
} }
#[no_mangle] #[no_mangle]
......
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