Adapt android build to new from_saved_sate changes

Former-commit-id: b6b225be3a9dd654c8f375b9f521950fa898969c
Former-commit-id: 3ec1e3134579e4c3204acd14e4e8a37adbc2d686
This commit is contained in:
Michel Heily 2020-10-19 15:26:25 -07:00 committed by MishMish
parent 6b8f4e8f51
commit 4ea8d9ccba
6 changed files with 57 additions and 25 deletions

View file

@ -224,14 +224,24 @@ impl EmulatorContext {
pub fn native_open_saved_state(
env: &JNIEnv,
state: jbyteArray,
bios: jbyteArray,
rom: jbyteArray,
savestate: jbyteArray,
renderer_obj: JObject,
audio_player: JObject,
keypad_obj: JObject,
) -> Result<EmulatorContext, String> {
let state = env
.convert_byte_array(state)
.map_err(|e| format!("could not get state buffer, error {}", e))?;
let bios = env
.convert_byte_array(savestate)
.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)?;
@ -240,13 +250,13 @@ impl EmulatorContext {
audio_producer: None,
key_state: 0xffff,
}));
let gba =
GameBoyAdvance::from_saved_state(&state, hw.clone(), hw.clone()).map_err(|e| {
format!(
"failed to create GameBoyAdvance from saved state, error {:?}",
e
)
})?;
let gba = GameBoyAdvance::from_saved_state(&savestate, bios, rom, hw.clone(), hw.clone())
.map_err(|e| {
format!(
"failed to create GameBoyAdvance from saved savestate, error {:?}",
e
)
})?;
let keypad = Keypad::new(env, keypad_obj);

View file

@ -106,14 +106,18 @@ pub mod bindings {
pub unsafe extern "C" fn Java_com_mrmichel_rustboyadvance_EmulatorBindings_openSavedState(
env: JNIEnv,
_obj: JClass,
state: jbyteArray,
bios: jbyteArray,
rom: jbyteArray,
savestate: jbyteArray,
renderer_obj: JObject,
audio_player_obj: JObject,
keypad_obj: JObject,
) -> jlong {
match EmulatorContext::native_open_saved_state(
&env,
state,
bios,
rom,
savestate,
renderer_obj,
audio_player_obj,
keypad_obj,
@ -287,7 +291,6 @@ pub mod bindings {
_obj: JClass,
ctx: jlong,
) {
let ctx = cast_ctx(ctx);
info!("CPU LOG: {:#x?}", ctx.gba.cpu);
info!("unimplemented")
}
}

View file

@ -1,15 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<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="testRunner" value="PLATFORM" />
</GradleProjectSettings>
</option>
</component>

View file

@ -27,6 +27,8 @@ public class EmulatorBindings {
/**
* 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 renderer renderer instance
* @param audioPlayer audio player instance
@ -34,7 +36,7 @@ public class EmulatorBindings {
* @return
* @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

View file

@ -65,11 +65,11 @@ public class Emulator {
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) {
EmulatorBindings.loadState(this.ctx, state);
} 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);
}
public synchronized void openSavedState(byte[] savedState) throws EmulatorBindings.NativeBindingException {
this.ctx = EmulatorBindings.openSavedState(savedState, this.frameRenderer, this.audioPlayer, this.keypad);
public synchronized void openSavedState(byte[] bios, byte[] rom, byte[] savedState) throws EmulatorBindings.NativeBindingException {
this.ctx = EmulatorBindings.openSavedState(bios, rom, savedState, this.frameRenderer, this.audioPlayer, this.keypad);
}
public synchronized void close() {

View file

@ -289,6 +289,7 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
fis.close();
outState.putString("saveFile", saveFile.getPath());
outState.putInt("romId", this.romMetadata.getId());
outState.putBoolean("turbo", false);
@ -334,6 +335,7 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
if (null != savedInstanceState && (saveFilePath = savedInstanceState.getString("saveFile")) != null) {
final EmulatorActivity thisActivity = this;
int romId = getIntent().getIntExtra("romId", -1);
// busy wait until surface view is ready
try {
@ -353,7 +355,18 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
saveFile.delete();
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();