summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/dmac_0266.h
blob: 83150106d5de3dc3a60f1d1932aa5d12d9c463d2 (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
// license:BSD-3-Clause
// copyright-holders:Patrick Mackinlay

#ifndef MAME_MACHINE_DMAC_0266_H
#define MAME_MACHINE_DMAC_0266_H

#pragma once

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

	// configuration
	template <typename T> void set_bus(T &&tag, int spacenum) { m_bus.set_tag(std::forward<T>(tag), spacenum); }

	auto dma_r_cb() { return m_dma_r.bind(); }
	auto dma_w_cb() { return m_dma_w.bind(); }

	void map(address_map &map);

	void eop_w(int state);
	void req_w(int state);

protected:
	// device_t overrides
	virtual void device_start() override;
	virtual void device_reset() override;

	// register handlers
	u32 control_r() { return m_control; }
	u32 status_r() { return m_status | (m_control & (DIRECTION | ENABLE)); }
	u32 tcount_r() { return m_tcount; }

	void control_w(u32 data);
	void tcount_w(u32 data) { m_tcount = data; }
	void tag_w(u32 data)    { m_tag = data; }
	void offset_w(u32 data) { m_offset = data; }
	void entry_w(u32 data)  { m_map[m_tag & 0x7f] = data & 0x7fff; }

	// dma logic
	void soft_reset();
	void dma_check(void *ptr, s32 param);

private:
	required_address_space m_bus;

	devcb_read8 m_dma_r;
	devcb_write8 m_dma_w;

	emu_timer *m_dma_check;

	enum control_mask : u32
	{
		ENABLE    = 0x01,
		DIRECTION = 0x02,
		RESET     = 0x04,
	};

	enum status_mask : u32
	{
		INTERRUPT = 0x08,
		TCZERO    = 0x10,
	};

	// registers
	u32 m_control;
	u32 m_status;
	u32 m_tcount;
	u32 m_tag;
	u32 m_offset;
	u32 m_map[129];

	// internal state
	bool m_req_state;
};

DECLARE_DEVICE_TYPE(DMAC_0266, dmac_0266_device)

#endif // MAME_MACHINE_DMAC_0266_H