summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/atarijsa.h
blob: 225a9113e1b1bea23804b1cf3416b29766dfe961 (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
/***************************************************************************

    audio/atarijsa.h

    Functions to emulate the Atari "JSA" audio boards

****************************************************************************

    Copyright Aaron Giles
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in
          the documentation and/or other materials provided with the
          distribution.
        * Neither the name 'MAME' nor the names of its contributors may be
          used to endorse or promote products derived from this software
          without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

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

#pragma once

#ifndef __ATARI_JSA__
#define __ATARI_JSA__

#include "cpu/m6502/m6502.h"
#include "sound/tms5220.h"
#include "sound/2151intf.h"
#include "sound/okim6295.h"
#include "sound/pokey.h"
#include "machine/atarigen.h"


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

extern const device_type ATARI_JSA_I;
extern const device_type ATARI_JSA_II;
extern const device_type ATARI_JSA_III;
extern const device_type ATARI_JSA_IIIS;



//**************************************************************************
//  DEVICE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_ATARI_JSA_I_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_I, 0) \
	devcb = &atari_jsa_i_device::static_set_main_int_cb(*device, DEVCB2_##_intcb);

#define MCFG_ATARI_JSA_II_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_II, 0) \
	devcb = &atari_jsa_ii_device::static_set_main_int_cb(*device, DEVCB2_##_intcb);

#define MCFG_ATARI_JSA_III_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_III, 0) \
	devcb = &atari_jsa_iii_device::static_set_main_int_cb(*device, DEVCB2_##_intcb);

#define MCFG_ATARI_JSA_IIIS_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_IIIS, 0) \
	devcb = &atari_jsa_iiis_device::static_set_main_int_cb(*device, DEVCB2_##_intcb);

#define MCFG_ATARI_JSA_TEST_PORT(_port, _bitnum) \
	devcb = &atari_jsa_base_device::static_set_test_read_cb(*device, DEVCB2_IOPORT(_port)); \
	MCFG_DEVCB_RSHIFT(_bitnum);


//**************************************************************************
//  I/O PORT BIT HELPERS
//**************************************************************************

#define PORT_ATARI_JSA_SOUND_TO_MAIN_READY(_tag) \
	PORT_READ_LINE_DEVICE_MEMBER(_tag, atari_jsa_base_device, sound_to_main_ready)

#define PORT_ATARI_JSA_MAIN_TO_SOUND_READY(_tag) \
	PORT_READ_LINE_DEVICE_MEMBER(_tag, atari_jsa_base_device, main_to_sound_ready)



//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> atari_jsa_base_device

class atari_jsa_base_device :   public device_t,
								public device_mixer_interface
{
protected:
	// construction/destruction
	atari_jsa_base_device(const machine_config &mconfig, device_type devtype, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, int channels);

public:
	// static configuration
	template<class _Object> static devcb2_base &static_set_test_read_cb(device_t &device, _Object object) { return downcast<atari_jsa_base_device &>(device).m_test_read_cb.set_callback(object); }
	template<class _Object> static devcb2_base &static_set_main_int_cb(device_t &device, _Object object) { return downcast<atari_jsa_base_device &>(device).m_main_int_cb.set_callback(object); }

	// getters
	m6502_device &soundcpu() const { return *m_jsacpu; }
	DECLARE_READ_LINE_MEMBER(main_to_sound_ready) { return m_soundcomm->main_to_sound_ready(); }
	DECLARE_READ_LINE_MEMBER(sound_to_main_ready) { return m_soundcomm->sound_to_main_ready(); }

	// main cpu accessors
	DECLARE_WRITE8_MEMBER(main_command_w);
	DECLARE_READ8_MEMBER(main_response_r);
	DECLARE_WRITE16_MEMBER(sound_reset_w);

	// read/write handlers
	DECLARE_WRITE8_MEMBER(ym2151_port_w);
	DECLARE_READ_LINE_MEMBER(main_test_read_line);

	// I/O lines
	DECLARE_WRITE_LINE_MEMBER(main_int_write_line);

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();

	// internal helpers
	virtual void update_all_volumes() = 0;

	// devices
	required_device<atari_sound_comm_device> m_soundcomm;
	required_device<m6502_device> m_jsacpu;
	required_device<ym2151_device> m_ym2151;

	// memory banks
	required_memory_bank m_cpu_bank;

	// configuration state
	devcb2_read_line    m_test_read_cb;
	devcb2_write_line   m_main_int_cb;

	// internal state
	double              m_ym2151_volume;
	UINT8               m_ym2151_ct1;
	UINT8               m_ym2151_ct2;
};


// ======================> atari_jsa_oki_base_device

class atari_jsa_oki_base_device : public atari_jsa_base_device
{
protected:
	// derived construction/destruction
	atari_jsa_oki_base_device(const machine_config &mconfig, device_type devtype, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, int channels);

public:
	// read/write handlers
	DECLARE_READ8_MEMBER( oki_r );
	DECLARE_WRITE8_MEMBER( oki_w );
	DECLARE_WRITE8_MEMBER( wrio_w );
	DECLARE_WRITE8_MEMBER( mix_w );
	DECLARE_WRITE8_MEMBER( overall_volume_w );

protected:
	// device level overrides
	virtual void device_start();
	virtual void device_reset();

	// internal helpers
	virtual void update_all_volumes();

	// devices
	optional_device<okim6295_device> m_oki1;
	optional_device<okim6295_device> m_oki2;    // JSA IIIs only

	// memory banks
	optional_memory_bank m_oki1_banklo;         // JSA III(s) only
	optional_memory_bank m_oki1_bankhi;         // JSA III(s)
	optional_memory_bank m_oki2_banklo;         // JSA IIIs only
	optional_memory_bank m_oki2_bankhi;         // JSA IIIs only

	// internal state
	double              m_oki6295_volume;
	double              m_overall_volume;       // JSA III(s) only
};


// ======================> atari_jsa_i_device

class atari_jsa_i_device : public atari_jsa_base_device
{
public:
	// construction/destruction
	atari_jsa_i_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// read/write handlers
	DECLARE_READ8_MEMBER( rdio_r );
	DECLARE_WRITE8_MEMBER( wrio_w );
	DECLARE_WRITE8_MEMBER( mix_w );
	DECLARE_WRITE8_MEMBER( tms5220_voice );
	DECLARE_READ8_MEMBER( pokey_r );
	DECLARE_WRITE8_MEMBER( pokey_w );

protected:
	// device level overrides
	virtual machine_config_constructor device_mconfig_additions() const;
	virtual ioport_constructor device_input_ports() const;
	virtual void device_start();
	virtual void device_reset();

	// internal helpers
	virtual void update_all_volumes();

	// devices
	optional_device<pokey_device> m_pokey;
	optional_device<tms5220_device> m_tms5220;

	// internal state
	double              m_pokey_volume;
	double              m_tms5220_volume;
};


// ======================> atari_jsa_ii_device

class atari_jsa_ii_device : public atari_jsa_oki_base_device
{
public:
	// construction/destruction
	atari_jsa_ii_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// read/write handlers
	DECLARE_READ8_MEMBER( rdio_r );

protected:
	// device level overrides
	virtual machine_config_constructor device_mconfig_additions() const;
	virtual ioport_constructor device_input_ports() const;
};


// ======================> atari_jsa_iii_device

class atari_jsa_iii_device : public atari_jsa_oki_base_device
{
public:
	// construction/destruction
	atari_jsa_iii_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

protected:
	// derived construction/destruction
	atari_jsa_iii_device(const machine_config &mconfig, device_type devtype, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, int channels);

public:
	// read/write handlers
	DECLARE_READ8_MEMBER( rdio_r );

protected:
	// device level overrides
	virtual machine_config_constructor device_mconfig_additions() const;
	virtual ioport_constructor device_input_ports() const;
};


// ======================> atari_jsa_iiis_device

class atari_jsa_iiis_device : public atari_jsa_iii_device
{
public:
	// construction/destruction
	atari_jsa_iiis_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

protected:
	// device level overrides
	virtual machine_config_constructor device_mconfig_additions() const;
};


#endif