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

    h8_dtc.h

    H8 Data Transfer Controller

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

#ifndef MAME_CPU_H8_H8_DTC_H
#define MAME_CPU_H8_H8_DTC_H

#pragma once

#include "h8_intc.h"

#include <list>

struct h8_dtc_state {
	u32 m_base, m_sra, m_dar, m_cr;
	s32 m_incs, m_incd;
	u32 m_count;
	int m_id;
	int m_next;
};

class h8_dtc_device : public device_t {
public:
	enum { DTC_CHAINED = 1000 };

	h8_dtc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
	template<typename T, typename U> h8_dtc_device(const machine_config &mconfig, const char *tag, device_t *owner, T &&cpu, U &&intc, int irq)
		: h8_dtc_device(mconfig, tag, owner)
	{
		m_cpu.set_tag(std::forward<T>(cpu));
		m_intc.set_tag(std::forward<U>(intc));
		m_irq = irq;
	}

	u8 dtcer_r(offs_t offset);
	void dtcer_w(offs_t offset, u8 data);
	u8 dtvecr_r();
	void dtvecr_w(u8 data);

	bool trigger_dtc(int vector);
	void count_done(int id);

	inline h8_dtc_state *get_object(int vector) { return m_states + vector; }
	inline u32 get_vector_address(int vector) { return 0x400 | ((vector ? vector : m_dtvecr & 0x7f) << 1); }
	int get_waiting_vector();
	int get_waiting_writeback();
	void vector_done(int vector);
	void writeback_done(int vector);

protected:
	static const int vector_to_enable[];
	required_device<h8_device> m_cpu;
	required_device<h8_intc_device> m_intc;
	const char *m_intc_tag;
	int m_irq;
	h8_dtc_state m_states[92];

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

	u8 m_dtcer[6], m_dtvecr;
	int m_cur_active_vector;

	std::vector<int> m_waiting_vector, m_waiting_writeback;

	void edge(int vector);
	void queue(int vector);
};

DECLARE_DEVICE_TYPE(H8_DTC, h8_dtc_device)

#endif // MAME_CPU_H8_H8_DTC_H