summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/hp_hil/hlemouse.cpp
blob: 215912b5cc63af60b688b5fc48bde43de946a0e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// license:BSD-3-Clause
// copyright-holders:Sven Schnelle
#include "emu.h"
#include "hlemouse.h"

//#define VERBOSE 1
#include "logmacro.h"

/***************************************************************************
    DEVICE TYPE GLOBALS
***************************************************************************/

DEFINE_DEVICE_TYPE(HP_46060B_MOUSE, bus::hp_hil::hle_hp_46060b_device, "hp_46060b", "HP 46060B Mouse")

namespace bus::hp_hil {

namespace {

/***************************************************************************
    INPUT PORT DEFINITIONS
***************************************************************************/

INPUT_PORTS_START( hle_hp_46060b_device )
	PORT_START("mouse_buttons")
	PORT_BIT(hle_hp_46060b_device::MOUSE_LBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Left Button") PORT_CODE(MOUSECODE_BUTTON1) PORT_CHANGED_MEMBER(DEVICE_SELF, hle_hp_46060b_device, mouse_button, 0)
	PORT_BIT(hle_hp_46060b_device::MOUSE_MBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Mouse Middle Button") PORT_CODE(MOUSECODE_BUTTON3) PORT_CHANGED_MEMBER(DEVICE_SELF, hle_hp_46060b_device, mouse_button, 0)
	PORT_BIT(hle_hp_46060b_device::MOUSE_RBUTTON, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Mouse Right Button") PORT_CODE(MOUSECODE_BUTTON2) PORT_CHANGED_MEMBER(DEVICE_SELF, hle_hp_46060b_device, mouse_button, 0)

	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, hle_hp_46060b_device, mouse_x, 0)
	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, hle_hp_46060b_device, mouse_y, 0)
INPUT_PORTS_END
} // anonymous namespace

hle_hp_46060b_device::hle_hp_46060b_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock)
	: hle_device_base(mconfig, HP_46060B_MOUSE, tag, owner, clock),
	mouse_x_delta{0},
	mouse_y_delta{0},
	mouse_buttons{0}
{ }

void hle_hp_46060b_device::device_reset()
{
	m_fifo.clear();

	mouse_x_delta = mouse_y_delta = 0;
}

int hle_hp_46060b_device::hil_poll()
{
	int frames = 0;
	uint16_t reports = 0;

	if (mouse_x_delta || mouse_y_delta)
		reports |= 2;

	if (!m_fifo.empty())
		reports |= 0x40;

	if (!reports)
		return 0;

	m_hp_hil_mlc->hil_write(m_device_id16 | reports);  // report X & Y data
	frames++;
	if (mouse_x_delta || mouse_y_delta) {
		m_hp_hil_mlc->hil_write(m_device_id16 | (uint8_t)mouse_x_delta);
		m_hp_hil_mlc->hil_write(m_device_id16 | (uint8_t)mouse_y_delta);
		mouse_x_delta = 0;
		mouse_y_delta = 0;
		frames+=2;
	}

	while (!m_fifo.empty()) {
		m_hp_hil_mlc->hil_write(m_device_id16 | m_fifo.dequeue());
		frames++;
	}

	return frames;
}


void hle_hp_46060b_device::hil_idd()
{
	m_hp_hil_mlc->hil_write(m_device_id16 | 0x68);
	m_hp_hil_mlc->hil_write(m_device_id16 | 0x12); // report X & Y Axes
	m_hp_hil_mlc->hil_write(m_device_id16 | 0xc2); // resolution Low
	m_hp_hil_mlc->hil_write(m_device_id16 | 0x1e); // resolution High
	return;
}

ioport_constructor hle_hp_46060b_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(hle_hp_46060b_device);
}

INPUT_CHANGED_MEMBER(hle_hp_46060b_device::mouse_y)
{
	int8_t delta = newval - oldval;
	mouse_y_delta += -delta;
}

INPUT_CHANGED_MEMBER(hle_hp_46060b_device::mouse_x)
{
	int8_t delta = newval - oldval;
	mouse_x_delta += delta;
}

INPUT_CHANGED_MEMBER(hle_hp_46060b_device::mouse_button)
{
	const ioport_value data = field.port().read();
	uint32_t _data = data & MOUSE_BUTTONS;

	switch(_data ^ mouse_buttons) {
		case MOUSE_LBUTTON:
			if (!m_fifo.full()) {
				m_fifo.enqueue(_data ? 0x80 : 0x81);
			}
			break;
		case MOUSE_RBUTTON:
			if (!m_fifo.full()) {
				m_fifo.enqueue(_data ? 0x82 : 0x83);
			}
			break;
	}
	mouse_buttons = data;
}

} // namespace bus::hp_hil