natkeyboard: Remove from ioport_manager

This commit is contained in:
AJR 2020-12-26 13:38:14 -05:00
parent 43f569e58f
commit c04e2cbe0b
13 changed files with 41 additions and 38 deletions

View File

@ -183,6 +183,9 @@ machine.render (read-only)
machine.debugger (read-only)
The :ref:`debugger manager <luareference-debug-manager>` for the current
emulation session, or ``nil`` if the debugger is not enabled.
machine.natkeyboard (read-only)
Gets the :ref:`natural keyboard manager <luareference-input-natkbd>`, used
for controlling keyboard and keypad input to the emulated system.
machine.options (read-only)
The user-specified :ref:`options <luareference-core-emuopts>` for the
current emulation session.
@ -1596,9 +1599,6 @@ ioport.ports[]
Gets the emulated :ref:`I/O ports <luareference-input-ioport>` in the
system. Keys are absolute tags. The ``at`` and ``index_of`` methods have
O(n) complexity; all other supported operations have O(1) complexity.
ioport.natkeyboard
Gets the :ref:`natural keyboard manager <luareference-input-natkbd>`, used
for controlling keyboard and keypad input to the emulated system.
.. _luareference-input-natkbd:
@ -1611,7 +1611,7 @@ keypad inputs.
Instantiation
^^^^^^^^^^^^^
manager.machine.ioport.natkeyboard
manager.machine.natkeyboard
Gets the global natural keyboard manager instance for the emulated machine.
Methods
@ -1675,7 +1675,7 @@ Represents a keyboard or keypad input device managed by the
Instantiation
^^^^^^^^^^^^^
manager.machine.ioport.natkeyboard.keyboards[tag]
manager.machine.natkeyboard.keyboards[tag]
Gets the keyboard input device with the specified tag, or ``nil`` if the tag
does not correspond to a keyboard input device.

View File

@ -320,7 +320,7 @@ void pc_keyboard_device::device_start()
memset(m_make, 0, sizeof(m_make));
machine().ioport().natkeyboard().configure(
machine().natkeyboard().configure(
ioport_queue_chars_delegate(&pc_keyboard_device::queue_chars, this),
ioport_accept_char_delegate(&pc_keyboard_device::accept_char, this),
ioport_charqueue_empty_delegate(&pc_keyboard_device::charqueue_empty, this));

View File

@ -3930,7 +3930,7 @@ void debugger_commands::execute_unmount(int ref, const std::vector<std::string>
void debugger_commands::execute_input(int ref, const std::vector<std::string> &params)
{
m_machine.ioport().natkeyboard().post_coded(params[0].c_str());
m_machine.natkeyboard().post_coded(params[0].c_str());
}
@ -3956,7 +3956,7 @@ void debugger_commands::execute_dumpkbd(int ref, const std::vector<std::string>
}
// loop through all codes
std::string buffer = m_machine.ioport().natkeyboard().dump();
std::string buffer = m_machine.natkeyboard().dump();
// and output it as appropriate
if (file != nullptr)

View File

@ -78,7 +78,7 @@ class crosshair_manager;
// declared in debug/debugcmd.h
class debugger_commands;
// declared in debug/debugcmd.h
// declared in debug/debugcon.h
class debugger_console;
// declared in debug/debugcpu.h

View File

@ -1732,9 +1732,6 @@ time_t ioport_manager::initialize()
break;
}
// initialize natural keyboard
m_natkeyboard = std::make_unique<natural_keyboard>(machine());
// register callbacks for when we load configurations
machine().configuration().config_register("input", config_load_delegate(&ioport_manager::load_config, this), config_save_delegate(&ioport_manager::save_config, this));
@ -2128,6 +2125,7 @@ void ioport_manager::load_config(config_type cfg_type, util::xml::data_node cons
{
std::vector<bool> kbd_enable_set;
bool keyboard_enabled = false, missing_enabled = false;
natural_keyboard &natkbd = machine().natkeyboard();
for (util::xml::data_node const *kbdnode = parentnode->get_child("keyboard"); kbdnode; kbdnode = kbdnode->get_next_sibling("keyboard"))
{
char const *const tag = kbdnode->get_attribute_string("tag", nullptr);
@ -2135,48 +2133,48 @@ void ioport_manager::load_config(config_type cfg_type, util::xml::data_node cons
if (tag && (0 <= enabled))
{
size_t i;
for (i = 0; natkeyboard().keyboard_count() > i; ++i)
for (i = 0; natkbd.keyboard_count() > i; ++i)
{
if (!strcmp(natkeyboard().keyboard_device(i).tag(), tag))
if (!strcmp(natkbd.keyboard_device(i).tag(), tag))
{
if (kbd_enable_set.empty())
kbd_enable_set.resize(natkeyboard().keyboard_count(), false);
kbd_enable_set.resize(natkbd.keyboard_count(), false);
kbd_enable_set[i] = true;
if (enabled)
{
if (!natkeyboard().keyboard_is_keypad(i))
if (!natkbd.keyboard_is_keypad(i))
keyboard_enabled = true;
natkeyboard().enable_keyboard(i);
natkbd.enable_keyboard(i);
}
else
{
natkeyboard().disable_keyboard(i);
natkbd.disable_keyboard(i);
}
break;
}
}
missing_enabled = missing_enabled || (enabled && (natkeyboard().keyboard_count() <= i));
missing_enabled = missing_enabled || (enabled && (natkbd.keyboard_count() <= i));
}
}
// if keyboard enable configuration was loaded, patch it up for principle of least surprise
if (!kbd_enable_set.empty())
{
for (size_t i = 0; natkeyboard().keyboard_count() > i; ++i)
for (size_t i = 0; natkbd.keyboard_count() > i; ++i)
{
if (!natkeyboard().keyboard_is_keypad(i))
if (!natkbd.keyboard_is_keypad(i))
{
if (!keyboard_enabled && missing_enabled)
{
natkeyboard().enable_keyboard(i);
natkbd.enable_keyboard(i);
keyboard_enabled = true;
}
else if (!kbd_enable_set[i])
{
if (keyboard_enabled)
natkeyboard().disable_keyboard(i);
natkbd.disable_keyboard(i);
else
natkeyboard().enable_keyboard(i);
natkbd.enable_keyboard(i);
keyboard_enabled = true;
}
}
@ -2422,11 +2420,12 @@ void ioport_manager::save_default_inputs(util::xml::data_node &parentnode)
void ioport_manager::save_game_inputs(util::xml::data_node &parentnode)
{
// save keyboard enable/disable state
for (size_t i = 0; natkeyboard().keyboard_count() > i; ++i)
natural_keyboard &natkbd = machine().natkeyboard();
for (size_t i = 0; natkbd.keyboard_count() > i; ++i)
{
util::xml::data_node *const kbdnode = parentnode.add_child("keyboard", nullptr);
kbdnode->set_attribute("tag", natkeyboard().keyboard_device(i).tag());
kbdnode->set_attribute_int("enabled", natkeyboard().keyboard_enabled(i));
kbdnode->set_attribute("tag", natkbd.keyboard_device(i).tag());
kbdnode->set_attribute_int("enabled", natkbd.keyboard_enabled(i));
}
// iterate over ports

View File

@ -1389,7 +1389,6 @@ public:
running_machine &machine() const noexcept { return m_machine; }
const ioport_list &ports() const noexcept { return m_portlist; }
bool safe_to_read() const noexcept { return m_safe_to_read; }
natural_keyboard &natkeyboard() noexcept { assert(m_natkeyboard != nullptr); return *m_natkeyboard; }
// type helpers
const std::vector<input_type_entry> &types() const noexcept { return m_typelist; }
@ -1459,7 +1458,6 @@ private:
// specific special global input states
simple_list<digital_joystick> m_joystick_list; // list of digital joysticks
std::unique_ptr<natural_keyboard> m_natkeyboard; // natural keyboard support
// frame time tracking
attotime m_last_frame_time; // time of the last frame callback

View File

@ -84,6 +84,7 @@
#include "network.h"
#include "romload.h"
#include "tilemap.h"
#include "natkeyboard.h"
#include "ui/uimain.h"
#include <ctime>
#include <rapidjson/writer.h>
@ -218,6 +219,9 @@ void running_machine::start()
if (newbase != 0)
m_base_time = newbase;
// initialize natural keyboard support after ports have been initialized
m_natkeyboard = std::make_unique<natural_keyboard>(*this);
// initialize the streams engine before the sound devices start
m_sound = std::make_unique<sound_manager>(*this);

View File

@ -188,6 +188,7 @@ public:
tilemap_manager &tilemap() const { assert(m_tilemap != nullptr); return *m_tilemap; }
debug_view_manager &debug_view() const { assert(m_debug_view != nullptr); return *m_debug_view; }
debugger_manager &debugger() const { assert(m_debugger != nullptr); return *m_debugger; }
natural_keyboard &natkeyboard() noexcept { assert(m_natkeyboard != nullptr); return *m_natkeyboard; }
template <class DriverClass> DriverClass *driver_data() const { return &downcast<DriverClass &>(root_device()); }
machine_phase phase() const { return m_current_phase; }
bool paused() const { return m_paused || (m_current_phase != machine_phase::RUNNING); }
@ -336,6 +337,7 @@ private:
std::unique_ptr<image_manager> m_image; // internal data from image.cpp
std::unique_ptr<rom_load_manager> m_rom_load; // internal data from romload.cpp
std::unique_ptr<debugger_manager> m_debugger; // internal data from debugger.cpp
std::unique_ptr<natural_keyboard> m_natkeyboard; // internal data from natkeyboard.cpp
// system state
machine_phase m_current_phase; // current execution phase

View File

@ -717,7 +717,7 @@ void lua_engine::initialize()
emu["gamename"] = [this] () { return machine().system().type.fullname(); };
emu["romname"] = [this] () { return machine().basename(); };
emu["softname"] = [this] () { return machine().options().software_name(); };
emu["keypost"] = [this] (const char *keys) { machine().ioport().natkeyboard().post_utf8(keys); };
emu["keypost"] = [this] (const char *keys) { machine().natkeyboard().post_utf8(keys); };
emu["time"] = [this] () { return machine().time().as_double(); };
emu["start"] =
[this](const char *driver)
@ -1287,6 +1287,7 @@ void lua_engine::initialize()
else
return sol::lua_nil;
});
machine_type["natkeyboard"] = sol::property(&running_machine::natkeyboard);
machine_type["paused"] = sol::property(&running_machine::paused);
machine_type["samplerate"] = sol::property(&running_machine::sample_rate);
machine_type["exit_pending"] = sol::property(&running_machine::exit_pending);

View File

@ -170,7 +170,6 @@ void lua_engine::initialize_input(sol::table &emu)
&ioport_manager::input_type_to_token,
[] (ioport_manager &im, ioport_type type) { return im.input_type_to_token(type, 0); });
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);
auto natkeyboard_type = sol().registry().new_usertype<natural_keyboard>("natkeyboard", sol::no_constructor);

View File

@ -30,7 +30,7 @@ menu_keyboard_mode::menu_keyboard_mode(mame_ui_manager &mui, render_container &c
void menu_keyboard_mode::populate(float &customtop, float &custombottom)
{
natural_keyboard &natkbd(machine().ioport().natkeyboard());
natural_keyboard &natkbd(machine().natkeyboard());
if (natkbd.can_post())
{
@ -69,7 +69,7 @@ void menu_keyboard_mode::handle()
event const *const menu_event(process(0));
if (menu_event && uintptr_t(menu_event->itemref))
{
natural_keyboard &natkbd(machine().ioport().natkeyboard());
natural_keyboard &natkbd(machine().natkeyboard());
uintptr_t const ref(uintptr_t(menu_event->itemref));
bool const left(IPT_UI_LEFT == menu_event->iptkey);
bool const right(IPT_UI_RIGHT == menu_event->iptkey);

View File

@ -109,7 +109,7 @@ void menu_main::populate(float &customtop, float &custombottom)
if (network_interface_enumerator(machine().root_device()).first() != nullptr)
item_append(_("Network Devices"), 0, (void*)NETWORK_DEVICES);
if (machine().ioport().natkeyboard().keyboard_count())
if (machine().natkeyboard().keyboard_count())
item_append(_("Keyboard Mode"), 0, (void *)KEYBOARD_MODE);
item_append(_("Slider Controls"), 0, (void *)SLIDERS);

View File

@ -992,7 +992,7 @@ void mame_ui_manager::process_natural_keyboard()
{
// if this was a UI_EVENT_CHAR event, post it
if (event.event_type == ui_event::type::IME_CHAR)
machine().ioport().natkeyboard().post_char(event.ch);
machine().natkeyboard().post_char(event.ch);
}
// process natural keyboard keys that don't get UI_EVENT_CHARs
@ -1015,7 +1015,7 @@ void mame_ui_manager::process_natural_keyboard()
*key_down_ptr |= key_down_mask;
// post the key
machine().ioport().natkeyboard().post_char(UCHAR_MAMEKEY_BEGIN + code.item_id());
machine().natkeyboard().post_char(UCHAR_MAMEKEY_BEGIN + code.item_id());
}
else if (!pressed && (*key_down_ptr & key_down_mask))
{
@ -1244,14 +1244,14 @@ uint32_t mame_ui_manager::handler_ingame(render_container &container)
}
// is the natural keyboard enabled?
if (machine().ioport().natkeyboard().in_use() && (machine().phase() == machine_phase::RUNNING))
if (machine().natkeyboard().in_use() && (machine().phase() == machine_phase::RUNNING))
process_natural_keyboard();
if (!ui_disabled)
{
// paste command
if (machine().ui_input().pressed(IPT_UI_PASTE))
machine().ioport().natkeyboard().paste();
machine().natkeyboard().paste();
}
image_handler_ingame();