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
|
// license:???
// copyright-holders:Mike Coates, Peter J.C.Clare
/*****************************************************************************/
/* */
/* (C) Copyright Peter J.C.Clare */
/* */
/*****************************************************************************/
/* */
/* */
/* Module name: carnival.c */
/* */
/* Creation date: 15/03/98 Revision date: 09/01/99 */
/* */
/* Produced by: Peter J.C.Clare */
/* */
/* */
/* Abstract: */
/* */
/* MAME sound & music driver for Sega/Gremlin Carnival. */
/* */
/*****************************************************************************/
/* */
/* Acknowledgements: */
/* */
/* Mike Coates, for the original Carnival MAME sound driver. */
/* Virtu-Al, for the sound samples & hardware information. */
/* The MAME Team, for the emulator framework. */
/* */
/*****************************************************************************/
/* */
/* Revision history */
/* ================ */
/* */
/* Date Vsn. Initials Description */
/* ~~~~ ~~~~ ~~~~~~~~ ~~~~~~~~~~~ */
/* 03/20/2007 1.1 ZV Moved structures from driver to make */
/* file more self contained. */
/* */
/*****************************************************************************/
#include "emu.h"
#include "includes/vicdual.h"
#define PSG_CLOCK (3579545 / 3) /* Hz */
/* output port 0x01 definitions - sound effect drive outputs */
#define OUT_PORT_1_RIFLE_SHOT 0x01
#define OUT_PORT_1_CLANG 0x02
#define OUT_PORT_1_DUCK_1 0x04
#define OUT_PORT_1_DUCK_2 0x08
#define OUT_PORT_1_DUCK_3 0x10
#define OUT_PORT_1_PIPE_HIT 0x20
#define OUT_PORT_1_BONUS_1 0x40
#define OUT_PORT_1_BONUS_2 0x80
/* output port 0x02 definitions - sound effect drive outputs */
#define OUT_PORT_2_BEAR 0x04
#define OUT_PORT_2_MUSIC_T1 0x08
#define OUT_PORT_2_MUSIC_RESET 0x10
#define OUT_PORT_2_RANKING 0x20
/* music CPU port definitions */
#define MUSIC_PORT2_PSG_BDIR 0x40 /* bit 6 on P2 */
#define MUSIC_PORT2_PSG_BC1 0x80 /* bit 7 on P2 */
#define PSG_BC_INACTIVE 0
#define PSG_BC_READ MUSIC_PORT2_PSG_BC1
#define PSG_BC_WRITE MUSIC_PORT2_PSG_BDIR
#define PSG_BC_LATCH_ADDRESS ( MUSIC_PORT2_PSG_BDIR | MUSIC_PORT2_PSG_BC1 )
#define PLAY(samp,id,loop) samp->start( id, id, loop )
#define STOP(samp,id) samp->stop( id )
/* sample file names */
static const char *const carnival_sample_names[] =
{
"*carnival",
"bear",
"bonus1",
"bonus2",
"clang",
"duck1",
"duck2",
"duck3",
"pipehit",
"ranking",
"rifle",
nullptr
};
/* sample IDs - must match sample file name table above */
enum
{
SND_BEAR = 0,
SND_BONUS_1,
SND_BONUS_2,
SND_CLANG,
SND_DUCK_1,
SND_DUCK_2,
SND_DUCK_3,
SND_PIPE_HIT,
SND_RANKING,
SND_RIFLE_SHOT
};
WRITE8_MEMBER( vicdual_state::carnival_audio_1_w )
{
static int port1State = 0;
int bitsChanged;
int bitsGoneHigh;
int bitsGoneLow;
/* U64 74LS374 8 bit latch */
/* bit 0: connector pin 36 - rifle shot */
/* bit 1: connector pin 35 - clang */
/* bit 2: connector pin 33 - duck #1 */
/* bit 3: connector pin 34 - duck #2 */
/* bit 4: connector pin 32 - duck #3 */
/* bit 5: connector pin 31 - pipe hit */
/* bit 6: connector pin 30 - bonus #1 */
/* bit 7: connector pin 29 - bonus #2 */
bitsChanged = port1State ^ data;
bitsGoneHigh = bitsChanged & data;
bitsGoneLow = bitsChanged & ~data;
port1State = data;
if ( bitsGoneLow & OUT_PORT_1_RIFLE_SHOT )
{
PLAY( m_samples, SND_RIFLE_SHOT, 0 );
}
if ( bitsGoneLow & OUT_PORT_1_CLANG )
{
PLAY( m_samples, SND_CLANG, 0 );
}
if ( bitsGoneLow & OUT_PORT_1_DUCK_1 )
{
PLAY( m_samples, SND_DUCK_1, 1 );
}
if ( bitsGoneHigh & OUT_PORT_1_DUCK_1 )
{
STOP( m_samples, SND_DUCK_1 );
}
if ( bitsGoneLow & OUT_PORT_1_DUCK_2 )
{
PLAY( m_samples, SND_DUCK_2, 1 );
}
if ( bitsGoneHigh & OUT_PORT_1_DUCK_2 )
{
STOP( m_samples, SND_DUCK_2 );
}
if ( bitsGoneLow & OUT_PORT_1_DUCK_3 )
{
PLAY( m_samples, SND_DUCK_3, 1 );
}
if ( bitsGoneHigh & OUT_PORT_1_DUCK_3 )
{
STOP( m_samples, SND_DUCK_3 );
}
if ( bitsGoneLow & OUT_PORT_1_PIPE_HIT )
{
PLAY( m_samples, SND_PIPE_HIT, 0 );
}
if ( bitsGoneLow & OUT_PORT_1_BONUS_1 )
{
PLAY( m_samples, SND_BONUS_1, 0 );
}
if ( bitsGoneLow & OUT_PORT_1_BONUS_2 )
{
PLAY( m_samples, SND_BONUS_2, 0 );
}
}
WRITE8_MEMBER( vicdual_state::carnival_audio_2_w )
{
int bitsChanged;
int bitsGoneHigh;
int bitsGoneLow;
/* U63 74LS374 8 bit latch */
/* bit 0: connector pin 48 */
/* bit 1: connector pin 47 */
/* bit 2: connector pin 45 - bear */
/* bit 3: connector pin 46 - Music !T1 input */
/* bit 4: connector pin 44 - Music reset */
/* bit 5: connector pin 43 - ranking */
/* bit 6: connector pin 42 */
/* bit 7: connector pin 41 */
bitsChanged = m_port2State ^ data;
bitsGoneHigh = bitsChanged & data;
bitsGoneLow = bitsChanged & ~data;
m_port2State = data;
if ( bitsGoneLow & OUT_PORT_2_BEAR )
PLAY( m_samples, SND_BEAR, 0 );
if ( bitsGoneLow & OUT_PORT_2_RANKING )
PLAY( m_samples, SND_RANKING, 0 );
if ( bitsGoneHigh & OUT_PORT_2_MUSIC_RESET )
/* reset output is no longer asserted active low */
m_audiocpu->set_input_line(INPUT_LINE_RESET, PULSE_LINE );
}
READ8_MEMBER( vicdual_state::carnival_music_port_t1_r )
{
/* note: 8039 T1 signal is inverted on music board */
return ( m_port2State & OUT_PORT_2_MUSIC_T1 ) ? 0 : 1;
}
WRITE8_MEMBER( vicdual_state::carnival_music_port_1_w )
{
m_psgData = data;
}
WRITE8_MEMBER( vicdual_state::carnival_music_port_2_w )
{
static int psgSelect = 0;
int newSelect;
newSelect = data & ( MUSIC_PORT2_PSG_BDIR | MUSIC_PORT2_PSG_BC1 );
if ( psgSelect != newSelect )
{
psgSelect = newSelect;
switch ( psgSelect )
{
case PSG_BC_INACTIVE:
/* do nowt */
break;
case PSG_BC_READ:
/* not very sensible for a write */
break;
case PSG_BC_WRITE:
m_psg->data_w(space, 0, m_psgData);
break;
case PSG_BC_LATCH_ADDRESS:
m_psg->address_w(space, 0, m_psgData);
break;
}
}
}
static ADDRESS_MAP_START( carnival_audio_map, AS_PROGRAM, 8, vicdual_state )
AM_RANGE(0x0000, 0x07ff) AM_ROM
ADDRESS_MAP_END
static ADDRESS_MAP_START( carnival_audio_io_map, AS_IO, 8, vicdual_state )
AM_RANGE(MCS48_PORT_T1, MCS48_PORT_T1) AM_READ(carnival_music_port_t1_r)
AM_RANGE(MCS48_PORT_P1, MCS48_PORT_P1) AM_WRITE(carnival_music_port_1_w)
AM_RANGE(MCS48_PORT_P2, MCS48_PORT_P2) AM_WRITE(carnival_music_port_2_w)
ADDRESS_MAP_END
MACHINE_CONFIG_FRAGMENT( carnival_audio )
MCFG_CPU_ADD("audiocpu", I8039, 3579545)
MCFG_CPU_PROGRAM_MAP(carnival_audio_map)
MCFG_CPU_IO_MAP(carnival_audio_io_map)
MCFG_QUANTUM_TIME(attotime::from_hz(600))
MCFG_SOUND_ADD("psg", AY8910, PSG_CLOCK)
MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
MCFG_SOUND_ADD("samples", SAMPLES, 0)
MCFG_SAMPLES_CHANNELS(10)
MCFG_SAMPLES_NAMES(carnival_sample_names)
MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
MACHINE_CONFIG_END
|