diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a44d5bef0..f6d109a56d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -886,7 +886,7 @@ if(WIN32)
endif()
if(HEADLESS)
- add_executable(PPSSPPHeadless headless/Headless.cpp)
+ add_executable(PPSSPPHeadless headless/Headless.cpp headless/StubHost.h)
target_link_libraries(PPSSPPHeadless ${CoreLibName}
${COCOA_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
setup_target_project(PPSSPPHeadless headless)
diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp
index c3b1386894..4f5ff5c8a4 100644
--- a/Core/HLE/sceIo.cpp
+++ b/Core/HLE/sceIo.cpp
@@ -22,6 +22,7 @@
#include "../System.h"
#include "../Config.h"
+#include "../Host.h"
#include "../SaveState.h"
#include "HLE.h"
#include "../MIPS/MIPS.h"
@@ -77,12 +78,6 @@ typedef s32 SceMode;
typedef s64 SceOff;
typedef u64 SceIores;
-std::string emuDebugOutput;
-
-const std::string &EmuDebugOutput() {
- return emuDebugOutput;
-}
-
typedef u32 (*DeferredAction)(SceUID id, int param);
DeferredAction defAction = 0;
u32 defParam = 0;
@@ -644,12 +639,7 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
std::string data(Memory::GetCharPointer(argAddr), argLen);
if (PSP_CoreParameter().printfEmuLog)
{
- printf("%s", data.c_str());
-#ifdef _WIN32
- OutputDebugString(data.c_str());
-#endif
- // Also collect the debug output
- emuDebugOutput += data;
+ host->SendDebugOutput(data.c_str());
}
else
{
diff --git a/Core/HLE/sceIo.h b/Core/HLE/sceIo.h
index 0f87cde613..d05c00df06 100644
--- a/Core/HLE/sceIo.h
+++ b/Core/HLE/sceIo.h
@@ -29,5 +29,3 @@ KernelObject *__KernelDirListingObject();
void Register_IoFileMgrForUser();
void Register_StdioForUser();
-
-const std::string &EmuDebugOutput();
diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp
index b590393c49..01df21da5d 100644
--- a/Core/HLE/sceKernel.cpp
+++ b/Core/HLE/sceKernel.cpp
@@ -182,20 +182,18 @@ bool __KernelIsRunning() {
void sceKernelExitGame()
{
INFO_LOG(HLE,"sceKernelExitGame");
- if (PSP_CoreParameter().headLess)
- exit(0);
- else
+ if (!PSP_CoreParameter().headLess)
PanicAlert("Game exited");
+ __KernelSwitchOffThread("game exited");
Core_Stop();
}
void sceKernelExitGameWithStatus()
{
INFO_LOG(HLE,"sceKernelExitGameWithStatus");
- if (PSP_CoreParameter().headLess)
- exit(0);
- else
+ if (!PSP_CoreParameter().headLess)
PanicAlert("Game exited (with status)");
+ __KernelSwitchOffThread("game exited");
Core_Stop();
}
diff --git a/Core/Host.h b/Core/Host.h
index 5600e01393..056395184c 100644
--- a/Core/Host.h
+++ b/Core/Host.h
@@ -60,6 +60,9 @@ public:
virtual bool IsDebuggingEnabled() {return true;}
virtual bool AttemptLoadSymbolMap() {return false;}
virtual void SetWindowTitle(const char *message) {}
+
+ // Used for headless.
+ virtual void SendDebugOutput(const std::string &output) {}
};
extern Host *host;
diff --git a/headless/Headless.cpp b/headless/Headless.cpp
index dabd2586e7..b0b3362a14 100644
--- a/headless/Headless.cpp
+++ b/headless/Headless.cpp
@@ -13,34 +13,10 @@
#include "Log.h"
#include "LogManager.h"
-// TODO: Get rid of this junk
-class HeadlessHost : public Host
-{
-public:
- // virtual void StartThread()
- virtual void UpdateUI() {}
-
- virtual void UpdateMemView() {}
- virtual void UpdateDisassembly() {}
-
- virtual void SetDebugMode(bool mode) { }
-
- virtual void InitGL() {}
- virtual void BeginFrame() {}
- virtual void EndFrame() {}
- virtual void ShutdownGL() {}
-
- virtual void InitSound(PMixer *mixer) {}
- virtual void UpdateSound() {}
- virtual void ShutdownSound() {}
-
- // this is sent from EMU thread! Make sure that Host handles it properly!
- virtual void BootDone() {}
- virtual void PrepareShutdown() {}
-
- virtual bool IsDebuggingEnabled() {return false;}
- virtual bool AttemptLoadSymbolMap() {return false;}
-};
+#include "StubHost.h"
+#ifdef _WIN32
+#include "WindowsHeadlessHost.h"
+#endif
class PrintfLogger : public LogListener
{
@@ -50,20 +26,20 @@ public:
switch (level)
{
case LogTypes::LDEBUG:
- printf("D %s", msg);
+ fprintf(stderr, "D %s", msg);
break;
case LogTypes::LINFO:
- printf("I %s", msg);
+ fprintf(stderr, "I %s", msg);
break;
case LogTypes::LERROR:
- printf("E %s", msg);
+ fprintf(stderr, "E %s", msg);
break;
case LogTypes::LWARNING:
- printf("W %s", msg);
+ fprintf(stderr, "W %s", msg);
break;
case LogTypes::LNOTICE:
default:
- printf("N %s", msg);
+ fprintf(stderr, "N %s", msg);
break;
}
}
@@ -79,6 +55,12 @@ void printUsage(const char *progname, const char *reason)
fprintf(stderr, "Options:\n");
fprintf(stderr, " -m, --mount umd.cso mount iso on umd:\n");
fprintf(stderr, " -l, --log full log output, not just emulated printfs\n");
+
+ HEADLESSHOST_CLASS h1;
+ HeadlessHost h2;
+ if (typeid(h1) != typeid(h2))
+ fprintf(stderr, " --graphics use the full gpu backend (slower)\n");
+
fprintf(stderr, " -f use the fast interpreter\n");
fprintf(stderr, " -j use jit (overrides -f)\n");
fprintf(stderr, " -c, --compare compare with output in file.expected\n");
@@ -91,6 +73,7 @@ int main(int argc, const char* argv[])
bool useJit = false;
bool fastInterpreter = false;
bool autoCompare = false;
+ bool useGraphics = false;
const char *bootFilename = 0;
const char *mountIso = 0;
@@ -114,6 +97,8 @@ int main(int argc, const char* argv[])
fastInterpreter = true;
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare"))
autoCompare = true;
+ else if (!strcmp(argv[i], "--graphics"))
+ useGraphics = true;
else if (bootFilename == 0)
bootFilename = argv[i];
else
@@ -140,7 +125,9 @@ int main(int argc, const char* argv[])
return 1;
}
- host = new HeadlessHost();
+ HeadlessHost *headlessHost = useGraphics ? new HEADLESSHOST_CLASS() : new HeadlessHost();
+ host = headlessHost;
+ host->InitGL();
LogManager::Init();
LogManager *logman = LogManager::GetInstance();
@@ -160,7 +147,7 @@ int main(int argc, const char* argv[])
coreParameter.mountIso = mountIso ? mountIso : "";
coreParameter.startPaused = false;
coreParameter.cpuCore = useJit ? CPU_JIT : (fastInterpreter ? CPU_FASTINTERPRETER : CPU_INTERPRETER);
- coreParameter.gpuCore = GPU_NULL;
+ coreParameter.gpuCore = headlessHost->isGLWorking() ? GPU_GLES : GPU_NULL;
coreParameter.enableSound = false;
coreParameter.headLess = true;
coreParameter.printfEmuLog = true;
@@ -177,8 +164,9 @@ int main(int argc, const char* argv[])
return 1;
}
- coreState = CORE_RUNNING;
+ host->BootDone();
+ coreState = CORE_RUNNING;
while (coreState == CORE_RUNNING)
{
// Run for a frame at a time, just because.
@@ -191,10 +179,13 @@ int main(int argc, const char* argv[])
coreState = CORE_RUNNING;
}
- // NOTE: we won't get here until I've gotten rid of the exit(0) in sceExitProcess or whatever it's called
-
+ host->ShutdownGL();
PSP_Shutdown();
+ delete host;
+ host = NULL;
+ headlessHost = NULL;
+
if (autoCompare)
{
std::string expect_filename = std::string(bootFilename).substr(strlen(bootFilename - 4)) + ".expected";
diff --git a/headless/Headless.vcxproj b/headless/Headless.vcxproj
index e4e8907ff7..3e58e022a8 100644
--- a/headless/Headless.vcxproj
+++ b/headless/Headless.vcxproj
@@ -81,7 +81,7 @@
Level3
Disabled
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../Common;..;../Core;../native/ext/glew;
+ ../Common;..;../Core;../native/ext/glew;../native
Default
@@ -112,7 +112,7 @@
true
true
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../Common;..;../Core;../native/ext/glew;
+ ../Common;..;../Core;../native/ext/glew;../native
false
StreamingSIMDExtensions2
Fast
@@ -151,6 +151,7 @@
NotUsing
NotUsing
+
@@ -175,6 +176,10 @@
{f761046e-6c38-4428-a5f1-38391a37bb34}
+
+
+
+
diff --git a/headless/Headless.vcxproj.filters b/headless/Headless.vcxproj.filters
index cb596797fd..5982bf35db 100644
--- a/headless/Headless.vcxproj.filters
+++ b/headless/Headless.vcxproj.filters
@@ -3,8 +3,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/headless/StubHost.h b/headless/StubHost.h
new file mode 100644
index 0000000000..9445aee06c
--- /dev/null
+++ b/headless/StubHost.h
@@ -0,0 +1,55 @@
+// 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
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program 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 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/.
+
+#pragma once
+
+#include "../Core/Host.h"
+
+#define HEADLESSHOST_CLASS HeadlessHost
+
+// TODO: Get rid of this junk
+class HeadlessHost : public Host
+{
+public:
+ // virtual void StartThread()
+ virtual void UpdateUI() {}
+
+ virtual void UpdateMemView() {}
+ virtual void UpdateDisassembly() {}
+
+ virtual void SetDebugMode(bool mode) { }
+
+ virtual void InitGL() {}
+ virtual void BeginFrame() {}
+ virtual void EndFrame() {}
+ virtual void ShutdownGL() {}
+
+ virtual void InitSound(PMixer *mixer) {}
+ virtual void UpdateSound() {}
+ virtual void ShutdownSound() {}
+
+ // this is sent from EMU thread! Make sure that Host handles it properly
+ virtual void BootDone() {}
+ virtual void PrepareShutdown() {}
+
+ virtual bool IsDebuggingEnabled() {return false;}
+ virtual bool AttemptLoadSymbolMap() {return false;}
+
+ virtual void SendDebugOutput(const std::string &output) { printf("%s", output.c_str()); }
+
+ virtual bool isGLWorking() { return false; }
+};
\ No newline at end of file
diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp
new file mode 100644
index 0000000000..dd473a8279
--- /dev/null
+++ b/headless/WindowsHeadlessHost.cpp
@@ -0,0 +1,174 @@
+// 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
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program 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 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/.
+
+#include "WindowsHeadlessHost.h"
+
+#include
+#include
+#include
+
+#include "gfx_es2/gl_state.h"
+#include "gfx/gl_common.h"
+#include "gfx/gl_lost_manager.h"
+#include "file/vfs.h"
+#include "file/zip_read.h"
+
+const bool WINDOW_VISIBLE = false;
+const int WINDOW_WIDTH = 480;
+const int WINDOW_HEIGHT = 272;
+
+typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int value);
+PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = NULL;
+
+HWND CreateHiddenWindow()
+{
+ static WNDCLASSEX wndClass = {
+ sizeof(WNDCLASSEX),
+ CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
+ DefWindowProc,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ LoadCursor(NULL, IDC_ARROW),
+ (HBRUSH) GetStockObject(BLACK_BRUSH),
+ NULL,
+ "PPSSPPHeadless",
+ NULL,
+ };
+ RegisterClassEx(&wndClass);
+
+ DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
+ return CreateWindowEx(0, "PPSSPPHeadless", "PPSSPPHeadless", style, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, NULL, NULL);
+}
+
+void SetVSync(int value)
+{
+ const char *extensions = (const char *) glGetString(GL_EXTENSIONS);
+
+ if (!strstr(extensions, "WGL_EXT_swap_control"))
+ return;
+
+ wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC) wglGetProcAddress("wglSwapIntervalEXT");
+ if (wglSwapIntervalEXT != NULL)
+ wglSwapIntervalEXT(value);
+}
+
+void WindowsHeadlessHost::LoadNativeAssets()
+{
+ // Native is kinda talkative, but that's annoying in our case.
+ out = _fdopen(_dup(_fileno(stdout)), "wt");
+ freopen("NUL", "wt", stdout);
+
+ VFSRegister("", new DirectoryAssetReader("assets/"));
+ VFSRegister("", new DirectoryAssetReader(""));
+ VFSRegister("", new DirectoryAssetReader("../"));
+
+ gl_lost_manager_init();
+
+ // See SendDebugOutput() for how things get back on track.
+}
+
+void WindowsHeadlessHost::SendDebugOutput(const std::string &output)
+{
+ fprintf_s(out, "%s", output.c_str());
+ OutputDebugString(output.c_str());
+}
+
+void WindowsHeadlessHost::InitGL()
+{
+ glOkay = false;
+ hWnd = CreateHiddenWindow();
+
+ if (WINDOW_VISIBLE)
+ {
+ ShowWindow(hWnd, TRUE);
+ SetFocus(hWnd);
+ }
+
+ int pixelFormat;
+
+ static PIXELFORMATDESCRIPTOR pfd = {0};
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+ pfd.cDepthBits = 16;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+
+#define ENFORCE(x, msg) { if (!(x)) { fprintf(stderr, msg); return; } }
+
+ ENFORCE(hDC = GetDC(hWnd), "Unable to create DC.");
+ ENFORCE(pixelFormat = ChoosePixelFormat(hDC, &pfd), "Unable to match pixel format.");
+ ENFORCE(SetPixelFormat(hDC, pixelFormat, &pfd), "Unable to set pixel format.");
+ ENFORCE(hRC = wglCreateContext(hDC), "Unable to create GL context.");
+ ENFORCE(wglMakeCurrent(hDC, hRC), "Unable to activate GL context.");
+
+ SetVSync(0);
+
+ glewInit();
+ glstate.Initialize();
+
+ LoadNativeAssets();
+
+ if (ResizeGL())
+ glOkay = true;
+}
+
+void WindowsHeadlessHost::ShutdownGL()
+{
+ if (hRC)
+ {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(hRC);
+ hRC = NULL;
+ }
+
+ if (hDC)
+ ReleaseDC(hWnd, hDC);
+ hDC = NULL;
+ DestroyWindow(hWnd);
+ hWnd = NULL;
+}
+
+bool WindowsHeadlessHost::ResizeGL()
+{
+ if (!hWnd)
+ return false;
+
+ RECT rc;
+ GetWindowRect(hWnd, &rc);
+
+ glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.0f, -1.0f, 1.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ return true;
+}
+
+void WindowsHeadlessHost::BeginFrame()
+{
+
+}
+
+void WindowsHeadlessHost::EndFrame()
+{
+ SwapBuffers(hDC);
+}
diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h
new file mode 100644
index 0000000000..28e51ee543
--- /dev/null
+++ b/headless/WindowsHeadlessHost.h
@@ -0,0 +1,48 @@
+// 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
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program 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 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/.
+
+#pragma once
+
+#include "StubHost.h"
+
+#undef HEADLESSHOST_CLASS
+#define HEADLESSHOST_CLASS WindowsHeadlessHost
+
+#include
+
+// TODO: Get rid of this junk
+class WindowsHeadlessHost : public HeadlessHost
+{
+public:
+ virtual void InitGL();
+ virtual void BeginFrame();
+ virtual void EndFrame();
+ virtual void ShutdownGL();
+ virtual bool isGLWorking() { return glOkay; }
+
+ virtual void SendDebugOutput(const std::string &output);
+
+private:
+ bool ResizeGL();
+ void LoadNativeAssets();
+
+ bool glOkay;
+ HWND hWnd;
+ HDC hDC;
+ HGLRC hRC;
+ FILE *out;
+};
\ No newline at end of file