summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/msx_cart/msx_audio.cpp
blob: 46983943967e652e7c7a73d152df7885ecc247cb (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
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
/**********************************************************************************

Emulation of the different MSX-AUDIO devices:

- Panasonic FS-CA1
  - Y8950
  - 4KB ram
  - Connector for Toshiba HX-MU901 keyboard

- Toshiba HX-MU900
  - Y8950
  - No midi ports
  - No ram
  - Connector for Toshiba HX-MU901 keyboard

- Philips NMS-1205
  - Y8950
  - Midi ports
  - 32KB sample ram
  - Connector for Philips NMS-1160 keyboard


The keyboards:
- Toshiba HX-MU901
  - 49 keys: 4 full octaves + high C
  - ENTER key
  - SELECT key
  - multi sensor (?)

- Philips NMS-1160
  - 61 keys: 5 full octaves + high C
  - Different wiring, so incompatible with the other keyboards

- Panasonic YK-20
  - 49 keys: 4 full octaves + high C


TODO:
- Test MIDI in/out/through
- Sample RAM, doesn't seem to get written to
- Test NMS-1160 keyboard
- HX-MU901: ENTER/SELECT keys and multi sensors
- NMS1160: Test the keyboard
- NMS1205: Add DAC
- NMS1205/FSCA1: Add muting of dac and y8950 based on io config writes.


For testing the sample ram (playback of a cuckoo sound, the volume of the sound is quite low):
- Disable firmware on the fs-ca1
- Execute the following basic commands:
  - CALL AUDIO
  - CALL COPY PCM(#1,0)
  - CALL PLAY PCM(0)

See also http://www.mccm.hetlab.tk/millennium/milc/gc/topic_26.htm (dutch)
and/or http://ngs.no.coocan.jp/doc/wiki.cgi/datapack?page=4.2+MSX-AUDIO+%B3%C8%C4%A5BASIC (japanese)


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

#include "emu.h"
#include "msx_audio.h"
#include "bus/msx_cart/msx_audio_kb.h"

#include "speaker.h"


DEFINE_DEVICE_TYPE(MSX_CART_MSX_AUDIO_HXMU900, msx_cart_msx_audio_hxmu900_device, "msx_audio_hxmu900", "MSX Cartridge - MSX-AUDIO HX-MU900")
DEFINE_DEVICE_TYPE(MSX_CART_MSX_AUDIO_NMS1205, msx_cart_msx_audio_nms1205_device, "msx_audio_nms1205", "MSX Cartridge - MSX-AUDIO NMS-1205")
DEFINE_DEVICE_TYPE(MSX_CART_MSX_AUDIO_FSCA1,   msx_cart_msx_audio_fsca1_device,   "msx_audio_fsca1",   "MSX Cartridge - MSX-AUDIO FS-CA1")


msx_cart_msx_audio_hxmu900_device::msx_cart_msx_audio_hxmu900_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, MSX_CART_MSX_AUDIO_HXMU900, tag, owner, clock)
	, msx_cart_interface(mconfig, *this)
	, m_y8950(*this, "y8950")
{
}


MACHINE_CONFIG_START(msx_cart_msx_audio_hxmu900_device::device_add_mconfig)
	// This is actually incorrect. The sound output is passed back into the MSX machine where it is mixed internally and output through the system 'speaker'.
	SPEAKER(config, "mono").front_center();
	MCFG_DEVICE_ADD("y8950", Y8950, XTAL(3'579'545))    // Not verified
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
	MCFG_Y8950_KEYBOARD_WRITE_HANDLER(WRITE8("kbdc", msx_audio_kbdc_port_device, write))
	MCFG_Y8950_KEYBOARD_READ_HANDLER(READ8("kbdc", msx_audio_kbdc_port_device, read))

	MCFG_MSX_AUDIO_KBDC_PORT_ADD("kbdc", msx_audio_keyboards, nullptr)
MACHINE_CONFIG_END


void msx_cart_msx_audio_hxmu900_device::device_start()
{
	// Install IO read/write handlers
	address_space &space = machine().device<cpu_device>("maincpu")->space(AS_IO);
	space.install_write_handler(0xc0, 0xc1, write8_delegate(FUNC(y8950_device::write), m_y8950.target()));
	space.install_read_handler(0xc0, 0xc1, read8_delegate(FUNC(y8950_device::read), m_y8950.target()));
}


void msx_cart_msx_audio_hxmu900_device::initialize_cartridge()
{
	if (get_rom_size() < 0x8000)
	{
		fatalerror("msx_audio: Invalid ROM size\n");
	}
}


READ8_MEMBER(msx_cart_msx_audio_hxmu900_device::read_cart)
{
	if (offset >= 0x4000 && offset < 0xC000)
	{
		return m_rom[offset - 0x4000];
	}
	return 0xff;
}


ROM_START( msx_hxmu )
	ROM_REGION(0x8000, "y8950", ROMREGION_ERASE00)
ROM_END


const tiny_rom_entry *msx_cart_msx_audio_hxmu900_device::device_rom_region() const
{
	return ROM_NAME( msx_hxmu );
}





msx_cart_msx_audio_nms1205_device::msx_cart_msx_audio_nms1205_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, MSX_CART_MSX_AUDIO_NMS1205, tag, owner, clock)
	, msx_cart_interface(mconfig, *this)
	, m_y8950(*this, "y8950")
	, m_acia6850(*this, "acia6850")
	, m_mdout(*this, "mdout")
	, m_mdthru(*this, "mdthru")
{
}


MACHINE_CONFIG_START(msx_cart_msx_audio_nms1205_device::device_add_mconfig)
	// This is actually incorrect. The sound output is passed back into the MSX machine where it is mixed internally and output through the system 'speaker'.
	// At the same time the sound is also output on two output on the nms1205 cartridge itself
	SPEAKER(config, "mono").front_center();
	MCFG_DEVICE_ADD("y8950", Y8950, XTAL(3'579'545))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
	MCFG_Y8950_KEYBOARD_WRITE_HANDLER(WRITE8("kbdc", msx_audio_kbdc_port_device, write))
	MCFG_Y8950_KEYBOARD_READ_HANDLER(READ8("kbdc", msx_audio_kbdc_port_device, read))
	MCFG_Y8950_IRQ_HANDLER(WRITELINE(*this, msx_cart_msx_audio_nms1205_device, irq_write))

	MCFG_MSX_AUDIO_KBDC_PORT_ADD("kbdc", msx_audio_keyboards, nullptr)

	// There is a 2 MHz crystal on the PCB, the 6850 TX and RX clocks are derived from it
	MCFG_DEVICE_ADD("acia6850", ACIA6850, 0)
	MCFG_ACIA6850_TXD_HANDLER(WRITELINE("mdout", midi_port_device, write_txd))

	MCFG_MIDI_PORT_ADD("mdin", midiin_slot, "midiin")
	MCFG_MIDI_RX_HANDLER(WRITELINE(*this, msx_cart_msx_audio_nms1205_device, midi_in))

	MCFG_MIDI_PORT_ADD("mdthru", midiout_slot, "midiout")

	MCFG_MIDI_PORT_ADD("mdout", midiout_slot, "midiout")
MACHINE_CONFIG_END


ROM_START( msx_nms1205 )
	ROM_REGION(0x8000, "y8950", ROMREGION_ERASE00)
ROM_END


const tiny_rom_entry *msx_cart_msx_audio_nms1205_device::device_rom_region() const
{
	return ROM_NAME( msx_nms1205 );
}


WRITE_LINE_MEMBER(msx_cart_msx_audio_nms1205_device::irq_write)
{
	// Trigger IRQ on the maincpu
	// The 8950 seems to trigger an irq on reset, this causes an infinite loop of continuously triggering
	// the MSX's interrupt handler. The 8950 irq will never be cleared the nms1205's irq handler hook hasn't
	// been installed yet.
//  m_out_irq_cb(state);
}


WRITE_LINE_MEMBER(msx_cart_msx_audio_nms1205_device::midi_in)
{
	// MIDI in signals is sent to both the 6850 and the MIDI thru output port
	m_acia6850->write_rxd(state);
	m_mdthru->write_txd(state);
}


void msx_cart_msx_audio_nms1205_device::device_start()
{
	// Install IO read/write handlers
	address_space &space = machine().device<cpu_device>("maincpu")->space(AS_IO);
	space.install_write_handler(0xc0, 0xc1, write8_delegate(FUNC(y8950_device::write), m_y8950.target()));
	space.install_read_handler(0xc0, 0xc1, read8_delegate(FUNC(y8950_device::read), m_y8950.target()));
	space.install_write_handler(0x00, 0x01, write8_delegate(FUNC(acia6850_device::write), m_acia6850.target()));
	space.install_read_handler(0x04, 0x05, read8_delegate(FUNC(acia6850_device::read), m_acia6850.target()));
}


void msx_cart_msx_audio_nms1205_device::initialize_cartridge()
{
	if (get_rom_size() < 0x8000)
	{
		fatalerror("msx_audio: Invalid ROM size\n");
	}
}


READ8_MEMBER(msx_cart_msx_audio_nms1205_device::read_cart)
{
	if (offset >= 0x4000 && offset < 0xC000)
	{
		return m_rom[offset - 0x4000];
	}
	return 0xff;
}







msx_cart_msx_audio_fsca1_device::msx_cart_msx_audio_fsca1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, MSX_CART_MSX_AUDIO_FSCA1, tag, owner, clock)
	, msx_cart_interface(mconfig, *this)
	, m_y8950(*this, "y8950")
	, m_io_config(*this, "CONFIG")
	, m_region_y8950(*this, "y8950")
	, m_7ffe(0)
	, m_7fff(0)
{
}


MACHINE_CONFIG_START(msx_cart_msx_audio_fsca1_device::device_add_mconfig)
	// This is actually incorrect. The sound output is passed back into the MSX machine where it is mixed internally and output through the system 'speaker'.
	SPEAKER(config, "mono").front_center();
	MCFG_DEVICE_ADD("y8950", Y8950, XTAL(3'579'545))
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
	MCFG_Y8950_KEYBOARD_WRITE_HANDLER(WRITE8("kbdc", msx_audio_kbdc_port_device, write))
	MCFG_Y8950_KEYBOARD_READ_HANDLER(READ8("kbdc", msx_audio_kbdc_port_device, read))
	MCFG_Y8950_IO_READ_HANDLER(READ8(*this, msx_cart_msx_audio_fsca1_device, y8950_io_r))
	MCFG_Y8950_IO_WRITE_HANDLER(WRITE8(*this, msx_cart_msx_audio_fsca1_device, y8950_io_w))

	MCFG_MSX_AUDIO_KBDC_PORT_ADD("kbdc", msx_audio_keyboards, nullptr)
MACHINE_CONFIG_END


static INPUT_PORTS_START( msx_audio_fsca1 )
	PORT_START("CONFIG")
	PORT_CONFNAME( 0x04, 0x04, "FS-CA1 Firmware switch")
	PORT_CONFSETTING( 0x04, "On" )
	PORT_CONFSETTING( 0x00, "Off" )
	PORT_BIT(0xFB, IP_ACTIVE_HIGH, IPT_UNKNOWN)
INPUT_PORTS_END


ioport_constructor msx_cart_msx_audio_fsca1_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( msx_audio_fsca1 );
}


ROM_START( msx_fsca1 )
	ROM_REGION(0x8000, "y8950", ROMREGION_ERASE00)
ROM_END


const tiny_rom_entry *msx_cart_msx_audio_fsca1_device::device_rom_region() const
{
	return ROM_NAME( msx_fsca1 );
}


void msx_cart_msx_audio_fsca1_device::device_start()
{
	// Install IO read/write handlers
	address_space &space = machine().device<cpu_device>("maincpu")->space(AS_IO);
	space.install_write_handler(0xc0, 0xc3, write8_delegate(FUNC(msx_cart_msx_audio_fsca1_device::write_y8950), this));
	space.install_read_handler(0xc0, 0xc3, read8_delegate(FUNC(msx_cart_msx_audio_fsca1_device::read_y8950), this));
}


void msx_cart_msx_audio_fsca1_device::initialize_cartridge()
{
	if (get_rom_size() < 0x20000)
	{
		fatalerror("msx_audio_fsca1: Invalid ROM size\n");
	}
}


READ8_MEMBER(msx_cart_msx_audio_fsca1_device::read_cart)
{
	if (m_7ffe == 0 && (offset & 0xB000) == 0x3000)
	{
		return m_sram[offset & 0xfff];
	}
	return m_rom[((m_7ffe & 0x03) << 15) | (offset & 0x7fff)];
}


WRITE8_MEMBER(msx_cart_msx_audio_fsca1_device::write_cart)
{
	if (offset == 0x7ffe)
	{
		m_7ffe = data;
		return;
	}

	if (offset == 0x7fff)
	{
		m_7fff = data;
		return;
	}

	if (m_7ffe == 0 && (offset & 0xb000) == 0x3000)
	{
		m_sram[offset & 0xfff] = data;
		return;
	}

	logerror("msx_cart_msx_audio_fsca1_device: Unhandled write %02x to %04x\n", data, offset);
}


WRITE8_MEMBER(msx_cart_msx_audio_fsca1_device::write_y8950)
{
	if (offset & 2)
	{
		if (m_7fff & 0x02)
		{
			m_y8950->write(space, offset, data);
		}
	}
	else
	{
		if (m_7fff & 0x01)
		{
			m_y8950->write(space, offset, data);
		}
	}
}


READ8_MEMBER(msx_cart_msx_audio_fsca1_device::read_y8950)
{
	if (offset & 2)
	{
		return (m_7fff & 0x02) ? m_y8950->read(space, offset) : 0xff;
	}
	else
	{
		return (m_7fff & 0x01) ? m_y8950->read(space, offset) : 0xff;
	}
}


WRITE8_MEMBER(msx_cart_msx_audio_fsca1_device::y8950_io_w)
{
	logerror("msx_fsca1::y8950_io_w: %02x\n", data);
}


READ8_MEMBER(msx_cart_msx_audio_fsca1_device::y8950_io_r)
{
	return m_io_config->read();
}