Previous 15994 Revisions Next

r6131 Sunday 18th October, 2009 at 16:42:54 UTC by Harmony
[CDI] Improving sound effect code; sounds great on Golden Oldies 1 and Lemmings, but causes bad sound in Hotel Mario and crashing in Pac-Panic. Commented out for now. [Harmony]
[src/mess/drivers]cdi.c

src/mess/drivers/cdi.c
r6130r6131
4747
4848#define VERBOSE_LEVEL   (6)
4949
50#define ENABLE_VERBOSE_LOG (1)
50#define ENABLE_VERBOSE_LOG (0)
5151
5252#if ENABLE_VERBOSE_LOG
5353INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...)
r6130r6131
328328   {
329329      case 0:
330330         compare = 0x10000 - scc68070_regs.timers.timer0;
331         period = attotime_mul(ATTOTIME_IN_HZ(CLOCK_A/150), compare);
331         period = attotime_mul(ATTOTIME_IN_HZ(CLOCK_A/192), compare);
332332            timer_adjust_oneshot(scc68070_regs.timers.timer0_timer, period, 0);
333333         break;
334334      default:
r6130r6131
11611161   cdic_xa_last[3]=l3;
11621162}
11631163
1164static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa)
1164static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa, int triggered)
11651165{
11661166   // Get XA format from sector header
11671167
r6130r6131
11701170   int bits = 4;
11711171   int index = 0;
11721172   INT16 samples[18*28*16+16];
1173   FILE* temp_adpcm = fopen("temp_adpcm.bin","ab");
1173   //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab");
11741174
1175   fseek(temp_adpcm, 0, SEEK_END);
1175   if(hdr[2] == 0xff && triggered == 1)
1176   {
1177      // Stop playing
1178      timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0);
1179      return;
1180   }
1181
1182   //fseek(temp_adpcm, 0, SEEK_END);
11761183   //printf( "%02x\n", hdr[2] & 0x3f );
11771184   switch(hdr[2] & 0x3f)   // ignore emphasis and reserved bits
11781185   {
r6130r6131
12731280
12741281    dmadac_transfer(&dmadac[0], 2, 2, 2, 18*28*2*cdic_regs.audio_sample_size, samples);
12751282
1276   fclose(temp_adpcm);
1283   //fclose(temp_adpcm);
12771284}
12781285
1286// After an appropriate delay for decoding to take place...
12791287static TIMER_CALLBACK( audio_sample_trigger )
12801288{
1281   cdic_regs.z_buffer += 0xa00;
1282   cdic_decode_audio_sector(machine, ((UINT8*)cdram) + cdic_regs.z_buffer + 4);
1283   timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0);
1289   attotime period;
1290
1291   // Decode the data at Z+4, the same offset as a normal CD sector.
1292   cdic_decode_audio_sector(machine, ((UINT8*)cdram) + cdic_regs.z_buffer + 4, 1);
1293
1294   // Swap buffer positions to indicate our new buffer position at the next read
1295   cdic_regs.z_buffer = (cdic_regs.z_buffer == 0x2800) ? 0x3200 : 0x2800;
1296
1297   //// Delay for Frequency * (18*28*2*size in bytes)
1298   period = attotime_mul(ATTOTIME_IN_HZ(cdic_regs.audio_sample_freq), 18*28*2*cdic_regs.audio_sample_size);
1299
1300   // Indicate that data has been decoded
1301   cdic_regs.audio_buffer |= 0x8000;
1302
1303   // Set the CDIC interrupt line
1304   //printf( "Setting CDIC interrupt line\n" );
1305   verboselog(machine, 0, "Setting CDIC interrupt line\n" );
1306   cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128);
1307   cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE);
1308
1309   // Request more data as necessary
1310   timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0);
12841311   //dmadac_enable(&dmadac[0], 2, 0);
12851312}
12861313
r6130r6131
13811408                  cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1];
13821409               }
13831410
1384               cdic_decode_audio_sector(machine, ((UINT8*)cdram) + ((cdic_regs.data_buffer & 5) * 0xa00 + 4));
1411               cdic_decode_audio_sector(machine, ((UINT8*)cdram) + ((cdic_regs.data_buffer & 5) * 0xa00 + 4), 0);
13851412               // Ignore the audio sector for now.
13861413               cdic_regs.x_buffer |= 0x8000;
13871414
r6130r6131
14601487   }
14611488}
14621489
1490INLINE int CDIC_IS_VALID_SAMPLE_BUF(UINT16 addr)
1491{
1492   UINT8 *cdram8 = ((UINT8*)cdram) + addr + 4;
1493   if(cdram8[2] != 0xff)
1494   {
1495      return 1;
1496   }
1497   return 0;
1498}
1499
1500INLINE double CDIC_SAMPLE_BUF_FREQ(UINT16 addr)
1501{
1502   UINT8 *cdram8 = ((UINT8*)cdram) + addr + 4;
1503   switch(cdram8[2] & 0x3f)
1504   {
1505      case 0:
1506      case 1:
1507      case 16:
1508      case 17:
1509         return 37800.0f;
1510
1511      case 4:
1512      case 5:
1513         return 18900.0f;
1514
1515      default:
1516         return 18900.0f;
1517   }
1518}
1519
1520INLINE int CDIC_SAMPLE_BUF_SIZE(UINT16 addr)
1521{
1522   UINT8 *cdram8 = ((UINT8*)cdram) + addr + 4;
1523   switch(cdram8[2] & 0x3f)
1524   {
1525      case 0:
1526      case 4:
1527         return 4;
1528
1529      case 1:
1530      case 5:
1531      case 16:
1532         return 2;
1533
1534      case 17:
1535         return 1;
1536
1537      default:
1538         return 2;
1539   }
1540}
1541
14631542static READ16_HANDLER( cdic_r )
14641543{
14651544   offset += 0x3c00/2;
r6130r6131
14781557         verboselog(space->machine, 0, "cdic_r: Audio Channel Register = %04x & %04x\n", cdic_regs.audio_channel, mem_mask);
14791558         return cdic_regs.audio_channel;
14801559      case 0x3ff4/2:
1481         verboselog(space->machine, 0, "cdic_r: Audio Buffer Register = %04x & %04x\n", cdic_regs.audio_buffer, mem_mask);
1482         return cdic_regs.audio_buffer | 0x8000;
1560      {
1561         UINT16 temp = cdic_regs.audio_buffer;
1562         if(cdic_regs.audio_buffer & 0x8000)
1563         {
1564            cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE);
1565            verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" );
1566            //printf("Clearing CDIC interrupt line\n" );
1567         }
1568         cdic_regs.audio_buffer &= 0x7fff;
1569         verboselog(space->machine, 0, "cdic_r: Audio Buffer Register = %04x & %04x\n", temp, mem_mask);
1570         return temp;
1571      }
14831572      case 0x3ff6/2:
14841573      {
14851574         UINT16 temp = cdic_regs.x_buffer;
r6130r6131
14931582      case 0x3ffe/2:
14941583      {
14951584         UINT16 temp = cdic_regs.data_buffer;
1496         cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE);
14971585         verboselog(space->machine, 0, "cdic_r: Data buffer Register = %04x & %04x\n", temp, mem_mask);
1498         verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" );
1499         //printf("Clearing CDIC interrupt line\n" );
1586         if(cdic_regs.data_buffer & 0x4000)
1587         {
1588            cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE);
1589            verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" );
1590            //printf("Clearing CDIC interrupt line\n" );
1591         }
1592         cdic_regs.data_buffer &= ~0x4000;
15001593         return temp;
15011594      }
15021595      default:
r6130r6131
15761669      case 0x3ffa/2:
15771670         verboselog(space->machine, 0, "cdic_w: Z-Buffer Register = %04x & %04x\n", data, mem_mask);
15781671         COMBINE_DATA(&cdic_regs.z_buffer);
1672         /*
15791673         if(cdic_regs.z_buffer & 0x2000)
15801674         {
1581            // Broken.
1582            //attotime period = attotime_mul(ATTOTIME_IN_HZ(cdic_regs.audio_sample_freq), 18*28*4*cdic_regs.audio_sample_size);
1583            //timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0);
1584            //cdic_decode_audio_sector(space->machine, ((UINT8*)cdram) + cdic_regs.z_buffer + 4);
1675            if(CDIC_IS_VALID_SAMPLE_BUF(cdic_regs.z_buffer))
1676            {
1677               attotime period = attotime_mul(ATTOTIME_IN_HZ(CDIC_SAMPLE_BUF_FREQ(cdic_regs.z_buffer)), 18*28*4*CDIC_SAMPLE_BUF_SIZE(cdic_regs.z_buffer));
1678               timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0);
1679            }
15851680         }
1681         else
1682         {
1683            timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0);
1684         }
1685         */
15861686         break;
15871687      case 0x3ffc/2:
15881688         verboselog(space->machine, 0, "cdic_w: Interrupt Vector Register = %04x & %04x\n", data, mem_mask);
r6130r6131
18971997                  dmadac_enable(&dmadac[0], 2, 0);
18981998                  slave_regs.in_index = 0;
18991999                  slave_regs.in_count = 0;
2000                  timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0);
19002001                  break;
19012002               case 0x83: // Unmute audio
19022003                  verboselog(space->machine, 0, "slave_w: Channel %d: Unmute Audio (0x83)\n", offset );
r6130r6131
36853786*************************/
36863787
36873788static MACHINE_DRIVER_START( cdimono1 )
3688   MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/3)
3789   MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/2)
36893790   MDRV_CPU_PROGRAM_MAP(cdimono1_mem)
36903791
36913792   MDRV_SCREEN_ADD("screen", RASTER)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team