2012-10-14 03:37:08 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <jni.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-10-15 19:09:37 +02:00
|
|
|
#include "android-general.h"
|
2012-10-14 05:18:53 +02:00
|
|
|
#include "../../../general.h"
|
2012-10-14 03:37:08 +02:00
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt)
|
|
|
|
{
|
|
|
|
return JNI_VERSION_1_2;
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt) { }
|
2012-10-14 03:37:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the next main command.
|
|
|
|
*/
|
|
|
|
static void engine_handle_cmd(struct android_app* app, int32_t cmd)
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case APP_CMD_SAVE_STATE:
|
2012-10-21 19:56:36 +02:00
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_SAVE_STATE.\n");
|
2012-10-14 03:37:08 +02:00
|
|
|
// The system has asked us to save our current state. Do so.
|
2012-10-31 17:12:18 +01:00
|
|
|
break;
|
2012-10-14 03:37:08 +02:00
|
|
|
case APP_CMD_INIT_WINDOW:
|
2012-10-21 19:56:36 +02:00
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_INIT_WINDOW.\n");
|
2012-10-31 17:12:18 +01:00
|
|
|
// The window is being shown, get it ready.
|
|
|
|
if (g_android.app->window != NULL)
|
2012-10-16 13:08:36 +02:00
|
|
|
g_android.window_inited = true;
|
2012-10-31 17:12:18 +01:00
|
|
|
break;
|
2012-10-21 19:56:36 +02:00
|
|
|
case APP_CMD_START:
|
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_START.\n");
|
|
|
|
break;
|
|
|
|
case APP_CMD_RESUME:
|
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_RESUME.\n");
|
|
|
|
break;
|
|
|
|
case APP_CMD_STOP:
|
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_STOP.\n");
|
|
|
|
break;
|
|
|
|
case APP_CMD_PAUSE:
|
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_PAUSE.\n");
|
2012-10-31 17:12:18 +01:00
|
|
|
g_android.init_quit = true;
|
2012-10-21 19:56:36 +02:00
|
|
|
break;
|
2012-10-14 03:37:08 +02:00
|
|
|
case APP_CMD_TERM_WINDOW:
|
2012-10-21 19:56:36 +02:00
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_TERM_WINDOW.\n");
|
2012-10-31 17:12:18 +01:00
|
|
|
// The window is being hidden or closed, clean it up.
|
|
|
|
break;
|
2012-10-14 03:37:08 +02:00
|
|
|
case APP_CMD_GAINED_FOCUS:
|
2012-10-21 19:56:36 +02:00
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_GAINED_FOCUS.\n");
|
2012-10-31 17:12:18 +01:00
|
|
|
// When our app gains focus, we start monitoring the accelerometer.
|
|
|
|
break;
|
2012-10-14 03:37:08 +02:00
|
|
|
case APP_CMD_LOST_FOCUS:
|
2012-10-21 19:56:36 +02:00
|
|
|
RARCH_LOG("engine_handle_cmd: APP_CMD_LOST_FOCUS.\n");
|
2012-10-31 17:12:18 +01:00
|
|
|
if (!g_android.window_inited)
|
2012-10-16 13:48:08 +02:00
|
|
|
{
|
|
|
|
}
|
2012-10-31 17:12:18 +01:00
|
|
|
break;
|
2012-10-14 03:37:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 18:38:41 +02:00
|
|
|
static void android_get_char_argv(char *argv, size_t sizeof_argv, const char *arg_name)
|
2012-10-16 11:59:08 +02:00
|
|
|
{
|
|
|
|
JNIEnv *env;
|
2012-10-16 18:38:41 +02:00
|
|
|
JavaVM *rarch_vm = g_android.app->activity->vm;
|
2012-10-16 11:59:08 +02:00
|
|
|
|
|
|
|
(*rarch_vm)->AttachCurrentThread(rarch_vm, &env, 0);
|
|
|
|
|
2012-10-16 18:38:41 +02:00
|
|
|
jobject me = g_android.app->activity->clazz;
|
2012-10-16 11:59:08 +02:00
|
|
|
|
|
|
|
jclass acl = (*env)->GetObjectClass(env, me); //class pointer of NativeActivity
|
|
|
|
jmethodID giid = (*env)->GetMethodID(env, acl, "getIntent", "()Landroid/content/Intent;");
|
|
|
|
jobject intent = (*env)->CallObjectMethod(env, me, giid); //Got our intent
|
|
|
|
|
|
|
|
jclass icl = (*env)->GetObjectClass(env, intent); //class pointer of Intent
|
|
|
|
jmethodID gseid = (*env)->GetMethodID(env, icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
|
|
|
|
|
|
|
|
jstring jsParam1 = (*env)->CallObjectMethod(env, intent, gseid, (*env)->NewStringUTF(env, arg_name));
|
|
|
|
const char *test_argv = (*env)->GetStringUTFChars(env, jsParam1, 0);
|
|
|
|
|
|
|
|
strncpy(argv, test_argv, sizeof_argv);
|
|
|
|
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jsParam1, test_argv);
|
2012-10-21 17:30:02 +02:00
|
|
|
|
|
|
|
(*rarch_vm)->DetachCurrentThread(rarch_vm);
|
2012-10-16 11:59:08 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:49:56 +02:00
|
|
|
#define MAX_ARGS 32
|
|
|
|
|
2012-10-14 03:37:08 +02:00
|
|
|
/**
|
|
|
|
* This is the main entry point of a native application that is using
|
|
|
|
* android_native_app_glue. It runs in its own thread, with its own
|
|
|
|
* event loop for receiving input events and doing other things.
|
|
|
|
*/
|
|
|
|
void android_main(struct android_app* state)
|
|
|
|
{
|
|
|
|
// Make sure glue isn't stripped.
|
|
|
|
app_dummy();
|
|
|
|
|
2012-10-15 08:57:23 +02:00
|
|
|
rarch_main_clear_state();
|
|
|
|
|
2012-10-16 02:05:47 +02:00
|
|
|
RARCH_LOG("Native Activity started.\n");
|
|
|
|
|
2012-10-15 08:57:23 +02:00
|
|
|
g_android.app = state;
|
2012-10-14 03:37:08 +02:00
|
|
|
|
2012-10-16 12:49:56 +02:00
|
|
|
char rom_path[512];
|
2012-10-16 11:59:08 +02:00
|
|
|
char libretro_path[512];
|
2012-10-16 02:05:47 +02:00
|
|
|
|
2012-10-16 11:59:08 +02:00
|
|
|
// Get arguments */
|
2012-10-16 18:38:41 +02:00
|
|
|
android_get_char_argv(rom_path, sizeof(rom_path), "ROM");
|
|
|
|
android_get_char_argv(libretro_path, sizeof(libretro_path), "LIBRETRO");
|
2012-10-16 02:05:47 +02:00
|
|
|
|
|
|
|
RARCH_LOG("Checking arguments passed...\n");
|
2012-10-16 12:49:56 +02:00
|
|
|
RARCH_LOG("ROM Filename: [%s].\n", rom_path);
|
2012-10-16 11:59:08 +02:00
|
|
|
RARCH_LOG("Libretro path: [%s].\n", libretro_path);
|
2012-10-16 02:05:47 +02:00
|
|
|
|
2012-10-16 12:58:43 +02:00
|
|
|
/* ugly hack for now - hardcode libretro path to 'allowed' dir */
|
|
|
|
snprintf(libretro_path, sizeof(libretro_path), "/data/data/com.retroarch/lib/libretro.so");
|
|
|
|
|
2012-10-16 18:38:41 +02:00
|
|
|
g_android.app->onAppCmd = engine_handle_cmd;
|
|
|
|
|
2012-10-16 12:49:56 +02:00
|
|
|
int argc = 0;
|
|
|
|
char *argv[MAX_ARGS] = {NULL};
|
2012-10-14 03:37:08 +02:00
|
|
|
|
2012-10-16 12:49:56 +02:00
|
|
|
argv[argc++] = strdup("retroarch");
|
|
|
|
argv[argc++] = strdup(rom_path);
|
|
|
|
argv[argc++] = strdup("-L");
|
|
|
|
argv[argc++] = strdup(libretro_path);
|
|
|
|
argv[argc++] = strdup("-v");
|
2012-10-14 03:37:08 +02:00
|
|
|
|
2012-10-16 13:27:49 +02:00
|
|
|
g_extern.verbose = true;
|
|
|
|
|
2012-10-16 13:08:36 +02:00
|
|
|
while(!g_android.window_inited)
|
|
|
|
{
|
|
|
|
// Read all pending events.
|
2012-10-31 22:22:01 +01:00
|
|
|
int id;
|
2012-10-16 13:08:36 +02:00
|
|
|
|
2012-10-31 17:12:18 +01:00
|
|
|
// Block forever waiting for events.
|
2012-10-31 22:22:01 +01:00
|
|
|
while ((id = ALooper_pollOnce(0, NULL, 0, NULL)) >= 0)
|
2012-10-16 13:08:36 +02:00
|
|
|
{
|
|
|
|
// Process this event.
|
2012-10-31 22:22:01 +01:00
|
|
|
if (id)
|
|
|
|
process_cmd();
|
2012-10-16 13:08:36 +02:00
|
|
|
|
2012-10-31 17:12:18 +01:00
|
|
|
// Check if we are exiting.
|
|
|
|
if (g_android.app->destroyRequested != 0)
|
|
|
|
return;
|
2012-10-16 13:08:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:12:18 +01:00
|
|
|
RARCH_LOG("Starting RetroArch...\n");
|
2012-10-16 13:08:36 +02:00
|
|
|
|
2012-10-16 12:49:56 +02:00
|
|
|
rarch_main(argc, argv);
|
2012-10-21 19:56:36 +02:00
|
|
|
exit(0);
|
2012-10-14 03:37:08 +02:00
|
|
|
}
|