Previous 15994 Revisions Next

r6191 Tuesday 27th October, 2009 at 00:36:18 UTC by Harmony
[CDI] Added CDDA support. [Harmony]
[src/mess/drivers]cdi.c

src/mess/drivers/cdi.c
r6190r6191
3434#include "cpu/m68000/m68000.h"
3535#include "sound/dmadac.h"
3636#include "devices/chd_cd.h"
37#include "machine/timekpr.h"
38#include "sound/cdda.h"
3739
3840static UINT16 *planea;
3941static UINT16 *planeb;
r6190r6191
4547
4648#define ENABLE_UART_PRINTING (0)
4749
48#define VERBOSE_LEVEL   (0)
50#define VERBOSE_LEVEL   (5)
4951
5052#define ENABLE_VERBOSE_LOG (0)
5153
r6190r6191
8890static READ16_HANDLER( slave_r );
8991static WRITE16_HANDLER( slave_w );
9092
91// RTC
92static READ16_HANDLER( m48t08_r );
93static WRITE16_HANDLER( m48t08_w );
94
9593// Platform-specific
9694static void cdi220_draw_lcd(running_machine *machine, int y);
9795
r6190r6191
13801378   }
13811379   else
13821380   {
1381      // Swap buffer positions to indicate our new buffer position at the next read
1382      cdic_regs.z_buffer ^= 0x1a00;
13831383      verboselog(machine, 0, "Data is not valid, stopping playback\n" );
13841384      timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0);
13851385   }
13861386}
13871387
1388static 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
13881418static TIMER_CALLBACK( cdic_trigger_readback_int )
13891419{
13901420   switch(cdic_regs.command)
r6190r6191
15631593      case 0x2e: // Abort
15641594         timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed
15651595         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      }
15661692   }
15671693}
15681694
r6190r6191
17401866         COMBINE_DATA(&cdic_regs.z_buffer);
17411867         if(cdic_regs.z_buffer & 0x2000)
17421868         {
1743            attotime period = timer_timeleft(cdic_regs.audio_sample_timer);
1869            attotime period = timer_timeleft(cdic_regs.interrupt_timer);
17441870            if(!attotime_is_never(period))
17451871            {
17461872               timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0);
r6190r6191
17781904               case 0x2a: // Read Mode 2
17791905                  timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed
17801906                  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;
17811915               case 0x2c: // Seek
1782                  if(cdic_regs.time & 0x00008000)
1783                  {
1784                     cdic_regs.time &= 0xffff0000;
1785                  }
17861916                  break;
17871917               default:
17881918                  verboselog(space->machine, 0, "Unknown CDIC command: %02x\n", cdic_regs.command );
r6190r6191
21742304   }
21752305}
21762306
2177typedef struct
2178{
2179   UINT8 nvram[0x2000];
2180   emu_timer *clock;
2181} m48t08_regs_t;
2182
2183static m48t08_regs_t m48t08;
2184
2185static 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
2191static 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
22442307/*************************
22452308*     Video Hardware     *
22462309*************************/
r6190r6191
24112474         }
24122475      }
24132476   }
2414   for(x = 8*24; x < 768; x++)
2477   for(x = 8*24; x < 384; x++)
24152478   {
24162479      scanline[x] = 0;
24172480   }
r6190r6191
35173580            {
35183581               if(mcd212.channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2))))
35193582               {
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;
35243587               }
35253588               else
35263589               {
r6190r6191
35333596            {
35343597               if(mcd212.channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1))))
35353598               {
3536                  scanline[x++] = color;
3537                  scanline[x] = color;
3599                  scanline[(x++)/2] = color;
3600                  scanline[x/2] = color;
35383601               }
35393602               else
35403603               {
r6190r6191
37153778   mcd212_process_vsr(machine, 0, plane_a_r, plane_a_g, plane_a_b);
37163779   mcd212_process_vsr(machine, 1, plane_b_r, plane_b_g, plane_b_b);
37173780   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++)
37193782   {
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];
37213786   }
37223787   mcd212_draw_cursor(machine, scanline, y);
37233788}
r6190r6191
38123877   mcd212.channel[0].clut_bank = 0;
38133878   mcd212.channel[1].clut_bank = 0;
38143879   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);
38163881}
38173882
38183883static TIMER_CALLBACK( test_timer_callback )
r6190r6191
38613926   AM_RANGE(0x00303c00, 0x00303fff) AM_READWRITE(cdic_r, cdic_w)
38623927   AM_RANGE(0x00310000, 0x00317fff) AM_READWRITE(slave_r, slave_w)
38633928   //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) */
38653930   AM_RANGE(0x00400000, 0x0047ffff) AM_ROM AM_REGION("maincpu", 0)
38663931   AM_RANGE(0x004fffe0, 0x004fffff) AM_READWRITE(mcd212_r, mcd212_w)
38673932   AM_RANGE(0x00500000, 0x0057ffff) AM_RAM
38683933   AM_RANGE(0x00580000, 0x00ffffff) AM_NOP
3934   AM_RANGE(0x00e00000, 0x00efffff) AM_RAM // DVC
38693935   AM_RANGE(0x80000000, 0x8000807f) AM_READWRITE(scc68070_periphs_r, scc68070_periphs_w)
38703936ADDRESS_MAP_END
38713937
r6190r6191
38833949   PORT_START("MOUSEBTN")
38843950   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_NAME("Mouse Button 1") PORT_CHANGED(mouse_update, 0)
38853951   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)
38873954INPUT_PORTS_END
38883955
38893956static MACHINE_RESET( cdi )
r6190r6191
39193986   if( cdrom_dev )
39203987   {
39213988      cdic_regs.cd = mess_cd_get_cdrom_file(cdrom_dev);
3989      cdda_set_cdrom(devtag_get_device(machine, "cdda"), cdic_regs.cd);
39223990   }
39233991
39243992   device_reset(cputag_get_cpu(machine, "maincpu"));
r6190r6191
39464014   MDRV_SCREEN_REFRESH_RATE(60)
39474015   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
39484016   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
39514019
39524020   MDRV_PALETTE_LENGTH(0x100)
39534021
3954   MDRV_NVRAM_HANDLER(generic_0fill)
39554022   MDRV_VIDEO_START(cdi)
39564023   MDRV_VIDEO_UPDATE(generic_bitmapped)
39574024
r6190r6191
39624029   /* sound hardware */
39634030   MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
39644031
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 )
39674034
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" )
39704043MACHINE_DRIVER_END
39714044
39724045/*************************

Previous 15994 Revisions Next


© 1998-2018 The MESS Team