From ea0a6844f7d1afa89d7fbc6680e0bb5661417875 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Sun, 10 Apr 2016 17:18:23 -0400 Subject: [PATCH] Skeleton implementation for Universal windows main app classes. --- src/osd/strconv.h | 11 +++++ src/osd/windows/main.cpp | 17 +++++++ src/osd/windows/winmain.cpp | 98 +++++++++++++++++++++++++++++++++++++ src/osd/windows/winmain.h | 29 ++++++++++- 4 files changed, 153 insertions(+), 2 deletions(-) diff --git a/src/osd/strconv.h b/src/osd/strconv.h index 6d23d78fbb1..aaab2527d25 100644 --- a/src/osd/strconv.h +++ b/src/osd/strconv.h @@ -33,6 +33,17 @@ char *utf8_from_astring(const CHAR *s); WCHAR *wstring_from_utf8(const char *s); char *utf8_from_wstring(const WCHAR *s); +struct osd_wstr_deleter +{ + void operator () (wchar_t* wstr) + { + if (wstr != nullptr) + osd_free(wstr); + } +}; + +typedef std::unique_ptr osd_unique_wstr; + #ifdef UNICODE #define tstring_from_utf8 wstring_from_utf8 #define utf8_from_tstring utf8_from_wstring diff --git a/src/osd/windows/main.cpp b/src/osd/windows/main.cpp index 4ef0baf1c98..6e7717349bb 100644 --- a/src/osd/windows/main.cpp +++ b/src/osd/windows/main.cpp @@ -17,6 +17,8 @@ #include "strconv.h" +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + extern int utf8_main(int argc, char *argv[]); //============================================================ // main @@ -50,3 +52,18 @@ extern "C" int _tmain(int argc, TCHAR **argv) return rc; } #endif + +#else + +#include "winmain.h" + +// The main function is only used to initialize our IFrameworkView class. +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto app_source = ref new MameViewSource(); + Windows::ApplicationModel::Core::CoreApplication::Run(app_source); + return 0; +} + +#endif diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index 0f3df9566e0..7249c9ee747 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -33,6 +33,13 @@ #include "winutil.h" #include "debugger.h" #include "winfile.h" +#include "strconv.h" + +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +using namespace Windows::ApplicationModel; +using namespace Windows::ApplicationModel::Core; +using namespace Windows::UI::Popups; +#endif #define DEBUG_SLOW_LOCKS 0 @@ -219,6 +226,33 @@ public: } }; +#else + +//============================================================ +// winuniversal_output_error +//============================================================ + +class winuniversal_output_error : public osd_output +{ +public: + virtual void output_callback(osd_output_channel channel, const char *msg, va_list args) override + { + if (channel == OSD_OUTPUT_CHANNEL_ERROR) + { + char buffer[1024]; + vsnprintf(buffer, ARRAY_LENGTH(buffer), msg, args); + + osd_unique_wstr wcbuffer(wstring_from_utf8(buffer)); + osd_unique_wstr wcappname(wstring_from_utf8(emulator_info::get_appname())); + + auto dlg = ref new MessageDialog(ref new Platform::String(wcbuffer.get()), ref new Platform::String(wcappname.get())); + dlg->ShowAsync(); + } + else + chain_output(channel, msg, args); + } +}; + #endif @@ -474,6 +508,70 @@ static BOOL WINAPI control_handler(DWORD type) return TRUE; } +#else + +MameMainApp::MameMainApp() +{ +} + +void MameMainApp::Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView) +{ + // Register event handlers for app lifecycle. +} + +// Called when the CoreWindow object is created (or re-created). +void MameMainApp::SetWindow(Windows::UI::Core::CoreWindow^ window) +{ + // Attach event handlers on the window for input, etc. +} + +// Initializes scene resources, or loads a previously saved app state. +void MameMainApp::Load(Platform::String^ entryPoint) +{ +} + +void MameMainApp::Run() +{ + // use small output buffers on non-TTYs (i.e. pipes) + if (!isatty(fileno(stdout))) + setvbuf(stdout, (char *) nullptr, _IOFBF, 64); + if (!isatty(fileno(stderr))) + setvbuf(stderr, (char *) nullptr, _IOFBF, 64); + + // parse config and cmdline options + m_options = std::make_unique(); + m_osd = std::make_unique(m_options); + + // Since we're a GUI app, out errors to message boxes + // Initialize this after the osd interface so that we are first in the + // output order + winuniversal_output_error winerror; + osd_output::push(&winerror); + + m_osd->register_options(); + m_frontend = std::make_unique(*m_options.get(), *m_osd.get()); + + // To satisfy the latter things, pass in the module path name + char exe_path[MAX_PATH]; + GetModuleFileNameA(NULL, exe_path, MAX_PATH); + char* args[2] = { exe_path, (char*)"-verbose" }; + + DWORD result = m_frontend->execute(ARRAY_LENGTH(args), args); + osd_output::pop(&winerror); +} + +// Required for IFrameworkView. +void MameMainApp::Uninitialize() +{ + // Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView + // class is torn down while the app is in the foreground. +} + +IFrameworkView^ MameViewSource::CreateView() +{ + return ref new MameMainApp(); +} + #endif diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 075459d6bc5..f4d1a611191 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -9,6 +9,7 @@ #ifndef __WINDOWS_WINMAIN_H__ #define __WINDOWS_WINMAIN_H__ +#include #include "clifront.h" #include "osdepend.h" #include "modules/lib/osdobj_common.h" @@ -210,8 +211,6 @@ private: static const options_entry s_option_entries[]; }; - - //============================================================ // MACROS //============================================================ @@ -296,7 +295,33 @@ private: static const int DEFAULT_FONT_HEIGHT = 200; }; +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +ref class MameMainApp sealed : public Windows::ApplicationModel::Core::IFrameworkView +{ +private: + std::unique_ptr m_options; + std::unique_ptr m_osd; + std::unique_ptr m_frontend; + +public: + MameMainApp(); + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); + virtual void Load(Platform::String^ entryPoint); + virtual void Run(); + virtual void Uninitialize(); +}; + +ref class MameViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView(); +}; + +#endif //============================================================ // GLOBAL VARIABLES