summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/atarijsa.h
blob: f8cef0ca4a434ddc433de15169d43cc97af1d5c6 (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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    atarijsa.h

    Functions to emulate the Atari "JSA" audio boards

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

#ifndef MAME_AUDIO_ATARI_JSA_H
#define MAME_AUDIO_ATARI_JSA_H

#pragma once

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


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

DECLARE_DEVICE_TYPE(ATARI_JSA_I,    atari_jsa_i_device)
DECLARE_DEVICE_TYPE(ATARI_JSA_II,   atari_jsa_ii_device)
DECLARE_DEVICE_TYPE(ATARI_JSA_III,  atari_jsa_iii_device)
DECLARE_DEVICE_TYPE(ATARI_JSA_IIIS, atari_jsa_iiis_device)



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

#define MCFG_ATARI_JSA_I_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_I, 0) \
	devcb = &downcast<atari_jsa_base_device &>(*device).set_main_int_cb(DEVCB_##_intcb);

#define MCFG_ATARI_JSA_II_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_II, 0) \
	devcb = &downcast<atari_jsa_base_device &>(*device).set_main_int_cb(DEVCB_##_intcb);

#define MCFG_ATARI_JSA_III_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_III, 0) \
	devcb = &downcast<atari_jsa_base_device &>(*device).set_main_int_cb(DEVCB_##_intcb);

#define MCFG_ATARI_JSA_IIIS_ADD(_tag, _intcb) \
	MCFG_DEVICE_ADD(_tag, ATARI_JSA_IIIS, 0) \
	devcb = &downcast<atari_jsa_base_device &>(*device).set_main_int_cb(DEVCB_##_intcb);

#define MCFG_ATARI_JSA_TEST_PORT(_port, _bitnum) \
	devcb = &downcast<atari_jsa_base_device &>(*device).set_test_read_cb(DEVCB_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 *tag, device_t *owner, uint32_t clock, int channels);

public:
	// configuration
	template <class Object> devcb_base &set_test_read_cb(Object &&cb) { return m_test_read_cb.set_callback(std::forward<Object>(cb)); }
	template <class Object> devcb_base &set_main_int_cb(Object &&cb) { return m_main_int_cb.set_callback(std::forward<Object>(cb)); }

	// 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() override;
	virtual void device_reset() override;

	// 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 regions
	required_memory_region m_cpu_region;

	// memory banks
	required_memory_bank m_cpu_bank;

	// configuration state
	devcb_read_line    m_test_read_cb;
	devcb_write_line   m_main_int_cb;

	// internal state
	double              m_ym2151_volume;
	uint8_t               m_ym2151_ct1;
	uint8_t               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 *tag, device_t *owner, uint32_t clock, 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() override;
	virtual void device_reset() override;

	// internal helpers
	virtual void update_all_volumes() override;

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

	// memory regions
	optional_memory_region m_oki1_region;
	optional_memory_region m_oki2_region;

	// 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_t 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 );

	void atarijsa1_map(address_map &map);
protected:
	// device level overrides
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;
	virtual void device_start() override;
	virtual void device_reset() override;

	// internal helpers
	virtual void update_all_volumes() override;

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

	// 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_t clock);

	// read/write handlers
	DECLARE_READ8_MEMBER( rdio_r );

	void atarijsa2_map(address_map &map);
protected:
	// device level overrides
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

	required_ioport m_jsaii;
};


// ======================> 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_t clock);

	void atarijsa3_map(address_map &map);
	void jsa3_oki1_map(address_map &map);
protected:
	// derived construction/destruction
	atari_jsa_iii_device(const machine_config &mconfig, device_type devtype, const char *tag, device_t *owner, uint32_t clock, int channels);

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

protected:
	// device level overrides
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

	required_ioport m_jsaiii;
};


// ======================> 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_t clock);

	void jsa3_oki2_map(address_map &map);
protected:
	// device level overrides
	virtual void device_add_mconfig(machine_config &config) override;
};


#endif // MAME_AUDIO_ATARI_JSA_H