summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/c64/magic_voice.cpp
blob: 8ec79474d50889817205efe895d5b5769623c826 (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Commodore Magic Voice cartridge emulation

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

/*

LA05-123 Pinout
---------------
                _____   _____
     NEXTP   1 |*    \_/     | 28  +5V
       PD0   2 |             | 27  _ROML2
       PD1   3 |             | 26  _ROML
       PD2   4 |             | 25  _I/O2
       PD3   5 |             | 24  _GAME
     CLEAR   6 |             | 23  PHI2
_RAM/EPROM   7 |  LA05-123   | 22  _ROMH2
       PB5   8 |  LA05-124   | 21  _ROMH
       PB6   9 |             | 20  CLOCK
     _6525  10 |             | 19  SDO
    _EPROM  11 |             | 18  NEXTS
      CA12  12 |             | 17  _DA/CA
      CA14  13 |             | 16  CA15
       GND  14 |_____________| 15  CA13


http://www.stefan-uhlmann.de/cbm/MVM/index.html

*/

/*

    TODO:

    - T6721A speech synthesis

*/

#include "emu.h"
#include "magic_voice.h"
#include "speaker.h"



//**************************************************************************
//  MACROS / CONSTANTS
//**************************************************************************

#define T6721A_TAG      "u5"
#define MOS6525_TAG     "u2"
#define CD40105_TAG     "u1"

#define A12 BIT(offset, 12)
#define A13 BIT(offset, 13)
#define A14 BIT(offset, 14)
#define A15 BIT(offset, 15)
#define PB5 BIT(m_tpi_pb, 5)
#define PB6 BIT(m_tpi_pb, 6)



//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(C64_MAGIC_VOICE, c64_magic_voice_cartridge_device, "c64_magic_voice", "C64 Magic Voice cartridge")


//-------------------------------------------------
//  tpi6525_interface tpi_intf
//-------------------------------------------------

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::tpi_irq_w )
{
	m_slot->nmi_w(state);
}

READ8_MEMBER( c64_magic_voice_cartridge_device::tpi_pa_r )
{
	/*

	    bit     description

	    0
	    1
	    2
	    3
	    4
	    5       J1 _GAME
	    6       T6721 _EOS
	    7       FIFO DIR

	*/

	uint8_t data = 0;

	data |= m_exp->game_r(get_offset(m_ca), 1, 1, 1, 0) << 5;
	data |= m_vslsi->eos_r() << 6;
	data |= m_fifo->dir_r() << 7;

	return data;
}

WRITE8_MEMBER( c64_magic_voice_cartridge_device::tpi_pa_w )
{
	/*

	    bit     description

	    0       FIFO D0
	    1       FIFO D1
	    2       FIFO D2
	    3       FIFO D3
	    4       FIFO SI
	    5
	    6
	    7

	*/

	m_fifo->write(data & 0x0f);
	m_fifo->si_w(BIT(data, 4));
}

READ8_MEMBER( c64_magic_voice_cartridge_device::tpi_pb_r )
{
	/*

	    bit     description

	    0
	    1
	    2
	    3
	    4
	    5
	    6
	    7       J1 _EXROM

	*/

	uint8_t data = 0;

	data |= m_exp->exrom_r(get_offset(m_ca), 1, 1, 1, 0) << 7;

	return data;
}

WRITE8_MEMBER( c64_magic_voice_cartridge_device::tpi_pb_w )
{
	/*

	    bit     description

	    0       T6721 D0
	    1       T6721 D1
	    2       T6721 D2
	    3       T6721 D3
	    4       T6721 _WR
	    5       LA05-124 pin 8 (DA/CA)
	    6       LA05-124 pin 9 (passthru)
	    7

	*/

	if (!BIT(m_tpi_pb, 4) && BIT(data, 4))
	{
		m_vslsi->write(space, 0, data & 0x0f);
	}

	m_tpi_pb = data;
}

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::tpi_ca_w )
{
	m_tpi_pc6 = state;
}

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::tpi_cb_w )
{
	m_exrom = state;
}

//-------------------------------------------------
//  t6721_interface
//-------------------------------------------------

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::phi2_w )
{
	if (state)
	{
		m_vslsi->di_w(m_pd & 0x01);

		m_pd >>= 1;
	}
}

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::dtrd_w )
{
	m_fifo->so_w(!state);

	m_pd = m_fifo->read();
}

WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::apd_w )
{
	if (state)
	{
		m_fifo->reset();
		m_pd = 0;
	}
}


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

MACHINE_CONFIG_START(c64_magic_voice_cartridge_device::device_add_mconfig)
	MCFG_DEVICE_ADD(MOS6525_TAG, TPI6525, 0)
	MCFG_TPI6525_OUT_IRQ_CB(WRITELINE(*this, c64_magic_voice_cartridge_device, tpi_irq_w))
	MCFG_TPI6525_IN_PA_CB(READ8(*this, c64_magic_voice_cartridge_device, tpi_pa_r))
	MCFG_TPI6525_OUT_PA_CB(WRITE8(*this, c64_magic_voice_cartridge_device, tpi_pa_w))
	MCFG_TPI6525_IN_PB_CB(READ8(*this, c64_magic_voice_cartridge_device, tpi_pb_r))
	MCFG_TPI6525_OUT_PB_CB(WRITE8(*this, c64_magic_voice_cartridge_device, tpi_pb_w))
	MCFG_TPI6525_OUT_CA_CB(WRITELINE(*this, c64_magic_voice_cartridge_device, tpi_ca_w))
	MCFG_TPI6525_OUT_CA_CB(WRITELINE(*this, c64_magic_voice_cartridge_device, tpi_cb_w))

	MCFG_DEVICE_ADD(CD40105_TAG, CD40105, 0)
	MCFG_40105_DATA_IN_READY_CB(WRITELINE(MOS6525_TAG, tpi6525_device, i3_w))

	SPEAKER(config, "mono").front_center();
	MCFG_DEVICE_ADD(T6721A_TAG, T6721A, XTAL(640'000))
	MCFG_T6721A_EOS_HANDLER(WRITELINE(MOS6525_TAG, tpi6525_device, i2_w))
	MCFG_T6721A_PHI2_HANDLER(WRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, phi2_w))
	MCFG_T6721A_DTRD_HANDLER(WRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, dtrd_w))
	MCFG_T6721A_APD_HANDLER(WRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, apd_w))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)

	MCFG_C64_PASSTHRU_EXPANSION_SLOT_ADD()
MACHINE_CONFIG_END



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

//-------------------------------------------------
//  c64_magic_voice_cartridge_device - constructor
//-------------------------------------------------

c64_magic_voice_cartridge_device::c64_magic_voice_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, C64_MAGIC_VOICE, tag, owner, clock),
	device_c64_expansion_card_interface(mconfig, *this),
	m_vslsi(*this, T6721A_TAG),
	m_tpi(*this, MOS6525_TAG),
	m_fifo(*this, CD40105_TAG),
	m_exp(*this, C64_EXPANSION_SLOT_TAG), m_ca(0),
	m_tpi_pb(0x60),
	m_tpi_pc6(1),
	m_pd(0)
{
}


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

void c64_magic_voice_cartridge_device::device_start()
{
	// state saving
	save_item(NAME(m_tpi_pb));
	save_item(NAME(m_tpi_pc6));
	save_item(NAME(m_pd));
}


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

void c64_magic_voice_cartridge_device::device_reset()
{
	m_tpi->reset();

	m_exrom = 1;

	m_tpi_pb = 0x60;
	m_tpi_pc6 = 1;
	m_pd = 0;
}


//-------------------------------------------------
//  c64_cd_r - cartridge data read
//-------------------------------------------------

uint8_t c64_magic_voice_cartridge_device::c64_cd_r(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!io2 && sphi2)
	{
		m_ca = offset;
		data = m_tpi->read(space, offset & 0x07);
	}

	if (PB6 && A13 && A15)
	{
		data = m_romh[(A14 << 13) | (offset & 0x1fff)];
	}

	int roml2 = !(!roml || (roml && !PB5 && A12 && A13 && !A14 && A15));
	int romh2 = !((!romh && !PB6) || (!PB5 && A12 && A13 && !A14 && !A15));

	data = m_exp->cd_r(space, get_offset(offset), data, sphi2, ba, roml2, romh2, io1, 1);

	return data;
}


//-------------------------------------------------
//  c64_cd_w - cartridge data write
//-------------------------------------------------

void c64_magic_voice_cartridge_device::c64_cd_w(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!io2 && sphi2)
	{
		m_tpi->write(space, offset & 0x07, data);
	}

	int roml2 = !(!roml || (roml && !PB5 && A12 && A13 && !A14 && A15));
	int romh2 = !((!romh && !PB6) || (!PB5 && A12 && A13 && !A14 && !A15));

	m_exp->cd_w(space, get_offset(offset), data, sphi2, ba, roml2, romh2, io1, 1);
}


//-------------------------------------------------
//  c64_game_r - GAME read
//-------------------------------------------------

int c64_magic_voice_cartridge_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
{
	return !((m_tpi_pc6 && sphi2) || (!m_tpi_pc6 && sphi2 && !PB5 && A12 && A13 && !A14));
}


//-------------------------------------------------
//  get_offset -
//-------------------------------------------------

offs_t c64_magic_voice_cartridge_device::get_offset(offs_t offset)
{
	if (!PB5 && A12 && A13 && !A14)
	{
		offset = ((m_tpi_pb & 0x0f) << 12) | (offset & 0xfff);
	}

	return offset;
}