summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/input_merger.h
blob: 325f1c7732833273db7526ea0e30cc66637d1362 (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:Dirk Best
/***************************************************************************

    Input Merger

    Used to connect multiple lines to a single device input while
    keeping it pulled high or low

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

#pragma once

#ifndef __INPUT_MERGER_H__
#define __INPUT_MERGER_H__



//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_INPUT_MERGER_ACTIVE_HIGH(_tag) \
	MCFG_DEVICE_ADD(_tag, INPUT_MERGER_ACTIVE_HIGH, 0)

#define MCFG_INPUT_MERGER_ACTIVE_LOW(_tag) \
	MCFG_DEVICE_ADD(_tag, INPUT_MERGER_ACTIVE_LOW, 0)

#define MCFG_INPUT_MERGER_OUTPUT_HANDLER(_devcb) \
	devcb = &input_merger_device::set_output_handler(*device, DEVCB_##_devcb);


//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> input_merger_device

class input_merger_device : public device_t
{
public:
	// callback
	template<class _Object> static devcb_base &set_output_handler(device_t &device, _Object object)
		{ return downcast<input_merger_device &>(device).m_output_handler.set_callback(object); }

	// input lines
	DECLARE_WRITE_LINE_MEMBER( in0_w ) { m_state[0] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in1_w ) { m_state[1] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in2_w ) { m_state[2] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in3_w ) { m_state[3] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in4_w ) { m_state[4] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in5_w ) { m_state[5] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in6_w ) { m_state[6] = state; update_state(); };
	DECLARE_WRITE_LINE_MEMBER( in7_w ) { m_state[7] = state; update_state(); };

protected:
	// constructor/destructor
	input_merger_device(machine_config const &mconfig, device_type type, char const *name, char const *tag, device_t *owner, uint32_t clock, char const *shortname, char const *source);
	virtual ~input_merger_device() override;

	// device-level overrides
	virtual void device_start() override;

	virtual void update_state() = 0;

	devcb_write_line m_output_handler;
	bool m_state[8];
};

// ======================> input_merger_active_high_device

class input_merger_active_high_device : public input_merger_device
{
public:
	input_merger_active_high_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:
	// device-level overrides
	virtual void device_reset() override;

	// input_merger device overrides
	virtual void update_state() override;
};

// ======================> input_merger_active_low_device

class input_merger_active_low_device : public input_merger_device
{
public:
	input_merger_active_low_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:
	// device-level overrides
	virtual void device_reset() override;

	// input_merger device overrides
	virtual void update_state() override;
};


// device type definition
extern const device_type INPUT_MERGER_ACTIVE_HIGH;
extern const device_type INPUT_MERGER_ACTIVE_LOW;


#endif  /* __INPUT_MERGER_H__ */