summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/snes_ctrl/pachinko.c
blob: 099e4e00f57de5210ed58ed2b82078b77dff0683 (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
/**********************************************************************

    Nintendo Super Famicom - Sunsoft Pachinko Controller

    Copyright MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

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

#include "pachinko.h"

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

const device_type SNES_PACHINKO = &device_creator<snes_pachinko_device>;


static INPUT_PORTS_START( snes_pachinko )
	PORT_START("DIAL")
	PORT_BIT( 0x7f, 0x3f, IPT_PADDLE) PORT_SENSITIVITY(25) PORT_KEYDELTA(25) PORT_CENTERDELTA(0) PORT_MINMAX(0x18,0x7f)

	PORT_START("BUTTON")
	PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED)
	PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Button")
	PORT_BIT( 0xfe00, IP_ACTIVE_HIGH, IPT_UNUSED)
INPUT_PORTS_END


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

ioport_constructor snes_pachinko_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( snes_pachinko );
}


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

//-------------------------------------------------
//  snes_pachinko_device - constructor
//-------------------------------------------------

snes_pachinko_device::snes_pachinko_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
					device_t(mconfig, SNES_PACHINKO, "Sunsoft Pachinko Controller", tag, owner, clock, "snes_pachinko", __FILE__),
					device_snes_control_port_interface(mconfig, *this),
					m_dial(*this, "DIAL"),
					m_button(*this, "BUTTON")
{
}


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

void snes_pachinko_device::device_start()
{
	save_item(NAME(m_latch));
	save_item(NAME(m_strobe));
}


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

void snes_pachinko_device::device_reset()
{
	m_latch = 0;
	m_strobe = 0;
}


//-------------------------------------------------
//  poll
//-------------------------------------------------

void snes_pachinko_device::port_poll()
{
	UINT8 dial = BITSWAP8(m_dial->read() ^ 0xff,7,6,5,4,3,2,1,0);
	m_latch = m_button->read() | (dial << 25) | 0xee7000;	// add ID
}

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

UINT8 snes_pachinko_device::read_pin4()
{
	UINT8 ret = m_latch & 1;
	m_latch >>= 1;
	return ret;
}

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

void snes_pachinko_device::write_strobe(UINT8 data)
{
	int old = m_strobe;
	m_strobe = data & 0x01;
	
	if (m_strobe < old)	// 1 -> 0 transition
		port_poll();
}