From bd9f203b655134ab33da3c1d5c7a8bde302c63d0 Mon Sep 17 00:00:00 2001 From: Patrick Mackinlay Date: Fri, 11 May 2018 13:25:42 +0700 Subject: [PATCH] interpro: slotify mouse (nw) (#3543) * interpro: slotify mouse (nw) Needed to make the mouse a slot device to enable it to be connected to graphics boards under development. * add validity check (nw) --- scripts/src/bus.lua | 12 +++ scripts/target/mame/mess.lua | 1 + src/devices/bus/interpro/mouse/mouse.cpp | 130 +++++++++++++++++++++++ src/devices/bus/interpro/mouse/mouse.h | 83 +++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 src/devices/bus/interpro/mouse/mouse.cpp create mode 100644 src/devices/bus/interpro/mouse/mouse.h diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index 4114928de76..fecb4721bbe 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -3423,6 +3423,18 @@ if (BUSES["INTERPRO_KEYBOARD"]~=null) then } end +--------------------------------------------------- +-- +--@src/devices/bus/interpro/mouse/mouse.h,BUSES["INTERPRO_MOUSE"] = true +--------------------------------------------------- + +if (BUSES["INTERPRO_MOUSE"]~=null) then + files { + MAME_DIR .. "src/devices/bus/interpro/mouse/mouse.cpp", + MAME_DIR .. "src/devices/bus/interpro/mouse/mouse.h" + } +end + --------------------------------------------------- -- --@src/devices/bus/einstein/pipe/pipe.h,BUSES["TATUNG_PIPE"] = true diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index 4e1485464c4..929009780b2 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -699,6 +699,7 @@ BUSES["IMI7000"] = true BUSES["INTELLEC4"] = true BUSES["INTERPRO_SR"] = true BUSES["INTERPRO_KEYBOARD"] = true +BUSES["INTERPRO_MOUSE"] = true BUSES["INTV"] = true BUSES["INTV_CTRL"] = true BUSES["IQ151"] = true diff --git a/src/devices/bus/interpro/mouse/mouse.cpp b/src/devices/bus/interpro/mouse/mouse.cpp new file mode 100644 index 00000000000..92e9ea06ce1 --- /dev/null +++ b/src/devices/bus/interpro/mouse/mouse.cpp @@ -0,0 +1,130 @@ +// license:BSD-3-Clause +// copyright-holders:Patrick Mackinlay + +/* + * A high-level emulation implementation of the Intergraph InterPro mouse. + * + * Little information is available on this hardware. The mouse has 3 buttons, + * all of which are commonly used by the system software, but earlier InterPro + * systems appear to have supported many more buttons; it's not known if those + * earlier versions use the same port or protocol. The mouse has a male D-sub + * 9-pin connector, using an unknown, probably TTL level signalling protocol. + * + * It's probable that this mouse can be connected to the mouse port on InterPro + * system main boards as well as the mouse port(s) on EDGE graphics boards. + */ + +#include "emu.h" +#include "mouse.h" + +#define VERBOSE (0) + +#include "logmacro.h" + +DEFINE_DEVICE_TYPE(INTERPRO_MOUSE_PORT, interpro_mouse_port_device, "interpro_mouse_port", "InterPro Mouse Port") +DEFINE_DEVICE_TYPE(INTERPRO_MOUSE, interpro_mouse_device, "interpro_mouse", "InterPro Mouse") + +static INPUT_PORTS_START(interpro_mouse) + PORT_START("mouse_buttons") + PORT_BIT(interpro_mouse_device::MOUSE_LBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Left Button") PORT_CODE(MOUSECODE_BUTTON1) PORT_CHANGED_MEMBER(DEVICE_SELF, interpro_mouse_device, mouse_button, nullptr) + PORT_BIT(interpro_mouse_device::MOUSE_MBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Mouse Middle Button") PORT_CODE(MOUSECODE_BUTTON3) PORT_CHANGED_MEMBER(DEVICE_SELF, interpro_mouse_device, mouse_button, nullptr) + PORT_BIT(interpro_mouse_device::MOUSE_RBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Mouse Right Button") PORT_CODE(MOUSECODE_BUTTON2) PORT_CHANGED_MEMBER(DEVICE_SELF, interpro_mouse_device, mouse_button, nullptr) + + PORT_START("mouse_x") + PORT_BIT(0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(50) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CHANGED_MEMBER(DEVICE_SELF, interpro_mouse_device, mouse_x, nullptr) + PORT_START("mouse_y") + PORT_BIT(0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(50) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CHANGED_MEMBER(DEVICE_SELF, interpro_mouse_device, mouse_y, nullptr) +INPUT_PORTS_END + +interpro_mouse_port_device::interpro_mouse_port_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, INTERPRO_MOUSE_PORT, tag, owner, clock) + , device_slot_interface(mconfig, *this) + , m_state_func(*this) + , m_device(nullptr) +{ +} + +void interpro_mouse_port_device::device_config_complete() +{ + m_device = dynamic_cast(get_card_device()); +} + +void interpro_mouse_port_device::device_validity_check(validity_checker &valid) const +{ + device_t *const card(get_card_device()); + + if (card && !dynamic_cast(card)) + osd_printf_error("Device %s (%s) does not implement device_interpro_mouse_port_interface\n", card->tag(), card->name()); +} + +void interpro_mouse_port_device::device_start() +{ + m_state_func.resolve_safe(); +} + +device_interpro_mouse_port_interface::device_interpro_mouse_port_interface(machine_config const &mconfig, device_t &device) + : device_slot_card_interface(mconfig, device) + , m_port(dynamic_cast(device.owner())) +{ +} + +interpro_mouse_device::interpro_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) + : device_t(mconfig, INTERPRO_MOUSE, tag, owner, clock) + , device_interpro_mouse_port_interface(mconfig, *this) +{ +} + +void interpro_mouse_device::device_start() +{ +} + +void interpro_mouse_device::device_reset() +{ +} + +ioport_constructor interpro_mouse_device::device_input_ports() const +{ + return INPUT_PORTS_NAME(interpro_mouse); +} + +void interpro_mouse_devices(device_slot_interface &device) +{ + device.option_add("interpro_mouse", INTERPRO_MOUSE); +} + +INPUT_CHANGED_MEMBER(interpro_mouse_device::mouse_button) +{ + const ioport_value data = field.port().read(); + + LOG("mouse_button 0x%02x\n", data); + + state_w(machine().dummy_space(), 0, data & MOUSE_BUTTONS, MOUSE_BUTTONS); +} + +INPUT_CHANGED_MEMBER(interpro_mouse_device::mouse_x) +{ + // compute x delta + int delta = newval - oldval; + if (delta > 0x80) + delta -= 0x100; + else if (delta < -0x80) + delta += 0x100; + + LOG("mouse_x delta %d\n", delta); + + state_w(machine().dummy_space(), 0, (delta << 8) & MOUSE_XPOS, MOUSE_XPOS); +} + +INPUT_CHANGED_MEMBER(interpro_mouse_device::mouse_y) +{ + // compute y delta + int delta = newval - oldval; + if (delta > 0x80) + delta -= 0x100; + else if (delta < -0x80) + delta += 0x100; + + LOG("mouse_y delta %d\n", delta); + + state_w(machine().dummy_space(), 0, (delta << 0) & MOUSE_YPOS, MOUSE_YPOS); +} diff --git a/src/devices/bus/interpro/mouse/mouse.h b/src/devices/bus/interpro/mouse/mouse.h new file mode 100644 index 00000000000..d3a03f494a8 --- /dev/null +++ b/src/devices/bus/interpro/mouse/mouse.h @@ -0,0 +1,83 @@ +// license:BSD-3-Clause +// copyright-holders:Patrick Mackinlay +#ifndef MAME_BUS_INTERPRO_MOUSE_MOUSE_H +#define MAME_BUS_INTERPRO_MOUSE_MOUSE_H + +#pragma once + +#define MCFG_MOUSE_STATE_CB(_state_cb) \ + devcb = &downcast(*device).set_state_callback(DEVCB_##_state_cb); + +class device_interpro_mouse_port_interface; + +class interpro_mouse_port_device : public device_t, public device_slot_interface +{ + friend class device_interpro_mouse_port_interface; + +public: + interpro_mouse_port_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock); + + template devcb_base &set_state_callback(Object &&cb) { return m_state_func.set_callback(std::forward(cb)); } + +protected: + // device-level overrides + virtual void device_validity_check(validity_checker &valid) const override; + virtual void device_start() override; + virtual void device_config_complete() override; + + devcb_write32 m_state_func; + +private: + device_interpro_mouse_port_interface *m_device; +}; + +class device_interpro_mouse_port_interface : public device_slot_card_interface +{ + friend class interpro_mouse_port_device; + +public: + DECLARE_WRITE32_MEMBER(state_w) { m_port->m_state_func(space, offset, data, mem_mask); } + +protected: + device_interpro_mouse_port_interface(machine_config const &mconfig, device_t &device); + + interpro_mouse_port_device *m_port; +}; + +class interpro_mouse_device : public device_t, public device_interpro_mouse_port_interface +{ +public: + enum state_mask + { + MOUSE_YPOS = 0x000000ff, + MOUSE_XPOS = 0x0000ff00, + MOUSE_LBUTTON = 0x00010000, + MOUSE_MBUTTON = 0x00020000, + MOUSE_RBUTTON = 0x00040000, + + MOUSE_BUTTONS = 0x00070000 + }; + + // constructor/destructor + interpro_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock); + + DECLARE_INPUT_CHANGED_MEMBER(mouse_button); + DECLARE_INPUT_CHANGED_MEMBER(mouse_x); + DECLARE_INPUT_CHANGED_MEMBER(mouse_y); + +protected: + // device overrides + virtual void device_start() override; + virtual void device_reset() override; + + virtual ioport_constructor device_input_ports() const override; + +private: +}; + +DECLARE_DEVICE_TYPE(INTERPRO_MOUSE_PORT, interpro_mouse_port_device) +DECLARE_DEVICE_TYPE(INTERPRO_MOUSE, interpro_mouse_device) + +void interpro_mouse_devices(device_slot_interface &device); + +#endif // MAME_BUS_INTERPRO_MOUSE_MOUSE_H