summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/emumem_hedp.h
blob: 37b47747d618d7463fe5d6eb91a735ffcc3ec816 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert

// handler_entry_read_delegate/handler_entry_write_delegate

// Executes an access through called a delegate, usually containing a handler or a lambda

template<int Width, int AddrShift, int Endian, typename READ> class handler_entry_read_delegate : public handler_entry_read_address<Width, AddrShift, Endian>
{
public:
	using uX = typename emu::detail::handler_entry_size<Width>::uX;
	using inh = handler_entry_read_address<Width, AddrShift, Endian>;

	handler_entry_read_delegate(address_space *space, const READ &delegate) : handler_entry_read_address<Width, AddrShift, Endian>(space, 0), m_delegate(delegate) {}
	~handler_entry_read_delegate() = default;

	uX read(offs_t offset, uX mem_mask) override;

	std::string name() const override;

private:
	READ m_delegate;

	template<typename R>
		std::enable_if_t<std::is_same<R, read8_delegate>::value ||
						 std::is_same<R, read16_delegate>::value ||
						 std::is_same<R, read32_delegate>::value ||
						 std::is_same<R, read64_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);

	template<typename R>
		std::enable_if_t<std::is_same<R, read8m_delegate>::value ||
						 std::is_same<R, read16m_delegate>::value ||
						 std::is_same<R, read32m_delegate>::value ||
						 std::is_same<R, read64m_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);

	template<typename R>
		std::enable_if_t<std::is_same<R, read8s_delegate>::value ||
						 std::is_same<R, read16s_delegate>::value ||
						 std::is_same<R, read32s_delegate>::value ||
						 std::is_same<R, read64s_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);

	template<typename R>
		std::enable_if_t<std::is_same<R, read8sm_delegate>::value ||
						 std::is_same<R, read16sm_delegate>::value ||
						 std::is_same<R, read32sm_delegate>::value ||
						 std::is_same<R, read64sm_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);

	template<typename R>
		std::enable_if_t<std::is_same<R, read8mo_delegate>::value ||
						 std::is_same<R, read16mo_delegate>::value ||
						 std::is_same<R, read32mo_delegate>::value ||
						 std::is_same<R, read64mo_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);

	template<typename R>
		std::enable_if_t<std::is_same<R, read8smo_delegate>::value ||
						 std::is_same<R, read16smo_delegate>::value ||
						 std::is_same<R, read32smo_delegate>::value ||
						 std::is_same<R, read64smo_delegate>::value,
						 uX> read_impl(offs_t offset, uX mem_mask);
};

template<int Width, int AddrShift, int Endian, typename WRITE> class handler_entry_write_delegate : public handler_entry_write_address<Width, AddrShift, Endian>
{
public:
	using uX = typename emu::detail::handler_entry_size<Width>::uX;
	using inh = handler_entry_write_address<Width, AddrShift, Endian>;

	handler_entry_write_delegate(address_space *space, const WRITE &delegate) : handler_entry_write_address<Width, AddrShift, Endian>(space, 0), m_delegate(delegate) {}
	~handler_entry_write_delegate() = default;

	void write(offs_t offset, uX data, uX mem_mask) override;

	std::string name() const override;

private:
	WRITE m_delegate;

	template<typename W>
		std::enable_if_t<std::is_same<W, write8_delegate>::value ||
						 std::is_same<W, write16_delegate>::value ||
						 std::is_same<W, write32_delegate>::value ||
						 std::is_same<W, write64_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);

	template<typename W>
		std::enable_if_t<std::is_same<W, write8m_delegate>::value ||
						 std::is_same<W, write16m_delegate>::value ||
						 std::is_same<W, write32m_delegate>::value ||
						 std::is_same<W, write64m_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);

	template<typename W>
		std::enable_if_t<std::is_same<W, write8s_delegate>::value ||
						 std::is_same<W, write16s_delegate>::value ||
						 std::is_same<W, write32s_delegate>::value ||
						 std::is_same<W, write64s_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);

	template<typename W>
		std::enable_if_t<std::is_same<W, write8sm_delegate>::value ||
						 std::is_same<W, write16sm_delegate>::value ||
						 std::is_same<W, write32sm_delegate>::value ||
						 std::is_same<W, write64sm_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);

	template<typename W>
		std::enable_if_t<std::is_same<W, write8mo_delegate>::value ||
						 std::is_same<W, write16mo_delegate>::value ||
						 std::is_same<W, write32mo_delegate>::value ||
						 std::is_same<W, write64mo_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);

	template<typename W>
		std::enable_if_t<std::is_same<W, write8smo_delegate>::value ||
						 std::is_same<W, write16smo_delegate>::value ||
						 std::is_same<W, write32smo_delegate>::value ||
						 std::is_same<W, write64smo_delegate>::value,
						 void> write_impl(offs_t offset, uX data, uX mem_mask);
};


// handler_entry_read_ioport/handler_entry_write_ioport

// Accesses an ioport

template<int Width, int AddrShift, int Endian> class handler_entry_read_ioport : public handler_entry_read<Width, AddrShift, Endian>
{
public:
	using uX = typename emu::detail::handler_entry_size<Width>::uX;
	using inh = handler_entry_read<Width, AddrShift, Endian>;

	handler_entry_read_ioport(address_space *space, ioport_port *port) : handler_entry_read<Width, AddrShift, Endian>(space, 0), m_port(port) {}
	~handler_entry_read_ioport() = default;

	uX read(offs_t offset, uX mem_mask) override;

	std::string name() const override;

private:
	ioport_port *m_port;
};

template<int Width, int AddrShift, int Endian> class handler_entry_write_ioport : public handler_entry_write<Width, AddrShift, Endian>
{
public:
	using uX = typename emu::detail::handler_entry_size<Width>::uX;
	using inh = handler_entry_write<Width, AddrShift, Endian>;

	handler_entry_write_ioport(address_space *space, ioport_port *port) : handler_entry_write<Width, AddrShift, Endian>(space, 0), m_port(port) {}
	~handler_entry_write_ioport() = default;

	void write(offs_t offset, uX data, uX mem_mask) override;

	std::string name() const override;

private:
	ioport_port *m_port;
};