2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-11-04 09:56:22 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-11-01 15:19:01 +00:00
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// NativeApp implementation for platforms that will use that framework, like:
|
|
|
|
// Android, Linux, MacOSX.
|
|
|
|
//
|
|
|
|
// Native is a cross platform framework. It's not very mature and mostly
|
|
|
|
// just built according to the needs of my own apps.
|
|
|
|
//
|
|
|
|
// Windows has its own code that bypasses the framework entirely.
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/NativeApp.h"
|
|
|
|
#include "file/vfs.h"
|
|
|
|
#include "file/zip_read.h"
|
2012-12-05 03:45:28 +00:00
|
|
|
#include "gfx_es2/gl_state.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "gfx/gl_lost_manager.h"
|
|
|
|
#include "gfx/texture.h"
|
|
|
|
#include "input/input_state.h"
|
|
|
|
#include "math/lin/matrix4x4.h"
|
|
|
|
#include "ui/screen.h"
|
|
|
|
#include "ui/ui.h"
|
|
|
|
|
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "LogManager.h"
|
|
|
|
#include "../../Core/PSPMixer.h"
|
|
|
|
#include "../../Core/CPU.h"
|
|
|
|
#include "../../Core/Config.h"
|
|
|
|
#include "../../Core/Host.h"
|
|
|
|
#include "../../Common/MemArena.h"
|
|
|
|
|
|
|
|
#include "ui_atlas.h"
|
|
|
|
#include "EmuScreen.h"
|
|
|
|
#include "MenuScreens.h"
|
|
|
|
#include "UIShader.h"
|
|
|
|
|
|
|
|
Texture *uiTexture;
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
ScreenManager *screenManager;
|
2012-11-01 15:19:01 +00:00
|
|
|
std::string config_filename;
|
|
|
|
|
|
|
|
class AndroidLogger : public LogListener
|
|
|
|
{
|
|
|
|
public:
|
2012-11-04 09:56:22 +00:00
|
|
|
void Log(LogTypes::LOG_LEVELS level, const char *msg)
|
|
|
|
{
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case LogTypes::LDEBUG:
|
|
|
|
case LogTypes::LINFO:
|
|
|
|
ILOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LERROR:
|
|
|
|
ELOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LWARNING:
|
|
|
|
WLOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LNOTICE:
|
|
|
|
default:
|
|
|
|
ILOG("%s", msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Get rid of this junk
|
|
|
|
class NativeHost : public Host
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NativeHost() {
|
|
|
|
// hasRendered = false;
|
|
|
|
}
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void UpdateUI() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void UpdateMemView() {}
|
|
|
|
virtual void UpdateDisassembly() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void SetDebugMode(bool mode) { }
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void InitGL() {}
|
|
|
|
virtual void BeginFrame() {}
|
|
|
|
virtual void EndFrame() {}
|
|
|
|
virtual void ShutdownGL() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void InitSound(PMixer *mixer);
|
|
|
|
virtual void UpdateSound() {};
|
|
|
|
virtual void ShutdownSound();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
// this is sent from EMU thread! Make sure that Host handles it properly!
|
|
|
|
virtual void BootDone() {}
|
|
|
|
virtual void PrepareShutdown() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual bool IsDebuggingEnabled() {return false;}
|
|
|
|
virtual bool AttemptLoadSymbolMap() {return false;}
|
|
|
|
virtual void ResetSymbolMap() {}
|
|
|
|
virtual void AddSymbol(std::string name, u32 addr, u32 size, int type=0) {}
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// globals
|
|
|
|
static PMixer *g_mixer = 0;
|
|
|
|
static AndroidLogger *logger = 0;
|
|
|
|
|
|
|
|
std::string boot_filename = "";
|
|
|
|
|
|
|
|
void NativeHost::InitSound(PMixer *mixer)
|
|
|
|
{
|
|
|
|
g_mixer = mixer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeHost::ShutdownSound()
|
|
|
|
{
|
|
|
|
g_mixer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeMix(short *audio, int num_samples)
|
|
|
|
{
|
2012-11-04 09:56:22 +00:00
|
|
|
if (g_mixer)
|
|
|
|
{
|
|
|
|
g_mixer->Mix(audio, num_samples/2);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//memset(audio, 0, numSamples * 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape)
|
|
|
|
{
|
|
|
|
*app_nice_name = "PPSSPP";
|
|
|
|
*app_dir_name = "ppsspp";
|
|
|
|
*landscape = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID)
|
|
|
|
{
|
2012-11-04 09:56:22 +00:00
|
|
|
std::string user_data_path = savegame_directory;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
// We want this to be FIRST.
|
2012-11-07 17:22:10 +00:00
|
|
|
#ifdef BLACKBERRY
|
|
|
|
// Packed assets are included in app/native/ dir
|
|
|
|
VFSRegister("", new DirectoryAssetReader("app/native/assets/"));
|
|
|
|
#else
|
2012-11-04 09:56:22 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader("assets/"));
|
2012-11-07 17:22:10 +00:00
|
|
|
#endif
|
2012-11-04 09:56:22 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(user_data_path.c_str()));
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
host = new NativeHost();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
logger = new AndroidLogger();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
LogManager::Init();
|
|
|
|
LogManager *logman = LogManager::GetInstance();
|
|
|
|
ILOG("Logman: %p", logman);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-12-01 22:20:08 +00:00
|
|
|
bool gfxLog = false;
|
2012-11-04 10:31:06 +00:00
|
|
|
// Parse command line
|
|
|
|
LogTypes::LOG_LEVELS logLevel = LogTypes::LINFO;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
switch (argv[i][1]) {
|
|
|
|
case 'd':
|
|
|
|
// Enable debug logging
|
|
|
|
logLevel = LogTypes::LDEBUG;
|
|
|
|
break;
|
2012-12-01 22:20:08 +00:00
|
|
|
case 'g':
|
|
|
|
gfxLog = true;
|
|
|
|
break;
|
2012-12-05 06:55:24 +00:00
|
|
|
case 'j':
|
|
|
|
g_Config.iCpuCore = CPU_JIT;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
g_Config.iCpuCore = CPU_INTERPRETER;
|
|
|
|
break;
|
2012-11-04 10:31:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-01 22:38:18 +00:00
|
|
|
if (boot_filename.empty()) {
|
|
|
|
boot_filename = argv[i];
|
|
|
|
if (!File::Exists(boot_filename))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "File not found: %s\n", boot_filename.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Can only boot one file");
|
2012-11-04 10:31:06 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
config_filename = user_data_path + "ppsspp.ini";
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
g_Config.Load(config_filename.c_str());
|
|
|
|
|
|
|
|
if (g_Config.currentDirectory == "") {
|
2012-12-13 03:15:20 +00:00
|
|
|
#if defined(ANDROID) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
|
2012-11-01 15:19:01 +00:00
|
|
|
g_Config.currentDirectory = external_directory;
|
|
|
|
#else
|
|
|
|
g_Config.currentDirectory = getenv("HOME");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-12-09 15:48:56 +00:00
|
|
|
#if defined(ANDROID) || defined(BLACKBERRY)
|
|
|
|
g_Config.memCardDirectory = user_data_path;
|
2012-12-09 23:32:44 +00:00
|
|
|
g_Config.flashDirectory = user_data_path+"/flash/";
|
2012-12-09 15:48:56 +00:00
|
|
|
#else
|
|
|
|
g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/";
|
2012-12-09 23:32:44 +00:00
|
|
|
g_Config.flashDirectory = g_Config.memCardDirectory+"/flash/";
|
2012-12-09 15:48:56 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
{
|
|
|
|
LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i;
|
|
|
|
logman->SetEnable(type, true);
|
2012-12-05 03:45:28 +00:00
|
|
|
logman->SetLogLevel(type, gfxLog && i == LogTypes::G3D ? LogTypes::LDEBUG : logLevel);
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifdef ANDROID
|
2012-11-04 09:56:22 +00:00
|
|
|
logman->AddListener(type, logger);
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif
|
2012-11-04 09:56:22 +00:00
|
|
|
}
|
2012-11-04 10:31:06 +00:00
|
|
|
// Special hack for G3D as it's very spammy. Need to make a flag for this.
|
2012-12-01 22:20:08 +00:00
|
|
|
if (!gfxLog)
|
|
|
|
logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
|
2012-11-04 09:56:22 +00:00
|
|
|
INFO_LOG(BOOT, "Logger inited.");
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeInitGraphics()
|
|
|
|
{
|
|
|
|
INFO_LOG(BOOT, "NativeInitGraphics - should only be called once!");
|
|
|
|
gl_lost_manager_init();
|
|
|
|
ui_draw2d.SetAtlas(&ui_atlas);
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager = new ScreenManager();
|
2012-11-04 09:56:22 +00:00
|
|
|
if (boot_filename.empty()) {
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->switchScreen(new LogoScreen(boot_filename));
|
2012-11-04 09:56:22 +00:00
|
|
|
} else {
|
|
|
|
// Go directly into the game.
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->switchScreen(new EmuScreen(boot_filename));
|
2012-11-04 09:56:22 +00:00
|
|
|
}
|
2012-11-04 10:54:45 +00:00
|
|
|
// screenManager->switchScreen(new FileSelectScreen());
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
UIShader_Init();
|
|
|
|
|
|
|
|
UITheme theme = {0};
|
|
|
|
theme.uiFont = UBUNTU24;
|
|
|
|
theme.uiFontSmall = UBUNTU24;
|
|
|
|
theme.uiFontSmaller = UBUNTU24;
|
|
|
|
theme.buttonImage = I_BUTTON;
|
|
|
|
theme.buttonSelected = I_BUTTON_SELECTED;
|
2012-11-20 10:35:48 +00:00
|
|
|
theme.checkOn = I_CHECKEDBOX;
|
2012-11-01 15:19:01 +00:00
|
|
|
theme.checkOff = I_SQUARE;
|
|
|
|
|
|
|
|
UIInit(&ui_atlas, theme);
|
|
|
|
|
|
|
|
uiTexture = new Texture();
|
|
|
|
if (!uiTexture->Load("ui_atlas.zim"))
|
2012-11-04 09:56:22 +00:00
|
|
|
{
|
|
|
|
ELOG("Failed to load texture");
|
|
|
|
}
|
|
|
|
uiTexture->Bind(0);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeRender()
|
|
|
|
{
|
2012-12-05 03:45:28 +00:00
|
|
|
glstate.Restore();
|
2012-11-01 15:19:01 +00:00
|
|
|
glViewport(0, 0, pixel_xres, pixel_yres);
|
2012-11-04 09:56:22 +00:00
|
|
|
Matrix4x4 ortho;
|
2012-11-01 15:19:01 +00:00
|
|
|
ortho.setOrtho(0.0f, dp_xres, dp_yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
glsl_bind(UIShader_Get());
|
|
|
|
glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr());
|
2012-11-04 10:54:45 +00:00
|
|
|
|
|
|
|
screenManager->render();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeUpdate(InputState &input)
|
|
|
|
{
|
|
|
|
UIUpdateMouse(0, input.pointer_x[0], input.pointer_y[0], input.pointer_down[0]);
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->update(input);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeDeviceLost()
|
|
|
|
{
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->deviceLost();
|
2012-11-01 15:19:01 +00:00
|
|
|
gl_lost();
|
|
|
|
// Should dirty EVERYTHING
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeIsAtTopLevel()
|
|
|
|
{
|
2012-11-04 09:56:22 +00:00
|
|
|
// TODO
|
|
|
|
return false;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeTouch(int finger, float x, float y, double time, TouchEvent event)
|
|
|
|
{
|
2012-11-04 09:56:22 +00:00
|
|
|
switch (event) {
|
|
|
|
case TOUCH_DOWN:
|
|
|
|
break;
|
|
|
|
case TOUCH_MOVE:
|
|
|
|
break;
|
|
|
|
case TOUCH_UP:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-01 09:39:20 +00:00
|
|
|
void NativeMessageReceived(const char *message, const char *value)
|
|
|
|
{
|
|
|
|
// Unused
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void NativeShutdownGraphics()
|
|
|
|
{
|
|
|
|
delete uiTexture;
|
|
|
|
uiTexture = NULL;
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->shutdown();
|
|
|
|
delete screenManager;
|
|
|
|
screenManager = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
UIShader_Shutdown();
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
gl_lost_manager_shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeShutdown()
|
|
|
|
{
|
2012-11-04 09:56:22 +00:00
|
|
|
delete host;
|
|
|
|
host = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
g_Config.Save();
|
2012-11-04 10:54:45 +00:00
|
|
|
LogManager::Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
// This means that the activity has been completely destroyed. PPSSPP does not
|
|
|
|
// boot up correctly with "dirty" global variables currently, so we hack around that
|
|
|
|
// by simply exiting.
|
2012-11-04 10:54:45 +00:00
|
|
|
#ifdef ANDROID
|
2012-11-01 15:19:01 +00:00
|
|
|
exit(0);
|
2012-11-04 10:54:45 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|