diff --git a/app/build.gradle b/app/build.gradle index 7ccb2de..58938d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ android { compileSdkVersion 28 defaultConfig { applicationId "com.regis.cosnier.emu48" - minSdkVersion 21 + minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/app/src/main/cpp/emu48-jni.c b/app/src/main/cpp/emu48-jni.c index 4a3b86d..1f0be04 100644 --- a/app/src/main/cpp/emu48-jni.c +++ b/app/src/main/cpp/emu48-jni.c @@ -8,6 +8,7 @@ #include #include "core/pch.h" +#include "core/Emu48.h" extern void emu48Start(); extern AAssetManager * assetManager; @@ -23,16 +24,16 @@ extern void buttonUp(int x, int y); extern void keyDown(int virtKey); extern void keyUp(int virtKey); -extern void OnFileNew(); -extern void OnFileOpen(); -extern void OnFileSave(); -extern void OnFileSaveAs(); -extern void OnFileClose(); +//extern void OnFileNew(); +//extern void OnFileOpen(); +//extern void OnFileSave(); +//extern void OnFileSaveAs(); +//extern void OnFileClose(); extern void OnObjectLoad(); extern void OnObjectSave(); extern void OnViewCopy(); -extern void OnStackCopy(); -extern void OnStackPaste(); +//extern void OnStackCopy(); +//extern void OnStackPaste(); extern void OnViewReset(); extern void OnBackupSave(); extern void OnBackupRestore(); @@ -204,21 +205,89 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_keyUp(JNIEnv *env, keyUp(virtKey); } -JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileNew(JNIEnv *env, jobject thisz) { - OnFileNew(); + + +JNIEXPORT jstring JNICALL Java_com_regis_cosnier_emu48_NativeLib_getCurrentFilename(JNIEnv *env, jobject thisz) { + jstring result = (*env)->NewStringUTF(env, szBufferFilename); + return result; } -JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileOpen(JNIEnv *env, jobject thisz) { - OnFileOpen(); +//JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setCurrentFilename(JNIEnv *env, jobject thisz, jstring newFilename) { +// const char *newFilenameUTF8 = (*env)->GetStringUTFChars(env, newFilename , NULL) ; +// _tcscpy(szBufferFilename, newFilenameUTF8); +// (*env)->ReleaseStringUTFChars(env, newFilename, newFilenameUTF8); +//} + + + +JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileNew(JNIEnv *env, jobject thisz) { + //OnFileNew(); + if (bDocumentAvail) + { + SwitchToState(SM_INVALID); + if(bAutoSave) { + SaveDocument(); + } + } + if (NewDocument()) SetWindowTitle(_T("Untitled")); + + if (pbyRom) SwitchToState(SM_RUN); +} +JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileOpen(JNIEnv *env, jobject thisz, jstring filename) { + //OnFileOpen(); + if (bDocumentAvail) + { + SwitchToState(SM_INVALID); + if(bAutoSave) { + SaveDocument(); + } + } + const char *filenameUTF8 = (*env)->GetStringUTFChars(env, filename , NULL) ; + _tcscpy(szBufferFilename, filenameUTF8); + if (OpenDocument(szBufferFilename)) + MruAdd(szBufferFilename); + (*env)->ReleaseStringUTFChars(env, filename, filenameUTF8); + + if (pbyRom) SwitchToState(SM_RUN); } JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileSave(JNIEnv *env, jobject thisz) { - OnFileSave(); + // szBufferFilename must be set before calling that!!! + //OnFileSave(); + if (bDocumentAvail) + { + SwitchToState(SM_INVALID); + SaveDocument(); + SwitchToState(SM_RUN); + } + } -JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileSaveAs(JNIEnv *env, jobject thisz) { - OnFileSaveAs(); +JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileSaveAs(JNIEnv *env, jobject thisz, jstring newFilename) { + const char *newFilenameUTF8 = (*env)->GetStringUTFChars(env, newFilename , NULL) ; + + if (bDocumentAvail) + { + SwitchToState(SM_INVALID); + _tcscpy(szBufferFilename, newFilenameUTF8); + if (SaveDocumentAs(szBufferFilename)) + MruAdd(szCurrentFilename); + else { + // ERROR !!!!!!!!! + } + SwitchToState(SM_RUN); + } + + (*env)->ReleaseStringUTFChars(env, newFilename, newFilenameUTF8); } JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileClose(JNIEnv *env, jobject thisz) { - OnFileClose(); + //OnFileClose(); + if (bDocumentAvail) + { + SwitchToState(SM_INVALID); + if(bAutoSave) + SaveDocument(); + ResetDocument(); + SetWindowTitle(NULL); + } } JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onObjectLoad(JNIEnv *env, jobject thisz) { diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java b/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java index 3bd0846..cac8010 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java @@ -165,16 +165,28 @@ public class MainActivity extends AppCompatActivity } + public static int INTENT_GETOPENFILENAME = 1; + public static int INTENT_GETSAVEFILENAME = 2; + private void OnFileOpen() { - NativeLib.onFileOpen(); + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + //intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull + intent.setType("*/*"); + intent.putExtra(Intent.EXTRA_TITLE, "emu48-state.e48"); //not needed, but maybe usefull + startActivityForResult(intent, INTENT_GETOPENFILENAME); } private void OnFileSave() { NativeLib.onFileSave(); } private void OnFileSaveAs() { - NativeLib.onFileSaveAs(); - + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + //intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull + intent.setType("*/*"); + intent.putExtra(Intent.EXTRA_TITLE, "emu48-state.e48"); //not needed, but maybe usefull + startActivityForResult(intent, INTENT_GETSAVEFILENAME); } private void OnFileClose() { NativeLib.onFileClose(); @@ -234,21 +246,40 @@ public class MainActivity extends AppCompatActivity @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - if(requestCode == MainScreenView.INTENT_GETSAVEFILENAME && resultCode == Activity.RESULT_OK) { - Uri uri = data.getData(); + if(resultCode == Activity.RESULT_OK) { - //just as an example, I am writing a String to the Uri I received from the user: - Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + uri.toString()); + if(requestCode == INTENT_GETOPENFILENAME) { + Uri uri = data.getData(); -// try { -// OutputStream output = getContentResolver().openOutputStream(uri); -// -// output.write(SOME_CONTENT.getBytes()); -// output.close(); -// } -// catch(IOException e) { -// Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show(); -// } + //just as an example, I am writing a String to the Uri I received from the user: + Log.d(TAG, "onActivityResult INTENT_GETOPENFILENAME " + uri.toString()); + NativeLib.onFileOpen(uri.toString()); + + // try { + // OutputStream output = getContentResolver().openOutputStream(uri); + // + // output.write(SOME_CONTENT.getBytes()); + // output.close(); + // } + // catch(IOException e) { + // Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show(); + // } + } else if(requestCode == INTENT_GETSAVEFILENAME) { + Uri uri = data.getData(); + + //just as an example, I am writing a String to the Uri I received from the user: + Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + uri.toString()); + NativeLib.onFileSaveAs(uri.toString()); + // try { + // OutputStream output = getContentResolver().openOutputStream(uri); + // + // output.write(SOME_CONTENT.getBytes()); + // output.close(); + // } + // catch(IOException e) { + // Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show(); + // } + } } super.onActivityResult(requestCode, resultCode, data); } diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java index 5bb6952..542f5c3 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java @@ -240,10 +240,7 @@ public class MainScreenView extends SurfaceView { final int CALLBACK_TYPE_INVALIDATE = 0; final int CALLBACK_TYPE_WINDOW_RESIZE = 1; - final int CALLBACK_TYPE_GETOPENFILENAME = 2; - final int CALLBACK_TYPE_GETSAVEFILENAME = 3; - public static int INTENT_GETSAVEFILENAME = 1; int updateCallback(int type, int param1, int param2, String param3, String param4) { switch (type) { case CALLBACK_TYPE_INVALIDATE: @@ -254,15 +251,6 @@ public class MainScreenView extends SurfaceView { bitmapMainScreen.reconfigure(/* x */ param1, /* y */ param2, Bitmap.Config.ARGB_8888); bitmapMainScreen.eraseColor(Color.LTGRAY); break; - case CALLBACK_TYPE_GETOPENFILENAME: - break; - case CALLBACK_TYPE_GETSAVEFILENAME: - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - //intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull - intent.putExtra(Intent.EXTRA_TITLE, "YOUR FILENAME"); //not needed, but maybe usefull - ((Activity)getContext()).startActivityForResult(intent, INTENT_GETSAVEFILENAME); - break; } return -1; } diff --git a/app/src/main/java/com/regis/cosnier/emu48/NativeLib.java b/app/src/main/java/com/regis/cosnier/emu48/NativeLib.java index 2c08ebb..040d6ce 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/NativeLib.java +++ b/app/src/main/java/com/regis/cosnier/emu48/NativeLib.java @@ -19,10 +19,13 @@ public class NativeLib { public static native void keyDown(int virtKey); public static native void keyUp(int virtKey); + + public static native String getCurrentFilename(); + public static native void onFileNew(); - public static native void onFileOpen(); + public static native void onFileOpen(String filename); public static native void onFileSave(); - public static native void onFileSaveAs(); + public static native void onFileSaveAs(String newFilename); public static native void onFileClose(); public static native void onObjectLoad(); public static native void onObjectSave();