summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/ioptimer.h
blob: 8683f3cd61e33669d370002300a507ae217d4adf (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
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/******************************************************************************
*
*   Sony PlayStation 2 IOP timer device skeleton
*
*   To Do:
*     Everything
*
*/

#ifndef MAME_MACHINE_IOPTIMER_H
#define MAME_MACHINE_IOPTIMER_H

#pragma once

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

	auto irq() { return m_int_cb.bind(); }

	DECLARE_READ32_MEMBER(read);
	DECLARE_WRITE32_MEMBER(write);

protected:
	enum timer_ctrl_mask : uint32_t
	{
		CTRL_GATE = (1 << 0),
		CTRL_GATM = (3 << 1),
		CTRL_ZRET = (1 << 3),
		CTRL_CMPE = (1 << 4),
		CTRL_OVFE = (1 << 5),
		CTRL_REPI = (1 << 6),
		CTRL_TOGI = (1 << 7),
		CTRL_INTE = (1 << 10),
		CTRL_CMPF = (1 << 11),
		CTRL_OVFF = (1 << 12),
	};

	enum timer_gate_mode : uint32_t
	{
		GATM_LOW = 0,
		GATM_RISING,
		GATM_FALLING,
		GATM_BOTH
	};

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

	TIMER_CALLBACK_MEMBER(compare);
	TIMER_CALLBACK_MEMBER(overflow);

	void set_ctrl(uint32_t data);

	void update_gate();
	void update_interrupts();

	void update_compare_timer();
	void update_overflow_timer();

	void update_count();

	emu_timer *m_compare_timer;
	emu_timer *m_overflow_timer;

	uint32_t m_ctrl;

	attotime m_last_update_time;
	attotime m_elapsed_time;
	bool m_zero_return;
	uint32_t m_count;
	uint32_t m_compare;

	bool m_gate_enable;
	timer_gate_mode m_gate_mode;

	bool m_cmp_int_enabled;
	bool m_cmp_int;

	bool m_ovf_int_enabled;
	bool m_ovf_int;

	bool m_repeat_int;
	bool m_toggle_int;

	bool m_ienable;
	devcb_write_line m_int_cb;
};

DECLARE_DEVICE_TYPE(SONYIOP_TIMER, iop_timer_device)

#endif // MAME_MACHINE_IOPTIMER_H