summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author arbee <rb6502@users.noreply.github.com>2018-05-06 21:22:30 -0400
committer arbee <rb6502@users.noreply.github.com>2018-05-06 21:22:30 -0400
commita823b5cc650531975af875be60cef8ca7b22ae88 (patch)
treea9d66b1416d13d7df15be4d54c3ee579858202de
parent6b0d4b91c7a0096f2d3aaaf1d249b6f5b0febd70 (diff)
Output system changes [headkaze, R. Belmont]
* Cleaned up syntax for network provider * Added pause and savestate commands to both network and win32 providers
-rw-r--r--src/osd/modules/output/network.cpp91
-rw-r--r--src/osd/modules/output/output_module.h3
-rw-r--r--src/osd/modules/output/win32_output.cpp25
-rw-r--r--src/osd/modules/output/win32_output.h4
4 files changed, 77 insertions, 46 deletions
diff --git a/src/osd/modules/output/network.cpp b/src/osd/modules/output/network.cpp
index 650a815a8ae..6c0af498204 100644
--- a/src/osd/modules/output/network.cpp
+++ b/src/osd/modules/output/network.cpp
@@ -43,9 +43,9 @@ public:
{
m_machine = &machine;
m_clients->insert(shared_from_this());
- // now send "hello = 1" to the newly connected client
- std::strncpy(m_data, "hello = 1\1", max_length);
- do_write(10);
+ // now send "mame_start = rom" to the newly connected client
+ std::snprintf(m_data, max_length, "mame_start = %s\r", machine.system().name);
+ do_write(std::strlen(m_data));
do_read();
}
@@ -58,44 +58,45 @@ private:
void handle_message(char *msg)
{
- char verb[1024];
- int value;
+ const char *equals_delimiter = " = ";
+ char *msg_name = strtok(msg, equals_delimiter);
+ char *msg_value = strtok(NULL, equals_delimiter);
- //printf("handle_message: got [%s]\n", msg);
-
- std::uint32_t ch = 0;
- while (msg[ch] != ' ')
- {
- ch++;
- }
- msg[ch] = '\0';
- ch++;
- std::strncpy(verb, msg, sizeof(verb)-1);
- //printf("verb = [%s], ", verb);
-
- while (msg[ch] != ' ')
- {
- ch++;
- }
-
- ch++;
- value = atoi(&msg[ch]);
- //printf("value = %d\n", value);
-
- if (!std::strcmp(verb, "send_id"))
+ //printf("handle_message: msg_name [%s] msg_value [%s]\n", msg_name, msg_value);
+
+ if (std::strcmp(msg_name, "mame_message") == 0)
{
- if (value == 0)
- {
- std::snprintf(m_data, max_length, "req_id = %s\1", machine().system().name);
- }
- else
+ const char *comma_delimiter = ",";
+ msg_name = strtok(msg_value, comma_delimiter);
+ msg_value = strtok(NULL, comma_delimiter);
+ int id = atoi(msg_name);
+ int value = atoi(msg_value);
+
+ switch(id)
{
- std::snprintf(m_data, max_length, "req_id = %s\1", machine().output().id_to_name(value));
+ case IM_MAME_PAUSE:
+ if (value == 1 && !machine().paused())
+ {
+ machine().pause();
+ }
+ else if (value == 0 && machine().paused())
+ {
+ machine().resume();
+ }
+ break;
+ case IM_MAME_SAVESTATE:
+ if (value == 0)
+ {
+ machine().schedule_load("auto");
+ }
+ else if (value == 1)
+ {
+ machine().schedule_save("auto");
+ }
+ break;
}
-
- do_write(std::strlen(m_data));
- }
}
+}
void do_read()
{
@@ -105,16 +106,16 @@ private:
{
if (!ec)
{
- if (length > 0)
- {
- m_input_m_data[length] = '\0';
- handle_message(m_input_m_data);
- }
- do_read();
+ if (length > 0)
+ {
+ m_input_m_data[length] = '\0';
+ handle_message(m_input_m_data);
+ }
+ do_read();
}
else
{
- m_clients->erase(shared_from_this());
+ m_clients->erase(shared_from_this());
}
});
}
@@ -204,7 +205,7 @@ public:
virtual void exit() override
{
// tell clients MAME is shutting down
- notify("mamerun", 0);
+ notify("mame_stop", 1);
m_io_context->stop();
m_working_thread.join();
delete m_server;
@@ -216,7 +217,7 @@ public:
virtual void notify(const char *outname, int32_t value) override
{
static char buf[256];
- sprintf(buf, "%s = %d\1", ((outname==nullptr) ? "none" : outname), value);
+ sprintf(buf, "%s = %d\r", ((outname==nullptr) ? "none" : outname), value);
m_server->deliver_to_all(buf);
}
diff --git a/src/osd/modules/output/output_module.h b/src/osd/modules/output/output_module.h
index 54f19dfa905..53cc46135ac 100644
--- a/src/osd/modules/output/output_module.h
+++ b/src/osd/modules/output/output_module.h
@@ -17,6 +17,9 @@
#define OSD_OUTPUT_PROVIDER "output"
+#define IM_MAME_PAUSE 0
+#define IM_MAME_SAVESTATE 1
+
class output_module
{
public:
diff --git a/src/osd/modules/output/win32_output.cpp b/src/osd/modules/output/win32_output.cpp
index 34465659ce3..64ab54014e0 100644
--- a/src/osd/modules/output/win32_output.cpp
+++ b/src/osd/modules/output/win32_output.cpp
@@ -54,7 +54,7 @@ static UINT om_mame_register_client;
static UINT om_mame_unregister_client;
static UINT om_mame_get_id_string;
-
+static UINT im_mame_message;
//============================================================
// FUNCTION PROTOTYPES
@@ -124,6 +124,8 @@ int output_win32::init(const osd_options &options)
assert(om_mame_unregister_client != 0);
om_mame_get_id_string = RegisterWindowMessage(OM_MAME_GET_ID_STRING);
assert(om_mame_get_id_string != 0);
+ im_mame_message = RegisterWindowMessage(IM_MAME_MESSAGE);
+ assert(im_mame_message != 0);
// create a window
m_output_hwnd = CreateWindowEx(
@@ -218,6 +220,27 @@ static LRESULT CALLBACK output_window_proc(HWND wnd, UINT message, WPARAM wparam
// get a string for an ID
else if (message == om_mame_get_id_string)
return output.send_id_string((HWND)wparam, lparam);
+
+ // received a message
+ else if (message == im_mame_message)
+ {
+ switch(wparam)
+ {
+ case IM_MAME_PAUSE:
+ if (lparam == 1 && !output.machine().paused())
+ output.machine().pause();
+ else if (lparam == 0 && output.machine().paused())
+ output.machine().resume();
+ case IM_MAME_SAVESTATE:
+ if (lparam == 0)
+ output.machine().schedule_load("auto");
+ else if (lparam == 1)
+ output.machine().schedule_save("auto");
+ break;
+ }
+
+ return 0;
+ }
else
return DefWindowProc(wnd, message, wparam, lparam);
diff --git a/src/osd/modules/output/win32_output.h b/src/osd/modules/output/win32_output.h
index f82b24b59c5..6b52a164051 100644
--- a/src/osd/modules/output/win32_output.h
+++ b/src/osd/modules/output/win32_output.h
@@ -63,6 +63,10 @@
// LPARAM = ID you wish to know about
#define OM_MAME_GET_ID_STRING TEXT("MAMEOutputGetIDString")
+// IM_MAME_MESSAGE: send message to MAME
+// WPARAM = ID of the message
+// LPARAM = value
+#define IM_MAME_MESSAGE TEXT("MAMEInputMessage")
//
// These constants are used to identify WM_COPYDATA messages