src/mess/drivers/cdi.c
| r6392 | r6393 | |
| 47 | 47 | |
| 48 | 48 | #define VERBOSE_LEVEL (5) |
| 49 | 49 | |
| 50 | | #define ENABLE_VERBOSE_LOG (0) |
| 50 | #define ENABLE_VERBOSE_LOG (1) |
| 51 | 51 | |
| 52 | 52 | #if ENABLE_VERBOSE_LOG |
| 53 | 53 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| r6392 | r6393 | |
| 1047 | 1047 | INT32 audio_sample_freq; |
| 1048 | 1048 | INT32 audio_sample_size; |
| 1049 | 1049 | |
| 1050 | UINT16 decode_addr; |
| 1051 | UINT8 decode_delay; |
| 1052 | attotime decode_period; |
| 1053 | |
| 1050 | 1054 | } cdic_regs_t; |
| 1051 | 1055 | |
| 1052 | 1056 | #define CDIC_SECTOR_SYNC 0 |
| r6392 | r6393 | |
| 1475 | 1479 | // After an appropriate delay for decoding to take place... |
| 1476 | 1480 | static TIMER_CALLBACK( audio_sample_trigger ) |
| 1477 | 1481 | { |
| 1478 | | // Indicate that data has been decoded |
| 1479 | | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 1480 | | cdic_regs.audio_buffer |= 0x8000; |
| 1482 | if(cdic_regs.decode_addr == 0xffff) |
| 1483 | { |
| 1484 | verboselog(machine, 0, "Decode stop requested, stopping playback\n" ); |
| 1485 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1486 | return; |
| 1487 | } |
| 1481 | 1488 | |
| 1482 | | // Set the CDIC interrupt line |
| 1483 | | verboselog(machine, 0, "Setting CDIC interrupt line for soundmap decode\n" ); |
| 1484 | | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1485 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1489 | if(!cdic_regs.decode_delay) |
| 1490 | { |
| 1491 | // Indicate that data has been decoded |
| 1492 | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 1493 | cdic_regs.audio_buffer |= 0x8000; |
| 1486 | 1494 | |
| 1487 | | if(CDIC_IS_VALID_SAMPLE_BUF(cdic_regs.z_buffer & 0x3ffe)) |
| 1495 | // Set the CDIC interrupt line |
| 1496 | verboselog(machine, 0, "Setting CDIC interrupt line for soundmap decode\n" ); |
| 1497 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1498 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1499 | } |
| 1500 | else |
| 1488 | 1501 | { |
| 1489 | | attotime period; |
| 1502 | cdic_regs.decode_delay = 0; |
| 1503 | } |
| 1490 | 1504 | |
| 1491 | | verboselog(machine, 0, "Hit audio_sample_trigger, with cdic_regs.z_buffer == %04x, calling cdic_decode_audio_sector\n", cdic_regs.z_buffer ); |
| 1505 | if(CDIC_IS_VALID_SAMPLE_BUF(cdic_regs.decode_addr & 0x3ffe)) |
| 1506 | { |
| 1507 | verboselog(machine, 0, "Hit audio_sample_trigger, with cdic_regs.decode_addr == %04x, calling cdic_decode_audio_sector\n", cdic_regs.decode_addr ); |
| 1492 | 1508 | |
| 1493 | 1509 | // Decode the data at Z+4, the same offset as a normal CD sector. |
| 1494 | | cdic_decode_audio_sector(machine, ((UINT8*)cdram) + (cdic_regs.z_buffer & 0x3ffe) + 4, 1); |
| 1510 | cdic_decode_audio_sector(machine, ((UINT8*)cdram) + (cdic_regs.decode_addr & 0x3ffe) + 4, 1); |
| 1495 | 1511 | |
| 1496 | 1512 | // Swap buffer positions to indicate our new buffer position at the next read |
| 1497 | | cdic_regs.z_buffer ^= 0x1a00; |
| 1498 | | cdic_regs.data_buffer ^= 0x0001; |
| 1513 | cdic_regs.decode_addr ^= 0x1a00; |
| 1499 | 1514 | |
| 1500 | | verboselog(machine, 0, "Updated cdic_regs.z_buffer, new value is %04x\n", cdic_regs.z_buffer ); |
| 1515 | verboselog(machine, 0, "Updated cdic_regs.decode_addr, new value is %04x\n", cdic_regs.decode_addr ); |
| 1501 | 1516 | |
| 1502 | 1517 | //// Delay for Frequency * (18*28*2*size in bytes) before requesting more data |
| 1503 | 1518 | verboselog(machine, 0, "Data is valid, setting up a new callback\n" ); |
| 1504 | | period = attotime_mul(ATTOTIME_IN_HZ(CDIC_SAMPLE_BUF_FREQ(cdic_regs.z_buffer & 0x3ffe)), 18*28*2*CDIC_SAMPLE_BUF_SIZE(cdic_regs.z_buffer & 0x3ffe)); |
| 1505 | | timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0); |
| 1519 | cdic_regs.decode_period = attotime_mul(ATTOTIME_IN_HZ(CDIC_SAMPLE_BUF_FREQ(cdic_regs.decode_addr & 0x3ffe)), 18*28*2*CDIC_SAMPLE_BUF_SIZE(cdic_regs.decode_addr & 0x3ffe)); |
| 1520 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, cdic_regs.decode_period, 0); |
| 1506 | 1521 | //dmadac_enable(&dmadac[0], 2, 0); |
| 1507 | 1522 | } |
| 1508 | 1523 | else |
| 1509 | 1524 | { |
| 1510 | 1525 | // Swap buffer positions to indicate our new buffer position at the next read |
| 1511 | | cdic_regs.z_buffer ^= 0x1a00; |
| 1512 | | cdic_regs.z_buffer &= 0xfffe; |
| 1513 | | verboselog(machine, 0, "Data is not valid, stopping playback\n" ); |
| 1514 | | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1526 | cdic_regs.decode_addr ^= 0x1a00; |
| 1527 | |
| 1528 | verboselog(machine, 0, "Data is not valid, indicating to shut down on the next audio sample\n" ); |
| 1529 | cdic_regs.decode_addr = 0xffff; |
| 1530 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, cdic_regs.decode_period, 0); |
| 1515 | 1531 | } |
| 1516 | 1532 | } |
| 1517 | 1533 | |
| r6392 | r6393 | |
| 1590 | 1606 | switch(cdic_regs.command) |
| 1591 | 1607 | { |
| 1592 | 1608 | case 0x23: // Reset Mode 1 |
| 1609 | case 0x24: // Reset Mode 2 |
| 1593 | 1610 | case 0x29: // Read Mode 1 |
| 1594 | 1611 | case 0x2a: // Read Mode 2 |
| 1595 | 1612 | //case 0x2c: // Seek |
| r6392 | r6393 | |
| 1673 | 1690 | } |
| 1674 | 1691 | } |
| 1675 | 1692 | |
| 1693 | cdic_regs.data_buffer &= ~0x0004; |
| 1694 | cdic_regs.data_buffer ^= 0x0001; |
| 1695 | |
| 1676 | 1696 | //printf( "%02x\n", buffer[CDIC_SECTOR_SUBMODE2] ); |
| 1677 | 1697 | if((buffer[CDIC_SECTOR_FILE2] << 8) == cdic_regs.file) |
| 1678 | 1698 | { |
| r6392 | r6393 | |
| 1684 | 1704 | { |
| 1685 | 1705 | verboselog(machine, 0, "Audio sector\n" ); |
| 1686 | 1706 | |
| 1687 | | cdic_regs.data_buffer ^= 0x0001; |
| 1688 | | |
| 1689 | 1707 | cdic_regs.x_buffer |= 0x8000; |
| 1690 | | cdic_regs.data_buffer |= 0x4000; |
| 1708 | //cdic_regs.data_buffer |= 0x4000; |
| 1691 | 1709 | cdic_regs.data_buffer |= 0x0004; |
| 1692 | 1710 | |
| 1693 | 1711 | for(index = 6; index < 2352/2; index++) |
| r6392 | r6393 | |
| 1705 | 1723 | } |
| 1706 | 1724 | else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00) |
| 1707 | 1725 | { |
| 1708 | | cdic_regs.data_buffer ^= 0x0001; |
| 1709 | | |
| 1710 | | cdic_regs.data_buffer &= ~0x0004; |
| 1711 | 1726 | cdic_regs.x_buffer |= 0x8000; |
| 1712 | | cdic_regs.data_buffer |= 0x4000; |
| 1727 | //cdic_regs.data_buffer |= 0x4000; |
| 1713 | 1728 | |
| 1714 | 1729 | for(index = 6; index < 2352/2; index++) |
| 1715 | 1730 | { |
| r6392 | r6393 | |
| 1732 | 1747 | } |
| 1733 | 1748 | else /*if(buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_VIDEO))*/ |
| 1734 | 1749 | { |
| 1735 | | cdic_regs.data_buffer ^= 0x0001; |
| 1736 | | |
| 1737 | | cdic_regs.data_buffer &= ~0x0004; |
| 1738 | 1750 | cdic_regs.x_buffer |= 0x8000; |
| 1739 | | cdic_regs.data_buffer |= 0x4000; |
| 1751 | //cdic_regs.data_buffer |= 0x4000; |
| 1740 | 1752 | |
| 1741 | 1753 | for(index = 6; index < 2352/2; index++) |
| 1742 | 1754 | { |
| r6392 | r6393 | |
| 1765 | 1777 | |
| 1766 | 1778 | break; |
| 1767 | 1779 | } |
| 1768 | | case 0x24: // Mode 2 Reset |
| 1780 | //case 0x24: // Mode 2 Reset |
| 1769 | 1781 | case 0x2e: // Abort |
| 1770 | 1782 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1771 | | cdic_regs.data_buffer &= ~4; |
| 1783 | //cdic_regs.data_buffer &= ~4; |
| 1772 | 1784 | break; |
| 1773 | 1785 | case 0x28: // Play CDDA audio |
| 1774 | 1786 | { |
| r6392 | r6393 | |
| 1830 | 1842 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 1831 | 1843 | |
| 1832 | 1844 | cdic_regs.x_buffer |= 0x8000; |
| 1833 | | cdic_regs.data_buffer |= 0x4000; |
| 1845 | //cdic_regs.data_buffer |= 0x4000; |
| 1834 | 1846 | |
| 1835 | 1847 | for(index = 6; index < 2352/2; index++) |
| 1836 | 1848 | { |
| r6392 | r6393 | |
| 2071 | 2083 | if(cdic_regs.z_buffer & 0x2000) |
| 2072 | 2084 | { |
| 2073 | 2085 | attotime period = timer_timeleft(cdic_regs.audio_sample_timer); |
| 2074 | | if(!attotime_is_never(period)) |
| 2086 | if(attotime_is_never(period)) |
| 2075 | 2087 | { |
| 2076 | | timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0); |
| 2077 | | } |
| 2078 | | else |
| 2079 | | { |
| 2088 | cdic_regs.decode_addr = cdic_regs.z_buffer & 0x3a00; |
| 2089 | cdic_regs.decode_delay = 1; |
| 2080 | 2090 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, ATTOTIME_IN_HZ(75), 0); |
| 2081 | 2091 | } |
| 2082 | 2092 | } |
| 2083 | 2093 | else |
| 2084 | 2094 | { |
| 2095 | cdic_regs.decode_addr = 0xffff; |
| 2085 | 2096 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 2086 | 2097 | } |
| 2087 | 2098 | break; |
| r6392 | r6393 | |
| 2098 | 2109 | { |
| 2099 | 2110 | switch(cdic_regs.command) |
| 2100 | 2111 | { |
| 2101 | | case 0x24: // Reset Mode 2 |
| 2112 | //case 0x24: // Reset Mode 2 |
| 2102 | 2113 | case 0x2e: // Abort |
| 2103 | 2114 | { |
| 2104 | 2115 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 2105 | 2116 | dmadac_enable(&dmadac[0], 2, 0); |
| 2106 | | cdic_regs.data_buffer &= 0xbfff; |
| 2117 | //cdic_regs.data_buffer &= 0xbfff; |
| 2107 | 2118 | break; |
| 2108 | 2119 | } |
| 2109 | 2120 | case 0x2b: // Stop CDDA |
| r6392 | r6393 | |
| 2117 | 2128 | case 0x2c: // Seek |
| 2118 | 2129 | { |
| 2119 | 2130 | attotime period = timer_timeleft(cdic_regs.interrupt_timer); |
| 2120 | | //if(cdic_regs.command == 0x2c) |
| 2121 | | //{ |
| 2122 | | // cdic_regs.time &= 0xffff0000; |
| 2123 | | //} |
| 2124 | 2131 | if(!attotime_is_never(period)) |
| 2125 | 2132 | { |
| 2126 | 2133 | timer_adjust_oneshot(cdic_regs.interrupt_timer, period, 0); |
| 2127 | 2134 | } |
| 2128 | 2135 | else |
| 2129 | 2136 | { |
| 2130 | | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 2137 | if(cdic_regs.command != 0x23 && cdic_regs.command != 0x24) |
| 2138 | { |
| 2139 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 2140 | } |
| 2131 | 2141 | } |
| 2132 | 2142 | break; |
| 2133 | 2143 | } |
| r6392 | r6393 | |
| 2161 | 2171 | |
| 2162 | 2172 | cdic->audio_sample_freq = 0; |
| 2163 | 2173 | cdic->audio_sample_size = 0; |
| 2174 | |
| 2175 | cdic->decode_addr = 0; |
| 2176 | cdic->decode_delay = 0; |
| 2164 | 2177 | } |
| 2165 | 2178 | |
| 2166 | 2179 | static void cdic_register_globals(running_machine *machine) |