summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/harddriv.cpp
blob: 45537c6c6529f600d999682ae0d01a5cb3a578b3 (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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    Hard Drivin' sound hardware

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

#include "emu.h"
#include "includes/harddriv.h"

#include "cpu/tms32010/tms32010.h"
#include "sound/volt_reg.h"
#include "speaker.h"


#define BIO_FREQUENCY       (1000000 / 50)
#define CYCLES_PER_BIO      (5000000 / BIO_FREQUENCY)


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  harddriv_sound_board_device - constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(HARDDRIV_SOUND_BOARD, harddriv_sound_board_device, "harddriv_sound", "Hard Drivin' Sound Board")

harddriv_sound_board_device::harddriv_sound_board_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, HARDDRIV_SOUND_BOARD, tag, owner, clock),
	m_soundcpu(*this, "soundcpu"),
	m_latch(*this, "latch"),
	m_dac(*this, "dac"),
	m_sounddsp(*this, "sounddsp"),
	m_sounddsp_ram(*this, "sounddsp_ram"),
	m_sound_rom(*this, "serialroms"),
	m_soundflag(0),
	m_mainflag(0),
	m_sounddata(0),
	m_maindata(0),
	m_cramen(0),
	m_irq68k(0),
	m_sound_rom_offs(0),
	m_last_bio_cycles(0)
{
	memset(m_comram, 0 , sizeof(m_comram));
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void harddriv_sound_board_device::device_start()
{
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void harddriv_sound_board_device::device_reset()
{
	m_last_bio_cycles = 0;
	m_sounddsp->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
}

/*************************************
 *
 *  Update flags
 *
 *************************************/

void harddriv_sound_board_device::update_68k_interrupts()
{
	m_soundcpu->set_input_line(1, m_mainflag ? ASSERT_LINE : CLEAR_LINE);
	m_soundcpu->set_input_line(3, m_irq68k   ? ASSERT_LINE : CLEAR_LINE);
}



/*************************************
 *
 *  I/O from main CPU side
 *
 *************************************/

uint16_t harddriv_sound_board_device::hd68k_snd_data_r()
{
	m_soundflag = 0;
	logerror("%s:main read from sound=%04X\n", machine().describe_context(), m_sounddata);
	return m_sounddata;
}


uint16_t harddriv_sound_board_device::hd68k_snd_status_r()
{
	return (m_mainflag << 15) | (m_soundflag << 14) | 0x1fff;
}


TIMER_CALLBACK_MEMBER( harddriv_sound_board_device::delayed_68k_w )
{
	m_maindata = param;
	m_mainflag = 1;
	update_68k_interrupts();
}


void harddriv_sound_board_device::hd68k_snd_data_w(uint16_t data)
{
	machine().scheduler().synchronize(timer_expired_delegate(FUNC(harddriv_sound_board_device::delayed_68k_w), this), data);
	logerror("%s:main write to sound=%04X\n", machine().describe_context(), data);
}


void harddriv_sound_board_device::hd68k_snd_reset_w(uint16_t data)
{
	m_soundcpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
	m_soundcpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
	m_mainflag = m_soundflag = 0;
	update_68k_interrupts();
	logerror("%s:Reset sound\n", machine().describe_context());
}



/*************************************
 *
 *  I/O from sound CPU side
 *
 *************************************/

uint16_t harddriv_sound_board_device::hdsnd68k_data_r()
{
	m_mainflag = 0;
	update_68k_interrupts();
	logerror("%s:sound read from main=%04X\n", machine().describe_context(), m_maindata);
	return m_maindata;
}


void harddriv_sound_board_device::hdsnd68k_data_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
	COMBINE_DATA(&m_sounddata);
	m_soundflag = 1;
	logerror("%s:sound write to main=%04X\n", machine().describe_context(), data);
}



/*************************************
 *
 *  Misc. 68k inputs
 *
 *************************************/

uint16_t harddriv_sound_board_device::hdsnd68k_switches_r(offs_t offset)
{
	logerror("%s:hdsnd68k_switches_r(%04X)\n", machine().describe_context(), offset);
	return 0;
}


uint16_t harddriv_sound_board_device::hdsnd68k_320port_r(offs_t offset)
{
	logerror("%s:hdsnd68k_320port_r(%04X)\n", machine().describe_context(), offset);
	return 0;
}


uint16_t harddriv_sound_board_device::hdsnd68k_status_r()
{
//FFFF 3000 R   READSTAT    Read Status
//            D15 = 'Main Flag'
//            D14 = 'Sound Flag'
//            D13 = Test Switch
//            D12 = 5220 Ready Flag (0=Ready)
	//logerror("%s:hdsnd68k_status_r(%04X)\n", machine().describe_context(), offset);
	return (m_mainflag << 15) | (m_soundflag << 14) | 0x2000 | 0;//((ioport("IN0")->read() & 0x0020) << 8) | 0;
}



/*************************************
 *
 *  Misc. 68k outputs
 *
 *************************************/

void harddriv_sound_board_device::hdsnd68k_latches_w(offs_t offset, uint16_t data)
{
	// bit 3 selects the value; data is ignored
	// low 3 bits select the function
	m_latch->write_bit(offset & 7, (offset >> 3) & 1);
}


WRITE_LINE_MEMBER(harddriv_sound_board_device::speech_write_w)
{
	// data == 0 means high, 1 means low
	logerror("%06X:SPWR=%d\n", m_soundcpu->pcbase(), state);
}


WRITE_LINE_MEMBER(harddriv_sound_board_device::speech_reset_w)
{
	// data == 0 means low, 1 means high
	logerror("%06X:SPRES=%d\n", m_soundcpu->pcbase(), state);
}


WRITE_LINE_MEMBER(harddriv_sound_board_device::speech_rate_w)
{
	// data == 0 means 8kHz, 1 means 10kHz
	logerror("%06X:SPRATE=%d\n", m_soundcpu->pcbase(), state);
}


WRITE_LINE_MEMBER(harddriv_sound_board_device::cram_enable_w)
{
	// data == 0 means disable 68k access to COM320, 1 means enable
	m_cramen = state;
}


WRITE_LINE_MEMBER(harddriv_sound_board_device::led_w)
{
}


void harddriv_sound_board_device::hdsnd68k_speech_w(offs_t offset, uint16_t data)
{
	logerror("%s:hdsnd68k_speech_w(%04X)=%04X\n", machine().describe_context(), offset, data);
}


void harddriv_sound_board_device::hdsnd68k_irqclr_w(uint16_t data)
{
	m_irq68k = 0;
	update_68k_interrupts();
}



/*************************************
 *
 *  TMS32010 access
 *
 *************************************/

uint16_t harddriv_sound_board_device::hdsnd68k_320ram_r(offs_t offset)
{
	return m_sounddsp_ram[offset & 0xfff];
}


void harddriv_sound_board_device::hdsnd68k_320ram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
	COMBINE_DATA(&m_sounddsp_ram[offset & 0xfff]);
}


uint16_t harddriv_sound_board_device::hdsnd68k_320ports_r(offs_t offset)
{
	return m_sounddsp->space(AS_IO).read_word(offset & 7);
}


void harddriv_sound_board_device::hdsnd68k_320ports_w(offs_t offset, uint16_t data)
{
	m_sounddsp->space(AS_IO).write_word(offset & 7, data);
}


uint16_t harddriv_sound_board_device::hdsnd68k_320com_r(offs_t offset)
{
	if (m_cramen)
		return m_comram[offset & 0x1ff];

	logerror("%s:hdsnd68k_320com_r(%04X) -- not allowed\n", machine().describe_context(), offset);
	return 0xffff;
}


void harddriv_sound_board_device::hdsnd68k_320com_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
	if (m_cramen)
		COMBINE_DATA(&m_comram[offset & 0x1ff]);
	else
		logerror("%s:hdsnd68k_320com_w(%04X)=%04X -- not allowed\n", machine().describe_context(), offset, data);
}



/*************************************
 *
 *  TMS32010 interrupts
 *
 *************************************/

READ_LINE_MEMBER(harddriv_sound_board_device::hdsnddsp_get_bio)
{
	uint64_t cycles_since_last_bio = m_sounddsp->total_cycles() - m_last_bio_cycles;
	int32_t cycles_until_bio = CYCLES_PER_BIO - cycles_since_last_bio;

	/* if we're not at the next BIO yet, advance us there */
	if (cycles_until_bio > 0)
	{
		m_sounddsp->adjust_icount(-cycles_until_bio);
		m_last_bio_cycles += CYCLES_PER_BIO;
	}
	else
		m_last_bio_cycles = m_sounddsp->total_cycles();
	return ASSERT_LINE;
}



/*************************************
 *
 *  TMS32010 ports
 *
 *************************************/

void harddriv_sound_board_device::hdsnddsp_dac_w(uint16_t data)
{
	/* /DACL */
	m_dac->write((data >> 4) ^ 0x800); // schematics show d0-3 are ignored & the msb is inverted
}


void harddriv_sound_board_device::hdsnddsp_comport_w(uint16_t data)
{
	/* COM port TD0-7 */
	logerror("%s:hdsnddsp_comport_w=%d\n", machine().describe_context(), data);
}


void harddriv_sound_board_device::hdsnddsp_mute_w(uint16_t data)
{
	/* mute DAC audio, D0=1 */
	logerror("%s:mute DAC=%d\n", machine().describe_context(), data);
}


void harddriv_sound_board_device::hdsnddsp_gen68kirq_w(uint16_t data)
{
	/* generate 68k IRQ */
	m_irq68k = 1;
	update_68k_interrupts();
}


void harddriv_sound_board_device::hdsnddsp_soundaddr_w(offs_t offset, uint16_t data)
{
	if (offset == 0)
	{
		/* select sound ROM block */
		m_sound_rom_offs = (m_sound_rom_offs & 0xffff) | ((data & 15) << 16);
	}
	else
	{
		/* sound memory address */
		m_sound_rom_offs = (m_sound_rom_offs & ~0xffff) | (data & 0xffff);
	}
}


uint16_t harddriv_sound_board_device::hdsnddsp_rom_r()
{
	if (m_sound_rom_offs < m_sound_rom.length())
		return m_sound_rom[m_sound_rom_offs++] << 7;
	m_sound_rom_offs++;
	return 0;
}


uint16_t harddriv_sound_board_device::hdsnddsp_comram_r()
{
	return m_comram[m_sound_rom_offs++ & 0x1ff];
}


uint16_t harddriv_sound_board_device::hdsnddsp_compare_r(offs_t offset)
{
	logerror("%s:hdsnddsp_compare_r(%04X)\n", machine().describe_context(), offset);
	return 0;
}

void harddriv_sound_board_device::driversnd_68k_map(address_map &map)
{
	map.unmap_value_high();
	map(0x000000, 0x01ffff).rom();
	map(0xff0000, 0xff0fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_data_r), FUNC(harddriv_sound_board_device::hdsnd68k_data_w));
	map(0xff1000, 0xff1fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_switches_r), FUNC(harddriv_sound_board_device::hdsnd68k_latches_w));
	map(0xff2000, 0xff2fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_320port_r), FUNC(harddriv_sound_board_device::hdsnd68k_speech_w));
	map(0xff3000, 0xff3fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_status_r), FUNC(harddriv_sound_board_device::hdsnd68k_irqclr_w));
	map(0xff4000, 0xff5fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_320ram_r), FUNC(harddriv_sound_board_device::hdsnd68k_320ram_w));
	map(0xff6000, 0xff7fff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_320ports_r), FUNC(harddriv_sound_board_device::hdsnd68k_320ports_w));
	map(0xff8000, 0xffbfff).rw(FUNC(harddriv_sound_board_device::hdsnd68k_320com_r), FUNC(harddriv_sound_board_device::hdsnd68k_320com_w));
	map(0xffc000, 0xffffff).ram();
}


void harddriv_sound_board_device::driversnd_dsp_program_map(address_map &map)
{
	map.unmap_value_high();
	map(0x000, 0xfff).ram().share("sounddsp_ram");
}


/* $000 - 08F  TMS32010 Internal Data RAM in Data Address Space */

void harddriv_sound_board_device::driversnd_dsp_io_map(address_map &map)
{
	map(0, 0).r(FUNC(harddriv_sound_board_device::hdsnddsp_rom_r)).w(FUNC(harddriv_sound_board_device::hdsnddsp_dac_w));
	map(1, 1).r(FUNC(harddriv_sound_board_device::hdsnddsp_comram_r));
	map(2, 2).r(FUNC(harddriv_sound_board_device::hdsnddsp_compare_r));
	map(1, 2).nopw();
	map(3, 3).w(FUNC(harddriv_sound_board_device::hdsnddsp_comport_w));
	map(4, 4).w(FUNC(harddriv_sound_board_device::hdsnddsp_mute_w));
	map(5, 5).w(FUNC(harddriv_sound_board_device::hdsnddsp_gen68kirq_w));
	map(6, 7).w(FUNC(harddriv_sound_board_device::hdsnddsp_soundaddr_w));
}


//-------------------------------------------------
// device_add_mconfig - add device configuration
//-------------------------------------------------

void harddriv_sound_board_device::device_add_mconfig(machine_config &config)
{
	/* basic machine hardware */
	M68000(config, m_soundcpu, 16_MHz_XTAL/2);
	m_soundcpu->set_addrmap(AS_PROGRAM, &harddriv_sound_board_device::driversnd_68k_map);

	LS259(config, m_latch, 0); // 80R
	m_latch->q_out_cb<0>().set(FUNC(harddriv_sound_board_device::speech_write_w)); // SPWR - 5220 write strobe
	m_latch->q_out_cb<1>().set(FUNC(harddriv_sound_board_device::speech_reset_w)); // SPRES - 5220 hard reset
	m_latch->q_out_cb<2>().set(FUNC(harddriv_sound_board_device::speech_rate_w)); // SPRATE
	m_latch->q_out_cb<3>().set(FUNC(harddriv_sound_board_device::cram_enable_w)); // CRAMEN
	m_latch->q_out_cb<4>().set_inputline(m_sounddsp, INPUT_LINE_HALT).invert(); // RES320
	m_latch->q_out_cb<7>().set(FUNC(harddriv_sound_board_device::led_w));

	TMS32010(config, m_sounddsp, XTAL(20'000'000));
	m_sounddsp->set_addrmap(AS_PROGRAM, &harddriv_sound_board_device::driversnd_dsp_program_map);
	/* Data Map is internal to the CPU */
	m_sounddsp->set_addrmap(AS_IO, &harddriv_sound_board_device::driversnd_dsp_io_map);
	m_sounddsp->bio().set(FUNC(harddriv_sound_board_device::hdsnddsp_get_bio));

	/* sound hardware */
	SPEAKER(config, "speaker").front_center();

	AM6012(config, m_dac, 0).add_route(ALL_OUTPUTS, "speaker", 0.5); // ls374d.75e + ls374d.90e + am6012
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref"));
	vref.add_route(0, "dac", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "dac", -1.0, DAC_VREF_NEG_INPUT);
}