Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1296 from reicast/lk/safe-dynarec
Browse files Browse the repository at this point in the history
Port the dynarec safe flag from nullDC (See #84)
  • Loading branch information
AbandonedCart committed Aug 18, 2018
2 parents 1bcffb5 + c604ae1 commit a412935
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 749 deletions.
5 changes: 4 additions & 1 deletion core/hw/sh4/dyna/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,10 @@ u32 MatchDiv32(u32 pc , Sh4RegType &reg1,Sh4RegType &reg2 , Sh4RegType &reg3)
break;
}

return match;
if (settings.dynarec.safemode)
return 0;
else
return match;
}
bool MatchDiv32u(u32 op,u32 pc)
{
Expand Down
1 change: 1 addition & 0 deletions core/nullDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void LoadSettings()
settings.dynarec.Enable = cfgLoadInt("config","Dynarec.Enabled", 1)!=0;
settings.dynarec.idleskip = cfgLoadInt("config","Dynarec.idleskip",1)!=0;
settings.dynarec.unstable_opt = cfgLoadInt("config","Dynarec.unstable-opt",0);
settings.dynarec.safemode = cfgLoadInt("config","Dynarec.safemode",0);
//disable_nvmem can't be loaded, because nvmem init is before cfg load
settings.dreamcast.cable = cfgLoadInt("config","Dreamcast.Cable",3);
settings.dreamcast.RTC = cfgLoadInt("config","Dreamcast.RTC",GetRTC_now());
Expand Down
1 change: 1 addition & 0 deletions core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ struct settings_t
bool Enable;
bool idleskip;
bool unstable_opt;
bool safemode;
bool disable_nvmem;
} dynarec;

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Emulator extends Application {
public static final String pref_nativeact = "enable_native";
public static final String pref_dynarecopt = "dynarec_opt";
public static final String pref_unstable = "unstable_opt";
public static final String pref_dynsafemode = "dyn_safemode";
public static final String pref_cable = "dc_cable";
public static final String pref_dcregion = "dc_region";
public static final String pref_broadcast = "dc_broadcast";
Expand All @@ -31,6 +32,7 @@ public class Emulator extends Application {
public static boolean dynarecopt = true;
public static boolean idleskip = true;
public static boolean unstableopt = false;
public static boolean dynsafemode = false;
public static int cable = 3;
public static int dcregion = 3;
public static int broadcast = 4;
Expand All @@ -55,6 +57,7 @@ public class Emulator extends Application {
public void getConfigurationPrefs(SharedPreferences mPrefs) {
Emulator.dynarecopt = mPrefs.getBoolean(pref_dynarecopt, dynarecopt);
Emulator.unstableopt = mPrefs.getBoolean(pref_unstable, unstableopt);
Emulator.dynsafemode = mPrefs.getBoolean(pref_dynsafemode, dynsafemode);
Emulator.cable = mPrefs.getInt(pref_cable, cable);
Emulator.dcregion = mPrefs.getInt(pref_dcregion, dcregion);
Emulator.broadcast = mPrefs.getInt(pref_broadcast, broadcast);
Expand All @@ -79,6 +82,7 @@ public void loadConfigurationPrefs() {
JNIdc.dynarec(Emulator.dynarecopt ? 1 : 0);
JNIdc.idleskip(Emulator.idleskip ? 1 : 0);
JNIdc.unstable(Emulator.unstableopt ? 1 : 0);
JNIdc.safemode(Emulator.dynsafemode ? 1 : 0);
JNIdc.cable(Emulator.cable);
JNIdc.region(Emulator.dcregion);
JNIdc.broadcast(Emulator.broadcast);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
String temp = mPrefs.getString(Config.pref_home, null);
if (temp == null || !new File(temp).isDirectory()) {
showToastMessage(getActivity().getString(R.string.config_home), Snackbar.LENGTH_LONG);
} else {
installButtons();
}
installButtons();
if (!ImgBrowse && !games) {
new LocateGames(R.array.flash).execute(home_directory);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.reicast.emulator.emu.OnScreenMenu.MainPopup;
import com.reicast.emulator.emu.OnScreenMenu.VmuPopup;
import com.reicast.emulator.periph.Gamepad;
import com.reicast.emulator.periph.MOGAInput;
import com.reicast.emulator.periph.SipEmulator;

import java.util.Arrays;
Expand All @@ -42,7 +41,6 @@ public class GL2JNIActivity extends Activity {
public MainPopup popUp;
VmuPopup vmuPop;
FpsPopup fpsPop;
MOGAInput moga = new MOGAInput();
private SharedPreferences prefs;

private Gamepad pad = new Gamepad();
Expand All @@ -63,7 +61,7 @@ protected void onCreate(Bundle icicle) {
app.getConfigurationPrefs(prefs);
menu = new OnScreenMenu(GL2JNIActivity.this, prefs);

pad.isOuyaOrTV = pad.IsOuyaOrTV(GL2JNIActivity.this);
pad.isOuyaOrTV = pad.IsOuyaOrTV(GL2JNIActivity.this, false);
// pad.isNvidiaShield = pad.IsNvidiaShield();

/*
Expand All @@ -76,13 +74,6 @@ protected void onCreate(Bundle icicle) {
* catch (IOException e) { e.getMessage(); e.printStackTrace(); }
*/

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
pad.compat[0] = true;
pad.compat[1] = true;
pad.compat[2] = true;
pad.compat[3] = true;
}

String fileName = null;

// Call parent onCreate()
Expand All @@ -100,9 +91,6 @@ protected void onCreate(Bundle icicle) {
prefs.getString(Gamepad.pref_player4, null), 3);
pad.deviceDescriptor_PlayerNum.remove(null);

moga.onCreate(this, pad);
moga.mListener.setPlayerNum(1);

boolean controllerTwoConnected = false;
boolean controllerThreeConnected = false;
boolean controllerFourConnected = false;
Expand Down Expand Up @@ -173,7 +161,10 @@ protected void onCreate(Bundle icicle) {
} else if (InputDevice.getDevice(joy).getName()
.contains(Gamepad.controllers_shield)) {
pad.map[playerNum] = pad.getConsoleController();
} else if (!pad.isActiveMoga[playerNum]) { // Ouya controller
} else if (InputDevice.getDevice(joy).getName()
.startsWith(Gamepad.controllers_moga)) {
pad.map[playerNum] = pad.getMogaController();
} else { // Ouya controller
pad.map[playerNum] = pad.getOUYAController();
}
} else {
Expand Down Expand Up @@ -232,52 +223,64 @@ public void run() {
}
}

private void processJoystickInput(MotionEvent event, Integer playerNum) {
// Joystick
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
// do other things with joystick
float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);
float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
float R2 = event.getAxisValue(OuyaController.AXIS_R2);

if (!pad.joystick[playerNum]) {
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = LS_X;
pad.globalLS_Y[playerNum] = LS_Y;
}
float getAxisValues(MotionEvent event, int axis, int historyPos) {
return historyPos < 0 ? event.getAxisValue(axis) :
event.getHistoricalAxisValue(axis, historyPos);
}

GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);

GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);

if (prefs.getBoolean(Gamepad.pref_js_rbuttons + pad.portId[playerNum], true)) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]){
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
} else {
if (RS_Y > 0.25) {
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
} else if (RS_Y < 0.25) {
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
}
private void processJoystickInput(MotionEvent event, Integer playerNum, int historyPos) {
float LS_X = getAxisValues(event, MotionEvent.AXIS_X, historyPos);
float LS_Y = getAxisValues(event, MotionEvent.AXIS_Y, historyPos);
float RS_X = getAxisValues(event, MotionEvent.AXIS_RX, historyPos);
float RS_Y = getAxisValues(event, MotionEvent.AXIS_RY, historyPos);
float L2 = getAxisValues(event, MotionEvent.AXIS_LTRIGGER, historyPos);
float R2 = getAxisValues(event, MotionEvent.AXIS_RTRIGGER, historyPos);

if (pad.IsOuyaOrTV(GL2JNIActivity.this, true)) {
LS_X = getAxisValues(event, OuyaController.AXIS_LS_X, historyPos);
LS_Y = getAxisValues(event, OuyaController.AXIS_LS_Y, historyPos);
RS_X = getAxisValues(event, OuyaController.AXIS_RS_X, historyPos);
RS_Y = getAxisValues(event, OuyaController.AXIS_RS_Y, historyPos);
L2 = getAxisValues(event, OuyaController.AXIS_L2, historyPos);
R2 = getAxisValues(event, OuyaController.AXIS_R2, historyPos);
}

if (!pad.joystick[playerNum]) {
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = LS_X;
pad.globalLS_Y[playerNum] = LS_Y;
}

GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);

GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);

if (prefs.getBoolean(Gamepad.pref_js_rbuttons + pad.portId[playerNum], true)) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]){
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
} else {
if (RS_Y > 0.25) {
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
} else if (RS_Y < 0.25) {
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
}
}

mView.pushInput();
}

@Override
Expand All @@ -295,78 +298,21 @@ public boolean onGenericMotionEvent(MotionEvent event) {
return false;

if (!pad.compat[playerNum]) {
final int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
processJoystickInput(event, i);
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) ==
InputDevice.SOURCE_JOYSTICK &&
event.getAction() == MotionEvent.ACTION_MOVE) {
final int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
processJoystickInput(event, playerNum, i);
}
processJoystickInput(event, playerNum, -1);
}
processJoystickInput(event, -1);
}

mView.pushInput();
// Only handle Left Stick on an Xbox 360 controller if there was actual
// motion on the stick, otherwise event can be handled as a DPAD event
return (pad.joystick[playerNum] || (!(pad.globalLS_X[playerNum] == pad.previousLS_X[playerNum])
|| !(pad.globalLS_Y[playerNum] == pad.previousLS_Y[playerNum])))
&& (!(pad.previousLS_X[playerNum] == 0.0f) || !(pad.previousLS_Y[playerNum] == 0.0f));
}

public boolean motionEventHandler(Integer playerNum, com.bda.controller.MotionEvent event) {
if (playerNum == null || playerNum == -1)
return false;

if (!pad.compat[playerNum]) {

// do other things with joystick
float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);
float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
float R2 = event.getAxisValue(OuyaController.AXIS_R2);

if (!pad.joystick[playerNum]) {
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
pad.globalLS_X[playerNum] = LS_X;
pad.globalLS_Y[playerNum] = LS_Y;
}

GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);

GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);

if (prefs.getBoolean(Gamepad.pref_js_rbuttons + pad.portId[playerNum], true)) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]){
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
} else {
if (RS_Y > 0.25) {
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
} else if (RS_Y < 0.25) {
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
}
}

}
mView.pushInput();
// Only handle Left Stick on an Xbox 360 controller if there was
// some actual motion on the stick,
// so otherwise the event can be handled as a DPAD event
return (pad.joystick[playerNum] || (!(pad.globalLS_X[playerNum] == pad.previousLS_X[playerNum])
|| !(pad.globalLS_Y[playerNum] == pad.previousLS_Y[playerNum])))
&& (!(pad.previousLS_X[playerNum] == 0.0f) || !(pad.previousLS_Y[playerNum] == 0.0f));
return (pad.joystick[playerNum] || (pad.globalLS_X[playerNum] != pad.previousLS_X[playerNum]
|| pad.globalLS_Y[playerNum] != pad.previousLS_Y[playerNum]))
&& (pad.previousLS_X[playerNum] != 0.0f || pad.previousLS_Y[playerNum] != 0.0f);
}

public boolean simulatedTouchEvent(int playerNum, float L2, float R2) {
Expand Down Expand Up @@ -566,15 +512,13 @@ protected void onPause() {
super.onPause();
mView.onPause();
JNIdc.pause();
moga.onPause();
}

@Override
protected void onDestroy() {
super.onDestroy();
mView.onDestroy();
JNIdc.destroy();
moga.onDestroy();
}

@Override
Expand All @@ -586,6 +530,5 @@ public void onConfigurationChanged(Configuration newConfig) {
protected void onResume() {
super.onResume();
mView.onResume();
moga.onResume();
}
}
Loading

0 comments on commit a412935

Please sign in to comment.