1
/**********************************************************************
3
RCA CDP1863 CMOS 8-Bit Programmable Frequency Generator emulation
6
Visit http://mamedev.org for licensing and usage restrictions.
8
**********************************************************************/
14
- what happens if you connect both clocks?
21
#include "cpu/cdp1802/cdp1802.h"
24
/***************************************************************************
26
***************************************************************************/
28
#define CDP1863_DEFAULT_LATCH 0x35
30
/***************************************************************************
32
***************************************************************************/
34
typedef struct _cdp1863_t cdp1863_t;
37
int clock1; /* clock 1 */
38
int clock2; /* clock 2 */
40
sound_stream *stream; /* sound output */
43
int oe; /* output enable */
44
int latch; /* sound latch */
45
INT16 signal; /* current signal */
46
int incr; /* initial wave state */
49
/***************************************************************************
51
***************************************************************************/
53
INLINE cdp1863_t *get_safe_token(const device_config *device)
55
assert(device != NULL);
56
assert(device->token != NULL);
57
return (cdp1863_t *)device->token;
60
INLINE cdp1863_config *get_safe_config(const device_config *device)
62
assert(device != NULL);
63
return (cdp1863_config *)device->inline_config;
66
/***************************************************************************
68
***************************************************************************/
70
/*-------------------------------------------------
71
cdp1863_str_w - tone latch write
72
-------------------------------------------------*/
74
WRITE8_DEVICE_HANDLER( cdp1863_str_w )
76
cdp1863_t *cdp1863 = get_safe_token(device);
78
cdp1863->latch = data;
81
/*-------------------------------------------------
82
cdp1863_oe_w - output enable write
83
------------------------------------------------*/
85
WRITE_LINE_DEVICE_HANDLER( cdp1863_oe_w )
87
cdp1863_t *cdp1863 = get_safe_token(device);
92
/*-------------------------------------------------
93
cdp1863_set_clk1 - set clock 1 frequency
94
------------------------------------------------*/
96
void cdp1863_set_clk1(const device_config *device, int frequency)
98
cdp1863_t *cdp1863 = get_safe_token(device);
100
cdp1863->clock1 = frequency;
103
/*-------------------------------------------------
104
cdp1863_set_clk2 - set clock 2 frequency
105
------------------------------------------------*/
107
void cdp1863_set_clk2(const device_config *device, int frequency)
109
cdp1863_t *cdp1863 = get_safe_token(device);
111
cdp1863->clock2 = frequency;
114
/*-------------------------------------------------
115
STREAM_UPDATE( cdp1863_stream_update )
116
-------------------------------------------------*/
118
static STREAM_UPDATE( cdp1863_stream_update )
120
cdp1863_t *cdp1863 = get_safe_token(device);
122
INT16 signal = cdp1863->signal;
123
stream_sample_t *buffer = outputs[0];
125
memset( buffer, 0, samples * sizeof(*buffer) );
130
int rate = device->machine->sample_rate / 2;
132
/* get progress through wave */
133
int incr = cdp1863->incr;
135
if (cdp1863->clock1 > 0)
137
/* CLK1 is pre-divided by 4 */
138
frequency = cdp1863->clock1 / 4 / (cdp1863->latch + 1) / 2;
142
/* CLK2 is pre-divided by 8 */
143
frequency = cdp1863->clock2 / 8 / (cdp1863->latch + 1) / 2;
155
while( samples-- > 0 )
166
/* store progress through wave */
167
cdp1863->incr = incr;
168
cdp1863->signal = signal;
172
/*-------------------------------------------------
173
DEVICE_START( cdp1863 )
174
-------------------------------------------------*/
176
static DEVICE_START( cdp1863 )
178
cdp1863_t *cdp1863 = get_safe_token(device);
179
const cdp1863_config *config = get_safe_config(device);
181
/* set initial values */
182
cdp1863->stream = stream_create(device, 0, 1, device->machine->sample_rate, cdp1863, cdp1863_stream_update);
183
cdp1863->clock1 = device->clock;
184
cdp1863->clock2 = config->clock2;
187
/* register for state saving */
188
state_save_register_device_item(device, 0, cdp1863->clock1);
189
state_save_register_device_item(device, 0, cdp1863->clock2);
190
state_save_register_device_item(device, 0, cdp1863->oe);
191
state_save_register_device_item(device, 0, cdp1863->latch);
192
state_save_register_device_item(device, 0, cdp1863->signal);
193
state_save_register_device_item(device, 0, cdp1863->incr);
196
/*-------------------------------------------------
197
DEVICE_RESET( cdp1863 )
198
-------------------------------------------------*/
200
static DEVICE_RESET( cdp1863 )
202
cdp1863_t *cdp1863 = get_safe_token(device);
204
cdp1863->latch = CDP1863_DEFAULT_LATCH;
207
/*-------------------------------------------------
208
DEVICE_GET_INFO( cdp1863 )
209
-------------------------------------------------*/
211
DEVICE_GET_INFO( cdp1863 )
215
/* --- the following bits of info are returned as 64-bit signed integers --- */
216
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1863_t); break;
217
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(cdp1863_config); break;
219
/* --- the following bits of info are returned as pointers to data or functions --- */
220
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1863); break;
221
case DEVINFO_FCT_STOP: /* Nothing */ break;
222
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cdp1863); break;
224
/* --- the following bits of info are returned as NULL-terminated strings --- */
225
case DEVINFO_STR_NAME: strcpy(info->s, "RCA CDP1863"); break;
226
case DEVINFO_STR_FAMILY: strcpy(info->s, "RCA CDP1800"); break;
227
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
228
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
229
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break;