1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli
3 /**********************************************************************
4
5 Nintendo Family Computer Yonezawa / PartyRoom 21 Party Tap Controller
6
7 **********************************************************************/
8
9 #include "emu.h"
10 #include "partytap.h"
11
12 //**************************************************************************
13 // DEVICE DEFINITIONS
14 //**************************************************************************
15
16 DEFINE_DEVICE_TYPE(NES_PARTYTAP, nes_partytap_device, "nes_partytap", "Yonezawa Party Tap Controller")
17
18
INPUT_PORTS_START(nes_partytap)19 static INPUT_PORTS_START( nes_partytap )
20 PORT_START("INPUTS")
21 PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_UNUSED )
22 PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P1 Button") PORT_CODE(KEYCODE_Z)
23 PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P2 Button") PORT_CODE(KEYCODE_X)
24 PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P3 Button") PORT_CODE(KEYCODE_C)
25 PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P4 Button") PORT_CODE(KEYCODE_V)
26 PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P5 Button") PORT_CODE(KEYCODE_B)
27 PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("P6 Button") PORT_CODE(KEYCODE_N)
28 INPUT_PORTS_END
29
30 //-------------------------------------------------
31 // input_ports - device-specific input ports
32 //-------------------------------------------------
33
34 ioport_constructor nes_partytap_device::device_input_ports() const
35 {
36 return INPUT_PORTS_NAME( nes_partytap );
37 }
38
39 //**************************************************************************
40 // LIVE DEVICE
41 //**************************************************************************
42
43 //-------------------------------------------------
44 // nes_partytap_device - constructor
45 //-------------------------------------------------
46
nes_partytap_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)47 nes_partytap_device::nes_partytap_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
48 device_t(mconfig, NES_PARTYTAP, tag, owner, clock),
49 device_nes_control_port_interface(mconfig, *this),
50 m_inputs(*this, "INPUTS"),
51 m_mode(0),
52 m_latch(0)
53 {
54 }
55
56
57 //-------------------------------------------------
58 // device_start
59 //-------------------------------------------------
60
device_start()61 void nes_partytap_device::device_start()
62 {
63 save_item(NAME(m_latch));
64 save_item(NAME(m_mode));
65 }
66
67
68 //-------------------------------------------------
69 // device_reset
70 //-------------------------------------------------
71
device_reset()72 void nes_partytap_device::device_reset()
73 {
74 m_mode = 0xe0;
75 m_latch = 0;
76 }
77
78
79 //-------------------------------------------------
80 // read
81 //-------------------------------------------------
82
read_exp(offs_t offset)83 uint8_t nes_partytap_device::read_exp(offs_t offset)
84 {
85 uint8_t ret = 0;
86 if (offset == 1) //$4017
87 {
88 ret |= m_latch & 0x1c;
89 m_latch >>= 3;
90 // append mode bits
91 m_latch |= m_mode;
92 }
93 return ret;
94 }
95
96 //-------------------------------------------------
97 // write
98 //-------------------------------------------------
99
write(uint8_t data)100 void nes_partytap_device::write(uint8_t data)
101 {
102 // inputs are read in two chunks of 3 bits, before the second one is read bit2 is written here
103 // probably a mechanism for the game to detect which group of inputs is being read
104 m_mode = BIT(data, 2) ? 0xa0 : 0xe0;
105
106 if (data & 0x01)
107 return;
108
109 m_latch = m_inputs->read();
110 }
111