summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/gen_latch.h
blob: 702c26ff333457f77bbe870ce933f431cbead83d (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/***************************************************************************

    Generic 8bit and 16 bit latch devices

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

#ifndef MAME_MACHINE_GEN_LATCH_H
#define MAME_MACHINE_GEN_LATCH_H

#pragma once



//**************************************************************************
//  DEVICE TYPE DECLARATIONS
//**************************************************************************

DECLARE_DEVICE_TYPE(GENERIC_LATCH_8, generic_latch_8_device)
DECLARE_DEVICE_TYPE(GENERIC_LATCH_16, generic_latch_16_device)


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

#define MCFG_GENERIC_LATCH_8_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, GENERIC_LATCH_8, 0)

#define MCFG_GENERIC_LATCH_16_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, GENERIC_LATCH_16, 0)

#define MCFG_GENERIC_LATCH_DATA_PENDING_CB(_devcb) \
	devcb = &downcast<generic_latch_base_device &>(*device).set_data_pending_callback(DEVCB_##_devcb);

#define MCFG_GENERIC_LATCH_SEPARATE_ACKNOWLEDGE(_ack) \
	downcast<generic_latch_base_device &>(*device).set_separate_acknowledge(_ack);


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

// ======================> generic_latch_base_device

class generic_latch_base_device : public device_t
{
public:
	// configuration
	template <class Object> devcb_base &set_data_pending_callback(Object &&cb) { return m_data_pending_cb.set_callback(std::forward<Object>(cb)); }
	void set_separate_acknowledge(bool ack) { m_separate_acknowledge = ack; }

	DECLARE_READ_LINE_MEMBER(pending_r);

	DECLARE_READ8_MEMBER( acknowledge_r );
	DECLARE_WRITE8_MEMBER( acknowledge_w );

protected:
	// construction/destruction
	generic_latch_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);

	virtual void device_start() override;
	virtual void device_reset() override;

	bool has_separate_acknowledge() const { return m_separate_acknowledge; }
	bool is_latch_written() const { return m_latch_written; }
	void set_latch_written(bool latch_written);

private:
	void init_callback(void *ptr, s32 param);

	bool                    m_separate_acknowledge;
	bool                    m_latch_written;
	devcb_write_line        m_data_pending_cb;
};


// ======================> generic_latch_8_device

class generic_latch_8_device : public generic_latch_base_device
{
public:
	// construction/destruction
	generic_latch_8_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);

	DECLARE_READ8_MEMBER( read );
	DECLARE_WRITE8_MEMBER( write );

	DECLARE_WRITE8_MEMBER( preset_w );
	DECLARE_WRITE8_MEMBER( clear_w );
	DECLARE_WRITE_LINE_MEMBER( preset );
	DECLARE_WRITE_LINE_MEMBER( clear );

	void preset_w(u8 value) { m_latched_value = value; }

protected:
	virtual void device_start() override;

	void sync_callback(void *ptr, s32 param);

private:
	u8 m_latched_value;
};


// ======================> generic_latch_16_device

class generic_latch_16_device : public generic_latch_base_device
{
public:
	// construction/destruction
	generic_latch_16_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);

	DECLARE_READ16_MEMBER( read );
	DECLARE_WRITE16_MEMBER( write );

	DECLARE_WRITE16_MEMBER( preset_w );
	DECLARE_WRITE16_MEMBER( clear_w );
	DECLARE_WRITE_LINE_MEMBER( preset );
	DECLARE_WRITE_LINE_MEMBER( clear );

	void preset_w(u16 value) { m_latched_value = value; }

protected:
	virtual void device_start() override;

	void sync_callback(void *ptr, s32 param);

private:
	u16 m_latched_value;
};

#endif  // MAME_MACHINE_GEN_LATCH_H