summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/sh/sh_dmac.h
blob: 3c8436df0d8c3f735773b880d92adf9a036dcea7 (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
/***************************************************************************

    sh_dmac.h

    SH DMA controller

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

#ifndef MAME_CPU_SH_SH_DMAC_H
#define MAME_CPU_SH_SH_DMAC_H

#pragma once

// To generalize eventually
class sh7042_device;
class sh_intc_device;

class sh_dmac_device : public device_t {
public:
	sh_dmac_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);

	template <typename T> sh_dmac_device(const machine_config &mconfig, const char *tag, device_t *owner, T &&cpu)
		: sh_dmac_device(mconfig, tag, owner)
	{
		set_info(cpu);
	}

	template<typename T> void set_info(T &&cpu) { m_cpu.set_tag(std::forward<T>(cpu)); }

	u16 dmaor_r();
	void dmaor_w(offs_t, u16 data, u16 mem_mask);


protected:
	required_device<sh7042_device> m_cpu;

	u16 m_dmaor;

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

class sh_dmac_channel_device : public device_t {
public:
	sh_dmac_channel_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);

	template <typename T, typename U> sh_dmac_channel_device(const machine_config &mconfig, const char *tag, device_t *owner, T &&cpu, U &&intc)
		: sh_dmac_channel_device(mconfig, tag, owner)
	{
		set_info(cpu, intc);
	}

	template<typename T, typename U> void set_info(T &&cpu, U &&intc) { m_cpu.set_tag(std::forward<T>(cpu)); m_intc.set_tag(std::forward<U>(intc)); }

	u32 sar_r();
	void sar_w(offs_t, u32 data, u32 mem_mask);
	u32 dar_r();
	void dar_w(offs_t, u32 data, u32 mem_mask);
	u32 dmatcr_r();
	void dmatcr_w(offs_t, u32 data, u32 mem_mask);
	u32 chcr_r();
	void chcr_w(offs_t, u32 data, u32 mem_mask);

protected:
	required_device<sh7042_device> m_cpu;
	required_device<sh_intc_device> m_intc;

	u32 m_sar, m_dar, m_dmatcr, m_chcr;

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

DECLARE_DEVICE_TYPE(SH_DMAC, sh_dmac_device)
DECLARE_DEVICE_TYPE(SH_DMAC_CHANNEL, sh_dmac_channel_device)

#endif