diff --git a/build/wiiu.vcxproj b/build/wiiu.vcxproj
index fc615621..dab66d23 100644
--- a/build/wiiu.vcxproj
+++ b/build/wiiu.vcxproj
@@ -66,7 +66,7 @@
Console
true
- asmjit.lib;docopt.lib;pugixml.lib;zlib.lib;%(AdditionalDependencies)
+ asmjit.lib;docopt.lib;pugixml.lib;zlib.lib;opengl32.lib;%(AdditionalDependencies)
@@ -85,7 +85,7 @@
Debug
true
true
- asmjit.lib;docopt.lib;pugixml.lib;zlib.lib;%(AdditionalDependencies)
+ asmjit.lib;docopt.lib;pugixml.lib;zlib.lib;opengl32.lib;%(AdditionalDependencies)
diff --git a/src/main.cpp b/src/main.cpp
index 1202d809..3c9f64dc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,6 +25,7 @@
#include "modules/padscore/padscore.h"
#include "system.h"
#include "usermodule.h"
+#include "platform.h"
std::shared_ptr
gLog;
@@ -122,6 +123,8 @@ int main(int argc, char **argv)
static void
initialiseEmulator()
{
+ platform::ui::initialise();
+
Interpreter::RegisterFunctions();
JitManager::RegisterFunctions();
@@ -264,8 +267,10 @@ play(const std::string &path)
// Run thread 1
OSRunThread(OSGetDefaultThread(1), module.entryPoint, 0, nullptr);
+ platform::ui::run();
+
// Wait for all processor threads to exit
- gProcessor.join();
+ //gProcessor.join();
// TODO: OSFreeToSystem data
return true;
diff --git a/src/platform.h b/src/platform.h
index 0ea44f3d..5362cc42 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -8,6 +8,19 @@ namespace platform {
tm localtime(const std::time_t& time);
void set_thread_name(std::thread* thread, const std::string& threadName);
+namespace ui {
+
+void initialise();
+void initialiseCore(int coreId);
+void run();
+
+int drcWidth();
+int drcHeight();
+int tvWidth();
+int tvHeight();
+
+}
+
}
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
diff --git a/src/platform/platform_windows.cpp b/src/platform/platform_windows.cpp
index f95a43db..e7130d31 100644
--- a/src/platform/platform_windows.cpp
+++ b/src/platform/platform_windows.cpp
@@ -1,7 +1,9 @@
#include "../platform.h"
#ifdef PLATFORM_WINDOWS
+#include
#include
+#include
const DWORD MS_VC_EXCEPTION = 0x406D1388;
@@ -42,6 +44,185 @@ void set_thread_name(std::thread* thread, const std::string& threadName)
}
}
+namespace ui {
+
+CHAR szAppName[] = "WiiUEmuClass";
+CHAR szAppTitle[] = "WiiU Emu";
+HWND ghWnd;
+HDC ghDC;
+HGLRC ghRC[3];
+
+BOOL bSetupPixelFormat(HDC hdc)
+{
+ PIXELFORMATDESCRIPTOR pfd, *ppfd;
+ int pixelformat;
+
+ ppfd = &pfd;
+
+ ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
+ ppfd->nVersion = 1;
+ ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
+ PFD_DOUBLEBUFFER;
+ ppfd->dwLayerMask = PFD_MAIN_PLANE;
+ ppfd->iPixelType = PFD_TYPE_COLORINDEX;
+ ppfd->cColorBits = 8;
+ ppfd->cDepthBits = 16;
+ ppfd->cAccumBits = 0;
+ ppfd->cStencilBits = 0;
+
+ pixelformat = ChoosePixelFormat(hdc, ppfd);
+
+ if ((pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0)
+ {
+ MessageBoxA(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
+ return FALSE;
+ }
+
+ if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
+ {
+ MessageBoxA(NULL, "SetPixelFormat failed", "Error", MB_OK);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+LONG WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ LONG lRet = 1;
+ PAINTSTRUCT ps;
+
+ switch (uMsg) {
+
+ case WM_PAINT:
+ BeginPaint(hWnd, &ps);
+ EndPaint(hWnd, &ps);
+ break;
+
+ case WM_CLOSE:
+ /*
+ if (ghDC)
+ ReleaseDC(hWnd, ghDC);
+ ghDC = 0;
+
+ DestroyWindow(hWnd);
+ */
+ break;
+
+ case WM_DESTROY:
+ if (ghDC)
+ ReleaseDC(hWnd, ghDC);
+
+ PostQuitMessage(0);
+ break;
+
+ default:
+ lRet = DefWindowProc(hWnd, uMsg, wParam, lParam);
+ break;
+ }
+
+ return lRet;
+}
+
+void initialise()
+{
+ WNDCLASSA wndclass;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ /* Register the frame class */
+ wndclass.style = 0;
+ wndclass.lpfnWndProc = (WNDPROC)WndProc;
+ wndclass.cbClsExtra = 0;
+ wndclass.cbWndExtra = 0;
+ wndclass.hInstance = hInstance;
+ wndclass.hIcon = LoadIconA(hInstance, szAppName);
+ wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wndclass.lpszMenuName = szAppName;
+ wndclass.lpszClassName = szAppName;
+
+ if (!RegisterClassA(&wndclass))
+ return;
+
+ auto windowWidth = 1920 / 2;
+ auto windowHeight = (854 / 2) + (480 / 2);
+
+ /* Create the frame */
+ ghWnd = CreateWindowA(szAppName,
+ szAppTitle,
+ WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ windowWidth,
+ windowHeight,
+ NULL,
+ NULL,
+ hInstance,
+ NULL);
+
+ /* show and update main window */
+ ShowWindow(ghWnd, 1);
+
+ UpdateWindow(ghWnd);
+
+ ghDC = GetDC(ghWnd);
+ if (!bSetupPixelFormat(ghDC))
+ PostQuitMessage(0);
+
+ for (auto i = 0; i < 3; ++i) {
+ ghRC[i] = (HGLRC)INVALID_HANDLE_VALUE;
+ }
+}
+
+void initialiseCore(int coreId)
+{
+ auto baseRC = (HGLRC)INVALID_HANDLE_VALUE;
+ for (auto i = 0; i < 3; ++i) {
+ if (ghRC[i] != INVALID_HANDLE_VALUE) {
+ baseRC = ghRC[i];
+ break;
+ }
+ }
+
+ if (ghRC[coreId] != INVALID_HANDLE_VALUE) {
+ assert(0);
+ }
+
+ ghRC[coreId] = wglCreateContext(ghDC);
+
+ if (baseRC != INVALID_HANDLE_VALUE) {
+ if (wglShareLists(baseRC, ghRC[coreId]) == FALSE) {
+ assert(0);
+ }
+ }
+
+ if (wglMakeCurrent(ghDC, ghRC[coreId]) == FALSE) {
+ assert(0);
+ }
+}
+
+void run()
+{
+ MSG msg;
+ while(true) {
+ while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) {
+ if (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ } else {
+ return;
+ }
+ }
+ }
+}
+
+int drcWidth() { return 854; }
+int drcHeight() { return 480; }
+int tvWidth() { return 1920; }
+int tvHeight() { return 1080; }
+
+}
+
}
#endif
diff --git a/src/processor.cpp b/src/processor.cpp
index c480342d..a0d2d432 100755
--- a/src/processor.cpp
+++ b/src/processor.cpp
@@ -69,6 +69,9 @@ void
Processor::coreEntryPoint(Core *core)
{
tCurrentCore = core;
+
+ platform::ui::initialiseCore(core->id);
+
core->primaryFiber = ConvertThreadToFiber(NULL);
while (mRunning) {