summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2gameio/paddles.cpp
blob: 095739fcb29670d45d34d02453b690cd675d005b (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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************

    Apple II paddles

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

#include "emu.h"
#include "bus/a2gameio/paddles.h"

namespace {

// ======================> apple2_paddles_device

class apple2_paddles_device : public device_t, public device_a2gameio_interface
{
public:
	// construction/destruction
	apple2_paddles_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

protected:
	// device-level overrides
	virtual ioport_constructor device_input_ports() const override ATTR_COLD;
	virtual void device_start() override ATTR_COLD;

	// device_a2gameio_interface overrides
	virtual u8 pdl0_r() override;
	virtual u8 pdl1_r() override;
	virtual u8 pdl2_r() override;
	virtual u8 pdl3_r() override;
	virtual int sw0_r() override;
	virtual int sw1_r() override;
	virtual int sw2_r() override;
	virtual int sw3_r() override;

private:
	// input ports
	required_ioport_array<4> m_pdl;
	required_ioport m_buttons;
};

//**************************************************************************
//  INPUT PORTS
//**************************************************************************

static INPUT_PORTS_START( apple2_paddles )
	PORT_START("paddle_1")
	PORT_BIT( 0xff, 0x80, IPT_PADDLE) PORT_PLAYER(1) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0, 255)

	PORT_START("paddle_2")
	PORT_BIT( 0xff, 0x80, IPT_PADDLE) PORT_PLAYER(2) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0, 255)

	PORT_START("paddle_3")
	PORT_BIT( 0xff, 0x80, IPT_PADDLE) PORT_PLAYER(3) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0, 255)

	PORT_START("paddle_4")
	PORT_BIT( 0xff, 0x80, IPT_PADDLE) PORT_PLAYER(4) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) PORT_MINMAX(0, 255)

	PORT_START("paddle_buttons")
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)   PORT_PLAYER(1)
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON1)   PORT_PLAYER(2)
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1)   PORT_PLAYER(3)
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1)   PORT_PLAYER(4)
INPUT_PORTS_END

//**************************************************************************
//  DEVICE IMPLEMENTATION
//**************************************************************************

apple2_paddles_device::apple2_paddles_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, APPLE2_PADDLES, tag, owner, clock)
	, device_a2gameio_interface(mconfig, *this)
	, m_pdl(*this, "paddle_%u", 1U)
	, m_buttons(*this, "paddle_buttons")
{
}

ioport_constructor apple2_paddles_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(apple2_paddles);
}

void apple2_paddles_device::device_start()
{
}

u8 apple2_paddles_device::pdl0_r()
{
	return m_pdl[0]->read();
}

u8 apple2_paddles_device::pdl1_r()
{
	return m_pdl[1]->read();
}

u8 apple2_paddles_device::pdl2_r()
{
	return m_pdl[2]->read();
}

u8 apple2_paddles_device::pdl3_r()
{
	return m_pdl[3]->read();
}

int apple2_paddles_device::sw0_r()
{
	return BIT(m_buttons->read(), 4);
}

int apple2_paddles_device::sw1_r()
{
	return BIT(m_buttons->read(), 5);
}

int apple2_paddles_device::sw2_r()
{
	return BIT(m_buttons->read(), 6);
}

int apple2_paddles_device::sw3_r()
{
	return BIT(m_buttons->read(), 7);
}

} // anonymous namespace


//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

// device type definition
DEFINE_DEVICE_TYPE_PRIVATE(APPLE2_PADDLES, device_a2gameio_interface, apple2_paddles_device, "a2pdls", "Apple II paddles")