summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/vt1682_alu.cpp
blob: f782a51f89e58b1cd0ace426857eeb67b1b444fd (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// license:BSD-3-Clause
// copyright-holders:David Haywood

#include "emu.h"
#include "machine/vt1682_alu.h"

#define LOG_ALU     (1U << 1)

#define LOG_ALL           ( LOG_ALU )

#define VERBOSE             (0)
#include "logmacro.h"


DEFINE_DEVICE_TYPE(VT_VT1682_ALU, vrt_vt1682_alu_device, "vt1682alu", "VRT VT1682 ALU")

vrt_vt1682_alu_device::vrt_vt1682_alu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, VT_VT1682_ALU, tag, owner, clock)
{
}

void vrt_vt1682_alu_device::device_start()
{
	save_item(NAME(m_alu_oprand));
	save_item(NAME(m_alu_oprand_mult));
	save_item(NAME(m_alu_oprand_div));
	save_item(NAME(m_alu_out));


}

void vrt_vt1682_alu_device::device_reset()
{
	for (int i=0;i<4;i++)
		m_alu_oprand[i] = 0;

	for (int i = 0; i < 2; i++)
	{
		m_alu_oprand_mult[i] = 0;
		m_alu_oprand_div[i] = 0;
	}

	for (int i=0;i<6;i++)
		m_alu_out[i] = 0;
}



/*
    Address 0x2130 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Oprand 1
    0x40 - ALU Oprand 1
    0x20 - ALU Oprand 1
    0x10 - ALU Oprand 1
    0x08 - ALU Oprand 1
    0x04 - ALU Oprand 1
    0x02 - ALU Oprand 1
    0x01 - ALU Oprand 1

    Address 0x2130 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 1
    0x40 - ALU Output 1
    0x20 - ALU Output 1
    0x10 - ALU Output 1
    0x08 - ALU Output 1
    0x04 - ALU Output 1
    0x02 - ALU Output 1
    0x01 - ALU Output 1
*/

uint8_t vrt_vt1682_alu_device::alu_out_1_r()
{
	uint8_t ret = m_alu_out[0];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_1_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

void vrt_vt1682_alu_device::alu_oprand_1_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_1_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand[0] = data;
}

/*
    Address 0x2131 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Oprand 2
    0x40 - ALU Oprand 2
    0x20 - ALU Oprand 2
    0x10 - ALU Oprand 2
    0x08 - ALU Oprand 2
    0x04 - ALU Oprand 2
    0x02 - ALU Oprand 2
    0x01 - ALU Oprand 2

    Address 0x2131 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 2
    0x40 - ALU Output 2
    0x20 - ALU Output 2
    0x10 - ALU Output 2
    0x08 - ALU Output 2
    0x04 - ALU Output 2
    0x02 - ALU Output 2
    0x01 - ALU Output 2
*/

uint8_t vrt_vt1682_alu_device::alu_out_2_r()
{
	uint8_t ret = m_alu_out[1];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_2_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

void vrt_vt1682_alu_device::alu_oprand_2_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_2_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand[1] = data;
}

/*
    Address 0x2132 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Oprand 3
    0x40 - ALU Oprand 3
    0x20 - ALU Oprand 3
    0x10 - ALU Oprand 3
    0x08 - ALU Oprand 3
    0x04 - ALU Oprand 3
    0x02 - ALU Oprand 3
    0x01 - ALU Oprand 3

    Address 0x2132 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 3
    0x40 - ALU Output 3
    0x20 - ALU Output 3
    0x10 - ALU Output 3
    0x08 - ALU Output 3
    0x04 - ALU Output 3
    0x02 - ALU Output 3
    0x01 - ALU Output 3
*/

uint8_t vrt_vt1682_alu_device::alu_out_3_r()
{
	uint8_t ret = m_alu_out[2];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_3_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

void vrt_vt1682_alu_device::alu_oprand_3_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_3_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand[2] = data;
}


/*
    Address 0x2133 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Oprand 4
    0x40 - ALU Oprand 4
    0x20 - ALU Oprand 4
    0x10 - ALU Oprand 4
    0x08 - ALU Oprand 4
    0x04 - ALU Oprand 4
    0x02 - ALU Oprand 4
    0x01 - ALU Oprand 4

    Address 0x2133 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 4
    0x40 - ALU Output 4
    0x20 - ALU Output 4
    0x10 - ALU Output 4
    0x08 - ALU Output 4
    0x04 - ALU Output 4
    0x02 - ALU Output 4
    0x01 - ALU Output 4
*/

uint8_t vrt_vt1682_alu_device::alu_out_4_r()
{
	uint8_t ret = m_alu_out[3];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_4_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}


void vrt_vt1682_alu_device::alu_oprand_4_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_4_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand[3] = data;
}

/*
    Address 0x2134 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Mul Oprand 5
    0x40 - ALU Mul Oprand 5
    0x20 - ALU Mul Oprand 5
    0x10 - ALU Mul Oprand 5
    0x08 - ALU Mul Oprand 5
    0x04 - ALU Mul Oprand 5
    0x02 - ALU Mul Oprand 5
    0x01 - ALU Mul Oprand 5

    Address 0x2134 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 5
    0x40 - ALU Output 5
    0x20 - ALU Output 5
    0x10 - ALU Output 5
    0x08 - ALU Output 5
    0x04 - ALU Output 5
    0x02 - ALU Output 5
    0x01 - ALU Output 5
*/

uint8_t vrt_vt1682_alu_device::alu_out_5_r()
{
	uint8_t ret = m_alu_out[4];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_5_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}


void vrt_vt1682_alu_device::alu_oprand_5_mult_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_5_mult_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand_mult[0] = data;
}


/*
    Address 0x2135 WRITE (MAIN CPU & SOUND CPU)

    0x80 - ALU Mul Oprand 6
    0x40 - ALU Mul Oprand 6
    0x20 - ALU Mul Oprand 6
    0x10 - ALU Mul Oprand 6
    0x08 - ALU Mul Oprand 6
    0x04 - ALU Mul Oprand 6
    0x02 - ALU Mul Oprand 6
    0x01 - ALU Mul Oprand 6

    Address 0x2135 READ (MAIN CPU & SOUND CPU)

    0x80 - ALU Output 6
    0x40 - ALU Output 6
    0x20 - ALU Output 6
    0x10 - ALU Output 6
    0x08 - ALU Output 6
    0x04 - ALU Output 6
    0x02 - ALU Output 6
    0x01 - ALU Output 6
*/

uint8_t vrt_vt1682_alu_device::alu_out_6_r()
{
	uint8_t ret = m_alu_out[5];
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_out_6_r returning: %02x\n", machine().describe_context(), ret);
	return ret;
}

void vrt_vt1682_alu_device::alu_oprand_6_mult_w(uint8_t data)
{
	// used one of the 32in1 menus

	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_6_mult_w writing: %02x\n", machine().describe_context(), data);
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "------------------------------------------ MULTIPLICATION REQUESTED ------------------------------------\n");
	m_alu_oprand_mult[1] = data;

	int param1 = (m_alu_oprand_mult[1] << 8) | m_alu_oprand_mult[0];
	int param2 = (m_alu_oprand[1] << 8) | m_alu_oprand[0];

	uint32_t result = param1 * param2;

	m_alu_out[0] = result & 0xff;
	m_alu_out[1] = (result >> 8) & 0xff;
	m_alu_out[2] = (result >> 16) & 0xff;
	m_alu_out[3] = (result >> 24) & 0xff;

	// oprands 5/6 cleared?
}


/*
    Address 0x2136 WRITE ONLY (MAIN CPU & SOUND CPU)

    0x80 - ALU Div Oprand 5
    0x40 - ALU Div Oprand 5
    0x20 - ALU Div Oprand 5
    0x10 - ALU Div Oprand 5
    0x08 - ALU Div Oprand 5
    0x04 - ALU Div Oprand 5
    0x02 - ALU Div Oprand 5
    0x01 - ALU Div Oprand 5

*/

void vrt_vt1682_alu_device::alu_oprand_5_div_w(uint8_t data)
{
	if (!m_is_sound_alu) LOGMASKED(LOG_ALU, "%s: alu_oprand_5_div_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand_div[0] = data;
}

/*
    Address 0x2137 WRITE ONLY (MAIN CPU & SOUND CPU)

    0x80 - ALU Div Oprand 6
    0x40 - ALU Div Oprand 6
    0x20 - ALU Div Oprand 6
    0x10 - ALU Div Oprand 6
    0x08 - ALU Div Oprand 6
    0x04 - ALU Div Oprand 6
    0x02 - ALU Div Oprand 6
    0x01 - ALU Div Oprand 6
*/

void vrt_vt1682_alu_device::alu_oprand_6_div_w(uint8_t data)
{
	//LOGMASKED(LOG_ALU, "%s: alu_oprand_6_div_w writing: %02x\n", machine().describe_context(), data);
	m_alu_oprand_div[1] = data;

	uint32_t param1 = (m_alu_oprand[3] << 24) | (m_alu_oprand[2] << 16) | (m_alu_oprand[1] << 8) | m_alu_oprand[0];
	// sources say the mult registers areu sed here, but that makes little sense?
	uint32_t param2 = (m_alu_oprand_div[1] << 8) | m_alu_oprand_div[0];

	if (param2 != 0)
	{
		//if (!m_is_sound_alu) popmessage("------------------------------------------ DIVISION REQUESTED ------------------------------------\n");

		uint32_t result = param1 / param2;

		m_alu_out[0] = result & 0xff;
		m_alu_out[1] = (result >> 8) & 0xff;
		m_alu_out[2] = (result >> 16) & 0xff;
		m_alu_out[3] = (result >> 24) & 0xff;

		// should be the remainder?
		m_alu_out[4] = 0x00;// machine().rand();
		m_alu_out[5] = 0x00;// machine().rand();

	}
}