summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/sound/2151intf.c
blob: 7f8f1b3b4f3fb027d5c5b56e9d6c6a243d0a1d4b (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
/***************************************************************************

  2151intf.c

  Support interface YM2151(OPM)

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

#include "sndintrf.h"
#include "streams.h"
#include "fm.h"
#include "2151intf.h"
#include "ym2151.h"


struct ym2151_info
{
	sound_stream *	stream;
	emu_timer *	timer[2];
	void *			chip;
	const ym2151_interface *intf;
};


static STREAM_UPDATE( ym2151_update )
{
	struct ym2151_info *info = param;
	ym2151_update_one(info->chip, outputs, samples);
}


static STATE_POSTLOAD( ym2151intf_postload )
{
	struct ym2151_info *info = param;
	ym2151_postload(machine, info->chip);
}


static SND_START( ym2151 )
{
	static const ym2151_interface dummy = { 0 };
	struct ym2151_info *info = device->token;
	int rate;

	info->intf = device->static_config ? device->static_config : &dummy;

	rate = clock/64;

	/* stream setup */
	info->stream = stream_create(device,0,2,rate,info,ym2151_update);

	info->chip = ym2151_init(device,clock,rate);
	assert_always(info->chip != NULL, "Error creating YM2151 chip");

	state_save_register_postload(device->machine, ym2151intf_postload, info);

	ym2151_set_irq_handler(info->chip,info->intf->irqhandler);
	ym2151_set_port_write_handler(info->chip,info->intf->portwritehandler);
}


static SND_STOP( ym2151 )
{
	struct ym2151_info *info = device->token;
	ym2151_shutdown(info->chip);
}

static SND_RESET( ym2151 )
{
	struct ym2151_info *info = device->token;
	ym2151_reset_chip(info->chip);
}

static int lastreg0,lastreg1,lastreg2;

READ8_HANDLER( ym2151_status_port_0_r )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 0);
	stream_update(token->stream);
	return ym2151_read_status(token->chip);
}

READ8_HANDLER( ym2151_status_port_1_r )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 1);
	stream_update(token->stream);
	return ym2151_read_status(token->chip);
}

READ8_HANDLER( ym2151_status_port_2_r )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 2);
	stream_update(token->stream);
	return ym2151_read_status(token->chip);
}

WRITE8_HANDLER( ym2151_register_port_0_w )
{
	lastreg0 = data;
}
WRITE8_HANDLER( ym2151_register_port_1_w )
{
	lastreg1 = data;
}
WRITE8_HANDLER( ym2151_register_port_2_w )
{
	lastreg2 = data;
}

WRITE8_HANDLER( ym2151_data_port_0_w )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 0);
	stream_update(token->stream);
	ym2151_write_reg(token->chip,lastreg0,data);
}

WRITE8_HANDLER( ym2151_data_port_1_w )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 1);
	stream_update(token->stream);
	ym2151_write_reg(token->chip,lastreg1,data);
}

WRITE8_HANDLER( ym2151_data_port_2_w )
{
	struct ym2151_info *token = sndti_token(SOUND_YM2151, 2);
	stream_update(token->stream);
	ym2151_write_reg(token->chip,lastreg2,data);
}

WRITE8_HANDLER( ym2151_word_0_w )
{
	if (offset)
		ym2151_data_port_0_w(space,0,data);
	else
		ym2151_register_port_0_w(space,0,data);
}

WRITE8_HANDLER( ym2151_word_1_w )
{
	if (offset)
		ym2151_data_port_1_w(space,0,data);
	else
		ym2151_register_port_1_w(space,0,data);
}

READ16_HANDLER( ym2151_status_port_0_lsb_r )
{
	return ym2151_status_port_0_r(space,0);
}

READ16_HANDLER( ym2151_status_port_1_lsb_r )
{
	return ym2151_status_port_1_r(space,0);
}

READ16_HANDLER( ym2151_status_port_2_lsb_r )
{
	return ym2151_status_port_2_r(space,0);
}


WRITE16_HANDLER( ym2151_register_port_0_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_register_port_0_w(space, 0, data & 0xff);
}

WRITE16_HANDLER( ym2151_register_port_1_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_register_port_1_w(space, 0, data & 0xff);
}

WRITE16_HANDLER( ym2151_register_port_2_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_register_port_2_w(space, 0, data & 0xff);
}

WRITE16_HANDLER( ym2151_data_port_0_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_data_port_0_w(space, 0, data & 0xff);
}

WRITE16_HANDLER( ym2151_data_port_1_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_data_port_1_w(space, 0, data & 0xff);
}

WRITE16_HANDLER( ym2151_data_port_2_lsb_w )
{
	if (ACCESSING_BITS_0_7)
		ym2151_data_port_2_w(space, 0, data & 0xff);
}


/**************************************************************************
 * Generic get_info
 **************************************************************************/

static SND_SET_INFO( ym2151 )
{
	switch (state)
	{
		/* no parameters to set */
	}
}


SND_GET_INFO( ym2151 )
{
	switch (state)
	{
		/* --- the following bits of info are returned as 64-bit signed integers --- */
		case SNDINFO_INT_TOKEN_BYTES:					info->i = sizeof(struct ym2151_info);				break;

		/* --- the following bits of info are returned as pointers to data or functions --- */
		case SNDINFO_PTR_SET_INFO:						info->set_info = SND_SET_INFO_NAME( ym2151 );		break;
		case SNDINFO_PTR_START:							info->start = SND_START_NAME( ym2151 );				break;
		case SNDINFO_PTR_STOP:							info->stop = SND_STOP_NAME( ym2151 );				break;
		case SNDINFO_PTR_RESET:							info->reset = SND_RESET_NAME( ym2151 );				break;

		/* --- the following bits of info are returned as NULL-terminated strings --- */
		case SNDINFO_STR_NAME:							strcpy(info->s, "YM2151");							break;
		case SNDINFO_STR_CORE_FAMILY:					strcpy(info->s, "Yamaha FM");						break;
		case SNDINFO_STR_CORE_VERSION:					strcpy(info->s, "1.0");								break;
		case SNDINFO_STR_CORE_FILE:						strcpy(info->s, __FILE__);							break;
		case SNDINFO_STR_CORE_CREDITS:					strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
	}
}