summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/coco/coco_max.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/bus/coco/coco_max.cpp')
-rw-r--r--src/devices/bus/coco/coco_max.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/src/devices/bus/coco/coco_max.cpp b/src/devices/bus/coco/coco_max.cpp
new file mode 100644
index 00000000000..82103e531d9
--- /dev/null
+++ b/src/devices/bus/coco/coco_max.cpp
@@ -0,0 +1,172 @@
+// license:BSD-3-Clause
+// copyright-holders:tim lindner
+/***************************************************************************
+
+ coco_max.cpp
+
+ Code for emulating CoCo Max Hi-Res Input Module
+
+***************************************************************************/
+
+#include "emu.h"
+#include "coco_max.h"
+
+#include "machine/ram.h"
+
+#define MOUSE_SENSITIVITY 75
+#define COCOMAX_X_TAG "cocomax_x"
+#define COCOMAX_Y_TAG "cocomax_y"
+#define COCOMAX_BUTTONS "cocomax_buttons"
+
+// #define VERBOSE (LOG_GENERAL )
+#include "logmacro.h"
+
+//-------------------------------------------------
+// INPUT_PORTS( cocomax_mouse )
+//-------------------------------------------------
+
+INPUT_PORTS_START( cocomax_mouse )
+ PORT_START(COCOMAX_X_TAG)
+ PORT_BIT( 0xff, 0x00, IPT_AD_STICK_X) PORT_NAME("CoCo Max Mouse X") PORT_SENSITIVITY(MOUSE_SENSITIVITY) PORT_MINMAX(0x00,0xff) PORT_PLAYER(1)
+ PORT_START(COCOMAX_Y_TAG)
+ PORT_BIT( 0xff, 0x00, IPT_AD_STICK_Y) PORT_NAME("CoCo Max Mouse Y") PORT_SENSITIVITY(MOUSE_SENSITIVITY) PORT_MINMAX(0x00,0xff) PORT_PLAYER(1)
+ PORT_START(COCOMAX_BUTTONS)
+ PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("CoCo Max Left Button") PORT_CODE(KEYCODE_0_PAD) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1)
+ PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("CoCo Max Right Button") PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(1)
+INPUT_PORTS_END
+
+//**************************************************************************
+// TYPE DECLARATIONS
+//**************************************************************************
+
+namespace
+{
+ // ======================> coco_pak_device
+
+ class coco_pak_max_device :
+ public device_t,
+ public device_cococart_interface
+ {
+ public:
+ // construction/destruction
+ coco_pak_max_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
+
+ protected:
+ // device-level overrides
+ virtual void device_start() override;
+ virtual void device_reset() override;
+ virtual ioport_constructor device_input_ports() const override;
+
+ u8 ff90_read(offs_t offset);
+
+ private:
+ required_ioport m_mouse_x;
+ required_ioport m_mouse_y;
+ required_ioport m_buttons;
+
+ uint8_t m_a2d_result;
+ };
+};
+
+
+
+//**************************************************************************
+// GLOBAL VARIABLES
+//**************************************************************************
+
+DEFINE_DEVICE_TYPE_PRIVATE(COCO_PAK_MAX, device_cococart_interface, coco_pak_max_device, "cocopakmax", "CoCo Max HI-RES input module")
+
+
+
+//-------------------------------------------------
+// coco_pak_device - constructor
+//-------------------------------------------------
+
+coco_pak_max_device::coco_pak_max_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
+ : device_t(mconfig, COCO_PAK_MAX, tag, owner, clock)
+ , device_cococart_interface(mconfig, *this)
+ , m_mouse_x(*this, COCOMAX_X_TAG)
+ , m_mouse_y(*this, COCOMAX_Y_TAG)
+ , m_buttons(*this, COCOMAX_BUTTONS)
+ , m_a2d_result(0)
+{
+}
+
+
+
+ioport_constructor coco_pak_max_device::device_input_ports() const
+{
+ return INPUT_PORTS_NAME(cocomax_mouse);
+}
+
+
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void coco_pak_max_device::device_start()
+{
+ // initial state
+ m_a2d_result = 0;
+
+ // save state
+ save_item(NAME(m_a2d_result));
+
+ // install $ff90-$ff93 handler
+ install_read_handler(0xff90, 0xff97, read8sm_delegate(*this, FUNC(coco_pak_max_device::ff90_read)));
+}
+
+
+
+//-------------------------------------------------
+// device_reset - device-specific reset
+//-------------------------------------------------
+
+void coco_pak_max_device::device_reset()
+{
+ m_a2d_result = 0;
+}
+
+
+
+//-------------------------------------------------
+// ff90_read
+//-------------------------------------------------
+
+u8 coco_pak_max_device::ff90_read(offs_t offset)
+{
+ uint8_t result = m_a2d_result;
+
+ switch (offset & 0x08)
+ {
+ case 0:
+ m_a2d_result = m_mouse_y->read();
+ break;
+ case 1:
+ m_a2d_result = m_mouse_x->read();
+ break;
+ case 2:
+ m_a2d_result = BIT(m_buttons->read(), 0) ? 0 : 0xff;
+ break;
+ case 3:
+ m_a2d_result = BIT(m_buttons->read(), 1) ? 0 : 0xff;
+ break;
+ case 4:
+ /* not connected*/
+ break;
+ case 5:
+ /* not connected*/
+ break;
+ case 6:
+ /* not connected*/
+ break;
+ case 7:
+ /* not connected*/
+ break;
+ default:
+ break;
+ }
+
+ return result;
+}