1 // license:BSD-3-Clause
2 // copyright-holders:Zsolt Vasvari
3 /*
4  *  Pulsar sound routines
5  *
6  *  TODO: change heart rate based on bit 7 of Port 1
7  *
8  */
9 
10 #include "emu.h"
11 #include "includes/vicdual.h"
12 
13 
14 /* output port 0x01 definitions - sound effect drive outputs */
15 #define OUT_PORT_1_CLANG        0x01
16 #define OUT_PORT_1_KEY          0x02
17 #define OUT_PORT_1_ALIENHIT     0x04
18 #define OUT_PORT_1_PHIT         0x08
19 #define OUT_PORT_1_ASHOOT       0x10
20 #define OUT_PORT_1_PSHOOT       0x20
21 #define OUT_PORT_1_BONUS        0x40
22 #define OUT_PORT_1_HBEAT_RATE   0x80    /* currently not used */
23 
24 /* output port 0x02 definitions - sound effect drive outputs */
25 #define OUT_PORT_2_SIZZLE       0x01
26 #define OUT_PORT_2_GATE         0x02
27 #define OUT_PORT_2_BIRTH        0x04
28 #define OUT_PORT_2_HBEAT        0x08
29 #define OUT_PORT_2_MOVMAZE      0x10
30 
31 
32 #define PLAY(samp,id,loop)           samp->start( id, id, loop )
33 #define STOP(samp,id)                samp->stop( id )
34 
35 
36 /* sample file names */
37 static const char *const pulsar_sample_names[] =
38 {
39 	"*pulsar",
40 	"clang",
41 	"key",
42 	"alienhit",
43 	"phit",
44 	"ashoot",
45 	"pshoot",
46 	"bonus",
47 	"sizzle",
48 	"gate",
49 	"birth",
50 	"hbeat",
51 	"movmaze",
52 	nullptr
53 };
54 
55 
56 /* sample IDs - must match sample file name table above */
57 enum
58 {
59 	SND_CLANG = 0,
60 	SND_KEY,
61 	SND_ALIENHIT,
62 	SND_PHIT,
63 	SND_ASHOOT,
64 	SND_PSHOOT,
65 	SND_BONUS,
66 	SND_SIZZLE,
67 	SND_GATE,
68 	SND_BIRTH,
69 	SND_HBEAT,
70 	SND_MOVMAZE
71 };
72 
73 
pulsar_audio_1_w(uint8_t data)74 void vicdual_state::pulsar_audio_1_w(uint8_t data)
75 {
76 	int bitsChanged;
77 	//int bitsGoneHigh;
78 	int bitsGoneLow;
79 
80 	bitsChanged  = m_port1State ^ data;
81 	//bitsGoneHigh = bitsChanged & data;
82 	bitsGoneLow  = bitsChanged & ~data;
83 
84 	m_port1State = data;
85 
86 	if ( bitsGoneLow & OUT_PORT_1_CLANG )
87 	{
88 		PLAY( m_samples, SND_CLANG, 0 );
89 	}
90 
91 	if ( bitsGoneLow & OUT_PORT_1_KEY )
92 	{
93 		PLAY( m_samples, SND_KEY, 0 );
94 	}
95 
96 	if ( bitsGoneLow & OUT_PORT_1_ALIENHIT )
97 	{
98 		PLAY( m_samples, SND_ALIENHIT, 0 );
99 	}
100 
101 	if ( bitsGoneLow & OUT_PORT_1_PHIT )
102 	{
103 		PLAY( m_samples, SND_PHIT, 0 );
104 	}
105 
106 	if ( bitsGoneLow & OUT_PORT_1_ASHOOT )
107 	{
108 		PLAY( m_samples, SND_ASHOOT, 0 );
109 	}
110 
111 	if ( bitsGoneLow & OUT_PORT_1_PSHOOT )
112 	{
113 		PLAY( m_samples, SND_PSHOOT, 0 );
114 	}
115 
116 	if ( bitsGoneLow & OUT_PORT_1_BONUS )
117 	{
118 		PLAY( m_samples, SND_BONUS, 0 );
119 	}
120 }
121 
122 
pulsar_audio_2_w(uint8_t data)123 void vicdual_state::pulsar_audio_2_w(uint8_t data)
124 {
125 	int bitsChanged;
126 	int bitsGoneHigh;
127 	int bitsGoneLow;
128 
129 	bitsChanged  = m_port2State ^ data;
130 	bitsGoneHigh = bitsChanged & data;
131 	bitsGoneLow  = bitsChanged & ~data;
132 
133 	m_port2State = data;
134 
135 	if ( bitsGoneLow & OUT_PORT_2_SIZZLE )
136 	{
137 		PLAY( m_samples, SND_SIZZLE, 0 );
138 	}
139 
140 	if ( bitsGoneLow & OUT_PORT_2_GATE )
141 	{
142 		m_samples->start(SND_CLANG, SND_GATE);
143 	}
144 	if ( bitsGoneHigh & OUT_PORT_2_GATE )
145 	{
146 		STOP( m_samples, SND_CLANG );
147 	}
148 
149 	if ( bitsGoneLow & OUT_PORT_2_BIRTH )
150 	{
151 		PLAY( m_samples, SND_BIRTH, 0 );
152 	}
153 
154 	if ( bitsGoneLow & OUT_PORT_2_HBEAT )
155 	{
156 		PLAY( m_samples, SND_HBEAT, 1 );
157 	}
158 	if ( bitsGoneHigh & OUT_PORT_2_HBEAT )
159 	{
160 		STOP( m_samples, SND_HBEAT );
161 	}
162 
163 	if ( bitsGoneLow & OUT_PORT_2_MOVMAZE )
164 	{
165 		PLAY( m_samples, SND_MOVMAZE, 1 );
166 	}
167 	if ( bitsGoneHigh & OUT_PORT_2_MOVMAZE )
168 	{
169 		STOP( m_samples, SND_MOVMAZE );
170 	}
171 }
172 
173 
pulsar_audio(machine_config & config)174 void vicdual_state::pulsar_audio(machine_config &config)
175 {
176 	/* samples */
177 	SAMPLES(config, m_samples);
178 	m_samples->set_channels(12);
179 	m_samples->set_samples_names(pulsar_sample_names);
180 	m_samples->add_route(ALL_OUTPUTS, "mono", 0.5);
181 }
182