1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /***************************************************************************
4
5 atarijsa.cpp
6
7 Functions to emulate the Atari "JSA" audio boards
8
9 ****************************************************************************
10
11 JSA I (stereo): used by:
12 * Blasteroids (YM2151 only)
13 * Toobin' (YM2151 + POKEY)
14 * Vindicators (YM2151 + POKEY)
15 * Escape from the Planets of the Robot Monsters (YM2151 + TMS5220)
16
17 JSA II (mono), used by:
18 * Cyberball 2072
19 * STUN Runner
20 * Skull & Crossbones
21 * ThunderJaws
22 * Hydra
23 * Pit Fighter
24
25 JSA III (mono), used by:
26 * Off the Wall (YM2151 only)
27 * Batman
28 * Guardians of the 'Hood
29 * Road Riot 4WD
30 * Steel Talons
31
32 JSA IIIs (stereo), used by:
33 * Space Lords
34 * Moto Frenzy
35 * Road Riot's Revenge Rally
36
37 ****************************************************************************
38
39 Atari Audio Board II
40 --------------------
41
42 6502 MEMORY MAP
43
44 Function Address R/W Data
45 ---------------------------------------------------------------
46 Program RAM 0000-1FFF R/W D0-D7
47
48 Music (YM-2151) 2000-2001 R/W D0-D7
49
50 Read 68010 Port (Input Buffer) 280A R D0-D7
51
52 Self-test 280C R D7
53 Output Buffer Full (@2A02) (Active High) R D5
54 Left Coin Switch R D1
55 Right Coin Switch R D0
56
57 Interrupt acknowledge 2A00 W xx
58 Write 68010 Port (Outbut Buffer) 2A02 W D0-D7
59 Banked ROM select (at 3000-3FFF) 2A04 W D6-D7
60 ??? 2A06 W
61
62 Effects 2C00-2C0F R/W D0-D7
63
64 Banked Program ROM (4 pages) 3000-3FFF R D0-D7
65 Static Program ROM (48K bytes) 4000-FFFF R D0-D7
66
67 TODO:
68 JSA-i: stereo gating for POKEY/TMS5220C is currently only mono, only looking at ym2151_ct1;
69 the two commented-out lines would be correct if stereo volume-set functions were written.
70 ALL: the LPF (low pass filter) bit which selectively places a lowpass filter in the output
71 path for all channels is currently unimplemented; someone who knows analog magic will need
72 to handle this.
73
74 ***************************************************************************/
75
76 #include "emu.h"
77 #include "audio/atarijsa.h"
78
79
80 #define JSA_MASTER_CLOCK XTAL(3'579'545)
81
82
83 //**************************************************************************
84 // GLOBAL VARIABLES
85 //**************************************************************************
86
87 DEFINE_DEVICE_TYPE(ATARI_JSA_I, atari_jsa_i_device, "atjsa1", "Atari JSA I Sound Board")
88 DEFINE_DEVICE_TYPE(ATARI_JSA_II, atari_jsa_ii_device, "atjsa2", "Atari JSA II Sound Board")
89 DEFINE_DEVICE_TYPE(ATARI_JSA_III, atari_jsa_iii_device, "atjsa3", "Atari JSA III Sound Board")
90 DEFINE_DEVICE_TYPE(ATARI_JSA_IIIS, atari_jsa_iiis_device, "atjsa3s", "Atari JSA IIIs Sound Board")
91
92
93
94 //**************************************************************************
95 // MEMORY MAPS
96 //**************************************************************************
97
atarijsa1_map(address_map & map)98 void atari_jsa_i_device::atarijsa1_map(address_map &map)
99 {
100 map(0x0000, 0x1fff).ram();
101 map(0x2000, 0x2001).rw(m_ym2151, FUNC(ym2151_device::read), FUNC(ym2151_device::write));
102 map(0x2800, 0x2800).mirror(0x01f9); // N/C
103 map(0x2802, 0x2802).mirror(0x01f9).r(m_soundcomm, FUNC(atari_sound_comm_device::sound_command_r)); // /RDP
104 map(0x2804, 0x2804).mirror(0x01f9).r(FUNC(atari_jsa_i_device::rdio_r)); // /RDIO
105 map(0x2806, 0x2806).mirror(0x01f9).rw(FUNC(atari_jsa_i_device::sound_irq_ack_r), FUNC(atari_jsa_i_device::sound_irq_ack_w)); // R/W=/IRQACK
106 map(0x2a00, 0x2a00).mirror(0x01f9).w(FUNC(atari_jsa_i_device::tms5220_voice)); // /VOICE
107 map(0x2a02, 0x2a02).mirror(0x01f9).w(m_soundcomm, FUNC(atari_sound_comm_device::sound_response_w)); // /WRP
108 map(0x2a04, 0x2a04).mirror(0x01f9).w(FUNC(atari_jsa_i_device::wrio_w)); // /WRIO
109 map(0x2a06, 0x2a06).mirror(0x01f9).w(FUNC(atari_jsa_i_device::mix_w)); // /MIX
110 map(0x2c00, 0x2c0f).mirror(0x03f0).rw(FUNC(atari_jsa_i_device::pokey_r), FUNC(atari_jsa_i_device::pokey_w));
111 map(0x3000, 0x3fff).bankr("cpubank");
112 map(0x4000, 0xffff).rom();
113 }
114
115
atarijsa2_map(address_map & map)116 void atari_jsa_ii_device::atarijsa2_map(address_map &map)
117 {
118 map(0x0000, 0x1fff).ram();
119 map(0x2000, 0x2001).rw(m_ym2151, FUNC(ym2151_device::read), FUNC(ym2151_device::write));
120 map(0x2800, 0x2800).mirror(0x01f9).r(FUNC(atari_jsa_ii_device::oki_r)); // /RDV
121 map(0x2802, 0x2802).mirror(0x01f9).r(m_soundcomm, FUNC(atari_sound_comm_device::sound_command_r)); // /RDP
122 map(0x2804, 0x2804).mirror(0x01f9).r(FUNC(atari_jsa_ii_device::rdio_r)); // /RDIO
123 map(0x2806, 0x2806).mirror(0x01f9).rw(FUNC(atari_jsa_ii_device::sound_irq_ack_r), FUNC(atari_jsa_ii_device::sound_irq_ack_w)); // R/W=/IRQACK
124 map(0x2a00, 0x2a00).mirror(0x01f9).w(FUNC(atari_jsa_ii_device::oki_w)); // /WRV
125 map(0x2a02, 0x2a02).mirror(0x01f9).w(m_soundcomm, FUNC(atari_sound_comm_device::sound_response_w)); // /WRP
126 map(0x2a04, 0x2a04).mirror(0x01f9).w(FUNC(atari_jsa_ii_device::wrio_w)); // /WRIO
127 map(0x2a06, 0x2a06).mirror(0x01f9).w(FUNC(atari_jsa_ii_device::mix_w)); // /MIX
128 map(0x3000, 0x3fff).bankr("cpubank");
129 map(0x4000, 0xffff).rom();
130 }
131
132
133 // full map verified from schematics and Batman GALs
atarijsa3_map(address_map & map)134 void atari_jsa_iii_device::atarijsa3_map(address_map &map)
135 {
136 map(0x0000, 0x1fff).ram();
137 map(0x2000, 0x2001).mirror(0x07fe).rw(m_ym2151, FUNC(ym2151_device::read), FUNC(ym2151_device::write));
138 map(0x2800, 0x2801).mirror(0x05f8).rw(FUNC(atari_jsa_iii_device::oki_r), FUNC(atari_jsa_iii_device::overall_volume_w)); // /RDV
139 map(0x2802, 0x2802).mirror(0x05f9).r(m_soundcomm, FUNC(atari_sound_comm_device::sound_command_r)); // /RDP
140 map(0x2804, 0x2804).mirror(0x05f9).r(FUNC(atari_jsa_iii_device::rdio_r)); // /RDIO
141 map(0x2806, 0x2806).mirror(0x05f9).rw(FUNC(atari_jsa_iii_device::sound_irq_ack_r), FUNC(atari_jsa_iii_device::sound_irq_ack_w)); // R/W=/IRQACK
142 map(0x2a00, 0x2a01).mirror(0x05f8).w(FUNC(atari_jsa_iii_device::oki_w)); // /WRV
143 map(0x2a02, 0x2a02).mirror(0x05f9).w(m_soundcomm, FUNC(atari_sound_comm_device::sound_response_w)); // /WRP
144 map(0x2a04, 0x2a04).mirror(0x05f9).w(FUNC(atari_jsa_iii_device::wrio_w)); // /WRIO
145 map(0x2a06, 0x2a06).mirror(0x05f9).w(FUNC(atari_jsa_iii_device::mix_w)); // /MIX
146 map(0x3000, 0x3fff).bankr("cpubank");
147 map(0x4000, 0xffff).rom();
148 }
149
150
jsa3_oki1_map(address_map & map)151 void atari_jsa_iii_device::jsa3_oki1_map(address_map &map)
152 {
153 map(0x00000, 0x1ffff).bankr("oki1lo");
154 map(0x20000, 0x3ffff).bankr("oki1hi");
155 }
156
157
jsa3_oki2_map(address_map & map)158 void atari_jsa_iiis_device::jsa3_oki2_map(address_map &map)
159 {
160 map(0x00000, 0x1ffff).bankr("oki2lo");
161 map(0x20000, 0x3ffff).bankr("oki2hi");
162 }
163
164
165 //**************************************************************************
166 // I/O PORT DEFINITIONS
167 //**************************************************************************
168
169 INPUT_PORTS_START( jsa_i_ioports )
170 PORT_START("JSAI")
171 PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
172 PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
173 PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
174 PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
175 PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED ) // speech chip ready
176 PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, sound_to_main_ready) // output buffer full
177 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, main_to_sound_ready) // input buffer full
PORT_READ_LINE_DEVICE_MEMBER(DEVICE_SELF,atari_jsa_base_device,main_test_read_line)178 PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER(DEVICE_SELF, atari_jsa_base_device, main_test_read_line) // self test
179 INPUT_PORTS_END
180
181 INPUT_PORTS_START( jsa_ii_ioports )
182 PORT_START("JSAII")
183 PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
184 PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
185 PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
186 PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
187 PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )
188 PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, sound_to_main_ready) // output buffer full
189 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, main_to_sound_ready) // input buffer full
190 PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER(DEVICE_SELF, atari_jsa_base_device, main_test_read_line) // self test
191 INPUT_PORTS_END
192
193 INPUT_PORTS_START( jsa_iii_ioports )
194 PORT_START("JSAIII")
195 PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN2 )
196 PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN1 )
197 PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_TILT )
198 PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_SERVICE )
199 PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER(DEVICE_SELF, atari_jsa_base_device, main_test_read_line) // self test
200 PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, sound_to_main_ready) // output buffer full
201 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("soundcomm", atari_sound_comm_device, main_to_sound_ready) // input buffer full
202 PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER(DEVICE_SELF, atari_jsa_base_device, main_test_read_line) // self test
203 INPUT_PORTS_END
204
205
206
207 //**************************************************************************
208 // BASE DEVICE CLASS
209 //**************************************************************************
210
211 //-------------------------------------------------
212 // atari_jsa_base_device - constructor
213 //-------------------------------------------------
214
215 atari_jsa_base_device::atari_jsa_base_device(const machine_config &mconfig, device_type devtype, const char *tag, device_t *owner, uint32_t clock, int channels)
216 : device_t(mconfig, devtype, tag, owner, clock),
217 device_mixer_interface(mconfig, *this, channels),
218 m_soundcomm(*this, "soundcomm"),
219 m_jsacpu(*this, "cpu"),
220 m_ym2151(*this, "ym2151"),
221 m_cpu_region(*this, "cpu"),
222 m_cpu_bank(*this, "cpubank"),
223 m_test_read_cb(*this),
224 m_main_int_cb(*this),
225 m_timed_int(false),
226 m_ym2151_int(false),
227 m_ym2151_volume(1.0),
228 m_ym2151_ct1(0),
229 m_ym2151_ct2(0)
230 {
231 }
232
233
234 //-------------------------------------------------
235 // device_start: Start up the device
236 //-------------------------------------------------
237
device_start()238 void atari_jsa_base_device::device_start()
239 {
240 // configure CPU bank
241 m_cpu_bank->configure_entries(0, 4, m_cpu_region->base(), 0x1000);
242
243 // resolve devices
244 m_test_read_cb.resolve_safe(0);
245 m_main_int_cb.resolve_safe();
246
247 // save states
248 save_item(NAME(m_timed_int));
249 save_item(NAME(m_ym2151_int));
250 save_item(NAME(m_ym2151_volume));
251 save_item(NAME(m_ym2151_ct1));
252 save_item(NAME(m_ym2151_ct2));
253 }
254
255
256 //-------------------------------------------------
257 // device_reset: Reset the device
258 //-------------------------------------------------
259
device_reset()260 void atari_jsa_base_device::device_reset()
261 {
262 // reset the static states
263 m_ym2151_volume = 1.0;
264 m_ym2151_ct1 = 0;
265 m_ym2151_ct2 = 0;
266
267 // Guardians of the Hood assumes we're reset to bank 0 on startup
268 m_cpu_bank->set_entry(0);
269 }
270
271
272 //-------------------------------------------------
273 // main_command_w: Handle command writes
274 //-------------------------------------------------
275
main_command_w(uint8_t data)276 void atari_jsa_base_device::main_command_w(uint8_t data)
277 {
278 m_soundcomm->main_command_w(data);
279 }
280
281
282 //-------------------------------------------------
283 // main_response_r: Handle response reads
284 //-------------------------------------------------
285
main_response_r()286 uint8_t atari_jsa_base_device::main_response_r()
287 {
288 return m_soundcomm->main_response_r();
289 }
290
291
292 //-------------------------------------------------
293 // sound_reset_w: Reset the sound board
294 //-------------------------------------------------
295
sound_reset_w(uint16_t data)296 void atari_jsa_base_device::sound_reset_w(uint16_t data)
297 {
298 m_soundcomm->sound_reset_w();
299 }
300
301
302 //-------------------------------------------------
303 // ym2151_port_w: Handle writes from the YM2151
304 // output port
305 //-------------------------------------------------
306
ym2151_port_w(uint8_t data)307 void atari_jsa_base_device::ym2151_port_w(uint8_t data)
308 {
309 m_ym2151_ct1 = (data >> 0) & 1;
310 m_ym2151_ct2 = (data >> 1) & 1;
311 update_all_volumes();
312 }
313
314
315 //-------------------------------------------------
316 // main_test_read_line: Return the state of the
317 // main's test line, provided by a callback
318 //-------------------------------------------------
319
READ_LINE_MEMBER(atari_jsa_base_device::main_test_read_line)320 READ_LINE_MEMBER(atari_jsa_base_device::main_test_read_line)
321 {
322 return !m_test_read_cb();
323 }
324
325
326 //-------------------------------------------------
327 // main_int_write_line: Forward interrupt signals
328 // from the comm device to the owning callback
329 //-------------------------------------------------
330
WRITE_LINE_MEMBER(atari_jsa_base_device::main_int_write_line)331 WRITE_LINE_MEMBER(atari_jsa_base_device::main_int_write_line)
332 {
333 m_main_int_cb(state);
334 }
335
336
337 //-------------------------------------------------
338 // sound_irq_gen: Generates an IRQ signal to the
339 // 6502 sound processor.
340 //-------------------------------------------------
341
INTERRUPT_GEN_MEMBER(atari_jsa_base_device::sound_irq_gen)342 INTERRUPT_GEN_MEMBER(atari_jsa_base_device::sound_irq_gen)
343 {
344 m_timed_int = 1;
345 update_sound_irq();
346 }
347
348
349 //-------------------------------------------------
350 // sound_irq_ack_r: Resets the IRQ signal to the
351 // 6502 sound processor. Both reads and writes
352 // can be used.
353 //-------------------------------------------------
354
sound_irq_ack_r()355 u8 atari_jsa_base_device::sound_irq_ack_r()
356 {
357 if (!machine().side_effects_disabled())
358 {
359 m_timed_int = 0;
360 update_sound_irq();
361 }
362 return 0;
363 }
364
sound_irq_ack_w(u8 data)365 void atari_jsa_base_device::sound_irq_ack_w(u8 data)
366 {
367 m_timed_int = 0;
368 update_sound_irq();
369 }
370
371
372 //-------------------------------------------------
373 // ym2151_irq_gen: Sets the state of the
374 // YM2151's IRQ line.
375 //-------------------------------------------------
376
WRITE_LINE_MEMBER(atari_jsa_base_device::ym2151_irq_gen)377 WRITE_LINE_MEMBER(atari_jsa_base_device::ym2151_irq_gen)
378 {
379 m_ym2151_int = state;
380 update_sound_irq();
381 }
382
383
384 //-------------------------------------------------
385 // update_sound_irq: Called whenever the IRQ state
386 // changes. An interrupt is generated if either
387 // sound_irq_gen() was called, or if the YM2151
388 // generated an interrupt via the
389 // ym2151_irq_gen() callback.
390 //-------------------------------------------------
391
update_sound_irq()392 void atari_jsa_base_device::update_sound_irq()
393 {
394 if (m_timed_int || m_ym2151_int)
395 m_jsacpu->set_input_line(m6502_device::IRQ_LINE, ASSERT_LINE);
396 else
397 m_jsacpu->set_input_line(m6502_device::IRQ_LINE, CLEAR_LINE);
398 }
399
400
401
402 //**************************************************************************
403 // BASE DEVICE CLASS FOR OKI6295-BASED VERSIONS
404 //**************************************************************************
405
406 //-------------------------------------------------
407 // atari_jsa_oki_base_device: Constructor
408 //-------------------------------------------------
409
atari_jsa_oki_base_device(const machine_config & mconfig,device_type devtype,const char * tag,device_t * owner,uint32_t clock,int channels)410 atari_jsa_oki_base_device::atari_jsa_oki_base_device(const machine_config &mconfig, device_type devtype, const char *tag, device_t *owner, uint32_t clock, int channels)
411 : atari_jsa_base_device(mconfig, devtype, tag, owner, clock, channels),
412 m_oki1(*this, "oki1"),
413 m_oki2(*this, "oki2"),
414 m_oki1_region(*this, "oki1"),
415 m_oki2_region(*this, "oki2"),
416 m_oki1_banklo(*this, "oki1lo"),
417 m_oki1_bankhi(*this, "oki1hi"),
418 m_oki2_banklo(*this, "oki2lo"),
419 m_oki2_bankhi(*this, "oki2hi"),
420 m_oki6295_volume(1.0),
421 m_overall_volume(1.0)
422 {
423 }
424
425
426 //-------------------------------------------------
427 // oki_r: Handle reads from the OKI chip(s)
428 // on the JSA II, III, and IIIs boards
429 //-------------------------------------------------
430
oki_r(offs_t offset)431 uint8_t atari_jsa_oki_base_device::oki_r(offs_t offset)
432 {
433 // JSA IIIs selects the 2nd OKI via the low bit, so select it
434 if (m_oki2 != nullptr && offset == 1)
435 return m_oki2->read();
436
437 // OKI may not be populated at all
438 else if (m_oki1 != nullptr)
439 return m_oki1->read();
440
441 // if not present, return all 0xff
442 return 0xff;
443 }
444
445
446 //-------------------------------------------------
447 // oki_w: Handle writes to the OKI chip(s)
448 // on the JSA II, III, and IIIs boards
449 //-------------------------------------------------
450
oki_w(offs_t offset,uint8_t data)451 void atari_jsa_oki_base_device::oki_w(offs_t offset, uint8_t data)
452 {
453 // JSA IIIs selects the 2nd OKI via the low bit, so select it
454 if (m_oki2 != nullptr && offset == 1)
455 m_oki2->write(data);
456
457 // OKI may not be populated at all
458 else if (m_oki1 != nullptr)
459 m_oki1->write(data);
460 }
461
462
463 //-------------------------------------------------
464 // wrio_w: Handle writes to the general
465 // I/O port on JSA II, III, and IIIs boards
466 //-------------------------------------------------
467
wrio_w(uint8_t data)468 void atari_jsa_oki_base_device::wrio_w(uint8_t data)
469 {
470 //
471 // 0xc0 = bank address
472 // 0x20 = coin counter 2
473 // 0x10 = coin counter 1
474 // 0x08 = voice frequency (tweaks the OKI6295 frequency)
475 // 0x04 = OKI6295 reset (active low)
476 // 0x02 = OKI6295 #1 bank bit 0 (JSA III/IIIs only)
477 // 0x01 = YM2151 reset (active low)
478 //
479
480 // update the bank
481 m_cpu_bank->set_entry((data >> 6) & 3);
482
483 // coin counters
484 machine().bookkeeping().coin_counter_w(1, (data >> 5) & 1);
485 machine().bookkeeping().coin_counter_w(0, (data >> 4) & 1);
486
487 // update the OKI frequency
488 if (m_oki1 != nullptr)
489 {
490 m_oki1->set_pin7(data & 8);
491 if ((data & 4) == 0)
492 m_oki1->reset();
493 }
494
495 // same for the 2nd OKI (JSA IIIs only)
496 if (m_oki2 != nullptr)
497 {
498 m_oki2->set_pin7(data & 8);
499 if ((data & 4) == 0)
500 m_oki2->reset();
501 }
502
503 // update the (left) OKI bank (JSA III/IIIs only)
504 if (m_oki1_banklo != nullptr)
505 m_oki1_banklo->set_entry((m_oki1_banklo->entry() & 2) | ((data >> 1) & 1));
506
507 // reset the YM2151 if needed
508 m_ym2151->reset_w(BIT(data, 0));
509 }
510
511
512 //-------------------------------------------------
513 // mix_w: Handle writes to the mixing
514 // register on JSA II, III, and IIIs boards
515 //-------------------------------------------------
516
mix_w(uint8_t data)517 void atari_jsa_oki_base_device::mix_w(uint8_t data)
518 {
519 //
520 // 0xc0 = right OKI6295 bank bits 0-1 (JSA IIIs only)
521 // 0x20 = low-pass filter enable
522 // 0x10 = OKI6295 #1 bank bit 1
523 // 0x0e = YM2151 volume (0-7)
524 // 0x01 = OKI6295 volume (0-1)
525 //
526
527 // update the right OKI bank (JSA IIIs only)
528 if (m_oki2_banklo != nullptr)
529 m_oki2_banklo->set_entry((data >> 6) & 3);
530
531 // TODO: emulate the low pass filter!
532
533 // update the (left) OKI bank (JSA III/IIIs only)
534 if (m_oki1_banklo != nullptr)
535 m_oki1_banklo->set_entry((m_oki1_banklo->entry() & 1) | ((data >> 3) & 2));
536
537 // update the volumes
538 m_ym2151_volume = ((data >> 1) & 7) / 7.0;
539 m_oki6295_volume = (data & 1) ? 1.0 : 0.5;
540 update_all_volumes();
541 }
542
543
544 //-------------------------------------------------
545 // overall_volume_w: Handle writes to control the
546 // total sound volume on JSA III/IIIs boards
547 //-------------------------------------------------
548
overall_volume_w(uint8_t data)549 void atari_jsa_oki_base_device::overall_volume_w(uint8_t data)
550 {
551 m_overall_volume = data / 127.0;
552 update_all_volumes();
553 }
554
555
556 //-------------------------------------------------
557 // device_start: Start up the device
558 //-------------------------------------------------
559
device_start()560 void atari_jsa_oki_base_device::device_start()
561 {
562 // call the parent
563 atari_jsa_base_device::device_start();
564
565 // save states
566 save_item(NAME(m_oki6295_volume));
567 save_item(NAME(m_overall_volume));
568
569 // configure JSA III ADPCM banking
570 if (m_oki1_banklo.found() && m_oki1_bankhi.found() && m_oki1_region->bytes() >= 0x80000)
571 {
572 m_oki1_banklo->configure_entries(0, 2, m_oki1_region->base() + 0x00000, 0x00000);
573 m_oki1_banklo->configure_entries(2, 2, m_oki1_region->base() + 0x20000, 0x20000);
574 m_oki1_bankhi->set_base(m_oki1_region->base() + 0x60000);
575 }
576
577 // configure JSA IIIs ADPCM banking
578 if (m_oki2_banklo.found() && m_oki2_bankhi.found() && m_oki2_region->bytes() >= 0x80000)
579 {
580 m_oki2_banklo->configure_entries(0, 2, m_oki2_region->base() + 0x00000, 0x00000);
581 m_oki2_banklo->configure_entries(2, 2, m_oki2_region->base() + 0x20000, 0x20000);
582 m_oki2_bankhi->set_base(m_oki2_region->base() + 0x60000);
583 }
584 }
585
586
587 //-------------------------------------------------
588 // device_reset: Reset the device
589 //-------------------------------------------------
590
device_reset()591 void atari_jsa_oki_base_device::device_reset()
592 {
593 // call the parent
594 atari_jsa_base_device::device_reset();
595
596 // reset the static states
597 m_oki6295_volume = 1.0;
598 m_overall_volume = 1.0;
599 update_all_volumes();
600 }
601
602
603 //-------------------------------------------------
604 // update_all_volumes: Update volumes for all
605 // chips
606 //-------------------------------------------------
607
update_all_volumes()608 void atari_jsa_oki_base_device::update_all_volumes()
609 {
610 if (m_oki1.found())
611 m_oki1->set_output_gain(ALL_OUTPUTS, m_overall_volume * m_oki6295_volume * m_ym2151_ct1);
612 if (m_oki2.found())
613 m_oki2->set_output_gain(ALL_OUTPUTS, m_overall_volume * m_oki6295_volume * m_ym2151_ct1);
614 m_ym2151->set_output_gain(ALL_OUTPUTS, m_overall_volume * m_ym2151_volume);
615 }
616
617
618
619 //**************************************************************************
620 // JSA I-SPECIFIC IMPLEMENTATION
621 //**************************************************************************
622
623 //-------------------------------------------------
624 // atari_jsa_i_device: Constructor
625 //-------------------------------------------------
626
atari_jsa_i_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)627 atari_jsa_i_device::atari_jsa_i_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
628 : atari_jsa_base_device(mconfig, ATARI_JSA_I, tag, owner, clock, 2),
629 m_pokey(*this, "pokey"),
630 m_tms5220(*this, "tms"),
631 m_jsai(*this, "JSAI"),
632 m_pokey_volume(1.0),
633 m_tms5220_volume(1.0)
634 {
635 }
636
637
638 //-------------------------------------------------
639 // rdio_r: Handle reads from the general I/O
640 // port on a JSA I board
641 //-------------------------------------------------
642
rdio_r()643 uint8_t atari_jsa_i_device::rdio_r()
644 {
645 //
646 // 0x80 = self test
647 // 0x40 = NMI line state (active low)
648 // 0x20 = sound output full
649 // 0x10 = TMS5220 ready (active low)
650 // 0x08 = +5V
651 // 0x04 = +5V
652 // 0x02 = coin 2
653 // 0x01 = coin 1
654 //
655
656 uint8_t result = m_jsai->read();
657 if (!m_test_read_cb())
658 result ^= 0x80;
659 if (m_tms5220 != nullptr && m_tms5220->readyq_r() == 0)
660 result |= 0x10;
661 else
662 result &= ~0x10;
663
664 return result;
665 }
666
667
668 //-------------------------------------------------
669 // wrio_w: Handle writes to the general I/O
670 // port on a JSA I board
671 //-------------------------------------------------
672
wrio_w(uint8_t data)673 void atari_jsa_i_device::wrio_w(uint8_t data)
674 {
675 //
676 // 0xc0 = bank address
677 // 0x20 = coin counter 2
678 // 0x10 = coin counter 1
679 // 0x08 = squeak (tweaks the 5220 frequency)
680 // 0x04 = TMS5220 reset (actually the read strobe) (active low)
681 // 0x02 = TMS5220 write strobe (active low)
682 // 0x01 = YM2151 reset (active low)
683 //
684
685 // update the bank
686 m_cpu_bank->set_entry((data >> 6) & 3);
687
688 // coin counters
689 machine().bookkeeping().coin_counter_w(1, (data >> 5) & 1);
690 machine().bookkeeping().coin_counter_w(0, (data >> 4) & 1);
691
692 // handle TMS5220 I/O
693 if (m_tms5220 != nullptr)
694 {
695 int count = 5 | ((data >> 2) & 2);
696 m_tms5220->set_unscaled_clock(JSA_MASTER_CLOCK*2 / (16 - count));
697 m_tms5220->wsq_w((data >> 1) & 1);
698 m_tms5220->rsq_w((data >> 2) & 1);
699 }
700
701 // reset the YM2151 if needed
702 m_ym2151->reset_w(BIT(data, 0));
703 }
704
705
706 //-------------------------------------------------
707 // mix_w: Handle writes to the mixing register
708 // on a JSA I board
709 //-------------------------------------------------
710
mix_w(uint8_t data)711 void atari_jsa_i_device::mix_w(uint8_t data)
712 {
713 //
714 // 0xc0 = TMS5220 volume (0-3)
715 // 0x30 = POKEY volume (0-3)
716 // 0x0e = YM2151 volume (0-7)
717 // 0x01 = low-pass filter enable
718 //
719
720 m_tms5220_volume = ((data >> 6) & 3) / 3.0;
721 m_pokey_volume = ((data >> 4) & 3) / 3.0;
722 m_ym2151_volume = ((data >> 1) & 7) / 7.0;
723 update_all_volumes();
724 }
725
726
727 //-------------------------------------------------
728 // tms5220_voice: Handle writes to the TMS5220
729 // voice data register
730 //-------------------------------------------------
731
tms5220_voice(uint8_t data)732 void atari_jsa_i_device::tms5220_voice(uint8_t data)
733 {
734 if (m_tms5220 != nullptr)
735 m_tms5220->data_w(data);
736 }
737
738
739 //-------------------------------------------------
740 // pokey_r: Handle reads from the POKEY if
741 // present
742 //-------------------------------------------------
743
pokey_r(offs_t offset)744 uint8_t atari_jsa_i_device::pokey_r(offs_t offset)
745 {
746 if (m_pokey != nullptr)
747 return m_pokey->read(offset);
748 return 0xff;
749 }
750
751
752 //-------------------------------------------------
753 // pokey_w: Handle writes to the POKEY if
754 // present
755 //-------------------------------------------------
756
pokey_w(offs_t offset,uint8_t data)757 void atari_jsa_i_device::pokey_w(offs_t offset, uint8_t data)
758 {
759 if (m_pokey != nullptr)
760 m_pokey->write(offset, data);
761 }
762
763
764 //-------------------------------------------------
765 // device_add_mconfig - add device configuration
766 //-------------------------------------------------
767
768 // Fully populated JSA-I, not used by anyone
device_add_mconfig(machine_config & config)769 void atari_jsa_i_device::device_add_mconfig(machine_config &config)
770 {
771 // basic machine hardware
772 M6502(config, m_jsacpu, JSA_MASTER_CLOCK/2);
773 m_jsacpu->set_addrmap(AS_PROGRAM, &atari_jsa_i_device::atarijsa1_map);
774 m_jsacpu->set_periodic_int(FUNC(atari_jsa_i_device::sound_irq_gen), attotime::from_hz(JSA_MASTER_CLOCK/4/16/16/14));
775
776 // sound hardware
777 ATARI_SOUND_COMM(config, m_soundcomm, m_jsacpu)
778 .int_callback().set(FUNC(atari_jsa_base_device::main_int_write_line));
779
780 YM2151(config, m_ym2151, JSA_MASTER_CLOCK);
781 m_ym2151->irq_handler().set(FUNC(atari_jsa_i_device::ym2151_irq_gen));
782 m_ym2151->port_write_handler().set(FUNC(atari_jsa_base_device::ym2151_port_w));
783 m_ym2151->add_route(0, *this, 0.60, AUTO_ALLOC_INPUT, 0);
784 m_ym2151->add_route(1, *this, 0.60, AUTO_ALLOC_INPUT, 1);
785
786 POKEY(config, m_pokey, JSA_MASTER_CLOCK/2);
787 m_pokey->add_route(ALL_OUTPUTS, *this, 0.40, AUTO_ALLOC_INPUT, 0);
788 m_pokey->add_route(ALL_OUTPUTS, *this, 0.40, AUTO_ALLOC_INPUT, 1);
789
790 TMS5220C(config, m_tms5220, JSA_MASTER_CLOCK*2/11); // potentially JSA_MASTER_CLOCK/9 as well
791 m_tms5220->add_route(ALL_OUTPUTS, *this, 1.0, AUTO_ALLOC_INPUT, 0);
792 m_tms5220->add_route(ALL_OUTPUTS, *this, 1.0, AUTO_ALLOC_INPUT, 1);
793 }
794
795
796 //-------------------------------------------------
797 // device_input_ports - return a pointer to
798 // the device's I/O ports
799 //-------------------------------------------------
800
device_input_ports() const801 ioport_constructor atari_jsa_i_device::device_input_ports() const
802 {
803 return INPUT_PORTS_NAME( jsa_i_ioports );
804 }
805
806
807 //-------------------------------------------------
808 // device_start: Start up the device
809 //-------------------------------------------------
810
device_start()811 void atari_jsa_i_device::device_start()
812 {
813 // call the parent
814 atari_jsa_base_device::device_start();
815
816 // save states
817 save_item(NAME(m_pokey_volume));
818 save_item(NAME(m_tms5220_volume));
819 }
820
821
822 //-------------------------------------------------
823 // device_reset: Reset the device
824 //-------------------------------------------------
825
device_reset()826 void atari_jsa_i_device::device_reset()
827 {
828 // call the parent
829 atari_jsa_base_device::device_reset();
830
831 // reset the static states
832 m_pokey_volume = 1.0;
833 m_tms5220_volume = 1.0;
834 update_all_volumes();
835 }
836
837
838 //-------------------------------------------------
839 // update_all_volumes: Update volumes for all
840 // chips
841 //-------------------------------------------------
842
update_all_volumes()843 void atari_jsa_i_device::update_all_volumes()
844 {
845 if (m_tms5220 != nullptr)
846 m_tms5220->set_output_gain(ALL_OUTPUTS, m_tms5220_volume * m_ym2151_ct1);
847 if (m_pokey != nullptr)
848 m_pokey->set_output_gain(ALL_OUTPUTS, m_pokey_volume * m_ym2151_ct1);
849 m_ym2151->set_output_gain(ALL_OUTPUTS, m_ym2151_volume);
850 }
851
852
853
854 //**************************************************************************
855 // JSA II-SPECIFIC IMPLEMENTATION
856 //**************************************************************************
857
858 //-------------------------------------------------
859 // atari_jsa_ii_device: Constructor
860 //-------------------------------------------------
861
atari_jsa_ii_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)862 atari_jsa_ii_device::atari_jsa_ii_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
863 : atari_jsa_oki_base_device(mconfig, ATARI_JSA_II, tag, owner, clock, 1)
864 , m_jsaii(*this, "JSAII")
865 {
866 }
867
868
869 //-------------------------------------------------
870 // rdio_r: Handle reads from the general I/O
871 // port on a JSA II board
872 //-------------------------------------------------
873
rdio_r()874 uint8_t atari_jsa_ii_device::rdio_r()
875 {
876 //
877 // 0x80 = self test
878 // 0x40 = NMI line state (active low)
879 // 0x20 = sound output full
880 // 0x10 = +5V
881 // 0x08 = +5V
882 // 0x04 = +5V
883 // 0x02 = coin 2
884 // 0x01 = coin 1
885 //
886
887 uint8_t result = m_jsaii->read();
888 if (!m_test_read_cb())
889 result ^= 0x80;
890
891 return result;
892 }
893
894
895 //-------------------------------------------------
896 // device_add_mconfig - add device configuration
897 //-------------------------------------------------
898
899 // Fully populated JSA-II
device_add_mconfig(machine_config & config)900 void atari_jsa_ii_device::device_add_mconfig(machine_config &config)
901 {
902 // basic machine hardware
903 M6502(config, m_jsacpu, JSA_MASTER_CLOCK/2);
904 m_jsacpu->set_addrmap(AS_PROGRAM, &atari_jsa_ii_device::atarijsa2_map);
905 m_jsacpu->set_periodic_int(FUNC(atari_jsa_ii_device::sound_irq_gen), attotime::from_hz(JSA_MASTER_CLOCK/4/16/16/14));
906
907 // sound hardware
908 ATARI_SOUND_COMM(config, m_soundcomm, m_jsacpu)
909 .int_callback().set(FUNC(atari_jsa_base_device::main_int_write_line));
910
911 YM2151(config, m_ym2151, JSA_MASTER_CLOCK);
912 m_ym2151->irq_handler().set(FUNC(atari_jsa_ii_device::ym2151_irq_gen));
913 m_ym2151->port_write_handler().set(FUNC(atari_jsa_base_device::ym2151_port_w));
914 m_ym2151->add_route(ALL_OUTPUTS, *this, 0.60, AUTO_ALLOC_INPUT, 0);
915
916 OKIM6295(config, m_oki1, JSA_MASTER_CLOCK/3, okim6295_device::PIN7_HIGH);
917 m_oki1->add_route(ALL_OUTPUTS, *this, 0.75, AUTO_ALLOC_INPUT, 0);
918 }
919
920
921 //-------------------------------------------------
922 // device_input_ports - return a pointer to
923 // the device's I/O ports
924 //-------------------------------------------------
925
device_input_ports() const926 ioport_constructor atari_jsa_ii_device::device_input_ports() const
927 {
928 return INPUT_PORTS_NAME( jsa_ii_ioports );
929 }
930
931
932
933 //**************************************************************************
934 // JSA III-SPECIFIC IMPLEMENTATION
935 //**************************************************************************
936
937 //-------------------------------------------------
938 // atari_jsa_iii_device: Constructor
939 //-------------------------------------------------
940
atari_jsa_iii_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)941 atari_jsa_iii_device::atari_jsa_iii_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
942 : atari_jsa_iii_device(mconfig, ATARI_JSA_III, tag, owner, clock, 1)
943 {
944 }
945
atari_jsa_iii_device(const machine_config & mconfig,device_type devtype,const char * tag,device_t * owner,uint32_t clock,int channels)946 atari_jsa_iii_device::atari_jsa_iii_device(const machine_config &mconfig, device_type devtype, const char *tag, device_t *owner, uint32_t clock, int channels)
947 : atari_jsa_oki_base_device(mconfig, devtype, tag, owner, clock, channels)
948 , m_jsaiii(*this, "JSAIII")
949 {
950 }
951
952
953 //-------------------------------------------------
954 // jsa_iii_rdio: Handle reads from the general I/O
955 // port on a JSA III/IIIs board
956 //-------------------------------------------------
957
rdio_r()958 uint8_t atari_jsa_iii_device::rdio_r()
959 {
960 //
961 // 0x80 = self test (active high)
962 // 0x40 = NMI line state (active high)
963 // 0x20 = sound output full (active high)
964 // 0x10 = self test (active high)
965 // 0x08 = service (active high)
966 // 0x04 = tilt (active high)
967 // 0x02 = coin L (active high)
968 // 0x01 = coin R (active high)
969 //
970
971 uint8_t result = m_jsaiii->read();
972 if (!m_test_read_cb())
973 result ^= 0x90;
974 return result;
975 }
976
977
978 //-------------------------------------------------
979 // device_add_mconfig - add device configuration
980 //-------------------------------------------------
981
982 // Fully populated JSA-III
device_add_mconfig(machine_config & config)983 void atari_jsa_iii_device::device_add_mconfig(machine_config &config)
984 {
985 // basic machine hardware
986 M6502(config, m_jsacpu, JSA_MASTER_CLOCK/2);
987 m_jsacpu->set_addrmap(AS_PROGRAM, &atari_jsa_iii_device::atarijsa3_map);
988 m_jsacpu->set_periodic_int(FUNC(atari_jsa_iii_device::sound_irq_gen), attotime::from_hz(JSA_MASTER_CLOCK/4/16/16/14));
989
990 // sound hardware
991 ATARI_SOUND_COMM(config, m_soundcomm, m_jsacpu)
992 .int_callback().set(FUNC(atari_jsa_base_device::main_int_write_line));
993
994 YM2151(config, m_ym2151, JSA_MASTER_CLOCK);
995 m_ym2151->irq_handler().set(FUNC(atari_jsa_iii_device::ym2151_irq_gen));
996 m_ym2151->port_write_handler().set(FUNC(atari_jsa_base_device::ym2151_port_w));
997 m_ym2151->add_route(ALL_OUTPUTS, *this, 0.60, AUTO_ALLOC_INPUT, 0);
998
999 OKIM6295(config, m_oki1, JSA_MASTER_CLOCK/3, okim6295_device::PIN7_HIGH);
1000 m_oki1->set_addrmap(0, &atari_jsa_iii_device::jsa3_oki1_map);
1001 m_oki1->add_route(ALL_OUTPUTS, *this, 0.75, AUTO_ALLOC_INPUT, 0);
1002 }
1003
1004
1005 //-------------------------------------------------
1006 // device_input_ports - return a pointer to
1007 // the device's I/O ports
1008 //-------------------------------------------------
1009
device_input_ports() const1010 ioport_constructor atari_jsa_iii_device::device_input_ports() const
1011 {
1012 return INPUT_PORTS_NAME( jsa_iii_ioports );
1013 }
1014
1015
1016
1017 //**************************************************************************
1018 // JSA IIIS-SPECIFIC IMPLEMENTATION
1019 //**************************************************************************
1020
1021 //-------------------------------------------------
1022 // atari_jsa_iiis_device: Constructor
1023 //-------------------------------------------------
1024
atari_jsa_iiis_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)1025 atari_jsa_iiis_device::atari_jsa_iiis_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
1026 : atari_jsa_iii_device(mconfig, ATARI_JSA_IIIS, tag, owner, clock, 2)
1027 {
1028 }
1029
1030
1031 //-------------------------------------------------
1032 // device_add_mconfig - add device configuration
1033 //-------------------------------------------------
1034
1035 // Fully populated JSA_IIIs
device_add_mconfig(machine_config & config)1036 void atari_jsa_iiis_device::device_add_mconfig(machine_config &config)
1037 {
1038 atari_jsa_iii_device::device_add_mconfig(config);
1039
1040 m_ym2151->reset_routes();
1041 m_ym2151->add_route(0, *this, 0.60, AUTO_ALLOC_INPUT, 0);
1042 m_ym2151->add_route(1, *this, 0.60, AUTO_ALLOC_INPUT, 1);
1043
1044 OKIM6295(config, m_oki2, JSA_MASTER_CLOCK/3, okim6295_device::PIN7_HIGH);
1045 m_oki2->add_route(ALL_OUTPUTS, *this, 0.75, AUTO_ALLOC_INPUT, 1);
1046 m_oki2->set_addrmap(0, &atari_jsa_iiis_device::jsa3_oki2_map);
1047 }
1048