mirror of
https://github.com/holub/mame
synced 2025-04-23 08:49:55 +03:00
Skeleton implementation for Universal windows main app classes.
This commit is contained in:
parent
c4d91605fc
commit
ea0a6844f7
@ -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<wchar_t, osd_wstr_deleter> osd_unique_wstr;
|
||||
|
||||
#ifdef UNICODE
|
||||
#define tstring_from_utf8 wstring_from_utf8
|
||||
#define utf8_from_tstring utf8_from_wstring
|
||||
|
@ -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<Platform::String^>^)
|
||||
{
|
||||
auto app_source = ref new MameViewSource();
|
||||
Windows::ApplicationModel::Core::CoreApplication::Run(app_source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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<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
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#ifndef __WINDOWS_WINMAIN_H__
|
||||
#define __WINDOWS_WINMAIN_H__
|
||||
|
||||
#include <winapifamily.h>
|
||||
#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<windows_options> m_options;
|
||||
std::unique_ptr<windows_osd_interface> m_osd;
|
||||
std::unique_ptr<cli_frontend> 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
|
||||
|
Loading…
Reference in New Issue
Block a user