summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/rs232/hlemouse.h
blob: be3142ad118e5ae48f6af24e0f3e9412420d4e22 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
/**************************************************************************

    PC Serial Mouse Simulation

**************************************************************************/
#ifndef MAME_BUS_RS232_HLEMOUSE_H
#define MAME_BUS_RS232_HLEMOUSE_H

#pragma once

#include "rs232.h"
#include "diserial.h"

#include <type_traits>


namespace bus { namespace rs232 {

//**************************************************
// Microsoft mouse base
//**************************************************

class hle_msmouse_device_base : public buffered_rs232_device<8>
{
public:
	DECLARE_INPUT_CHANGED_MEMBER(input_changed);

protected:
	hle_msmouse_device_base(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, uint32_t clock);

	virtual void device_resolve_objects() override;
	virtual void device_start() override;

	virtual DECLARE_WRITE_LINE_MEMBER(input_dtr) override;
	virtual DECLARE_WRITE_LINE_MEMBER(input_rts) override;

	virtual void tra_complete() override;

	virtual void received_byte(u8 byte) override;

	virtual bool read_inputs();

private:
	TIMER_CALLBACK_MEMBER(start_mouse);
	void check_enable();
	void check_inputs();

	virtual void reset_and_identify() = 0;
	virtual void transmit_extensions(uint8_t btn_val, uint8_t btn_sent) = 0;

	required_ioport m_buttons, m_x_axis, m_y_axis;
	int16_t m_x_delta, m_y_delta;
	uint16_t m_x_val, m_y_val;
	uint8_t m_btn_val, m_btn_sent;
	uint8_t m_dtr, m_rts, m_enable;
};


//**************************************************
// Microsoft 2-button mouse
//**************************************************

class hle_msft_mouse_device : public hle_msmouse_device_base
{
public:
	hle_msft_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock);

protected:
	virtual ioport_constructor device_input_ports() const override;

private:
	virtual void reset_and_identify() override;
	virtual void transmit_extensions(uint8_t btn_val, uint8_t btn_sent) override;
};


//**************************************************
//  Logitech 3-button mouse
//**************************************************

class hle_logitech_mouse_device : public hle_msmouse_device_base
{
public:
	hle_logitech_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock);

protected:
	virtual ioport_constructor device_input_ports() const override;

private:
	virtual void reset_and_identify() override;
	virtual void transmit_extensions(uint8_t btn_val, uint8_t btn_sent) override;
};


//**************************************************
// Microsoft wheel mouse
//**************************************************

class hle_wheel_mouse_device : public hle_msmouse_device_base
{
public:
	hle_wheel_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock);

protected:
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;

	virtual bool read_inputs() override;

private:
	virtual void reset_and_identify() override;
	virtual void transmit_extensions(uint8_t btn_val, uint8_t btn_sent) override;

	required_ioport m_wheel;
	int16_t m_wheel_delta;
	uint16_t m_wheel_val;
};


//**************************************************
//  Mouse Systems mouse base
//**************************************************

class hle_msystems_device_base : public device_t, public device_rs232_port_interface, public device_serial_interface
{
public:
	DECLARE_INPUT_CHANGED_MEMBER(input_changed);

protected:
	hle_msystems_device_base(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, uint32_t clock);

	virtual void device_start() override;

	virtual void tra_callback() override;
	virtual void tra_complete() override;

private:
	TIMER_CALLBACK_MEMBER(start_mouse);

	virtual bool read_inputs() = 0;
	virtual uint8_t report_buttons() = 0;
	virtual uint8_t report_x1_delta() = 0;
	virtual uint8_t report_y1_delta() = 0;
	virtual uint8_t report_x2_delta() = 0;
	virtual uint8_t report_y2_delta() = 0;

	uint8_t m_phase;
};


//**************************************************
//  Mouse Systems non-rotatable mouse
//**************************************************

class hle_msystems_mouse_device : public hle_msystems_device_base
{
public:
	hle_msystems_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock);

protected:
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;

private:
	virtual bool read_inputs() override;
	virtual uint8_t report_buttons() override;
	virtual uint8_t report_x1_delta() override;
	virtual uint8_t report_y1_delta() override;
	virtual uint8_t report_x2_delta() override;
	virtual uint8_t report_y2_delta() override;

	required_ioport m_buttons, m_x_axis, m_y_axis;
	int16_t m_x_delta, m_y_delta;
	uint16_t m_x_val, m_y_val;
	uint8_t m_btn_val, m_btn_sent;
};


//**************************************************
//  Mouse Systems rotatable mouse
//**************************************************

class hle_rotatable_mouse_device : public hle_msystems_device_base
{
public:
	hle_rotatable_mouse_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock);

protected:
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;

private:
	virtual bool read_inputs() override;
	virtual uint8_t report_buttons() override;
	virtual uint8_t report_x1_delta() override;
	virtual uint8_t report_y1_delta() override;
	virtual uint8_t report_x2_delta() override;
	virtual uint8_t report_y2_delta() override;

	required_ioport m_buttons, m_x_axis, m_y_axis, m_rotation;
	int16_t m_x_delta[2], m_y_delta[2];
	uint16_t m_x_val, m_y_val, m_rot_val;
	uint8_t m_btn_val, m_btn_sent;
};

} } // namespace bus::rs232


//**************************************************
//  Device type globals
//**************************************************

DECLARE_DEVICE_TYPE_NS(MSFT_HLE_SERIAL_MOUSE,      bus::rs232, hle_msft_mouse_device)
DECLARE_DEVICE_TYPE_NS(LOGITECH_HLE_SERIAL_MOUSE,  bus::rs232, hle_logitech_mouse_device)
DECLARE_DEVICE_TYPE_NS(WHEEL_HLE_SERIAL_MOUSE,     bus::rs232, hle_wheel_mouse_device)
DECLARE_DEVICE_TYPE_NS(MSYSTEMS_HLE_SERIAL_MOUSE,  bus::rs232, hle_msystems_mouse_device)
DECLARE_DEVICE_TYPE_NS(ROTATABLE_HLE_SERIAL_MOUSE, bus::rs232, hle_rotatable_mouse_device)

#endif // MAME_BUS_RS232_SER_MOUSE_H