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

feat: save state support for libretro

parent 55765e41
No related branches found
No related tags found
1 merge request!31System state save
Pipeline #3269 passed
...@@ -16,12 +16,12 @@ systemid = "game_boy" ...@@ -16,12 +16,12 @@ systemid = "game_boy"
# Libretro Features # Libretro Features
supports_no_game = "false" supports_no_game = "false"
database = "Nintendo - Game Boy|Nintendo - Game Boy Color" database = "Nintendo - Game Boy|Nintendo - Game Boy Color"
savestate = "false" savestate = "true"
savestate_features = "null" savestate_features = "serialized"
cheats = "true" cheats = "true"
input_descriptors = "true" input_descriptors = "true"
memory_descriptors = "false" memory_descriptors = "false"
libretro_saves = "false" libretro_saves = "true"
core_options = "true" core_options = "true"
description = "A Game Boy emulator that is written in Rust." description = "A Game Boy emulator that is written in Rust."
...@@ -9,6 +9,7 @@ use boytacean::{ ...@@ -9,6 +9,7 @@ use boytacean::{
pad::PadKey, pad::PadKey,
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,
}; };
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,
...@@ -24,6 +25,7 @@ use std::{ ...@@ -24,6 +25,7 @@ use std::{
ffi::CStr, ffi::CStr,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
os::raw::{c_char, c_float, c_uint, c_void}, os::raw::{c_char, c_float, c_uint, c_void},
ptr,
slice::from_raw_parts, slice::from_raw_parts,
}; };
...@@ -333,6 +335,8 @@ pub extern "C" fn retro_load_game_special( ...@@ -333,6 +335,8 @@ pub extern "C" fn retro_load_game_special(
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_unload_game() { pub extern "C" fn retro_unload_game() {
debugln!("retro_unload_game()"); debugln!("retro_unload_game()");
let instance = unsafe { EMULATOR.as_mut().unwrap() };
instance.reset();
} }
#[no_mangle] #[no_mangle]
...@@ -348,18 +352,28 @@ pub extern "C" fn retro_get_memory_size(_memory_id: u32) -> usize { ...@@ -348,18 +352,28 @@ pub extern "C" fn retro_get_memory_size(_memory_id: u32) -> usize {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_serialize_size() { pub extern "C" fn retro_serialize_size() -> usize {
debugln!("retro_serialize_size()"); debugln!("retro_serialize_size()");
let instance = unsafe { EMULATOR.as_mut().unwrap() };
StateManager::save(instance).unwrap().len()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_serialize() { pub extern "C" fn retro_serialize(data: *mut c_void, size: usize) {
debugln!("retro_serialize()"); debugln!("retro_serialize()");
let instance = unsafe { EMULATOR.as_mut().unwrap() };
let state = StateManager::save(instance).unwrap();
unsafe {
ptr::copy_nonoverlapping(state.as_ptr(), data as *mut u8, size);
}
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn retro_unserialize() { pub extern "C" fn retro_unserialize(data: *const c_void, size: usize) {
debugln!("retro_unserialize()"); debugln!("retro_unserialize()");
let instance = unsafe { EMULATOR.as_mut().unwrap() };
let state = unsafe { from_raw_parts(data as *const u8, size) };
StateManager::load(state, instance).unwrap();
} }
#[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