This commit is contained in:
dgis 2018-12-17 21:24:16 +00:00
parent 66ab6d7ce0
commit a6f599e263
6 changed files with 327 additions and 157 deletions

View file

@ -13,6 +13,7 @@ NOT WORKING
- Serial Ports (Wire or Ir)
TODO
- Permission issues when reopening document after an OS restart
- Change settings per settings
- Support 8bits images
- Put the KML title in the header of the menu in the drawer

View file

@ -106,135 +106,6 @@ int openFileFromContentResolver(const TCHAR * url, int writeAccess) {
return result;
}
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(JNIEnv *env, jobject thisz,
jint settingsRealspeed, jint settingsGrayscale, jint settingsAutosave,
jint settingsAutosaveonexit, jint settingsObjectloadwarning, jint settingsAlwaysdisplog,
jint settingsPort1en, jint settingsPort1wr,
jint settingsPort2len, jint settingsPort2wr, jstring settingsPort2load) {
bRealSpeed = settingsRealspeed;
bAutoSave = settingsAutosave;
bAutoSaveOnExit = settingsAutosaveonexit;
bLoadObjectWarning = settingsObjectloadwarning;
bAlwaysDisplayLog = settingsAlwaysdisplog;
SetSpeed(bRealSpeed); // set speed
// LCD grayscale checkbox has been changed
if (bGrayscale != (BOOL)settingsGrayscale) {
UINT nOldState = SwitchToState(SM_INVALID);
SetLcdMode(!bGrayscale); // set new display mode
SwitchToState(nOldState);
}
//SettingsMemoryProc
LPCTSTR szActPort2Filename = _T("");
BOOL bPort2CfgChange = FALSE;
BOOL bPort2AttChange = FALSE;
// port1
if (Chipset.Port1Size && (cCurrentRomType!='X' || cCurrentRomType!='2' || cCurrentRomType!='Q')) // CdB for HP: add apples
{
UINT nOldState = SwitchToState(SM_SLEEP);
// save old card status
BYTE byCardsStatus = Chipset.cards_status;
// port1 disabled?
Chipset.cards_status &= ~(PORT1_PRESENT | PORT1_WRITE);
if (settingsPort1en)
{
Chipset.cards_status |= PORT1_PRESENT;
if (settingsPort1wr)
Chipset.cards_status |= PORT1_WRITE;
}
// changed card status in slot1?
if ( ((byCardsStatus ^ Chipset.cards_status) & (PORT1_PRESENT | PORT1_WRITE)) != 0
&& (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
)
{
Chipset.HST |= MP; // set Module Pulled
IOBit(SRQ2,NINT,FALSE); // set NINT to low
Chipset.SoftInt = TRUE; // set interrupt
bInterrupt = TRUE;
}
SwitchToState(nOldState);
}
// HP48SX/GX port2 change settings detection
if (cCurrentRomType=='S' || cCurrentRomType=='G' || cCurrentRomType==0)
{
//bPort2IsShared = settingsPort2isshared;
const char * szNewPort2Filename = NULL;
const char *settingsPort2loadUTF8 = NULL;
if(settingsPort2load) {
settingsPort2loadUTF8 = (*env)->GetStringUTFChars(env, settingsPort2load , NULL);
szNewPort2Filename = settingsPort2loadUTF8;
} else
szNewPort2Filename = _T("SHARED.BIN");
if(_tcscmp(szPort2Filename, szNewPort2Filename) != 0) {
_tcscpy(szPort2Filename, szNewPort2Filename);
szActPort2Filename = szPort2Filename;
bPort2CfgChange = TRUE; // slot2 configuration changed
// R/W port
if ( *szActPort2Filename != 0
&& (BOOL) settingsAlwaysdisplog != bPort2Writeable)
{
bPort2AttChange = TRUE; // slot2 file R/W attribute changed
bPort2CfgChange = TRUE; // slot2 configuration changed
}
}
if(settingsPort2loadUTF8)
(*env)->ReleaseStringUTFChars(env, settingsPort2load, settingsPort2loadUTF8);
}
if (bPort2CfgChange) // slot2 configuration changed
{
UINT nOldState = SwitchToState(SM_INVALID);
UnmapPort2(); // unmap port2
// if (bPort2AttChange) // slot2 R/W mode changed
// {
// DWORD dwFileAtt;
//
// SetCurrentDirectory(szEmuDirectory);
// dwFileAtt = GetFileAttributes(szActPort2Filename);
// if (dwFileAtt != 0xFFFFFFFF)
// {
// if (IsDlgButtonChecked(hDlg,IDC_PORT2WR))
// dwFileAtt &= ~FILE_ATTRIBUTE_READONLY;
// else
// dwFileAtt |= FILE_ATTRIBUTE_READONLY;
//
// SetFileAttributes(szActPort2Filename,dwFileAtt);
// }
// SetCurrentDirectory(szCurrentDirectory);
// }
if (cCurrentRomType) // ROM defined
{
MapPort2(szActPort2Filename);
// port2 changed and card detection enabled
if ( (bPort2AttChange || Chipset.wPort2Crc != wPort2Crc)
&& (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
)
{
Chipset.HST |= MP; // set Module Pulled
IOBit(SRQ2,NINT,FALSE); // set NINT to low
Chipset.SoftInt = TRUE; // set interrupt
bInterrupt = TRUE;
}
// save fingerprint of port2
Chipset.wPort2Crc = wPort2Crc;
}
SwitchToState(nOldState);
}
}
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_start(JNIEnv *env, jobject thisz, jobject assetMgr, jobject bitmapMainScreen0, jobject activity, jobject view) {
@ -590,6 +461,276 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onBackupDelete(JNI
OnBackupDelete();
}
//JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(JNIEnv *env, jobject thisz,
// jint settingsRealspeed, jint settingsGrayscale, jint settingsAutosave,
// jint settingsAutosaveonexit, jint settingsObjectloadwarning, jint settingsAlwaysdisplog,
// jint settingsPort1en, jint settingsPort1wr,
// jint settingsPort2len, jint settingsPort2wr, jstring settingsPort2load) {
//
// bRealSpeed = settingsRealspeed;
// bAutoSave = settingsAutosave;
// bAutoSaveOnExit = settingsAutosaveonexit;
// bLoadObjectWarning = settingsObjectloadwarning;
// bAlwaysDisplayLog = settingsAlwaysdisplog;
//
// SetSpeed(bRealSpeed); // set speed
//
// // LCD grayscale checkbox has been changed
// if (bGrayscale != (BOOL)settingsGrayscale) {
// UINT nOldState = SwitchToState(SM_INVALID);
// SetLcdMode(!bGrayscale); // set new display mode
// SwitchToState(nOldState);
// }
//
// //SettingsMemoryProc
// LPCTSTR szActPort2Filename = _T("");
//
// BOOL bPort2CfgChange = FALSE;
// BOOL bPort2AttChange = FALSE;
//
// // port1
// if (Chipset.Port1Size && (cCurrentRomType!='X' || cCurrentRomType!='2' || cCurrentRomType!='Q')) // CdB for HP: add apples
// {
// UINT nOldState = SwitchToState(SM_SLEEP);
// // save old card status
// BYTE byCardsStatus = Chipset.cards_status;
//
// // port1 disabled?
// Chipset.cards_status &= ~(PORT1_PRESENT | PORT1_WRITE);
// if (settingsPort1en)
// {
// Chipset.cards_status |= PORT1_PRESENT;
// if (settingsPort1wr)
// Chipset.cards_status |= PORT1_WRITE;
// }
//
// // changed card status in slot1?
// if ( ((byCardsStatus ^ Chipset.cards_status) & (PORT1_PRESENT | PORT1_WRITE)) != 0
// && (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
// )
// {
// Chipset.HST |= MP; // set Module Pulled
// IOBit(SRQ2,NINT,FALSE); // set NINT to low
// Chipset.SoftInt = TRUE; // set interrupt
// bInterrupt = TRUE;
// }
// SwitchToState(nOldState);
// }
// // HP48SX/GX port2 change settings detection
// if (cCurrentRomType=='S' || cCurrentRomType=='G' || cCurrentRomType==0)
// {
// //bPort2IsShared = settingsPort2isshared;
// const char * szNewPort2Filename = NULL;
// const char *settingsPort2loadUTF8 = NULL;
// if(settingsPort2load) {
// settingsPort2loadUTF8 = (*env)->GetStringUTFChars(env, settingsPort2load , NULL);
// szNewPort2Filename = settingsPort2loadUTF8;
// } else
// szNewPort2Filename = _T("SHARED.BIN");
//
// if(_tcscmp(szPort2Filename, szNewPort2Filename) != 0) {
// _tcscpy(szPort2Filename, szNewPort2Filename);
// szActPort2Filename = szPort2Filename;
// bPort2CfgChange = TRUE; // slot2 configuration changed
//
// // R/W port
// if ( *szActPort2Filename != 0
// && (BOOL) settingsAlwaysdisplog != bPort2Writeable)
// {
// bPort2AttChange = TRUE; // slot2 file R/W attribute changed
// bPort2CfgChange = TRUE; // slot2 configuration changed
// }
// }
// if(settingsPort2loadUTF8)
// (*env)->ReleaseStringUTFChars(env, settingsPort2load, settingsPort2loadUTF8);
// }
//
// if (bPort2CfgChange) // slot2 configuration changed
// {
// UINT nOldState = SwitchToState(SM_INVALID);
//
// UnmapPort2(); // unmap port2
//
//// if (bPort2AttChange) // slot2 R/W mode changed
//// {
//// DWORD dwFileAtt;
////
//// SetCurrentDirectory(szEmuDirectory);
//// dwFileAtt = GetFileAttributes(szActPort2Filename);
//// if (dwFileAtt != 0xFFFFFFFF)
//// {
//// if (IsDlgButtonChecked(hDlg,IDC_PORT2WR))
//// dwFileAtt &= ~FILE_ATTRIBUTE_READONLY;
//// else
//// dwFileAtt |= FILE_ATTRIBUTE_READONLY;
////
//// SetFileAttributes(szActPort2Filename,dwFileAtt);
//// }
//// SetCurrentDirectory(szCurrentDirectory);
//// }
//
// if (cCurrentRomType) // ROM defined
// {
// MapPort2(szActPort2Filename);
//
// // port2 changed and card detection enabled
// if ( (bPort2AttChange || Chipset.wPort2Crc != wPort2Crc)
// && (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
// )
// {
// Chipset.HST |= MP; // set Module Pulled
// IOBit(SRQ2,NINT,FALSE); // set NINT to low
// Chipset.SoftInt = TRUE; // set interrupt
// bInterrupt = TRUE;
// }
// // save fingerprint of port2
// Chipset.wPort2Crc = wPort2Crc;
// }
// SwitchToState(nOldState);
// }
//}
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setConfiguration(JNIEnv *env, jobject thisz, jstring key, jint isDynamic, jint intValue1, jint intValue2, jstring stringValue) {
const char *configKey = (*env)->GetStringUTFChars(env, key, NULL) ;
const char *configStringValue = stringValue ? (*env)->GetStringUTFChars(env, stringValue, NULL) : NULL;
bAutoSave = FALSE; //settingsAutosave;
bAutoSaveOnExit = FALSE; //settingsAutosaveonexit;
bLoadObjectWarning = FALSE; //settingsObjectloadwarning;
if(_tcscmp(_T("settings_realspeed"), configKey) == 0) {
bRealSpeed = intValue1;
if(isDynamic)
SetSpeed(bRealSpeed); // set speed
} else if(_tcscmp(_T("settings_grayscale"), configKey) == 0) {
// LCD grayscale checkbox has been changed
if (bGrayscale != (BOOL)intValue1) {
UINT nOldState = SwitchToState(SM_INVALID);
SetLcdMode(!bGrayscale); // set new display mode
SwitchToState(nOldState);
}
} else if(_tcscmp(_T("settings_alwaysdisplog"), configKey) == 0) {
bAlwaysDisplayLog = intValue1;
} else if(_tcscmp(_T("settings_port1"), configKey) == 0) {
BOOL settingsPort1en = intValue1;
BOOL settingsPort1wr = intValue2;
// port1
if (Chipset.Port1Size && (cCurrentRomType!='X' || cCurrentRomType!='2' || cCurrentRomType!='Q')) // CdB for HP: add apples
{
UINT nOldState = SwitchToState(SM_SLEEP);
// save old card status
BYTE byCardsStatus = Chipset.cards_status;
// port1 disabled?
Chipset.cards_status &= ~(PORT1_PRESENT | PORT1_WRITE);
if (settingsPort1en)
{
Chipset.cards_status |= PORT1_PRESENT;
if (settingsPort1wr)
Chipset.cards_status |= PORT1_WRITE;
}
// changed card status in slot1?
if ( ((byCardsStatus ^ Chipset.cards_status) & (PORT1_PRESENT | PORT1_WRITE)) != 0
&& (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
)
{
Chipset.HST |= MP; // set Module Pulled
IOBit(SRQ2,NINT,FALSE); // set NINT to low
Chipset.SoftInt = TRUE; // set interrupt
bInterrupt = TRUE;
}
SwitchToState(nOldState);
}
} else if(_tcscmp(_T("settings_port2"), configKey) == 0) {
BOOL settingsPort2en = (BOOL)intValue1;
BOOL settingsPort2wr = (BOOL)intValue2;
const char * settingsPort2load = settingsPort2en ? configStringValue : NULL;
LPCTSTR szActPort2Filename = _T("");
BOOL bPort2CfgChange = FALSE;
BOOL bPort2AttChange = FALSE;
// HP48SX/GX port2 change settings detection
if (cCurrentRomType=='S' || cCurrentRomType=='G' || cCurrentRomType==0)
{
//bPort2IsShared = settingsPort2isshared;
const char * szNewPort2Filename = NULL;
if(settingsPort2load) {
szNewPort2Filename = settingsPort2load;
}
// else
// szNewPort2Filename = _T("SHARED.BIN");
if(szNewPort2Filename && _tcscmp(szPort2Filename, szNewPort2Filename) != 0) {
_tcscpy(szPort2Filename, szNewPort2Filename);
szActPort2Filename = szPort2Filename;
bPort2CfgChange = TRUE; // slot2 configuration changed
// R/W port
if (*szActPort2Filename != 0 && (BOOL)settingsPort2wr != bPort2Writeable)
{
bPort2AttChange = TRUE; // slot2 file R/W attribute changed
bPort2CfgChange = TRUE; // slot2 configuration changed
}
}
}
if (bPort2CfgChange) // slot2 configuration changed
{
UINT nOldState = SwitchToState(SM_INVALID);
UnmapPort2(); // unmap port2
// if (bPort2AttChange) // slot2 R/W mode changed
// {
// DWORD dwFileAtt;
//
// SetCurrentDirectory(szEmuDirectory);
// dwFileAtt = GetFileAttributes(szActPort2Filename);
// if (dwFileAtt != 0xFFFFFFFF)
// {
// if (IsDlgButtonChecked(hDlg,IDC_PORT2WR))
// dwFileAtt &= ~FILE_ATTRIBUTE_READONLY;
// else
// dwFileAtt |= FILE_ATTRIBUTE_READONLY;
//
// SetFileAttributes(szActPort2Filename,dwFileAtt);
// }
// SetCurrentDirectory(szCurrentDirectory);
// }
if (cCurrentRomType) // ROM defined
{
MapPort2(szActPort2Filename);
// port2 changed and card detection enabled
if ( (bPort2AttChange || Chipset.wPort2Crc != wPort2Crc)
&& (Chipset.IORam[CARDCTL] & ECDT) != 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0
)
{
Chipset.HST |= MP; // set Module Pulled
IOBit(SRQ2,NINT,FALSE); // set NINT to low
Chipset.SoftInt = TRUE; // set interrupt
bInterrupt = TRUE;
}
// save fingerprint of port2
Chipset.wPort2Crc = wPort2Crc;
}
SwitchToState(nOldState);
}
}
if(configKey)
(*env)->ReleaseStringUTFChars(env, key, configKey);
if(configStringValue)
(*env)->ReleaseStringUTFChars(env, stringValue, configStringValue);
}
JNIEXPORT jint JNICALL Java_com_regis_cosnier_emu48_NativeLib_getIsPortExtensionPossible(JNIEnv *env, jobject thisz) {
return (cCurrentRomType=='S' || cCurrentRomType=='G' || cCurrentRomType==0);
}
//p Read5(0x7050E)
// -> $1 = 461076
//p Read5(0x70914)

View file

@ -7,6 +7,7 @@
#include <android/bitmap.h>
#include "core/resource.h"
#include "win32-layer.h"
#include "core/Emu48.h"
extern JavaVM *java_machine;
extern jobject bitmapMainScreen;
@ -64,6 +65,11 @@ BOOL SetCurrentDirectory(LPCTSTR path)
HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPVOID lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, LPVOID hTemplateFile)
{
if(_tcscmp(lpFileName, szPort2Filename) == 0) {
// Special case for Port2 filename
//TODO
}
if(szCurrentDirectorySet || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength / sizeof(TCHAR)) == 0) {
TCHAR szFileName[MAX_PATH];
AAsset * asset = NULL;

View file

@ -102,11 +102,11 @@ public class MainActivity extends AppCompatActivity
mainScreenContainer.addView(mainScreenView, 0);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
updateFromPreferences();
updateFromPreferences(null, false);
sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updateFromPreferences();
updateFromPreferences(key, true);
}
};
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
@ -549,27 +549,45 @@ public class MainActivity extends AppCompatActivity
return fd;
}
private void updateFromPreferences() {
//int settingsInput = Integer.parseInt(sharedPreferences.getString("settings_input", "0"));
boolean settingsRealspeed = sharedPreferences.getBoolean("settings_realspeed", false);
boolean settingsGrayscale = sharedPreferences.getBoolean("settings_grayscale", false);
// boolean settingsAlwaysontopt = sharedPreferences.getBoolean("settings_alwaysontop", false);
// boolean settingsActfollowsmouset = sharedPreferences.getBoolean("settings_actfollowsmouse", false);
// boolean settingsSingleinstancet = sharedPreferences.getBoolean("settings_singleinstance", false);
boolean settingsAutosave = sharedPreferences.getBoolean("settings_autosave", false);
boolean settingsAutosaveonexit = sharedPreferences.getBoolean("settings_autosaveonexit", false);
boolean settingsObjectloadwarning = sharedPreferences.getBoolean("settings_objectloadwarning", false);
boolean settingsAlwaysdisplog = sharedPreferences.getBoolean("settings_alwaysdisplog", true);
boolean settingsPort1en = sharedPreferences.getBoolean("settings_port1en", false);
boolean settingsPort1wr = sharedPreferences.getBoolean("settings_port1wr", false);
boolean settingsPort2en = sharedPreferences.getBoolean("settings_port2en", false);
boolean settingsPort2wr = sharedPreferences.getBoolean("settings_port2wr", false);
String settingsPort2load = sharedPreferences.getString("settings_port2load", "");
NativeLib.setConfiguration(settingsRealspeed ? 1 : 0, settingsGrayscale ? 1 : 0, settingsAutosave ? 1 : 0,
settingsAutosaveonexit ? 1 : 0, settingsObjectloadwarning ? 1 : 0, settingsAlwaysdisplog ? 1 : 0,
settingsPort1en ? 1 : 0, settingsPort1wr ? 1 : 0,
settingsPort2en ? 1 : 0, settingsPort2wr ? 1 : 0, settingsPort2load);
private void updateFromPreferences(String key, boolean isDynamic) {
int isDynamicValue = isDynamic ? 1 : 0;
if(key == null) {
// boolean settingsAutosave = sharedPreferences.getBoolean("settings_autosave", false);
// boolean settingsAutosaveonexit = sharedPreferences.getBoolean("settings_autosaveonexit", false);
// boolean settingsObjectloadwarning = sharedPreferences.getBoolean("settings_objectloadwarning", false);
String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_alwaysdisplog", "settings_port1", "settings_port2" };
for (String settingKey : settingKeys) {
updateFromPreferences(settingKey, false);
}
} else {
switch (key) {
case "settings_realspeed":
NativeLib.setConfiguration(key, isDynamicValue, sharedPreferences.getBoolean(key, false) ? 1 : 0, 0, null);
break;
case "settings_grayscale":
NativeLib.setConfiguration(key, isDynamicValue, sharedPreferences.getBoolean(key, false) ? 1 : 0, 0, null);
break;
case "settings_alwaysdisplog":
NativeLib.setConfiguration(key, isDynamicValue, sharedPreferences.getBoolean(key, true) ? 1 : 0, 0, null);
break;
case "settings_port1":
case "settings_port1en":
case "settings_port1wr":
NativeLib.setConfiguration("settings_port1", isDynamicValue,
sharedPreferences.getBoolean("settings_port1en", false) ? 1 : 0,
sharedPreferences.getBoolean("settings_port1wr", false) ? 1 : 0,
null);
break;
case "settings_port2":
case "settings_port2en":
case "settings_port2wr":
case "settings_port2load":
NativeLib.setConfiguration("settings_port2", isDynamicValue,
sharedPreferences.getBoolean("settings_port2en", false) ? 1 : 0,
sharedPreferences.getBoolean("settings_port2wr", false) ? 1 : 0,
sharedPreferences.getString("settings_port2load", ""));
break;
}
}
}
}

View file

@ -41,8 +41,6 @@ public class NativeLib {
public static native void onBackupRestore();
public static native void onBackupDelete();
public static native void setConfiguration(int settingsRealspeed, int settingsGrayscale, int settingsAutosave,
int settingsAutosaveonexit, int settingsObjectloadwarning, int settingsAlwaysdisplog,
int settingsPort1en, int settingsPort1wr,
int settingsPort2en, int settingsPort2wr, String settingsPort2load);
public static native void setConfiguration(String key, int isDynamic, int intValue1, int intValue2, String stringValue);
public static native int getIsPortExtensionPossible();
}

View file

@ -217,6 +217,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
bindPreferenceSummaryToBoolValue(findPreference("settings_port2en"));
bindPreferenceSummaryToBoolValue(findPreference("settings_port2wr"));
boolean disablePortPreferences = (NativeLib.getIsPortExtensionPossible() == 0);
//TODO not working
findPreference("settings_port1en").setShouldDisableView(disablePortPreferences);
findPreference("settings_port1wr").setShouldDisableView(disablePortPreferences);
findPreference("settings_port2en").setShouldDisableView(disablePortPreferences);
findPreference("settings_port2wr").setShouldDisableView(disablePortPreferences);
}
@Override