src/mess/drivers/fmtowns.c
| r6538 | r6539 | |
| 184 | 184 | INT32 buffer_ptr; |
| 185 | 185 | UINT32 lba_current; |
| 186 | 186 | UINT32 lba_last; |
| 187 | UINT32 cdda_current; |
| 188 | UINT32 cdda_length; |
| 187 | 189 | emu_timer* read_timer; |
| 188 | 190 | } towns_cd; |
| 189 | 191 | |
| 190 | 192 | static void towns_update_video_banks(const address_space* space); |
| 191 | 193 | static PIC8259_SET_INT_LINE( towns_pic_irq ); |
| 192 | 194 | |
| 193 | | INLINE UINT32 bcd_to_dec(UINT32 val) |
| 195 | INLINE UINT8 byte_to_bcd(UINT8 val) |
| 194 | 196 | { |
| 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); |
| 201 | 198 | } |
| 202 | 199 | |
| 203 | | INLINE UINT8 byte_to_bcd(UINT8 val) |
| 200 | INLINE UINT8 bcd_to_byte(UINT8 val) |
| 204 | 201 | { |
| 205 | | return ((val / 10) << 4) | (val % 10); |
| 202 | return (((val & 0xf0) >> 4) * 10) + (val & 0x0f); |
| 206 | 203 | } |
| 207 | 204 | |
| 208 | | INLINE UINT32 dword_to_bcd(UINT32 val) |
| 205 | INLINE UINT32 msf_to_lba(UINT32 val) // because the CDROM core doesn't provide this |
| 209 | 206 | { |
| 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; |
| 216 | 212 | } |
| 217 | 213 | |
| 218 | 214 | static void towns_init_serial_rom(running_machine* machine) |
| r6538 | r6539 | |
| 357 | 353 | |
| 358 | 354 | static WRITE8_HANDLER(towns_sys6c_w) |
| 359 | 355 | { |
| 360 | | logerror("SYS: (0x6c) write to timer (0x%02x)\n",data); |
| 356 | // logerror("SYS: (0x6c) write to timer (0x%02x)\n",data); |
| 361 | 357 | ftimer -= 0x54; |
| 362 | 358 | } |
| 363 | 359 | |
| r6538 | r6539 | |
| 1244 | 1240 | } |
| 1245 | 1241 | } |
| 1246 | 1242 | |
| 1243 | static 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 | |
| 1247 | 1258 | static TIMER_CALLBACK( towns_cdrom_read_byte ) |
| 1248 | 1259 | { |
| 1249 | 1260 | const device_config* device = ptr; |
| r6538 | r6539 | |
| 1308 | 1319 | { |
| 1309 | 1320 | // MODE 1 read |
| 1310 | 1321 | // 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 |
| 1311 | 1327 | UINT32 lba1,lba2; |
| 1312 | 1328 | |
| 1313 | 1329 | lba1 = towns_cd.parameter[7] << 16; |
| r6538 | r6539 | |
| 1316 | 1332 | lba2 = towns_cd.parameter[4] << 16; |
| 1317 | 1333 | lba2 += towns_cd.parameter[3] << 8; |
| 1318 | 1334 | 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); |
| 1321 | 1337 | |
| 1322 | 1338 | logerror("CD: Mode 1 read from LBA next:%i last:%i\n",towns_cd.lba_current,towns_cd.lba_last); |
| 1323 | 1339 | |
| r6538 | r6539 | |
| 1351 | 1367 | //timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1352 | 1368 | } |
| 1353 | 1369 | |
| 1370 | static 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 | |
| 1354 | 1403 | static void towns_cdrom_execute_command(const device_config* device) |
| 1355 | 1404 | { |
| 1356 | | // For now, we'll return status codes that hopefully tell the system |
| 1357 | | // that there is no CD-ROM in the drive. |
| 1358 | | |
| 1359 | 1405 | if(mess_cd_get_cdrom_file(device) == NULL) |
| 1360 | 1406 | { // No CD in drive |
| 1361 | 1407 | if(towns_cd.command & 0x20) |
| r6538 | r6539 | |
| 1392 | 1438 | logerror("CD: Command 0x02: READ MODE1\n"); |
| 1393 | 1439 | towns_cdrom_read(device); |
| 1394 | 1440 | break; |
| 1441 | case 0x04: // Play Audio Track |
| 1442 | logerror("CD: Command 0x04: PLAY CD-DA\n"); |
| 1443 | towns_cdrom_play_cdda(device); |
| 1444 | break; |
| 1395 | 1445 | case 0x05: // Read TOC |
| 1396 | 1446 | 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); |
| 1405 | 1455 | 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; |
| 1406 | 1467 | case 0x80: // set state |
| 1407 | 1468 | if(towns_cd.command & 0x20) |
| 1408 | 1469 | { |
| r6538 | r6539 | |
| 1410 | 1471 | towns_cd.cmd_status_ptr = 0; |
| 1411 | 1472 | towns_cd.extra_status = 0; |
| 1412 | 1473 | 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; |
| 1414 | 1475 | towns_cd.cmd_status[2] = 0x00; |
| 1415 | 1476 | 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 | } |
| 1416 | 1482 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1417 | 1483 | } |
| 1418 | 1484 | logerror("CD: Command 0x80: set state\n"); |
| r6538 | r6539 | |
| 1431 | 1497 | } |
| 1432 | 1498 | logerror("CD: Command 0x81: set state (CDDASET)\n"); |
| 1433 | 1499 | break; |
| 1434 | | case 0x84: // Stop audio track (?) |
| 1500 | case 0x84: // Unknown (status?) |
| 1435 | 1501 | if(towns_cd.command & 0x20) |
| 1436 | 1502 | { |
| 1437 | 1503 | towns_cd.status |= 0x02; // status read request |
| 1438 | 1504 | towns_cd.cmd_status_ptr = 0; |
| 1439 | | towns_cd.extra_status = 0; |
| 1505 | towns_cd.extra_status = 1; |
| 1440 | 1506 | towns_cd.cmd_status[0] = 0x00; |
| 1441 | 1507 | towns_cd.cmd_status[1] = 0x00; |
| 1442 | 1508 | towns_cd.cmd_status[2] = 0x00; |
| 1443 | 1509 | towns_cd.cmd_status[3] = 0x00; |
| 1510 | cdda_stop_audio(devtag_get_device(device->machine,"cdda")); |
| 1444 | 1511 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1445 | 1512 | } |
| 1446 | | logerror("CD: Command 0x84: Stop audio track(?)\n"); |
| 1513 | logerror("CD: Command 0x84: STOP CD-DA\n"); |
| 1447 | 1514 | break; |
| 1448 | 1515 | default: |
| 1449 | 1516 | towns_cd.status |= 0x02; // status read request |
| r6538 | r6539 | |
| 1470 | 1537 | { |
| 1471 | 1538 | UINT32 addr = 0; |
| 1472 | 1539 | UINT8 ret = 0; |
| 1540 | |
| 1541 | ret = towns_cd.cmd_status[towns_cd.cmd_status_ptr]; |
| 1542 | |
| 1473 | 1543 | switch(offset) |
| 1474 | 1544 | { |
| 1475 | 1545 | case 0x00: // status |
| r6538 | r6539 | |
| 1504 | 1574 | towns_cd.cmd_status[3] = 0x00; |
| 1505 | 1575 | towns_cd.extra_status = 0; |
| 1506 | 1576 | 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; |
| 1507 | 1584 | case 0x05: // read toc |
| 1508 | 1585 | switch(towns_cd.extra_status) |
| 1509 | 1586 | { |
| r6538 | r6539 | |
| 1573 | 1650 | break; |
| 1574 | 1651 | } |
| 1575 | 1652 | 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; |
| 1576 | 1692 | case 0x84: |
| 1577 | | towns_cd.cmd_status[0] = 0x07; |
| 1693 | towns_cd.cmd_status[0] = 0x11; |
| 1578 | 1694 | towns_cd.cmd_status[1] = 0x00; |
| 1579 | 1695 | towns_cd.cmd_status[2] = 0x00; |
| 1580 | 1696 | towns_cd.cmd_status[3] = 0x00; |
| r6538 | r6539 | |
| 1583 | 1699 | } |
| 1584 | 1700 | } |
| 1585 | 1701 | } |
| 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++; |
| 1588 | 1704 | if(towns_cd.cmd_status_ptr > 3) |
| 1589 | 1705 | towns_cd.cmd_status_ptr = 0; |
| 1590 | 1706 | return ret; |