49
49
#define OKIM6295_VOICES 4
50
50
struct ADPCMVoice voice[OKIM6295_VOICES];
51
const device_config *device;
53
UINT8 *region_base; /* pointer to the base of the region */
54
55
sound_stream *stream; /* which stream are we playing on? */
55
56
UINT32 master_clock; /* master clock frequency */
91
92
const okim6295_interface okim6295_interface_pin7high = { 1 };
92
93
const okim6295_interface okim6295_interface_pin7low = { 0 };
95
/* default address map */
96
static ADDRESS_MAP_START( okim6295, 0, 8 )
97
AM_RANGE(0x00000, 0x3ffff) AM_ROM
95
101
INLINE okim6295_state *get_safe_token(const device_config *device)
202
208
/* if this voice is active */
203
209
if (voice->playing)
205
UINT8 *base = chip->region_base + chip->bank_offset + voice->base_offset;
211
offs_t base = voice->base_offset;
206
212
int sample = voice->sample;
207
213
int count = voice->count;
212
218
/* compute the new amplitude and update the current step */
213
int nibble = base[sample / 2] >> (((sample & 1) << 2) ^ 4);
219
int nibble = memory_raw_read_byte(chip->device->space[0], base + sample / 2) >> (((sample & 1) << 2) ^ 4);
215
221
/* output to the buffer, scaling by the volume */
216
222
/* signal in range -2048..2047, volume in range 2..32 => signal * volume / 2 in range -32768..32767 */
309
315
state_save_register_device_item(device, index, voice->base_offset);
318
static STATE_POSTLOAD( okim6295_postload )
320
const device_config *device = (const device_config *)param;
321
okim6295_state *info = get_safe_token(device);
322
okim6295_set_bank_base(device, info->bank_offs);
312
325
static void okim6295_state_save_register(okim6295_state *info, const device_config *device)
316
329
state_save_register_device_item(device, 0, info->command);
317
state_save_register_device_item(device, 0, info->bank_offset);
330
state_save_register_device_item(device, 0, info->bank_offs);
318
331
for (j = 0; j < OKIM6295_VOICES; j++)
319
332
adpcm_state_save_register(&info->voice[j], device, j);
334
state_save_register_postload(device->machine, okim6295_postload, (void *)device);
332
347
const okim6295_interface *intf = (const okim6295_interface *)device->static_config;
333
348
okim6295_state *info = get_safe_token(device);
349
int divisor = intf->pin7 ? 132 : 165;
335
int divisor = intf->pin7 ? 132 : 165;
337
352
compute_tables();
339
354
info->command = -1;
340
info->bank_offset = 0;
341
info->region_base = device->region;
342
if (intf->rgnoverride != NULL)
343
info->region_base = memory_region(device->machine, intf->rgnoverride);
357
info->device = device;
345
359
info->master_clock = device->clock;
389
403
okim6295_state *info = get_safe_token(device);
390
404
stream_update(info->stream);
391
info->bank_offset = base;
406
/* if we are setting a non-zero base, and we have no bank, allocate one */
407
if (info->bank_num == -1 && base != 0)
409
info->bank_num = memory_find_unused_bank(device->machine);
410
if (info->bank_num == -1)
411
fatalerror("Unable to allocate bank for oki6295 device '%s'", device->tag);
413
/* override our memory map with a bank */
414
memory_install_read8_handler(device->space[0], 0x00000, 0x3ffff, 0, 0, (read8_space_func)SMH_BANK(info->bank_num));
417
/* if we have a bank number, set the base pointer */
418
if (info->bank_num != -1)
420
info->bank_offs = base;
421
memory_set_bankptr(device->machine, info->bank_num, device->region + base);
451
482
if (info->command != -1)
453
484
int temp = data >> 4, i, start, stop;
457
487
/* the manual explicitly says that it's not possible to start multiple voices at the same time */
458
488
if (temp != 0 && temp != 1 && temp != 2 && temp != 4 && temp != 8)
469
499
struct ADPCMVoice *voice = &info->voice[i];
471
501
/* determine the start/stop positions */
472
base = &info->region_base[info->bank_offset + info->command * 8];
473
start = ((base[0] << 16) + (base[1] << 8) + base[2]) & 0x3ffff;
474
stop = ((base[3] << 16) + (base[4] << 8) + base[5]) & 0x3ffff;
502
base = info->command * 8;
504
start = memory_raw_read_byte(device->space[0], base + 0) << 16;
505
start |= memory_raw_read_byte(device->space[0], base + 1) << 8;
506
start |= memory_raw_read_byte(device->space[0], base + 2) << 0;
509
stop = memory_raw_read_byte(device->space[0], base + 3) << 16;
510
stop |= memory_raw_read_byte(device->space[0], base + 4) << 8;
511
stop |= memory_raw_read_byte(device->space[0], base + 5) << 0;
476
514
/* set up the voice to play this sample */
477
515
if (start < stop)
545
583
/* --- the following bits of info are returned as 64-bit signed integers --- */
546
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(okim6295_state); break;
548
/* --- the following bits of info are returned as pointers to data or functions --- */
549
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( okim6295 ); break;
550
case DEVINFO_FCT_STOP: /* nothing */ break;
551
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( okim6295 ); break;
584
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(okim6295_state); break;
585
case DEVINFO_INT_DATABUS_WIDTH_0: info->i = 8; break;
586
case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = 18; break;
587
case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = 0; break;
589
/* --- the following bits of info are returned as pointers to data --- */
590
case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->default_map8 = ADDRESS_MAP_NAME(okim6295);break;
592
/* --- the following bits of info are returned as pointers to functions --- */
593
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( okim6295 ); break;
594
case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( okim6295 ); break;
553
596
/* --- the following bits of info are returned as NULL-terminated strings --- */
554
case DEVINFO_STR_NAME: strcpy(info->s, "OKI6295"); break;
555
case DEVINFO_STR_FAMILY: strcpy(info->s, "OKI ADPCM"); break;
556
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
557
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
597
case DEVINFO_STR_NAME: strcpy(info->s, "OKI6295"); break;
598
case DEVINFO_STR_FAMILY: strcpy(info->s, "OKI ADPCM"); break;
599
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
600
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
558
601
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;