1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli
3 /**********************************************************************
4
5 Sega Saturn Analog Controller emulation
6
7 **********************************************************************/
8
9 #include "emu.h"
10 #include "analog.h"
11
12 //**************************************************************************
13 // DEVICE DEFINITIONS
14 //**************************************************************************
15
16 DEFINE_DEVICE_TYPE(SATURN_ANALOG, saturn_analog_device, "saturn_analog", "Sega Saturn Analog Controller")
17
18
INPUT_PORTS_START(saturn_analog)19 static INPUT_PORTS_START( saturn_analog )
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(0x0080, IP_ACTIVE_LOW, IPT_BUTTON8) PORT_NAME("R")
30 PORT_BIT(0x0040, IP_ACTIVE_LOW, IPT_BUTTON4) PORT_NAME("X")
31 PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("Y")
32 PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_BUTTON6) PORT_NAME("Z")
33 PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_BUTTON7) PORT_NAME("L")
34 // Note: unused bits must stay high, Bug 2 relies on this.
35 PORT_BIT(0x0007, IP_ACTIVE_LOW, IPT_UNUSED)
36
37 PORT_START("ANALOG_X")
38 PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(25) PORT_KEYDELTA(200) PORT_NAME("AD Stick X")
39
40 PORT_START("ANALOG_Y")
41 PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(25) PORT_KEYDELTA(200) PORT_NAME("AD Stick Y")
42
43 PORT_START("ANALOG_Z")
44 PORT_BIT( 0xff, 0x00, IPT_AD_STICK_Z ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(25) PORT_KEYDELTA(200) PORT_NAME("AD Stick Z")
45 INPUT_PORTS_END
46
47
48 //-------------------------------------------------
49 // input_ports - device-specific input ports
50 //-------------------------------------------------
51
52 ioport_constructor saturn_analog_device::device_input_ports() const
53 {
54 return INPUT_PORTS_NAME( saturn_analog );
55 }
56
57
58 //**************************************************************************
59 // LIVE DEVICE
60 //**************************************************************************
61
62 //-------------------------------------------------
63 // saturn_analog_device - constructor
64 //-------------------------------------------------
65
saturn_analog_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)66 saturn_analog_device::saturn_analog_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
67 device_t(mconfig, SATURN_ANALOG, tag, owner, clock),
68 device_saturn_control_port_interface(mconfig, *this),
69 m_joy(*this, "JOY"),
70 m_anx(*this, "ANALOG_X"),
71 m_any(*this, "ANALOG_Y"),
72 m_anz(*this, "ANALOG_Z")
73 {
74 m_ctrl_id = 0x15;
75 }
76
77
78 //-------------------------------------------------
79 // device_start - device-specific startup
80 //-------------------------------------------------
81
device_start()82 void saturn_analog_device::device_start()
83 {
84 }
85
86
87 //-------------------------------------------------
88 // device_reset - device-specific reset
89 //-------------------------------------------------
90
device_reset()91 void saturn_analog_device::device_reset()
92 {
93 }
94
95
96 //-------------------------------------------------
97 // read_ctrl
98 //-------------------------------------------------
99
read_ctrl(uint8_t offset)100 uint8_t saturn_analog_device::read_ctrl(uint8_t offset)
101 {
102 uint8_t res = 0;
103 switch (offset)
104 {
105 case 0:
106 default:
107 res = m_joy->read() >> 8;
108 break;
109 case 1:
110 res = m_joy->read() & 0xff;
111 break;
112 case 2:
113 res = m_anx->read();
114 break;
115 case 3:
116 res = m_any->read();
117 break;
118 case 4:
119 res = m_anz->read();
120 break;
121 }
122 return res;
123 }
124