src/mess/drivers/cdi.c
| r6130 | r6131 | |
| 47 | 47 | |
| 48 | 48 | #define VERBOSE_LEVEL (6) |
| 49 | 49 | |
| 50 | | #define ENABLE_VERBOSE_LOG (1) |
| 50 | #define ENABLE_VERBOSE_LOG (0) |
| 51 | 51 | |
| 52 | 52 | #if ENABLE_VERBOSE_LOG |
| 53 | 53 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| r6130 | r6131 | |
| 328 | 328 | { |
| 329 | 329 | case 0: |
| 330 | 330 | 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); |
| 332 | 332 | timer_adjust_oneshot(scc68070_regs.timers.timer0_timer, period, 0); |
| 333 | 333 | break; |
| 334 | 334 | default: |
| r6130 | r6131 | |
| 1161 | 1161 | cdic_xa_last[3]=l3; |
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | | static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa) |
| 1164 | static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa, int triggered) |
| 1165 | 1165 | { |
| 1166 | 1166 | // Get XA format from sector header |
| 1167 | 1167 | |
| r6130 | r6131 | |
| 1170 | 1170 | int bits = 4; |
| 1171 | 1171 | int index = 0; |
| 1172 | 1172 | INT16 samples[18*28*16+16]; |
| 1173 | | FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1173 | //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1174 | 1174 | |
| 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); |
| 1176 | 1183 | //printf( "%02x\n", hdr[2] & 0x3f ); |
| 1177 | 1184 | switch(hdr[2] & 0x3f) // ignore emphasis and reserved bits |
| 1178 | 1185 | { |
| r6130 | r6131 | |
| 1273 | 1280 | |
| 1274 | 1281 | dmadac_transfer(&dmadac[0], 2, 2, 2, 18*28*2*cdic_regs.audio_sample_size, samples); |
| 1275 | 1282 | |
| 1276 | | fclose(temp_adpcm); |
| 1283 | //fclose(temp_adpcm); |
| 1277 | 1284 | } |
| 1278 | 1285 | |
| 1286 | // After an appropriate delay for decoding to take place... |
| 1279 | 1287 | static TIMER_CALLBACK( audio_sample_trigger ) |
| 1280 | 1288 | { |
| 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); |
| 1284 | 1311 | //dmadac_enable(&dmadac[0], 2, 0); |
| 1285 | 1312 | } |
| 1286 | 1313 | |
| r6130 | r6131 | |
| 1381 | 1408 | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1382 | 1409 | } |
| 1383 | 1410 | |
| 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); |
| 1385 | 1412 | // Ignore the audio sector for now. |
| 1386 | 1413 | cdic_regs.x_buffer |= 0x8000; |
| 1387 | 1414 | |
| r6130 | r6131 | |
| 1460 | 1487 | } |
| 1461 | 1488 | } |
| 1462 | 1489 | |
| 1490 | INLINE 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 | |
| 1500 | INLINE 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 | |
| 1520 | INLINE 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 | |
| 1463 | 1542 | static READ16_HANDLER( cdic_r ) |
| 1464 | 1543 | { |
| 1465 | 1544 | offset += 0x3c00/2; |
| r6130 | r6131 | |
| 1478 | 1557 | verboselog(space->machine, 0, "cdic_r: Audio Channel Register = %04x & %04x\n", cdic_regs.audio_channel, mem_mask); |
| 1479 | 1558 | return cdic_regs.audio_channel; |
| 1480 | 1559 | 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 | } |
| 1483 | 1572 | case 0x3ff6/2: |
| 1484 | 1573 | { |
| 1485 | 1574 | UINT16 temp = cdic_regs.x_buffer; |
| r6130 | r6131 | |
| 1493 | 1582 | case 0x3ffe/2: |
| 1494 | 1583 | { |
| 1495 | 1584 | UINT16 temp = cdic_regs.data_buffer; |
| 1496 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 1497 | 1585 | 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; |
| 1500 | 1593 | return temp; |
| 1501 | 1594 | } |
| 1502 | 1595 | default: |
| r6130 | r6131 | |
| 1576 | 1669 | case 0x3ffa/2: |
| 1577 | 1670 | verboselog(space->machine, 0, "cdic_w: Z-Buffer Register = %04x & %04x\n", data, mem_mask); |
| 1578 | 1671 | COMBINE_DATA(&cdic_regs.z_buffer); |
| 1672 | /* |
| 1579 | 1673 | if(cdic_regs.z_buffer & 0x2000) |
| 1580 | 1674 | { |
| 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 | } |
| 1585 | 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1684 | } |
| 1685 | */ |
| 1586 | 1686 | break; |
| 1587 | 1687 | case 0x3ffc/2: |
| 1588 | 1688 | verboselog(space->machine, 0, "cdic_w: Interrupt Vector Register = %04x & %04x\n", data, mem_mask); |
| r6130 | r6131 | |
| 1897 | 1997 | dmadac_enable(&dmadac[0], 2, 0); |
| 1898 | 1998 | slave_regs.in_index = 0; |
| 1899 | 1999 | slave_regs.in_count = 0; |
| 2000 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1900 | 2001 | break; |
| 1901 | 2002 | case 0x83: // Unmute audio |
| 1902 | 2003 | verboselog(space->machine, 0, "slave_w: Channel %d: Unmute Audio (0x83)\n", offset ); |
| r6130 | r6131 | |
| 3685 | 3786 | *************************/ |
| 3686 | 3787 | |
| 3687 | 3788 | static MACHINE_DRIVER_START( cdimono1 ) |
| 3688 | | MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/3) |
| 3789 | MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/2) |
| 3689 | 3790 | MDRV_CPU_PROGRAM_MAP(cdimono1_mem) |
| 3690 | 3791 | |
| 3691 | 3792 | MDRV_SCREEN_ADD("screen", RASTER) |