summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/nichisnd.cpp
blob: f6dd3030111c48596fe6de44eb4bab536ddb245d (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
// license:BSD-3-Clause
// copyright-holders:Angelo Salese,Takahiro Nogi
/***************************************************************************

    Nichibutsu sound HW

    Shared component between niyanpai.cpp and csplayh5.cpp

    Uses a TMPZ84C011 with YM3812 and two DACs

    TODO:
    - DVD sound routing in here

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

#include "emu.h"
#include "nichisnd.h"



//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

// device type definition
DEFINE_DEVICE_TYPE(NICHISND, nichisnd_device, "nichisnd", "Nichibutsu Sound Device")


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

//-------------------------------------------------
//  nichisnd_device - constructor
//-------------------------------------------------

nichisnd_device::nichisnd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, NICHISND, tag, owner, clock),
	m_soundlatch(*this, "soundlatch"),
	m_sound_rom(*this, "audiorom")
{
}

void nichisnd_device::nichisnd_map(address_map &map)
{
	map(0x0000, 0x77ff).rom().region("audiorom", 0);
	map(0x7800, 0x7fff).ram();
	map(0x8000, 0xffff).bankr("soundbank");
}

void nichisnd_device::nichisnd_io_map(address_map &map)
{
	map(0x80, 0x81).mirror(0xff00).w("ymsnd", FUNC(ym3812_device::write));
}


WRITE8_MEMBER(nichisnd_device::soundbank_w)
{
	membank("soundbank")->set_entry(data & 0x03);
}

WRITE8_MEMBER(nichisnd_device::soundlatch_clear_w)
{
	if (!(data & 0x01)) m_soundlatch->clear_w(space, 0, 0);
}


//-------------------------------------------------
//  add_device_mconfig - device-specific machine
//  configuration addiitons
//-------------------------------------------------

static const z80_daisy_config daisy_chain[] =
{
	TMPZ84C011_DAISY_INTERNAL,
	{ nullptr }
};



void nichisnd_device::device_add_mconfig(machine_config &config)
{
	tmpz84c011_device& audiocpu(TMPZ84C011(config, "audiocpu", 8000000)); /* TMPZ84C011, 8.00 MHz */
	audiocpu.set_daisy_config(daisy_chain);
	audiocpu.set_addrmap(AS_PROGRAM, &nichisnd_device::nichisnd_map);
	audiocpu.set_addrmap(AS_IO, &nichisnd_device::nichisnd_io_map);
	audiocpu.in_pd_callback().set(m_soundlatch, FUNC(generic_latch_8_device::read));
	audiocpu.out_pa_callback().set(FUNC(nichisnd_device::soundbank_w));
	audiocpu.out_pb_callback().set("dac1", FUNC(dac_byte_interface::data_w));
	audiocpu.out_pc_callback().set("dac2", FUNC(dac_byte_interface::data_w));
	audiocpu.out_pe_callback().set(FUNC(nichisnd_device::soundlatch_clear_w));
	audiocpu.zc0_callback().set("audiocpu", FUNC(tmpz84c011_device::trg3));

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

	GENERIC_LATCH_8(config, m_soundlatch);

	YM3812(config, "ymsnd", 4000000).add_route(ALL_OUTPUTS, "speaker", 1.0);

	DAC_8BIT_R2R(config, "dac1", 0).add_route(ALL_OUTPUTS, "speaker", 0.37); // unknown DAC
	DAC_8BIT_R2R(config, "dac2", 0).add_route(ALL_OUTPUTS, "speaker", 0.37); // unknown DAC
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref"));
	vref.add_route(0, "dac1", 1.0, DAC_VREF_POS_INPUT).add_route(0, "dac1", -1.0, DAC_VREF_NEG_INPUT);
	vref.add_route(0, "dac2", 1.0, DAC_VREF_POS_INPUT).add_route(0, "dac2", -1.0, DAC_VREF_NEG_INPUT);
}


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

void nichisnd_device::device_start()
{
	uint8_t *SNDROM = m_sound_rom;

	// sound program patch
	SNDROM[0x0213] = 0x00;          // DI -> NOP

	// initialize sound rom bank
	membank("soundbank")->configure_entries(0, 3, m_sound_rom + 0x8000, 0x8000);
	membank("soundbank")->set_entry(0);
}


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

void nichisnd_device::device_reset()
{
}


//**************************************************************************
//  READ/WRITE HANDLERS
//**************************************************************************

// use this to connect to the sound board
WRITE8_MEMBER(nichisnd_device::sound_host_command_w)
{
	m_soundlatch->write(space,0,data);
}