mirror of
https://github.com/dgis/emu48android
synced 2024-12-26 09:58:49 +01:00
This commit is contained in:
parent
537e9238b5
commit
7e008185b5
5 changed files with 137 additions and 46 deletions
|
@ -4,7 +4,7 @@ android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.regis.cosnier.emu48"
|
applicationId "com.regis.cosnier.emu48"
|
||||||
minSdkVersion 21
|
minSdkVersion 19
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <android/bitmap.h>
|
#include <android/bitmap.h>
|
||||||
|
|
||||||
#include "core/pch.h"
|
#include "core/pch.h"
|
||||||
|
#include "core/Emu48.h"
|
||||||
|
|
||||||
extern void emu48Start();
|
extern void emu48Start();
|
||||||
extern AAssetManager * assetManager;
|
extern AAssetManager * assetManager;
|
||||||
|
@ -23,16 +24,16 @@ extern void buttonUp(int x, int y);
|
||||||
extern void keyDown(int virtKey);
|
extern void keyDown(int virtKey);
|
||||||
extern void keyUp(int virtKey);
|
extern void keyUp(int virtKey);
|
||||||
|
|
||||||
extern void OnFileNew();
|
//extern void OnFileNew();
|
||||||
extern void OnFileOpen();
|
//extern void OnFileOpen();
|
||||||
extern void OnFileSave();
|
//extern void OnFileSave();
|
||||||
extern void OnFileSaveAs();
|
//extern void OnFileSaveAs();
|
||||||
extern void OnFileClose();
|
//extern void OnFileClose();
|
||||||
extern void OnObjectLoad();
|
extern void OnObjectLoad();
|
||||||
extern void OnObjectSave();
|
extern void OnObjectSave();
|
||||||
extern void OnViewCopy();
|
extern void OnViewCopy();
|
||||||
extern void OnStackCopy();
|
//extern void OnStackCopy();
|
||||||
extern void OnStackPaste();
|
//extern void OnStackPaste();
|
||||||
extern void OnViewReset();
|
extern void OnViewReset();
|
||||||
extern void OnBackupSave();
|
extern void OnBackupSave();
|
||||||
extern void OnBackupRestore();
|
extern void OnBackupRestore();
|
||||||
|
@ -204,21 +205,89 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_keyUp(JNIEnv *env,
|
||||||
keyUp(virtKey);
|
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) {
|
//JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_setCurrentFilename(JNIEnv *env, jobject thisz, jstring newFilename) {
|
||||||
OnFileOpen();
|
// 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) {
|
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) {
|
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onFileSaveAs(JNIEnv *env, jobject thisz, jstring newFilename) {
|
||||||
OnFileSaveAs();
|
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) {
|
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) {
|
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_onObjectLoad(JNIEnv *env, jobject thisz) {
|
||||||
|
|
|
@ -165,16 +165,28 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int INTENT_GETOPENFILENAME = 1;
|
||||||
|
public static int INTENT_GETSAVEFILENAME = 2;
|
||||||
|
|
||||||
private void OnFileOpen() {
|
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() {
|
private void OnFileSave() {
|
||||||
NativeLib.onFileSave();
|
NativeLib.onFileSave();
|
||||||
}
|
}
|
||||||
private void OnFileSaveAs() {
|
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() {
|
private void OnFileClose() {
|
||||||
NativeLib.onFileClose();
|
NativeLib.onFileClose();
|
||||||
|
@ -234,21 +246,40 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
if(requestCode == MainScreenView.INTENT_GETSAVEFILENAME && resultCode == Activity.RESULT_OK) {
|
if(resultCode == Activity.RESULT_OK) {
|
||||||
Uri uri = data.getData();
|
|
||||||
|
|
||||||
//just as an example, I am writing a String to the Uri I received from the user:
|
if(requestCode == INTENT_GETOPENFILENAME) {
|
||||||
Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + uri.toString());
|
Uri uri = data.getData();
|
||||||
|
|
||||||
// try {
|
//just as an example, I am writing a String to the Uri I received from the user:
|
||||||
// OutputStream output = getContentResolver().openOutputStream(uri);
|
Log.d(TAG, "onActivityResult INTENT_GETOPENFILENAME " + uri.toString());
|
||||||
//
|
NativeLib.onFileOpen(uri.toString());
|
||||||
// output.write(SOME_CONTENT.getBytes());
|
|
||||||
// output.close();
|
// try {
|
||||||
// }
|
// OutputStream output = getContentResolver().openOutputStream(uri);
|
||||||
// catch(IOException e) {
|
//
|
||||||
// Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
|
// 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);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,10 +240,7 @@ public class MainScreenView extends SurfaceView {
|
||||||
|
|
||||||
final int CALLBACK_TYPE_INVALIDATE = 0;
|
final int CALLBACK_TYPE_INVALIDATE = 0;
|
||||||
final int CALLBACK_TYPE_WINDOW_RESIZE = 1;
|
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) {
|
int updateCallback(int type, int param1, int param2, String param3, String param4) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CALLBACK_TYPE_INVALIDATE:
|
case CALLBACK_TYPE_INVALIDATE:
|
||||||
|
@ -254,15 +251,6 @@ public class MainScreenView extends SurfaceView {
|
||||||
bitmapMainScreen.reconfigure(/* x */ param1, /* y */ param2, Bitmap.Config.ARGB_8888);
|
bitmapMainScreen.reconfigure(/* x */ param1, /* y */ param2, Bitmap.Config.ARGB_8888);
|
||||||
bitmapMainScreen.eraseColor(Color.LTGRAY);
|
bitmapMainScreen.eraseColor(Color.LTGRAY);
|
||||||
break;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,13 @@ public class NativeLib {
|
||||||
public static native void keyDown(int virtKey);
|
public static native void keyDown(int virtKey);
|
||||||
public static native void keyUp(int virtKey);
|
public static native void keyUp(int virtKey);
|
||||||
|
|
||||||
|
|
||||||
|
public static native String getCurrentFilename();
|
||||||
|
|
||||||
public static native void onFileNew();
|
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 onFileSave();
|
||||||
public static native void onFileSaveAs();
|
public static native void onFileSaveAs(String newFilename);
|
||||||
public static native void onFileClose();
|
public static native void onFileClose();
|
||||||
public static native void onObjectLoad();
|
public static native void onObjectLoad();
|
||||||
public static native void onObjectSave();
|
public static native void onObjectSave();
|
||||||
|
|
Loading…
Reference in a new issue