trunk/src/mess/machine/psxcd.c
| r20446 | r20447 | |
| 1 | |
| 1 | 2 | #include "emu.h" |
| 2 | 3 | #include "psxcd.h" |
| 3 | | #include "sound/spu.h" |
| 4 | 4 | #include "debugger.h" |
| 5 | 5 | |
| 6 | 6 | // |
| r20446 | r20447 | |
| 114 | 114 | { |
| 115 | 115 | m_irq_handler.resolve_safe(); |
| 116 | 116 | |
| 117 | | unsigned int sysclk=machine().device<cpu_device>("maincpu")->clock()/2; |
| 117 | m_maincpu = machine().device<cpu_device>("maincpu"); |
| 118 | m_spu = machine().device<spu_device>("spu"); |
| 119 | |
| 120 | unsigned int sysclk=m_maincpu->clock()/2; |
| 118 | 121 | start_read_delay=(sysclk/60); |
| 119 | 122 | read_sector_cycles=(sysclk/75); |
| 120 | 123 | preread_delay=(read_sector_cycles>>2)-500; |
| r20446 | r20447 | |
| 223 | 226 | } |
| 224 | 227 | |
| 225 | 228 | #ifdef debug_cdrom_registers |
| 226 | | printf("cdrom: read byte %08x = %02x (PC=%x)\n",offset,ret,machine().device("maincpu")->safe_pc()); |
| 229 | printf("cdrom: read byte %08x = %02x (PC=%x)\n",offset,ret,m_maincpu->safe_pc()); |
| 227 | 230 | #endif |
| 228 | 231 | |
| 229 | 232 | return ret; |
| r20446 | r20447 | |
| 236 | 239 | WRITE8_MEMBER( psxcd_device::write ) |
| 237 | 240 | { |
| 238 | 241 | #ifdef debug_cdrom_registers |
| 239 | | printf("cdrom: write byte %08x = %02x (PC=%x)\n",offset,data,machine().device("maincpu")->safe_pc()); |
| 242 | printf("cdrom: write byte %08x = %02x (PC=%x)\n",offset,data,m_maincpu->safe_pc()); |
| 240 | 243 | #endif |
| 241 | 244 | |
| 242 | 245 | switch (offset&3) |
| r20446 | r20447 | |
| 972 | 975 | // Avoid returning results after sector read results - |
| 973 | 976 | // delay the sector read slightly if necessary |
| 974 | 977 | |
| 975 | | UINT64 systime = machine().device<cpu_device>("maincpu")->total_cycles(); |
| 978 | UINT64 systime = m_maincpu->total_cycles(); |
| 976 | 979 | if ((next_read_event) && ((systime+ev->t)>(next_sector_t))) |
| 977 | 980 | { |
| 978 | 981 | UINT32 hz = m_sysclock / (delay + 2000); |
| r20446 | r20447 | |
| 1135 | 1138 | if (xa_prefetch_sector==-1) |
| 1136 | 1139 | { |
| 1137 | 1140 | xa_prefetch_sector=cursec; |
| 1138 | | machine().device<spu_device>("spu")->flush_xa(); |
| 1141 | m_spu->flush_xa(); |
| 1139 | 1142 | } |
| 1140 | 1143 | |
| 1141 | 1144 | unsigned char *xaptr; |
| r20446 | r20447 | |
| 1166 | 1169 | ((xasub->file==sub->file) && |
| 1167 | 1170 | (xasub->channel==sub->channel)))) |
| 1168 | 1171 | { |
| 1169 | | if (! machine().device<spu_device>("spu")->play_xa(xa_prefetch_sector,xaptr)) |
| 1172 | if (! m_spu->play_xa(xa_prefetch_sector,xaptr)) |
| 1170 | 1173 | break; |
| 1171 | 1174 | } |
| 1172 | 1175 | xa_prefetch_sector++; |
| 1173 | 1176 | } |
| 1174 | 1177 | #else |
| 1175 | | machine().device<spu_device>("spu")->play_xa(0,rawsec+16); |
| 1178 | m_spu->play_xa(0,rawsec+16); |
| 1176 | 1179 | #endif |
| 1177 | 1180 | |
| 1178 | 1181 | status|=status_playing; |
| r20446 | r20447 | |
| 1253 | 1256 | |
| 1254 | 1257 | bool psxcd_device::play_cdda_sector(const unsigned int sector, unsigned char *rawsec) |
| 1255 | 1258 | { |
| 1256 | | return machine().device<spu_device>("spu")->play_cdda(sector,rawsec); |
| 1259 | return m_spu->play_cdda(sector,rawsec); |
| 1257 | 1260 | } |
| 1258 | 1261 | |
| 1259 | 1262 | // |
| r20446 | r20447 | |
| 1280 | 1283 | if (cdda_prefetch_sector==-1) |
| 1281 | 1284 | { |
| 1282 | 1285 | cdda_prefetch_sector=cursec; |
| 1283 | | machine().device<spu_device>("spu")->flush_cdda(); |
| 1286 | m_spu->flush_cdda(); |
| 1284 | 1287 | } |
| 1285 | 1288 | |
| 1286 | 1289 | unsigned char *cddaptr; |
| r20446 | r20447 | |
| 1360 | 1363 | unsigned int cyc=read_sector_cycles; |
| 1361 | 1364 | |
| 1362 | 1365 | event *ev=new event; |
| 1363 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1366 | ev->t=next_sector_t - m_maincpu->total_cycles(); |
| 1364 | 1367 | ev->type=event_play_sector; |
| 1365 | 1368 | |
| 1366 | 1369 | next_sector_t+=cyc>>1; |
| r20446 | r20447 | |
| 1394 | 1397 | |
| 1395 | 1398 | unsigned int cyc=read_sector_cycles; |
| 1396 | 1399 | if (mode&mode_double_speed) cyc>>=1; |
| 1397 | | next_sector_t=ev->t+(cyc-preread_delay)+machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1400 | next_sector_t=ev->t+(cyc-preread_delay)+m_maincpu->total_cycles(); |
| 1398 | 1401 | } else |
| 1399 | 1402 | { |
| 1400 | 1403 | memcpy(lastsechdr,buf+12,8); |
| r20446 | r20447 | |
| 1414 | 1417 | |
| 1415 | 1418 | // |
| 1416 | 1419 | |
| 1417 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1420 | ev->t=next_sector_t - m_maincpu->total_cycles(); |
| 1418 | 1421 | ev->type=event_read_sector; |
| 1419 | 1422 | |
| 1420 | 1423 | //read_next_sector(); |
| r20446 | r20447 | |
| 1444 | 1447 | unsigned int cyc=read_sector_cycles; |
| 1445 | 1448 | if (mode&mode_double_speed) cyc>>=1; |
| 1446 | 1449 | |
| 1447 | | INT64 systime=machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1450 | INT64 systime=m_maincpu->total_cycles(); |
| 1448 | 1451 | |
| 1449 | 1452 | systime+=start_read_delay; |
| 1450 | 1453 | |
| r20446 | r20447 | |
| 1495 | 1498 | |
| 1496 | 1499 | unsigned int cyc=read_sector_cycles; |
| 1497 | 1500 | |
| 1498 | | next_sector_t=machine().device<cpu_device>("maincpu")->total_cycles()+cyc; |
| 1501 | next_sector_t=m_maincpu->total_cycles()+cyc; |
| 1499 | 1502 | |
| 1500 | 1503 | event *ev=new event; |
| 1501 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1504 | ev->t=next_sector_t - m_maincpu->total_cycles(); |
| 1502 | 1505 | ev->type=event_play_sector; |
| 1503 | 1506 | |
| 1504 | 1507 | next_sector_t+=cyc>>1; |
| r20446 | r20447 | |
| 1539 | 1542 | } |
| 1540 | 1543 | |
| 1541 | 1544 | unsigned int sector=msf_to_sector(curpos); |
| 1542 | | machine().device<spu_device>("spu")->flush_xa(sector); |
| 1543 | | machine().device<spu_device>("spu")->flush_cdda(sector); |
| 1545 | m_spu->flush_xa(sector); |
| 1546 | m_spu->flush_cdda(sector); |
| 1544 | 1547 | } |
| 1545 | 1548 | |
| 1546 | 1549 | // |