diff options
Diffstat (limited to 'src/osd/windows/winmain.cpp')
-rw-r--r-- | src/osd/windows/winmain.cpp | 228 |
1 files changed, 170 insertions, 58 deletions
diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index 55cbde387e6..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 @@ -52,6 +59,8 @@ // TYPE DEFINITIONS //************************************************************************** +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + template<typename _FunctionPtr> class dynamic_bind { @@ -217,6 +226,34 @@ 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 @@ -231,21 +268,23 @@ int _CRT_glob = 0; // LOCAL VARIABLES //************************************************************************** +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) static LPTOP_LEVEL_EXCEPTION_FILTER pass_thru_filter; -static HANDLE watchdog_reset_event; -static HANDLE watchdog_exit_event; -static HANDLE watchdog_thread; +static sampling_profiler *profiler = nullptr; +static symbol_manager *symbols = nullptr; -static running_machine *g_current_machine; +bool stack_walker::s_initialized = false; static int timeresult = !TIMERR_NOERROR; static TIMECAPS timecaps; +#endif -static sampling_profiler *profiler = nullptr; -static symbol_manager *symbols = nullptr; +static HANDLE watchdog_reset_event; +static HANDLE watchdog_exit_event; +static HANDLE watchdog_thread; -bool stack_walker::s_initialized = false; +static running_machine *g_current_machine; //************************************************************************** @@ -374,6 +413,7 @@ const options_entry windows_options::s_option_entries[] = // MAIN ENTRY POINT //************************************************************************** +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) //============================================================ // utf8_main @@ -432,18 +472,6 @@ int main(int argc, char *argv[]) return result; } - -//============================================================ -// windows_options -//============================================================ - -windows_options::windows_options() -: osd_options() -{ - add_entries(s_option_entries); -} - - //============================================================ // control_handler //============================================================ @@ -453,12 +481,12 @@ static BOOL WINAPI control_handler(DWORD type) // indicate to the user that we detected something switch (type) { - case CTRL_C_EVENT: fprintf(stderr, "Caught Ctrl+C"); break; - case CTRL_BREAK_EVENT: fprintf(stderr, "Caught Ctrl+break"); break; - case CTRL_CLOSE_EVENT: fprintf(stderr, "Caught console close"); break; - case CTRL_LOGOFF_EVENT: fprintf(stderr, "Caught logoff"); break; - case CTRL_SHUTDOWN_EVENT: fprintf(stderr, "Caught shutdown"); break; - default: fprintf(stderr, "Caught unexpected console event"); break; + case CTRL_C_EVENT: fprintf(stderr, "Caught Ctrl+C"); break; + case CTRL_BREAK_EVENT: fprintf(stderr, "Caught Ctrl+break"); break; + case CTRL_CLOSE_EVENT: fprintf(stderr, "Caught console close"); break; + case CTRL_LOGOFF_EVENT: fprintf(stderr, "Caught logoff"); break; + case CTRL_SHUTDOWN_EVENT: fprintf(stderr, "Caught shutdown"); break; + default: fprintf(stderr, "Caught unexpected console event"); break; } // if we don't have a machine yet, or if we are handling ctrl+c/ctrl+break, @@ -480,7 +508,82 @@ 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<windows_options>(); + m_osd = std::make_unique<windows_osd_interface>(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<cli_frontend>(*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 + + +//============================================================ +// windows_options +//============================================================ + +windows_options::windows_options() +: osd_options() +{ + add_entries(s_option_entries); +} //============================================================ @@ -501,7 +604,6 @@ static void output_oslog(const running_machine &machine, const char *buffer) windows_osd_interface::windows_osd_interface(windows_options &options) : osd_common_t(options) , m_options(options) - , m_sliders(nullptr) { } @@ -592,11 +694,13 @@ void windows_osd_interface::init(running_machine &machine) if (options.oslog()) machine.add_logerror_callback(output_oslog); +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // crank up the multimedia timer resolution to its max // this gives the system much finer timeslices timeresult = timeGetDevCaps(&timecaps, sizeof(timecaps)); if (timeresult == TIMERR_NOERROR) timeBeginPeriod(timecaps.wPeriodMin); +#endif // if a watchdog thread is requested, create one int watchdog = options.watchdog(); @@ -611,11 +715,13 @@ void windows_osd_interface::init(running_machine &machine) } // create and start the profiler +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) if (profile > 0) { profiler = global_alloc(sampling_profiler(1000, profile - 1)); profiler->start(); } +#endif // initialize sockets win_init_sockets(); @@ -652,6 +758,7 @@ void windows_osd_interface::osd_exit() watchdog_thread = nullptr; } +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // stop the profiler if (profiler != nullptr) { @@ -663,43 +770,12 @@ void windows_osd_interface::osd_exit() // restore the timer resolution if (timeresult == TIMERR_NOERROR) timeEndPeriod(timecaps.wPeriodMin); +#endif // one last pass at events winwindow_process_events(machine(), 0, 0); } -//============================================================ -// winmain_dump_stack -//============================================================ - -void winmain_dump_stack() -{ - // set up the stack walker - stack_walker walker; - if (!walker.reset()) - return; - - // walk the stack - while (walker.unwind()) - fprintf(stderr, " %p: %p%s\n", (void *)walker.frame(), (void *)walker.ip(), (symbols == nullptr) ? "" : symbols->symbol_for_address(walker.ip())); -} - - -//============================================================ -// check_for_double_click_start -//============================================================ - -static int is_double_click_start(int argc) -{ - STARTUPINFO startup_info = { sizeof(STARTUPINFO) }; - - // determine our startup information - GetStartupInfo(&startup_info); - - // try to determine if MAME was simply double-clicked - return (argc <= 1 && startup_info.dwFlags && !(startup_info.dwFlags & STARTF_USESTDHANDLES)); -} - //============================================================ // watchdog_thread_entry @@ -751,6 +827,40 @@ void winmain_watchdog_ping(void) } +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +//============================================================ +// winmain_dump_stack +//============================================================ + +void winmain_dump_stack() +{ + // set up the stack walker + stack_walker walker; + if (!walker.reset()) + return; + + // walk the stack + while (walker.unwind()) + fprintf(stderr, " %p: %p%s\n", (void *)walker.frame(), (void *)walker.ip(), (symbols == nullptr) ? "" : symbols->symbol_for_address(walker.ip())); +} + + +//============================================================ +// check_for_double_click_start +//============================================================ + +static int is_double_click_start(int argc) +{ + STARTUPINFO startup_info = { sizeof(STARTUPINFO) }; + + // determine our startup information + GetStartupInfo(&startup_info); + + // try to determine if MAME was simply double-clicked + return (argc <= 1 && startup_info.dwFlags && !(startup_info.dwFlags & STARTF_USESTDHANDLES)); +} + //============================================================ // exception_filter //============================================================ @@ -1559,3 +1669,5 @@ void sampling_profiler::thread_run() Sleep(1); } } + +#endif
\ No newline at end of file |