~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/sound/okim6295.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
{
49
49
        #define OKIM6295_VOICES         4
50
50
        struct ADPCMVoice voice[OKIM6295_VOICES];
 
51
        const device_config *device;
51
52
        INT32 command;
52
 
        INT32 bank_offset;
53
 
        UINT8 *region_base;             /* pointer to the base of the region */
 
53
        INT32 bank_num;
 
54
        INT32 bank_offs;
54
55
        sound_stream *stream;   /* which stream are we playing on? */
55
56
        UINT32 master_clock;    /* master clock frequency */
56
57
};
91
92
const okim6295_interface okim6295_interface_pin7high = { 1 };
92
93
const okim6295_interface okim6295_interface_pin7low = { 0 };
93
94
 
 
95
/* default address map */
 
96
static ADDRESS_MAP_START( okim6295, 0, 8 )
 
97
        AM_RANGE(0x00000, 0x3ffff) AM_ROM
 
98
ADDRESS_MAP_END
 
99
 
94
100
 
95
101
INLINE okim6295_state *get_safe_token(const device_config *device)
96
102
{
202
208
        /* if this voice is active */
203
209
        if (voice->playing)
204
210
        {
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;
208
214
 
210
216
                while (samples)
211
217
                {
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);
214
220
 
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);
310
316
}
311
317
 
 
318
static STATE_POSTLOAD( okim6295_postload )
 
319
{
 
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);
 
323
}
 
324
 
312
325
static void okim6295_state_save_register(okim6295_state *info, const device_config *device)
313
326
{
314
327
        int j;
315
328
 
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);
 
333
 
 
334
        state_save_register_postload(device->machine, okim6295_postload, (void *)device);
320
335
}
321
336
 
322
337
 
331
346
{
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;
334
350
        int voice;
335
 
        int divisor = intf->pin7 ? 132 : 165;
336
351
 
337
352
        compute_tables();
338
353
 
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);
 
355
        info->bank_num = -1;
 
356
        info->bank_offs = 0;
 
357
        info->device = device;
344
358
 
345
359
        info->master_clock = device->clock;
346
360
 
388
402
{
389
403
        okim6295_state *info = get_safe_token(device);
390
404
        stream_update(info->stream);
391
 
        info->bank_offset = base;
 
405
 
 
406
        /* if we are setting a non-zero base, and we have no bank, allocate one */
 
407
        if (info->bank_num == -1 && base != 0)
 
408
        {
 
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);
 
412
 
 
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));
 
415
        }
 
416
 
 
417
        /* if we have a bank number, set the base pointer */
 
418
        if (info->bank_num != -1)
 
419
        {
 
420
                info->bank_offs = base;
 
421
                memory_set_bankptr(device->machine, info->bank_num, device->region + base);
 
422
        }
392
423
}
393
424
 
394
425
 
451
482
        if (info->command != -1)
452
483
        {
453
484
                int temp = data >> 4, i, start, stop;
454
 
                unsigned char *base;
455
 
 
 
485
                offs_t base;
456
486
 
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];
470
500
 
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;
 
503
 
 
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;
 
507
                                start &= 0x3ffff;
 
508
 
 
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;
 
512
                                stop &= 0x3ffff;
475
513
 
476
514
                                /* set up the voice to play this sample */
477
515
                                if (start < stop)
543
581
        switch (state)
544
582
        {
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;
547
 
 
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;
 
588
 
 
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;
 
591
 
 
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;
552
595
 
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;
559
602
        }
560
603
}