src/mess/drivers/cdi.c
| r6190 | r6191 | |
| 34 | 34 | #include "cpu/m68000/m68000.h" |
| 35 | 35 | #include "sound/dmadac.h" |
| 36 | 36 | #include "devices/chd_cd.h" |
| 37 | #include "machine/timekpr.h" |
| 38 | #include "sound/cdda.h" |
| 37 | 39 | |
| 38 | 40 | static UINT16 *planea; |
| 39 | 41 | static UINT16 *planeb; |
| r6190 | r6191 | |
| 45 | 47 | |
| 46 | 48 | #define ENABLE_UART_PRINTING (0) |
| 47 | 49 | |
| 48 | | #define VERBOSE_LEVEL (0) |
| 50 | #define VERBOSE_LEVEL (5) |
| 49 | 51 | |
| 50 | 52 | #define ENABLE_VERBOSE_LOG (0) |
| 51 | 53 | |
| r6190 | r6191 | |
| 88 | 90 | static READ16_HANDLER( slave_r ); |
| 89 | 91 | static WRITE16_HANDLER( slave_w ); |
| 90 | 92 | |
| 91 | | // RTC |
| 92 | | static READ16_HANDLER( m48t08_r ); |
| 93 | | static WRITE16_HANDLER( m48t08_w ); |
| 94 | | |
| 95 | 93 | // Platform-specific |
| 96 | 94 | static void cdi220_draw_lcd(running_machine *machine, int y); |
| 97 | 95 | |
| r6190 | r6191 | |
| 1380 | 1378 | } |
| 1381 | 1379 | else |
| 1382 | 1380 | { |
| 1381 | // Swap buffer positions to indicate our new buffer position at the next read |
| 1382 | cdic_regs.z_buffer ^= 0x1a00; |
| 1383 | 1383 | verboselog(machine, 0, "Data is not valid, stopping playback\n" ); |
| 1384 | 1384 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | static UINT32 increment_cdda_bcd(UINT32 bcd) |
| 1389 | { |
| 1390 | UINT8 nybbles[6] = |
| 1391 | { |
| 1392 | bcd & 0x0000000f, |
| 1393 | (bcd & 0x000000f0) >> 4, |
| 1394 | (bcd & 0x00000f00) >> 8, |
| 1395 | (bcd & 0x0000f000) >> 12, |
| 1396 | (bcd & 0x000f0000) >> 16, |
| 1397 | (bcd & 0x00f00000) >> 20 |
| 1398 | }; |
| 1399 | nybbles[2]++; |
| 1400 | if(nybbles[2] == 10) |
| 1401 | { |
| 1402 | nybbles[3]++; |
| 1403 | nybbles[2] = 0; |
| 1404 | } |
| 1405 | if(nybbles[3] == 6) |
| 1406 | { |
| 1407 | nybbles[4]++; |
| 1408 | nybbles[3] = 0; |
| 1409 | } |
| 1410 | if(nybbles[4] == 10) |
| 1411 | { |
| 1412 | nybbles[5]++; |
| 1413 | nybbles[4] = 0; |
| 1414 | } |
| 1415 | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 1416 | } |
| 1417 | |
| 1388 | 1418 | static TIMER_CALLBACK( cdic_trigger_readback_int ) |
| 1389 | 1419 | { |
| 1390 | 1420 | switch(cdic_regs.command) |
| r6190 | r6191 | |
| 1563 | 1593 | case 0x2e: // Abort |
| 1564 | 1594 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1565 | 1595 | break; |
| 1596 | case 0x28: // Play CDDA audio |
| 1597 | { |
| 1598 | UINT32 msf = (cdic_regs.time & 0xffff0000) >> 8; |
| 1599 | UINT32 next_msf = increment_cdda_bcd((cdic_regs.time & 0xffff0000) >> 8); |
| 1600 | UINT32 lba = 0; |
| 1601 | UINT32 next_lba = 0; |
| 1602 | UINT8 nybbles[6] = |
| 1603 | { |
| 1604 | msf & 0x0000000f, |
| 1605 | (msf & 0x000000f0) >> 4, |
| 1606 | (msf & 0x00000f00) >> 8, |
| 1607 | (msf & 0x0000f000) >> 12, |
| 1608 | (msf & 0x000f0000) >> 16, |
| 1609 | (msf & 0x00f00000) >> 20 |
| 1610 | }; |
| 1611 | UINT8 next_nybbles[6] = |
| 1612 | { |
| 1613 | next_msf & 0x0000000f, |
| 1614 | (next_msf & 0x000000f0) >> 4, |
| 1615 | (next_msf & 0x00000f00) >> 8, |
| 1616 | (next_msf & 0x0000f000) >> 12, |
| 1617 | (next_msf & 0x000f0000) >> 16, |
| 1618 | (next_msf & 0x00f00000) >> 20 |
| 1619 | }; |
| 1620 | cdic_regs.time = next_msf << 8; |
| 1621 | if(msf & 0x000080) |
| 1622 | { |
| 1623 | msf &= 0xffff00; |
| 1624 | nybbles[0] = 0; |
| 1625 | nybbles[1] = 0; |
| 1626 | } |
| 1627 | if(nybbles[2] >= 2) |
| 1628 | { |
| 1629 | nybbles[2] -= 2; |
| 1630 | } |
| 1631 | else |
| 1632 | { |
| 1633 | nybbles[2] = 8 + nybbles[2]; |
| 1634 | if(nybbles[3] > 0) |
| 1635 | { |
| 1636 | nybbles[3]--; |
| 1637 | } |
| 1638 | else |
| 1639 | { |
| 1640 | nybbles[3] = 5; |
| 1641 | if(nybbles[4] > 0) |
| 1642 | { |
| 1643 | nybbles[4]--; |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | nybbles[4] = 9; |
| 1648 | nybbles[5]--; |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 1653 | if(next_nybbles[2] >= 2) |
| 1654 | { |
| 1655 | next_nybbles[2] -= 2; |
| 1656 | } |
| 1657 | else |
| 1658 | { |
| 1659 | next_nybbles[2] = 8 + next_nybbles[2]; |
| 1660 | if(next_nybbles[3] > 0) |
| 1661 | { |
| 1662 | next_nybbles[3]--; |
| 1663 | } |
| 1664 | else |
| 1665 | { |
| 1666 | next_nybbles[3] = 5; |
| 1667 | if(next_nybbles[4] > 0) |
| 1668 | { |
| 1669 | next_nybbles[4]--; |
| 1670 | } |
| 1671 | else |
| 1672 | { |
| 1673 | next_nybbles[4] = 9; |
| 1674 | next_nybbles[5]--; |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | next_lba = next_nybbles[0] + next_nybbles[1]*10 + ((next_nybbles[2] + next_nybbles[3]*10)*75) + ((next_nybbles[4] + next_nybbles[5]*10)*75*60); |
| 1680 | |
| 1681 | verboselog(machine, 0, "Playing CDDA sector from MSF location %06x\n", cdic_regs.time | 2 ); |
| 1682 | |
| 1683 | cdda_start_audio(devtag_get_device(machine, "cdda"), lba, next_lba); |
| 1684 | |
| 1685 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(1), 0); |
| 1686 | |
| 1687 | verboselog(machine, 0, "Setting CDIC interrupt line for CDDA sector\n" ); |
| 1688 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1689 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1690 | break; |
| 1691 | } |
| 1566 | 1692 | } |
| 1567 | 1693 | } |
| 1568 | 1694 | |
| r6190 | r6191 | |
| 1740 | 1866 | COMBINE_DATA(&cdic_regs.z_buffer); |
| 1741 | 1867 | if(cdic_regs.z_buffer & 0x2000) |
| 1742 | 1868 | { |
| 1743 | | attotime period = timer_timeleft(cdic_regs.audio_sample_timer); |
| 1869 | attotime period = timer_timeleft(cdic_regs.interrupt_timer); |
| 1744 | 1870 | if(!attotime_is_never(period)) |
| 1745 | 1871 | { |
| 1746 | 1872 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0); |
| r6190 | r6191 | |
| 1778 | 1904 | case 0x2a: // Read Mode 2 |
| 1779 | 1905 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1780 | 1906 | break; |
| 1907 | case 0x28: // Play CDDA |
| 1908 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_zero, 0); |
| 1909 | cdic_regs.data_buffer &= 0x3fff; |
| 1910 | break; |
| 1911 | case 0x2b: // Stop CDDA |
| 1912 | cdda_stop_audio(devtag_get_device(space->machine, "cdda")); |
| 1913 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1914 | break; |
| 1781 | 1915 | case 0x2c: // Seek |
| 1782 | | if(cdic_regs.time & 0x00008000) |
| 1783 | | { |
| 1784 | | cdic_regs.time &= 0xffff0000; |
| 1785 | | } |
| 1786 | 1916 | break; |
| 1787 | 1917 | default: |
| 1788 | 1918 | verboselog(space->machine, 0, "Unknown CDIC command: %02x\n", cdic_regs.command ); |
| r6190 | r6191 | |
| 2174 | 2304 | } |
| 2175 | 2305 | } |
| 2176 | 2306 | |
| 2177 | | typedef struct |
| 2178 | | { |
| 2179 | | UINT8 nvram[0x2000]; |
| 2180 | | emu_timer *clock; |
| 2181 | | } m48t08_regs_t; |
| 2182 | | |
| 2183 | | static m48t08_regs_t m48t08; |
| 2184 | | |
| 2185 | | static READ16_HANDLER( m48t08_r ) |
| 2186 | | { |
| 2187 | | verboselog(space->machine, 11, "m48t08_r: %04x = %02x & %04x\n", offset, m48t08.nvram[offset], mem_mask ); |
| 2188 | | return m48t08.nvram[offset] << 8; |
| 2189 | | } |
| 2190 | | |
| 2191 | | static WRITE16_HANDLER( m48t08_w ) |
| 2192 | | { |
| 2193 | | verboselog(space->machine, 11, "m48t08_w: %04x = %02x\n", offset, data >> 8); |
| 2194 | | switch(offset) |
| 2195 | | { |
| 2196 | | case 0x1ff9: |
| 2197 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2198 | | { |
| 2199 | | m48t08.nvram[0x1ff9] = (data >> 8) & 0x00ff; |
| 2200 | | } |
| 2201 | | break; |
| 2202 | | case 0x1ffa: |
| 2203 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2204 | | { |
| 2205 | | m48t08.nvram[0x1ffa] = (data >> 8) & 0x7f; |
| 2206 | | } |
| 2207 | | break; |
| 2208 | | case 0x1ffb: |
| 2209 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2210 | | { |
| 2211 | | m48t08.nvram[0x1ffb] = (data >> 8) & 0x003f; |
| 2212 | | } |
| 2213 | | break; |
| 2214 | | case 0x1ffc: |
| 2215 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2216 | | { |
| 2217 | | m48t08.nvram[0x1ffc] = (data >> 8) & 0x0047; |
| 2218 | | } |
| 2219 | | break; |
| 2220 | | case 0x1ffd: |
| 2221 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2222 | | { |
| 2223 | | m48t08.nvram[0x1ffd] = (data >> 8) & 0x003f; |
| 2224 | | } |
| 2225 | | break; |
| 2226 | | case 0x1ffe: |
| 2227 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2228 | | { |
| 2229 | | m48t08.nvram[0x1ffe] = (data >> 8) & 0x001f; |
| 2230 | | } |
| 2231 | | break; |
| 2232 | | case 0x1fff: |
| 2233 | | if(m48t08.nvram[0x1ff8] & 0x80) |
| 2234 | | { |
| 2235 | | m48t08.nvram[0x1fff] = (data >> 8) & 0x00ff; |
| 2236 | | } |
| 2237 | | break; |
| 2238 | | default: |
| 2239 | | m48t08.nvram[offset] = (data & mem_mask) >> 8; |
| 2240 | | break; |
| 2241 | | } |
| 2242 | | } |
| 2243 | | |
| 2244 | 2307 | /************************* |
| 2245 | 2308 | * Video Hardware * |
| 2246 | 2309 | *************************/ |
| r6190 | r6191 | |
| 2411 | 2474 | } |
| 2412 | 2475 | } |
| 2413 | 2476 | } |
| 2414 | | for(x = 8*24; x < 768; x++) |
| 2477 | for(x = 8*24; x < 384; x++) |
| 2415 | 2478 | { |
| 2416 | 2479 | scanline[x] = 0; |
| 2417 | 2480 | } |
| r6190 | r6191 | |
| 3517 | 3580 | { |
| 3518 | 3581 | if(mcd212.channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2)))) |
| 3519 | 3582 | { |
| 3520 | | scanline[x++] = color; |
| 3521 | | scanline[x++] = color; |
| 3522 | | scanline[x++] = color; |
| 3523 | | scanline[x] = color; |
| 3583 | scanline[(x++)/2] = color; |
| 3584 | scanline[(x++)/2] = color; |
| 3585 | scanline[(x++)/2] = color; |
| 3586 | scanline[(x/2)] = color; |
| 3524 | 3587 | } |
| 3525 | 3588 | else |
| 3526 | 3589 | { |
| r6190 | r6191 | |
| 3533 | 3596 | { |
| 3534 | 3597 | if(mcd212.channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1)))) |
| 3535 | 3598 | { |
| 3536 | | scanline[x++] = color; |
| 3537 | | scanline[x] = color; |
| 3599 | scanline[(x++)/2] = color; |
| 3600 | scanline[x/2] = color; |
| 3538 | 3601 | } |
| 3539 | 3602 | else |
| 3540 | 3603 | { |
| r6190 | r6191 | |
| 3715 | 3778 | mcd212_process_vsr(machine, 0, plane_a_r, plane_a_g, plane_a_b); |
| 3716 | 3779 | mcd212_process_vsr(machine, 1, plane_b_r, plane_b_g, plane_b_b); |
| 3717 | 3780 | mcd212_mix_lines(machine, plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out); |
| 3718 | | for(x = 0; x < 768; x++) |
| 3781 | for(x = 0; x < 384; x++) |
| 3719 | 3782 | { |
| 3720 | | scanline[x] = out[x]; |
| 3783 | scanline[x] = out[x*2]; |
| 3784 | //scanline[x] = (plane_a_r[x*2] << 16) | (plane_a_g[x*2] << 8) | plane_a_b[x*2]; |
| 3785 | //scanline[x+384] = (plane_b_r[x*2] << 16) | (plane_b_g[x*2] << 8) | plane_b_b[x*2]; |
| 3721 | 3786 | } |
| 3722 | 3787 | mcd212_draw_cursor(machine, scanline, y); |
| 3723 | 3788 | } |
| r6190 | r6191 | |
| 3812 | 3877 | mcd212.channel[0].clut_bank = 0; |
| 3813 | 3878 | mcd212.channel[1].clut_bank = 0; |
| 3814 | 3879 | mcd212.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0); |
| 3815 | | timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 22, 0), 0); |
| 3880 | timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 3816 | 3881 | } |
| 3817 | 3882 | |
| 3818 | 3883 | static TIMER_CALLBACK( test_timer_callback ) |
| r6190 | r6191 | |
| 3861 | 3926 | AM_RANGE(0x00303c00, 0x00303fff) AM_READWRITE(cdic_r, cdic_w) |
| 3862 | 3927 | AM_RANGE(0x00310000, 0x00317fff) AM_READWRITE(slave_r, slave_w) |
| 3863 | 3928 | //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP |
| 3864 | | AM_RANGE(0x00320000, 0x00323fff) AM_READWRITE(m48t08_r, m48t08_w) AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size) |
| 3929 | AM_RANGE(0x00320000, 0x00323fff) AM_DEVREADWRITE8("mk48t08", timekeeper_r, timekeeper_w, 0xff00) /* nvram (only low bytes used) */ |
| 3865 | 3930 | AM_RANGE(0x00400000, 0x0047ffff) AM_ROM AM_REGION("maincpu", 0) |
| 3866 | 3931 | AM_RANGE(0x004fffe0, 0x004fffff) AM_READWRITE(mcd212_r, mcd212_w) |
| 3867 | 3932 | AM_RANGE(0x00500000, 0x0057ffff) AM_RAM |
| 3868 | 3933 | AM_RANGE(0x00580000, 0x00ffffff) AM_NOP |
| 3934 | AM_RANGE(0x00e00000, 0x00efffff) AM_RAM // DVC |
| 3869 | 3935 | AM_RANGE(0x80000000, 0x8000807f) AM_READWRITE(scc68070_periphs_r, scc68070_periphs_w) |
| 3870 | 3936 | ADDRESS_MAP_END |
| 3871 | 3937 | |
| r6190 | r6191 | |
| 3883 | 3949 | PORT_START("MOUSEBTN") |
| 3884 | 3950 | PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_NAME("Mouse Button 1") PORT_CHANGED(mouse_update, 0) |
| 3885 | 3951 | PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_NAME("Mouse Button 2") PORT_CHANGED(mouse_update, 0) |
| 3886 | | PORT_BIT(0xfc, IP_ACTIVE_HIGH, IPT_UNUSED) |
| 3952 | PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_CODE(MOUSECODE_BUTTON3) PORT_NAME("Mouse Button 3") PORT_CHANGED(mouse_update, 0) |
| 3953 | PORT_BIT(0xf8, IP_ACTIVE_HIGH, IPT_UNUSED) |
| 3887 | 3954 | INPUT_PORTS_END |
| 3888 | 3955 | |
| 3889 | 3956 | static MACHINE_RESET( cdi ) |
| r6190 | r6191 | |
| 3919 | 3986 | if( cdrom_dev ) |
| 3920 | 3987 | { |
| 3921 | 3988 | cdic_regs.cd = mess_cd_get_cdrom_file(cdrom_dev); |
| 3989 | cdda_set_cdrom(devtag_get_device(machine, "cdda"), cdic_regs.cd); |
| 3922 | 3990 | } |
| 3923 | 3991 | |
| 3924 | 3992 | device_reset(cputag_get_cpu(machine, "maincpu")); |
| r6190 | r6191 | |
| 3946 | 4014 | MDRV_SCREEN_REFRESH_RATE(60) |
| 3947 | 4015 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 3948 | 4016 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 3949 | | MDRV_SCREEN_SIZE(768, 262) |
| 3950 | | MDRV_SCREEN_VISIBLE_AREA(0, 768-1, 22, 262-1) //dynamic resolution,TODO |
| 4017 | MDRV_SCREEN_SIZE(384, 262) |
| 4018 | MDRV_SCREEN_VISIBLE_AREA(0, 384-1, 0, 262-1) //dynamic resolution,TODO |
| 3951 | 4019 | |
| 3952 | 4020 | MDRV_PALETTE_LENGTH(0x100) |
| 3953 | 4021 | |
| 3954 | | MDRV_NVRAM_HANDLER(generic_0fill) |
| 3955 | 4022 | MDRV_VIDEO_START(cdi) |
| 3956 | 4023 | MDRV_VIDEO_UPDATE(generic_bitmapped) |
| 3957 | 4024 | |
| r6190 | r6191 | |
| 3962 | 4029 | /* sound hardware */ |
| 3963 | 4030 | MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 3964 | 4031 | |
| 3965 | | MDRV_SOUND_ADD("dac1", DMADAC, 0) |
| 3966 | | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.0) |
| 4032 | MDRV_SOUND_ADD( "dac1", DMADAC, 0 ) |
| 4033 | MDRV_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 1.0 ) |
| 3967 | 4034 | |
| 3968 | | MDRV_SOUND_ADD("dac2", DMADAC, 0) |
| 3969 | | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0) |
| 4035 | MDRV_SOUND_ADD( "dac2", DMADAC, 0 ) |
| 4036 | MDRV_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 1.0 ) |
| 4037 | |
| 4038 | MDRV_SOUND_ADD( "cdda", CDDA, 0 ) |
| 4039 | MDRV_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 1.0 ) |
| 4040 | MDRV_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 1.0 ) |
| 4041 | |
| 4042 | MDRV_MK48T08_ADD( "mk48t08" ) |
| 3970 | 4043 | MACHINE_DRIVER_END |
| 3971 | 4044 | |
| 3972 | 4045 | /************************* |