diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index 0d98c3da1f7..bebcde91fae 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -3306,6 +3306,8 @@ if (BUSES["EINSTEIN_USERPORT"]~=null) then files { MAME_DIR .. "src/devices/bus/einstein/userport/userport.cpp", MAME_DIR .. "src/devices/bus/einstein/userport/userport.h", + MAME_DIR .. "src/devices/bus/einstein/userport/mouse.cpp", + MAME_DIR .. "src/devices/bus/einstein/userport/mouse.h", MAME_DIR .. "src/devices/bus/einstein/userport/speech.cpp", MAME_DIR .. "src/devices/bus/einstein/userport/speech.h", } diff --git a/src/devices/bus/einstein/userport/mouse.cpp b/src/devices/bus/einstein/userport/mouse.cpp new file mode 100644 index 00000000000..945bff5d37c --- /dev/null +++ b/src/devices/bus/einstein/userport/mouse.cpp @@ -0,0 +1,106 @@ +// license: GPL-2.0+ +// copyright-holders: Dirk Best +/*************************************************************************** + + Einstein Mouse + + TODO: Verify implementation (mouse directions are digital only?) + +***************************************************************************/ + +#include "emu.h" +#include "mouse.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(EINSTEIN_MOUSE, einstein_mouse_device, "einstein_mouse", "Einstein Mouse") + +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + +static INPUT_PORTS_START( mouse ) + PORT_START("mouse_b") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_PLAYER(1) PORT_NAME("Mouse Left Button") + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_PLAYER(1) PORT_NAME("Mouse Right Button") + + PORT_START("mouse_x") + PORT_BIT(0xff, 0x00, IPT_MOUSE_X) PORT_PLAYER(1) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) + + PORT_START("mouse_y") + PORT_BIT(0xff, 0x00, IPT_MOUSE_Y) PORT_PLAYER(1) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) +INPUT_PORTS_END + +ioport_constructor einstein_mouse_device::device_input_ports() const +{ + return INPUT_PORTS_NAME( mouse ); +} + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// einstein_speech_device - constructor +//------------------------------------------------- + +einstein_mouse_device::einstein_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, EINSTEIN_MOUSE, tag, owner, clock), + device_einstein_userport_interface(mconfig, *this), + m_mouse_b(*this, "mouse_b"), + m_mouse_x(*this, "mouse_x"), + m_mouse_y(*this, "mouse_y"), + m_x(0), m_y(0) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void einstein_mouse_device::device_start() +{ + // register for save states + save_item(NAME(m_x)); + save_item(NAME(m_y)); +} + + +//************************************************************************** +// IMPLEMENTATION +//************************************************************************** + +// 7------- not used +// -6------ not used +// --5----- right button +// ---4---- left button +// ----3--- right +// -----2-- left +// ------1- down +// -------0 up + +uint8_t einstein_mouse_device::read() +{ + uint8_t data = 0; + + uint8_t x = m_mouse_x->read(); + uint8_t y = m_mouse_y->read(); + + int dx = m_x - x; + int dy = m_y - y; + + data |= m_mouse_b->read() << 4; + data |= (dx < 0) ? 0 : 1 << 3; + data |= (dx > 0) ? 0 : 1 << 2; + data |= (dy < 0) ? 0 : 1 << 1; + data |= (dy > 0) ? 0 : 1 << 0; + + m_x = x; + m_y = y; + + return data; +} diff --git a/src/devices/bus/einstein/userport/mouse.h b/src/devices/bus/einstein/userport/mouse.h new file mode 100644 index 00000000000..dad8200d06b --- /dev/null +++ b/src/devices/bus/einstein/userport/mouse.h @@ -0,0 +1,47 @@ +// license: GPL-2.0+ +// copyright-holders: Dirk Best +/*************************************************************************** + + Einstein Mouse + +***************************************************************************/ + +#ifndef MAME_BUS_EINSTEIN_USERPORT_MOUSE_H +#define MAME_BUS_EINSTEIN_USERPORT_MOUSE_H + +#pragma once + +#include "userport.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> einstein_mouse_device + +class einstein_mouse_device : public device_t, public device_einstein_userport_interface +{ +public: + // construction/destruction + einstein_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + +protected: + virtual ioport_constructor device_input_ports() const override; + virtual void device_start() override; + + virtual uint8_t read() override; + +private: + required_ioport m_mouse_b; + required_ioport m_mouse_x; + required_ioport m_mouse_y; + + int m_x; + int m_y; +}; + +// device type definition +DECLARE_DEVICE_TYPE(EINSTEIN_MOUSE, einstein_mouse_device) + +#endif // MAME_BUS_EINSTEIN_USERPORT_MOUSE_H diff --git a/src/devices/bus/einstein/userport/userport.cpp b/src/devices/bus/einstein/userport/userport.cpp index 853fbd8777a..d38dba12af9 100644 --- a/src/devices/bus/einstein/userport/userport.cpp +++ b/src/devices/bus/einstein/userport/userport.cpp @@ -10,6 +10,7 @@ #include "userport.h" // supported devices +#include "mouse.h" #include "speech.h" @@ -118,5 +119,6 @@ device_einstein_userport_interface::~device_einstein_userport_interface() //************************************************************************** SLOT_INTERFACE_START( einstein_userport_cards ) + SLOT_INTERFACE("mouse", EINSTEIN_MOUSE) SLOT_INTERFACE("speech", EINSTEIN_SPEECH) SLOT_INTERFACE_END