summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/hp98x5_io_sys.cpp
blob: f403117f172f13dc730c7ec5a7d67744cc3dbf69 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// License:BSD-3-Clause
// copyright-holders:F. Ulivi
/*********************************************************************

    hp98x5_io_sys.cpp

    HP98x5 I/O sub-system

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

#include "emu.h"
#include "hp98x5_io_sys.h"
#include "cpu/hphybrid/hphybrid.h"

// Bit manipulation
namespace {
	template<typename T> constexpr T BIT_MASK(unsigned n)
	{
		return (T)1U << n;
	}

	template<typename T> void BIT_CLR(T& w , unsigned n)
	{
		w &= ~BIT_MASK<T>(n);
	}

	template<typename T> void BIT_SET(T& w , unsigned n)
	{
		w |= BIT_MASK<T>(n);
	}
}

// Device type definition
DEFINE_DEVICE_TYPE(HP98X5_IO_SYS, hp98x5_io_sys_device, "hp98x5_io_sys", "HP98x5 I/O sub-system")

hp98x5_io_sys_device::hp98x5_io_sys_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig , HP98X5_IO_SYS , tag , owner , clock)
	, m_irl_handler(*this)
	, m_irh_handler(*this)
	, m_flg_handler(*this)
	, m_sts_handler(*this)
	, m_dmar_handler(*this)
{
}

void hp98x5_io_sys_device::device_start()
{
	m_irl_handler.resolve_safe();
	m_irh_handler.resolve_safe();
	m_flg_handler.resolve_safe();
	m_sts_handler.resolve_safe();
	m_dmar_handler.resolve_safe();

	save_item(NAME(m_irq_pending));
	save_item(NAME(m_pa));
	save_item(NAME(m_flg_status));
	save_item(NAME(m_sts_status));
	save_item(NAME(m_dmar_status));
}

void hp98x5_io_sys_device::device_reset()
{
	m_irq_pending = 0;
	update_irq();
	m_pa = 0;
	m_flg_status = 0;
	m_sts_status = 0;
	update_flg_sts();
	m_dmar_status = 0;
	update_dmar();
}

uint8_t hp98x5_io_sys_device::int_r(offs_t offset)
{
	if (offset == 0) {
		return m_irq_pending & 0xff;
	} else {
		return m_irq_pending >> 8;
	}
}

void hp98x5_io_sys_device::pa_w(uint8_t data)
{
	m_pa = data;
	update_flg_sts();
}

void hp98x5_io_sys_device::set_irq(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_irq_pending, sc);
	} else {
		BIT_CLR(m_irq_pending, sc);
	}
	update_irq();
}

void hp98x5_io_sys_device::set_sts(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_sts_status, sc);
	} else {
		BIT_CLR(m_sts_status, sc);
	}
	if (sc == m_pa) {
		update_flg_sts();
	}
}

void hp98x5_io_sys_device::set_flg(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_flg_status, sc);
	} else {
		BIT_CLR(m_flg_status, sc);
	}
	if (sc == m_pa) {
		update_flg_sts();
	}
}

void hp98x5_io_sys_device::set_dmar(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_dmar_status, sc);
	} else {
		BIT_CLR(m_dmar_status, sc);
	}
	update_dmar();
}

bool hp98x5_io_sys_device::is_irq_pending(uint8_t sc) const
{
	return BIT(m_irq_pending , sc);
}

void hp98x5_io_sys_device::update_irq()
{
	m_irl_handler((m_irq_pending & 0x00ff) != 0);
	m_irh_handler((m_irq_pending & 0xff00) != 0);
}

void hp98x5_io_sys_device::update_flg_sts()
{
	bool sts = BIT(m_sts_status , m_pa);
	bool flg = BIT(m_flg_status , m_pa);
	m_sts_handler(sts);
	m_flg_handler(flg);
}

void hp98x5_io_sys_device::update_dmar()
{
	m_dmar_handler(m_dmar_status != 0);
}