1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli
3 /**********************************************************************
4 
5     Sega Saturn MD Joypad (3 buttons & 6 buttons) emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "joy_md.h"
11 
12 //**************************************************************************
13 //  DEVICE DEFINITIONS
14 //**************************************************************************
15 
16 DEFINE_DEVICE_TYPE(SATURN_JOYMD3B, saturn_joymd3b_device, "saturn_md3b", "Sega Saturn Joypad MD 3buttons")
17 DEFINE_DEVICE_TYPE(SATURN_JOYMD6B, saturn_joymd6b_device, "saturn_md6b", "Sega Saturn Joypad MD 6buttons")
18 
INPUT_PORTS_START(saturn_md3b)19 static INPUT_PORTS_START( saturn_md3b )
20 	PORT_START("JOY")
21 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
22 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
23 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
24 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
25 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START )
26 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A")
27 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C")
28 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B")
29 	PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED ) //reads '1' when direct mode is polled
30 INPUT_PORTS_END
31 
32 static INPUT_PORTS_START( saturn_md6b )
33 	PORT_START("JOY")
34 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
35 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
36 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
37 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
38 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START )
39 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A")
40 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C")
41 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B")
42 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Mode")
43 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("X")
44 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Y")
45 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Z")
46 	PORT_BIT( 0x000f, IP_ACTIVE_LOW, IPT_UNUSED ) //reads '1' when direct mode is polled
47 INPUT_PORTS_END
48 
49 
50 //-------------------------------------------------
51 //  input_ports - device-specific input ports
52 //-------------------------------------------------
53 
54 ioport_constructor saturn_joymd3b_device::device_input_ports() const
55 {
56 	return INPUT_PORTS_NAME( saturn_md3b );
57 }
58 
device_input_ports() const59 ioport_constructor saturn_joymd6b_device::device_input_ports() const
60 {
61 	return INPUT_PORTS_NAME( saturn_md6b );
62 }
63 
64 
65 //**************************************************************************
66 //  LIVE DEVICE
67 //**************************************************************************
68 
69 //-------------------------------------------------
70 //  constructors
71 //-------------------------------------------------
72 
saturn_joymd3b_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)73 saturn_joymd3b_device::saturn_joymd3b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
74 	device_t(mconfig, SATURN_JOYMD3B, tag, owner, clock),
75 	device_saturn_control_port_interface(mconfig, *this),
76 	m_joy(*this, "JOY")
77 {
78 	m_ctrl_id = 0xe1;
79 }
80 
81 
saturn_joymd6b_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)82 saturn_joymd6b_device::saturn_joymd6b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
83 	device_t(mconfig, SATURN_JOYMD6B, tag, owner, clock),
84 	device_saturn_control_port_interface(mconfig, *this),
85 	m_joy(*this, "JOY")
86 {
87 	m_ctrl_id = 0xe2;
88 }
89 
90 
91 //-------------------------------------------------
92 //  read_ctrl
93 //-------------------------------------------------
94 
read_ctrl(uint8_t offset)95 uint8_t saturn_joymd3b_device::read_ctrl(uint8_t offset)
96 {
97 	uint8_t res = 0;
98 	switch (offset)
99 	{
100 		case 0:
101 		default:
102 			res = m_joy->read() >> 8;
103 			break;
104 	}
105 	return res;
106 }
107 
read_ctrl(uint8_t offset)108 uint8_t saturn_joymd6b_device::read_ctrl(uint8_t offset)
109 {
110 	uint8_t res = 0;
111 	switch (offset)
112 	{
113 		case 0:
114 		default:
115 			res = m_joy->read() >> 8;
116 			break;
117 		case 1:
118 			res = m_joy->read() & 0xff;
119 			break;
120 	}
121 	return res;
122 }
123