Previous 15994 Revisions Next

r6539 Friday 4th December, 2009 at 22:39:05 UTC by Barry Rodewald
[FMTOWNS] Basic implementation of CD-DA stop, play and info commands.
[src/mess/drivers]fmtowns.c

src/mess/drivers/fmtowns.c
r6538r6539
184184   INT32 buffer_ptr;
185185   UINT32 lba_current;
186186   UINT32 lba_last;
187   UINT32 cdda_current;
188   UINT32 cdda_length;
187189   emu_timer* read_timer;
188190} towns_cd;
189191
190192static void towns_update_video_banks(const address_space* space);
191193static PIC8259_SET_INT_LINE( towns_pic_irq );
192194
193INLINE UINT32 bcd_to_dec(UINT32 val)
195INLINE UINT8 byte_to_bcd(UINT8 val)
194196{
195   return (val & 0x00000f) +
196      (((val & 0x0000f0) >> 4) * 10) +
197      (((val & 0x000f00) >> 8) * 100) +
198      (((val & 0x00f000) >> 12) * 1000) +
199      (((val & 0x0f0000) >> 16) * 10000) +
200      (((val & 0xf00000) >> 24) * 100000);
197   return ((val / 10) << 4) | (val % 10);
201198}
202199
203INLINE UINT8 byte_to_bcd(UINT8 val)
200INLINE UINT8 bcd_to_byte(UINT8 val)
204201{
205   return ((val / 10) << 4) | (val % 10);
202   return (((val & 0xf0) >> 4) * 10) + (val & 0x0f);
206203}
207204
208INLINE UINT32 dword_to_bcd(UINT32 val)
205INLINE UINT32 msf_to_lba(UINT32 val)  // because the CDROM core doesn't provide this
209206{
210   return (((val / 100000) % 10) << 20) |
211      (((val / 10000) % 10) << 16) |
212      (((val / 1000) % 10) << 12) |
213      (((val / 100) % 10) << 8) |
214      (((val / 10) % 10) << 4) |
215      (val % 10);
207   UINT8 m,s,f;
208   f = bcd_to_byte(val & 0x0000ff);
209   s = (bcd_to_byte((val & 0x00ff00) >> 8));
210   m = (bcd_to_byte((val & 0xff0000) >> 16));
211   return (m * (60 * 75)) + (s * 75) + f;   
216212}
217213
218214static void towns_init_serial_rom(running_machine* machine)
r6538r6539
357353
358354static WRITE8_HANDLER(towns_sys6c_w)
359355{
360   logerror("SYS: (0x6c) write to timer (0x%02x)\n",data);
356//   logerror("SYS: (0x6c) write to timer (0x%02x)\n",data);
361357   ftimer -= 0x54;
362358}
363359
r6538r6539
12441240   }
12451241}
12461242
1243static UINT8 towns_cd_get_track(running_machine* machine)
1244{
1245   const device_config* cdrom = devtag_get_device(machine,"cdrom");
1246   const device_config* cdda = devtag_get_device(machine,"cdda");
1247   UINT32 lba = cdda_get_audio_lba(cdda);
1248   UINT8 track;
1249   
1250   for(track=1;track<99;track++)
1251   {
1252      if(cdrom_get_track_start(mess_cd_get_cdrom_file(cdrom),track) > lba)
1253         break;
1254   }
1255   return track;
1256}
1257
12471258static TIMER_CALLBACK( towns_cdrom_read_byte )
12481259{
12491260   const device_config* device = ptr;
r6538r6539
13081319{
13091320   // MODE 1 read
13101321   // load data into buffer to be sent via DMA1 channel 3
1322   // A set of status bytes is sent after each sector, and DMA is paused
1323   // so that the DMA controller than be set up again.
1324   // parameters:
1325   //          3 bytes: MSF of first sector to read
1326   //          3 bytes: MSF of last sector to read
13111327   UINT32 lba1,lba2;
13121328   
13131329   lba1 = towns_cd.parameter[7] << 16;
r6538r6539
13161332   lba2 = towns_cd.parameter[4] << 16;
13171333   lba2 += towns_cd.parameter[3] << 8;
13181334   lba2 += towns_cd.parameter[2];
1319   towns_cd.lba_current = bcd_to_dec(lba1) - 200;
1320   towns_cd.lba_last = bcd_to_dec(lba2) - 200;
1335   towns_cd.lba_current = msf_to_lba(lba1-0x200);
1336   towns_cd.lba_last = msf_to_lba(lba2-0x200);
13211337   
13221338   logerror("CD: Mode 1 read from LBA next:%i last:%i\n",towns_cd.lba_current,towns_cd.lba_last);
13231339
r6538r6539
13511367   //timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
13521368}
13531369
1370static void towns_cdrom_play_cdda(const device_config* device)
1371{
1372   // PLAY AUDIO
1373   // Plays CD-DA audio from the specified MSF
1374   // Parameters:
1375   //          3 bytes: starting MSF of audio to play
1376   //          3 bytes: ending MSF of audio to play (can span multiple tracks)
1377   UINT32 lba1,lba2;
1378   const device_config* cdda = devtag_get_device(device->machine,"cdda");
1379   
1380   lba1 = towns_cd.parameter[7] << 16;
1381   lba1 += towns_cd.parameter[6] << 8;
1382   lba1 += towns_cd.parameter[5];
1383   lba2 = towns_cd.parameter[4] << 16;
1384   lba2 += towns_cd.parameter[3] << 8;
1385   lba2 += towns_cd.parameter[2];
1386   towns_cd.cdda_current = msf_to_lba(lba1);
1387   towns_cd.cdda_length = msf_to_lba(lba2) - towns_cd.cdda_current;
1388   
1389   cdda_set_cdrom(cdda,mess_cd_get_cdrom_file(device));
1390   cdda_start_audio(cdda,towns_cd.cdda_current,towns_cd.cdda_length);
1391   logerror("CD: CD-DA start from LBA:%i length:%i\n",towns_cd.cdda_current,towns_cd.cdda_length);
1392   
1393   towns_cd.status |= 0x03;
1394   towns_cd.extra_status = 1;
1395   towns_cd.cmd_status[0] = 0x00;
1396   towns_cd.cmd_status[1] = 0x00;
1397   towns_cd.cmd_status[2] = 0x00;
1398   towns_cd.cmd_status[3] = 0x00;
1399   towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
1400   
1401}
1402
13541403static void towns_cdrom_execute_command(const device_config* device)
13551404{
1356   // For now, we'll return status codes that hopefully tell the system
1357   // that there is no CD-ROM in the drive.
1358
13591405   if(mess_cd_get_cdrom_file(device) == NULL)
13601406   {  // No CD in drive
13611407      if(towns_cd.command & 0x20)
r6538r6539
13921438            logerror("CD: Command 0x02: READ MODE1\n");
13931439            towns_cdrom_read(device);
13941440            break;
1441         case 0x04:  // Play Audio Track
1442            logerror("CD: Command 0x04: PLAY CD-DA\n");
1443            towns_cdrom_play_cdda(device);
1444            break;
13951445         case 0x05:  // Read TOC
13961446            logerror("CD: Command 0x05: READ TOC\n");
1397               towns_cd.status |= 0x02;  // status read request
1398               towns_cd.cmd_status_ptr = 0;
1399               towns_cd.extra_status = 1;
1400               towns_cd.cmd_status[0] = 0x00;
1401               towns_cd.cmd_status[1] = 0x00;
1402               towns_cd.cmd_status[2] = 0x00;
1403               towns_cd.cmd_status[3] = 0x00;
1404               towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
1447            towns_cd.status |= 0x02;  // status read request
1448            towns_cd.cmd_status_ptr = 0;
1449            towns_cd.extra_status = 1;
1450            towns_cd.cmd_status[0] = 0x00;
1451            towns_cd.cmd_status[1] = 0x00;
1452            towns_cd.cmd_status[2] = 0x00;
1453            towns_cd.cmd_status[3] = 0x00;
1454            towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
14051455            break;
1456         case 0x06:  // Read CD-DA state?
1457            logerror("CD: Command 0x06: READ CD-DA STATE\n");
1458            towns_cd.status |= 0x02;  // status read request
1459            towns_cd.cmd_status_ptr = 0;
1460            towns_cd.extra_status = 1;
1461            towns_cd.cmd_status[0] = 0x00;
1462            towns_cd.cmd_status[1] = 0x00;
1463            towns_cd.cmd_status[2] = 0x00;
1464            towns_cd.cmd_status[3] = 0x00;
1465            towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
1466            break;
14061467         case 0x80:  // set state
14071468            if(towns_cd.command & 0x20)
14081469            {
r6538r6539
14101471               towns_cd.cmd_status_ptr = 0;
14111472               towns_cd.extra_status = 0;
14121473               towns_cd.cmd_status[0] = 0x00;
1413               towns_cd.cmd_status[1] = 0x01; // CD-ROM/CD-DA status?  bit 1 = error type(HE or CDR)
1474               towns_cd.cmd_status[1] = 0x01;
14141475               towns_cd.cmd_status[2] = 0x00;
14151476               towns_cd.cmd_status[3] = 0x00;
1477               if(cdda_audio_active(devtag_get_device(device->machine,"cdda")))
1478               {
1479                  towns_cd.cmd_status[0] = 0x00;
1480                  towns_cd.cmd_status[1] |= 0x02;
1481               }
14161482               towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
14171483            }
14181484            logerror("CD: Command 0x80: set state\n");
r6538r6539
14311497            }
14321498            logerror("CD: Command 0x81: set state (CDDASET)\n");
14331499            break;
1434         case 0x84:   // Stop audio track (?)
1500         case 0x84:   // Unknown (status?)
14351501            if(towns_cd.command & 0x20)
14361502            {
14371503               towns_cd.status |= 0x02;  // status read request
14381504               towns_cd.cmd_status_ptr = 0;
1439               towns_cd.extra_status = 0;
1505               towns_cd.extra_status = 1;
14401506               towns_cd.cmd_status[0] = 0x00;
14411507               towns_cd.cmd_status[1] = 0x00;
14421508               towns_cd.cmd_status[2] = 0x00;
14431509               towns_cd.cmd_status[3] = 0x00;
1510               cdda_stop_audio(devtag_get_device(device->machine,"cdda"));
14441511               towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1);
14451512            }
1446            logerror("CD: Command 0x84: Stop audio track(?)\n");
1513            logerror("CD: Command 0x84: STOP CD-DA\n");
14471514            break;
14481515         default:
14491516            towns_cd.status |= 0x02;  // status read request
r6538r6539
14701537{
14711538   UINT32 addr = 0;
14721539   UINT8 ret = 0;
1540
1541   ret = towns_cd.cmd_status[towns_cd.cmd_status_ptr];
1542
14731543   switch(offset)
14741544   {
14751545      case 0x00:  // status
r6538r6539
15041574                     towns_cd.cmd_status[3] = 0x00;
15051575                     towns_cd.extra_status = 0;
15061576                     break;
1577                  case 0x04:  // play cdda
1578                     towns_cd.cmd_status[0] = 0x07;
1579                     towns_cd.cmd_status[1] = 0x00;
1580                     towns_cd.cmd_status[2] = 0x00;
1581                     towns_cd.cmd_status[3] = 0x00;
1582                     towns_cd.extra_status = 0;
1583                     break;
15071584                  case 0x05:  // read toc
15081585                     switch(towns_cd.extra_status)
15091586                     {
r6538r6539
15731650                           break;
15741651                     }
15751652                     break;
1653                  case 0x06:  // read CD-DA state
1654                     switch(towns_cd.extra_status)
1655                     {
1656                        case 1:  // st2 = track number
1657                           towns_cd.cmd_status[0] = 0x18;
1658                           towns_cd.cmd_status[1] = 0x00;
1659                           towns_cd.cmd_status[2] = towns_cd_get_track(space->machine);  // track number
1660                           towns_cd.cmd_status[3] = 0x00;
1661                           towns_cd.extra_status++;
1662                           break;
1663                        case 2:  // st0/1/2 = MSF from beginning of current track
1664                           addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda"));
1665                           addr = lba_to_msf(addr - towns_cd.cdda_current); 
1666                           towns_cd.cmd_status[0] = 0x19;
1667                           towns_cd.cmd_status[1] = (addr & 0xff0000) >> 16;
1668                           towns_cd.cmd_status[2] = (addr & 0x00ff00) >> 8;
1669                           towns_cd.cmd_status[3] = addr & 0x0000ff;
1670                           towns_cd.extra_status++;
1671                           break;
1672                        case 3:  // st1/2 = current MSF
1673                           addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda"));
1674                           addr = lba_to_msf(addr);  // this data is incorrect, but will do until exact meaning is found
1675                           towns_cd.cmd_status[0] = 0x19;
1676                           towns_cd.cmd_status[1] = 0;
1677                           towns_cd.cmd_status[2] = (addr & 0xff0000) >> 16;
1678                           towns_cd.cmd_status[3] = (addr & 0x00ff00) >> 8;
1679                           towns_cd.extra_status++;
1680                           break;
1681                        case 4:
1682                           addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda"));
1683                           addr = lba_to_msf(addr);  // this data is incorrect, but will do until exact meaning is found
1684                           towns_cd.cmd_status[0] = 0x20;
1685                           towns_cd.cmd_status[1] = addr & 0x0000ff;
1686                           towns_cd.cmd_status[2] = 0x00;
1687                           towns_cd.cmd_status[3] = 0x00;
1688                           towns_cd.extra_status = 0;
1689                           break;
1690                     }
1691                     break;
15761692                  case 0x84:
1577                     towns_cd.cmd_status[0] = 0x07;
1693                     towns_cd.cmd_status[0] = 0x11;
15781694                     towns_cd.cmd_status[1] = 0x00;
15791695                     towns_cd.cmd_status[2] = 0x00;
15801696                     towns_cd.cmd_status[3] = 0x00;
r6538r6539
15831699               }
15841700            }
15851701         }
1586         logerror("CD: reading command status port, returning %02x\n",towns_cd.cmd_status[towns_cd.cmd_status_ptr]);
1587         ret = towns_cd.cmd_status[towns_cd.cmd_status_ptr++];
1702         logerror("CD: reading command status port, returning %02x\n",ret);
1703         towns_cd.cmd_status_ptr++;
15881704         if(towns_cd.cmd_status_ptr > 3)
15891705            towns_cd.cmd_status_ptr = 0;
15901706         return ret;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team