From bdf4645b737d4fc350b21bd0d207ec1461d20f96 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Wed, 21 Dec 2022 08:26:53 +1100 Subject: bus/pce_ctrl: Added PC Engine Mouse support. --- scripts/src/bus.lua | 2 + src/devices/bus/pce_ctrl/joypad2.cpp | 1 + src/devices/bus/pce_ctrl/joypad2.h | 1 - src/devices/bus/pce_ctrl/joypad6.cpp | 96 +++++++++++++++++++++++- src/devices/bus/pce_ctrl/joypad6.h | 91 +---------------------- src/devices/bus/pce_ctrl/mouse.cpp | 137 +++++++++++++++++++++++++++++++++++ src/devices/bus/pce_ctrl/mouse.h | 18 +++++ src/devices/bus/pce_ctrl/pcectrl.cpp | 7 +- src/devices/bus/sms_ctrl/mouse.cpp | 2 + 9 files changed, 260 insertions(+), 95 deletions(-) create mode 100644 src/devices/bus/pce_ctrl/mouse.cpp create mode 100644 src/devices/bus/pce_ctrl/mouse.h diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index e954b19dc20..197b15c0f12 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -4068,6 +4068,8 @@ if (BUSES["PCE_CTRL"]~=null) then MAME_DIR .. "src/devices/bus/pce_ctrl/joypad2.h", MAME_DIR .. "src/devices/bus/pce_ctrl/joypad6.cpp", MAME_DIR .. "src/devices/bus/pce_ctrl/joypad6.h", + MAME_DIR .. "src/devices/bus/pce_ctrl/mouse.cpp", + MAME_DIR .. "src/devices/bus/pce_ctrl/mouse.h", MAME_DIR .. "src/devices/bus/pce_ctrl/multitap.cpp", MAME_DIR .. "src/devices/bus/pce_ctrl/multitap.h", MAME_DIR .. "src/devices/bus/pce_ctrl/pachinko.cpp", diff --git a/src/devices/bus/pce_ctrl/joypad2.cpp b/src/devices/bus/pce_ctrl/joypad2.cpp index 7e07f827b56..ff09eb8dbe9 100644 --- a/src/devices/bus/pce_ctrl/joypad2.cpp +++ b/src/devices/bus/pce_ctrl/joypad2.cpp @@ -69,6 +69,7 @@ INPUT_PORTS_START( pce_joypad2_turbo ) INPUT_PORTS_END + //************************************************************************** // TYPE DEFINITIONS //************************************************************************** diff --git a/src/devices/bus/pce_ctrl/joypad2.h b/src/devices/bus/pce_ctrl/joypad2.h index 2ad0e2727ec..008a9100825 100644 --- a/src/devices/bus/pce_ctrl/joypad2.h +++ b/src/devices/bus/pce_ctrl/joypad2.h @@ -13,7 +13,6 @@ #include "pcectrl.h" -// device type definition DECLARE_DEVICE_TYPE(PCE_JOYPAD2, device_pce_control_port_interface) DECLARE_DEVICE_TYPE(PCE_JOYPAD2_TURBO, device_pce_control_port_interface) diff --git a/src/devices/bus/pce_ctrl/joypad6.cpp b/src/devices/bus/pce_ctrl/joypad6.cpp index b11d400d5d1..ef5deb6d272 100644 --- a/src/devices/bus/pce_ctrl/joypad6.cpp +++ b/src/devices/bus/pce_ctrl/joypad6.cpp @@ -26,17 +26,94 @@ #include "emu.h" #include "joypad6.h" +#include "machine/74157.h" +namespace { + //************************************************************************** -// DEVICE DEFINITIONS +// TYPE DEFINITIONS //************************************************************************** -DEFINE_DEVICE_TYPE(PCE_AVENUE_PAD_6, pce_avenue_pad_6_device, "pce_avenue_pad_6", "NEC Avenue Pad 6") -DEFINE_DEVICE_TYPE(PCE_ARCADE_PAD_6, pce_arcade_pad_6_device, "pce_arcade_pad_6", "NEC Arcade Pad 6") +// ======================> pce_joypad6_base_device + +class pce_joypad6_base_device : public device_t, + public device_pce_control_port_interface +{ +public: + DECLARE_INPUT_CHANGED_MEMBER(joypad_mode_changed); + +protected: + // construction/destruction + pce_joypad6_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); + + // device-level overrides + virtual void device_add_mconfig(machine_config &config) override; + virtual void device_start() override; + virtual void device_reset() override; + + // device_pce_control_port_interface overrides + virtual u8 peripheral_r() override; + virtual void sel_w(int state) override; + virtual void clr_w(int state) override; + + // button handlers + void buttonset_update(); + + // devices + required_device_array m_muxer; + + // IO ports + required_ioport m_joypad_mode; + + // internal states + u8 m_counter; // buttonset select, autofire counter (74xx163 QA-QB pin) + bool m_prev_clr; // previous CLR pin state +}; + + +// ======================> pce_avenue_pad_6_device + +class pce_avenue_pad_6_device : public pce_joypad6_base_device +{ +public: + // construction/destruction + pce_avenue_pad_6_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); + +protected: + // construction/destruction + pce_avenue_pad_6_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); + + // optional information overrides + virtual ioport_constructor device_input_ports() const override; + // device-level overrides + virtual void device_add_mconfig(machine_config &config) override; -static INPUT_PORTS_START( pce_joypad6 ) + template u8 buttons_r(); + + // IO ports + required_ioport_array<2> m_buttons_io; + required_ioport m_turbo_io; +}; + + +// ======================> pce_arcade_pad_6_device + +class pce_arcade_pad_6_device : public pce_avenue_pad_6_device +{ +public: + // construction/destruction + pce_arcade_pad_6_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); + +protected: + // optional information overrides + virtual ioport_constructor device_input_ports() const override; +}; + + + +INPUT_PORTS_START( pce_joypad6 ) // Action button order on original pad is bottom row: III, II, I, and top row: IV, V, VI PORT_START("BUTTONS_0") PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("%p Button I") @@ -298,3 +375,14 @@ u8 pce_avenue_pad_6_device::buttons_r() } return ret; } + +} // anonymous namespace + + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE_PRIVATE(PCE_AVENUE_PAD_6, device_pce_control_port_interface, pce_avenue_pad_6_device, "pce_avenue_pad_6", "NEC Avenue Pad 6") +DEFINE_DEVICE_TYPE_PRIVATE(PCE_ARCADE_PAD_6, device_pce_control_port_interface, pce_arcade_pad_6_device, "pce_arcade_pad_6", "NEC Arcade Pad 6") diff --git a/src/devices/bus/pce_ctrl/joypad6.h b/src/devices/bus/pce_ctrl/joypad6.h index fedac375a22..88d83b4e3c2 100644 --- a/src/devices/bus/pce_ctrl/joypad6.h +++ b/src/devices/bus/pce_ctrl/joypad6.h @@ -5,102 +5,15 @@ NEC PC Engine/TurboGrafx-16 6 Button Joypad emulation **********************************************************************/ - #ifndef MAME_BUS_PCE_CTRL_JOYPAD6_H #define MAME_BUS_PCE_CTRL_JOYPAD6_H #pragma once - -#include "machine/74157.h" #include "pcectrl.h" - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// ======================> pce_joypad6_base_device - -class pce_joypad6_base_device : public device_t, - public device_pce_control_port_interface -{ -public: - DECLARE_INPUT_CHANGED_MEMBER(joypad_mode_changed); - -protected: - // construction/destruction - pce_joypad6_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); - - // device-level overrides - virtual void device_add_mconfig(machine_config &config) override; - virtual void device_start() override; - virtual void device_reset() override; - - // device_pce_control_port_interface overrides - virtual u8 peripheral_r() override; - virtual void sel_w(int state) override; - virtual void clr_w(int state) override; - - // button handlers - void buttonset_update(); - - // devices - required_device_array m_muxer; - - // IO ports - required_ioport m_joypad_mode; - - // internal states - u8 m_counter; // buttonset select, autofire counter (74xx163 QA-QB pin) - bool m_prev_clr; // previous CLR pin state -}; - - -// ======================> pce_avenue_pad_6_device - -class pce_avenue_pad_6_device : public pce_joypad6_base_device -{ -public: - // construction/destruction - pce_avenue_pad_6_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - -protected: - // construction/destruction - pce_avenue_pad_6_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); - - // optional information overrides - virtual ioport_constructor device_input_ports() const override; - - // device-level overrides - virtual void device_add_mconfig(machine_config &config) override; - - template u8 buttons_r(); - - // IO ports - required_ioport_array<2> m_buttons_io; - required_ioport m_turbo_io; -}; - - -// ======================> pce_arcade_pad_6_device - -class pce_arcade_pad_6_device : public pce_avenue_pad_6_device -{ -public: - // construction/destruction - pce_arcade_pad_6_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - -protected: - // optional information overrides - virtual ioport_constructor device_input_ports() const override; -}; - - -// device type definition -DECLARE_DEVICE_TYPE(PCE_AVENUE_PAD_6, pce_avenue_pad_6_device) -DECLARE_DEVICE_TYPE(PCE_ARCADE_PAD_6, pce_arcade_pad_6_device) - +DECLARE_DEVICE_TYPE(PCE_AVENUE_PAD_6, device_pce_control_port_interface) +DECLARE_DEVICE_TYPE(PCE_ARCADE_PAD_6, device_pce_control_port_interface) #endif // MAME_BUS_PCE_CTRL_JOYPAD6_H diff --git a/src/devices/bus/pce_ctrl/mouse.cpp b/src/devices/bus/pce_ctrl/mouse.cpp new file mode 100644 index 00000000000..9d608008104 --- /dev/null +++ b/src/devices/bus/pce_ctrl/mouse.cpp @@ -0,0 +1,137 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +/*********************************************************************** + + NEC PC Engine/TurboGrafx-16 Mouse emulation + +***********************************************************************/ + +#include "emu.h" +#include "mouse.h" + +#include +#include + +//#define VERBOSE 1 +//#define LOG_OUTPUT_FUNC osd_printf_info +#include "logmacro.h" + + +namespace { + +INPUT_PORTS_START( pce_mouse ) + PORT_START("BUTTONS") + PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("%p Button I (right)") + PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("%p Button II (left)") + PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT ) + PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START ) PORT_NAME("%p Run") + + PORT_START("X") + PORT_BIT( 0xff, 0x00, IPT_MOUSE_X ) PORT_SENSITIVITY(20) PORT_KEYDELTA(1) PORT_REVERSE + + PORT_START("Y") + PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y ) PORT_SENSITIVITY(20) PORT_KEYDELTA(1) PORT_REVERSE +INPUT_PORTS_END + + +class pce_mouse_device : public device_t, public device_pce_control_port_interface +{ +public: + pce_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock); + + virtual u8 peripheral_r() override; + virtual void sel_w(int state) override { m_sel_in = state ? 1 : 0; } + virtual void clr_w(int state) override; + +protected: + virtual ioport_constructor device_input_ports() const override { return INPUT_PORTS_NAME(pce_mouse); } + virtual void device_start() override; + +private: + required_ioport m_buttons; + required_ioport_array<2> m_axes; + + attotime m_squeak; + u16 m_data; + u8 m_base[2]; + u8 m_sel_in; + u8 m_clr_in; +}; + + +pce_mouse_device::pce_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) : + device_t(mconfig, PCE_MOUSE, tag, owner, clock), + device_pce_control_port_interface(mconfig, *this), + m_buttons(*this, "BUTTONS"), + m_axes(*this, "%c", 'X'), + m_squeak(), + m_data(0), + m_sel_in(1), + m_clr_in(1) +{ +} + + +u8 pce_mouse_device::peripheral_r() +{ + if (m_clr_in) + return 0x0f; + else if (!m_sel_in) + return m_buttons->read(); + else + return BIT(m_data, 12, 4); +} + + +void pce_mouse_device::clr_w(int state) +{ + u8 const clr = state ? 1 : 0; + if (clr != m_clr_in) + { + m_clr_in = clr; + if (clr) + { + attotime const now = machine().time(); + if ((now - m_squeak) > attotime::from_usec(550)) + { + LOG("%s: CLR rising, latch count\n", machine().describe_context()); + m_squeak = now; + for (unsigned i = 0; m_axes.size() > i; ++i) + { + uint8_t const count = m_axes[i]->read(); + m_data <<= 8; + m_data |= (count - m_base[i]) & 0x00ff; + m_base[i] = count; + } + } + else + { + LOG("%s: CLR rising, shift count\n", machine().describe_context()); + m_data <<= 4; + } + } + else + { + LOG("%s: CLR falling\n", machine().describe_context()); + } + } +} + + +void pce_mouse_device::device_start() +{ + m_squeak = machine().time(); + m_data = 0; + std::fill(std::begin(m_base), std::end(m_base), 0); + + save_item(NAME(m_squeak)); + save_item(NAME(m_data)); + save_item(NAME(m_base)); + save_item(NAME(m_sel_in)); + save_item(NAME(m_clr_in)); +} + +} // anonymous namespace + + +DEFINE_DEVICE_TYPE_PRIVATE(PCE_MOUSE, device_pce_control_port_interface, pce_mouse_device, "pce_mouse", "NEC PC Engine Mouse") diff --git a/src/devices/bus/pce_ctrl/mouse.h b/src/devices/bus/pce_ctrl/mouse.h new file mode 100644 index 00000000000..3855c7cd5e3 --- /dev/null +++ b/src/devices/bus/pce_ctrl/mouse.h @@ -0,0 +1,18 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +/*********************************************************************** + + NEC PC Engine/TurboGrafx-16 Mouse emulation + +***********************************************************************/ +#ifndef MAME_BUS_PCE_CTRL_MOUSE_H +#define MAME_BUS_PCE_CTRL_MOUSE_H + +#pragma once + +#include "pcectrl.h" + + +DECLARE_DEVICE_TYPE(PCE_MOUSE, device_pce_control_port_interface) + +#endif // MAME_BUS_PCE_CTRL_MOUSE_H diff --git a/src/devices/bus/pce_ctrl/pcectrl.cpp b/src/devices/bus/pce_ctrl/pcectrl.cpp index 6ed8f3c5acd..e67f592c01e 100644 --- a/src/devices/bus/pce_ctrl/pcectrl.cpp +++ b/src/devices/bus/pce_ctrl/pcectrl.cpp @@ -58,6 +58,7 @@ // slot devices #include "joypad2.h" #include "joypad6.h" +#include "mouse.h" #include "multitap.h" #include "pachinko.h" #include "xhe3.h" @@ -172,14 +173,18 @@ void pce_control_port_devices(device_slot_interface &device) // 2 Button Joypad/Joysticks device.option_add("joypad2", PCE_JOYPAD2); // bundled pad for White PC Engine device.option_add("joypad2_turbo", PCE_JOYPAD2_TURBO); // Turbo pad and compatibles + // 6 Button Joypad/Joysticks device.option_add("avenue_pad_6", PCE_AVENUE_PAD_6); device.option_add("arcade_pad_6", PCE_ARCADE_PAD_6); + device.option_add("mouse", PCE_MOUSE); + device.option_add("multitap", PCE_MULTITAP); device.option_add("pachinko", PCE_PACHINKO); - device.option_add("pcjoy", PCE_XHE3); + device.option_add("pcjoy", PCE_XHE3); // PC joystick adapter (most useful with analog pad) + // 3 Button Joypad/Joysticks (ex: Avenue Pad 3) // PC Engine Mouse (PI-PD10) // Memory Base 128 (PI-AD19) diff --git a/src/devices/bus/sms_ctrl/mouse.cpp b/src/devices/bus/sms_ctrl/mouse.cpp index 2f72a0ec729..bb39fcd8bcd 100644 --- a/src/devices/bus/sms_ctrl/mouse.cpp +++ b/src/devices/bus/sms_ctrl/mouse.cpp @@ -63,6 +63,7 @@ protected: private: TIMER_CALLBACK_MEMBER(next_step); + required_ioport m_buttons; required_ioport_array<2> m_axes; @@ -88,6 +89,7 @@ sms_megamouse_device::sms_megamouse_device(machine_config const &mconfig, device device_sms_control_interface(mconfig, *this), m_buttons(*this, "BUTTONS"), m_axes(*this, "%c", 'X'), + m_busy_timer(nullptr), m_th_in(1), m_tr_in(1), m_out(0x30), -- cgit v1.2.3