summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/iopintc.cpp
blob: 96a8aef6034c66fa0588f13c1eed15e1063f8f1f (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
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/******************************************************************************
*
*   Sony PlayStation 2 IOP interrupt controller device skeleton
*
*   To Do:
*     Everything
*
*/

#include "emu.h"
#include "iopintc.h"

DEFINE_DEVICE_TYPE(SONYIOP_INTC, iop_intc_device, "iopintc", "PlayStation 2 IOP INTC")

iop_intc_device::iop_intc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, SONYIOP_INTC, tag, owner, clock)
	, m_iop(*this, finder_base::DUMMY_TAG)
{
}

iop_intc_device::~iop_intc_device()
{
}

void iop_intc_device::device_start()
{
	save_item(NAME(m_status));
	save_item(NAME(m_mask));
	save_item(NAME(m_enabled));
}

void iop_intc_device::device_reset()
{
	m_status = 0;
	m_mask = 0;
	m_enabled = false;
}

READ32_MEMBER(iop_intc_device::read)
{
	uint32_t ret = 0;
	switch (offset)
	{
		case 0: // I_STAT
			ret = m_status;
			//logerror("%s: read: I_STAT %08x & %08x\n", machine().describe_context(), ret, mem_mask);
			break;
		case 1: // I_MASK
			ret = m_mask;
			//logerror("%s: read: I_MASK %08x & %08x\n", machine().describe_context(), ret, mem_mask);
			break;
		case 2: // I_ENABLE
			ret = m_enabled ? 1 : 0;
			m_enabled = false;
			update_interrupts();
			//logerror("%s: read: I_ENABLE %08x & %08x\n", machine().describe_context(), ret, mem_mask);
			break;
		default:
			logerror("%s: read: Unknown offset %08x & %08x\n", machine().describe_context(), 0x1f801070 + (offset << 2), mem_mask);
			break;
	}
	return ret;
}

WRITE32_MEMBER(iop_intc_device::write)
{
	switch (offset)
	{
		case 0: // I_STAT
			//logerror("%s: write: I_STAT = %08x & %08x\n", machine().describe_context(), data, mem_mask);
			m_status &= data;
			update_interrupts();
			break;
		case 1: // I_MASK
			//logerror("%s: write: I_MASK = %08x & %08x\n", machine().describe_context(), data, mem_mask);
			m_mask = data;
			update_interrupts();
			break;
		case 2: // I_ENABLE
			//logerror("%s: write: I_ENABLE = %08x & %08x\n", machine().describe_context(), data, mem_mask);
			m_enabled = BIT(data, 0);
			update_interrupts();
			break;
		default:
			logerror("%s: write: Unknown offset %08x = %08x & %08x\n", machine().describe_context(), 0x1f801070 + (offset << 2), data, mem_mask);
			break;
	}
}

void iop_intc_device::raise_interrupt(uint32_t line)
{
	//logerror("%s: raise_interrupt: %d\n", machine().describe_context(), line);
	m_status |= (1 << line);
	update_interrupts();
}

void iop_intc_device::update_interrupts()
{
	bool active = (m_enabled && (m_status & m_mask));
	//printf("iop_intc: %d && (%08x & %08x) = %d\n", m_enabled, m_status, m_mask, active);
	m_iop->set_input_line(INPUT_LINE_IRQ0, active ? ASSERT_LINE : CLEAR_LINE);
}