summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/am25s55x.cpp
blob: b162417946381026eaa1a1a22dac1bbdaf14284b (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/***************************************************************************

    am25s55x.cpp
    AMD Am25S557/Am25S558 8x8-bit Combinatorial Multiplier

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

#include "emu.h"
#include "am25s55x.h"

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

DEFINE_DEVICE_TYPE(AM25S557, am25s557_device, "am25s557", "AMD Am25S557 Combinatorial Multiplier")
DEFINE_DEVICE_TYPE(AM25S558, am25s558_device, "am25s558", "AMD Am25S558 Combinatorial Multiplier")

//-------------------------------------------------
//  am25s55x_device - constructor
//-------------------------------------------------

am25s55x_device::am25s55x_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, m_x_in(0)
	, m_y_in(0)
	, m_xm(false)
	, m_ym(false)
	, m_oe(false)
	, m_round_s(false)
	, m_round_u(false)
	, m_s(*this)
{
}

am25s557_device::am25s557_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: am25s55x_device(mconfig, AM25S557, tag, owner, clock)
	, m_r(false)
{
}

am25s558_device::am25s558_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: am25s55x_device(mconfig, AM25S558, tag, owner, clock)
{
}

void am25s55x_device::device_start()
{
	save_item(NAME(m_x_in));
	save_item(NAME(m_y_in));
	save_item(NAME(m_xm));
	save_item(NAME(m_ym));
	save_item(NAME(m_oe));
	save_item(NAME(m_round_s));
	save_item(NAME(m_round_u));
	save_item(NAME(m_x.u));
	save_item(NAME(m_y.u));
	save_item(NAME(m_s_out.u));

	m_s.resolve_safe();
}

void am25s55x_device::device_reset()
{
	m_x_in = 0;
	m_y_in = 0;
	m_xm = false;
	m_ym = false;
	m_oe = false;
	m_round_s = false;
	m_round_u = false;

	m_x.u = 0;
	m_y.u = 0;
	m_s_out.u = 0;
}

void am25s55x_device::x_w(uint8_t data)
{
	m_x_in = data;
}

void am25s55x_device::y_w(uint8_t data)
{
	m_y_in = data;
}

void am25s55x_device::xm_w(int state)
{
	m_xm = (bool)state;
}

void am25s55x_device::ym_w(int state)
{
	m_ym = (bool)state;
}

void am25s55x_device::oe_w(int state)
{
	m_oe = (bool)state;
}

void am25s55x_device::multiply()
{
	if (m_xm)
	{
		if (m_ym)
		{
			m_s_out.s = (int16_t)m_x.u * (int16_t)m_y.u;
		}
		else
		{
			m_s_out.s = (int16_t)m_x.u * (uint16_t)m_y.u;
		}
	}
	else
	{
		if (m_ym)
		{
			m_s_out.s = (uint16_t)m_x.u * (int16_t)m_y.u;
		}
		else
		{
			m_s_out.u = (uint16_t)m_x.u * (uint16_t)m_y.u;
		}
	}

	if (m_round_u)
		m_s_out.u += 0x80;
	if (m_round_s)
		m_s_out.u += 0x40;

	if (!m_oe)
		m_s(m_s_out.u);
}

//
// Am25S557, combined signed/unsigned rounding pin
//

void am25s557_device::device_start()
{
	am25s55x_device::device_start();
	save_item(NAME(m_r));
}

void am25s557_device::device_reset()
{
	am25s55x_device::device_reset();
	m_r = false;
}

void am25s557_device::xm_w(int state)
{
	am25s55x_device::xm_w(state);
	update_rounding();
}

void am25s557_device::ym_w(int state)
{
	am25s55x_device::ym_w(state);
	update_rounding();
}

void am25s557_device::r_w(int state)
{
	m_r = (bool)state;
	update_rounding();
}

void am25s557_device::update_rounding()
{
	if (m_r)
	{
		if (m_xm || m_ym)
		{
			m_round_s = true;
			m_round_u = false;
		}
		else
		{
			m_round_s = false;
			m_round_u = true;
		}
	}
	else
	{
		m_round_s = false;
		m_round_u = false;
	}
}

//
// Am25S558, separate signed/unsigned rounding pins
//

void am25s558_device::rs_w(int state)
{
	m_round_s = (bool)state;
}

void am25s558_device::ru_w(int state)
{
	m_round_u = (bool)state;
}