summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/abckb/r8.cpp
blob: 8372bbdedbcb3f2a5996ba6376317f66a0e3140e (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
// copyright-holders:Curt Coder
/**********************************************************************

    Luxor R8 mouse emulation

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

#include "emu.h"
#include "r8.h"



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

DEFINE_DEVICE_TYPE(LUXOR_R8, luxor_r8_device, "luxor_r8", "Luxor R8")


//-------------------------------------------------
//  INPUT_PORTS( r8 )
//-------------------------------------------------

static INPUT_PORTS_START( r8 )
	PORT_START("MOUSEB")
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Left Mouse Button") PORT_CODE(MOUSECODE_BUTTON1)
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Middle Mouse Button") PORT_CODE(MOUSECODE_BUTTON3)
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Right Mouse Button") PORT_CODE(MOUSECODE_BUTTON2)

	PORT_START("MOUSEX")
	PORT_BIT( 0xfff, 0x000, IPT_MOUSE_X ) PORT_SENSITIVITY(50)

	PORT_START("MOUSEY")
	PORT_BIT( 0xfff, 0x000, IPT_MOUSE_Y ) PORT_SENSITIVITY(50)
INPUT_PORTS_END


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

ioport_constructor luxor_r8_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( r8 );
}


//-------------------------------------------------
//  scan_mouse -
//-------------------------------------------------

TIMER_CALLBACK_MEMBER(luxor_r8_device::scan_mouse)
{
	switch(m_phase)
	{
	case 0:
		m_xa = m_x > m_prev_x ? CLEAR_LINE : ASSERT_LINE;
		m_xb = m_x < m_prev_x ? CLEAR_LINE : ASSERT_LINE;
		m_ya = m_y > m_prev_y ? CLEAR_LINE : ASSERT_LINE;
		m_yb = m_y < m_prev_y ? CLEAR_LINE : ASSERT_LINE;
		break;
	case 1:
		m_xa = m_xb = m_x != m_prev_x ? CLEAR_LINE : ASSERT_LINE;
		m_ya = m_yb = m_y != m_prev_y ? CLEAR_LINE : ASSERT_LINE;
		break;
	case 2:
		m_xa = m_x < m_prev_x ? CLEAR_LINE : ASSERT_LINE;
		m_xb = m_x > m_prev_x ? CLEAR_LINE : ASSERT_LINE;
		m_ya = m_y < m_prev_y ? CLEAR_LINE : ASSERT_LINE;
		m_yb = m_y > m_prev_y ? CLEAR_LINE : ASSERT_LINE;
		break;
	case 3:
		m_xa = m_xb = ASSERT_LINE;
		m_ya = m_yb = ASSERT_LINE;
		m_prev_x = m_x;
		m_prev_y = m_y;
		m_x = m_mouse_x->read();
		m_y = m_mouse_y->read();
		break;
	}

	m_phase = (m_phase + 1) & 3;
}



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

//-------------------------------------------------
//  luxor_r8_device - constructor
//-------------------------------------------------

luxor_r8_device::luxor_r8_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, LUXOR_R8, tag, owner, clock),
	m_mouse_timer(nullptr),
	m_mouse_b(*this, "MOUSEB"),
	m_mouse_x(*this, "MOUSEX"),
	m_mouse_y(*this, "MOUSEY")
{
}


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

void luxor_r8_device::device_start()
{
	// allocate timers
	m_mouse_timer = timer_alloc(FUNC(luxor_r8_device::scan_mouse), this);
	m_mouse_timer->adjust(attotime::from_hz(1000), 0, attotime::from_hz(1000));

	// state saving
	save_item(NAME(m_phase));
	save_item(NAME(m_x));
	save_item(NAME(m_y));
	save_item(NAME(m_prev_x));
	save_item(NAME(m_prev_y));
	save_item(NAME(m_xa));
	save_item(NAME(m_xb));
	save_item(NAME(m_ya));
	save_item(NAME(m_yb));
}


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

void luxor_r8_device::device_reset()
{
	m_phase = 0;
	m_xa = m_xb = ASSERT_LINE;
	m_ya = m_yb = ASSERT_LINE;
	m_x = m_y = 0;
	m_prev_x = m_prev_y = 0;
}


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

u8 luxor_r8_device::read()
{
	u8 data = 0;

	// mouse movement
	data |= m_xa;
	data |= m_xb << 1;
	data |= m_ya << 2;
	data |= m_yb << 3;

	// mouse buttons
	data |= (m_mouse_b->read() & 0x07) << 4;

	return data;
}