summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/qimi.cpp
blob: dba7bd9ee59480f2280d506c4c07ea5fb20a4688 (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder, Phill Harvey-Smith
/**********************************************************************

    QJump/Quanta QL Internal Mouse Interface emulation

**********************************************************************/

#include "emu.h"
#include "qimi.h"



//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(QIMI, qimi_device, "qimi", "QL Internal Mouse Interface")


//-------------------------------------------------
//  INPUT_CHANGED_MEMBER( mouse_x_changed )
//-------------------------------------------------

INPUT_CHANGED_MEMBER( qimi_device::mouse_x_changed )
{
	if (newval > oldval)
	{
		m_status |= ST_X_DIR;
	}
	else
	{
		m_status &= ~ST_X_DIR;
	}

	m_status |= ST_X_INT;

	if (m_extint_en)
	{
		m_write_extint(ASSERT_LINE);
	}
}


//-------------------------------------------------
//  INPUT_CHANGED_MEMBER( mouse_y_changed )
//-------------------------------------------------

INPUT_CHANGED_MEMBER( qimi_device::mouse_y_changed )
{
	if (newval < oldval)
	{
		m_status |= ST_Y_DIR;
	}
	else
	{
		m_status &= ~ST_Y_DIR;
	}

	m_status |= ST_Y_INT;

	if (m_extint_en)
	{
		m_write_extint(ASSERT_LINE);
	}
}


//-------------------------------------------------
//  INPUT_PORTS( qimi )
//-------------------------------------------------

INPUT_PORTS_START( qimi )
	PORT_START("mouse_x")
	PORT_BIT( 0xff, 0x00, IPT_MOUSE_X ) PORT_SENSITIVITY(50) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_CHANGED_MEMBER(DEVICE_SELF, qimi_device, mouse_x_changed, 0)

	PORT_START("mouse_y")
	PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y ) PORT_SENSITIVITY(50) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_CHANGED_MEMBER(DEVICE_SELF, qimi_device, mouse_y_changed, 0)

	PORT_START("mouse_buttons")
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Right Mouse Button") PORT_CODE(MOUSECODE_BUTTON2)
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Left Mouse Button") PORT_CODE(MOUSECODE_BUTTON1)
	PORT_BIT( 0xcf, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor qimi_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( qimi );
}



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  qimi_device - constructor
//-------------------------------------------------

qimi_device::qimi_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, QIMI, tag, owner, clock),
	m_write_extint(*this),
	m_buttons(*this, "mouse_buttons"),
	m_status(0),
	m_extint_en(false)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void qimi_device::device_start()
{
	// resolve callbacks
	m_write_extint.resolve_safe();
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void qimi_device::device_reset()
{
	m_status = 0;
	m_extint_en = false;
}


//-------------------------------------------------
//  read -
//-------------------------------------------------

uint8_t qimi_device::read(offs_t offset, uint8_t data)
{
	switch (offset)
	{
	// button status
	case 0x1bf9c:
		data = m_buttons->read();
		break;

	// direction status
	case 0x1bfbc:
		data = m_status;
		break;

	case 0x1bfbe:
		m_status &= ~(ST_Y_INT | ST_X_INT);
		m_extint_en = true;

		m_write_extint(CLEAR_LINE);
		break;
	}

	return data;
}


//-------------------------------------------------
//  write -
//-------------------------------------------------

void qimi_device::write(offs_t offset, uint8_t data)
{
	(void)data;

	// write to 0x1bfbe resets int status
	if (offset == 0x1bfbe)
	{
		m_status &= ~(ST_Y_INT | ST_X_INT);
		m_extint_en = true;

		m_write_extint(CLEAR_LINE);
	}
}