Adapt android build to new from_saved_sate changes
Former-commit-id: b6b225be3a9dd654c8f375b9f521950fa898969c Former-commit-id: 3ec1e3134579e4c3204acd14e4e8a37adbc2d686
This commit is contained in:
parent
6b8f4e8f51
commit
4ea8d9ccba
|
@ -224,14 +224,24 @@ impl EmulatorContext {
|
||||||
|
|
||||||
pub fn native_open_saved_state(
|
pub fn native_open_saved_state(
|
||||||
env: &JNIEnv,
|
env: &JNIEnv,
|
||||||
state: jbyteArray,
|
bios: jbyteArray,
|
||||||
|
rom: jbyteArray,
|
||||||
|
savestate: jbyteArray,
|
||||||
renderer_obj: JObject,
|
renderer_obj: JObject,
|
||||||
audio_player: JObject,
|
audio_player: JObject,
|
||||||
keypad_obj: JObject,
|
keypad_obj: JObject,
|
||||||
) -> Result<EmulatorContext, String> {
|
) -> Result<EmulatorContext, String> {
|
||||||
let state = env
|
let bios = env
|
||||||
.convert_byte_array(state)
|
.convert_byte_array(savestate)
|
||||||
.map_err(|e| format!("could not get state buffer, error {}", e))?;
|
.map_err(|e| format!("could not get bios buffer, error {}", e))?
|
||||||
|
.into_boxed_slice();
|
||||||
|
let rom = env
|
||||||
|
.convert_byte_array(savestate)
|
||||||
|
.map_err(|e| format!("could not get rom buffer, error {}", e))?
|
||||||
|
.into_boxed_slice();
|
||||||
|
let savestate = env
|
||||||
|
.convert_byte_array(savestate)
|
||||||
|
.map_err(|e| format!("could not get savestate buffer, error {}", e))?;
|
||||||
|
|
||||||
let renderer = Renderer::new(env, renderer_obj)?;
|
let renderer = Renderer::new(env, renderer_obj)?;
|
||||||
|
|
||||||
|
@ -240,13 +250,13 @@ impl EmulatorContext {
|
||||||
audio_producer: None,
|
audio_producer: None,
|
||||||
key_state: 0xffff,
|
key_state: 0xffff,
|
||||||
}));
|
}));
|
||||||
let gba =
|
let gba = GameBoyAdvance::from_saved_state(&savestate, bios, rom, hw.clone(), hw.clone())
|
||||||
GameBoyAdvance::from_saved_state(&state, hw.clone(), hw.clone()).map_err(|e| {
|
.map_err(|e| {
|
||||||
format!(
|
format!(
|
||||||
"failed to create GameBoyAdvance from saved state, error {:?}",
|
"failed to create GameBoyAdvance from saved savestate, error {:?}",
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let keypad = Keypad::new(env, keypad_obj);
|
let keypad = Keypad::new(env, keypad_obj);
|
||||||
|
|
||||||
|
|
|
@ -106,14 +106,18 @@ pub mod bindings {
|
||||||
pub unsafe extern "C" fn Java_com_mrmichel_rustboyadvance_EmulatorBindings_openSavedState(
|
pub unsafe extern "C" fn Java_com_mrmichel_rustboyadvance_EmulatorBindings_openSavedState(
|
||||||
env: JNIEnv,
|
env: JNIEnv,
|
||||||
_obj: JClass,
|
_obj: JClass,
|
||||||
state: jbyteArray,
|
bios: jbyteArray,
|
||||||
|
rom: jbyteArray,
|
||||||
|
savestate: jbyteArray,
|
||||||
renderer_obj: JObject,
|
renderer_obj: JObject,
|
||||||
audio_player_obj: JObject,
|
audio_player_obj: JObject,
|
||||||
keypad_obj: JObject,
|
keypad_obj: JObject,
|
||||||
) -> jlong {
|
) -> jlong {
|
||||||
match EmulatorContext::native_open_saved_state(
|
match EmulatorContext::native_open_saved_state(
|
||||||
&env,
|
&env,
|
||||||
state,
|
bios,
|
||||||
|
rom,
|
||||||
|
savestate,
|
||||||
renderer_obj,
|
renderer_obj,
|
||||||
audio_player_obj,
|
audio_player_obj,
|
||||||
keypad_obj,
|
keypad_obj,
|
||||||
|
@ -287,7 +291,6 @@ pub mod bindings {
|
||||||
_obj: JClass,
|
_obj: JClass,
|
||||||
ctx: jlong,
|
ctx: jlong,
|
||||||
) {
|
) {
|
||||||
let ctx = cast_ctx(ctx);
|
info!("unimplemented")
|
||||||
info!("CPU LOG: {:#x?}", ctx.gba.cpu);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<compositeConfiguration>
|
<option name="testRunner" value="PLATFORM" />
|
||||||
<compositeBuild compositeDefinitionSource="SCRIPT" />
|
|
||||||
</compositeConfiguration>
|
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
<option name="testRunner" value="PLATFORM" />
|
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -27,6 +27,8 @@ public class EmulatorBindings {
|
||||||
/**
|
/**
|
||||||
* Open a new emulator context from a saved state buffer
|
* Open a new emulator context from a saved state buffer
|
||||||
*
|
*
|
||||||
|
* @param bios bytearray of the GBA bios
|
||||||
|
* @param rom bytearray of the rom to run
|
||||||
* @param savedState saved state buffer
|
* @param savedState saved state buffer
|
||||||
* @param renderer renderer instance
|
* @param renderer renderer instance
|
||||||
* @param audioPlayer audio player instance
|
* @param audioPlayer audio player instance
|
||||||
|
@ -34,7 +36,7 @@ public class EmulatorBindings {
|
||||||
* @return
|
* @return
|
||||||
* @throws NativeBindingException
|
* @throws NativeBindingException
|
||||||
*/
|
*/
|
||||||
public static native long openSavedState(byte[] savedState, IFrameRenderer renderer, IAudioPlayer audioPlayer, Keypad keypad) throws NativeBindingException;
|
public static native long openSavedState(byte[] bios, byte[] rom, byte[] savedState, IFrameRenderer renderer, IAudioPlayer audioPlayer, Keypad keypad) throws NativeBindingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys the emulator instance
|
* Destroys the emulator instance
|
||||||
|
|
|
@ -65,11 +65,11 @@ public class Emulator {
|
||||||
return EmulatorBindings.saveState(this.ctx);
|
return EmulatorBindings.saveState(this.ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void loadState(byte[] state) throws EmulatorBindings.NativeBindingException {
|
public synchronized void loadState(byte[] state) throws EmulatorBindings.NativeBindingException, EmulatorException {
|
||||||
if (ctx != -1) {
|
if (ctx != -1) {
|
||||||
EmulatorBindings.loadState(this.ctx, state);
|
EmulatorBindings.loadState(this.ctx, state);
|
||||||
} else {
|
} else {
|
||||||
openSavedState(state);
|
throw new EmulatorException("Call open() first");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ public class Emulator {
|
||||||
this.ctx = EmulatorBindings.openEmulator(bios, rom, this.frameRenderer, this.audioPlayer, this.keypad, saveName, skipBios);
|
this.ctx = EmulatorBindings.openEmulator(bios, rom, this.frameRenderer, this.audioPlayer, this.keypad, saveName, skipBios);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void openSavedState(byte[] savedState) throws EmulatorBindings.NativeBindingException {
|
public synchronized void openSavedState(byte[] bios, byte[] rom, byte[] savedState) throws EmulatorBindings.NativeBindingException {
|
||||||
this.ctx = EmulatorBindings.openSavedState(savedState, this.frameRenderer, this.audioPlayer, this.keypad);
|
this.ctx = EmulatorBindings.openSavedState(bios, rom, savedState, this.frameRenderer, this.audioPlayer, this.keypad);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
|
|
|
@ -289,6 +289,7 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
fis.close();
|
fis.close();
|
||||||
|
|
||||||
outState.putString("saveFile", saveFile.getPath());
|
outState.putString("saveFile", saveFile.getPath());
|
||||||
|
outState.putInt("romId", this.romMetadata.getId());
|
||||||
|
|
||||||
outState.putBoolean("turbo", false);
|
outState.putBoolean("turbo", false);
|
||||||
|
|
||||||
|
@ -334,6 +335,7 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
|
|
||||||
if (null != savedInstanceState && (saveFilePath = savedInstanceState.getString("saveFile")) != null) {
|
if (null != savedInstanceState && (saveFilePath = savedInstanceState.getString("saveFile")) != null) {
|
||||||
final EmulatorActivity thisActivity = this;
|
final EmulatorActivity thisActivity = this;
|
||||||
|
int romId = getIntent().getIntExtra("romId", -1);
|
||||||
|
|
||||||
// busy wait until surface view is ready
|
// busy wait until surface view is ready
|
||||||
try {
|
try {
|
||||||
|
@ -353,7 +355,18 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
saveFile.delete();
|
saveFile.delete();
|
||||||
|
|
||||||
byte[] savedState = outputStream.toByteArray();
|
byte[] savedState = outputStream.toByteArray();
|
||||||
emulator.openSavedState(savedState);
|
RomManager romManager = RomManager.getInstance(this);
|
||||||
|
romManager.updateLastPlayed(romId);
|
||||||
|
this.romMetadata = romManager.getRomMetadata(romId);
|
||||||
|
|
||||||
|
byte[] romData;
|
||||||
|
try {
|
||||||
|
romData = Util.readFile(romMetadata.getRomFile());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.showAlertDialogAndExit(this, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emulator.openSavedState(this.bios, romData, savedState);
|
||||||
|
|
||||||
createThreads();
|
createThreads();
|
||||||
|
|
||||||
|
|
Reference in a new issue