summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/hyperscan_ctrl.cpp
blob: c99972feab894591e2362a019e8bfa63dde1fe1e (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
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/*****************************************************************************

        Hyperscan controller

        The controller contains a SPC11122A MCU and a Winbond W55AD808 ADC.

        Pinouts:

            3   4
           2  I  5
            1 I 6

        1: Brown  : GND
        2: Yellow : DATA
        3: Grey   : CLK
        4: Green  : ENABLE
        5: Blue   : RESET
        6: Red    : VCC 3.3v

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

#include "emu.h"
#include "hyperscan_ctrl.h"


DEFINE_DEVICE_TYPE(HYPERSCAN_CTRL, hyperscan_ctrl_device, "hyperscan_ctrl", "Hyperscan controller HLE")


hyperscan_ctrl_device::hyperscan_ctrl_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, HYPERSCAN_CTRL, tag, owner, clock)
	, m_inputs(*this, "IN.%u", 0U)
{
}

static INPUT_PORTS_START( hyperscan_ctrl )
	PORT_START("IN.0")
	PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Blue")
	PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_START)   PORT_NAME("Start")
	PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_SELECT)  PORT_NAME("Select")
	PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("Left Shoulder")
	PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON7) PORT_NAME("Right Shoulder")
	PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("Left Trigger")
	PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_BUTTON8) PORT_NAME("Right Trigger")
	PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_UNUSED)

	PORT_START("IN.1")
	PORT_BIT(0x1f, IP_ACTIVE_HIGH, IPT_UNUSED)
	PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Yellow")
	PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("Red")
	PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Green")

	PORT_START("IN.2")
	PORT_BIT(0xff, 0x7f, IPT_AD_STICK_Y) PORT_NAME("Analog Y") PORT_REVERSE PORT_SENSITIVITY(100) PORT_KEYDELTA(30) PORT_CENTERDELTA(50)

	PORT_START("IN.3")
	PORT_BIT(0xff, 0x7f, IPT_AD_STICK_X) PORT_NAME("Analog X") PORT_REVERSE PORT_SENSITIVITY(100) PORT_KEYDELTA(30) PORT_CENTERDELTA(50)
INPUT_PORTS_END


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

void hyperscan_ctrl_device::device_start()
{
	save_item(NAME(m_input_data));
}

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

void hyperscan_ctrl_device::device_reset()
{
	m_input_data[0] = m_input_data[1] = m_input_data[2] = m_input_data[3] = 0;
}


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

ioport_constructor hyperscan_ctrl_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( hyperscan_ctrl );
}


uint16_t hyperscan_ctrl_device::read(offs_t offset)
{
	int port = (offset >> 4) & 0x0f;
	int addr = offset & 0x0f;

	if (addr < 4)
	{
		m_input_data[addr] = m_inputs[addr]->read();
		return m_input_data[addr];
	}
	else
	{
		// this is used to validate the inputs
		return ((m_input_data[0] + m_input_data[1] + m_input_data[2] + m_input_data[3]) << 2) | port;
	}
}