summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2020-12-16 02:18:52 +1100
committer Vas Crabb <vas@vastheman.com>2020-12-16 02:18:52 +1100
commit503332a9867f9aa27fc77cd9e762626d22d213ef (patch)
treee60fba6664a3d980d5f62846982bde381a25c3f7 /src/frontend
parentb5f78fe38358b68fc54416328f764cf4e2bf3333 (diff)
-Lua cleanup and documentation migration checkpoint.
* Cleaned up some more of the Lua inteface. Mostly replacing methods with properties, some consistency fixes, a few renames, some more exposed functionality, and a couple of properties that have no business being set from scripts made read-only. * Moved a lot more Lua documentation out of source comments into the documentation, and expanded on it in the process. * Got more UI code out of the input manager. * Changed input sequence poller to a polymorphic class where you specify your intention upfront. * Changed the cheat plugin to use UI Clear to clear hotkey assignments and leave them unchanged if the user starts assignment but doesn't press any switches. * Ported AJR's fix for over-eager double-click recognition from SDL to Windows OSD. -goldnpkr.cpp: Cleaned up inputs, using standard keyout and payout types and key assignments.
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mame/iptseqpoll.cpp437
-rw-r--r--src/frontend/mame/iptseqpoll.h102
-rw-r--r--src/frontend/mame/luaengine.cpp44
-rw-r--r--src/frontend/mame/luaengine.ipp3
-rw-r--r--src/frontend/mame/luaengine_debug.cpp115
-rw-r--r--src/frontend/mame/luaengine_input.cpp248
-rw-r--r--src/frontend/mame/luaengine_mem.cpp270
-rw-r--r--src/frontend/mame/ui/inputmap.cpp22
-rw-r--r--src/frontend/mame/ui/inputmap.h2
-rw-r--r--src/frontend/mame/ui/pluginopt.cpp1
-rw-r--r--src/frontend/mame/ui/state.cpp5
-rw-r--r--src/frontend/mame/ui/state.h4
-rw-r--r--src/frontend/mame/ui/ui.cpp114
-rw-r--r--src/frontend/mame/ui/ui.h3
14 files changed, 706 insertions, 664 deletions
diff --git a/src/frontend/mame/iptseqpoll.cpp b/src/frontend/mame/iptseqpoll.cpp
index 8082b257e2f..145c64f033a 100644
--- a/src/frontend/mame/iptseqpoll.cpp
+++ b/src/frontend/mame/iptseqpoll.cpp
@@ -1,113 +1,299 @@
// license:BSD-3-Clause
-// copyright-holders:Vas Crabb,Aaron Giles
+// copyright-holders:Vas Crabb, Aaron Giles
#include "emu.h"
#include "iptseqpoll.h"
+#include "inputdev.h"
+
#include <cassert>
+#include <algorithm>
-input_sequence_poller::input_sequence_poller(input_manager &manager) noexcept :
- m_manager(manager),
- m_sequence(),
- m_class(ITEM_CLASS_INVALID),
- m_last_ticks(0),
- m_modified(false)
+input_code_poller::input_code_poller(input_manager &manager) noexcept :
+ m_manager(manager)
{
}
-void input_sequence_poller::start(input_item_class itemclass)
+input_code_poller::~input_code_poller()
{
- m_sequence.reset();
- do_start(itemclass);
}
-void input_sequence_poller::start(input_item_class itemclass, input_seq const &startseq)
+void input_code_poller::reset()
{
- // grab the starting sequence to append to, and append an OR if it isn't empty
- m_sequence = startseq;
- if (input_seq::end_code != m_sequence[0])
- m_sequence += input_seq::or_code;
+ // iterate over device classes and devices
+ for (input_device_class classno = DEVICE_CLASS_FIRST_VALID; DEVICE_CLASS_LAST_VALID >= classno; ++classno)
+ {
+ input_class &devclass(m_manager.device_class(classno));
+ for (int devnum = 0; devclass.maxindex() >= devnum; ++devnum)
+ {
+ // fetch the device; ignore if nullptr
+ input_device *const device(devclass.device(devnum));
+ if (device)
+ {
+ // iterate over items within each device
+ for (input_item_id itemid = ITEM_ID_FIRST_VALID; device->maxitem() >= itemid; ++itemid)
+ {
+ // for any non-switch items, set memory to the current value
+ input_device_item *const item(device->item(itemid));
+ if (item && (item->itemclass() != ITEM_CLASS_SWITCH))
+ item->set_memory(m_manager.code_value(item->code()));
+ }
+ }
+ }
+ }
+}
+
+
- do_start(itemclass);
+switch_code_poller_base::switch_code_poller_base(input_manager &manager) noexcept :
+ input_code_poller(manager),
+ m_switch_memory()
+{
}
-bool input_sequence_poller::poll()
+void switch_code_poller_base::reset()
{
- assert((ITEM_CLASS_SWITCH == m_class) || (ITEM_CLASS_ABSOLUTE == m_class) || (ITEM_CLASS_RELATIVE == m_class));
- int const curlen = m_sequence.length();
- input_code lastcode = m_sequence[curlen - 1];
+ m_switch_memory.clear();
+ input_code_poller::reset();
+}
+
+
+bool switch_code_poller_base::code_pressed_once(input_code code)
+{
+ // look for the code in the memory
+ bool const pressed(m_manager.code_pressed(code));
+ auto const found(std::lower_bound(m_switch_memory.begin(), m_switch_memory.end(), code));
+ if ((m_switch_memory.end() != found) && (*found == code))
+ {
+ // if no longer pressed, clear entry
+ if (!pressed)
+ m_switch_memory.erase(found);
+
+ // always return false
+ return false;
+ }
+
+ // if we get here, we were not previously pressed; if still not pressed, return false
+ if (!pressed)
+ return false;
+
+ // otherwise, add the code to the memory and return true
+ m_switch_memory.emplace(found, code);
+ return true;
+}
+
+
+
+axis_code_poller::axis_code_poller(input_manager &manager) noexcept :
+ input_code_poller(manager)
+{
+}
+
- input_code newcode;
- if (ITEM_CLASS_SWITCH == m_class)
+input_code axis_code_poller::poll()
+{
+ // iterate over device classes and devices, skipping disabled classes
+ for (input_device_class classno = DEVICE_CLASS_FIRST_VALID; DEVICE_CLASS_LAST_VALID >= classno; ++classno)
{
- // switch case: see if we have a new code to process
- newcode = m_manager.poll_switches();
- if (INPUT_CODE_INVALID != newcode)
+ input_class &devclass(m_manager.device_class(classno));
+ if (devclass.enabled())
{
- // if code is duplicate, toggle the NOT state on the code
- if (curlen && (newcode == lastcode))
+ for (int devnum = 0; devclass.maxindex() >= devnum; ++devnum)
{
- // back up over the existing code
- m_sequence.backspace();
-
- // if there was a NOT preceding it, delete it as well, otherwise append a fresh one
- if (m_sequence[curlen - 2] == input_seq::not_code)
- m_sequence.backspace();
- else
- m_sequence += input_seq::not_code;
+ // fetch the device; ignore if nullptr
+ input_device *const device(devclass.device(devnum));
+ if (device)
+ {
+ // iterate over items within each device
+ for (input_item_id itemid = ITEM_ID_FIRST_VALID; device->maxitem() >= itemid; ++itemid)
+ {
+ input_device_item *const item(device->item(itemid));
+ if (item && (item->itemclass() != ITEM_CLASS_SWITCH))
+ {
+ input_code const code = item->code();
+ if (item->check_axis(code.item_modifier()))
+ return code;
+ }
+ }
+ }
}
}
}
- else
+
+ // if nothing, return an invalid code
+ return INPUT_CODE_INVALID;
+}
+
+
+
+switch_code_poller::switch_code_poller(input_manager &manager) noexcept :
+ switch_code_poller_base(manager)
+{
+}
+
+
+input_code switch_code_poller::poll()
+{
+ // iterate over device classes and devices, skipping disabled classes
+ for (input_device_class classno = DEVICE_CLASS_FIRST_VALID; DEVICE_CLASS_LAST_VALID >= classno; ++classno)
{
- // absolute/relative case: see if we have an analog change of sufficient amount
- bool const has_or = input_seq::or_code == lastcode;
- if (has_or)
- lastcode = m_sequence[curlen - 2];
- newcode = m_manager.poll_axes();
-
- // if the last code doesn't match absolute/relative of this code, ignore the new one
- input_item_class const lastclass = lastcode.item_class();
- input_item_class const newclass = newcode.item_class();
- if (((ITEM_CLASS_ABSOLUTE == lastclass) && (ITEM_CLASS_ABSOLUTE != newclass)) ||
- ((ITEM_CLASS_RELATIVE == lastclass) && (ITEM_CLASS_RELATIVE != newclass)))
- newcode = INPUT_CODE_INVALID;
-
- // if the new code is valid, check for half-axis toggles on absolute controls
- if ((INPUT_CODE_INVALID != newcode) && curlen && (ITEM_CLASS_ABSOLUTE == newclass))
+ input_class &devclass(m_manager.device_class(classno));
+ if (devclass.enabled())
{
- input_code last_nomodifier = lastcode;
- last_nomodifier.set_item_modifier(ITEM_MODIFIER_NONE);
- if (newcode == last_nomodifier)
+ for (int devnum = 0; devclass.maxindex() >= devnum; ++devnum)
{
- // increment the modifier, wrapping back to none
- switch (lastcode.item_modifier())
+ // fetch the device; ignore if nullptr
+ input_device *const device(devclass.device(devnum));
+ if (device)
{
- case ITEM_MODIFIER_NONE:
- newcode.set_item_modifier(ITEM_MODIFIER_POS);
- break;
- case ITEM_MODIFIER_POS:
- newcode.set_item_modifier(ITEM_MODIFIER_NEG);
- break;
- default:
- case ITEM_MODIFIER_NEG:
- newcode.set_item_modifier(ITEM_MODIFIER_NONE);
- break;
+ // iterate over items within each device
+ for (input_item_id itemid = ITEM_ID_FIRST_VALID; device->maxitem() >= itemid; ++itemid)
+ {
+ input_device_item *const item(device->item(itemid));
+ if (item)
+ {
+ input_code code = item->code();
+ if (item->itemclass() == ITEM_CLASS_SWITCH)
+ {
+ // item is natively a switch, poll it
+ if (code_pressed_once(code))
+ return code;
+ }
+ else if (item->check_axis(code.item_modifier()))
+ {
+ // poll axes digitally
+ code.set_item_class(ITEM_CLASS_SWITCH);
+ if ((classno == DEVICE_CLASS_JOYSTICK) && (code.item_id() == ITEM_ID_XAXIS))
+ {
+ // joystick X axis - check with left/right modifiers
+ code.set_item_modifier(ITEM_MODIFIER_LEFT);
+ if (code_pressed_once(code))
+ return code;
+ code.set_item_modifier(ITEM_MODIFIER_RIGHT);
+ if (code_pressed_once(code))
+ return code;
+ }
+ else if ((classno == DEVICE_CLASS_JOYSTICK) && (code.item_id() == ITEM_ID_YAXIS))
+ {
+ // if this is a joystick Y axis, check with up/down modifiers
+ code.set_item_modifier(ITEM_MODIFIER_UP);
+ if (code_pressed_once(code))
+ return code;
+ code.set_item_modifier(ITEM_MODIFIER_DOWN);
+ if (code_pressed_once(code))
+ return code;
+ }
+ else
+ {
+ // any other axis, check with pos/neg modifiers
+ code.set_item_modifier(ITEM_MODIFIER_POS);
+ if (code_pressed_once(code))
+ return code;
+ code.set_item_modifier(ITEM_MODIFIER_NEG);
+ if (code_pressed_once(code))
+ return code;
+ }
+ }
+ }
+ }
}
+ }
+ }
+ }
- // back up over the previous code so we can re-append
- if (has_or)
- m_sequence.backspace();
- m_sequence.backspace();
+ // if nothing, return an invalid code
+ return INPUT_CODE_INVALID;
+}
+
+
+
+keyboard_code_poller::keyboard_code_poller(input_manager &manager) noexcept :
+ switch_code_poller_base(manager)
+{
+}
+
+
+input_code keyboard_code_poller::poll()
+{
+ // iterate over devices in keyboard class
+ input_class &devclass = m_manager.device_class(DEVICE_CLASS_KEYBOARD);
+ for (int devnum = 0; devclass.maxindex() >= devnum; ++devnum)
+ {
+ // fetch the device; ignore if nullptr
+ input_device *const device(devclass.device(devnum));
+ if (device)
+ {
+ // iterate over items within each device
+ for (input_item_id itemid = ITEM_ID_FIRST_VALID; itemid <= device->maxitem(); ++itemid)
+ {
+ // iterate over items within each device
+ for (input_item_id itemid = ITEM_ID_FIRST_VALID; device->maxitem() >= itemid; ++itemid)
+ {
+ input_device_item *const item = device->item(itemid);
+ if (item && (item->itemclass() == ITEM_CLASS_SWITCH))
+ {
+ input_code const code = item->code();
+ if (code_pressed_once(code))
+ return code;
+ }
+ }
}
}
}
+ // if nothing, return an invalid code
+ return INPUT_CODE_INVALID;
+}
+
+
+
+input_sequence_poller::input_sequence_poller() noexcept :
+ m_sequence(),
+ m_last_ticks(0),
+ m_modified(false)
+{
+}
+
+
+input_sequence_poller::~input_sequence_poller()
+{
+}
+
+
+void input_sequence_poller::start()
+{
+ // start with an empty sequence
+ m_sequence.reset();
+
+ // reset the recording count and the clock
+ m_last_ticks = 0;
+ m_modified = false;
+ do_start();
+}
+
+
+void input_sequence_poller::start(input_seq const &startseq)
+{
+ // grab the starting sequence to append to, and append an OR if it isn't empty
+ m_sequence = startseq;
+ if (input_seq::end_code != m_sequence[0])
+ m_sequence += input_seq::or_code;
+
+ // reset the recording count and the clock
+ m_last_ticks = 0;
+ m_modified = false;
+ do_start();
+}
+
+
+bool input_sequence_poller::poll()
+{
// if we got a new code to append it, append it and reset the timer
+ input_code const newcode = do_poll();
osd_ticks_t const newticks = osd_ticks();
if (INPUT_CODE_INVALID != newcode)
{
@@ -118,27 +304,116 @@ bool input_sequence_poller::poll()
// if we're recorded at least one item and 2/3 of a second has passed, we're done
if (m_last_ticks && ((m_last_ticks + (osd_ticks_per_second() * 2 / 3)) < newticks))
- {
- m_class = ITEM_CLASS_INVALID;
return true;
- }
// return false to indicate we are still polling
return false;
}
-void input_sequence_poller::do_start(input_item_class itemclass)
+
+axis_sequence_poller::axis_sequence_poller(input_manager &manager) noexcept :
+ input_sequence_poller(),
+ m_code_poller(manager)
{
- assert((ITEM_CLASS_SWITCH == itemclass) || (ITEM_CLASS_ABSOLUTE == itemclass) || (ITEM_CLASS_RELATIVE == itemclass));
+}
- // reset the recording count and the clock
- m_class = itemclass;
- m_last_ticks = 0;
- m_modified = false;
+void axis_sequence_poller::do_start()
+{
// wait for any inputs that are already active to be released
- m_manager.reset_polling();
+ m_code_poller.reset();
for (input_code dummycode = KEYCODE_ENTER; INPUT_CODE_INVALID != dummycode; )
- dummycode = (ITEM_CLASS_SWITCH == itemclass) ? m_manager.poll_switches() : m_manager.poll_axes();
+ dummycode = m_code_poller.poll();
+}
+
+
+input_code axis_sequence_poller::do_poll()
+{
+ // absolute/relative case: see if we have an analog change of sufficient amount
+ int const curlen = m_sequence.length();
+ input_code lastcode = m_sequence[curlen - 1];
+ bool const has_or = input_seq::or_code == lastcode;
+ if (has_or)
+ lastcode = m_sequence[curlen - 2];
+ input_code newcode = m_code_poller.poll();
+
+ // if the last code doesn't match absolute/relative of this code, ignore the new one
+ input_item_class const lastclass = lastcode.item_class();
+ input_item_class const newclass = newcode.item_class();
+ if (((ITEM_CLASS_ABSOLUTE == lastclass) && (ITEM_CLASS_ABSOLUTE != newclass)) ||
+ ((ITEM_CLASS_RELATIVE == lastclass) && (ITEM_CLASS_RELATIVE != newclass)))
+ newcode = INPUT_CODE_INVALID;
+
+ // if the new code is valid, check for half-axis toggles on absolute controls
+ if ((INPUT_CODE_INVALID != newcode) && curlen && (ITEM_CLASS_ABSOLUTE == newclass))
+ {
+ input_code last_nomodifier = lastcode;
+ last_nomodifier.set_item_modifier(ITEM_MODIFIER_NONE);
+ if (newcode == last_nomodifier)
+ {
+ // increment the modifier, wrapping back to none
+ switch (lastcode.item_modifier())
+ {
+ case ITEM_MODIFIER_NONE:
+ newcode.set_item_modifier(ITEM_MODIFIER_POS);
+ break;
+ case ITEM_MODIFIER_POS:
+ newcode.set_item_modifier(ITEM_MODIFIER_NEG);
+ break;
+ default:
+ case ITEM_MODIFIER_NEG:
+ newcode.set_item_modifier(ITEM_MODIFIER_NONE);
+ break;
+ }
+
+ // back up over the previous code so we can re-append
+ if (has_or)
+ m_sequence.backspace();
+ m_sequence.backspace();
+ }
+ }
+ return newcode;
+}
+
+
+
+switch_sequence_poller::switch_sequence_poller(input_manager &manager) noexcept :
+ input_sequence_poller(),
+ m_code_poller(manager)
+{
+}
+
+
+void switch_sequence_poller::do_start()
+{
+ // wait for any inputs that are already active to be released
+ m_code_poller.reset();
+ for (input_code dummycode = KEYCODE_ENTER; INPUT_CODE_INVALID != dummycode; )
+ dummycode = m_code_poller.poll();
+}
+
+
+input_code switch_sequence_poller::do_poll()
+{
+ // switch case: see if we have a new code to process
+ int const curlen = m_sequence.length();
+ input_code lastcode = m_sequence[curlen - 1];
+ input_code newcode = m_code_poller.poll();
+ if (INPUT_CODE_INVALID != newcode)
+ {
+ // if code is duplicate, toggle the NOT state on the code
+ if (curlen && (newcode == lastcode))
+ {
+ // back up over the existing code
+ m_sequence.backspace();
+
+ // if there was a NOT preceding it, delete it as well, otherwise append a fresh one
+ if (m_sequence[curlen - 2] == input_seq::not_code)
+ m_sequence.backspace();
+ else
+ m_sequence += input_seq::not_code;
+ }
+ }
+ return newcode;
}
diff --git a/src/frontend/mame/iptseqpoll.h b/src/frontend/mame/iptseqpoll.h
index e3083f7509a..13c0d9c6484 100644
--- a/src/frontend/mame/iptseqpoll.h
+++ b/src/frontend/mame/iptseqpoll.h
@@ -12,28 +12,116 @@
#pragma once
+#include <vector>
+
+
+class input_code_poller
+{
+public:
+ virtual ~input_code_poller();
+
+ virtual void reset();
+ virtual input_code poll() = 0;
+
+protected:
+ input_code_poller(input_manager &manager) noexcept;
+
+ input_manager &m_manager;
+};
+
+
+class switch_code_poller_base : public input_code_poller
+{
+public:
+ virtual void reset() override;
+
+protected:
+ switch_code_poller_base(input_manager &manager) noexcept;
+
+ bool code_pressed_once(input_code code);
+
+private:
+ std::vector<input_code> m_switch_memory;
+};
+
+
+class axis_code_poller : public input_code_poller
+{
+public:
+ axis_code_poller(input_manager &manager) noexcept;
+
+ virtual input_code poll() override;
+};
+
+
+class switch_code_poller : public switch_code_poller_base
+{
+public:
+ switch_code_poller(input_manager &manager) noexcept;
+
+ virtual input_code poll() override;
+};
+
+
+class keyboard_code_poller : public switch_code_poller_base
+{
+public:
+ keyboard_code_poller(input_manager &manager) noexcept;
+
+ virtual input_code poll() override;
+};
+
class input_sequence_poller
{
public:
- input_sequence_poller(input_manager &manager) noexcept;
+ virtual ~input_sequence_poller();
- void start(input_item_class itemclass);
- void start(input_item_class itemclass, input_seq const &startseq);
+ void start();
+ void start(input_seq const &startseq);
bool poll();
input_seq const &sequence() const noexcept { return m_sequence; }
bool valid() const noexcept { return m_sequence.is_valid(); }
bool modified() const noexcept { return m_modified; }
-private:
- void do_start(input_item_class itemclass);
+protected:
+ input_sequence_poller() noexcept;
- input_manager &m_manager;
input_seq m_sequence;
- input_item_class m_class;
+
+private:
+ virtual void do_start() = 0;
+ virtual input_code do_poll() = 0;
+
osd_ticks_t m_last_ticks;
bool m_modified;
};
+
+class axis_sequence_poller : public input_sequence_poller
+{
+public:
+ axis_sequence_poller(input_manager &manager) noexcept;
+
+private:
+ virtual void do_start() override;
+ virtual input_code do_poll() override;
+
+ axis_code_poller m_code_poller;
+};
+
+
+class switch_sequence_poller : public input_sequence_poller
+{
+public:
+ switch_sequence_poller(input_manager &manager) noexcept;
+
+private:
+ virtual void do_start() override;
+ virtual input_code do_poll() override;
+
+ switch_code_poller m_code_poller;
+};
+
#endif // MAME_FRONTEND_IPTSEQPOLL_H
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp
index 45e6367bdfc..4e7fb5412da 100644
--- a/src/frontend/mame/luaengine.cpp
+++ b/src/frontend/mame/luaengine.cpp
@@ -299,50 +299,6 @@ bool sol_lua_check(sol::types<osd_file::error>, lua_State *L, int index, Handler
return sol::stack::check<int>(L, index, std::forward<Handler>(handler));
}
-int sol_lua_push(sol::types<map_handler_type>, lua_State *L, map_handler_type &&value)
-{
- const char *typestr;
- switch(value)
- {
- case AMH_NONE:
- typestr = "none";
- break;
- case AMH_RAM:
- typestr = "ram";
- break;
- case AMH_ROM:
- typestr = "rom";
- break;
- case AMH_NOP:
- typestr = "nop";
- break;
- case AMH_UNMAP:
- typestr = "unmap";
- break;
- case AMH_DEVICE_DELEGATE:
- case AMH_DEVICE_DELEGATE_M:
- case AMH_DEVICE_DELEGATE_S:
- case AMH_DEVICE_DELEGATE_SM:
- case AMH_DEVICE_DELEGATE_MO:
- case AMH_DEVICE_DELEGATE_SMO:
- typestr = "delegate";
- break;
- case AMH_PORT:
- typestr = "port";
- break;
- case AMH_BANK:
- typestr = "bank";
- break;
- case AMH_DEVICE_SUBMAP:
- typestr = "submap";
- break;
- default:
- typestr = "unknown";
- break;
- }
- return sol::stack::push(L, typestr);
-}
-
//-------------------------------------------------
// process_snapshot_filename - processes a snapshot
diff --git a/src/frontend/mame/luaengine.ipp b/src/frontend/mame/luaengine.ipp
index 3c878b68c2a..d6ca0e981a0 100644
--- a/src/frontend/mame/luaengine.ipp
+++ b/src/frontend/mame/luaengine.ipp
@@ -268,6 +268,9 @@ bool sol_lua_check(sol::types<osd_file::error>, lua_State *L, int index, Handler
// map_handler_type customisation
int sol_lua_push(sol::types<map_handler_type>, lua_State *L, map_handler_type &&value);
+// endianness customisation
+int sol_lua_push(sol::types<map_handler_type>, lua_State *L, map_handler_type &&value);
+
template <typename T>
struct lua_engine::immutable_container_helper
diff --git a/src/frontend/mame/luaengine_debug.cpp b/src/frontend/mame/luaengine_debug.cpp
index aec17ada89b..7297a7f82a3 100644
--- a/src/frontend/mame/luaengine_debug.cpp
+++ b/src/frontend/mame/luaengine_debug.cpp
@@ -93,18 +93,6 @@ void lua_engine::initialize_debug(sol::table &emu)
};
-/* debugger_manager library (requires debugger to be active)
- *
- * manager:machine():debugger()
- *
- * debugger:command(command_string) - run command_string in debugger console
- *
- * debugger.consolelog[] - get consolelog text buffer (wrap_textbuf)
- * debugger.errorlog[] - get errorlog text buffer (wrap_textbuf)
- * debugger.visible_cpu - accessor for debugger active cpu for commands, affects debug views
- * debugger.execution_state - accessor for active cpu run state
- */
-
auto debugger_type = sol().registry().new_usertype<debugger_manager>("debugger", sol::no_constructor);
debugger_type["command"] = [] (debugger_manager &debug, std::string const &cmd) { debug.console().execute_command(cmd, false); };
debugger_type["consolelog"] = sol::property([] (debugger_manager &debug) { return wrap_textbuf(debug.console().get_console_textbuf()); });
@@ -116,7 +104,7 @@ void lua_engine::initialize_debug(sol::table &emu)
[] (debugger_manager &debug) { return debug.cpu().is_stopped() ? "stop" : "run"; },
[] (debugger_manager &debug, std::string const &state)
{
- if(state == "stop")
+ if (state == "stop")
debug.cpu().set_execution_stopped();
else
debug.cpu().set_execution_running();
@@ -139,27 +127,6 @@ void lua_engine::initialize_debug(sol::table &emu)
"__len", [](wrap_textbuf &buf) { return text_buffer_num_lines(buf.textbuf) + text_buffer_line_index_to_seqnum(buf.textbuf, 0) - 1; });
-/* device_debug library (requires debugger to be active)
- *
- * manager:machine().devices[device_tag]:debug()
- *
- * debug:step([opt] steps) - run cpu steps, default 1
- * debug:go() - run cpu
- * debug:bpset(addr, [opt] cond, [opt] act) - set breakpoint on addr, cond and act are debugger
- * expressions. returns breakpoint index
- * debug:bpclr(idx) - clear breakpoint
- * debug:bpenable(idx) - enable breakpoint
- * debug:bpdisable(idx) - disable breakpoint
- * debug:bplist()[] - table of breakpoints (k=index, v=debug_breakpoint)
- * debug:wpset(space, type, addr, len, [opt] cond, [opt] act) - set watchpoint, cond and act
- * are debugger expressions.
- * returns watchpoint index
- * debug:wpclr(idx) - clear watchpoint
- * debug:wpenable(idx) - enable watchpoint
- * debug:wpdisable(idx) - disable watchpoint
- * debug:wplist(space)[] - table of watchpoints (k=index, v=debug_watchpoint)
- */
-
auto device_debug_type = sol().registry().new_usertype<device_debug>("device_debug", sol::no_constructor);
device_debug_type["step"] =
[] (device_debug &dev, sol::object num)
@@ -178,32 +145,23 @@ void lua_engine::initialize_debug(sol::table &emu)
dev.device().machine().debug_view().update_all(DVT_BREAK_POINTS);
return result;
};
- device_debug_type["bpclear"] =
- [this] (device_debug &dev, sol::object index) -> sol::object
- {
- if (index == sol::lua_nil)
- {
- dev.breakpoint_clear_all();
- dev.device().machine().debug_view().update_all(DVT_DISASSEMBLY);
- dev.device().machine().debug_view().update_all(DVT_BREAK_POINTS);
- return sol::lua_nil;
- }
- else if (index.is<int>())
+ device_debug_type["bpclear"] = sol::overload(
+ [] (device_debug &dev, int index)
{
- bool result(dev.breakpoint_clear(index.as<int>()));
+ bool result(dev.breakpoint_clear(index));
if (result)
{
dev.device().machine().debug_view().update_all(DVT_DISASSEMBLY);
dev.device().machine().debug_view().update_all(DVT_BREAK_POINTS);
}
- return sol::make_object(sol(), result);
- }
- else
+ return result;
+ },
+ [] (device_debug &dev)
{
- osd_printf_error("[LUA ERROR] must call bpclear with integer or nil");
- return sol::lua_nil;
- }
- };
+ dev.breakpoint_clear_all();
+ dev.device().machine().debug_view().update_all(DVT_DISASSEMBLY);
+ dev.device().machine().debug_view().update_all(DVT_BREAK_POINTS);
+ });
device_debug_type["bpenable"] = [this] (device_debug &dev, sol::object index) { return do_breakpoint_enable(sol(), dev, index, true); };
device_debug_type["bpdisable"] = [this] (device_debug &dev, sol::object index) { return do_breakpoint_enable(sol(), dev, index, false); };
device_debug_type["bplist"] =
@@ -222,28 +180,19 @@ void lua_engine::initialize_debug(sol::table &emu)
dev.device().machine().debug_view().update_all(DVT_WATCH_POINTS);
return result;
};
- device_debug_type["wpclear"] =
- [this] (device_debug &dev, sol::object index) -> sol::object
- {
- if (index == sol::lua_nil)
- {
- dev.watchpoint_clear_all();
- dev.device().machine().debug_view().update_all(DVT_WATCH_POINTS);
- return sol::lua_nil;
- }
- else if (index.is<int>())
+ device_debug_type["wpclear"] = sol::overload(
+ [] (device_debug &dev, int index)
{
- bool result(dev.watchpoint_clear(index.as<int>()));
+ bool result(dev.watchpoint_clear(index));
if (result)
dev.device().machine().debug_view().update_all(DVT_WATCH_POINTS);
- return sol::make_object(sol(), result);
- }
- else
+ return result;
+ },
+ [] (device_debug &dev)
{
- osd_printf_error("[LUA ERROR] must call wpclear with integer or nil");
- return sol::lua_nil;
- }
- };
+ dev.watchpoint_clear_all();
+ dev.device().machine().debug_view().update_all(DVT_WATCH_POINTS);
+ });
device_debug_type["wpenable"] = [this] (device_debug &dev, sol::object index) { return do_watchpoint_enable(sol(), dev, index, true); };
device_debug_type["wpdisable"] = [this] (device_debug &dev, sol::object index) { return do_watchpoint_enable(sol(), dev, index, false); };
device_debug_type["wplist"] =
@@ -256,17 +205,6 @@ void lua_engine::initialize_debug(sol::table &emu)
};
-/* debug_breakpoint library (requires debugger to be active)
- *
- * manager:machine().devices[device_tag]:debug():bplist()[index]
- *
- * breakpoint.index - stable index of breakpoint
- * breakpoint.enabled - whether breakpoint is enabled
- * breakpoint.address -
- * breakpoint.condition -
- * breakpoint.action -
- */
-
auto breakpoint_type = sol().registry().new_usertype<debug_breakpoint>("breakpoint", sol::no_constructor);
breakpoint_type["index"] = sol::property(&debug_breakpoint::index);
breakpoint_type["enabled"] = sol::property(&debug_breakpoint::enabled);
@@ -275,19 +213,6 @@ void lua_engine::initialize_debug(sol::table &emu)
breakpoint_type["action"] = sol::property(&debug_breakpoint::action);
-/* debug_watchpoint library (requires debugger to be active)
- *
- * manager:machine().devices[device_tag]:debug():wplist()[index]
- *
- * watchpoint.index - stable index of watchpoint
- * watchpoint.enabled - whether breakpoint is enabled
- * watchpoint.type - type of access to watch ("r", "w" or "rw")
- * watchpoint.address - start of address range to watch
- * watchpoint.length - lenght of address range to watch
- * watchpoint.condition -
- * watchpoint.action -
- */
-
auto watchpoint_type = sol().registry().new_usertype<debug_watchpoint>("watchpoint", sol::no_constructor);
watchpoint_type["index"] = sol::property(&debug_watchpoint::index);
watchpoint_type["enabled"] = sol::property(&debug_watchpoint::enabled);
diff --git a/src/frontend/mame/luaengine_input.cpp b/src/frontend/mame/luaengine_input.cpp
index 77e002ce848..866117a29b2 100644
--- a/src/frontend/mame/luaengine_input.cpp
+++ b/src/frontend/mame/luaengine_input.cpp
@@ -140,43 +140,19 @@ void lua_engine::initialize_input(sol::table &emu)
};
-/* ioport_manager library
- *
- * manager:machine():ioport()
- *
- * ioport:count_players() - get count of player controllers
- * ioport:type_group(type, player)
- * ioport:type_seq(type, player, seqtype) - get input sequence for ioport type/player
- *
- * ioport.ports[] - ioports table (k=tag, v=ioport_port)
- * ioport.natkeyboard - get natural keyboard manager
- */
-
auto ioport_manager_type = sol().registry().new_usertype<ioport_manager>("ioport", sol::no_constructor);
ioport_manager_type["count_players"] = &ioport_manager::count_players;
ioport_manager_type["type_group"] = &ioport_manager::type_group;
- ioport_manager_type["type_seq"] = &ioport_manager::type_seq;
+ ioport_manager_type["type_seq"] =
+ [this] (ioport_manager &im, ioport_type type, int player, std::string const &seq_type_string)
+ {
+ input_seq_type seq_type = s_seq_type_parser(seq_type_string);
+ return im.type_seq(type, player, seq_type);
+ };
ioport_manager_type["ports"] = sol::property([] (ioport_manager &im) { return tag_object_ptr_map<ioport_list>(im.ports()); });
ioport_manager_type["natkeyboard"] = sol::property(&ioport_manager::natkeyboard);
-/* natural_keyboard library
- *
- * manager:machine():ioport().natkeyboard
- *
- * natkeyboard:post(text) - post data to natural keyboard
- * natkeyboard:post_coded(text) - post data to natural keyboard
- * natkeyboard:paste() - paste host clipboard text
- * natkeyboard:dump() - returns human-readable description of character mappings
- *
- * natkeyboard.empty - is the natural keyboard buffer empty?
- * natkeyboard.full - is the natural keyboard buffer full?
- * natkeyboard.can_post - does the system support posting characters via natural keyboard?
- * natkeyboard.is_posting - is a post operation currently in progress?
- * natkeyboard.in_use - is natural keyboard mode enabled (read/write)?
- * natkeyboard.keyboards[] - get keyboard devices in system (k=tag, v=natkbd_kbd_dev)
- */
-
auto natkeyboard_type = sol().registry().new_usertype<natural_keyboard>("natkeyboard", sol::no_constructor);
natkeyboard_type["post"] = [] (natural_keyboard &nat, std::string const &text) { nat.post_utf8(text); };
natkeyboard_type["post_coded"] = [] (natural_keyboard &nat, std::string const &text) { nat.post_coded(text); };
@@ -190,19 +166,6 @@ void lua_engine::initialize_input(sol::table &emu)
natkeyboard_type["keyboards"] = sol::property([] (natural_keyboard &nat) { return natkbd_kbd_list(nat); });
-/* natkbd_kbd_dev library
- *
- * manager:machine():ioport().natkeyboard.keyboards[tag]
- *
- * keyboard.device - underlying device that the inputs belong to
- * keyboard.tag - absolute tag of the device
- * keyboard.basetag - last component of the device tag ("root" for root device)
- * keyboard.name - device type full name
- * keyboard.shortname - device type short name
- * keyboard.is_keypad - does the device have keypad inputs but no keyboard inputs?
- * keyboard.enabled - are the device's keyboard/keypad inputs enabled (read/write)?
- */
-
auto natkbddev_type = sol().registry().new_usertype<natkbd_kbd_dev>("natkeyboard_device", sol::no_constructor);
natkbddev_type["device"] = sol::property([] (natkbd_kbd_dev const &kbd) -> device_t & { return kbd.manager.keyboard_device(kbd.index); });
natkbddev_type["tag"] = sol::property([] (natkbd_kbd_dev const &kbd) { return kbd.manager.keyboard_device(kbd.index).tag(); });
@@ -221,21 +184,6 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* ioport_port library
- *
- * manager:machine():ioport().ports[port_tag]
- *
- * port:read() - get port value
- * port:write(val, mask) - set port to value & mask (output fields only, for other fields use field:set_value(val))
- * port:field(mask) - get ioport_field for port and mask
- *
- * port.device - get device that the port belongs to
- * port.tag - get port tag
- * port.active - get port status
- * port.live - get port ioport_port_live (TODO: not usable from lua as of now)
- * port.fields[] - get ioport_field table (k=name, v=ioport_field)
- */
-
auto ioport_port_type = sol().registry().new_usertype<ioport_port>("ioport_port", "new", sol::no_constructor);
ioport_port_type["read"] = &ioport_port::read;
ioport_port_type["write"] = &ioport_port::write;
@@ -268,48 +216,6 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* ioport_field library
- *
- * manager:machine():ioport().ports[port_tag].fields[field_name]
- *
- * field:set_value(value)
- * field:set_input_seq(seq_type, seq)
- * field:input_seq(seq_type)
- * field:set_default_input_seq(seq_type, seq)
- * field:default_input_seq(seq_type)
- * field:keyboard_codes(which)
- *
- * field.device - get associated device_t
- * field.port - get associated ioport_port
- * field.live - get ioport_field_live
- * field.name
- * field.default_name
- * field.player
- * field.mask
- * field.defvalue
- * field.sensitivity
- * field.way - amount of available directions
- * field.type_class
- * field.is_analog
- * field.is_digital_joystick
- * field.enabled
- * field.optional
- * field.cocktail
- * field.toggle - whether field is a toggle
- * field.rotated
- * field.analog_reverse
- * field.analog_reset
- * field.analog_wraps
- * field.analog_invert
- * field.impulse
- * field.type
- * field.crosshair_scale
- * field.crosshair_offset
- * field.user_value
- *
- * field.settings[] - ioport_setting table (k=value, v=name)
- */
-
auto ioport_field_type = sol().registry().new_usertype<ioport_field>("ioport_field", sol::no_constructor);
ioport_field_type["set_value"] = &ioport_field::set_value;
ioport_field_type["set_input_seq"] =
@@ -350,6 +256,8 @@ void lua_engine::initialize_input(sol::table &emu)
};
ioport_field_type["device"] = sol::property(&ioport_field::device);
ioport_field_type["port"] = sol::property(&ioport_field::port);
+ ioport_field_type["live"] = sol::property(&ioport_field::live);
+ ioport_field_type["type"] = sol::property(&ioport_field::type);
ioport_field_type["name"] = sol::property(&ioport_field::name);
ioport_field_type["default_name"] = sol::property(
[] (ioport_field &f)
@@ -387,8 +295,6 @@ void lua_engine::initialize_input(sol::table &emu)
ioport_field_type["analog_wraps"] = sol::property(&ioport_field::analog_wraps);
ioport_field_type["analog_invert"] = sol::property(&ioport_field::analog_invert);
ioport_field_type["impulse"] = sol::property(&ioport_field::impulse);
- ioport_field_type["type"] = sol::property(&ioport_field::type);
- ioport_field_type["live"] = sol::property(&ioport_field::live);
ioport_field_type["crosshair_scale"] = sol::property(&ioport_field::crosshair_scale, &ioport_field::set_crosshair_scale);
ioport_field_type["crosshair_offset"] = sol::property(&ioport_field::crosshair_offset, &ioport_field::set_crosshair_offset);
ioport_field_type["user_value"] = sol::property(
@@ -416,37 +322,10 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* ioport_field_live library
- *
- * manager:machine():ioport().ports[port_tag].fields[field_name].live
- *
- * live.name
- */
-
auto ioport_field_live_type = sol().registry().new_usertype<ioport_field_live>("ioport_field_live", sol::no_constructor);
ioport_field_live_type["name"] = &ioport_field_live::name;
-/* input_manager library
- *
- * manager:machine():input()
- *
- * input:code_value(code) -
- * input:code_pressed(code) - get pressed state for input_code
- * input:code_pressed_once(code) -
- * input:code_name(code) - get code friendly name
- * input:code_to_token(code) - get KEYCODE_* string token for code
- * input:code_from_token(token) - get input_code for KEYCODE_* string token
- * input:seq_pressed(seq) - get pressed state for input_seq
- * input:seq_clean(seq) - clean the seq and remove invalid elements
- * input:seq_name(seq) - get seq friendly name
- * input:seq_to_tokens(seq) - get KEYCODE_* string tokens for seq
- * input:seq_from_tokens(tokens) - get input_seq for multiple space separated KEYCODE_* string tokens
- * input:sequence_poller() - get an input sequence poller
- *
- * input.device_classes[] - returns device classes (k=name, v=input_device_class)
- */
-
auto input_type = sol().registry().new_usertype<input_manager>("input", sol::no_constructor);
input_type["code_value"] = &input_manager::code_value;
input_type["code_pressed"] = &input_manager::code_pressed;
@@ -465,7 +344,11 @@ void lua_engine::initialize_input(sol::table &emu)
input.seq_from_tokens(seq, tokens);
return seq;
};
- input_type["sequence_poller"] = [] (input_manager &input) { return input_sequence_poller(input); };
+ input_type["axis_code_poller"] = [] (input_manager &input) { return std::unique_ptr<input_code_poller>(new axis_code_poller(input)); };
+ input_type["switch_code_poller"] = [] (input_manager &input) { return std::unique_ptr<input_code_poller>(new switch_code_poller(input)); };
+ input_type["keyboard_code_poller"] = [] (input_manager &input) { return std::unique_ptr<input_code_poller>(new keyboard_code_poller(input)); };
+ input_type["axis_sequence_poller"] = [] (input_manager &input) { return std::unique_ptr<input_sequence_poller>(new axis_sequence_poller(input)); };
+ input_type["switch_sequence_poller"] = [] (input_manager &input) { return std::unique_ptr<input_sequence_poller>(new switch_sequence_poller(input)); };
input_type["device_classes"] = sol::property(
[this] (input_manager &input)
{
@@ -479,60 +362,25 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* input_sequence_poller library
- *
- * manager:machine():input():seq_poll()
- *
- * poller:start(class, [opt] start_seq) - start polling for input_item_class passed as string
- * (switch/abs[olute]/rel[ative]/max[imum])
- * poller:poll() - poll once, returns true if input was fetched
- *
- * poller.sequence - get current input_seq
- * poller.valid - true if input sequence is valid
- * poller.modified - true if input sequence was modified
- */
+ auto codepoll_type = sol().registry().new_usertype<input_code_poller>("input_code_poller", sol::no_constructor);
+ codepoll_type["reset"] = &input_code_poller::reset;
+ codepoll_type["poll"] = &input_code_poller::poll;
+
auto seqpoll_type = sol().registry().new_usertype<input_sequence_poller>("input_seq_poller", sol::no_constructor);
- seqpoll_type["start"] =
- [] (input_sequence_poller &poller, char const *cls_string, sol::object seq)
- {
- input_item_class cls;
- if (!strcmp(cls_string, "switch"))
- cls = ITEM_CLASS_SWITCH;
- else if (!strcmp(cls_string, "absolute") || !strcmp(cls_string, "abs"))
- cls = ITEM_CLASS_ABSOLUTE;
- else if (!strcmp(cls_string, "relative") || !strcmp(cls_string, "rel"))
- cls = ITEM_CLASS_RELATIVE;
- else if (!strcmp(cls_string, "maximum") || !strcmp(cls_string, "max"))
- cls = ITEM_CLASS_MAXIMUM;
- else
- cls = ITEM_CLASS_INVALID;
-
- if (seq.is<sol::user<input_seq>>())
- poller.start(cls, seq.as<input_seq>());
- else
- poller.start(cls);
- };
+ seqpoll_type["start"] = sol::overload(
+ [] (input_sequence_poller &poller) { return poller.start(); },
+ [] (input_sequence_poller &poller, input_seq const &seq) { return poller.start(seq); });
seqpoll_type["poll"] = &input_sequence_poller::poll;
seqpoll_type["sequence"] = sol::property(&input_sequence_poller::sequence);
seqpoll_type["valid"] = sol::property(&input_sequence_poller::valid);
seqpoll_type["modified"] = sol::property(&input_sequence_poller::modified);
-/* input_class library
- *
- * manager:machine():input().device_classes[devclass]
- *
- * devclass.name
- * devclass.enabled
- * devclass.multi
- * devclass.devices[]
- */
-
- auto input_class_type = sol().registry().new_usertype<input_class>("input_class", "new", sol::no_constructor);
+ auto input_class_type = sol().registry().new_usertype<input_class>("input_class", sol::no_constructor);
input_class_type["name"] = sol::property(&input_class::name);
- input_class_type["enabled"] = sol::property(&input_class::enabled, &input_class::enable);
- input_class_type["multi"] = sol::property(&input_class::multi, &input_class::set_multi);
+ input_class_type["enabled"] = sol::property(&input_class::enabled);
+ input_class_type["multi"] = sol::property(&input_class::multi);
input_class_type["devices"] = sol::property(
[this] (input_class &devclass)
{
@@ -540,7 +388,7 @@ void lua_engine::initialize_input(sol::table &emu)
int index = 1;
for (int devindex = 0; devindex <= devclass.maxindex(); devindex++)
{
- input_device *dev = devclass.device(devindex);
+ input_device *const dev = devclass.device(devindex);
if (dev)
result[index++] = dev;
}
@@ -548,17 +396,7 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* input_device library
- *
- * manager:machine():input().device_classes[devclass].devices[index]
- *
- * device.name -
- * device.id -
- * device.devindex -
- * device.items[] -
- */
-
- auto input_device_type = sol().registry().new_usertype<input_device>("input_device", "new", sol::no_constructor);
+ auto input_device_type = sol().registry().new_usertype<input_device>("input_device", sol::no_constructor);
input_device_type["name"] = sol::property(&input_device::name);
input_device_type["id"] = sol::property(&input_device::id);
input_device_type["devindex"] = sol::property(&input_device::devindex);
@@ -576,40 +414,24 @@ void lua_engine::initialize_input(sol::table &emu)
});
-/* input_device_item library
- *
- * manager:machine():input().device_classes[devclass].devices[index].items[item_id]
- *
- * item.name -
- * item.code -
- * item.token -
- * item.current -
- */
-
- auto input_device_item_type = sol().registry().new_usertype<input_device_item>("input_device_item", "new", sol::no_constructor);
+ auto input_device_item_type = sol().registry().new_usertype<input_device_item>("input_device_item", sol::no_constructor);
input_device_item_type["name"] = sol::property(&input_device_item::name);
input_device_item_type["code"] = sol::property(&input_device_item::code);
input_device_item_type["token"] = sol::property(&input_device_item::token);
input_device_item_type["current"] = sol::property(&input_device_item::current);
-/* ui_input_manager library
- *
- * manager:machine():uiinput()
- *
- * uiinput:find_mouse() - return x, y, button state, ui render target
- * uiinput:pressed(key) - get pressed state for ui key
- * uiinput.presses_enabled - enable/disable ui key presses
- */
-
- auto uiinput_type = sol().registry().new_usertype<ui_input_manager>("uiinput", "new", sol::no_constructor);
- uiinput_type.set("find_mouse", [](ui_input_manager &ui) {
+ auto uiinput_type = sol().registry().new_usertype<ui_input_manager>("uiinput", sol::no_constructor);
+ uiinput_type["find_mouse"] =
+ [] (ui_input_manager &ui)
+ {
int32_t x, y;
bool button;
render_target *rt = ui.find_mouse(&x, &y, &button);
- return std::tuple<int32_t, int32_t, bool, render_target *>(x, y, button, rt);
- });
- uiinput_type.set("pressed", &ui_input_manager::pressed);
- uiinput_type.set("presses_enabled", sol::property(&ui_input_manager::presses_enabled, &ui_input_manager::set_presses_enabled));
+ return std::make_tuple(x, y, button, rt);
+ };
+ uiinput_type["pressed"] = &ui_input_manager::pressed;
+ uiinput_type["pressed_repeat"] = &ui_input_manager::pressed_repeat;
+ uiinput_type["presses_enabled"] = sol::property(&ui_input_manager::presses_enabled, &ui_input_manager::set_presses_enabled);
}
diff --git a/src/frontend/mame/luaengine_mem.cpp b/src/frontend/mame/luaengine_mem.cpp
index dc9abcbbb21..4016ce1d20f 100644
--- a/src/frontend/mame/luaengine_mem.cpp
+++ b/src/frontend/mame/luaengine_mem.cpp
@@ -14,24 +14,6 @@
namespace {
-
-template <typename T>
-std::string get_endianness_name(T const &obj)
-{
- std::string endianness;
- switch (obj.endianness())
- {
- case endianness_t::ENDIANNESS_BIG:
- endianness = "big";
- break;
- case endianness_t::ENDIANNESS_LITTLE:
- endianness = "little";
- break;
- }
- return endianness;
-}
-
-
//-------------------------------------------------
// region_read - templated region readers for <sign>,<size>
// -> manager:machine():memory().regions[":maincpu"]:read_i8(0xC000)
@@ -141,6 +123,77 @@ void share_write(memory_share &share, offs_t address, T val)
//-------------------------------------------------
+// sol_lua_push - automatically convert
+// map_handler_type to a string
+//-------------------------------------------------
+
+int sol_lua_push(sol::types<map_handler_type>, lua_State *L, map_handler_type &&value)
+{
+ const char *typestr;
+ switch(value)
+ {
+ case AMH_NONE:
+ typestr = "none";
+ break;
+ case AMH_RAM:
+ typestr = "ram";
+ break;
+ case AMH_ROM:
+ typestr = "rom";
+ break;
+ case AMH_NOP:
+ typestr = "nop";
+ break;
+ case AMH_UNMAP:
+ typestr = "unmap";
+ break;
+ case AMH_DEVICE_DELEGATE:
+ case AMH_DEVICE_DELEGATE_M:
+ case AMH_DEVICE_DELEGATE_S:
+ case AMH_DEVICE_DELEGATE_SM:
+ case AMH_DEVICE_DELEGATE_MO:
+ case AMH_DEVICE_DELEGATE_SMO:
+ typestr = "delegate";
+ break;
+ case AMH_PORT:
+ typestr = "port";
+ break;
+ case AMH_BANK:
+ typestr = "bank";
+ break;
+ case AMH_DEVICE_SUBMAP:
+ typestr = "submap";
+ break;
+ default:
+ typestr = "unknown";
+ break;
+ }
+ return sol::stack::push(L, typestr);
+}
+
+
+//-------------------------------------------------
+// sol_lua_push - automatically convert
+// endianness_t to a string
+//-------------------------------------------------
+
+int sol_lua_push(sol::types<endianness_t>, lua_State *L, endianness_t &&value)
+{
+ char const *endianness = "unknown";
+ switch (value)
+ {
+ case endianness_t::ENDIANNESS_BIG:
+ endianness = "big";
+ break;
+ case endianness_t::ENDIANNESS_LITTLE:
+ endianness = "little";
+ break;
+ }
+ return sol::stack::push(L, endianness);
+}
+
+
+//-------------------------------------------------
// mem_read - templated memory readers for <sign>,<size>
// -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000)
//-------------------------------------------------
@@ -356,36 +409,7 @@ void lua_engine::addr_space::direct_mem_write(offs_t address, T val)
void lua_engine::initialize_memory(sol::table &emu)
{
-/* addr_space library
- *
- * manager:machine().devices[device_tag].spaces[space]
- *
- * read/write by signedness u/i and bit-width 8/16/32/64:
- * space:read_*(addr)
- * space:write_*(addr, val)
- * space:read_log_*(addr)
- * space:write_log_*(addr, val)
- * space:read_direct_*(addr)
- * space:write_direct_*(addr, val)
- * space:read_range(first_addr, last_addr, width, [opt] step) - read range of addresses and
- * return as a binary string
- *
- * space.name - address space name
- * space.shift - address bus shift, bitshift required for a bytewise address
- * to map onto this space's address resolution (addressing granularity).
- * positive value means leftshift, negative means rightshift.
- * space.index
- * space.address_mask
- * space.data_width
- * space.endianness
- *
- * space.map[] - table of address map entries (k=index, v=address_map_entry)
- */
-
- auto addr_space_type = sol().registry().new_usertype<addr_space>(
- "addr_space",
- sol::call_constructor,
- sol::constructors<sol::types<address_space &, device_memory_interface &>>());
+ auto addr_space_type = sol().registry().new_usertype<addr_space>("addr_space", sol::no_constructor);
addr_space_type["read_i8"] = &addr_space::mem_read<s8>;
addr_space_type["read_u8"] = &addr_space::mem_read<u8>;
addr_space_type["read_i16"] = &addr_space::mem_read<s16>;
@@ -402,22 +426,22 @@ void lua_engine::initialize_memory(sol::table &emu)
addr_space_type["write_u32"] = &addr_space::mem_write<u32>;
addr_space_type["write_i64"] = &addr_space::mem_write<s64>;
addr_space_type["write_u64"] = &addr_space::mem_write<u64>;
- addr_space_type["read_log_i8"] = &addr_space::log_mem_read<s8>;
- addr_space_type["read_log_u8"] = &addr_space::log_mem_read<u8>;
- addr_space_type["read_log_i16"] = &addr_space::log_mem_read<s16>;
- addr_space_type["read_log_u16"] = &addr_space::log_mem_read<u16>;
- addr_space_type["read_log_i32"] = &addr_space::log_mem_read<s32>;
- addr_space_type["read_log_u32"] = &addr_space::log_mem_read<u32>;
- addr_space_type["read_log_i64"] = &addr_space::log_mem_read<s64>;
- addr_space_type["read_log_u64"] = &addr_space::log_mem_read<u64>;
- addr_space_type["write_log_i8"] = &addr_space::log_mem_write<s8>;
- addr_space_type["write_log_u8"] = &addr_space::log_mem_write<u8>;
- addr_space_type["write_log_i16"] = &addr_space::log_mem_write<s16>;
- addr_space_type["write_log_u16"] = &addr_space::log_mem_write<u16>;
- addr_space_type["write_log_i32"] = &addr_space::log_mem_write<s32>;
- addr_space_type["write_log_u32"] = &addr_space::log_mem_write<u32>;
- addr_space_type["write_log_i64"] = &addr_space::log_mem_write<s64>;
- addr_space_type["write_log_u64"] = &addr_space::log_mem_write<u64>;
+ addr_space_type["readv_i8"] = &addr_space::log_mem_read<s8>;
+ addr_space_type["readv_u8"] = &addr_space::log_mem_read<u8>;
+ addr_space_type["readv_i16"] = &addr_space::log_mem_read<s16>;
+ addr_space_type["readv_u16"] = &addr_space::log_mem_read<u16>;
+ addr_space_type["readv_i32"] = &addr_space::log_mem_read<s32>;
+ addr_space_type["readv_u32"] = &addr_space::log_mem_read<u32>;
+ addr_space_type["readv_i64"] = &addr_space::log_mem_read<s64>;
+ addr_space_type["readv_u64"] = &addr_space::log_mem_read<u64>;
+ addr_space_type["writev_i8"] = &addr_space::log_mem_write<s8>;
+ addr_space_type["writev_u8"] = &addr_space::log_mem_write<u8>;
+ addr_space_type["writev_i16"] = &addr_space::log_mem_write<s16>;
+ addr_space_type["writev_u16"] = &addr_space::log_mem_write<u16>;
+ addr_space_type["writev_i32"] = &addr_space::log_mem_write<s32>;
+ addr_space_type["writev_u32"] = &addr_space::log_mem_write<u32>;
+ addr_space_type["writev_i64"] = &addr_space::log_mem_write<s64>;
+ addr_space_type["writev_u64"] = &addr_space::log_mem_write<u64>;
addr_space_type["read_direct_i8"] = &addr_space::direct_mem_read<s8>;
addr_space_type["read_direct_u8"] = &addr_space::direct_mem_read<u8>;
addr_space_type["read_direct_i16"] = &addr_space::direct_mem_read<s16>;
@@ -435,7 +459,7 @@ void lua_engine::initialize_memory(sol::table &emu)
addr_space_type["write_direct_i64"] = &addr_space::direct_mem_write<s64>;
addr_space_type["write_direct_u64"] = &addr_space::direct_mem_write<u64>;
addr_space_type["read_range"] =
- [] (addr_space &sp, sol::this_state s, u64 first, u64 last, int width, sol::object opt_step)
+ [] (addr_space &sp, sol::this_state s, u64 first, u64 last, int width, sol::object opt_step) -> sol::object
{
lua_State *L = s;
luaL_Buffer buff;
@@ -447,13 +471,13 @@ void lua_engine::initialize_memory(sol::table &emu)
if (step < 1 || step > last - first)
{
luaL_error(L, "Invalid step");
- return sol::make_reference(L, nullptr);
+ return sol::lua_nil;
}
}
if (first > space_size || last > space_size || last < first)
{
luaL_error(L, "Invalid offset");
- return sol::make_reference(L, nullptr);
+ return sol::lua_nil;
}
int byte_count = width / 8 * (last - first + 1) / step;
switch (width)
@@ -488,7 +512,7 @@ void lua_engine::initialize_memory(sol::table &emu)
}
default:
luaL_error(L, "Invalid width. Must be 8/16/32/64");
- return sol::make_reference(L, nullptr);
+ return sol::lua_nil;
}
luaL_pushresultsize(&buff, byte_count);
return sol::make_reference(L, sol::stack_reference(L, -1));
@@ -498,44 +522,38 @@ void lua_engine::initialize_memory(sol::table &emu)
addr_space_type["index"] = sol::property([] (addr_space &sp) { return sp.space.spacenum(); });
addr_space_type["address_mask"] = sol::property([] (addr_space &sp) { return sp.space.addrmask(); });
addr_space_type["data_width"] = sol::property([] (addr_space &sp) { return sp.space.data_width(); });
- addr_space_type["endianness"] = sol::property([] (addr_space &sp) { return get_endianness_name(sp.space); });
-
-
-/* address_map_entry library
- *
- * manager:machine().devices[device_tag].spaces[space].map[entry_index]
- *
- * mapentry.offset - address start
- * mapentry.endoff - address end
- * mapentry.readtype
- * mapentry.writetype
- */
- addr_space_type["map"] = sol::property(
- [this] (addr_space &sp)
- {
- address_space &space = sp.space;
- sol::table map = sol().create_table();
- for (address_map_entry &entry : space.map()->m_entrylist)
- {
- sol::table mapentry = sol().create_table();
- mapentry["offset"] = entry.m_addrstart & space.addrmask();
- mapentry["endoff"] = entry.m_addrend & space.addrmask();
- mapentry["readtype"] = entry.m_read.m_type;
- mapentry["writetype"] = entry.m_write.m_type;
- map.add(mapentry);
- }
- return map;
- });
+ addr_space_type["endianness"] = sol::property([] (addr_space &sp) { return sp.space.endianness(); });
+ addr_space_type["map"] = sol::property([] (addr_space &sp) { return sp.space.map(); });
+
+ auto addrmap_type = sol().registry().new_usertype<address_map>("addrmap", sol::no_constructor);
+ addrmap_type["spacenum"] = sol::readonly(&address_map::m_spacenum);
+ addrmap_type["device"] = sol::readonly(&address_map::m_device);
+ addrmap_type["unmap_value"] = sol::readonly(&address_map::m_unmapval);
+ addrmap_type["global_mask"] = sol::readonly(&address_map::m_globalmask);
+ addrmap_type["entries"] = sol::property([] (address_map &m) { return simple_list_wrapper<address_map_entry>(m.m_entrylist); });
+
+
+ auto mapentry_type = sol().registry().new_usertype<address_map_entry>("mapentry", sol::no_constructor);
+ mapentry_type["address_start"] = sol::readonly(&address_map_entry::m_addrstart);
+ mapentry_type["address_end"] = sol::readonly(&address_map_entry::m_addrend);
+ mapentry_type["address_mirror"] = sol::readonly(&address_map_entry::m_addrmirror);
+ mapentry_type["address_mask"] = sol::readonly(&address_map_entry::m_addrmask);
+ mapentry_type["mask"] = sol::readonly(&address_map_entry::m_mask);
+ mapentry_type["cswidth"] = sol::readonly(&address_map_entry::m_cswidth);
+ mapentry_type["read"] = sol::readonly(&address_map_entry::m_read);
+ mapentry_type["write"] = sol::readonly(&address_map_entry::m_write);
+ mapentry_type["share"] = sol::readonly(&address_map_entry::m_share);
+ mapentry_type["region"] = sol::readonly(&address_map_entry::m_region);
+ mapentry_type["region_offset"] = sol::readonly(&address_map_entry::m_rgnoffs);
+
+
+ auto handler_data_type = sol().registry().new_usertype<map_handler_data>("handlerdata", sol::no_constructor);
+ handler_data_type["handlertype"] = sol::property([] (map_handler_data const &hd) { return hd.m_type; }); // can't use member pointer or won't be converted to string
+ handler_data_type["bits"] = sol::readonly(&map_handler_data::m_bits);
+ handler_data_type["name"] = sol::readonly(&map_handler_data::m_name);
+ handler_data_type["tag"] = sol::readonly(&map_handler_data::m_tag);
-/* memory_manager library
- *
- * manager:machine():memory()
- *
- * memory.banks[] - table of memory banks (k=tag, v=memory_bank)
- * memory.regions[] - table of memory regions (k=tag, v=memory_region)
- * memory.shares[] - table of memory shares (k=tag, v=memory_share)
- */
auto memory_type = sol().registry().new_usertype<memory_manager>("memory", sol::no_constructor);
memory_type["banks"] = sol::property([] (memory_manager &mm) { return standard_tag_object_ptr_map<memory_bank>(mm.banks()); });
@@ -543,35 +561,11 @@ void lua_engine::initialize_memory(sol::table &emu)
memory_type["shares"] = sol::property([] (memory_manager &mm) { return standard_tag_object_ptr_map<memory_share>(mm.shares()); });
-/* memory_bank library
- *
- * manager:machine():memory().banks[bank_tag]
- *
- * region.tag - absolute tag of the bank
- * bank.entry - get/set the selected entry
- */
-
auto bank_type = sol().registry().new_usertype<memory_bank>("membank", sol::no_constructor);
bank_type["tag"] = sol::property(&memory_bank::tag);
bank_type["entry"] = sol::property(&memory_bank::entry, &memory_bank::set_entry);
-/* memory_region library
- *
- * manager:machine():memory().regions[region_tag]
- *
- * read/write by signedness u/i and bit-width 8/16/32/64:
- * region:read_*(addr)
- * region:write_*(addr, val)
- *
- * region.tag - absolute tag of the region
- * region.size - size in bytes
- * region.length - length in items
- * region.endianness - endiannes as string ("big" or "little")
- * region.bitwidth - item width in bits
- * region.bytewidth - item width in bytes
- */
-
auto region_type = sol().registry().new_usertype<memory_region>("region", sol::no_constructor);
region_type["read_i8"] = &region_read<s8>;
region_type["read_u8"] = &region_read<u8>;
@@ -592,27 +586,11 @@ void lua_engine::initialize_memory(sol::table &emu)
region_type["tag"] = sol::property(&memory_region::name);
region_type["size"] = sol::property(&memory_region::bytes);
region_type["length"] = sol::property([] (memory_region &r) { return r.bytes() / r.bytewidth(); });
- region_type["endianness"] = sol::property(&get_endianness_name<memory_region>);
+ region_type["endianness"] = sol::property(&memory_region::endianness);
region_type["bitwidth"] = sol::property(&memory_region::bitwidth);
region_type["bytewidth"] = sol::property(&memory_region::bytewidth);
-/* memory_share library
- *
- * manager:machine():memory().shares[share_tag]
- *
- * read/write by signedness u/i and bit-width 8/16/32/64:
- * share:read_*(addr)
- * share:write_*(addr, val)
- *
- * share.tag - absolute tag of the share
- * share.size - size in bytes
- * share.length - length in items
- * region.endianness - endiannes as string ("big" or "little")
- * share.bitwidth - item width in bits
- * share.bytewidth - item width in bytes
-*/
-
auto share_type = sol().registry().new_usertype<memory_share>("share", sol::no_constructor);
share_type["read_i8"] = &share_read<s8>;
share_type["read_u8"] = &share_read<u8>;
@@ -633,7 +611,7 @@ void lua_engine::initialize_memory(sol::table &emu)
share_type["tag"] = sol::property(&memory_share::name);
share_type["size"] = sol::property(&memory_share::bytes);
share_type["length"] = sol::property([] (memory_share &s) { return s.bytes() / s.bytewidth(); });
- share_type["endianness"] = sol::property(&get_endianness_name<memory_share>);
+ share_type["endianness"] = sol::property(&memory_share::endianness);
share_type["bitwidth"] = sol::property(&memory_share::bitwidth);
share_type["bytewidth"] = sol::property(&memory_share::bytewidth);
diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp
index 0d49fc1ad29..94643849893 100644
--- a/src/frontend/mame/ui/inputmap.cpp
+++ b/src/frontend/mame/ui/inputmap.cpp
@@ -240,7 +240,7 @@ menu_input::menu_input(mame_ui_manager &mui, render_container &container)
: menu(mui, container)
, data()
, pollingitem(nullptr)
- , seq_poll(machine().input())
+ , seq_poll()
, errormsg()
, erroritem(nullptr)
, lastitem(nullptr)
@@ -269,7 +269,7 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float
{
if (pollingitem)
{
- const std::string seqname = machine().input().seq_name(seq_poll.sequence());
+ const std::string seqname = machine().input().seq_name(seq_poll->sequence());
char const *const text[] = { seqname.c_str() };
draw_text_box(
std::begin(text), std::end(text),
@@ -326,7 +326,7 @@ void menu_input::handle()
{
// if UI_CANCEL is pressed, abort
pollingitem = nullptr;
- if (!seq_poll.modified())
+ if (!seq_poll->modified())
{
// cancelled immediately - toggle between default and none
record_next = false;
@@ -338,14 +338,15 @@ void menu_input::handle()
// entered something before cancelling - abandon change
invalidate = true;
}
+ seq_poll.reset();
}
- else if (seq_poll.poll()) // poll again; if finished, update the sequence
+ else if (seq_poll->poll()) // poll again; if finished, update the sequence
{
pollingitem = nullptr;
- if (seq_poll.valid())
+ if (seq_poll->valid())
{
record_next = true;
- item->seq = seq_poll.sequence();
+ item->seq = seq_poll->sequence();
seqchangeditem = item;
}
else
@@ -355,6 +356,7 @@ void menu_input::handle()
errormsg = _("Invalid sequence entered");
erroritem = item;
}
+ seq_poll.reset();
}
}
else if (menu_event && menu_event->itemref)
@@ -369,10 +371,14 @@ void menu_input::handle()
pollingitem = &item;
lastitem = &item;
starting_seq = item.seq;
+ if (INPUT_TYPE_ANALOG == item.type)
+ seq_poll.reset(new axis_sequence_poller(machine().input()));
+ else
+ seq_poll.reset(new switch_sequence_poller(machine().input()));
if (record_next)
- seq_poll.start((item.type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, item.seq);
+ seq_poll->start(item.seq);
else
- seq_poll.start((item.type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH);
+ seq_poll->start();
invalidate = true;
break;
diff --git a/src/frontend/mame/ui/inputmap.h b/src/frontend/mame/ui/inputmap.h
index 01649b0b1ef..bdc1449c89b 100644
--- a/src/frontend/mame/ui/inputmap.h
+++ b/src/frontend/mame/ui/inputmap.h
@@ -70,7 +70,7 @@ protected:
input_item_data *pollingitem;
private:
- input_sequence_poller seq_poll;
+ std::unique_ptr<input_sequence_poller> seq_poll;
std::string errormsg;
input_item_data *erroritem;
input_item_data *lastitem;
diff --git a/src/frontend/mame/ui/pluginopt.cpp b/src/frontend/mame/ui/pluginopt.cpp
index 2fb36393ba7..90522bc48ae 100644
--- a/src/frontend/mame/ui/pluginopt.cpp
+++ b/src/frontend/mame/ui/pluginopt.cpp
@@ -18,6 +18,7 @@
namespace ui {
+
void menu_plugin::handle()
{
const event *menu_event = process(0);
diff --git a/src/frontend/mame/ui/state.cpp b/src/frontend/mame/ui/state.cpp
index 3064fd654dd..81c210cced2 100644
--- a/src/frontend/mame/ui/state.cpp
+++ b/src/frontend/mame/ui/state.cpp
@@ -84,6 +84,7 @@ menu_load_save_state_base::file_entry::file_entry(std::string &&file_name, std::
menu_load_save_state_base::menu_load_save_state_base(mame_ui_manager &mui, render_container &container, std::string_view header, std::string_view footer, bool must_exist)
: menu(mui, container)
+ , m_switch_poller(machine().input())
, m_header(header)
, m_footer(footer)
, m_must_exist(must_exist)
@@ -224,7 +225,7 @@ void menu_load_save_state_base::populate(float &customtop, float &custombottom)
machine().pause();
// get ready to poll inputs
- machine().input().reset_polling();
+ m_switch_poller.reset();
m_keys_released = false;
}
@@ -279,7 +280,7 @@ std::string menu_load_save_state_base::get_visible_name(const std::string &file_
std::string menu_load_save_state_base::poll_inputs()
{
- input_code const code = machine().input().poll_switches();
+ input_code const code = m_switch_poller.poll();
if (INPUT_CODE_INVALID == code)
{
m_keys_released = true;
diff --git a/src/frontend/mame/ui/state.h b/src/frontend/mame/ui/state.h
index 30bd9513bf3..cdf597db7d1 100644
--- a/src/frontend/mame/ui/state.h
+++ b/src/frontend/mame/ui/state.h
@@ -14,9 +14,12 @@
#include "ui/menu.h"
+#include "iptseqpoll.h"
+
#include <chrono>
#include <unordered_map>
+
namespace ui {
// ======================> menu_load_save_state_base
@@ -54,6 +57,7 @@ private:
static std::string s_last_file_selected;
+ switch_code_poller m_switch_poller;
std::unordered_map<std::string, file_entry> m_file_entries;
std::unordered_map<std::string, std::string> m_filename_to_code_map;
std::string_view const m_header;
diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp
index 5918d0e13d6..1273c5e92df 100644
--- a/src/frontend/mame/ui/ui.cpp
+++ b/src/frontend/mame/ui/ui.cpp
@@ -11,8 +11,9 @@
#include "emu.h"
#include "ui/ui.h"
-#include "luaengine.h"
#include "infoxml.h"
+#include "iptseqpoll.h"
+#include "luaengine.h"
#include "mame.h"
#include "ui/filemngr.h"
#include "ui/info.h"
@@ -110,7 +111,6 @@ static input_item_id const non_char_keys[] =
// messagebox buffer
std::string mame_ui_manager::messagebox_text;
std::string mame_ui_manager::messagebox_poptext;
-rgb_t mame_ui_manager::messagebox_backcolor;
// slider info
std::vector<ui::menu_item> mame_ui_manager::slider_list;
@@ -203,8 +203,13 @@ void mame_ui_manager::init()
update_target_font_height();
// more initialization
- using namespace std::placeholders;
- set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_messagebox, this, _1));
+ set_handler(
+ ui_callback_type::GENERAL,
+ [this] (render_container &container) -> uint32_t
+ {
+ draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, colors().background_color());
+ return 0;
+ });
m_non_char_keys_down = std::make_unique<uint8_t[]>((ARRAY_LENGTH(non_char_keys) + 7) / 8);
m_mouse_show = machine().system().flags & machine_flags::CLICKABLE_ARTWORK ? true : false;
@@ -406,31 +411,56 @@ void mame_ui_manager::display_startup_screens(bool first_time)
show_gameinfo = show_warnings = false;
#endif
- // loop over states
+ // set up event handlers
using namespace std::placeholders;
+ switch_code_poller poller(machine().input());
+ std::string warning_text;
+ rgb_t warning_color;
+ auto handler_messagebox_anykey =
+ [this, &poller, &warning_text, &warning_color] (render_container &container) -> uint32_t
+ {
+ // draw a standard message window
+ draw_text_box(container, warning_text, ui::text_layout::LEFT, 0.5f, 0.5f, warning_color);
+
+ if (machine().ui_input().pressed(IPT_UI_CANCEL))
+ {
+ // if the user cancels, exit out completely
+ machine().schedule_exit();
+ return UI_HANDLER_CANCEL;
+ }
+ else if (poller.poll() != INPUT_CODE_INVALID)
+ {
+ // if any key is pressed, just exit
+ return UI_HANDLER_CANCEL;
+ }
+
+ return 0;
+ };
set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_ingame, this, _1));
+
+ // loop over states
for (int state = 0; state < maxstate && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(machine()); state++)
{
// default to standard colors
- messagebox_backcolor = colors().background_color();
- messagebox_text.clear();
+ warning_color = colors().background_color();
+ warning_text.clear();
// pick the next state
switch (state)
{
case 0:
if (show_gameinfo)
- messagebox_text = machine_info().game_info_string();
- if (!messagebox_text.empty())
+ warning_text = machine_info().game_info_string();
+ if (!warning_text.empty())
{
- messagebox_text.append(_("\n\nPress any key to continue"));
- set_handler(ui_callback_type::MODAL, std::bind(&mame_ui_manager::handler_messagebox_anykey, this, _1));
+ warning_text.append(_("\n\nPress any key to continue"));
+ set_handler(ui_callback_type::MODAL, handler_messagebox_anykey);
}
break;
case 1:
- messagebox_text = machine_info().warnings_string();
- m_has_warnings = !messagebox_text.empty();
+ warning_text = machine_info().warnings_string();
+ m_has_warnings = !warning_text.empty();
if (show_warnings)
{
bool need_warning = m_has_warnings;
@@ -496,9 +526,9 @@ void mame_ui_manager::display_startup_screens(bool first_time)
}
if (need_warning)
{
- messagebox_text.append(_("\n\nPress any key to continue"));
- set_handler(ui_callback_type::MODAL, std::bind(&mame_ui_manager::handler_messagebox_anykey, this, _1));
- messagebox_backcolor = machine_info().warnings_color();
+ warning_text.append(_("\n\nPress any key to continue"));
+ set_handler(ui_callback_type::MODAL, handler_messagebox_anykey);
+ warning_color = machine_info().warnings_color();
}
}
break;
@@ -519,15 +549,13 @@ void mame_ui_manager::display_startup_screens(bool first_time)
break;
}
- // clear the input memory
- machine().input().reset_polling();
- while (machine().input().poll_switches() != INPUT_CODE_INVALID) { }
+ // clear the input memory and wait for all keys to be released
+ poller.reset();
+ while (poller.poll() != INPUT_CODE_INVALID) { }
// loop while we have a handler
while (m_handler_callback_type == ui_callback_type::MODAL && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(machine()))
- {
machine().video().frame_update();
- }
// clear the handler and force an update
set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_ingame, this, _1));
@@ -556,7 +584,6 @@ void mame_ui_manager::set_startup_text(const char *text, bool force)
// copy in the new text
messagebox_text.assign(text);
- messagebox_backcolor = colors().background_color();
// don't update more than 4 times/second
if (force || (curtime - lastupdatetime) > osd_ticks_per_second() / 4)
@@ -598,7 +625,7 @@ void mame_ui_manager::update_and_render(render_container &container)
// display any popup messages
if (osd_ticks() < m_popup_text_end)
- draw_text_box(container, messagebox_poptext, ui::text_layout::CENTER, 0.5f, 0.9f, messagebox_backcolor);
+ draw_text_box(container, messagebox_poptext, ui::text_layout::CENTER, 0.5f, 0.9f, colors().background_color());
else
m_popup_text_end = 0;
@@ -947,46 +974,6 @@ bool mame_ui_manager::is_menu_active(void)
***************************************************************************/
//-------------------------------------------------
-// handler_messagebox - displays the current
-// messagebox_text string but handles no input
-//-------------------------------------------------
-
-uint32_t mame_ui_manager::handler_messagebox(render_container &container)
-{
- draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, messagebox_backcolor);
- return 0;
-}
-
-
-//-------------------------------------------------
-// handler_messagebox_anykey - displays the
-// current messagebox_text string and waits for
-// any keypress
-//-------------------------------------------------
-
-uint32_t mame_ui_manager::handler_messagebox_anykey(render_container &container)
-{
- uint32_t state = 0;
-
- // draw a standard message window
- draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, messagebox_backcolor);
-
- // if the user cancels, exit out completely
- if (machine().ui_input().pressed(IPT_UI_CANCEL))
- {
- machine().schedule_exit();
- state = UI_HANDLER_CANCEL;
- }
-
- // if any key is pressed, just exit
- else if (machine().input().poll_switches() != INPUT_CODE_INVALID)
- state = UI_HANDLER_CANCEL;
-
- return state;
-}
-
-
-//-------------------------------------------------
// process_natural_keyboard - processes any
// natural keyboard input
//-------------------------------------------------
@@ -2232,7 +2219,6 @@ void mame_ui_manager::popup_time_string(int seconds, std::string message)
{
// extract the text
messagebox_poptext = message;
- messagebox_backcolor = colors().background_color();
// set a timer
m_popup_text_end = osd_ticks() + osd_ticks_per_second() * seconds;
diff --git a/src/frontend/mame/ui/ui.h b/src/frontend/mame/ui/ui.h
index d2fcd19d512..932957d9f9d 100644
--- a/src/frontend/mame/ui/ui.h
+++ b/src/frontend/mame/ui/ui.h
@@ -299,14 +299,11 @@ private:
// static variables
static std::string messagebox_text;
static std::string messagebox_poptext;
- static rgb_t messagebox_backcolor;
static std::vector<ui::menu_item> slider_list;
static slider_state *slider_current;
// UI handlers
- uint32_t handler_messagebox(render_container &container);
- uint32_t handler_messagebox_anykey(render_container &container);
uint32_t handler_ingame(render_container &container);
uint32_t handler_load_save(render_container &container, uint32_t state);
uint32_t handler_confirm_quit(render_container &container);