src/mess/drivers/cdi.c
| r6228 | r6229 | |
| 36 | 36 | #include "devices/chd_cd.h" |
| 37 | 37 | #include "machine/timekpr.h" |
| 38 | 38 | #include "sound/cdda.h" |
| 39 | #include "cdi.lh" |
| 39 | 40 | |
| 40 | 41 | static UINT16 *planea; |
| 41 | 42 | static UINT16 *planeb; |
| r6228 | r6229 | |
| 44 | 45 | static const device_config *dmadac[2]; |
| 45 | 46 | |
| 46 | 47 | static emu_timer *test_timer; |
| 48 | static bitmap_t* lcdbitmap; |
| 47 | 49 | |
| 48 | 50 | #define ENABLE_UART_PRINTING (0) |
| 49 | 51 | |
| 50 | 52 | #define VERBOSE_LEVEL (5) |
| 51 | 53 | |
| 52 | | #define ENABLE_VERBOSE_LOG (0) |
| 54 | #define ENABLE_VERBOSE_LOG (1) |
| 53 | 55 | |
| 54 | 56 | #if ENABLE_VERBOSE_LOG |
| 55 | 57 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| r6228 | r6229 | |
| 111 | 113 | static void mcd212_draw_scanline(running_machine *machine, int y); |
| 112 | 114 | static TIMER_CALLBACK( mcd212_perform_scan ); |
| 113 | 115 | static VIDEO_START(cdi); |
| 116 | static VIDEO_UPDATE(cdi); |
| 114 | 117 | |
| 115 | 118 | // Miscellaneous |
| 116 | 119 | static TIMER_CALLBACK( test_timer_callback ); |
| r6228 | r6229 | |
| 1224 | 1227 | int bits = 4; |
| 1225 | 1228 | int index = 0; |
| 1226 | 1229 | INT16 samples[18*28*16+16]; |
| 1227 | | //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1230 | FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1228 | 1231 | |
| 1229 | 1232 | //printf( "%02x\n", hdr[2] & 0x3f ); |
| 1230 | 1233 | |
| r6228 | r6229 | |
| 1232 | 1235 | { |
| 1233 | 1236 | // Don't play |
| 1234 | 1237 | //timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1235 | | //fclose(temp_adpcm); |
| 1238 | fclose(temp_adpcm); |
| 1236 | 1239 | return; |
| 1237 | 1240 | } |
| 1238 | 1241 | |
| 1239 | 1242 | verboselog(machine, 0, "cdic_decode_audio_sector, got header type %02x\n", hdr[2] ); |
| 1240 | 1243 | |
| 1241 | | //fseek(temp_adpcm, 0, SEEK_END); |
| 1244 | fseek(temp_adpcm, 0, SEEK_END); |
| 1242 | 1245 | switch(hdr[2] & 0x3f) // ignore emphasis and reserved bits |
| 1243 | 1246 | { |
| 1244 | 1247 | case 0: |
| r6228 | r6229 | |
| 1325 | 1328 | cdic_decode_xa_stereo(hdr + 4, samples); |
| 1326 | 1329 | samples[18*28*8 + 0] = samples[18*28*8 + 2] = samples[18*28*8 + 4] = samples[18*28*8 + 6] = samples[18*28*8 + 8] = samples[18*28*8 + 10] = samples[18*28*8 + 12] = samples[18*28*8 + 14] = samples[18*28*8 - 2]; |
| 1327 | 1330 | samples[18*28*8 + 1] = samples[18*28*8 + 3] = samples[18*28*8 + 5] = samples[18*28*8 + 7] = samples[18*28*8 + 9] = samples[18*28*8 + 11] = samples[18*28*8 + 13] = samples[18*28*8 + 15] = samples[18*28*8 - 1]; |
| 1328 | | //fwrite(samples, 1, 18*28*4*cdic_regs.audio_sample_size, temp_adpcm); |
| 1331 | fwrite(samples, 1, 18*28*4*cdic_regs.audio_sample_size, temp_adpcm); |
| 1329 | 1332 | break; |
| 1330 | 1333 | case 8: |
| 1331 | 1334 | cdic_decode_xa_stereo8(hdr + 4, samples); |
| r6228 | r6229 | |
| 1338 | 1341 | |
| 1339 | 1342 | dmadac_transfer(&dmadac[0], 2, 1, 2, 18*28*2*cdic_regs.audio_sample_size, samples); |
| 1340 | 1343 | |
| 1341 | | //fclose(temp_adpcm); |
| 1344 | fclose(temp_adpcm); |
| 1342 | 1345 | } |
| 1343 | 1346 | |
| 1344 | 1347 | // After an appropriate delay for decoding to take place... |
| 1345 | 1348 | static TIMER_CALLBACK( audio_sample_trigger ) |
| 1346 | 1349 | { |
| 1347 | | if(cdic_regs.z_buffer & 0x2000) |
| 1348 | | { |
| 1349 | | // Indicate that data has been decoded |
| 1350 | | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 1351 | | cdic_regs.audio_buffer |= 0x8000; |
| 1352 | | } |
| 1350 | // Indicate that data has been decoded |
| 1351 | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 1352 | cdic_regs.audio_buffer |= 0x8000; |
| 1353 | 1353 | |
| 1354 | 1354 | // Set the CDIC interrupt line |
| 1355 | 1355 | verboselog(machine, 0, "Setting CDIC interrupt line for soundmap decode\n" ); |
| r6228 | r6229 | |
| 1367 | 1367 | |
| 1368 | 1368 | // Swap buffer positions to indicate our new buffer position at the next read |
| 1369 | 1369 | cdic_regs.z_buffer ^= 0x1a00; |
| 1370 | cdic_regs.data_buffer ^= 0x0001; |
| 1370 | 1371 | |
| 1371 | 1372 | verboselog(machine, 0, "Updated cdic_regs.z_buffer, new value is %04x\n", cdic_regs.z_buffer ); |
| 1372 | 1373 | |
| r6228 | r6229 | |
| 1380 | 1381 | { |
| 1381 | 1382 | // Swap buffer positions to indicate our new buffer position at the next read |
| 1382 | 1383 | cdic_regs.z_buffer ^= 0x1a00; |
| 1384 | cdic_regs.z_buffer &= 0xfffe; |
| 1383 | 1385 | verboselog(machine, 0, "Data is not valid, stopping playback\n" ); |
| 1384 | 1386 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, attotime_never, 0); |
| 1385 | 1387 | } |
| 1386 | 1388 | } |
| 1387 | 1389 | |
| 1388 | | static UINT32 increment_cdda_bcd(UINT32 bcd) |
| 1390 | static UINT32 increment_cdda_frame_bcd(UINT32 bcd) |
| 1389 | 1391 | { |
| 1390 | 1392 | UINT8 nybbles[6] = |
| 1391 | 1393 | { |
| r6228 | r6229 | |
| 1396 | 1398 | (bcd & 0x000f0000) >> 16, |
| 1397 | 1399 | (bcd & 0x00f00000) >> 20 |
| 1398 | 1400 | }; |
| 1401 | nybbles[0]++; |
| 1402 | if(nybbles[0] == 5 && nybbles[1] == 7) |
| 1403 | { |
| 1404 | nybbles[0] = 0; |
| 1405 | nybbles[1] = 0; |
| 1406 | nybbles[2]++; |
| 1407 | } |
| 1408 | else if(nybbles[0] == 10) |
| 1409 | { |
| 1410 | nybbles[1]++; |
| 1411 | } |
| 1412 | if(nybbles[2] == 10) |
| 1413 | { |
| 1414 | nybbles[3]++; |
| 1415 | nybbles[2] = 0; |
| 1416 | } |
| 1417 | if(nybbles[3] == 6) |
| 1418 | { |
| 1419 | nybbles[4]++; |
| 1420 | nybbles[3] = 0; |
| 1421 | } |
| 1422 | if(nybbles[4] == 10) |
| 1423 | { |
| 1424 | nybbles[5]++; |
| 1425 | nybbles[4] = 0; |
| 1426 | } |
| 1427 | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 1428 | } |
| 1429 | |
| 1430 | static UINT32 increment_cdda_sector_bcd(UINT32 bcd) |
| 1431 | { |
| 1432 | UINT8 nybbles[6] = |
| 1433 | { |
| 1434 | bcd & 0x0000000f, |
| 1435 | (bcd & 0x000000f0) >> 4, |
| 1436 | (bcd & 0x00000f00) >> 8, |
| 1437 | (bcd & 0x0000f000) >> 12, |
| 1438 | (bcd & 0x000f0000) >> 16, |
| 1439 | (bcd & 0x00f00000) >> 20 |
| 1440 | }; |
| 1399 | 1441 | nybbles[2]++; |
| 1400 | 1442 | if(nybbles[2] == 10) |
| 1401 | 1443 | { |
| r6228 | r6229 | |
| 1502 | 1544 | } |
| 1503 | 1545 | } |
| 1504 | 1546 | |
| 1547 | cdic_regs.data_buffer ^= 0x0001; |
| 1548 | |
| 1505 | 1549 | //printf( "%02x\n", buffer[CDIC_SECTOR_SUBMODE2] ); |
| 1506 | 1550 | if((buffer[CDIC_SECTOR_FILE2] << 8) == cdic_regs.file) |
| 1507 | 1551 | { |
| 1508 | | if(((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_FORM | CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == (CDIC_SUBMODE_FORM | CDIC_SUBMODE_AUDIO)) && |
| 1509 | | (cdic_regs.channel & cdic_regs.audio_channel & (1 << buffer[CDIC_SECTOR_CHAN2]))) |
| 1552 | if(cdic_regs.channel & (1 << buffer[CDIC_SECTOR_CHAN2])) |
| 1510 | 1553 | { |
| 1554 | if(((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_FORM | CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == (CDIC_SUBMODE_FORM | CDIC_SUBMODE_AUDIO)) && |
| 1555 | (cdic_regs.audio_channel & (1 << buffer[CDIC_SECTOR_CHAN2]))) |
| 1511 | 1556 | { |
| 1512 | | verboselog(machine, 0, "Audio sector\n" ); |
| 1557 | { |
| 1558 | verboselog(machine, 0, "Audio sector\n" ); |
| 1513 | 1559 | |
| 1560 | //cdic_regs.data_buffer ^= 0x0001; |
| 1561 | |
| 1562 | cdic_regs.x_buffer |= 0x8000; |
| 1563 | cdic_regs.data_buffer |= 0x4000; |
| 1564 | cdic_regs.data_buffer |= 0x0004; |
| 1565 | |
| 1566 | for(index = 6; index < 2352/2; index++) |
| 1567 | { |
| 1568 | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1569 | } |
| 1570 | |
| 1571 | cdic_decode_audio_sector(machine, ((UINT8*)cdram) + ((cdic_regs.data_buffer & 5) * 0xa00 + 4), 0); |
| 1572 | |
| 1573 | //printf( "Setting CDIC interrupt line\n" ); |
| 1574 | verboselog(machine, 0, "Setting CDIC interrupt line for audio sector\n" ); |
| 1575 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1576 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1577 | } |
| 1578 | } |
| 1579 | else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00) |
| 1580 | { |
| 1581 | //cdic_regs.data_buffer ^= 0x0001; |
| 1582 | |
| 1583 | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG) == CDIC_SUBMODE_TRIG || |
| 1584 | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOR) == CDIC_SUBMODE_EOR || |
| 1585 | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == CDIC_SUBMODE_EOF) |
| 1586 | { |
| 1587 | cdic_regs.data_buffer &= ~0x0004; |
| 1588 | cdic_regs.x_buffer |= 0x8000; |
| 1589 | cdic_regs.data_buffer |= 0x4000; |
| 1590 | |
| 1591 | for(index = 6; index < 2352/2; index++) |
| 1592 | { |
| 1593 | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1594 | } |
| 1595 | |
| 1596 | //printf( "Setting CDIC interrupt line\n" ); |
| 1597 | verboselog(machine, 0, "Setting CDIC interrupt line for message sector\n" ); |
| 1598 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1599 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1600 | } |
| 1601 | else |
| 1602 | { |
| 1603 | verboselog(machine, 0, "Message sector, ignored\n" ); |
| 1604 | } |
| 1605 | } |
| 1606 | else /*if(buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_VIDEO))*/ |
| 1607 | { |
| 1608 | //cdic_regs.data_buffer ^= 0x0001; |
| 1609 | |
| 1610 | cdic_regs.data_buffer &= ~0x0004; |
| 1514 | 1611 | cdic_regs.x_buffer |= 0x8000; |
| 1515 | 1612 | cdic_regs.data_buffer |= 0x4000; |
| 1516 | | cdic_regs.data_buffer |= 0x0004; |
| 1517 | | cdic_regs.data_buffer ^= 0x0001; |
| 1518 | 1613 | |
| 1519 | 1614 | for(index = 6; index < 2352/2; index++) |
| 1520 | 1615 | { |
| 1521 | 1616 | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1522 | 1617 | } |
| 1523 | 1618 | |
| 1524 | | cdic_decode_audio_sector(machine, ((UINT8*)cdram) + ((cdic_regs.data_buffer & 5) * 0xa00 + 4), 0); |
| 1525 | | |
| 1526 | 1619 | //printf( "Setting CDIC interrupt line\n" ); |
| 1527 | | verboselog(machine, 0, "Setting CDIC interrupt line for audio sector\n" ); |
| 1620 | verboselog(machine, 0, "Setting CDIC interrupt line for data sector\n" ); |
| 1528 | 1621 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1529 | 1622 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1530 | | //} |
| 1531 | 1623 | } |
| 1532 | 1624 | } |
| 1533 | | else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00) |
| 1534 | | { |
| 1535 | | cdic_regs.data_buffer &= ~0x0004; |
| 1536 | | cdic_regs.x_buffer |= 0x8000; |
| 1537 | | cdic_regs.data_buffer |= 0x4000; |
| 1538 | | cdic_regs.data_buffer ^= 0x0001; |
| 1539 | 1625 | |
| 1540 | | for(index = 6; index < 2352/2; index++) |
| 1541 | | { |
| 1542 | | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1543 | | } |
| 1544 | | |
| 1545 | | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG) == CDIC_SUBMODE_TRIG || |
| 1546 | | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOR) == CDIC_SUBMODE_EOR || |
| 1547 | | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == CDIC_SUBMODE_EOF) |
| 1548 | | { |
| 1549 | | //printf( "Setting CDIC interrupt line\n" ); |
| 1550 | | verboselog(machine, 0, "Setting CDIC interrupt line for message sector\n" ); |
| 1551 | | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1552 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1553 | | } |
| 1554 | | else |
| 1555 | | { |
| 1556 | | verboselog(machine, 0, "Message sector, ignored\n" ); |
| 1557 | | } |
| 1558 | | } |
| 1559 | | else /*if(buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_VIDEO))*/ |
| 1560 | | { |
| 1561 | | cdic_regs.data_buffer &= ~0x0004; |
| 1562 | | cdic_regs.x_buffer |= 0x8000; |
| 1563 | | cdic_regs.data_buffer |= 0x4000; |
| 1564 | | cdic_regs.data_buffer ^= 0x0001; |
| 1565 | | |
| 1566 | | for(index = 6; index < 2352/2; index++) |
| 1567 | | { |
| 1568 | | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1569 | | } |
| 1570 | | |
| 1571 | | //printf( "Setting CDIC interrupt line\n" ); |
| 1572 | | verboselog(machine, 0, "Setting CDIC interrupt line for data sector\n" ); |
| 1573 | | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1574 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1575 | | } |
| 1576 | | |
| 1577 | 1626 | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == 0 && cdic_regs.command != 0x23) |
| 1578 | 1627 | { |
| 1579 | 1628 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| r6228 | r6229 | |
| 1589 | 1638 | |
| 1590 | 1639 | break; |
| 1591 | 1640 | } |
| 1641 | case 0x2c: // Seek |
| 1642 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1643 | |
| 1644 | cdic_regs.data_buffer &= ~4; |
| 1645 | |
| 1646 | verboselog(machine, 0, "Setting CDIC interrupt line for data sector\n" ); |
| 1647 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1648 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1649 | break; |
| 1592 | 1650 | case 0x24: // Mode 2 Reset |
| 1593 | 1651 | case 0x2e: // Abort |
| 1594 | | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1652 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1653 | cdic_regs.data_buffer &= ~4; |
| 1595 | 1654 | break; |
| 1596 | 1655 | case 0x28: // Play CDDA audio |
| 1597 | 1656 | { |
| 1598 | | UINT32 msf = (cdic_regs.time & 0xffff0000) >> 8; |
| 1599 | | UINT32 next_msf = increment_cdda_bcd((cdic_regs.time & 0xffff0000) >> 8); |
| 1657 | UINT8 buffer[2560] = { 0 }; |
| 1658 | int index = 0; |
| 1659 | UINT32 msf = (cdic_regs.time & 0xffff7f00) >> 8; |
| 1660 | UINT32 next_msf = increment_cdda_frame_bcd((cdic_regs.time & 0xffff7f00) >> 8); |
| 1661 | UINT32 rounded_next_msf = increment_cdda_sector_bcd((cdic_regs.time & 0xffff0000) >> 8); |
| 1600 | 1662 | UINT32 lba = 0; |
| 1601 | 1663 | UINT32 next_lba = 0; |
| 1602 | 1664 | UINT8 nybbles[6] = |
| r6228 | r6229 | |
| 1610 | 1672 | }; |
| 1611 | 1673 | UINT8 next_nybbles[6] = |
| 1612 | 1674 | { |
| 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 |
| 1675 | rounded_next_msf & 0x0000000f, |
| 1676 | (rounded_next_msf & 0x000000f0) >> 4, |
| 1677 | (rounded_next_msf & 0x00000f00) >> 8, |
| 1678 | (rounded_next_msf & 0x0000f000) >> 12, |
| 1679 | (rounded_next_msf & 0x000f0000) >> 16, |
| 1680 | (rounded_next_msf & 0x00f00000) >> 20 |
| 1619 | 1681 | }; |
| 1620 | 1682 | 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 | 1683 | 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) |
| 1684 | |
| 1685 | cdrom_read_data(cdic_regs.cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 1686 | |
| 1687 | if(!(msf & 0x0000ff)) |
| 1654 | 1688 | { |
| 1655 | | next_nybbles[2] -= 2; |
| 1689 | 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); |
| 1690 | |
| 1691 | verboselog(machine, 0, "Playing CDDA sector from MSF location %06x\n", cdic_regs.time | 2 ); |
| 1692 | |
| 1693 | cdda_start_audio(devtag_get_device(machine, "cdda"), lba, rounded_next_msf); |
| 1694 | |
| 1656 | 1695 | } |
| 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 | 1696 | |
| 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); |
| 1697 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 1680 | 1698 | |
| 1681 | | verboselog(machine, 0, "Playing CDDA sector from MSF location %06x\n", cdic_regs.time | 2 ); |
| 1699 | cdic_regs.x_buffer |= 0x8000; |
| 1700 | cdic_regs.data_buffer |= 0x4000; |
| 1682 | 1701 | |
| 1683 | | cdda_start_audio(devtag_get_device(machine, "cdda"), lba, next_lba); |
| 1702 | for(index = 6; index < 2352/2; index++) |
| 1703 | { |
| 1704 | cdram[(cdic_regs.data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1705 | } |
| 1684 | 1706 | |
| 1685 | | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(1), 0); |
| 1686 | | |
| 1687 | 1707 | verboselog(machine, 0, "Setting CDIC interrupt line for CDDA sector\n" ); |
| 1688 | 1708 | cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 128); |
| 1689 | 1709 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| r6228 | r6229 | |
| 1866 | 1886 | COMBINE_DATA(&cdic_regs.z_buffer); |
| 1867 | 1887 | if(cdic_regs.z_buffer & 0x2000) |
| 1868 | 1888 | { |
| 1869 | | attotime period = timer_timeleft(cdic_regs.interrupt_timer); |
| 1889 | attotime period = timer_timeleft(cdic_regs.audio_sample_timer); |
| 1870 | 1890 | if(!attotime_is_never(period)) |
| 1871 | 1891 | { |
| 1872 | 1892 | timer_adjust_oneshot(cdic_regs.audio_sample_timer, period, 0); |
| r6228 | r6229 | |
| 1896 | 1916 | { |
| 1897 | 1917 | case 0x24: // Reset Mode 2 |
| 1898 | 1918 | case 0x2e: // Abort |
| 1919 | { |
| 1899 | 1920 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1900 | 1921 | dmadac_enable(&dmadac[0], 2, 0); |
| 1922 | cdic_regs.data_buffer &= 0xbfff; |
| 1901 | 1923 | break; |
| 1924 | } |
| 1925 | case 0x2b: // Stop CDDA |
| 1926 | cdda_stop_audio(devtag_get_device(space->machine, "cdda")); |
| 1927 | timer_adjust_oneshot(cdic_regs.interrupt_timer, attotime_never, 0); |
| 1928 | break; |
| 1902 | 1929 | case 0x23: // Reset Mode 1 |
| 1903 | 1930 | case 0x29: // Read Mode 1 |
| 1904 | 1931 | case 0x2a: // Read Mode 2 |
| 1905 | | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1906 | | break; |
| 1907 | 1932 | 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; |
| 1915 | 1933 | case 0x2c: // Seek |
| 1934 | { |
| 1935 | attotime period = timer_timeleft(cdic_regs.interrupt_timer); |
| 1936 | if(!attotime_is_never(period)) |
| 1937 | { |
| 1938 | timer_adjust_oneshot(cdic_regs.interrupt_timer, period, 0); |
| 1939 | } |
| 1940 | else |
| 1941 | { |
| 1942 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 1943 | } |
| 1916 | 1944 | break; |
| 1945 | } |
| 1917 | 1946 | default: |
| 1918 | 1947 | verboselog(space->machine, 0, "Unknown CDIC command: %02x\n", cdic_regs.command ); |
| 1919 | 1948 | break; |
| r6228 | r6229 | |
| 1982 | 2011 | } |
| 1983 | 2012 | |
| 1984 | 2013 | static void perform_mouse_update(running_machine *machine) |
| 2014 | |
| 1985 | 2015 | { |
| 1986 | 2016 | UINT16 x = input_port_read(machine, "MOUSEX"); |
| 1987 | 2017 | UINT16 y = input_port_read(machine, "MOUSEY"); |
| r6228 | r6229 | |
| 2455 | 2485 | |
| 2456 | 2486 | static void cdi220_draw_lcd(running_machine *machine, int y) |
| 2457 | 2487 | { |
| 2458 | | bitmap_t *bitmap = tmpbitmap; |
| 2488 | bitmap_t *bitmap = lcdbitmap; |
| 2459 | 2489 | UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 2460 | 2490 | int x = 0; |
| 2461 | 2491 | int lcd = 0; |
| r6228 | r6229 | |
| 2474 | 2504 | } |
| 2475 | 2505 | } |
| 2476 | 2506 | } |
| 2477 | | for(x = 8*24; x < 384; x++) |
| 2478 | | { |
| 2479 | | scanline[x] = 0; |
| 2480 | | } |
| 2481 | 2507 | } |
| 2482 | 2508 | |
| 2483 | 2509 | static READ16_HANDLER(mcd212_r) |
| r6228 | r6229 | |
| 3878 | 3904 | mcd212.channel[1].clut_bank = 0; |
| 3879 | 3905 | mcd212.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0); |
| 3880 | 3906 | timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 3907 | |
| 3908 | lcdbitmap = video_screen_auto_bitmap_alloc(devtag_get_device(machine, "lcd")); |
| 3881 | 3909 | } |
| 3882 | 3910 | |
| 3911 | static VIDEO_UPDATE(cdi) |
| 3912 | { |
| 3913 | const device_config *main_screen = devtag_get_device(screen->machine, "screen"); |
| 3914 | const device_config *lcd_screen = devtag_get_device(screen->machine, "lcd"); |
| 3915 | |
| 3916 | if (screen == main_screen) |
| 3917 | { |
| 3918 | copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, cliprect); |
| 3919 | } |
| 3920 | else if (screen == lcd_screen) |
| 3921 | { |
| 3922 | copybitmap(bitmap, lcdbitmap, 0, 0, 0, 0, cliprect); |
| 3923 | } |
| 3924 | |
| 3925 | return 0; |
| 3926 | } |
| 3927 | |
| 3883 | 3928 | static TIMER_CALLBACK( test_timer_callback ) |
| 3884 | 3929 | { |
| 3885 | 3930 | // This function manually triggers interrupt requests as a test. |
| r6228 | r6229 | |
| 3949 | 3994 | PORT_START("MOUSEBTN") |
| 3950 | 3995 | PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_NAME("Mouse Button 1") PORT_CHANGED(mouse_update, 0) |
| 3951 | 3996 | PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_NAME("Mouse Button 2") PORT_CHANGED(mouse_update, 0) |
| 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) |
| 3997 | PORT_BIT(0xfc, IP_ACTIVE_HIGH, IPT_UNUSED) |
| 3954 | 3998 | INPUT_PORTS_END |
| 3955 | 3999 | |
| 3956 | 4000 | static MACHINE_RESET( cdi ) |
| r6228 | r6229 | |
| 4015 | 4059 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 4016 | 4060 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 4017 | 4061 | MDRV_SCREEN_SIZE(384, 262) |
| 4018 | | MDRV_SCREEN_VISIBLE_AREA(0, 384-1, 0, 262-1) //dynamic resolution,TODO |
| 4062 | MDRV_SCREEN_VISIBLE_AREA(0, 384-1, 22, 262-1) //dynamic resolution,TODO |
| 4019 | 4063 | |
| 4064 | MDRV_SCREEN_ADD("lcd", RASTER) |
| 4065 | MDRV_SCREEN_REFRESH_RATE(60) |
| 4066 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 4067 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 4068 | MDRV_SCREEN_SIZE(192, 22) |
| 4069 | MDRV_SCREEN_VISIBLE_AREA(0, 192-1, 0, 22-1) |
| 4070 | |
| 4020 | 4071 | MDRV_PALETTE_LENGTH(0x100) |
| 4021 | 4072 | |
| 4073 | MDRV_DEFAULT_LAYOUT(layout_cdi) |
| 4074 | |
| 4022 | 4075 | MDRV_VIDEO_START(cdi) |
| 4023 | | MDRV_VIDEO_UPDATE(generic_bitmapped) |
| 4076 | MDRV_VIDEO_UPDATE(cdi) |
| 4024 | 4077 | |
| 4025 | 4078 | MDRV_MACHINE_RESET(cdi) |
| 4026 | 4079 | |
src/mess/drivers/ip6.c
| r0 | r6229 | |
| 1 | /*********************************************************************\ |
| 2 | * |
| 3 | * SGI IP6 4D/PI workstation |
| 4 | * |
| 5 | * Skeleton driver by Harmony |
| 6 | * |
| 7 | * Todo: Everything |
| 8 | * |
| 9 | * Preliminary Memory map: |
| 10 | * |
| 11 | * 1fc00000 - 1fc3ffff BIOS |
| 12 | * |
| 13 | \*********************************************************************/ |
| 14 | |
| 15 | #include "driver.h" |
| 16 | #include "cpu/mips/r3000.h" |
| 17 | |
| 18 | #define VERBOSE_LEVEL ( 99 ) |
| 19 | |
| 20 | INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) |
| 21 | { |
| 22 | if( VERBOSE_LEVEL >= n_level ) |
| 23 | { |
| 24 | va_list v; |
| 25 | char buf[ 32768 ]; |
| 26 | va_start( v, s_fmt ); |
| 27 | vsprintf( buf, s_fmt, v ); |
| 28 | va_end( v ); |
| 29 | logerror("%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | typedef struct |
| 34 | { |
| 35 | UINT16 unknown_half_0; |
| 36 | UINT8 unknown_byte_0; |
| 37 | UINT8 unknown_byte_1; |
| 38 | } ip6_regs_t; |
| 39 | |
| 40 | static ip6_regs_t ip6_regs; |
| 41 | |
| 42 | static READ32_HANDLER( ip6_unk1_r ) |
| 43 | { |
| 44 | UINT32 ret = 0; |
| 45 | switch(offset) |
| 46 | { |
| 47 | case 0x0000/4: |
| 48 | if(ACCESSING_BITS_16_31) |
| 49 | { |
| 50 | verboselog(space->machine, 0, "ip6_unk1_r: Unknown address: %08x & %08x\n", 0x1f880000 + (offset << 2), mem_mask ); |
| 51 | } |
| 52 | if(ACCESSING_BITS_0_15) |
| 53 | { |
| 54 | verboselog(space->machine, 0, "ip6_unk1_r: Unknown Halfword 0: %08x & %08x\n", ip6_regs.unknown_half_0, mem_mask ); |
| 55 | ret |= ip6_regs.unknown_half_0; |
| 56 | } |
| 57 | break; |
| 58 | default: |
| 59 | verboselog(space->machine, 0, "ip6_unk1_r: Unknown address: %08x & %08x\n", 0x1f880000 + (offset << 2), mem_mask ); |
| 60 | break; |
| 61 | } |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | static WRITE32_HANDLER( ip6_unk1_w ) |
| 66 | { |
| 67 | switch(offset) |
| 68 | { |
| 69 | case 0x0000/4: |
| 70 | if(ACCESSING_BITS_16_31) |
| 71 | { |
| 72 | verboselog(space->machine, 0, "ip6_unk1_w: Unknown address: %08x = %08x & %08x\n", 0x1f880000 + (offset << 2), data, mem_mask ); |
| 73 | } |
| 74 | if(ACCESSING_BITS_0_15) |
| 75 | { |
| 76 | verboselog(space->machine, 0, "ip6_unk1_w: Unknown Halfword 0 = %04x & %04x\n", data & 0x0000ffff, mem_mask & 0x0000ffff ); |
| 77 | ip6_regs.unknown_half_0 = data & 0x0000ffff; |
| 78 | } |
| 79 | break; |
| 80 | default: |
| 81 | verboselog(space->machine, 0, "ip6_unk1_w: Unknown address: %08x = %08x & %08x\n", 0x1f880000 + (offset << 2), data, mem_mask ); |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static READ32_HANDLER( ip6_unk2_r ) |
| 87 | { |
| 88 | UINT32 ret = 0; |
| 89 | switch(offset) |
| 90 | { |
| 91 | case 0x0000/4: |
| 92 | if(!ACCESSING_BITS_24_31) |
| 93 | { |
| 94 | verboselog(space->machine, 0, "ip6_unk2_r: Unknown address: %08x & %08x\n", 0x1f880000 + (offset << 2), mem_mask ); |
| 95 | } |
| 96 | if(ACCESSING_BITS_24_31) |
| 97 | { |
| 98 | verboselog(space->machine, 0, "ip6_unk2_r: Unknown Byte 0 = %02x & %02x\n", ip6_regs.unknown_byte_0, mem_mask >> 24 ); |
| 99 | ret |= ip6_regs.unknown_byte_0 << 24; |
| 100 | } |
| 101 | break; |
| 102 | default: |
| 103 | verboselog(space->machine, 0, "ip6_unk2_r: Unknown address: %08x & %08x\n", 0x1f880000 + (offset << 2), mem_mask ); |
| 104 | break; |
| 105 | } |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | static WRITE32_HANDLER( ip6_unk2_w ) |
| 110 | { |
| 111 | switch(offset) |
| 112 | { |
| 113 | case 0x0000/4: |
| 114 | if(!ACCESSING_BITS_24_31) |
| 115 | { |
| 116 | verboselog(space->machine, 0, "ip6_unk2_w: Unknown address: %08x = %08x & %08x\n", 0x1f880000 + (offset << 2), data, mem_mask ); |
| 117 | } |
| 118 | if(ACCESSING_BITS_24_31) |
| 119 | { |
| 120 | verboselog(space->machine, 0, "ip6_unk2_w: Unknown Byte 0 = %02x & %02x\n", data >> 24, mem_mask >> 24 ); |
| 121 | ip6_regs.unknown_byte_0 = (data & 0xff000000) >> 24; |
| 122 | } |
| 123 | break; |
| 124 | default: |
| 125 | verboselog(space->machine, 0, "ip6_unk2_w: Unknown address: %08x = %08x & %08x\n", 0x1f880000 + (offset << 2), data, mem_mask ); |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | static READ32_HANDLER(ip6_unk3_r) |
| 131 | { |
| 132 | UINT32 ret = 0; |
| 133 | if(ACCESSING_BITS_16_23) |
| 134 | { |
| 135 | verboselog(space->machine, 0, "ip6_unk3_r: Unknown Byte 1: %02x & %02x\n", ip6_regs.unknown_byte_1, (mem_mask >> 16) & 0x000000ff); |
| 136 | ret |= ip6_regs.unknown_byte_1 << 16; |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | verboselog(space->machine, 0, "ip6_unk3_r: Unknown address: %08x & %08x\n", 0x1fb00000 + (offset << 2), mem_mask ); |
| 141 | } |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static WRITE32_HANDLER(ip6_unk3_w) |
| 146 | { |
| 147 | verboselog(space->machine, 0, "ip6_unk3_w: Unknown address: %08x = %08x & %08x\n", 0x1fb00000 + (offset << 2), data, mem_mask ); |
| 148 | } |
| 149 | |
| 150 | static ADDRESS_MAP_START( sgi_ip6_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 151 | AM_RANGE( 0x1f880000, 0x1f880003 ) AM_READWRITE(ip6_unk1_r, ip6_unk1_w) |
| 152 | AM_RANGE( 0x1fb00000, 0x1fb00003 ) AM_READWRITE(ip6_unk3_r, ip6_unk3_w) |
| 153 | AM_RANGE( 0x1fbc004c, 0x1fbc004f ) AM_READWRITE(ip6_unk2_r, ip6_unk2_w) |
| 154 | AM_RANGE( 0x1fc00000, 0x1fc3ffff ) AM_ROM AM_REGION( "user1", 0 ) |
| 155 | ADDRESS_MAP_END |
| 156 | |
| 157 | static MACHINE_START( sgi_ip6 ) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | static MACHINE_RESET( sgi_ip6 ) |
| 162 | { |
| 163 | ip6_regs.unknown_byte_0 = 0x80; |
| 164 | ip6_regs.unknown_byte_1 = 0x80; |
| 165 | ip6_regs.unknown_half_0 = 0; |
| 166 | } |
| 167 | |
| 168 | static DRIVER_INIT( sgi_ip6 ) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | static INPUT_PORTS_START( sgi_ip6 ) |
| 173 | PORT_START("UNUSED") // unused IN0 |
| 174 | PORT_BIT(0xffff, IP_ACTIVE_HIGH, IPT_UNUSED) |
| 175 | INPUT_PORTS_END |
| 176 | |
| 177 | static INTERRUPT_GEN( sgi_ip6_vbl ) |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | static const r3000_cpu_core config = |
| 182 | { |
| 183 | 0, /* 1 if we have an FPU, 0 otherwise */ |
| 184 | 4096, /* code cache size */ |
| 185 | 4096 /* data cache size */ |
| 186 | }; |
| 187 | |
| 188 | static MACHINE_DRIVER_START( sgi_ip6 ) |
| 189 | MDRV_CPU_ADD( "maincpu", R3000BE, 20000000 ) // FIXME: Should be R2000 |
| 190 | MDRV_CPU_CONFIG( config ) |
| 191 | MDRV_CPU_PROGRAM_MAP( sgi_ip6_map ) |
| 192 | MDRV_CPU_VBLANK_INT("screen", sgi_ip6_vbl) |
| 193 | |
| 194 | MDRV_MACHINE_RESET( sgi_ip6 ) |
| 195 | |
| 196 | /* video hardware */ |
| 197 | MDRV_SCREEN_ADD("screen", RASTER) |
| 198 | MDRV_SCREEN_REFRESH_RATE( 60 ) |
| 199 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| 200 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 201 | MDRV_SCREEN_SIZE(640, 480) |
| 202 | MDRV_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1) |
| 203 | |
| 204 | MDRV_MACHINE_START( sgi_ip6 ) |
| 205 | |
| 206 | MDRV_VIDEO_START(generic_bitmapped) |
| 207 | MDRV_VIDEO_UPDATE(generic_bitmapped) |
| 208 | MACHINE_DRIVER_END |
| 209 | |
| 210 | ROM_START( sgi_ip6 ) |
| 211 | ROM_REGION32_BE( 0x40000, "user1", 0 ) |
| 212 | ROM_LOAD( "4d202031.bin", 0x000000, 0x040000, CRC(12345678) SHA1(1234567812345678123456781234567812345678) ) |
| 213 | ROM_END |
| 214 | |
| 215 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 216 | COMP( 1988, sgi_ip6, 0, 0, sgi_ip6, sgi_ip6, sgi_ip6, 0, "Silicon Graphics, Inc", "4D/PI (R2000, 20MHz)", GAME_NOT_WORKING ) |