src/mame/machine/psxcd.c
| r11505 | r11506 | |
| 1 | | #include "emu.h" |
| 2 | | #include "includes/psx.h" |
| 3 | | #include "psxcd.h" |
| 4 | | #include "machine/devhelpr.h" |
| 5 | | #include "sound/spu.h" |
| 6 | | #include "debugger.h" |
| 7 | | |
| 8 | | // |
| 9 | | // |
| 10 | | // |
| 11 | | |
| 12 | | //#define debug_cdrom |
| 13 | | //#define debug_cdrom_registers |
| 14 | | //#define skip_reads |
| 15 | | //#define dump_subheader |
| 16 | | //#define disable_xa_prefetch |
| 17 | | //#define disable_cdda_prefetch |
| 18 | | |
| 19 | | // |
| 20 | | // |
| 21 | | // |
| 22 | | |
| 23 | | enum cdrom_events |
| 24 | | { |
| 25 | | event_cmd_complete=0, |
| 26 | | event_preread_sector, |
| 27 | | event_read_sector, |
| 28 | | event_play_sector |
| 29 | | }; |
| 30 | | |
| 31 | | // |
| 32 | | // |
| 33 | | // |
| 34 | | |
| 35 | | enum intr_status |
| 36 | | { |
| 37 | | intr_nointr=0, |
| 38 | | intr_dataready, |
| 39 | | intr_acknowledge, |
| 40 | | intr_complete, |
| 41 | | intr_dataend, |
| 42 | | intr_diskerror |
| 43 | | }; |
| 44 | | |
| 45 | | enum mode_flags |
| 46 | | { |
| 47 | | mode_double_speed=0x80, |
| 48 | | mode_adpcm=0x40, |
| 49 | | mode_size=0x20, |
| 50 | | mode_size2=0x10, |
| 51 | | mode_size_shift=4, |
| 52 | | mode_size_mask=(3<<mode_size_shift), |
| 53 | | mode_channel=0x08, |
| 54 | | mode_report=0x04, |
| 55 | | mode_autopause=0x02, |
| 56 | | mode_cdda=0x01 |
| 57 | | }; |
| 58 | | |
| 59 | | enum status_f |
| 60 | | { |
| 61 | | status_playing=0x80, |
| 62 | | status_seeking=0x40, |
| 63 | | status_reading=0x20, |
| 64 | | status_shellopen=0x10, |
| 65 | | status_seekerror=0x04, |
| 66 | | status_standby=0x02, |
| 67 | | status_error=0x01 |
| 68 | | }; |
| 69 | | |
| 70 | | struct subheader |
| 71 | | { |
| 72 | | unsigned char file, |
| 73 | | channel, |
| 74 | | submode, |
| 75 | | coding; |
| 76 | | }; |
| 77 | | |
| 78 | | enum submode_flags |
| 79 | | { |
| 80 | | submode_eof=0x80, |
| 81 | | submode_realtime=0x40, |
| 82 | | submode_form=0x20, |
| 83 | | submode_trigger=0x10, |
| 84 | | submode_data=0x08, |
| 85 | | submode_audio=0x04, |
| 86 | | submode_video=0x02, |
| 87 | | submode_eor=0x01 |
| 88 | | }; |
| 89 | | |
| 90 | | // |
| 91 | | // |
| 92 | | // |
| 93 | | |
| 94 | | static const unsigned int max_xa_prefetch_distance=32, |
| 95 | | max_cdda_prefetch_distance=32; |
| 96 | | |
| 97 | | //************************************************************************** |
| 98 | | // DEVICE DEFINITIONS |
| 99 | | //************************************************************************** |
| 100 | | |
| 101 | | const device_type PSXCD = &device_creator<psxcd_device>; |
| 102 | | |
| 103 | | void psxcd_device::static_set_devname(device_t &device, const char *devname) |
| 104 | | { |
| 105 | | psxcd_device &psxcd = downcast<psxcd_device &>(device); |
| 106 | | psxcd.m_devname = devname; |
| 107 | | } |
| 108 | | |
| 109 | | psxcd_device::psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 110 | | : device_t(mconfig, PSXCD, "PSXCD", tag, owner, clock) |
| 111 | | { |
| 112 | | } |
| 113 | | |
| 114 | | void psxcd_device::device_start() |
| 115 | | { |
| 116 | | unsigned int sysclk=machine().device<cpu_device>("maincpu")->clock()/2; |
| 117 | | start_read_delay=(sysclk/60); |
| 118 | | read_sector_cycles=(sysclk/75); |
| 119 | | preread_delay=(read_sector_cycles>>2)-500; |
| 120 | | |
| 121 | | m_sysclock = sysclk; |
| 122 | | |
| 123 | | secleft = 0; |
| 124 | | secsize = 2048; |
| 125 | | res_queue = NULL; |
| 126 | | cur_res = NULL; |
| 127 | | open = false; |
| 128 | | streaming = false; |
| 129 | | sechead = 0; |
| 130 | | sectail = 0; |
| 131 | | secin = 0; |
| 132 | | secskip = 0; |
| 133 | | next_read_event = NULL; |
| 134 | | cbp = cmdbuf; |
| 135 | | first_open = true; |
| 136 | | |
| 137 | | status=status_standby; |
| 138 | | sr=8|1; |
| 139 | | res=0; |
| 140 | | ir=0; |
| 141 | | mode=0; |
| 142 | | |
| 143 | | driver = NULL; |
| 144 | | |
| 145 | | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 146 | | { |
| 147 | | m_timers[i] = timer_alloc(i, NULL); |
| 148 | | m_timerinuse[i] = false; |
| 149 | | } |
| 150 | | } |
| 151 | | |
| 152 | | // |
| 153 | | // |
| 154 | | // |
| 155 | | |
| 156 | | void psxcd_device::device_reset() |
| 157 | | { |
| 158 | | stop_read(); |
| 159 | | open=false; |
| 160 | | |
| 161 | | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 162 | | { |
| 163 | | m_timerinuse[i] = false; |
| 164 | | } |
| 165 | | |
| 166 | | m_cddevice = machine().device(m_devname); |
| 167 | | if (m_cddevice) |
| 168 | | { |
| 169 | | m_cd = cd_get_cdrom_file(m_cddevice); |
| 170 | | |
| 171 | | if (m_cd) |
| 172 | | { |
| 173 | | // printf("psxcd: found disc!\n"); |
| 174 | | driver = open_mess_drv(); |
| 175 | | driver->set_machine(machine()); |
| 176 | | driver->set_cdrom_file(m_cd); |
| 177 | | } |
| 178 | | else |
| 179 | | { |
| 180 | | driver = NULL; |
| 181 | | // printf("psxcd: Found device, but no disc\n"); |
| 182 | | } |
| 183 | | } |
| 184 | | else |
| 185 | | { |
| 186 | | driver = NULL; |
| 187 | | // printf("psxcd: Device [%s] not found!\n", m_devname); |
| 188 | | } |
| 189 | | |
| 190 | | } |
| 191 | | |
| 192 | | // |
| 193 | | // |
| 194 | | // |
| 195 | | |
| 196 | | unsigned char psxcd_device::read_byte(const unsigned int addr) |
| 197 | | { |
| 198 | | unsigned char ret = 0; |
| 199 | | |
| 200 | | switch (addr&3) |
| 201 | | { |
| 202 | | case 0: ret=sr; break; |
| 203 | | case 1: |
| 204 | | ret=res; |
| 205 | | if ((cur_res) && (rdp<cur_res->sz)) |
| 206 | | { |
| 207 | | res=cur_res->data[rdp++]; |
| 208 | | sr|=(1<<5); |
| 209 | | } else |
| 210 | | { |
| 211 | | if ((cur_res) && (cur_res->res&0x10)) |
| 212 | | { |
| 213 | | global_free(cur_res); |
| 214 | | cur_res=NULL; |
| 215 | | } |
| 216 | | |
| 217 | | sr&=~(1<<5); |
| 218 | | } |
| 219 | | break; |
| 220 | | case 2: ret=0; break; |
| 221 | | case 3: ret=ir; break; |
| 222 | | } |
| 223 | | |
| 224 | | #ifdef debug_cdrom_registers |
| 225 | | printf("cdrom: read byte %08x = %02x (PC=%x)\n",addr,ret,cpu_get_pc(machine().device("maincpu"))); |
| 226 | | #endif |
| 227 | | |
| 228 | | return ret; |
| 229 | | } |
| 230 | | |
| 231 | | // |
| 232 | | // |
| 233 | | // |
| 234 | | |
| 235 | | void psxcd_device::write_byte(const unsigned int addr, const unsigned char byte) |
| 236 | | { |
| 237 | | #ifdef debug_cdrom_registers |
| 238 | | printf("cdrom: write byte %08x = %02x (PC=%x)\n",addr,byte,cpu_get_pc(machine().device("maincpu"))); |
| 239 | | #endif |
| 240 | | |
| 241 | | switch (addr&3) |
| 242 | | { |
| 243 | | case 0: |
| 244 | | cmdmode=byte&1; |
| 245 | | if (cmdmode==0) |
| 246 | | { |
| 247 | | cbp=cmdbuf; |
| 248 | | } else |
| 249 | | { |
| 250 | | if (! cur_res) |
| 251 | | { |
| 252 | | if (cur_res) global_free(cur_res); |
| 253 | | |
| 254 | | if (res_queue) |
| 255 | | { |
| 256 | | #ifdef debug_cdrom_registers |
| 257 | | printf("cdrom: nextres\n"); |
| 258 | | #endif |
| 259 | | |
| 260 | | cur_res=res_queue; |
| 261 | | res_queue=res_queue->next; |
| 262 | | ir=cur_res->res&0xf; |
| 263 | | rdp=0; |
| 264 | | |
| 265 | | if (cur_res->sz) |
| 266 | | { |
| 267 | | res=cur_res->data[rdp++]; |
| 268 | | sr|=(1<<5); |
| 269 | | } else |
| 270 | | { |
| 271 | | sr&=~(1<<5); |
| 272 | | } |
| 273 | | } else |
| 274 | | { |
| 275 | | //ir=0; |
| 276 | | cur_res=NULL; |
| 277 | | } |
| 278 | | } |
| 279 | | /*else |
| 280 | | { |
| 281 | | if (rdp>=cur_res->sz) |
| 282 | | { |
| 283 | | sr&=~(1<<5); |
| 284 | | } else |
| 285 | | { |
| 286 | | sr|=~(1<<5); |
| 287 | | res=cur_res->data[rdp++]; |
| 288 | | } |
| 289 | | } |
| 290 | | */ |
| 291 | | } |
| 292 | | break; |
| 293 | | |
| 294 | | case 1: |
| 295 | | if (cmdmode==0) |
| 296 | | { |
| 297 | | write_command(byte); |
| 298 | | } |
| 299 | | break; |
| 300 | | |
| 301 | | case 2: |
| 302 | | if (cmdmode==0) |
| 303 | | { |
| 304 | | *cbp++=byte; |
| 305 | | } else |
| 306 | | { |
| 307 | | // ?flush buffer? |
| 308 | | } |
| 309 | | break; |
| 310 | | |
| 311 | | case 3: |
| 312 | | if (byte==0x07) |
| 313 | | { |
| 314 | | if (cur_res) |
| 315 | | { |
| 316 | | global_free(cur_res); |
| 317 | | cur_res=NULL; |
| 318 | | sr&=~(1<<5); |
| 319 | | } |
| 320 | | ir=0; |
| 321 | | } |
| 322 | | break; |
| 323 | | } |
| 324 | | } |
| 325 | | |
| 326 | | psxcd_device::command_info psxcd_device::cmd_table[num_commands]= |
| 327 | | { |
| 328 | | { &psxcd_device::cdcmd_sync, "sync" }, // 00 |
| 329 | | { &psxcd_device::cdcmd_nop, "nop" }, // 01 |
| 330 | | { &psxcd_device::cdcmd_setloc, "setloc" }, // 02 |
| 331 | | { &psxcd_device::cdcmd_play, "play" }, // 03 |
| 332 | | { &psxcd_device::cdcmd_forward, "forward" }, // 04 |
| 333 | | { &psxcd_device::cdcmd_backward, "backward" }, // 05 |
| 334 | | { &psxcd_device::cdcmd_readn, "readn" }, // 06 |
| 335 | | { &psxcd_device::cdcmd_standby, "standby" }, // 07 |
| 336 | | { &psxcd_device::cdcmd_stop, "stop" }, // 08 |
| 337 | | { &psxcd_device::cdcmd_pause, "pause" }, // 09 |
| 338 | | { &psxcd_device::cdcmd_init, "init" }, // 0a |
| 339 | | { &psxcd_device::cdcmd_mute, "mute" }, // 0b |
| 340 | | { &psxcd_device::cdcmd_demute, "demute" }, // 0c |
| 341 | | { &psxcd_device::cdcmd_setfilter, "setfilter" }, // 0d |
| 342 | | { &psxcd_device::cdcmd_setmode, "setmode" }, // 0e |
| 343 | | { &psxcd_device::cdcmd_getparam, "getparam" }, // 0f |
| 344 | | { &psxcd_device::cdcmd_getlocl, "getlocl" }, // 10 |
| 345 | | { &psxcd_device::cdcmd_getlocp, "getlocp" }, // 11 |
| 346 | | { &psxcd_device::cdcmd_illegal, "illegal" }, // 12 |
| 347 | | { &psxcd_device::cdcmd_gettn, "gettn" }, // 13 |
| 348 | | { &psxcd_device::cdcmd_gettd, "gettd" }, // 14 |
| 349 | | { &psxcd_device::cdcmd_seekl, "seekl" }, // 15 |
| 350 | | { &psxcd_device::cdcmd_seekp, "seekp" }, // 16 |
| 351 | | { &psxcd_device::cdcmd_illegal, "illegal" }, // 17 |
| 352 | | { &psxcd_device::cdcmd_illegal, "illegal" }, // 18 |
| 353 | | { &psxcd_device::cdcmd_test, "test" }, // 19 |
| 354 | | { &psxcd_device::cdcmd_id, "id" }, // 1a |
| 355 | | { &psxcd_device::cdcmd_reads, "reads" }, // 1b |
| 356 | | { &psxcd_device::cdcmd_reset, "reset" }, // 1c |
| 357 | | { &psxcd_device::cdcmd_illegal, "illegal" }, // 1d |
| 358 | | { &psxcd_device::cdcmd_readtoc, "readtoc" }, // 1e |
| 359 | | }; |
| 360 | | |
| 361 | | // |
| 362 | | // |
| 363 | | // |
| 364 | | |
| 365 | | void psxcd_device::write_command(const unsigned char byte) |
| 366 | | { |
| 367 | | assert(byte<num_commands); |
| 368 | | (this->*cmd_table[byte].func)(); |
| 369 | | } |
| 370 | | |
| 371 | | // |
| 372 | | // |
| 373 | | // |
| 374 | | |
| 375 | | void psxcd_device::cdcmd_sync() |
| 376 | | { |
| 377 | | #ifdef debug_cdrom |
| 378 | | printf("cdrom: sync\n"); |
| 379 | | #endif |
| 380 | | |
| 381 | | stop_read(); |
| 382 | | send_result(intr_acknowledge); |
| 383 | | } |
| 384 | | |
| 385 | | static int open_nops=0; |
| 386 | | |
| 387 | | void psxcd_device::cdcmd_nop() |
| 388 | | { |
| 389 | | #ifdef debug_cdrom |
| 390 | | printf("cdrom: nop\n"); |
| 391 | | #endif |
| 392 | | |
| 393 | | //stop_read(); |
| 394 | | |
| 395 | | if ((! open) && (driver)) |
| 396 | | { |
| 397 | | if (open_nops==0) |
| 398 | | { |
| 399 | | open=driver->read_toc(); |
| 400 | | } else |
| 401 | | { |
| 402 | | open_nops--; |
| 403 | | } |
| 404 | | } |
| 405 | | |
| 406 | | send_result(intr_complete); |
| 407 | | } |
| 408 | | |
| 409 | | void psxcd_device::cdcmd_setloc() |
| 410 | | { |
| 411 | | #ifdef debug_cdrom |
| 412 | | printf("cdrom: setloc %08x:%08x:%08x\n", |
| 413 | | cmdbuf[0], |
| 414 | | cmdbuf[1], |
| 415 | | cmdbuf[2]); |
| 416 | | #endif |
| 417 | | |
| 418 | | stop_read(); |
| 419 | | |
| 420 | | unsigned char l[3]; |
| 421 | | l[0]=bcd_to_decimal(cmdbuf[0]); |
| 422 | | l[1]=bcd_to_decimal(cmdbuf[1]); |
| 423 | | l[2]=bcd_to_decimal(cmdbuf[2]); |
| 424 | | |
| 425 | | if ((l[0]>0) || (l[1]>=2)) |
| 426 | | { |
| 427 | | loc[0]=l[0]; |
| 428 | | loc[1]=l[1]; |
| 429 | | loc[2]=l[2]; |
| 430 | | } else |
| 431 | | { |
| 432 | | printf("setloc out of range: %02d:%02d:%02d\n", |
| 433 | | l[0],l[1],l[2]); |
| 434 | | } |
| 435 | | |
| 436 | | send_result(intr_complete); |
| 437 | | } |
| 438 | | |
| 439 | | void psxcd_device::cdcmd_play() |
| 440 | | { |
| 441 | | #ifdef debug_cdrom |
| 442 | | printf("cdrom: play %02x %02x %02x => %d\n", loc[0], loc[1], loc[2], msf_to_sector(loc)); |
| 443 | | #endif |
| 444 | | |
| 445 | | curpos[0]=loc[0]; |
| 446 | | curpos[1]=loc[1]; |
| 447 | | curpos[2]=loc[2]; |
| 448 | | |
| 449 | | if ((curpos[0]==0) && |
| 450 | | (curpos[1]==0) && |
| 451 | | (curpos[2]==0)) |
| 452 | | { |
| 453 | | send_result(intr_acknowledge); |
| 454 | | } else |
| 455 | | { |
| 456 | | stop_read(); |
| 457 | | start_play(); |
| 458 | | send_result(intr_acknowledge); |
| 459 | | } |
| 460 | | } |
| 461 | | |
| 462 | | void psxcd_device::cdcmd_forward() |
| 463 | | { |
| 464 | | #ifdef debug_cdrom |
| 465 | | printf("cdrom: forward\n"); |
| 466 | | #endif |
| 467 | | } |
| 468 | | |
| 469 | | void psxcd_device::cdcmd_backward() |
| 470 | | { |
| 471 | | #ifdef debug_cdrom |
| 472 | | printf("cdrom: backward\n"); |
| 473 | | #endif |
| 474 | | } |
| 475 | | |
| 476 | | void psxcd_device::cdcmd_readn() |
| 477 | | { |
| 478 | | if (driver) |
| 479 | | { |
| 480 | | #ifdef debug_cdrom |
| 481 | | printf("cdrom: readn\n"); |
| 482 | | #endif |
| 483 | | |
| 484 | | curpos[0]=loc[0]; |
| 485 | | curpos[1]=loc[1]; |
| 486 | | curpos[2]=loc[2]; |
| 487 | | |
| 488 | | stop_read(); |
| 489 | | start_read(); |
| 490 | | send_result(intr_complete); |
| 491 | | } else |
| 492 | | { |
| 493 | | printf("read without driver\n"); |
| 494 | | send_result(intr_diskerror); |
| 495 | | } |
| 496 | | } |
| 497 | | |
| 498 | | void psxcd_device::cdcmd_standby() |
| 499 | | { |
| 500 | | #ifdef debug_cdrom |
| 501 | | printf("cdrom: standby\n"); |
| 502 | | #endif |
| 503 | | |
| 504 | | stop_read(); |
| 505 | | send_result(intr_acknowledge); |
| 506 | | } |
| 507 | | |
| 508 | | void psxcd_device::cdcmd_stop() |
| 509 | | { |
| 510 | | #ifdef debug_cdrom |
| 511 | | printf("cdrom: stop\n"); |
| 512 | | #endif |
| 513 | | |
| 514 | | stop_read(); |
| 515 | | send_result(intr_acknowledge); |
| 516 | | } |
| 517 | | |
| 518 | | void psxcd_device::cdcmd_pause() |
| 519 | | { |
| 520 | | #ifdef debug_cdrom |
| 521 | | printf("cdrom: pause\n"); |
| 522 | | #endif |
| 523 | | |
| 524 | | stop_read(); |
| 525 | | |
| 526 | | send_result(intr_acknowledge); |
| 527 | | } |
| 528 | | |
| 529 | | void psxcd_device::cdcmd_init() |
| 530 | | { |
| 531 | | #ifdef debug_cdrom |
| 532 | | printf("cdrom: init\n"); |
| 533 | | #endif |
| 534 | | |
| 535 | | stop_read(); |
| 536 | | mode=0; |
| 537 | | sr|=0x10; |
| 538 | | |
| 539 | | send_result(intr_acknowledge); |
| 540 | | } |
| 541 | | |
| 542 | | void psxcd_device::cdcmd_mute() |
| 543 | | { |
| 544 | | #ifdef debug_cdrom |
| 545 | | printf("cdrom: mute\n"); |
| 546 | | #endif |
| 547 | | |
| 548 | | send_result(intr_acknowledge); |
| 549 | | } |
| 550 | | |
| 551 | | void psxcd_device::cdcmd_demute() |
| 552 | | { |
| 553 | | #ifdef debug_cdrom |
| 554 | | printf("cdrom: demute\n"); |
| 555 | | #endif |
| 556 | | |
| 557 | | send_result(intr_acknowledge); |
| 558 | | } |
| 559 | | |
| 560 | | void psxcd_device::cdcmd_setfilter() |
| 561 | | { |
| 562 | | #ifdef debug_cdrom |
| 563 | | printf("cdrom: setfilter %08x,%08x\n",cmdbuf[0],cmdbuf[1]); |
| 564 | | #endif |
| 565 | | |
| 566 | | filter_file=cmdbuf[0]; |
| 567 | | filter_channel=cmdbuf[1]; |
| 568 | | |
| 569 | | send_result(intr_acknowledge); |
| 570 | | } |
| 571 | | |
| 572 | | void psxcd_device::cdcmd_setmode() |
| 573 | | { |
| 574 | | #ifdef debug_cdrom |
| 575 | | printf("cdrom: setmode %08x\n",cmdbuf[0]); |
| 576 | | #endif |
| 577 | | |
| 578 | | mode=cmdbuf[0]; |
| 579 | | |
| 580 | | switch ((mode&mode_size_mask)>>mode_size_shift) |
| 581 | | { |
| 582 | | case 1: |
| 583 | | secsize=2328; |
| 584 | | secskip=24; |
| 585 | | break; |
| 586 | | |
| 587 | | case 2: |
| 588 | | secsize=2340; |
| 589 | | secskip=12; |
| 590 | | break; |
| 591 | | |
| 592 | | default: |
| 593 | | secsize=2048; |
| 594 | | secskip=24; |
| 595 | | break; |
| 596 | | } |
| 597 | | |
| 598 | | send_result(intr_complete); |
| 599 | | } |
| 600 | | |
| 601 | | void psxcd_device::cdcmd_getparam() |
| 602 | | { |
| 603 | | unsigned char data[6]= |
| 604 | | { |
| 605 | | status, |
| 606 | | mode, |
| 607 | | filter_file, |
| 608 | | filter_channel, |
| 609 | | 0, |
| 610 | | 0 |
| 611 | | }; |
| 612 | | |
| 613 | | #ifdef debug_cdrom |
| 614 | | printf("cdrom: getparam [%02x %02x %02x %02x %02x %02x]\n", |
| 615 | | data[0], |
| 616 | | data[1], |
| 617 | | data[2], |
| 618 | | data[3], |
| 619 | | data[4], |
| 620 | | data[5]); |
| 621 | | #endif |
| 622 | | |
| 623 | | send_result(intr_complete,data,6); |
| 624 | | } |
| 625 | | |
| 626 | | #if 0 |
| 627 | | static void add_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2) |
| 628 | | { |
| 629 | | int f=src1[2]+src2[2], |
| 630 | | s=src1[1]+src2[1], |
| 631 | | m=src1[0]+src2[0]; |
| 632 | | while (f>=75) { s++; f-=75; } |
| 633 | | while (s>=60) { m++; s-=60; } |
| 634 | | |
| 635 | | dst[0]=m; |
| 636 | | dst[1]=s; |
| 637 | | dst[2]=f; |
| 638 | | } |
| 639 | | #endif |
| 640 | | static void sub_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2) |
| 641 | | { |
| 642 | | int f=src1[2]-src2[2], |
| 643 | | s=src1[1]-src2[1], |
| 644 | | m=src1[0]-src2[0]; |
| 645 | | while (f<0) { s--; f+=75; } |
| 646 | | while (s<0) { m--; s+=60; } |
| 647 | | |
| 648 | | if (m<0) |
| 649 | | m=s=f=0; |
| 650 | | |
| 651 | | dst[0]=m; |
| 652 | | dst[1]=s; |
| 653 | | dst[2]=f; |
| 654 | | } |
| 655 | | |
| 656 | | void psxcd_device::cdcmd_getlocl() |
| 657 | | { |
| 658 | | #ifdef debug_cdrom |
| 659 | | printf("cdrom: getlocl\n"); |
| 660 | | #endif |
| 661 | | |
| 662 | | #ifdef debug_cdrom |
| 663 | | printf("cdrom: getlocl [%02x %02x %02x %02x %02x %02x %02x %02x]\n", |
| 664 | | lastsechdr[0], |
| 665 | | lastsechdr[1], |
| 666 | | lastsechdr[2], |
| 667 | | lastsechdr[3], |
| 668 | | lastsechdr[4], |
| 669 | | lastsechdr[5], |
| 670 | | lastsechdr[6], |
| 671 | | lastsechdr[7]); |
| 672 | | #endif |
| 673 | | |
| 674 | | send_result(intr_complete,lastsechdr,8); |
| 675 | | } |
| 676 | | |
| 677 | | void psxcd_device::cdcmd_getlocp() |
| 678 | | { |
| 679 | | unsigned char tloc[3], |
| 680 | | twosec[3]={ 0,2,0 }; |
| 681 | | sub_loc(tloc,loc,twosec); |
| 682 | | |
| 683 | | unsigned char data[8]= |
| 684 | | { |
| 685 | | 0x01, // track |
| 686 | | 0x01, // index |
| 687 | | decimal_to_bcd(tloc[0]), // min |
| 688 | | decimal_to_bcd(tloc[1]), // sec |
| 689 | | decimal_to_bcd(tloc[2]), // frame |
| 690 | | decimal_to_bcd(loc[0]), // amin |
| 691 | | decimal_to_bcd(loc[1]), // asec |
| 692 | | decimal_to_bcd(loc[2]) // aframe |
| 693 | | }; |
| 694 | | |
| 695 | | //unsigned char data[8]={ 2,1,0,0xff,0xff,0xff,0xff,0xff }; |
| 696 | | |
| 697 | | #ifdef debug_cdrom |
| 698 | | printf("cdrom: getlocp [%02x %02x %02x %02x %02x %02x %02x %02x]\n", |
| 699 | | data[0], |
| 700 | | data[1], |
| 701 | | data[2], |
| 702 | | data[3], |
| 703 | | data[4], |
| 704 | | data[5], |
| 705 | | data[6], |
| 706 | | data[7]); |
| 707 | | #endif |
| 708 | | |
| 709 | | send_result(intr_complete,data,8); |
| 710 | | } |
| 711 | | |
| 712 | | void psxcd_device::cdcmd_illegal() |
| 713 | | { |
| 714 | | assert(0); |
| 715 | | } |
| 716 | | |
| 717 | | void psxcd_device::cdcmd_gettn() |
| 718 | | { |
| 719 | | #ifdef debug_cdrom |
| 720 | | printf("cdrom: gettn\n"); |
| 721 | | #endif |
| 722 | | |
| 723 | | assert(driver); |
| 724 | | |
| 725 | | unsigned char data[3]= |
| 726 | | { |
| 727 | | status, |
| 728 | | decimal_to_bcd(driver->get_first_track()), |
| 729 | | decimal_to_bcd(driver->get_num_tracks()) |
| 730 | | }; |
| 731 | | |
| 732 | | //stop_read(); |
| 733 | | send_result(intr_acknowledge,data,3); |
| 734 | | } |
| 735 | | |
| 736 | | void psxcd_device::cdcmd_gettd() |
| 737 | | { |
| 738 | | unsigned char addr[3]; |
| 739 | | driver->get_track_address(bcd_to_decimal(cmdbuf[0]), addr); |
| 740 | | |
| 741 | | unsigned char data[3]= |
| 742 | | { |
| 743 | | status, |
| 744 | | decimal_to_bcd(addr[0]), |
| 745 | | decimal_to_bcd(addr[1]) |
| 746 | | }; |
| 747 | | |
| 748 | | #ifdef debug_cdrom |
| 749 | | printf("cdrom: gettd %02x [%02x %02x %02x]\n", |
| 750 | | cmdbuf[0], |
| 751 | | data[0], |
| 752 | | data[1], |
| 753 | | data[2]); |
| 754 | | #endif |
| 755 | | |
| 756 | | //stop_read(); |
| 757 | | send_result(intr_acknowledge,data,3); |
| 758 | | } |
| 759 | | |
| 760 | | void psxcd_device::cdcmd_seekl() |
| 761 | | { |
| 762 | | #ifdef debug_cdrom |
| 763 | | printf("cdrom: seekl [%02d:%02d:%02d]\n",loc[0],loc[1],loc[2]); |
| 764 | | #endif |
| 765 | | |
| 766 | | curpos[0]=loc[0]; |
| 767 | | curpos[1]=loc[1]; |
| 768 | | curpos[2]=loc[2]; |
| 769 | | |
| 770 | | send_result(intr_acknowledge); |
| 771 | | } |
| 772 | | |
| 773 | | void psxcd_device::cdcmd_seekp() |
| 774 | | { |
| 775 | | #ifdef debug_cdrom |
| 776 | | printf("cdrom: seekp\n"); |
| 777 | | #endif |
| 778 | | |
| 779 | | curpos[0]=loc[0]; |
| 780 | | curpos[1]=loc[1]; |
| 781 | | curpos[2]=loc[2]; |
| 782 | | |
| 783 | | send_result(intr_acknowledge); |
| 784 | | } |
| 785 | | |
| 786 | | void psxcd_device::cdcmd_test() |
| 787 | | { |
| 788 | | #ifdef debug_cdrom |
| 789 | | printf("cdrom: test %08x\n",cmdbuf[0]); |
| 790 | | #endif |
| 791 | | |
| 792 | | static unsigned char data[4]= |
| 793 | | { |
| 794 | | 0x95, |
| 795 | | 0x07, |
| 796 | | 0x06, |
| 797 | | 0xff |
| 798 | | }; |
| 799 | | |
| 800 | | send_result(intr_complete,data,4); |
| 801 | | } |
| 802 | | |
| 803 | | void psxcd_device::cdcmd_id() |
| 804 | | { |
| 805 | | #ifdef debug_cdrom |
| 806 | | printf("cdrom: id\n"); |
| 807 | | #endif |
| 808 | | |
| 809 | | if (! open) |
| 810 | | { |
| 811 | | if (driver) |
| 812 | | open=driver->read_toc(); |
| 813 | | } |
| 814 | | |
| 815 | | if (open) |
| 816 | | { |
| 817 | | static unsigned char gamedata[8] = { 0x08, 0x00, 0x00, 0x00, 'S', 'C', 'E', 'A' }; |
| 818 | | static unsigned char audiodata[8] = { 0x08, 0x90, 0x00, 0x00, 'S', 'C', 'E', 'A' }; // drops into the audio CD player. 08 80 goes to the menu. |
| 819 | | |
| 820 | | if (cdrom_get_track_type(m_cd, 0) == CD_TRACK_AUDIO) |
| 821 | | { |
| 822 | | send_result(intr_acknowledge,audiodata,8); |
| 823 | | } |
| 824 | | else |
| 825 | | { |
| 826 | | send_result(intr_acknowledge,gamedata,8); |
| 827 | | } |
| 828 | | } else |
| 829 | | { |
| 830 | | status=status_error|status_shellopen; |
| 831 | | send_result(intr_diskerror); |
| 832 | | } |
| 833 | | } |
| 834 | | |
| 835 | | void psxcd_device::cdcmd_reads() |
| 836 | | { |
| 837 | | curpos[0]=loc[0]; |
| 838 | | curpos[1]=loc[1]; |
| 839 | | curpos[2]=loc[2]; |
| 840 | | |
| 841 | | #ifdef skip_reads |
| 842 | | #ifdef debug_cdrom |
| 843 | | log("cdrom: reads [SKIPPING - RETURN COMPLETE]\n"); |
| 844 | | #endif |
| 845 | | |
| 846 | | send_result(intr_complete); |
| 847 | | #else |
| 848 | | #ifdef debug_cdrom |
| 849 | | printf("cdrom: reads\n"); |
| 850 | | #endif |
| 851 | | |
| 852 | | stop_read(); |
| 853 | | start_streaming(); |
| 854 | | #endif |
| 855 | | } |
| 856 | | |
| 857 | | void psxcd_device::cdcmd_reset() |
| 858 | | { |
| 859 | | #ifdef debug_cdrom |
| 860 | | printf("cdrom: reset\n"); |
| 861 | | #endif |
| 862 | | } |
| 863 | | |
| 864 | | void psxcd_device::cdcmd_readtoc() |
| 865 | | { |
| 866 | | #ifdef debug_cdrom |
| 867 | | printf("cdrom: readtoc\n"); |
| 868 | | #endif |
| 869 | | |
| 870 | | static unsigned char data[4]= |
| 871 | | { |
| 872 | | 0x00, |
| 873 | | 0x00, |
| 874 | | 0xff, |
| 875 | | 0xfe |
| 876 | | }; |
| 877 | | |
| 878 | | send_result(intr_complete|0x10,data,2); |
| 879 | | } |
| 880 | | |
| 881 | | // |
| 882 | | // |
| 883 | | // |
| 884 | | |
| 885 | | void psxcd_device::cmd_complete(command_result *res) |
| 886 | | { |
| 887 | | bool doint=((res->res&0x10)==0); |
| 888 | | #ifdef debug_cdrom |
| 889 | | command_result *rf; |
| 890 | | #endif |
| 891 | | |
| 892 | | if (doint) |
| 893 | | { |
| 894 | | psx_irq_set(machine(), 0x0004); |
| 895 | | } |
| 896 | | |
| 897 | | add_result(res); |
| 898 | | |
| 899 | | #ifdef debug_cdrom |
| 900 | | if (doint) |
| 901 | | { |
| 902 | | printf("cdrom: irq ["); |
| 903 | | for (rf=res_queue; ((rf) && (rf->next)); rf=rf->next); |
| 904 | | printf("%d ",rf->res); |
| 905 | | printf("]\n"); |
| 906 | | } |
| 907 | | #endif |
| 908 | | } |
| 909 | | |
| 910 | | // |
| 911 | | // |
| 912 | | // |
| 913 | | |
| 914 | | void psxcd_device::add_result(command_result *res) |
| 915 | | { |
| 916 | | command_result *rf; |
| 917 | | |
| 918 | | if (res_queue) |
| 919 | | { |
| 920 | | for (rf=res_queue; rf->next; rf=rf->next); |
| 921 | | rf->next=res; |
| 922 | | } else |
| 923 | | { |
| 924 | | res_queue=res; |
| 925 | | } |
| 926 | | |
| 927 | | res->next=NULL; |
| 928 | | } |
| 929 | | |
| 930 | | // |
| 931 | | // |
| 932 | | // |
| 933 | | |
| 934 | | event *psxcd_device::send_result(const unsigned int res, |
| 935 | | const unsigned char *data, |
| 936 | | const unsigned int sz, |
| 937 | | const unsigned int delay) |
| 938 | | { |
| 939 | | // Update shell open status |
| 940 | | |
| 941 | | if (! open) |
| 942 | | { |
| 943 | | status=status_error|status_shellopen; |
| 944 | | } |
| 945 | | else |
| 946 | | { |
| 947 | | if (status&status_shellopen) |
| 948 | | status=status_standby; |
| 949 | | } |
| 950 | | |
| 951 | | // Prepare event |
| 952 | | |
| 953 | | event *ev=new event; |
| 954 | | ev->t=delay; |
| 955 | | ev->type=event_cmd_complete; |
| 956 | | |
| 957 | | command_result *cr=(command_result *)ev->data; |
| 958 | | |
| 959 | | cr->res=res; |
| 960 | | if (sz) |
| 961 | | { |
| 962 | | assert(sz<sizeof(cr->data)); |
| 963 | | memcpy(cr->data,data,sz); |
| 964 | | cr->sz=sz; |
| 965 | | } else |
| 966 | | { |
| 967 | | cr->data[0]=status; |
| 968 | | cr->sz=1; |
| 969 | | } |
| 970 | | |
| 971 | | // Avoid returning results after sector read results - |
| 972 | | // delay the sector read slightly if necessary |
| 973 | | |
| 974 | | UINT64 systime = machine().device<cpu_device>("maincpu")->total_cycles(); |
| 975 | | if ((next_read_event) && ((systime+ev->t)>(next_sector_t))) |
| 976 | | { |
| 977 | | UINT32 hz = m_sysclock / (delay + 2000); |
| 978 | | next_read_event->timer->adjust(attotime::from_hz(hz), 0, attotime::never); |
| 979 | | |
| 980 | | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 981 | | { |
| 982 | | if (m_eventfortimer[i] == next_read_event) |
| 983 | | { |
| 984 | | printf("Adjusting timer %d to %d hz]n", i, hz); |
| 985 | | } |
| 986 | | } |
| 987 | | } |
| 988 | | |
| 989 | | add_system_event(ev); |
| 990 | | return ev; |
| 991 | | } |
| 992 | | |
| 993 | | // |
| 994 | | // |
| 995 | | // |
| 996 | | |
| 997 | | void psxcd_device::start_dma(UINT8 *mainram, UINT32 size) |
| 998 | | { |
| 999 | | if ((int)size>secleft) |
| 1000 | | { |
| 1001 | | printf("cdrom: dma past end of sector (secleft=%d sz=%d)\n",secleft,size); |
| 1002 | | } |
| 1003 | | |
| 1004 | | // printf("cdrom: start dma %d bytes, %d remaining, secptr %p\n", size, secleft, secptr); |
| 1005 | | #ifdef debug_cdrom |
| 1006 | | if (size==12) |
| 1007 | | { |
| 1008 | | char poo[1024],*pp=poo; |
| 1009 | | for (unsigned int i=0; i<12; i++) |
| 1010 | | { |
| 1011 | | sprintf(pp,"%02x ",secptr[i]); |
| 1012 | | pp+=3; |
| 1013 | | } |
| 1014 | | printf("cdrom: data=%s\n",poo); |
| 1015 | | } |
| 1016 | | #endif |
| 1017 | | |
| 1018 | | memcpy(mainram, secptr, size); |
| 1019 | | memset(secptr, 0xff, size); |
| 1020 | | |
| 1021 | | secptr += size; |
| 1022 | | secleft -= size; |
| 1023 | | |
| 1024 | | if (secleft<0) secleft=0; |
| 1025 | | if (secleft==0) sr&=~0x40; |
| 1026 | | } |
| 1027 | | |
| 1028 | | // |
| 1029 | | // |
| 1030 | | // |
| 1031 | | |
| 1032 | | void psxcd_device::prefetch_next_sector() |
| 1033 | | { |
| 1034 | | unsigned int pos=msf_to_sector(curpos); |
| 1035 | | assert(driver); |
| 1036 | | driver->prefetch_sector(pos); |
| 1037 | | } |
| 1038 | | |
| 1039 | | // |
| 1040 | | // |
| 1041 | | // |
| 1042 | | |
| 1043 | | bool psxcd_device::read_next_sector(const bool block) |
| 1044 | | { |
| 1045 | | unsigned int pos=msf_to_sector(curpos); |
| 1046 | | unsigned char *buf=&secbuf[sechead*raw_sector_size]; |
| 1047 | | assert(driver); |
| 1048 | | assert(secin<sector_buffer_size); |
| 1049 | | |
| 1050 | | // printf("read_next_sector: sec %d, sechead %d, raw_sector_size %d\n", pos, sechead, raw_sector_size); |
| 1051 | | if (driver->read_sector(pos, buf, block)) |
| 1052 | | { |
| 1053 | | // printf("buf contents = %02x %02x | %02x %02x\n", buf[0], buf[1], buf[0x20], buf[0x21]); |
| 1054 | | |
| 1055 | | sechead=(sechead+1)&(sector_buffer_size-1); |
| 1056 | | secin++; |
| 1057 | | |
| 1058 | | memcpy(lastsechdr,&secbuf[raw_sector_size*sectail]+12,8); |
| 1059 | | |
| 1060 | | return true; |
| 1061 | | } else |
| 1062 | | { |
| 1063 | | return false; |
| 1064 | | } |
| 1065 | | } |
| 1066 | | |
| 1067 | | // |
| 1068 | | // |
| 1069 | | // |
| 1070 | | |
| 1071 | | void psxcd_device::read_sector() |
| 1072 | | { |
| 1073 | | next_read_event=NULL; |
| 1074 | | |
| 1075 | | if (status & status_reading) |
| 1076 | | { |
| 1077 | | bool isend=false; |
| 1078 | | |
| 1079 | | if (read_next_sector(false)) |
| 1080 | | { |
| 1081 | | unsigned char *rawsec; |
| 1082 | | |
| 1083 | | if ((mode&mode_adpcm) && (streaming)) |
| 1084 | | { |
| 1085 | | rawsec=&secbuf[raw_sector_size*sectail]; |
| 1086 | | secptr=rawsec+24; |
| 1087 | | secleft=2048; |
| 1088 | | } |
| 1089 | | else |
| 1090 | | { |
| 1091 | | rawsec=&secbuf[raw_sector_size*sectail]; |
| 1092 | | secptr=rawsec+secskip; |
| 1093 | | secleft=secsize; |
| 1094 | | } |
| 1095 | | |
| 1096 | | secin--; |
| 1097 | | sectail=(sectail+1)&(sector_buffer_size-1); |
| 1098 | | |
| 1099 | | // |
| 1100 | | |
| 1101 | | bool isxa=false; |
| 1102 | | |
| 1103 | | subheader *sub=(subheader *)(rawsec+16); |
| 1104 | | |
| 1105 | | #ifdef dump_subheader |
| 1106 | | printf("cdrom: subheader file=%02x chan=%02x submode=%02x coding=%02x [%02x%02x%02x%02x]\n", |
| 1107 | | sub->file, |
| 1108 | | sub->channel, |
| 1109 | | sub->submode, |
| 1110 | | sub->coding, |
| 1111 | | rawsec[0xc], |
| 1112 | | rawsec[0xd], |
| 1113 | | rawsec[0xe], |
| 1114 | | rawsec[0xf]); |
| 1115 | | #endif |
| 1116 | | |
| 1117 | | status&=~status_playing; |
| 1118 | | isxa=((mode&mode_adpcm) && (sub->submode&submode_audio)); |
| 1119 | | |
| 1120 | | if (((mode&mode_channel)==0) || |
| 1121 | | ((sub->file==filter_file) && (sub->channel==filter_channel))) |
| 1122 | | { |
| 1123 | | if (isxa) |
| 1124 | | { |
| 1125 | | if (sub->submode&submode_eof) |
| 1126 | | { |
| 1127 | | isend=true; |
| 1128 | | //printf("end of file\n"); |
| 1129 | | } |
| 1130 | | |
| 1131 | | #ifndef disable_xa_prefetch |
| 1132 | | unsigned int cursec=msf_to_sector(curpos); |
| 1133 | | |
| 1134 | | if (xa_prefetch_sector==-1) |
| 1135 | | { |
| 1136 | | xa_prefetch_sector=cursec; |
| 1137 | | machine().device<spu_device>("spu")->flush_xa(); |
| 1138 | | } |
| 1139 | | |
| 1140 | | unsigned char *xaptr; |
| 1141 | | unsigned int xasecsz; |
| 1142 | | |
| 1143 | | while (1) |
| 1144 | | { |
| 1145 | | int dist=xa_prefetch_sector-cursec; |
| 1146 | | if (dist>max_xa_prefetch_distance) break; |
| 1147 | | |
| 1148 | | xaptr=driver->get_prefetch_sector(xa_prefetch_sector,&xasecsz); |
| 1149 | | if (! xaptr) break; |
| 1150 | | |
| 1151 | | switch (xasecsz) |
| 1152 | | { |
| 1153 | | case 2336: |
| 1154 | | break; |
| 1155 | | |
| 1156 | | default: |
| 1157 | | xaptr+=16; |
| 1158 | | break; |
| 1159 | | } |
| 1160 | | |
| 1161 | | subheader *xasub=(subheader *)xaptr; |
| 1162 | | |
| 1163 | | if ((xasub->submode&submode_audio) && |
| 1164 | | (((mode&mode_channel)==0) || |
| 1165 | | ((xasub->file==sub->file) && |
| 1166 | | (xasub->channel==sub->channel)))) |
| 1167 | | { |
| 1168 | | if (! machine().device<spu_device>("spu")->play_xa(xa_prefetch_sector,xaptr)) |
| 1169 | | break; |
| 1170 | | } |
| 1171 | | xa_prefetch_sector++; |
| 1172 | | } |
| 1173 | | #else |
| 1174 | | machine().device<spu_device>("spu")->play_xa(0,rawsec+16); |
| 1175 | | #endif |
| 1176 | | |
| 1177 | | status|=status_playing; |
| 1178 | | } |
| 1179 | | } |
| 1180 | | |
| 1181 | | if ((mode&mode_autopause)==0) |
| 1182 | | isend=false; |
| 1183 | | |
| 1184 | | // |
| 1185 | | |
| 1186 | | curpos[2]++; |
| 1187 | | if (curpos[2]==75) |
| 1188 | | { |
| 1189 | | curpos[2]=0; |
| 1190 | | curpos[1]++; |
| 1191 | | if (curpos[1]==60) |
| 1192 | | { |
| 1193 | | curpos[1]=0; |
| 1194 | | curpos[0]++; |
| 1195 | | } |
| 1196 | | } |
| 1197 | | |
| 1198 | | loc[0]=curpos[0]; |
| 1199 | | loc[1]=curpos[1]; |
| 1200 | | loc[2]=curpos[2]; |
| 1201 | | |
| 1202 | | // |
| 1203 | | |
| 1204 | | command_result *res=new command_result; |
| 1205 | | res->res=isend?intr_dataend:intr_dataready; |
| 1206 | | res->data[0]=status; |
| 1207 | | res->sz=1; |
| 1208 | | |
| 1209 | | sr|=0x40; |
| 1210 | | |
| 1211 | | if ((streaming) && (isxa)) |
| 1212 | | { |
| 1213 | | global_free(res); |
| 1214 | | res=NULL; |
| 1215 | | } |
| 1216 | | |
| 1217 | | if (res) |
| 1218 | | { |
| 1219 | | #ifdef debug_cdrom |
| 1220 | | printf("cdrom:: data ready\n"); |
| 1221 | | #endif |
| 1222 | | |
| 1223 | | cmd_complete(res); |
| 1224 | | } |
| 1225 | | } |
| 1226 | | |
| 1227 | | if (! isend) |
| 1228 | | { |
| 1229 | | unsigned int cyc=read_sector_cycles; |
| 1230 | | if (mode&mode_double_speed) cyc>>=1; |
| 1231 | | |
| 1232 | | next_sector_t+=cyc; |
| 1233 | | |
| 1234 | | event *ev=new event; |
| 1235 | | ev->t=cyc; |
| 1236 | | ev->type=event_read_sector; |
| 1237 | | next_read_event=ev; |
| 1238 | | add_system_event(ev); |
| 1239 | | |
| 1240 | | //read_next_sector(); |
| 1241 | | } else |
| 1242 | | { |
| 1243 | | printf("autopause xa\n"); |
| 1244 | | stop_read(); |
| 1245 | | } |
| 1246 | | } |
| 1247 | | } |
| 1248 | | |
| 1249 | | // |
| 1250 | | // |
| 1251 | | // |
| 1252 | | |
| 1253 | | bool psxcd_device::play_cdda_sector(const unsigned int sector, |
| 1254 | | unsigned char *rawsec) |
| 1255 | | { |
| 1256 | | bool isdata=true; |
| 1257 | | |
| 1258 | | if (rawsec[0]!=0) |
| 1259 | | { |
| 1260 | | isdata=false; |
| 1261 | | } else |
| 1262 | | { |
| 1263 | | for (int i=0; i<10; i++) |
| 1264 | | if (rawsec[i+1]!=0xff) |
| 1265 | | { |
| 1266 | | isdata=false; |
| 1267 | | break; |
| 1268 | | } |
| 1269 | | } |
| 1270 | | |
| 1271 | | if (! isdata) |
| 1272 | | { |
| 1273 | | return machine().device<spu_device>("spu")->play_cdda(sector,rawsec); |
| 1274 | | } else |
| 1275 | | { |
| 1276 | | return true; |
| 1277 | | } |
| 1278 | | } |
| 1279 | | |
| 1280 | | // |
| 1281 | | // |
| 1282 | | // |
| 1283 | | |
| 1284 | | void psxcd_device::play_sector() |
| 1285 | | { |
| 1286 | | next_read_event=NULL; |
| 1287 | | |
| 1288 | | if (status&status_playing) |
| 1289 | | { |
| 1290 | | #ifdef disable_cdda_prefetch |
| 1291 | | unsigned char *rawsec=&secbuf[raw_sector_size*sectail]; |
| 1292 | | #endif |
| 1293 | | secin--; |
| 1294 | | sectail=(sectail+1)&(sector_buffer_size-1); |
| 1295 | | |
| 1296 | | // |
| 1297 | | |
| 1298 | | #ifndef disable_cdda_prefetch |
| 1299 | | unsigned int cursec=msf_to_sector(curpos); |
| 1300 | | |
| 1301 | | if (cdda_prefetch_sector==-1) |
| 1302 | | { |
| 1303 | | cdda_prefetch_sector=cursec; |
| 1304 | | machine().device<spu_device>("spu")->flush_cdda(); |
| 1305 | | } |
| 1306 | | |
| 1307 | | unsigned char *cddaptr; |
| 1308 | | // bool full=false; |
| 1309 | | unsigned int cddasecsz; |
| 1310 | | |
| 1311 | | while (1) |
| 1312 | | { |
| 1313 | | int dist=cdda_prefetch_sector-cursec; |
| 1314 | | if (dist>max_cdda_prefetch_distance) break; |
| 1315 | | |
| 1316 | | cddaptr=driver->get_prefetch_sector(cdda_prefetch_sector,&cddasecsz); |
| 1317 | | if (! cddaptr) break; |
| 1318 | | |
| 1319 | | if (! play_cdda_sector(cdda_prefetch_sector,cddaptr)) |
| 1320 | | break; |
| 1321 | | |
| 1322 | | cdda_prefetch_sector++; |
| 1323 | | } |
| 1324 | | #else |
| 1325 | | play_cdda_sector(0,rawsec); |
| 1326 | | #endif |
| 1327 | | |
| 1328 | | // |
| 1329 | | |
| 1330 | | curpos[2]++; |
| 1331 | | if (curpos[2]==75) |
| 1332 | | { |
| 1333 | | curpos[2]=0; |
| 1334 | | curpos[1]++; |
| 1335 | | if (curpos[1]==60) |
| 1336 | | { |
| 1337 | | curpos[1]=0; |
| 1338 | | curpos[0]++; |
| 1339 | | } |
| 1340 | | } |
| 1341 | | |
| 1342 | | loc[0]=curpos[0]; |
| 1343 | | loc[1]=curpos[1]; |
| 1344 | | loc[2]=curpos[2]; |
| 1345 | | |
| 1346 | | // |
| 1347 | | |
| 1348 | | if (mode&mode_autopause) |
| 1349 | | { |
| 1350 | | if (msf_to_sector(loc)>=autopause_sector) |
| 1351 | | { |
| 1352 | | printf("autopause cdda\n"); |
| 1353 | | |
| 1354 | | command_result *res=new command_result; |
| 1355 | | res->res=intr_dataend; |
| 1356 | | res->data[0]=status_standby; |
| 1357 | | res->sz=1; |
| 1358 | | cmd_complete(res); |
| 1359 | | stop_read(); |
| 1360 | | return; |
| 1361 | | } |
| 1362 | | } |
| 1363 | | |
| 1364 | | if (mode&mode_report) |
| 1365 | | { |
| 1366 | | command_result *res=new command_result; |
| 1367 | | res->res=intr_complete; //dataready; |
| 1368 | | |
| 1369 | | res->data[0]=status_playing|status_standby; |
| 1370 | | res->data[1]=0x01; |
| 1371 | | res->data[2]=0x80; |
| 1372 | | res->data[3]=decimal_to_bcd(loc[0]); |
| 1373 | | res->data[4]=decimal_to_bcd(loc[1])|0x80; |
| 1374 | | res->data[5]=decimal_to_bcd(loc[2]); |
| 1375 | | |
| 1376 | | res->sz=8; |
| 1377 | | |
| 1378 | | cmd_complete(res); |
| 1379 | | } |
| 1380 | | |
| 1381 | | unsigned int cyc=read_sector_cycles; |
| 1382 | | |
| 1383 | | event *ev=new event; |
| 1384 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1385 | | ev->type=event_play_sector; |
| 1386 | | |
| 1387 | | next_sector_t+=cyc; |
| 1388 | | |
| 1389 | | next_read_event=ev; |
| 1390 | | add_system_event(ev); |
| 1391 | | |
| 1392 | | read_next_sector(); |
| 1393 | | } |
| 1394 | | } |
| 1395 | | |
| 1396 | | |
| 1397 | | // |
| 1398 | | // |
| 1399 | | // |
| 1400 | | |
| 1401 | | void psxcd_device::preread_sector() |
| 1402 | | { |
| 1403 | | next_read_event=NULL; |
| 1404 | | |
| 1405 | | // |
| 1406 | | |
| 1407 | | event *ev=new event; |
| 1408 | | |
| 1409 | | unsigned int pos=msf_to_sector(curpos); |
| 1410 | | unsigned char *buf=&secbuf[sechead*raw_sector_size]; |
| 1411 | | if (! driver->read_sector(pos,buf,false)) |
| 1412 | | { |
| 1413 | | ev->t=(m_sysclock/60); |
| 1414 | | ev->type=event_preread_sector; |
| 1415 | | |
| 1416 | | unsigned int cyc=read_sector_cycles; |
| 1417 | | if (mode&mode_double_speed) cyc>>=1; |
| 1418 | | next_sector_t=ev->t+(cyc-preread_delay)+machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1419 | | } else |
| 1420 | | { |
| 1421 | | memcpy(lastsechdr,buf+12,8); |
| 1422 | | |
| 1423 | | // |
| 1424 | | |
| 1425 | | command_result *res=new command_result; |
| 1426 | | res->res=intr_complete; |
| 1427 | | res->data[0]=status; |
| 1428 | | res->sz=1; |
| 1429 | | |
| 1430 | | #ifdef debug_cdrom |
| 1431 | | printf("cdrom: read acknowledge\n"); |
| 1432 | | #endif |
| 1433 | | |
| 1434 | | cmd_complete(res); |
| 1435 | | |
| 1436 | | // |
| 1437 | | |
| 1438 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1439 | | ev->type=event_read_sector; |
| 1440 | | |
| 1441 | | //read_next_sector(); |
| 1442 | | } |
| 1443 | | |
| 1444 | | next_read_event=ev; |
| 1445 | | add_system_event(ev); |
| 1446 | | } |
| 1447 | | |
| 1448 | | // |
| 1449 | | // |
| 1450 | | // |
| 1451 | | |
| 1452 | | void psxcd_device::start_read() |
| 1453 | | { |
| 1454 | | #ifdef debug_cdrom |
| 1455 | | printf("cdrom: start read\n"); |
| 1456 | | #endif |
| 1457 | | |
| 1458 | | assert((status&(status_reading|status_playing))==0); |
| 1459 | | |
| 1460 | | status|=status_reading; |
| 1461 | | |
| 1462 | | secin=sechead=sectail=0; |
| 1463 | | xa_prefetch_sector=-1; |
| 1464 | | |
| 1465 | | unsigned int cyc=read_sector_cycles; |
| 1466 | | if (mode&mode_double_speed) cyc>>=1; |
| 1467 | | |
| 1468 | | INT64 systime=machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1469 | | |
| 1470 | | systime+=start_read_delay; |
| 1471 | | |
| 1472 | | event *ev=new event; |
| 1473 | | ev->t=start_read_delay+preread_delay; |
| 1474 | | ev->type=event_preread_sector; |
| 1475 | | |
| 1476 | | next_sector_t=systime+cyc; |
| 1477 | | next_read_event=ev; |
| 1478 | | add_system_event(ev); |
| 1479 | | |
| 1480 | | prefetch_next_sector(); |
| 1481 | | } |
| 1482 | | |
| 1483 | | // |
| 1484 | | // |
| 1485 | | // |
| 1486 | | |
| 1487 | | void psxcd_device::start_streaming() |
| 1488 | | { |
| 1489 | | assert(! streaming); |
| 1490 | | |
| 1491 | | streaming=true; |
| 1492 | | start_read(); |
| 1493 | | } |
| 1494 | | |
| 1495 | | // |
| 1496 | | // |
| 1497 | | // |
| 1498 | | |
| 1499 | | void psxcd_device::start_play() |
| 1500 | | { |
| 1501 | | #ifdef debug_cdrom |
| 1502 | | printf("cdrom: start play\n"); |
| 1503 | | #endif |
| 1504 | | |
| 1505 | | status|=status_playing; |
| 1506 | | |
| 1507 | | secin=sechead=sectail=0; |
| 1508 | | cdda_prefetch_sector=-1; |
| 1509 | | |
| 1510 | | if (mode&mode_autopause) |
| 1511 | | { |
| 1512 | | unsigned int pos=msf_to_sector(curpos); |
| 1513 | | driver->find_track(pos+150,NULL,&autopause_sector); |
| 1514 | | // printf("pos=%d auto=%d\n",pos,autopause_sector); |
| 1515 | | } |
| 1516 | | |
| 1517 | | unsigned int cyc=read_sector_cycles; |
| 1518 | | |
| 1519 | | next_sector_t=machine().device<cpu_device>("maincpu")->total_cycles()+cyc; |
| 1520 | | |
| 1521 | | event *ev=new event; |
| 1522 | | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1523 | | ev->type=event_play_sector; |
| 1524 | | |
| 1525 | | next_sector_t+=cyc; |
| 1526 | | |
| 1527 | | next_read_event=ev; |
| 1528 | | add_system_event(ev); |
| 1529 | | |
| 1530 | | read_next_sector(); |
| 1531 | | } |
| 1532 | | |
| 1533 | | // |
| 1534 | | // |
| 1535 | | // |
| 1536 | | |
| 1537 | | void psxcd_device::stop_read() |
| 1538 | | { |
| 1539 | | #ifdef debug_cdrom |
| 1540 | | if (status&status_reading) |
| 1541 | | printf("cdrom: stop read\n"); |
| 1542 | | #endif |
| 1543 | | status&=~(status_reading|status_playing); |
| 1544 | | streaming=false; |
| 1545 | | |
| 1546 | | if (next_read_event) |
| 1547 | | { |
| 1548 | | next_read_event->timer->adjust(attotime::never, 0, attotime::never); |
| 1549 | | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 1550 | | { |
| 1551 | | if (m_timers[i] == next_read_event->timer) |
| 1552 | | { |
| 1553 | | m_timerinuse[i] = false; |
| 1554 | | m_eventfortimer[i] = false; |
| 1555 | | break; |
| 1556 | | } |
| 1557 | | } |
| 1558 | | global_free(next_read_event); |
| 1559 | | next_read_event=NULL; |
| 1560 | | } |
| 1561 | | |
| 1562 | | unsigned int sector=msf_to_sector(curpos); |
| 1563 | | machine().device<spu_device>("spu")->flush_xa(sector); |
| 1564 | | machine().device<spu_device>("spu")->flush_cdda(sector); |
| 1565 | | } |
| 1566 | | |
| 1567 | | // |
| 1568 | | // |
| 1569 | | // |
| 1570 | | |
| 1571 | | void psxcd_device::set_driver(cdrom_driver *d) |
| 1572 | | { |
| 1573 | | char err[1024]; |
| 1574 | | |
| 1575 | | if (d) |
| 1576 | | { |
| 1577 | | if (d->is_usable(err,1024)) |
| 1578 | | { |
| 1579 | | driver=d; |
| 1580 | | open=false; |
| 1581 | | |
| 1582 | | if (! first_open) |
| 1583 | | { |
| 1584 | | command_result *res=new command_result; |
| 1585 | | res->res=intr_acknowledge; |
| 1586 | | res->data[0]=status_standby; |
| 1587 | | res->sz=1; |
| 1588 | | |
| 1589 | | cmd_complete(res); |
| 1590 | | |
| 1591 | | open_nops=10; |
| 1592 | | } |
| 1593 | | |
| 1594 | | first_open=false; |
| 1595 | | } |
| 1596 | | } else |
| 1597 | | { |
| 1598 | | driver=NULL; |
| 1599 | | open=false; |
| 1600 | | |
| 1601 | | command_result *res=new command_result; |
| 1602 | | res->res=intr_acknowledge; |
| 1603 | | res->data[0]=status_shellopen; |
| 1604 | | res->sz=1; |
| 1605 | | |
| 1606 | | cmd_complete(res); |
| 1607 | | } |
| 1608 | | } |
| 1609 | | |
| 1610 | | // |
| 1611 | | // |
| 1612 | | // |
| 1613 | | void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 1614 | | { |
| 1615 | | event *ev = m_eventfortimer[tid]; |
| 1616 | | |
| 1617 | | // printf("timer %d fired, performing event type %d\n", tid, ev->type); |
| 1618 | | |
| 1619 | | switch (ev->type) |
| 1620 | | { |
| 1621 | | case event_cmd_complete: |
| 1622 | | { |
| 1623 | | #ifdef debug_cdrom |
| 1624 | | printf("cdrom:: event cmd complete\n"); |
| 1625 | | #endif |
| 1626 | | |
| 1627 | | command_result *res=new command_result; |
| 1628 | | memcpy(res,ev->data,sizeof(command_result)); |
| 1629 | | cmd_complete(res); |
| 1630 | | break; |
| 1631 | | } |
| 1632 | | |
| 1633 | | case event_preread_sector: |
| 1634 | | preread_sector(); |
| 1635 | | break; |
| 1636 | | |
| 1637 | | case event_read_sector: |
| 1638 | | read_sector(); |
| 1639 | | break; |
| 1640 | | |
| 1641 | | case event_play_sector: |
| 1642 | | play_sector(); |
| 1643 | | break; |
| 1644 | | } |
| 1645 | | |
| 1646 | | // free the timer |
| 1647 | | // printf("Freeing timer %d\n", tid); |
| 1648 | | m_timers[tid]->adjust(attotime::never, 0, attotime::never); |
| 1649 | | m_timerinuse[tid] = false; |
| 1650 | | m_eventfortimer[tid] = NULL; |
| 1651 | | |
| 1652 | | global_free(ev); |
| 1653 | | } |
| 1654 | | |
| 1655 | | void psxcd_device::add_system_event(event *ev) |
| 1656 | | { |
| 1657 | | emu_timer *timer = NULL; |
| 1658 | | int tnum = -1; |
| 1659 | | |
| 1660 | | // allocate a timer for this event |
| 1661 | | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 1662 | | { |
| 1663 | | if (!m_timerinuse[i]) |
| 1664 | | { |
| 1665 | | tnum = i; |
| 1666 | | timer = m_timers[i]; |
| 1667 | | m_timerinuse[i] = true; |
| 1668 | | m_eventfortimer[i] = ev; |
| 1669 | | break; |
| 1670 | | } |
| 1671 | | } |
| 1672 | | |
| 1673 | | if (tnum == -1) |
| 1674 | | { |
| 1675 | | fatalerror("PSXCD: ran out of timers!\n"); |
| 1676 | | } |
| 1677 | | |
| 1678 | | // ev->t is in maincpu clock cycles |
| 1679 | | UINT32 hz = m_sysclock / ev->t; |
| 1680 | | // printf("add_system_event: event type %d for %d hz (using timer %d)\n", ev->type, hz, tnum); |
| 1681 | | timer->adjust(attotime::from_hz(hz), tnum, attotime::never); |
| 1682 | | |
| 1683 | | // back-reference the timer from the event |
| 1684 | | ev->timer = timer; |
| 1685 | | } |
| 1686 | | |
src/mame/machine/psxcddrv.c
| r11505 | r11506 | |
| 1 | | #include "emu.h" |
| 2 | | #include "includes/psx.h" |
| 3 | | #include "psxcd.h" |
| 4 | | #include "psxcddrv.h" |
| 5 | | |
| 6 | | //#define debug_mess_driver |
| 7 | | |
| 8 | | // |
| 9 | | // |
| 10 | | // |
| 11 | | |
| 12 | | static const unsigned int num_pf_sectors=32, num_pf_buffers=16; |
| 13 | | |
| 14 | | // |
| 15 | | // |
| 16 | | // |
| 17 | | |
| 18 | | cdrom_driver::cdrom_driver() |
| 19 | | { |
| 20 | | pf_head = 0; |
| 21 | | pf_tail = 0; |
| 22 | | num_pf = 0; |
| 23 | | pf_head_sector = 0; |
| 24 | | pf_status = NULL; |
| 25 | | native_sector_size = raw_sector_size; |
| 26 | | last_pf_status = NULL; |
| 27 | | m_cd = NULL; |
| 28 | | m_machine = NULL; |
| 29 | | |
| 30 | | // printf("cdrom_driver base class init, pf_buffer size is %d\n", num_pf_sectors*num_pf_buffers*raw_sector_size); |
| 31 | | |
| 32 | | pf_buffer=new unsigned char [num_pf_sectors*num_pf_buffers*raw_sector_size]; |
| 33 | | |
| 34 | | timestamp_frequency = 1; |
| 35 | | } |
| 36 | | |
| 37 | | cdrom_driver::~cdrom_driver() |
| 38 | | { |
| 39 | | global_free(pf_buffer); |
| 40 | | } |
| 41 | | |
| 42 | | // |
| 43 | | // |
| 44 | | // |
| 45 | | |
| 46 | | void cdrom_driver::set_native_sector_size(const unsigned int sz) |
| 47 | | { |
| 48 | | native_sector_size=sz; |
| 49 | | } |
| 50 | | |
| 51 | | // |
| 52 | | // |
| 53 | | // |
| 54 | | |
| 55 | | void cdrom_driver::cancel_io() |
| 56 | | { |
| 57 | | if (pf_status) |
| 58 | | { |
| 59 | | pf_status->cancel(); |
| 60 | | pf_status->release(); |
| 61 | | } |
| 62 | | |
| 63 | | pf_status=NULL; |
| 64 | | } |
| 65 | | |
| 66 | | // |
| 67 | | // |
| 68 | | // |
| 69 | | |
| 70 | | void cdrom_driver::prefetch_sector(const unsigned int sec) |
| 71 | | { |
| 72 | | int numpfsec=num_pf*num_pf_sectors, |
| 73 | | pfsec=sec-pf_head_sector; |
| 74 | | |
| 75 | | // printf("prefetch_sector: %d\n", sec); |
| 76 | | |
| 77 | | if ((pfsec<0) || (pfsec>numpfsec)) |
| 78 | | { |
| 79 | | // Sector is not in prefetch buffer, abort current prefetch |
| 80 | | |
| 81 | | if (pf_status) |
| 82 | | { |
| 83 | | pf_status->cancel(); |
| 84 | | pf_status->release(); |
| 85 | | } |
| 86 | | |
| 87 | | // Reset the buffer and begin a new prefetch |
| 88 | | |
| 89 | | pf_head=0; |
| 90 | | pf_tail=0; |
| 91 | | num_pf=1; |
| 92 | | pf_head_sector=sec; |
| 93 | | |
| 94 | | last_pf_status=NULL; |
| 95 | | pf_status=read_sectors(sec, num_pf_sectors, pf_buffer); |
| 96 | | } |
| 97 | | } |
| 98 | | |
| 99 | | // |
| 100 | | // |
| 101 | | // |
| 102 | | |
| 103 | | bool cdrom_driver::is_prefetch_sector_loaded(const unsigned int sec) |
| 104 | | { |
| 105 | | int numpfsec=num_pf*num_pf_sectors, |
| 106 | | pfsec=sec-pf_head_sector; |
| 107 | | |
| 108 | | if ((pfsec<0) || (pfsec>=numpfsec)) |
| 109 | | { |
| 110 | | // Requested sector is not in prefetch buffer, begin a new prefetch |
| 111 | | |
| 112 | | prefetch_sector(sec); |
| 113 | | pfsec=sec-pf_head_sector; |
| 114 | | numpfsec=num_pf*num_pf_sectors; |
| 115 | | } |
| 116 | | |
| 117 | | int blk=pfsec/num_pf_sectors; |
| 118 | | |
| 119 | | if (blk>0) |
| 120 | | { |
| 121 | | // Discard blocks below the prefetch point |
| 122 | | |
| 123 | | pf_head=(pf_head+blk)%num_pf_buffers; |
| 124 | | pf_head_sector+=num_pf_sectors*blk; |
| 125 | | pfsec-=num_pf_sectors*blk; |
| 126 | | num_pf-=blk; |
| 127 | | blk=0; |
| 128 | | } |
| 129 | | |
| 130 | | bool comp=((! pf_status) || (pf_status->complete())); |
| 131 | | |
| 132 | | if (! comp) |
| 133 | | { |
| 134 | | INT64 curtime=m_machine->device<cpu_device>("maincpu")->total_cycles(); |
| 135 | | |
| 136 | | if (last_pf_status!=pf_status) |
| 137 | | { |
| 138 | | last_pf_status=pf_status; |
| 139 | | pf_timeout_begin=curtime; |
| 140 | | } |
| 141 | | |
| 142 | | INT64 timeout=curtime-pf_timeout_begin; |
| 143 | | int timeout_sec=(int)(timeout/timestamp_frequency); |
| 144 | | if (timeout_sec>20) |
| 145 | | { |
| 146 | | printf("cdrom: prefetch timed out, trying again...\n"); |
| 147 | | num_pf=0; |
| 148 | | pf_head_sector=-1; |
| 149 | | prefetch_sector(sec); |
| 150 | | return is_prefetch_sector_loaded(sec); |
| 151 | | } |
| 152 | | } |
| 153 | | |
| 154 | | if ((num_pf<num_pf_buffers) && (comp)) |
| 155 | | { |
| 156 | | // The prefetch buffer is not full and we are not waiting on IO, |
| 157 | | // prefetch the next block |
| 158 | | |
| 159 | | pf_tail=(pf_tail+1)%num_pf_buffers; |
| 160 | | num_pf++; |
| 161 | | |
| 162 | | int nxtsec=pf_head_sector+((num_pf-1)*num_pf_sectors); |
| 163 | | unsigned char *ptr=pf_buffer+((pf_tail*num_pf_sectors)*native_sector_size); |
| 164 | | |
| 165 | | if (pf_status) |
| 166 | | { |
| 167 | | pf_status->release(); |
| 168 | | pf_status=last_pf_status=NULL; |
| 169 | | } |
| 170 | | |
| 171 | | pf_status=read_sectors(nxtsec, num_pf_sectors, ptr); |
| 172 | | } |
| 173 | | |
| 174 | | if (blk==(num_pf-1)) |
| 175 | | { |
| 176 | | // The sector we want is in the last block in the prefetch buffer |
| 177 | | // which might still be loading, check if the sector we want is loaded |
| 178 | | #if 0 // we do not load async in MESS |
| 179 | | INT64 trans=pf_status->bytes_transferred(); |
| 180 | | unsigned int secmod=pfsec%num_pf_sectors, |
| 181 | | needbytes=(secmod+1)*native_sector_size; |
| 182 | | |
| 183 | | if (trans<needbytes) |
| 184 | | { |
| 185 | | // The sector is not loaded yet |
| 186 | | |
| 187 | | return false; |
| 188 | | } else |
| 189 | | #endif |
| 190 | | { |
| 191 | | // The sector is loaded |
| 192 | | |
| 193 | | return true; |
| 194 | | } |
| 195 | | } else |
| 196 | | { |
| 197 | | // The sector is not in the last block so it must be loaded |
| 198 | | |
| 199 | | return true; |
| 200 | | } |
| 201 | | } |
| 202 | | |
| 203 | | // |
| 204 | | // |
| 205 | | // |
| 206 | | |
| 207 | | unsigned char *cdrom_driver::get_prefetch_sector(const unsigned int sec, unsigned int *sz) |
| 208 | | { |
| 209 | | int numpfsec=num_pf*num_pf_sectors, |
| 210 | | pfsec=sec-pf_head_sector; |
| 211 | | if ((pfsec>=0) && (pfsec<numpfsec)) |
| 212 | | { |
| 213 | | int blk=(pf_head+(pfsec/num_pf_sectors))%num_pf_buffers, |
| 214 | | off=((blk*num_pf_sectors)+(pfsec%num_pf_sectors))*native_sector_size; |
| 215 | | *sz=native_sector_size; |
| 216 | | return pf_buffer+off; |
| 217 | | } else |
| 218 | | { |
| 219 | | return NULL; |
| 220 | | } |
| 221 | | } |
| 222 | | |
| 223 | | // |
| 224 | | // |
| 225 | | // |
| 226 | | |
| 227 | | bool cdrom_driver::read_sector(const unsigned int sec, unsigned char *buf, const bool block) |
| 228 | | { |
| 229 | | bool loaded=is_prefetch_sector_loaded(sec); |
| 230 | | |
| 231 | | // printf("read_sector: %d (loaded=%c)\n", sec, loaded ? 'Y' : 'N'); |
| 232 | | |
| 233 | | if ((! loaded) && (block)) |
| 234 | | { |
| 235 | | pf_status->block_until_complete(); |
| 236 | | loaded=true; |
| 237 | | } |
| 238 | | |
| 239 | | if (loaded) |
| 240 | | { |
| 241 | | unsigned int secsz=0; |
| 242 | | unsigned char *ptr=get_prefetch_sector(sec,&secsz); |
| 243 | | assert(ptr); |
| 244 | | |
| 245 | | // printf("got sector %d @ %p, size %d = %02x %02x | %02x %02x\n", sec, ptr, secsz, ptr[0], ptr[1], ptr[0x20], ptr[0x21]); |
| 246 | | |
| 247 | | if (secsz<2352) |
| 248 | | { |
| 249 | | // Add sector header |
| 250 | | |
| 251 | | buf[0]=0; |
| 252 | | memset(buf+1,0xff,10); |
| 253 | | buf[11]=0; |
| 254 | | sector_to_msf(sec,buf+12); |
| 255 | | buf[12]=decimal_to_bcd(buf[12]); |
| 256 | | buf[13]=decimal_to_bcd(buf[13]); |
| 257 | | buf[14]=decimal_to_bcd(buf[14]); |
| 258 | | buf[15]=2; |
| 259 | | |
| 260 | | if (secsz<2336) |
| 261 | | { |
| 262 | | memset(buf+16,0xff,8); |
| 263 | | } |
| 264 | | } |
| 265 | | |
| 266 | | switch (secsz) |
| 267 | | { |
| 268 | | case 2048: |
| 269 | | memcpy(buf+24,ptr,2048); |
| 270 | | break; |
| 271 | | |
| 272 | | case 2336: |
| 273 | | memcpy(buf+16,ptr,2336); |
| 274 | | break; |
| 275 | | |
| 276 | | case 2352: |
| 277 | | memcpy(buf,ptr,raw_sector_size); |
| 278 | | break; |
| 279 | | } |
| 280 | | |
| 281 | | return true; |
| 282 | | } else |
| 283 | | { |
| 284 | | return false; |
| 285 | | } |
| 286 | | } |
| 287 | | |
| 288 | | void cdrom_driver::set_machine(const running_machine &machine) |
| 289 | | { |
| 290 | | m_machine = (running_machine *)&machine; |
| 291 | | |
| 292 | | timestamp_frequency = m_machine->device<cpu_device>("maincpu")->clock(); |
| 293 | | |
| 294 | | // printf("cdrom_driver::set_machine: timestamp frequency = %d\n", timestamp_frequency); |
| 295 | | } |
| 296 | | |
| 297 | | /* |
| 298 | | MAME/MESS driver implementation |
| 299 | | */ |
| 300 | | |
| 301 | | class mess_cdrom_driver : public cdrom_driver |
| 302 | | { |
| 303 | | enum track_type |
| 304 | | { |
| 305 | | track_illegal=-1, |
| 306 | | track_mode1_2048=0, |
| 307 | | track_mode2_2352, |
| 308 | | track_mode2_2336, |
| 309 | | track_audio |
| 310 | | }; |
| 311 | | |
| 312 | | struct toc_entry |
| 313 | | { |
| 314 | | unsigned int type; |
| 315 | | unsigned char address[3]; |
| 316 | | }; |
| 317 | | |
| 318 | | int num_sectors, num_tracks; |
| 319 | | toc_entry toc[100]; |
| 320 | | int bin_sector_size; |
| 321 | | const char *err; |
| 322 | | |
| 323 | | io_status *read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf); |
| 324 | | |
| 325 | | public: |
| 326 | | mess_cdrom_driver(); |
| 327 | | ~mess_cdrom_driver(); |
| 328 | | |
| 329 | | bool is_usable(char *error_msg, const int msglen) const |
| 330 | | { |
| 331 | | return true; |
| 332 | | } |
| 333 | | |
| 334 | | bool read_toc(); |
| 335 | | unsigned int get_first_track() const; |
| 336 | | unsigned int get_num_tracks() const; |
| 337 | | bool get_track_address(const unsigned int track,unsigned char *address) const; |
| 338 | | tracktype get_track_type(const unsigned int track) const; |
| 339 | | unsigned int find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const; |
| 340 | | cdromtype get_type() const; |
| 341 | | }; |
| 342 | | |
| 343 | | mess_cdrom_driver::mess_cdrom_driver() |
| 344 | | : err(NULL) |
| 345 | | { |
| 346 | | for (int i=0; i<100; i++) |
| 347 | | toc[i].type=track_illegal; |
| 348 | | num_tracks=0; |
| 349 | | num_sectors=0; |
| 350 | | } |
| 351 | | |
| 352 | | // |
| 353 | | // |
| 354 | | // |
| 355 | | |
| 356 | | mess_cdrom_driver::~mess_cdrom_driver() |
| 357 | | { |
| 358 | | cancel_io(); |
| 359 | | } |
| 360 | | |
| 361 | | // |
| 362 | | // |
| 363 | | // |
| 364 | | |
| 365 | | bool mess_cdrom_driver::read_toc() |
| 366 | | { |
| 367 | | if (m_cd) |
| 368 | | { |
| 369 | | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 370 | | |
| 371 | | num_tracks = cdrom_get_last_track(m_cd); |
| 372 | | |
| 373 | | switch (toc->tracks[0].trktype) |
| 374 | | { |
| 375 | | case CD_TRACK_MODE1: bin_sector_size=2048; break; |
| 376 | | case CD_TRACK_MODE2_FORM1: bin_sector_size=2048; break; |
| 377 | | case CD_TRACK_MODE2: bin_sector_size=2336; break; |
| 378 | | case CD_TRACK_MODE2_FORM_MIX: bin_sector_size=2336; break; |
| 379 | | default: bin_sector_size=2352; break; |
| 380 | | } |
| 381 | | |
| 382 | | set_native_sector_size(bin_sector_size); |
| 383 | | num_sectors = cdrom_get_track_start(m_cd, num_tracks) + toc->tracks[num_tracks].frames; |
| 384 | | |
| 385 | | // printf("mess_cdrom_driver: %d sectors, native size %d\n",num_sectors, bin_sector_size); |
| 386 | | |
| 387 | | return true; |
| 388 | | } |
| 389 | | |
| 390 | | return false; |
| 391 | | } |
| 392 | | |
| 393 | | // |
| 394 | | // |
| 395 | | // |
| 396 | | |
| 397 | | io_status *mess_cdrom_driver::read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf) |
| 398 | | { |
| 399 | | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 400 | | UINT32 track = cdrom_get_track(m_cd, startsec); |
| 401 | | UINT32 secsize = toc->tracks[track].datasize; |
| 402 | | |
| 403 | | #ifdef debug_mess_driver |
| 404 | | printf("mess: read %d sectors from %d (secsize %d)\n",numsec,startsec,secsize); |
| 405 | | #endif |
| 406 | | |
| 407 | | if ((startsec>=0)) // && ((int)startsec<num_sectors)) |
| 408 | | { |
| 409 | | // fin->seek((INT64)startsec*(INT64)bin_sector_size); |
| 410 | | |
| 411 | | // io_status *ios=fin->async_read(buf,numsec*bin_sector_size); |
| 412 | | // if (! ios) |
| 413 | | for (int i = 0; i < numsec; i++) |
| 414 | | { |
| 415 | | // printf("[%d/%d] Reading to pf_buffer %p at offset %d, size %d\n", i, numsec, &buf[secsize*i], secsize*i, secsize); |
| 416 | | cdrom_read_data(m_cd, startsec+i, &buf[secsize*i], CD_TRACK_RAW_DONTCARE); |
| 417 | | } |
| 418 | | |
| 419 | | return NULL; |
| 420 | | |
| 421 | | // return ios; |
| 422 | | } |
| 423 | | else |
| 424 | | { |
| 425 | | printf("mess: read sector out of range (%d, max=%d)\n", |
| 426 | | startsec, |
| 427 | | num_sectors); |
| 428 | | |
| 429 | | memset(buf,0xff,numsec*bin_sector_size); |
| 430 | | return NULL; |
| 431 | | } |
| 432 | | } |
| 433 | | |
| 434 | | // |
| 435 | | // |
| 436 | | // |
| 437 | | |
| 438 | | unsigned int mess_cdrom_driver::get_first_track() const |
| 439 | | { |
| 440 | | return 1; |
| 441 | | } |
| 442 | | |
| 443 | | unsigned int mess_cdrom_driver::get_num_tracks() const |
| 444 | | { |
| 445 | | // printf("get_num_tracks = %d\n", num_tracks); |
| 446 | | return num_tracks; |
| 447 | | } |
| 448 | | |
| 449 | | bool mess_cdrom_driver::get_track_address(const unsigned int track, unsigned char *address) const |
| 450 | | { |
| 451 | | if ((track>=1) && ((int)track<=num_tracks)) |
| 452 | | { |
| 453 | | UINT32 trkstart = cdrom_get_track_start(m_cd, track); |
| 454 | | |
| 455 | | sector_to_msf(trkstart, address); |
| 456 | | |
| 457 | | address[0] = address[0]; |
| 458 | | address[1] = address[1]; |
| 459 | | address[2] = address[2]; |
| 460 | | |
| 461 | | // printf("get_track_address %d = %02x:%02x:%02x\n", track, address[0], address[1], address[2]); |
| 462 | | |
| 463 | | return true; |
| 464 | | } |
| 465 | | else |
| 466 | | { |
| 467 | | address[0]=address[1]=address[2]=0; |
| 468 | | return false; |
| 469 | | } |
| 470 | | } |
| 471 | | |
| 472 | | unsigned int mess_cdrom_driver::find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const |
| 473 | | { |
| 474 | | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 475 | | UINT32 track = cdrom_get_track(m_cd, sector); |
| 476 | | int start; |
| 477 | | |
| 478 | | start = cdrom_get_track_start(m_cd, track); |
| 479 | | |
| 480 | | if (start_sector != NULL) |
| 481 | | { |
| 482 | | *start_sector = start; |
| 483 | | } |
| 484 | | |
| 485 | | if (end_sector != NULL) |
| 486 | | { |
| 487 | | *end_sector = start + toc->tracks[track].frames; |
| 488 | | } |
| 489 | | |
| 490 | | printf("find_track: track %d start %d end %d\n", track, start, *end_sector); |
| 491 | | |
| 492 | | return -1; |
| 493 | | } |
| 494 | | |
| 495 | | // |
| 496 | | // |
| 497 | | // |
| 498 | | |
| 499 | | cdromtype mess_cdrom_driver::get_type() const |
| 500 | | { |
| 501 | | // printf("get_type\n"); |
| 502 | | return cdromtype_cd; |
| 503 | | } |
| 504 | | |
| 505 | | // |
| 506 | | // |
| 507 | | // |
| 508 | | |
| 509 | | tracktype mess_cdrom_driver::get_track_type(const unsigned int track) const |
| 510 | | { |
| 511 | | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 512 | | |
| 513 | | // printf("get_track_type %d = %d\n", track, toc->tracks[track].trktype); |
| 514 | | |
| 515 | | switch (toc->tracks[track].trktype) |
| 516 | | { |
| 517 | | case CD_TRACK_MODE1: return tracktype_mode1; |
| 518 | | case CD_TRACK_MODE2_RAW: return tracktype_mode2; |
| 519 | | case CD_TRACK_MODE2_FORM_MIX: return tracktype_mode2; |
| 520 | | case CD_TRACK_AUDIO: return tracktype_audio; |
| 521 | | default: return tracktype_unknown; |
| 522 | | } |
| 523 | | } |
| 524 | | |
| 525 | | // |
| 526 | | // |
| 527 | | // |
| 528 | | |
| 529 | | cdrom_driver *open_mess_drv() |
| 530 | | { |
| 531 | | return new mess_cdrom_driver(); |
| 532 | | } |
| 533 | | |
src/mame/machine/psx.c
| r11505 | r11506 | |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | | #ifdef UNUSED_FUNCTION |
| 29 | | INLINE void psxwriteword( UINT32 *p_n_psxram, UINT32 n_address, UINT16 n_data ) |
| 30 | | { |
| 31 | | *( (UINT16 *)( (UINT8 *)p_n_psxram + WORD_XOR_LE( n_address ) ) ) = n_data; |
| 32 | | } |
| 33 | | #endif |
| 34 | | |
| 35 | | INLINE UINT16 psxreadword( UINT32 *p_n_psxram, UINT32 n_address ) |
| 36 | | { |
| 37 | | return *( (UINT16 *)( (UINT8 *)p_n_psxram + WORD_XOR_LE( n_address ) ) ); |
| 38 | | } |
| 39 | | |
| 40 | 28 | WRITE32_HANDLER( psx_com_delay_w ) |
| 41 | 29 | { |
| 42 | 30 | psx_machine *p_psx = space->machine().driver_data<psx_state>()->m_p_psx; |
| r11505 | r11506 | |
| 125 | 113 | |
| 126 | 114 | /* DMA */ |
| 127 | 115 | |
| 128 | | void psx_dma_install_read_handler( running_machine &machine, int n_channel, psx_dma_read_handler p_fn_dma_read ) |
| 129 | | |
| 116 | void psx_dma_install_read_handler( running_machine &machine, int n_channel, psx_dma_read_delegate p_fn_dma_read ) |
| 130 | 117 | { |
| 131 | | psxcpu_device::install_dma_read_handler( *machine.device("maincpu"), n_channel, p_fn_dma_read ); |
| 118 | psxcpu_device::install_dma_read_handler( *machine.device("maincpu"), "maincpu", n_channel, p_fn_dma_read ); |
| 132 | 119 | } |
| 133 | 120 | |
| 134 | | void psx_dma_install_write_handler( running_machine &machine, int n_channel, psx_dma_read_handler p_fn_dma_write ) |
| 121 | void psx_dma_install_write_handler( running_machine &machine, int n_channel, psx_dma_read_delegate p_fn_dma_write ) |
| 135 | 122 | { |
| 136 | | psxcpu_device::install_dma_write_handler( *machine.device("maincpu"), n_channel, p_fn_dma_write ); |
| 123 | psxcpu_device::install_dma_write_handler( *machine.device("maincpu"), "maincpu", n_channel, p_fn_dma_write ); |
| 137 | 124 | } |
| 138 | 125 | |
| 139 | 126 | /* Root Counters */ |
| r11505 | r11506 | |
| 618 | 605 | p_psx->sio[ n_port ].fn_handler = p_f_sio_handler; |
| 619 | 606 | } |
| 620 | 607 | |
| 621 | | /* MDEC */ |
| 622 | | |
| 623 | | static const UINT32 m_p_n_mdec_zigzag[ DCTSIZE2 ] = |
| 608 | static void gpu_read( psx_state *state, UINT32 n_address, INT32 n_size ) |
| 624 | 609 | { |
| 625 | | 0, 1, 8, 16, 9, 2, 3, 10, |
| 626 | | 17, 24, 32, 25, 18, 11, 4, 5, |
| 627 | | 12, 19, 26, 33, 40, 48, 41, 34, |
| 628 | | 27, 20, 13, 6, 7, 14, 21, 28, |
| 629 | | 35, 42, 49, 56, 57, 50, 43, 36, |
| 630 | | 29, 22, 15, 23, 30, 37, 44, 51, |
| 631 | | 58, 59, 52, 45, 38, 31, 39, 46, |
| 632 | | 53, 60, 61, 54, 47, 55, 62, 63 |
| 633 | | }; |
| 634 | | |
| 635 | | static void mdec_cos_precalc( psx_machine *p_psx ) |
| 636 | | { |
| 637 | | psx_mdec *p_mdec = &p_psx->mdec; |
| 638 | | UINT32 n_x; |
| 639 | | UINT32 n_y; |
| 640 | | UINT32 n_u; |
| 641 | | UINT32 n_v; |
| 642 | | INT32 *p_n_precalc; |
| 643 | | |
| 644 | | p_n_precalc = p_mdec->p_n_cos_precalc; |
| 645 | | |
| 646 | | for( n_y = 0; n_y < 8; n_y++ ) |
| 647 | | { |
| 648 | | for( n_x = 0; n_x < 8; n_x++ ) |
| 649 | | { |
| 650 | | for( n_v = 0; n_v < 8; n_v++ ) |
| 651 | | { |
| 652 | | for( n_u = 0; n_u < 8; n_u++ ) |
| 653 | | { |
| 654 | | *( p_n_precalc++ ) = |
| 655 | | ( ( p_mdec->p_n_cos[ ( n_u * 8 ) + n_x ] * |
| 656 | | p_mdec->p_n_cos[ ( n_v * 8 ) + n_y ] ) >> ( 30 - MDEC_COS_PRECALC_BITS ) ); |
| 657 | | } |
| 658 | | } |
| 659 | | } |
| 660 | | } |
| 661 | | } |
| 662 | | |
| 663 | | static void mdec_idct( psx_machine *p_psx, INT32 *p_n_src, INT32 *p_n_dst ) |
| 664 | | { |
| 665 | | psx_mdec *p_mdec = &p_psx->mdec; |
| 666 | | UINT32 n_yx; |
| 667 | | UINT32 n_vu; |
| 668 | | INT32 p_n_z[ 8 ]; |
| 669 | | INT32 *p_n_data; |
| 670 | | INT32 *p_n_precalc; |
| 671 | | |
| 672 | | p_n_precalc = p_mdec->p_n_cos_precalc; |
| 673 | | |
| 674 | | for( n_yx = 0; n_yx < DCTSIZE2; n_yx++ ) |
| 675 | | { |
| 676 | | p_n_data = p_n_src; |
| 677 | | |
| 678 | | memset( p_n_z, 0, sizeof( p_n_z ) ); |
| 679 | | |
| 680 | | for( n_vu = 0; n_vu < DCTSIZE2 / 8; n_vu++ ) |
| 681 | | { |
| 682 | | p_n_z[ 0 ] += p_n_data[ 0 ] * p_n_precalc[ 0 ]; |
| 683 | | p_n_z[ 1 ] += p_n_data[ 1 ] * p_n_precalc[ 1 ]; |
| 684 | | p_n_z[ 2 ] += p_n_data[ 2 ] * p_n_precalc[ 2 ]; |
| 685 | | p_n_z[ 3 ] += p_n_data[ 3 ] * p_n_precalc[ 3 ]; |
| 686 | | p_n_z[ 4 ] += p_n_data[ 4 ] * p_n_precalc[ 4 ]; |
| 687 | | p_n_z[ 5 ] += p_n_data[ 5 ] * p_n_precalc[ 5 ]; |
| 688 | | p_n_z[ 6 ] += p_n_data[ 6 ] * p_n_precalc[ 6 ]; |
| 689 | | p_n_z[ 7 ] += p_n_data[ 7 ] * p_n_precalc[ 7 ]; |
| 690 | | p_n_data += 8; |
| 691 | | p_n_precalc += 8; |
| 692 | | } |
| 693 | | |
| 694 | | *( p_n_dst++ ) = ( p_n_z[ 0 ] + p_n_z[ 1 ] + p_n_z[ 2 ] + p_n_z[ 3 ] + |
| 695 | | p_n_z[ 4 ] + p_n_z[ 5 ] + p_n_z[ 6 ] + p_n_z[ 7 ] ) >> ( MDEC_COS_PRECALC_BITS + 2 ); |
| 696 | | } |
| 697 | | } |
| 698 | | |
| 699 | | INLINE UINT16 mdec_unpack_run( UINT16 n_packed ) |
| 700 | | { |
| 701 | | return n_packed >> 10; |
| 702 | | } |
| 703 | | |
| 704 | | INLINE INT32 mdec_unpack_val( UINT16 n_packed ) |
| 705 | | { |
| 706 | | return ( ( (INT32)n_packed ) << 22 ) >> 22; |
| 707 | | } |
| 708 | | |
| 709 | | static UINT32 mdec_unpack( psx_machine *p_psx, UINT32 n_address ) |
| 710 | | { |
| 610 | psx_machine *p_psx = state->m_p_psx; |
| 711 | 611 | UINT32 *p_n_psxram = p_psx->p_n_psxram; |
| 712 | | psx_mdec *p_mdec = &p_psx->mdec; |
| 713 | | UINT8 n_z; |
| 714 | | INT32 n_qscale; |
| 715 | | UINT16 n_packed; |
| 716 | | UINT32 n_block; |
| 717 | | INT32 *p_n_block; |
| 718 | | INT32 p_n_unpacked[ 64 ]; |
| 719 | | INT32 *p_n_q; |
| 720 | 612 | |
| 721 | | p_n_q = p_mdec->p_n_quantize_uv; |
| 722 | | p_n_block = p_mdec->p_n_unpacked; |
| 723 | | |
| 724 | | for( n_block = 0; n_block < 6; n_block++ ) |
| 725 | | { |
| 726 | | memset( p_n_unpacked, 0, sizeof( p_n_unpacked ) ); |
| 727 | | |
| 728 | | if( n_block == 2 ) |
| 729 | | { |
| 730 | | p_n_q = p_mdec->p_n_quantize_y; |
| 731 | | } |
| 732 | | n_packed = psxreadword( p_n_psxram, n_address ); |
| 733 | | n_address += 2; |
| 734 | | if( n_packed == 0xfe00 ) |
| 735 | | { |
| 736 | | break; |
| 737 | | } |
| 738 | | |
| 739 | | n_qscale = mdec_unpack_run( n_packed ); |
| 740 | | p_n_unpacked[ 0 ] = mdec_unpack_val( n_packed ) * p_n_q[ 0 ]; |
| 741 | | |
| 742 | | n_z = 0; |
| 743 | | for( ;; ) |
| 744 | | { |
| 745 | | n_packed = psxreadword( p_n_psxram, n_address ); |
| 746 | | n_address += 2; |
| 747 | | |
| 748 | | if( n_packed == 0xfe00 ) |
| 749 | | { |
| 750 | | break; |
| 751 | | } |
| 752 | | n_z += mdec_unpack_run( n_packed ) + 1; |
| 753 | | if( n_z > 63 ) |
| 754 | | { |
| 755 | | break; |
| 756 | | } |
| 757 | | p_n_unpacked[ m_p_n_mdec_zigzag[ n_z ] ] = ( mdec_unpack_val( n_packed ) * p_n_q[ n_z ] * n_qscale ) / 8; |
| 758 | | } |
| 759 | | mdec_idct( p_psx, p_n_unpacked, p_n_block ); |
| 760 | | p_n_block += DCTSIZE2; |
| 761 | | } |
| 762 | | return n_address; |
| 613 | psx_gpu_read( state->machine(), &p_n_psxram[ n_address / 4 ], n_size ); |
| 763 | 614 | } |
| 764 | 615 | |
| 765 | | INLINE INT32 mdec_cr_to_r( INT32 n_cr ) |
| 616 | static void gpu_write( psx_state *state, UINT32 n_address, INT32 n_size ) |
| 766 | 617 | { |
| 767 | | return ( 1435 * n_cr ) >> 10; |
| 768 | | } |
| 769 | | |
| 770 | | INLINE INT32 mdec_cr_to_g( INT32 n_cr ) |
| 771 | | { |
| 772 | | return ( -731 * n_cr ) >> 10; |
| 773 | | } |
| 774 | | |
| 775 | | INLINE INT32 mdec_cb_to_g( INT32 n_cb ) |
| 776 | | { |
| 777 | | return ( -351 * n_cb ) >> 10; |
| 778 | | } |
| 779 | | |
| 780 | | INLINE INT32 mdec_cb_to_b( INT32 n_cb ) |
| 781 | | { |
| 782 | | return ( 1814 * n_cb ) >> 10; |
| 783 | | } |
| 784 | | |
| 785 | | INLINE UINT16 mdec_clamp_r5( psx_mdec *p_mdec, INT32 n_r ) |
| 786 | | { |
| 787 | | return p_mdec->p_n_r5[ n_r + 128 + 256 ]; |
| 788 | | } |
| 789 | | |
| 790 | | INLINE UINT16 mdec_clamp_g5( psx_mdec *p_mdec, INT32 n_g ) |
| 791 | | { |
| 792 | | return p_mdec->p_n_g5[ n_g + 128 + 256 ]; |
| 793 | | } |
| 794 | | |
| 795 | | INLINE UINT16 mdec_clamp_b5( psx_mdec *p_mdec, INT32 n_b ) |
| 796 | | { |
| 797 | | return p_mdec->p_n_b5[ n_b + 128 + 256 ]; |
| 798 | | } |
| 799 | | |
| 800 | | INLINE void mdec_makergb15( psx_mdec *p_mdec, UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT16 n_stp ) |
| 801 | | { |
| 802 | | p_mdec->p_n_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = n_stp | |
| 803 | | mdec_clamp_r5( p_mdec, p_n_y[ 0 ] + n_r ) | |
| 804 | | mdec_clamp_g5( p_mdec, p_n_y[ 0 ] + n_g ) | |
| 805 | | mdec_clamp_b5( p_mdec, p_n_y[ 0 ] + n_b ); |
| 806 | | |
| 807 | | p_mdec->p_n_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = n_stp | |
| 808 | | mdec_clamp_r5( p_mdec, p_n_y[ 1 ] + n_r ) | |
| 809 | | mdec_clamp_g5( p_mdec, p_n_y[ 1 ] + n_g ) | |
| 810 | | mdec_clamp_b5( p_mdec, p_n_y[ 1 ] + n_b ); |
| 811 | | } |
| 812 | | |
| 813 | | static void mdec_yuv2_to_rgb15( psx_machine *p_psx ) |
| 814 | | { |
| 815 | | psx_mdec *p_mdec = &p_psx->mdec; |
| 816 | | INT32 n_r; |
| 817 | | INT32 n_g; |
| 818 | | INT32 n_b; |
| 819 | | INT32 n_cb; |
| 820 | | INT32 n_cr; |
| 821 | | INT32 *p_n_cb; |
| 822 | | INT32 *p_n_cr; |
| 823 | | INT32 *p_n_y; |
| 824 | | UINT32 n_x; |
| 825 | | UINT32 n_y; |
| 826 | | UINT32 n_z; |
| 827 | | UINT16 n_stp; |
| 828 | | int n_address = 0; |
| 829 | | |
| 830 | | if( ( p_mdec->n_0_command & ( 1L << 25 ) ) != 0 ) |
| 831 | | { |
| 832 | | n_stp = 0x8000; |
| 833 | | } |
| 834 | | else |
| 835 | | { |
| 836 | | n_stp = 0x0000; |
| 837 | | } |
| 838 | | |
| 839 | | p_n_cr = &p_mdec->p_n_unpacked[ 0 ]; |
| 840 | | p_n_cb = &p_mdec->p_n_unpacked[ DCTSIZE2 ]; |
| 841 | | p_n_y = &p_mdec->p_n_unpacked[ DCTSIZE2 * 2 ]; |
| 842 | | |
| 843 | | for( n_z = 0; n_z < 2; n_z++ ) |
| 844 | | { |
| 845 | | for( n_y = 0; n_y < 4; n_y++ ) |
| 846 | | { |
| 847 | | for( n_x = 0; n_x < 4; n_x++ ) |
| 848 | | { |
| 849 | | n_cr = *( p_n_cr ); |
| 850 | | n_cb = *( p_n_cb ); |
| 851 | | n_r = mdec_cr_to_r( n_cr ); |
| 852 | | n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); |
| 853 | | n_b = mdec_cb_to_b( n_cb ); |
| 854 | | |
| 855 | | mdec_makergb15( p_mdec, ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); |
| 856 | | mdec_makergb15( p_mdec, ( n_address + 32 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); |
| 857 | | |
| 858 | | n_cr = *( p_n_cr + 4 ); |
| 859 | | n_cb = *( p_n_cb + 4 ); |
| 860 | | n_r = mdec_cr_to_r( n_cr ); |
| 861 | | n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); |
| 862 | | n_b = mdec_cb_to_b( n_cb ); |
| 863 | | |
| 864 | | mdec_makergb15( p_mdec, ( n_address + 16 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); |
| 865 | | mdec_makergb15( p_mdec, ( n_address + 48 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); |
| 866 | | |
| 867 | | p_n_cr++; |
| 868 | | p_n_cb++; |
| 869 | | p_n_y += 2; |
| 870 | | n_address += 4; |
| 871 | | } |
| 872 | | p_n_cr += 4; |
| 873 | | p_n_cb += 4; |
| 874 | | p_n_y += 8; |
| 875 | | n_address += 48; |
| 876 | | } |
| 877 | | p_n_y += DCTSIZE2; |
| 878 | | } |
| 879 | | p_mdec->n_decoded = ( 16 * 16 ) / 2; |
| 880 | | } |
| 881 | | |
| 882 | | INLINE UINT16 mdec_clamp8( psx_mdec *p_mdec, INT32 n_r ) |
| 883 | | { |
| 884 | | return p_mdec->p_n_clamp8[ n_r + 128 + 256 ]; |
| 885 | | } |
| 886 | | |
| 887 | | INLINE void mdec_makergb24( psx_mdec *p_mdec, UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT32 n_stp ) |
| 888 | | { |
| 889 | | p_mdec->p_n_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_g ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_r ); |
| 890 | | p_mdec->p_n_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_r ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_b ); |
| 891 | | p_mdec->p_n_output[ WORD_XOR_LE( n_address + 4 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_b ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_g ); |
| 892 | | } |
| 893 | | |
| 894 | | static void mdec_yuv2_to_rgb24( psx_machine *p_psx ) |
| 895 | | { |
| 896 | | psx_mdec *p_mdec = &p_psx->mdec; |
| 897 | | INT32 n_r; |
| 898 | | INT32 n_g; |
| 899 | | INT32 n_b; |
| 900 | | INT32 n_cb; |
| 901 | | INT32 n_cr; |
| 902 | | INT32 *p_n_cb; |
| 903 | | INT32 *p_n_cr; |
| 904 | | INT32 *p_n_y; |
| 905 | | UINT32 n_x; |
| 906 | | UINT32 n_y; |
| 907 | | UINT32 n_z; |
| 908 | | UINT32 n_stp; |
| 909 | | int n_address = 0; |
| 910 | | |
| 911 | | if( ( p_psx->mdec.n_0_command & ( 1L << 25 ) ) != 0 ) |
| 912 | | { |
| 913 | | n_stp = 0x80008000; |
| 914 | | } |
| 915 | | else |
| 916 | | { |
| 917 | | n_stp = 0x00000000; |
| 918 | | } |
| 919 | | |
| 920 | | p_n_cr = &p_psx->mdec.p_n_unpacked[ 0 ]; |
| 921 | | p_n_cb = &p_psx->mdec.p_n_unpacked[ DCTSIZE2 ]; |
| 922 | | p_n_y = &p_psx->mdec.p_n_unpacked[ DCTSIZE2 * 2 ]; |
| 923 | | |
| 924 | | for( n_z = 0; n_z < 2; n_z++ ) |
| 925 | | { |
| 926 | | for( n_y = 0; n_y < 4; n_y++ ) |
| 927 | | { |
| 928 | | for( n_x = 0; n_x < 4; n_x++ ) |
| 929 | | { |
| 930 | | n_cr = *( p_n_cr ); |
| 931 | | n_cb = *( p_n_cb ); |
| 932 | | n_r = mdec_cr_to_r( n_cr ); |
| 933 | | n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); |
| 934 | | n_b = mdec_cb_to_b( n_cb ); |
| 935 | | |
| 936 | | mdec_makergb24( p_mdec, ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); |
| 937 | | mdec_makergb24( p_mdec, ( n_address + 48 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); |
| 938 | | |
| 939 | | n_cr = *( p_n_cr + 4 ); |
| 940 | | n_cb = *( p_n_cb + 4 ); |
| 941 | | n_r = mdec_cr_to_r( n_cr ); |
| 942 | | n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); |
| 943 | | n_b = mdec_cb_to_b( n_cb ); |
| 944 | | |
| 945 | | mdec_makergb24( p_mdec, ( n_address + 24 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); |
| 946 | | mdec_makergb24( p_mdec, ( n_address + 72 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); |
| 947 | | |
| 948 | | p_n_cr++; |
| 949 | | p_n_cb++; |
| 950 | | p_n_y += 2; |
| 951 | | n_address += 6; |
| 952 | | } |
| 953 | | p_n_cr += 4; |
| 954 | | p_n_cb += 4; |
| 955 | | p_n_y += 8; |
| 956 | | n_address += 72; |
| 957 | | } |
| 958 | | p_n_y += DCTSIZE2; |
| 959 | | } |
| 960 | | p_psx->mdec.n_decoded = ( 24 * 16 ) / 2; |
| 961 | | } |
| 962 | | |
| 963 | | static void mdec0_write( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 964 | | { |
| 965 | | psx_machine *p_psx = machine.driver_data<psx_state>()->m_p_psx; |
| 618 | psx_machine *p_psx = state->m_p_psx; |
| 966 | 619 | UINT32 *p_n_psxram = p_psx->p_n_psxram; |
| 967 | | int n_index; |
| 968 | 620 | |
| 969 | | verboselog( p_psx, 2, "mdec0_write( %08x, %08x )\n", n_address, n_size ); |
| 970 | | switch( p_psx->mdec.n_0_command >> 28 ) |
| 971 | | { |
| 972 | | case 0x3: |
| 973 | | verboselog( p_psx, 1, "mdec decode %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); |
| 974 | | p_psx->mdec.n_0_address = n_address; |
| 975 | | p_psx->mdec.n_0_size = n_size * 4; |
| 976 | | p_psx->mdec.n_1_status |= ( 1L << 29 ); |
| 977 | | break; |
| 978 | | case 0x4: |
| 979 | | verboselog( p_psx, 1, "mdec quantize table %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); |
| 980 | | n_index = 0; |
| 981 | | while( n_size > 0 ) |
| 982 | | { |
| 983 | | if( n_index < DCTSIZE2 ) |
| 984 | | { |
| 985 | | p_psx->mdec.p_n_quantize_y[ n_index + 0 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; |
| 986 | | p_psx->mdec.p_n_quantize_y[ n_index + 1 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; |
| 987 | | p_psx->mdec.p_n_quantize_y[ n_index + 2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; |
| 988 | | p_psx->mdec.p_n_quantize_y[ n_index + 3 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; |
| 989 | | } |
| 990 | | else if( n_index < DCTSIZE2 * 2 ) |
| 991 | | { |
| 992 | | p_psx->mdec.p_n_quantize_uv[ n_index + 0 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; |
| 993 | | p_psx->mdec.p_n_quantize_uv[ n_index + 1 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; |
| 994 | | p_psx->mdec.p_n_quantize_uv[ n_index + 2 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; |
| 995 | | p_psx->mdec.p_n_quantize_uv[ n_index + 3 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; |
| 996 | | } |
| 997 | | n_index += 4; |
| 998 | | n_address += 4; |
| 999 | | n_size--; |
| 1000 | | } |
| 1001 | | break; |
| 1002 | | case 0x6: |
| 1003 | | verboselog( p_psx, 1, "mdec cosine table %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); |
| 1004 | | n_index = 0; |
| 1005 | | while( n_size > 0 ) |
| 1006 | | { |
| 1007 | | p_psx->mdec.p_n_cos[ n_index + 0 ] = (INT16)( ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xffff ); |
| 1008 | | p_psx->mdec.p_n_cos[ n_index + 1 ] = (INT16)( ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xffff ); |
| 1009 | | n_index += 2; |
| 1010 | | n_address += 4; |
| 1011 | | n_size--; |
| 1012 | | } |
| 1013 | | mdec_cos_precalc(p_psx); |
| 1014 | | break; |
| 1015 | | default: |
| 1016 | | verboselog( p_psx, 0, "mdec unknown command %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); |
| 1017 | | break; |
| 1018 | | } |
| 621 | psx_gpu_write( state->machine(), &p_n_psxram[ n_address / 4 ], n_size ); |
| 1019 | 622 | } |
| 1020 | 623 | |
| 1021 | | static void mdec1_read( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 1022 | | { |
| 1023 | | psx_machine *p_psx = machine.driver_data<psx_state>()->m_p_psx; |
| 1024 | | UINT32 *p_n_psxram = p_psx->p_n_psxram; |
| 1025 | | UINT32 n_this; |
| 1026 | | UINT32 n_nextaddress; |
| 1027 | | |
| 1028 | | verboselog( p_psx, 2, "mdec1_read( %08x, %08x )\n", n_address, n_size ); |
| 1029 | | if( ( p_psx->mdec.n_0_command & ( 1L << 29 ) ) != 0 && p_psx->mdec.n_0_size != 0 ) |
| 1030 | | { |
| 1031 | | while( n_size > 0 ) |
| 1032 | | { |
| 1033 | | if( p_psx->mdec.n_decoded == 0 ) |
| 1034 | | { |
| 1035 | | if( (int)p_psx->mdec.n_0_size <= 0 ) |
| 1036 | | { |
| 1037 | | mame_printf_debug( "ran out of data %08x\n", n_size ); |
| 1038 | | p_psx->mdec.n_0_size = 0; |
| 1039 | | break; |
| 1040 | | } |
| 1041 | | |
| 1042 | | n_nextaddress = mdec_unpack( p_psx, p_psx->mdec.n_0_address ); |
| 1043 | | p_psx->mdec.n_0_size -= n_nextaddress - p_psx->mdec.n_0_address; |
| 1044 | | p_psx->mdec.n_0_address = n_nextaddress; |
| 1045 | | |
| 1046 | | if( ( p_psx->mdec.n_0_command & ( 1L << 27 ) ) != 0 ) |
| 1047 | | { |
| 1048 | | mdec_yuv2_to_rgb15(p_psx); |
| 1049 | | } |
| 1050 | | else |
| 1051 | | { |
| 1052 | | mdec_yuv2_to_rgb24(p_psx); |
| 1053 | | } |
| 1054 | | p_psx->mdec.n_offset = 0; |
| 1055 | | } |
| 1056 | | |
| 1057 | | n_this = p_psx->mdec.n_decoded; |
| 1058 | | if( n_this > n_size ) |
| 1059 | | { |
| 1060 | | n_this = n_size; |
| 1061 | | } |
| 1062 | | p_psx->mdec.n_decoded -= n_this; |
| 1063 | | |
| 1064 | | memcpy( (UINT8 *)p_n_psxram + n_address, (UINT8 *)p_psx->mdec.p_n_output + p_psx->mdec.n_offset, n_this * 4 ); |
| 1065 | | p_psx->mdec.n_offset += n_this * 4; |
| 1066 | | n_address += n_this * 4; |
| 1067 | | n_size -= n_this; |
| 1068 | | } |
| 1069 | | |
| 1070 | | if( (int)p_psx->mdec.n_0_size < 0 ) |
| 1071 | | { |
| 1072 | | mame_printf_debug( "ran out of data %d\n", p_psx->mdec.n_0_size ); |
| 1073 | | } |
| 1074 | | } |
| 1075 | | else |
| 1076 | | { |
| 1077 | | mame_printf_debug( "mdec1_read no conversion :%08x:%08x:\n", p_psx->mdec.n_0_command, p_psx->mdec.n_0_size ); |
| 1078 | | } |
| 1079 | | p_psx->mdec.n_1_status &= ~( 1L << 29 ); |
| 1080 | | } |
| 1081 | | |
| 1082 | | WRITE32_HANDLER( psx_mdec_w ) |
| 1083 | | { |
| 1084 | | psx_machine *p_psx = space->machine().driver_data<psx_state>()->m_p_psx; |
| 1085 | | |
| 1086 | | switch( offset ) |
| 1087 | | { |
| 1088 | | case 0: |
| 1089 | | verboselog( p_psx, 2, "mdec 0 command %08x\n", data ); |
| 1090 | | p_psx->mdec.n_0_command = data; |
| 1091 | | break; |
| 1092 | | case 1: |
| 1093 | | verboselog( p_psx, 2, "mdec 1 command %08x\n", data ); |
| 1094 | | p_psx->mdec.n_1_command = data; |
| 1095 | | break; |
| 1096 | | } |
| 1097 | | } |
| 1098 | | |
| 1099 | | READ32_HANDLER( psx_mdec_r ) |
| 1100 | | { |
| 1101 | | psx_machine *p_psx = space->machine().driver_data<psx_state>()->m_p_psx; |
| 1102 | | |
| 1103 | | switch( offset ) |
| 1104 | | { |
| 1105 | | case 0: |
| 1106 | | verboselog( p_psx, 2, "mdec 0 status %08x\n", 0 ); |
| 1107 | | return 0; |
| 1108 | | case 1: |
| 1109 | | verboselog( p_psx, 2, "mdec 1 status %08x\n", p_psx->mdec.n_1_status ); |
| 1110 | | return p_psx->mdec.n_1_status; |
| 1111 | | } |
| 1112 | | return 0; |
| 1113 | | } |
| 1114 | | |
| 1115 | | static void gpu_read( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 1116 | | { |
| 1117 | | psx_machine *p_psx = machine.driver_data<psx_state>()->m_p_psx; |
| 1118 | | UINT32 *p_n_psxram = p_psx->p_n_psxram; |
| 1119 | | |
| 1120 | | psx_gpu_read( machine, &p_n_psxram[ n_address / 4 ], n_size ); |
| 1121 | | } |
| 1122 | | |
| 1123 | | static void gpu_write( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 1124 | | { |
| 1125 | | psx_machine *p_psx = machine.driver_data<psx_state>()->m_p_psx; |
| 1126 | | UINT32 *p_n_psxram = p_psx->p_n_psxram; |
| 1127 | | |
| 1128 | | psx_gpu_write( machine, &p_n_psxram[ n_address / 4 ], n_size ); |
| 1129 | | } |
| 1130 | | |
| 1131 | 624 | void psx_machine_init( running_machine &machine ) |
| 1132 | 625 | { |
| 1133 | 626 | psx_machine *p_psx = machine.driver_data<psx_state>()->m_p_psx; |
| r11505 | r11506 | |
| 1137 | 630 | p_psx->n_irqdata = 0; |
| 1138 | 631 | p_psx->n_irqmask = 0; |
| 1139 | 632 | |
| 1140 | | p_psx->mdec.n_0_command = 0; |
| 1141 | | p_psx->mdec.n_0_address = 0; |
| 1142 | | p_psx->mdec.n_0_size = 0; |
| 1143 | | p_psx->mdec.n_1_command = 0; |
| 1144 | | p_psx->mdec.n_1_status = 0; |
| 1145 | | |
| 1146 | 633 | for( n = 0; n < 2; n++ ) |
| 1147 | 634 | { |
| 1148 | 635 | p_psx->sio[ n ].n_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; |
| r11505 | r11506 | |
| 1179 | 666 | { |
| 1180 | 667 | sio_timer_adjust( p_psx, n ); |
| 1181 | 668 | } |
| 1182 | | |
| 1183 | | mdec_cos_precalc(p_psx); |
| 1184 | 669 | } |
| 1185 | 670 | |
| 1186 | 671 | void psx_driver_init( running_machine &machine ) |
| r11505 | r11506 | |
| 1207 | 692 | p_psx->sio[ n ].fn_handler = NULL; |
| 1208 | 693 | } |
| 1209 | 694 | |
| 1210 | | for( n = 0; n < 256; n++ ) |
| 1211 | | { |
| 1212 | | p_psx->mdec.p_n_clamp8[ n ] = 0; |
| 1213 | | p_psx->mdec.p_n_clamp8[ n + 256 ] = n; |
| 1214 | | p_psx->mdec.p_n_clamp8[ n + 512 ] = 255; |
| 695 | psx_dma_install_read_handler( machine, 2, psx_dma_read_delegate( FUNC( gpu_read ), state ) ); |
| 696 | psx_dma_install_write_handler( machine, 2, psx_dma_write_delegate( FUNC( gpu_write ), state ) ); |
| 1215 | 697 | |
| 1216 | | p_psx->mdec.p_n_r5[ n ] = 0; |
| 1217 | | p_psx->mdec.p_n_r5[ n + 256 ] = ( n >> 3 ); |
| 1218 | | p_psx->mdec.p_n_r5[ n + 512 ] = ( 255 >> 3 ); |
| 1219 | | |
| 1220 | | p_psx->mdec.p_n_g5[ n ] = 0; |
| 1221 | | p_psx->mdec.p_n_g5[ n + 256 ] = ( n >> 3 ) << 5; |
| 1222 | | p_psx->mdec.p_n_g5[ n + 512 ] = ( 255 >> 3 ) << 5; |
| 1223 | | |
| 1224 | | p_psx->mdec.p_n_b5[ n ] = 0; |
| 1225 | | p_psx->mdec.p_n_b5[ n + 256 ] = ( n >> 3 ) << 10; |
| 1226 | | p_psx->mdec.p_n_b5[ n + 512 ] = ( 255 >> 3 ) << 10; |
| 1227 | | } |
| 1228 | | |
| 1229 | | psx_dma_install_read_handler( machine, 1, mdec1_read ); |
| 1230 | | psx_dma_install_read_handler( machine, 2, gpu_read ); |
| 1231 | | |
| 1232 | | psx_dma_install_write_handler( machine, 0, mdec0_write ); |
| 1233 | | psx_dma_install_write_handler( machine, 2, gpu_write ); |
| 1234 | | |
| 1235 | 698 | state_save_register_global( machine, p_psx->n_irqdata ); |
| 1236 | 699 | state_save_register_global( machine, p_psx->n_irqmask ); |
| 1237 | 700 | for ( n = 0; n < 3; n++ ) |
| r11505 | r11506 | |
| 1259 | 722 | state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx_bits ); |
| 1260 | 723 | } |
| 1261 | 724 | |
| 1262 | | state_save_register_global( machine, p_psx->mdec.n_0_command ); |
| 1263 | | state_save_register_global( machine, p_psx->mdec.n_0_address ); |
| 1264 | | state_save_register_global( machine, p_psx->mdec.n_0_size ); |
| 1265 | | state_save_register_global( machine, p_psx->mdec.n_1_command ); |
| 1266 | | state_save_register_global( machine, p_psx->mdec.n_1_status ); |
| 1267 | | state_save_register_global_array( machine, p_psx->mdec.p_n_quantize_y ); |
| 1268 | | state_save_register_global_array( machine, p_psx->mdec.p_n_quantize_uv ); |
| 1269 | | state_save_register_global_array( machine, p_psx->mdec.p_n_cos ); |
| 1270 | | |
| 1271 | 725 | machine.save().register_postload( save_prepost_delegate(FUNC(psx_postload), p_psx )); |
| 1272 | 726 | } |
src/mame/drivers/psx.c
| r11505 | r11506 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | Sony Playstaion |
| 4 | | =============== |
| 5 | | Preliminary driver by smf |
| 6 | | Additional development by pSXAuthor and R. Belmont |
| 7 | | |
| 8 | | ***************************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "cpu/psx/psx.h" |
| 12 | | #include "imagedev/snapquik.h" |
| 13 | | #include "imagedev/chd_cd.h" |
| 14 | | #include "includes/psx.h" |
| 15 | | #include "sound/spu.h" |
| 16 | | #include "debugger.h" |
| 17 | | #include "zlib.h" |
| 18 | | #include "machine/psxcd.h" |
| 19 | | #include "machine/psxcard.h" |
| 20 | | |
| 21 | | typedef struct |
| 22 | | { |
| 23 | | UINT8 n_shiftin; |
| 24 | | UINT8 n_shiftout; |
| 25 | | int n_bits; |
| 26 | | int n_state; |
| 27 | | int n_byte; |
| 28 | | int b_lastclock; |
| 29 | | int b_ack; |
| 30 | | } pad_t; |
| 31 | | |
| 32 | | |
| 33 | | class psx1_state : public psx_state |
| 34 | | { |
| 35 | | public: |
| 36 | | psx1_state(const machine_config &mconfig, device_type type, const char *tag) |
| 37 | | : psx_state(mconfig, type, tag) { } |
| 38 | | |
| 39 | | UINT8 *m_exe_buffer; |
| 40 | | int m_exe_size; |
| 41 | | pad_t m_pad[ 2 ]; |
| 42 | | int m_cd_param_p; |
| 43 | | int m_cd_result_p; |
| 44 | | int m_cd_result_c; |
| 45 | | int m_cd_result_ready; |
| 46 | | int m_cd_reset; |
| 47 | | UINT8 m_cd_stat; |
| 48 | | UINT8 m_cd_io_status; |
| 49 | | UINT8 m_cd_param[8]; |
| 50 | | UINT8 m_cd_result[8]; |
| 51 | | }; |
| 52 | | |
| 53 | | |
| 54 | | #define VERBOSE_LEVEL ( 0 ) |
| 55 | | |
| 56 | | INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ... ) |
| 57 | | { |
| 58 | | if( VERBOSE_LEVEL >= n_level ) |
| 59 | | { |
| 60 | | va_list v; |
| 61 | | char buf[ 32768 ]; |
| 62 | | va_start( v, s_fmt ); |
| 63 | | vsprintf( buf, s_fmt, v ); |
| 64 | | va_end( v ); |
| 65 | | logerror( "%s: %s", machine.describe_context(), buf ); |
| 66 | | } |
| 67 | | } |
| 68 | | |
| 69 | | |
| 70 | | static void psxexe_conv32( UINT32 *p_uint32 ) |
| 71 | | { |
| 72 | | UINT8 *p_uint8; |
| 73 | | |
| 74 | | p_uint8 = (UINT8 *)p_uint32; |
| 75 | | |
| 76 | | *( p_uint32 ) = p_uint8[ 0 ] | |
| 77 | | ( p_uint8[ 1 ] << 8 ) | |
| 78 | | ( p_uint8[ 2 ] << 16 ) | |
| 79 | | ( p_uint8[ 3 ] << 24 ); |
| 80 | | } |
| 81 | | |
| 82 | | static int load_psxexe( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 83 | | { |
| 84 | | psx_state *state = cpu->machine().driver_data<psx_state>(); |
| 85 | | struct PSXEXE_HEADER |
| 86 | | { |
| 87 | | UINT8 id[ 8 ]; |
| 88 | | UINT32 text; /* SCE only */ |
| 89 | | UINT32 data; /* SCE only */ |
| 90 | | UINT32 pc0; |
| 91 | | UINT32 gp0; /* SCE only */ |
| 92 | | UINT32 t_addr; |
| 93 | | UINT32 t_size; |
| 94 | | UINT32 d_addr; /* SCE only */ |
| 95 | | UINT32 d_size; /* SCE only */ |
| 96 | | UINT32 b_addr; /* SCE only */ |
| 97 | | UINT32 b_size; /* SCE only */ |
| 98 | | UINT32 s_addr; |
| 99 | | UINT32 s_size; |
| 100 | | UINT32 SavedSP; |
| 101 | | UINT32 SavedFP; |
| 102 | | UINT32 SavedGP; |
| 103 | | UINT32 SavedRA; |
| 104 | | UINT32 SavedS0; |
| 105 | | UINT8 dummy[ 0x800 - 76 ]; |
| 106 | | }; |
| 107 | | |
| 108 | | struct PSXEXE_HEADER *psxexe_header = (struct PSXEXE_HEADER *)p_n_file; |
| 109 | | |
| 110 | | if( n_len >= sizeof( struct PSXEXE_HEADER ) && |
| 111 | | memcmp( psxexe_header->id, "PS-X EXE", 8 ) == 0 ) |
| 112 | | { |
| 113 | | UINT8 *p_ram; |
| 114 | | UINT8 *p_psxexe; |
| 115 | | UINT32 n_stack; |
| 116 | | UINT32 n_ram; |
| 117 | | UINT32 n_address; |
| 118 | | UINT32 n_size; |
| 119 | | |
| 120 | | psxexe_conv32( &psxexe_header->text ); |
| 121 | | psxexe_conv32( &psxexe_header->data ); |
| 122 | | psxexe_conv32( &psxexe_header->pc0 ); |
| 123 | | psxexe_conv32( &psxexe_header->gp0 ); |
| 124 | | psxexe_conv32( &psxexe_header->t_addr ); |
| 125 | | psxexe_conv32( &psxexe_header->t_size ); |
| 126 | | psxexe_conv32( &psxexe_header->d_addr ); |
| 127 | | psxexe_conv32( &psxexe_header->d_size ); |
| 128 | | psxexe_conv32( &psxexe_header->b_addr ); |
| 129 | | psxexe_conv32( &psxexe_header->b_size ); |
| 130 | | psxexe_conv32( &psxexe_header->s_addr ); |
| 131 | | psxexe_conv32( &psxexe_header->s_size ); |
| 132 | | psxexe_conv32( &psxexe_header->SavedSP ); |
| 133 | | psxexe_conv32( &psxexe_header->SavedFP ); |
| 134 | | psxexe_conv32( &psxexe_header->SavedGP ); |
| 135 | | psxexe_conv32( &psxexe_header->SavedRA ); |
| 136 | | psxexe_conv32( &psxexe_header->SavedS0 ); |
| 137 | | |
| 138 | | /* todo: check size.. */ |
| 139 | | |
| 140 | | logerror( "psx_exe_load: pc %08x\n", psxexe_header->pc0 ); |
| 141 | | logerror( "psx_exe_load: org %08x\n", psxexe_header->t_addr ); |
| 142 | | logerror( "psx_exe_load: len %08x\n", psxexe_header->t_size ); |
| 143 | | logerror( "psx_exe_load: sp %08x\n", psxexe_header->s_addr ); |
| 144 | | logerror( "psx_exe_load: len %08x\n", psxexe_header->s_size ); |
| 145 | | |
| 146 | | p_ram = (UINT8 *)state->m_p_n_psxram; |
| 147 | | n_ram = state->m_n_psxramsize; |
| 148 | | |
| 149 | | p_psxexe = p_n_file + sizeof( struct PSXEXE_HEADER ); |
| 150 | | |
| 151 | | n_address = psxexe_header->t_addr; |
| 152 | | n_size = psxexe_header->t_size; |
| 153 | | while( n_size != 0 ) |
| 154 | | { |
| 155 | | p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = *( p_psxexe ); |
| 156 | | n_address++; |
| 157 | | p_psxexe++; |
| 158 | | n_size--; |
| 159 | | } |
| 160 | | |
| 161 | | cpu_set_reg( cpu, PSXCPU_PC, psxexe_header->pc0 ); |
| 162 | | cpu_set_reg( cpu, PSXCPU_R28, psxexe_header->gp0 ); |
| 163 | | n_stack = psxexe_header->s_addr + psxexe_header->s_size; |
| 164 | | if( n_stack != 0 ) |
| 165 | | { |
| 166 | | cpu_set_reg( cpu, PSXCPU_R29, n_stack ); |
| 167 | | cpu_set_reg( cpu, PSXCPU_R30, n_stack ); |
| 168 | | } |
| 169 | | |
| 170 | | return 1; |
| 171 | | } |
| 172 | | return 0; |
| 173 | | } |
| 174 | | |
| 175 | | static void cpe_set_register( device_t *cpu, int n_reg, int n_value ) |
| 176 | | { |
| 177 | | if( n_reg < 0x80 && ( n_reg % 4 ) == 0 ) |
| 178 | | { |
| 179 | | logerror( "psx_exe_load: r%-2d %08x\n", n_reg / 4, n_value ); |
| 180 | | cpu_set_reg( cpu, PSXCPU_R0 + ( n_reg / 4 ), n_value ); |
| 181 | | } |
| 182 | | else if( n_reg == 0x80 ) |
| 183 | | { |
| 184 | | logerror( "psx_exe_load: lo %08x\n", n_value ); |
| 185 | | cpu_set_reg( cpu, PSXCPU_LO, n_value ); |
| 186 | | } |
| 187 | | else if( n_reg == 0x84 ) |
| 188 | | { |
| 189 | | logerror( "psx_exe_load: hi %08x\n", n_value ); |
| 190 | | cpu_set_reg( cpu, PSXCPU_HI, n_value ); |
| 191 | | } |
| 192 | | else if( n_reg == 0x88 ) |
| 193 | | { |
| 194 | | logerror( "psx_exe_load: sr %08x\n", n_value ); |
| 195 | | cpu_set_reg( cpu, PSXCPU_CP0R12, n_value ); |
| 196 | | } |
| 197 | | else if( n_reg == 0x8c ) |
| 198 | | { |
| 199 | | logerror( "psx_exe_load: cause %08x\n", n_value ); |
| 200 | | cpu_set_reg( cpu, PSXCPU_CP0R13, n_value ); |
| 201 | | } |
| 202 | | else if( n_reg == 0x90 ) |
| 203 | | { |
| 204 | | logerror( "psx_exe_load: pc %08x\n", n_value ); |
| 205 | | cpu_set_reg( cpu, PSXCPU_PC, n_value ); |
| 206 | | } |
| 207 | | else if( n_reg == 0x94 ) |
| 208 | | { |
| 209 | | logerror( "psx_exe_load: prid %08x\n", n_value ); |
| 210 | | cpu_set_reg( cpu, PSXCPU_CP0R15, n_value ); |
| 211 | | } |
| 212 | | else |
| 213 | | { |
| 214 | | logerror( "psx_exe_load: invalid register %04x/%08x\n", n_reg, n_value ); |
| 215 | | } |
| 216 | | } |
| 217 | | |
| 218 | | static int load_cpe( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 219 | | { |
| 220 | | psx_state *state = cpu->machine().driver_data<psx_state>(); |
| 221 | | if( n_len >= 4 && |
| 222 | | memcmp( p_n_file, "CPE\001", 4 ) == 0 ) |
| 223 | | { |
| 224 | | int n_offset = 4; |
| 225 | | |
| 226 | | for( ;; ) |
| 227 | | { |
| 228 | | if( n_offset >= n_len || p_n_file[ n_offset ] > 8 ) |
| 229 | | { |
| 230 | | break; |
| 231 | | } |
| 232 | | |
| 233 | | switch( p_n_file[ n_offset++ ] ) |
| 234 | | { |
| 235 | | case 0: |
| 236 | | /* end of file */ |
| 237 | | return 1; |
| 238 | | case 1: |
| 239 | | /* read bytes */ |
| 240 | | { |
| 241 | | int n_address = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 242 | | ( (int)p_n_file[ n_offset + 1 ] << 8 ) | |
| 243 | | ( (int)p_n_file[ n_offset + 2 ] << 16 ) | |
| 244 | | ( (int)p_n_file[ n_offset + 3 ] << 24 ); |
| 245 | | int n_size = ( (int)p_n_file[ n_offset + 4 ] << 0 ) | |
| 246 | | ( (int)p_n_file[ n_offset + 5 ] << 8 ) | |
| 247 | | ( (int)p_n_file[ n_offset + 6 ] << 16 ) | |
| 248 | | ( (int)p_n_file[ n_offset + 7 ] << 24 ); |
| 249 | | |
| 250 | | UINT8 *p_ram = (UINT8 *)state->m_p_n_psxram; |
| 251 | | UINT32 n_ram = state->m_n_psxramsize; |
| 252 | | |
| 253 | | n_offset += 8; |
| 254 | | |
| 255 | | logerror( "psx_exe_load: org %08x\n", n_address ); |
| 256 | | logerror( "psx_exe_load: len %08x\n", n_size ); |
| 257 | | |
| 258 | | while( n_size > 0 ) |
| 259 | | { |
| 260 | | p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = p_n_file[ n_offset++ ]; |
| 261 | | n_address++; |
| 262 | | n_size--; |
| 263 | | } |
| 264 | | break; |
| 265 | | } |
| 266 | | case 2: |
| 267 | | /* run address: not tested */ |
| 268 | | { |
| 269 | | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 270 | | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 271 | | ( (int)p_n_file[ n_offset + 4 ] << 16 ) | |
| 272 | | ( (int)p_n_file[ n_offset + 5 ] << 24 ); |
| 273 | | |
| 274 | | n_offset += 4; |
| 275 | | |
| 276 | | cpe_set_register( cpu, 0x90, n_value ); |
| 277 | | break; |
| 278 | | } |
| 279 | | case 3: |
| 280 | | /* set reg to longword */ |
| 281 | | { |
| 282 | | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 283 | | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 284 | | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 285 | | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 286 | | ( (int)p_n_file[ n_offset + 4 ] << 16 ) | |
| 287 | | ( (int)p_n_file[ n_offset + 5 ] << 24 ); |
| 288 | | |
| 289 | | n_offset += 6; |
| 290 | | |
| 291 | | cpe_set_register( cpu, n_reg, n_value ); |
| 292 | | break; |
| 293 | | } |
| 294 | | case 4: |
| 295 | | /* set reg to word: not tested */ |
| 296 | | { |
| 297 | | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 298 | | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 299 | | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 300 | | ( (int)p_n_file[ n_offset + 3 ] << 8 ); |
| 301 | | |
| 302 | | n_offset += 4; |
| 303 | | |
| 304 | | cpe_set_register( cpu, n_reg, n_value ); |
| 305 | | break; |
| 306 | | } |
| 307 | | case 5: |
| 308 | | /* set reg to byte: not tested */ |
| 309 | | { |
| 310 | | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 311 | | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 312 | | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ); |
| 313 | | |
| 314 | | n_offset += 3; |
| 315 | | |
| 316 | | cpe_set_register( cpu, n_reg, n_value ); |
| 317 | | break; |
| 318 | | } |
| 319 | | case 6: |
| 320 | | /* set reg to 3-byte: not tested */ |
| 321 | | { |
| 322 | | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 323 | | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 324 | | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 325 | | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 326 | | ( (int)p_n_file[ n_offset + 4 ] << 16 ); |
| 327 | | |
| 328 | | n_offset += 5; |
| 329 | | |
| 330 | | cpe_set_register( cpu, n_reg, n_value ); |
| 331 | | break; |
| 332 | | } |
| 333 | | case 7: |
| 334 | | /* workspace: not tested */ |
| 335 | | n_offset += 4; |
| 336 | | break; |
| 337 | | case 8: |
| 338 | | /* unit */ |
| 339 | | { |
| 340 | | int n_unit = p_n_file[ n_offset + 0 ]; |
| 341 | | |
| 342 | | n_offset++; |
| 343 | | |
| 344 | | logerror( "psx_exe_load: unit %08x\n", n_unit ); |
| 345 | | } |
| 346 | | break; |
| 347 | | } |
| 348 | | } |
| 349 | | } |
| 350 | | return 0; |
| 351 | | } |
| 352 | | |
| 353 | | static int load_psf( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 354 | | { |
| 355 | | int n_return; |
| 356 | | unsigned long n_crc; |
| 357 | | unsigned long n_compressed; |
| 358 | | unsigned char *p_n_compressed; |
| 359 | | unsigned long n_uncompressed; |
| 360 | | unsigned char *p_n_uncompressed; |
| 361 | | |
| 362 | | struct PSF_HEADER |
| 363 | | { |
| 364 | | unsigned char id[ 4 ]; |
| 365 | | UINT32 reserved_size; |
| 366 | | UINT32 exe_size; |
| 367 | | UINT32 exe_crc; |
| 368 | | }; |
| 369 | | |
| 370 | | struct PSF_HEADER *psf_header = (struct PSF_HEADER *)p_n_file; |
| 371 | | |
| 372 | | n_return = 0; |
| 373 | | |
| 374 | | if( n_len >= sizeof( struct PSF_HEADER ) && |
| 375 | | memcmp( p_n_file, "PSF", 3 ) == 0 ) |
| 376 | | { |
| 377 | | psxexe_conv32( &psf_header->reserved_size ); |
| 378 | | psxexe_conv32( &psf_header->exe_size ); |
| 379 | | psxexe_conv32( &psf_header->exe_crc ); |
| 380 | | |
| 381 | | logerror( "psx_exe_load: reserved_size %08x\n", psf_header->reserved_size ); |
| 382 | | logerror( "psx_exe_load: exe_size %08x\n", psf_header->exe_size ); |
| 383 | | logerror( "psx_exe_load: exe_crc %08x\n", psf_header->exe_crc ); |
| 384 | | |
| 385 | | n_compressed = psf_header->exe_size; |
| 386 | | p_n_compressed = p_n_file + sizeof( struct PSF_HEADER ) + psf_header->reserved_size; |
| 387 | | |
| 388 | | n_crc = crc32( crc32( 0L, Z_NULL, 0 ), p_n_compressed, n_compressed ); |
| 389 | | if( n_crc != psf_header->exe_crc ) |
| 390 | | { |
| 391 | | logerror( "psx_exe_load: psf invalid crc\n" ); |
| 392 | | return 0; |
| 393 | | } |
| 394 | | |
| 395 | | n_uncompressed = 0x200000; |
| 396 | | p_n_uncompressed = (unsigned char *)malloc( n_uncompressed ); |
| 397 | | |
| 398 | | if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK ) |
| 399 | | { |
| 400 | | logerror( "psx_exe_load: psf uncompress failed\n" ); |
| 401 | | } |
| 402 | | else if( !load_psxexe( cpu, p_n_uncompressed, n_uncompressed ) ) |
| 403 | | { |
| 404 | | logerror( "psx_exe_load: psf load failed\n" ); |
| 405 | | } |
| 406 | | else |
| 407 | | { |
| 408 | | n_return = 1; |
| 409 | | } |
| 410 | | |
| 411 | | free( p_n_uncompressed ); |
| 412 | | } |
| 413 | | return n_return; |
| 414 | | } |
| 415 | | |
| 416 | | DIRECT_UPDATE_HANDLER( psx_default ) |
| 417 | | { |
| 418 | | return address; |
| 419 | | } |
| 420 | | |
| 421 | | DIRECT_UPDATE_HANDLER( psx_setopbase ) |
| 422 | | { |
| 423 | | psx1_state *state = machine.driver_data<psx1_state>(); |
| 424 | | if( address == 0x80030000 ) |
| 425 | | { |
| 426 | | device_t *cpu = machine.device("maincpu"); |
| 427 | | |
| 428 | | machine.device("maincpu")->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate(FUNC(psx_default), &machine)); |
| 429 | | |
| 430 | | if( load_psxexe( cpu, state->m_exe_buffer, state->m_exe_size ) || |
| 431 | | load_cpe( cpu, state->m_exe_buffer, state->m_exe_size ) || |
| 432 | | load_psf( cpu, state->m_exe_buffer, state->m_exe_size ) ) |
| 433 | | { |
| 434 | | /* DEBUGGER_BREAK; */ |
| 435 | | |
| 436 | | address = cpu_get_reg( cpu, PSXCPU_PC ); |
| 437 | | } |
| 438 | | else |
| 439 | | { |
| 440 | | logerror( "psx_exe_load: invalid exe\n" ); |
| 441 | | } |
| 442 | | |
| 443 | | state->m_exe_size = 0; |
| 444 | | free( state->m_exe_buffer ); |
| 445 | | } |
| 446 | | return address; |
| 447 | | } |
| 448 | | |
| 449 | | static QUICKLOAD_LOAD( psx_exe_load ) |
| 450 | | { |
| 451 | | psx1_state *state = image.device().machine().driver_data<psx1_state>(); |
| 452 | | address_space *space = image.device().machine().device( "maincpu")->memory().space( AS_PROGRAM ); |
| 453 | | |
| 454 | | state->m_exe_size = 0; |
| 455 | | state->m_exe_buffer = (UINT8*)malloc( quickload_size ); |
| 456 | | if( state->m_exe_buffer == NULL ) |
| 457 | | { |
| 458 | | logerror( "psx_exe_load: out of memory\n" ); |
| 459 | | return IMAGE_INIT_FAIL; |
| 460 | | } |
| 461 | | if( image.fread( state->m_exe_buffer, quickload_size ) != quickload_size ) |
| 462 | | { |
| 463 | | free( state->m_exe_buffer ); |
| 464 | | return IMAGE_INIT_FAIL; |
| 465 | | } |
| 466 | | state->m_exe_size = quickload_size; |
| 467 | | space->set_direct_update_handler(direct_update_delegate(FUNC(psx_setopbase), &image.device().machine())); |
| 468 | | |
| 469 | | return IMAGE_INIT_PASS; |
| 470 | | } |
| 471 | | |
| 472 | | /* PAD emulation */ |
| 473 | | |
| 474 | | #define PAD_STATE_IDLE ( 0 ) |
| 475 | | #define PAD_STATE_LISTEN ( 1 ) |
| 476 | | #define PAD_STATE_ACTIVE ( 2 ) |
| 477 | | #define PAD_STATE_READ ( 3 ) |
| 478 | | #define PAD_STATE_UNLISTEN ( 4 ) |
| 479 | | #define PAD_STATE_MEMCARD ( 5 ) |
| 480 | | |
| 481 | | #define PAD_TYPE_STANDARD ( 4 ) |
| 482 | | #define PAD_BYTES_STANDARD ( 2 ) |
| 483 | | |
| 484 | | #define PAD_CMD_START ( 0x01 ) |
| 485 | | #define PAD_CMD_READ ( 0x42 ) /* B */ |
| 486 | | |
| 487 | | #define PAD_DATA_OK ( 0x5a ) /* Z */ |
| 488 | | #define PAD_DATA_IDLE ( 0xff ) |
| 489 | | |
| 490 | | static TIMER_CALLBACK(psx_pad_ack) |
| 491 | | { |
| 492 | | psx1_state *state = machine.driver_data<psx1_state>(); |
| 493 | | int n_port = param; |
| 494 | | pad_t *pad = &state->m_pad[ n_port ]; |
| 495 | | |
| 496 | | if( pad->n_state != PAD_STATE_IDLE ) |
| 497 | | { |
| 498 | | psx_sio_input( machine, 0, PSX_SIO_IN_DSR, pad->b_ack * PSX_SIO_IN_DSR ); |
| 499 | | if( !pad->b_ack ) |
| 500 | | { |
| 501 | | pad->b_ack = 1; |
| 502 | | machine.scheduler().timer_set(attotime::from_usec( 2 ), FUNC(psx_pad_ack) , n_port); |
| 503 | | } |
| 504 | | } |
| 505 | | } |
| 506 | | |
| 507 | | static void psx_pad( running_machine &machine, int n_port, int n_data ) |
| 508 | | { |
| 509 | | psx1_state *state = machine.driver_data<psx1_state>(); |
| 510 | | pad_t *pad = &state->m_pad[ n_port ]; |
| 511 | | int b_sel; |
| 512 | | int b_clock; |
| 513 | | int b_data; |
| 514 | | int b_ack; |
| 515 | | int b_ready; |
| 516 | | static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" }; |
| 517 | | psxcard_device *psxcard = NULL; |
| 518 | | |
| 519 | | if (n_port == 0) |
| 520 | | { |
| 521 | | psxcard = machine.device<psxcard_device>("card1"); |
| 522 | | } |
| 523 | | else |
| 524 | | { |
| 525 | | psxcard = machine.device<psxcard_device>("card2"); |
| 526 | | } |
| 527 | | |
| 528 | | b_sel = ( n_data & PSX_SIO_OUT_DTR ) / PSX_SIO_OUT_DTR; |
| 529 | | b_clock = ( n_data & PSX_SIO_OUT_CLOCK ) / PSX_SIO_OUT_CLOCK; |
| 530 | | b_data = ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA; |
| 531 | | b_ready = 0; |
| 532 | | b_ack = 0; |
| 533 | | |
| 534 | | if( b_sel ) |
| 535 | | { |
| 536 | | pad->n_state = PAD_STATE_IDLE; |
| 537 | | } |
| 538 | | |
| 539 | | switch( pad->n_state ) |
| 540 | | { |
| 541 | | case PAD_STATE_LISTEN: |
| 542 | | case PAD_STATE_ACTIVE: |
| 543 | | case PAD_STATE_READ: |
| 544 | | case PAD_STATE_MEMCARD: |
| 545 | | if( pad->b_lastclock && !b_clock ) |
| 546 | | { |
| 547 | | psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( pad->n_shiftout & 1 ) * PSX_SIO_IN_DATA ); |
| 548 | | pad->n_shiftout >>= 1; |
| 549 | | } |
| 550 | | if( !pad->b_lastclock && b_clock ) |
| 551 | | { |
| 552 | | pad->n_shiftin >>= 1; |
| 553 | | pad->n_shiftin |= b_data << 7; |
| 554 | | pad->n_bits++; |
| 555 | | |
| 556 | | if( pad->n_bits == 8 ) |
| 557 | | { |
| 558 | | pad->n_bits = 0; |
| 559 | | b_ready = 1; |
| 560 | | } |
| 561 | | } |
| 562 | | break; |
| 563 | | } |
| 564 | | |
| 565 | | pad->b_lastclock = b_clock; |
| 566 | | |
| 567 | | switch( pad->n_state ) |
| 568 | | { |
| 569 | | case PAD_STATE_IDLE: |
| 570 | | if( !b_sel ) |
| 571 | | { |
| 572 | | pad->n_state = PAD_STATE_LISTEN; |
| 573 | | pad->n_shiftout = PAD_DATA_IDLE; |
| 574 | | pad->n_bits = 0; |
| 575 | | } |
| 576 | | break; |
| 577 | | case PAD_STATE_LISTEN: |
| 578 | | if( b_ready ) |
| 579 | | { |
| 580 | | if( pad->n_shiftin == PAD_CMD_START ) |
| 581 | | { |
| 582 | | pad->n_state = PAD_STATE_ACTIVE; |
| 583 | | pad->n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 ); |
| 584 | | b_ack = 1; |
| 585 | | } |
| 586 | | else if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) ) |
| 587 | | { |
| 588 | | pad->n_state = PAD_STATE_MEMCARD; |
| 589 | | b_ack = 1; |
| 590 | | } |
| 591 | | else |
| 592 | | { |
| 593 | | pad->n_state = PAD_STATE_UNLISTEN; |
| 594 | | } |
| 595 | | } |
| 596 | | break; |
| 597 | | case PAD_STATE_MEMCARD: |
| 598 | | if( b_ready ) |
| 599 | | { |
| 600 | | if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) ) |
| 601 | | { |
| 602 | | b_ack = 1; |
| 603 | | } |
| 604 | | else |
| 605 | | { |
| 606 | | b_ack = 0; |
| 607 | | pad->n_state = PAD_STATE_IDLE; |
| 608 | | } |
| 609 | | } |
| 610 | | break; |
| 611 | | case PAD_STATE_ACTIVE: |
| 612 | | if( b_ready ) |
| 613 | | { |
| 614 | | if( pad->n_shiftin == PAD_CMD_READ ) |
| 615 | | { |
| 616 | | pad->n_state = PAD_STATE_READ; |
| 617 | | pad->n_shiftout = PAD_DATA_OK; |
| 618 | | pad->n_byte = 0; |
| 619 | | b_ack = 1; |
| 620 | | } |
| 621 | | else |
| 622 | | { |
| 623 | | pad->n_state = PAD_STATE_UNLISTEN; |
| 624 | | } |
| 625 | | } |
| 626 | | break; |
| 627 | | case PAD_STATE_READ: |
| 628 | | if( b_ready ) |
| 629 | | { |
| 630 | | if( pad->n_byte < PAD_BYTES_STANDARD ) |
| 631 | | { |
| 632 | | pad->n_shiftout = input_port_read(machine, portnames[pad->n_byte + ( n_port * PAD_BYTES_STANDARD )]); |
| 633 | | pad->n_byte++; |
| 634 | | b_ack = 1; |
| 635 | | } |
| 636 | | else |
| 637 | | { |
| 638 | | pad->n_state = PAD_STATE_LISTEN; |
| 639 | | } |
| 640 | | } |
| 641 | | break; |
| 642 | | } |
| 643 | | |
| 644 | | if( b_ack ) |
| 645 | | { |
| 646 | | pad->b_ack = 0; |
| 647 | | machine.scheduler().timer_set(attotime::from_usec( 10 ), FUNC(psx_pad_ack), n_port); |
| 648 | | } |
| 649 | | } |
| 650 | | |
| 651 | | static void psx_sio0( running_machine &machine, int n_data ) |
| 652 | | { |
| 653 | | /* todo: raise data & ack when nothing is driving it low */ |
| 654 | | psx_pad( machine, 0, n_data ); |
| 655 | | psx_pad( machine, 1, n_data ^ PSX_SIO_OUT_DTR ); |
| 656 | | } |
| 657 | | |
| 658 | | /* ----------------------------------------------------------------------- */ |
| 659 | | |
| 660 | | static void cd_dma_read( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 661 | | { |
| 662 | | psxcd_device *psxcd = machine.device<psxcd_device>("psxcd"); |
| 663 | | UINT8 *psxram = (UINT8 *)memory_get_shared(machine, "share1"); |
| 664 | | |
| 665 | | psxcd->start_dma(psxram + n_address, n_size*4); |
| 666 | | } |
| 667 | | |
| 668 | | static void cd_dma_write( running_machine &machine, UINT32 n_address, INT32 n_size ) |
| 669 | | { |
| 670 | | printf("cd_dma_write?!: addr %x, size %x\n", n_address, n_size); |
| 671 | | } |
| 672 | | |
| 673 | | static READ8_HANDLER( psx_cd_r ) |
| 674 | | { |
| 675 | | psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG); |
| 676 | | |
| 677 | | return psxcd->read_byte(offset); |
| 678 | | } |
| 679 | | |
| 680 | | static WRITE8_HANDLER( psx_cd_w ) |
| 681 | | { |
| 682 | | psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG); |
| 683 | | |
| 684 | | psxcd->write_byte(offset, data); |
| 685 | | } |
| 686 | | |
| 687 | | static ADDRESS_MAP_START( psx_map, AS_PROGRAM, 32 ) |
| 688 | | AM_RANGE(0x00000000, 0x001fffff) AM_RAM AM_SHARE("share1") /* ram */ |
| 689 | | AM_RANGE(0x1f801800, 0x1f801803) AM_READWRITE8(psx_cd_r, psx_cd_w, 0xffffffff) |
| 690 | | AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */ |
| 691 | | AM_RANGE(0x80000000, 0x801fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 692 | | AM_RANGE(0x80600000, 0x807fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 693 | | AM_RANGE(0x9fc00000, 0x9fc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */ |
| 694 | | AM_RANGE(0xa0000000, 0xa01fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 695 | | AM_RANGE(0xbfc00000, 0xbfc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */ |
| 696 | | AM_RANGE(0xfffe0130, 0xfffe0133) AM_WRITENOP |
| 697 | | ADDRESS_MAP_END |
| 698 | | |
| 699 | | |
| 700 | | static MACHINE_RESET( psx ) |
| 701 | | { |
| 702 | | psx_machine_init(machine); |
| 703 | | psx_sio_install_handler( machine, 0, psx_sio0 ); |
| 704 | | |
| 705 | | psx_dma_install_read_handler(machine, 3, cd_dma_read); |
| 706 | | psx_dma_install_write_handler(machine, 3, cd_dma_write); |
| 707 | | } |
| 708 | | |
| 709 | | static DRIVER_INIT( psx ) |
| 710 | | { |
| 711 | | psx_driver_init(machine); |
| 712 | | } |
| 713 | | |
| 714 | | static INPUT_PORTS_START( psx ) |
| 715 | | PORT_START("IN0") |
| 716 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) |
| 717 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) |
| 718 | | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) |
| 719 | | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) |
| 720 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1) |
| 721 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1) |
| 722 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1) |
| 723 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(1) |
| 724 | | |
| 725 | | PORT_START("IN1") |
| 726 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Square") |
| 727 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Cross") |
| 728 | | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Circle") |
| 729 | | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 Triangle") |
| 730 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 R1") |
| 731 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 L1") |
| 732 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 R2") |
| 733 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 L2") |
| 734 | | |
| 735 | | PORT_START("IN2") |
| 736 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) |
| 737 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) |
| 738 | | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) |
| 739 | | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) |
| 740 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2) |
| 741 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) |
| 742 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) |
| 743 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(2) |
| 744 | | |
| 745 | | PORT_START("IN3") |
| 746 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Square") |
| 747 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Cross") |
| 748 | | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Circle") |
| 749 | | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 Triangle") |
| 750 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 R1") |
| 751 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 L1") |
| 752 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 R2") |
| 753 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 L2") |
| 754 | | INPUT_PORTS_END |
| 755 | | |
| 756 | | static void spu_irq(device_t *device, UINT32 data) |
| 757 | | { |
| 758 | | if (data) |
| 759 | | { |
| 760 | | psx_irq_set(device->machine(), 1<<9); |
| 761 | | } |
| 762 | | } |
| 763 | | |
| 764 | | static MACHINE_CONFIG_START( psxntsc, psx1_state ) |
| 765 | | /* basic machine hardware */ |
| 766 | | MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz ) |
| 767 | | MCFG_CPU_PROGRAM_MAP( psx_map) |
| 768 | | MCFG_CPU_VBLANK_INT("screen", psx_vblank) |
| 769 | | |
| 770 | | MCFG_SCREEN_ADD("screen", RASTER) |
| 771 | | MCFG_SCREEN_REFRESH_RATE( 60 ) |
| 772 | | MCFG_SCREEN_VBLANK_TIME(0) |
| 773 | | |
| 774 | | MCFG_MACHINE_RESET( psx ) |
| 775 | | |
| 776 | | /* video hardware */ |
| 777 | | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 778 | | MCFG_SCREEN_SIZE( 1024, 512 ) |
| 779 | | MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 479 ) |
| 780 | | MCFG_SCREEN_UPDATE( psx ) |
| 781 | | |
| 782 | | MCFG_PALETTE_LENGTH( 65536 ) |
| 783 | | |
| 784 | | MCFG_PALETTE_INIT( psx ) |
| 785 | | MCFG_VIDEO_START( psx_type2 ) |
| 786 | | |
| 787 | | /* sound hardware */ |
| 788 | | MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 789 | | MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq ) |
| 790 | | MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 ) |
| 791 | | MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 ) |
| 792 | | |
| 793 | | /* quickload */ |
| 794 | | MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0) |
| 795 | | |
| 796 | | MCFG_CDROM_ADD("cdrom") |
| 797 | | MCFG_PSXCD_ADD("cdrom") |
| 798 | | MCFG_PSXCARD_ADD("card1") |
| 799 | | MCFG_PSXCARD_ADD("card2") |
| 800 | | MACHINE_CONFIG_END |
| 801 | | |
| 802 | | static MACHINE_CONFIG_START( psxpal, psx1_state ) |
| 803 | | /* basic machine hardware */ |
| 804 | | MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz ) |
| 805 | | MCFG_CPU_PROGRAM_MAP( psx_map) |
| 806 | | MCFG_CPU_VBLANK_INT("screen", psx_vblank) |
| 807 | | |
| 808 | | MCFG_SCREEN_ADD("screen", RASTER) |
| 809 | | MCFG_SCREEN_REFRESH_RATE( 50 ) |
| 810 | | MCFG_SCREEN_VBLANK_TIME(0) |
| 811 | | |
| 812 | | MCFG_MACHINE_RESET( psx ) |
| 813 | | |
| 814 | | /* video hardware */ |
| 815 | | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 816 | | MCFG_SCREEN_SIZE( 1024, 512 ) |
| 817 | | MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 511 ) |
| 818 | | MCFG_SCREEN_UPDATE( psx ) |
| 819 | | MCFG_PALETTE_LENGTH( 65536 ) |
| 820 | | |
| 821 | | MCFG_PALETTE_INIT( psx ) |
| 822 | | MCFG_VIDEO_START( psx_type2 ) |
| 823 | | |
| 824 | | /* sound hardware */ |
| 825 | | MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 826 | | MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq ) |
| 827 | | MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 ) |
| 828 | | MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 ) |
| 829 | | |
| 830 | | /* quickload */ |
| 831 | | MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0) |
| 832 | | |
| 833 | | MCFG_CDROM_ADD("cdrom") |
| 834 | | MCFG_PSXCD_ADD("cdrom") |
| 835 | | MCFG_PSXCARD_ADD("card1") |
| 836 | | MCFG_PSXCARD_ADD("card2") |
| 837 | | MACHINE_CONFIG_END |
| 838 | | |
| 839 | | ROM_START( psj ) |
| 840 | | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 841 | | |
| 842 | | ROM_SYSTEM_BIOS( 0, "1.0J", "SCPH-1000/DTL-H1000" ) // 22091994 |
| 843 | | ROMX_LOAD( "ps-10j.bin", 0x0000000, 0x080000, CRC(3b601fc8) SHA1(343883a7b555646da8cee54aadd2795b6e7dd070), ROM_BIOS(1) ) |
| 844 | | |
| 845 | | ROM_SYSTEM_BIOS( 1, "1.1J", "SCPH-3000/DTL-H1000H (Version 1.1 01/22/95)" ) // 22091994 |
| 846 | | ROMX_LOAD( "ps-11j.bin", 0x0000000, 0x080000, CRC(3539def6) SHA1(b06f4a861f74270be819aa2a07db8d0563a7cc4e), ROM_BIOS(2) ) |
| 847 | | |
| 848 | | ROM_SYSTEM_BIOS( 2, "2.1J", "SCPH-3500 (Version 2.1 07/17/95 J)" ) // 22091994 |
| 849 | | ROMX_LOAD( "ps-21j.bin", 0x0000000, 0x080000, CRC(bc190209) SHA1(e38466a4ba8005fba7e9e3c7b9efeba7205bee3f), ROM_BIOS(3) ) |
| 850 | | |
| 851 | | ROM_SYSTEM_BIOS( 3, "2.2J", "SCPH-5000/DTL-H1200 (Version 2.2 12/04/95 J)" ) // 04121995 |
| 852 | | /* ROMX_LOAD( "ps-22j.bad", 0x0000000, 0x080000, BAD_DUMP CRC(8c93a399) SHA1(e340db2696274dda5fdc25e434a914db71e8b02b), ROM_BIOS(4) ) */ |
| 853 | | ROMX_LOAD( "ps-22j.bin", 0x0000000, 0x080000, CRC(24fc7e17) SHA1(ffa7f9a7fb19d773a0c3985a541c8e5623d2c30d), ROM_BIOS(4) ) |
| 854 | | |
| 855 | | ROM_SYSTEM_BIOS( 4, "2.2D", "DTL-H1100 (Version 2.2 03/06/96 D)" ) // 04121995 |
| 856 | | ROMX_LOAD( "ps-22d.bin", 0x0000000, 0x080000, CRC(decb22f5) SHA1(73107d468fc7cb1d2c5b18b269715dd889ecef06), ROM_BIOS(5) ) |
| 857 | | |
| 858 | | ROM_SYSTEM_BIOS( 5, "3.0J", "SCPH-5500 (Version 3.0 09/09/96 J)" ) // 04121995 |
| 859 | | ROMX_LOAD( "ps-30j.bin", 0x0000000, 0x080000, CRC(ff3eeb8c) SHA1(b05def971d8ec59f346f2d9ac21fb742e3eb6917), ROM_BIOS(6) ) |
| 860 | | |
| 861 | | ROM_SYSTEM_BIOS( 6, "4.0J", "SCPH-7000/SCPH-9000 (Version 4.0 08/18/97 J)" ) // 29051997 |
| 862 | | ROMX_LOAD( "ps-40j.bin", 0x0000000, 0x080000, CRC(ec541cd0) SHA1(77b10118d21ac7ffa9b35f9c4fd814da240eb3e9), ROM_BIOS(7) ) |
| 863 | | |
| 864 | | ROM_SYSTEM_BIOS( 7, "4.3J", "SCPH-100 (Version 4.3 03/11/00 J)" ) // 04121995 |
| 865 | | ROMX_LOAD( "psone-43j.bin", 0x0000000, 0x080000, CRC(f2af798b) SHA1(339a48f4fcf63e10b5b867b8c93cfd40945faf6c), ROM_BIOS(8) ) |
| 866 | | ROM_END |
| 867 | | |
| 868 | | ROM_START( psu ) |
| 869 | | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 870 | | |
| 871 | | ROM_SYSTEM_BIOS( 0, "2.0A", "DTL-H1001 (Version 2.0 05/07/95 A)" ) // 22091994 |
| 872 | | ROMX_LOAD( "ps-20a.bin", 0x0000000, 0x080000, CRC(55847d8c) SHA1(649895efd79d14790eabb362e94eb0622093dfb9), ROM_BIOS(1) ) |
| 873 | | |
| 874 | | ROM_SYSTEM_BIOS( 1, "2.1A", "DTL-H1101 (Version 2.1 07/17/95 A)" ) // 22091994 |
| 875 | | ROMX_LOAD( "ps-21a.bin", 0x0000000, 0x080000, CRC(aff00f2f) SHA1(ca7af30b50d9756cbd764640126c454cff658479), ROM_BIOS(2) ) |
| 876 | | |
| 877 | | ROM_SYSTEM_BIOS( 2, "2.2A", "SCPH-1001/DTL-H1201/DTL-H3001 (Version 2.2 12/04/95 A)" ) // 04121995 |
| 878 | | ROMX_LOAD( "ps-22a.bin", 0x0000000, 0x080000, CRC(37157331) SHA1(10155d8d6e6e832d6ea66db9bc098321fb5e8ebf), ROM_BIOS(3) ) |
| 879 | | |
| 880 | | ROM_SYSTEM_BIOS( 3, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995 |
| 881 | | ROMX_LOAD( "ps-30a.bin", 0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(4) ) |
| 882 | | |
| 883 | | ROM_SYSTEM_BIOS( 4, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995 |
| 884 | | ROMX_LOAD( "ps-41a.bin", 0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(5) ) |
| 885 | | |
| 886 | | ROM_SYSTEM_BIOS( 5, "4.5A", "SCPH-101 (Version 4.5 05/25/00 A)" ) // 04121995 |
| 887 | | ROMX_LOAD( "psone-45a.bin", 0x0000000, 0x080000, CRC(171bdcec) SHA1(dcffe16bd90a723499ad46c641424981338d8378), ROM_BIOS(6) ) |
| 888 | | ROM_END |
| 889 | | |
| 890 | | ROM_START( pse ) |
| 891 | | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 892 | | |
| 893 | | ROM_SYSTEM_BIOS( 0, "2.0E", "DTL-H1002/SCPH-1002 (Version 2.0 05/10/95 E)" ) // 22091994 |
| 894 | | ROMX_LOAD( "ps-20e.bin", 0x0000000, 0x080000, CRC(9bb87c4b) SHA1(20b98f3d80f11cbf5a7bfd0779b0e63760ecc62c), ROM_BIOS(1) ) |
| 895 | | |
| 896 | | ROM_SYSTEM_BIOS( 1, "2.1E", "SCPH-1002/DTL-H1102 (Version 2.1 07/17/95 E)" ) // 22091994 |
| 897 | | ROMX_LOAD( "ps-21e.bin", 0x0000000, 0x080000, CRC(86c30531) SHA1(76cf6b1b2a7c571a6ad07f2bac0db6cd8f71e2cc), ROM_BIOS(2) ) |
| 898 | | |
| 899 | | ROM_SYSTEM_BIOS( 2, "2.2E", "SCPH-1002/DTL-H1202/DTL-H3002 (Version 2.2 12/04/95 E)" ) // 04121995 |
| 900 | | ROMX_LOAD( "ps-22e.bin", 0x0000000, 0x080000, CRC(1e26792f) SHA1(b6a11579caef3875504fcf3831b8e3922746df2c), ROM_BIOS(3) ) |
| 901 | | |
| 902 | | ROM_SYSTEM_BIOS( 3, "3.0E", "SCPH-5502/SCPH-5552 (Version 3.0 01/06/97 E)" ) // 04121995 |
| 903 | | /* ROMX_LOAD( "ps-30e.bad", 0x0000000, 0x080000, BAD_DUMP CRC(4d9e7c86) SHA1(f8de9325fc36fcfa4b29124d291c9251094f2e54), ROM_BIOS(4) ) */ |
| 904 | | ROMX_LOAD( "ps-30e.bin", 0x0000000, 0x080000, CRC(d786f0b9) SHA1(f6bc2d1f5eb6593de7d089c425ac681d6fffd3f0), ROM_BIOS(4) ) |
| 905 | | |
| 906 | | ROM_SYSTEM_BIOS( 4, "4.1E", "SCPH-7002/SCPH-7502/SCPH-9002 (Version 4.1 12/16/97 E)" ) // 04121995 |
| 907 | | ROMX_LOAD( "ps-41e.bin", 0x0000000, 0x080000, CRC(318178bf) SHA1(8d5de56a79954f29e9006929ba3fed9b6a418c1d), ROM_BIOS(5) ) |
| 908 | | |
| 909 | | ROM_SYSTEM_BIOS( 5, "4.4E", "SCPH-102 (Version 4.4 03/24/00 E)" ) // 04121995 |
| 910 | | ROMX_LOAD( "psone-44e.bin", 0x0000000, 0x080000, CRC(0bad7ea9) SHA1(beb0ac693c0dc26daf5665b3314db81480fa5c7c), ROM_BIOS(6) ) |
| 911 | | |
| 912 | | ROM_SYSTEM_BIOS( 6, "4.5E", "SCPH-102 (Version 4.5 05/25/00 E)" ) // 04121995 |
| 913 | | ROMX_LOAD( "psone-45e.bin", 0x0000000, 0x080000, CRC(76b880e5) SHA1(dbc7339e5d85827c095764fc077b41f78fd2ecae), ROM_BIOS(7) ) |
| 914 | | ROM_END |
| 915 | | |
| 916 | | ROM_START( psa ) |
| 917 | | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 918 | | |
| 919 | | ROM_SYSTEM_BIOS( 0, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995 |
| 920 | | ROMX_LOAD( "ps-30a.bin", 0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(1) ) |
| 921 | | |
| 922 | | ROM_SYSTEM_BIOS( 1, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995 |
| 923 | | ROMX_LOAD( "ps-41a.bin", 0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(2) ) |
| 924 | | ROM_END |
| 925 | | |
| 926 | | /* |
| 927 | | The version number & release date is stored in ascii text at the end of every bios, except for scph1000. |
| 928 | | There is also a BCD encoded date at offset 0x100, but this is set to 22091994 for versions prior to 2.2 |
| 929 | | and 04121995 for all versions from 2.2 ( except Version 4.0J which is 29051997 ). |
| 930 | | |
| 931 | | Consoles not dumped: |
| 932 | | |
| 933 | | DTL-H1001H |
| 934 | | DTL-H3000 |
| 935 | | SCPH-5001 |
| 936 | | SCPH-5002 |
| 937 | | SCPH-5003 |
| 938 | | SCPH-5503 |
| 939 | | SCPH-7500 |
| 940 | | SCPH-9003 |
| 941 | | SCPH-103 |
| 942 | | |
| 943 | | Holes in version numbers: |
| 944 | | |
| 945 | | Version 2.0 J |
| 946 | | Version 4.1 J |
| 947 | | Version 4.2 J |
| 948 | | Version 4.4 J |
| 949 | | Version 4.5 J |
| 950 | | Version 4.0 A |
| 951 | | Version 4.2 A |
| 952 | | Version 4.3 A |
| 953 | | Version 4.4 A |
| 954 | | Version 4.0 E |
| 955 | | Version 4.2 E |
| 956 | | Version 4.3 E |
| 957 | | |
| 958 | | */ |
| 959 | | |
| 960 | | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME FLAGS */ |
| 961 | | CONS( 1994, psj, 0, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Japan)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 962 | | CONS( 1995, pse, psj, 0, psxpal, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Europe)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 963 | | CONS( 1995, psu, psj, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (USA)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 964 | | CONS( 1995, psa, psj, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Asia-Pacific)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
src/emu/cpu/psx/psx.c
| r11505 | r11506 | |
| 61 | 61 | * |
| 62 | 62 | */ |
| 63 | 63 | |
| 64 | #define ADDRESS_MAP_MODERN |
| 64 | 65 | #include "emu.h" |
| 65 | 66 | #include "debugger.h" |
| 66 | 67 | #include "psx.h" |
| 67 | 68 | #include "dma.h" |
| 69 | #include "mdec.h" |
| 68 | 70 | #include "includes/psx.h" |
| 69 | 71 | #include "sound/spu.h" |
| 70 | 72 | |
| r11505 | r11506 | |
| 1519 | 1521 | } |
| 1520 | 1522 | |
| 1521 | 1523 | // On-board RAM and peripherals |
| 1522 | | static ADDRESS_MAP_START( psxcpu_internal_map, AS_PROGRAM, 32 ) |
| 1523 | | AM_RANGE(0x00800000, 0x1effffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1524 | static ADDRESS_MAP_START( psxcpu_internal_map, AS_PROGRAM, 32, psxcpu_device ) |
| 1525 | AM_RANGE(0x00800000, 0x1effffff) AM_READWRITE( berr_r, berr_w ) |
| 1524 | 1526 | AM_RANGE(0x1f800000, 0x1f8003ff) AM_NOP /* scratchpad */ |
| 1525 | | AM_RANGE(0x1f800400, 0x1f800fff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1527 | AM_RANGE(0x1f800400, 0x1f800fff) AM_READWRITE( berr_r, berr_w ) |
| 1526 | 1528 | AM_RANGE(0x1f801004, 0x1f80101f) AM_RAM |
| 1527 | | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE(psx_com_delay_r, psx_com_delay_w) |
| 1529 | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w ) |
| 1528 | 1530 | AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM |
| 1529 | | AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w) |
| 1531 | AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE_LEGACY( psx_sio_r, psx_sio_w ) |
| 1530 | 1532 | AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM |
| 1531 | | AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE(psx_irq_r, psx_irq_w) |
| 1532 | | AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE_MODERN("dma", psxdma_device, read, write) |
| 1533 | | AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w) |
| 1534 | | AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w) |
| 1535 | | AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w) |
| 1536 | | AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff) |
| 1533 | AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE_LEGACY( psx_irq_r, psx_irq_w ) |
| 1534 | AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE( "dma", psxdma_device, read, write ) |
| 1535 | AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE_LEGACY( psx_counter_r, psx_counter_w ) |
| 1536 | AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE_LEGACY( psx_gpu_r, psx_gpu_w ) |
| 1537 | AM_RANGE(0x1f801820, 0x1f801827) AM_DEVREADWRITE( "mdec", psxmdec_device, read, write ) |
| 1538 | AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16_LEGACY( spu_r, spu_w, 0xffffffff ) |
| 1537 | 1539 | AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */ |
| 1538 | 1540 | AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP |
| 1539 | | AM_RANGE(0x20000000, 0x7fffffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1540 | | AM_RANGE(0x80800000, 0x9effffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1541 | | AM_RANGE(0xa0800000, 0xbeffffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1542 | | AM_RANGE(0xc0000000, 0xfffdffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1543 | | AM_RANGE(0xfffe0130, 0xfffe0133) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, biu_r, biu_w) |
| 1541 | AM_RANGE(0x20000000, 0x7fffffff) AM_READWRITE( berr_r, berr_w ) |
| 1542 | AM_RANGE(0x80800000, 0x9effffff) AM_READWRITE( berr_r, berr_w ) |
| 1543 | AM_RANGE(0xa0800000, 0xbeffffff) AM_READWRITE( berr_r, berr_w ) |
| 1544 | AM_RANGE(0xc0000000, 0xfffdffff) AM_READWRITE( berr_r, berr_w ) |
| 1545 | AM_RANGE(0xfffe0130, 0xfffe0133) AM_READWRITE( biu_r, biu_w ) |
| 1544 | 1546 | ADDRESS_MAP_END |
| 1545 | 1547 | |
| 1546 | | static ADDRESS_MAP_START( cxd8661r_internal_map, AS_PROGRAM, 32 ) |
| 1547 | | AM_RANGE(0x01000000, 0x1effffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1548 | static ADDRESS_MAP_START( cxd8661r_internal_map, AS_PROGRAM, 32, psxcpu_device ) |
| 1549 | AM_RANGE(0x01000000, 0x1effffff) AM_READWRITE( berr_r, berr_w ) |
| 1548 | 1550 | AM_RANGE(0x1f800000, 0x1f8003ff) AM_NOP /* scratchpad */ |
| 1549 | | AM_RANGE(0x1f800400, 0x1f800fff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1551 | AM_RANGE(0x1f800400, 0x1f800fff) AM_READWRITE( berr_r, berr_w ) |
| 1550 | 1552 | AM_RANGE(0x1f801004, 0x1f80101f) AM_RAM |
| 1551 | | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE(psx_com_delay_r, psx_com_delay_w) |
| 1553 | AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE_LEGACY( psx_com_delay_r, psx_com_delay_w ) |
| 1552 | 1554 | AM_RANGE(0x1f801024, 0x1f80102f) AM_RAM |
| 1553 | | AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w) |
| 1555 | AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE_LEGACY( psx_sio_r, psx_sio_w ) |
| 1554 | 1556 | AM_RANGE(0x1f801060, 0x1f80106f) AM_RAM |
| 1555 | | AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE(psx_irq_r, psx_irq_w) |
| 1556 | | AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE_MODERN("dma", psxdma_device, read, write) |
| 1557 | | AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w) |
| 1558 | | AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w) |
| 1559 | | AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w) |
| 1560 | | AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff) |
| 1557 | AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE_LEGACY( psx_irq_r, psx_irq_w ) |
| 1558 | AM_RANGE(0x1f801080, 0x1f8010ff) AM_DEVREADWRITE( "dma", psxdma_device, read, write ) |
| 1559 | AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE_LEGACY( psx_counter_r, psx_counter_w ) |
| 1560 | AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE_LEGACY( psx_gpu_r, psx_gpu_w ) |
| 1561 | AM_RANGE(0x1f801820, 0x1f801827) AM_DEVREADWRITE( "mdec", psxmdec_device, read, write ) |
| 1562 | AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16_LEGACY( spu_r, spu_w, 0xffffffff ) |
| 1563 | AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */ |
| 1561 | 1564 | AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP |
| 1562 | | AM_RANGE(0x20000000, 0x7fffffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1563 | | AM_RANGE(0x81000000, 0x9effffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1564 | | AM_RANGE(0xa1000000, 0xbeffffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1565 | | AM_RANGE(0xc0000000, 0xfffdffff) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, berr_r, berr_w) |
| 1566 | | AM_RANGE(0xfffe0130, 0xfffe0133) AM_DEVREADWRITE_MODERN(DEVICE_SELF, psxcpu_device, biu_r, biu_w) |
| 1565 | AM_RANGE(0x20000000, 0x7fffffff) AM_READWRITE( berr_r, berr_w ) |
| 1566 | AM_RANGE(0x81000000, 0x9effffff) AM_READWRITE( berr_r, berr_w ) |
| 1567 | AM_RANGE(0xa1000000, 0xbeffffff) AM_READWRITE( berr_r, berr_w ) |
| 1568 | AM_RANGE(0xc0000000, 0xfffdffff) AM_READWRITE( berr_r, berr_w ) |
| 1569 | AM_RANGE(0xfffe0130, 0xfffe0133) AM_READWRITE( biu_r, biu_w ) |
| 1567 | 1570 | ADDRESS_MAP_END |
| 1568 | 1571 | |
| 1569 | 1572 | |
| r11505 | r11506 | |
| 3144 | 3147 | { |
| 3145 | 3148 | } |
| 3146 | 3149 | |
| 3147 | | void psxcpu_device::install_dma_read_handler( device_t &device, int channel, psx_dma_read_handler handler ) |
| 3150 | static psxcpu_device *getcpu( device_t &device, const char *cputag ) |
| 3148 | 3151 | { |
| 3149 | | (downcast<psxdma_device*>(device.subdevice("dma")))->install_read_handler( channel, handler ); |
| 3152 | if( strcmp( cputag, DEVICE_SELF ) == 0 ) |
| 3153 | { |
| 3154 | return downcast<psxcpu_device *>( &device ); |
| 3155 | } |
| 3156 | |
| 3157 | return downcast<psxcpu_device *>( device.siblingdevice( cputag ) ); |
| 3150 | 3158 | } |
| 3151 | 3159 | |
| 3152 | | void psxcpu_device::install_dma_write_handler( device_t &device, int channel, psx_dma_write_handler handler ) |
| 3160 | void psxcpu_device::install_dma_read_handler( device_t &device, const char *cputag, int channel, psx_dma_read_delegate handler ) |
| 3153 | 3161 | { |
| 3154 | | (downcast<psxdma_device*>(device.subdevice("dma")))->install_write_handler( channel, handler ); |
| 3162 | psxdma_device *dma = downcast<psxdma_device *>( getcpu( device, cputag )->subdevice("dma") ); |
| 3163 | dma->install_read_handler( channel, handler ); |
| 3155 | 3164 | } |
| 3156 | 3165 | |
| 3166 | void psxcpu_device::install_dma_write_handler( device_t &device, const char *cputag, int channel, psx_dma_write_delegate handler ) |
| 3167 | { |
| 3168 | psxdma_device *dma = downcast<psxdma_device *>( getcpu( device, cputag )->subdevice("dma") ); |
| 3169 | dma->install_write_handler( channel, handler ); |
| 3170 | } |
| 3171 | |
| 3157 | 3172 | static MACHINE_CONFIG_FRAGMENT( psx ) |
| 3158 | 3173 | MCFG_DEVICE_ADD("dma", PSX_DMA, 0) |
| 3174 | |
| 3175 | MCFG_DEVICE_ADD("mdec", PSX_MDEC, 0) |
| 3176 | MCFG_PSX_DMA_CHANNEL_WRITE( DEVICE_SELF, 0, psx_dma_write_delegate( FUNC( psxmdec_device::dma_write ), (psxmdec_device *) device ) ) |
| 3177 | MCFG_PSX_DMA_CHANNEL_READ( DEVICE_SELF, 1, psx_dma_read_delegate( FUNC( psxmdec_device::dma_read ), (psxmdec_device *) device ) ) |
| 3159 | 3178 | MACHINE_CONFIG_END |
| 3160 | 3179 | |
| 3161 | 3180 | //------------------------------------------------- |
src/mess/machine/psxcd.c
| r0 | r11506 | |
| 1 | #include "emu.h" |
| 2 | #include "includes/psx.h" |
| 3 | #include "psxcd.h" |
| 4 | #include "machine/devhelpr.h" |
| 5 | #include "sound/spu.h" |
| 6 | #include "debugger.h" |
| 7 | |
| 8 | // |
| 9 | // |
| 10 | // |
| 11 | |
| 12 | //#define debug_cdrom |
| 13 | //#define debug_cdrom_registers |
| 14 | //#define skip_reads |
| 15 | //#define dump_subheader |
| 16 | //#define disable_xa_prefetch |
| 17 | //#define disable_cdda_prefetch |
| 18 | |
| 19 | // |
| 20 | // |
| 21 | // |
| 22 | |
| 23 | enum cdrom_events |
| 24 | { |
| 25 | event_cmd_complete=0, |
| 26 | event_preread_sector, |
| 27 | event_read_sector, |
| 28 | event_play_sector |
| 29 | }; |
| 30 | |
| 31 | // |
| 32 | // |
| 33 | // |
| 34 | |
| 35 | enum intr_status |
| 36 | { |
| 37 | intr_nointr=0, |
| 38 | intr_dataready, |
| 39 | intr_acknowledge, |
| 40 | intr_complete, |
| 41 | intr_dataend, |
| 42 | intr_diskerror |
| 43 | }; |
| 44 | |
| 45 | enum mode_flags |
| 46 | { |
| 47 | mode_double_speed=0x80, |
| 48 | mode_adpcm=0x40, |
| 49 | mode_size=0x20, |
| 50 | mode_size2=0x10, |
| 51 | mode_size_shift=4, |
| 52 | mode_size_mask=(3<<mode_size_shift), |
| 53 | mode_channel=0x08, |
| 54 | mode_report=0x04, |
| 55 | mode_autopause=0x02, |
| 56 | mode_cdda=0x01 |
| 57 | }; |
| 58 | |
| 59 | enum status_f |
| 60 | { |
| 61 | status_playing=0x80, |
| 62 | status_seeking=0x40, |
| 63 | status_reading=0x20, |
| 64 | status_shellopen=0x10, |
| 65 | status_seekerror=0x04, |
| 66 | status_standby=0x02, |
| 67 | status_error=0x01 |
| 68 | }; |
| 69 | |
| 70 | struct subheader |
| 71 | { |
| 72 | unsigned char file, |
| 73 | channel, |
| 74 | submode, |
| 75 | coding; |
| 76 | }; |
| 77 | |
| 78 | enum submode_flags |
| 79 | { |
| 80 | submode_eof=0x80, |
| 81 | submode_realtime=0x40, |
| 82 | submode_form=0x20, |
| 83 | submode_trigger=0x10, |
| 84 | submode_data=0x08, |
| 85 | submode_audio=0x04, |
| 86 | submode_video=0x02, |
| 87 | submode_eor=0x01 |
| 88 | }; |
| 89 | |
| 90 | // |
| 91 | // |
| 92 | // |
| 93 | |
| 94 | static const unsigned int max_xa_prefetch_distance=32, |
| 95 | max_cdda_prefetch_distance=32; |
| 96 | |
| 97 | //************************************************************************** |
| 98 | // DEVICE DEFINITIONS |
| 99 | //************************************************************************** |
| 100 | |
| 101 | const device_type PSXCD = &device_creator<psxcd_device>; |
| 102 | |
| 103 | void psxcd_device::static_set_devname(device_t &device, const char *devname) |
| 104 | { |
| 105 | psxcd_device &psxcd = downcast<psxcd_device &>(device); |
| 106 | psxcd.m_devname = devname; |
| 107 | } |
| 108 | |
| 109 | psxcd_device::psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 110 | : device_t(mconfig, PSXCD, "PSXCD", tag, owner, clock) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | void psxcd_device::device_start() |
| 115 | { |
| 116 | unsigned int sysclk=machine().device<cpu_device>("maincpu")->clock()/2; |
| 117 | start_read_delay=(sysclk/60); |
| 118 | read_sector_cycles=(sysclk/75); |
| 119 | preread_delay=(read_sector_cycles>>2)-500; |
| 120 | |
| 121 | m_sysclock = sysclk; |
| 122 | |
| 123 | secleft = 0; |
| 124 | secsize = 2048; |
| 125 | res_queue = NULL; |
| 126 | cur_res = NULL; |
| 127 | open = false; |
| 128 | streaming = false; |
| 129 | sechead = 0; |
| 130 | sectail = 0; |
| 131 | secin = 0; |
| 132 | secskip = 0; |
| 133 | next_read_event = NULL; |
| 134 | cbp = cmdbuf; |
| 135 | first_open = true; |
| 136 | |
| 137 | status=status_standby; |
| 138 | sr=8|1; |
| 139 | res=0; |
| 140 | ir=0; |
| 141 | mode=0; |
| 142 | |
| 143 | driver = NULL; |
| 144 | |
| 145 | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 146 | { |
| 147 | m_timers[i] = timer_alloc(i, NULL); |
| 148 | m_timerinuse[i] = false; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // |
| 153 | // |
| 154 | // |
| 155 | |
| 156 | void psxcd_device::device_reset() |
| 157 | { |
| 158 | stop_read(); |
| 159 | open=false; |
| 160 | |
| 161 | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 162 | { |
| 163 | m_timerinuse[i] = false; |
| 164 | } |
| 165 | |
| 166 | m_cddevice = machine().device(m_devname); |
| 167 | if (m_cddevice) |
| 168 | { |
| 169 | m_cd = cd_get_cdrom_file(m_cddevice); |
| 170 | |
| 171 | if (m_cd) |
| 172 | { |
| 173 | // printf("psxcd: found disc!\n"); |
| 174 | driver = open_mess_drv(); |
| 175 | driver->set_machine(machine()); |
| 176 | driver->set_cdrom_file(m_cd); |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | driver = NULL; |
| 181 | // printf("psxcd: Found device, but no disc\n"); |
| 182 | } |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | driver = NULL; |
| 187 | // printf("psxcd: Device [%s] not found!\n", m_devname); |
| 188 | } |
| 189 | |
| 190 | } |
| 191 | |
| 192 | // |
| 193 | // |
| 194 | // |
| 195 | |
| 196 | unsigned char psxcd_device::read_byte(const unsigned int addr) |
| 197 | { |
| 198 | unsigned char ret = 0; |
| 199 | |
| 200 | switch (addr&3) |
| 201 | { |
| 202 | case 0: ret=sr; break; |
| 203 | case 1: |
| 204 | ret=res; |
| 205 | if ((cur_res) && (rdp<cur_res->sz)) |
| 206 | { |
| 207 | res=cur_res->data[rdp++]; |
| 208 | sr|=(1<<5); |
| 209 | } else |
| 210 | { |
| 211 | if ((cur_res) && (cur_res->res&0x10)) |
| 212 | { |
| 213 | global_free(cur_res); |
| 214 | cur_res=NULL; |
| 215 | } |
| 216 | |
| 217 | sr&=~(1<<5); |
| 218 | } |
| 219 | break; |
| 220 | case 2: ret=0; break; |
| 221 | case 3: ret=ir; break; |
| 222 | } |
| 223 | |
| 224 | #ifdef debug_cdrom_registers |
| 225 | printf("cdrom: read byte %08x = %02x (PC=%x)\n",addr,ret,cpu_get_pc(machine().device("maincpu"))); |
| 226 | #endif |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | // |
| 232 | // |
| 233 | // |
| 234 | |
| 235 | void psxcd_device::write_byte(const unsigned int addr, const unsigned char byte) |
| 236 | { |
| 237 | #ifdef debug_cdrom_registers |
| 238 | printf("cdrom: write byte %08x = %02x (PC=%x)\n",addr,byte,cpu_get_pc(machine().device("maincpu"))); |
| 239 | #endif |
| 240 | |
| 241 | switch (addr&3) |
| 242 | { |
| 243 | case 0: |
| 244 | cmdmode=byte&1; |
| 245 | if (cmdmode==0) |
| 246 | { |
| 247 | cbp=cmdbuf; |
| 248 | } else |
| 249 | { |
| 250 | if (! cur_res) |
| 251 | { |
| 252 | if (cur_res) global_free(cur_res); |
| 253 | |
| 254 | if (res_queue) |
| 255 | { |
| 256 | #ifdef debug_cdrom_registers |
| 257 | printf("cdrom: nextres\n"); |
| 258 | #endif |
| 259 | |
| 260 | cur_res=res_queue; |
| 261 | res_queue=res_queue->next; |
| 262 | ir=cur_res->res&0xf; |
| 263 | rdp=0; |
| 264 | |
| 265 | if (cur_res->sz) |
| 266 | { |
| 267 | res=cur_res->data[rdp++]; |
| 268 | sr|=(1<<5); |
| 269 | } else |
| 270 | { |
| 271 | sr&=~(1<<5); |
| 272 | } |
| 273 | } else |
| 274 | { |
| 275 | //ir=0; |
| 276 | cur_res=NULL; |
| 277 | } |
| 278 | } |
| 279 | /*else |
| 280 | { |
| 281 | if (rdp>=cur_res->sz) |
| 282 | { |
| 283 | sr&=~(1<<5); |
| 284 | } else |
| 285 | { |
| 286 | sr|=~(1<<5); |
| 287 | res=cur_res->data[rdp++]; |
| 288 | } |
| 289 | } |
| 290 | */ |
| 291 | } |
| 292 | break; |
| 293 | |
| 294 | case 1: |
| 295 | if (cmdmode==0) |
| 296 | { |
| 297 | write_command(byte); |
| 298 | } |
| 299 | break; |
| 300 | |
| 301 | case 2: |
| 302 | if (cmdmode==0) |
| 303 | { |
| 304 | *cbp++=byte; |
| 305 | } else |
| 306 | { |
| 307 | // ?flush buffer? |
| 308 | } |
| 309 | break; |
| 310 | |
| 311 | case 3: |
| 312 | if (byte==0x07) |
| 313 | { |
| 314 | if (cur_res) |
| 315 | { |
| 316 | global_free(cur_res); |
| 317 | cur_res=NULL; |
| 318 | sr&=~(1<<5); |
| 319 | } |
| 320 | ir=0; |
| 321 | } |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | psxcd_device::command_info psxcd_device::cmd_table[num_commands]= |
| 327 | { |
| 328 | { &psxcd_device::cdcmd_sync, "sync" }, // 00 |
| 329 | { &psxcd_device::cdcmd_nop, "nop" }, // 01 |
| 330 | { &psxcd_device::cdcmd_setloc, "setloc" }, // 02 |
| 331 | { &psxcd_device::cdcmd_play, "play" }, // 03 |
| 332 | { &psxcd_device::cdcmd_forward, "forward" }, // 04 |
| 333 | { &psxcd_device::cdcmd_backward, "backward" }, // 05 |
| 334 | { &psxcd_device::cdcmd_readn, "readn" }, // 06 |
| 335 | { &psxcd_device::cdcmd_standby, "standby" }, // 07 |
| 336 | { &psxcd_device::cdcmd_stop, "stop" }, // 08 |
| 337 | { &psxcd_device::cdcmd_pause, "pause" }, // 09 |
| 338 | { &psxcd_device::cdcmd_init, "init" }, // 0a |
| 339 | { &psxcd_device::cdcmd_mute, "mute" }, // 0b |
| 340 | { &psxcd_device::cdcmd_demute, "demute" }, // 0c |
| 341 | { &psxcd_device::cdcmd_setfilter, "setfilter" }, // 0d |
| 342 | { &psxcd_device::cdcmd_setmode, "setmode" }, // 0e |
| 343 | { &psxcd_device::cdcmd_getparam, "getparam" }, // 0f |
| 344 | { &psxcd_device::cdcmd_getlocl, "getlocl" }, // 10 |
| 345 | { &psxcd_device::cdcmd_getlocp, "getlocp" }, // 11 |
| 346 | { &psxcd_device::cdcmd_illegal, "illegal" }, // 12 |
| 347 | { &psxcd_device::cdcmd_gettn, "gettn" }, // 13 |
| 348 | { &psxcd_device::cdcmd_gettd, "gettd" }, // 14 |
| 349 | { &psxcd_device::cdcmd_seekl, "seekl" }, // 15 |
| 350 | { &psxcd_device::cdcmd_seekp, "seekp" }, // 16 |
| 351 | { &psxcd_device::cdcmd_illegal, "illegal" }, // 17 |
| 352 | { &psxcd_device::cdcmd_illegal, "illegal" }, // 18 |
| 353 | { &psxcd_device::cdcmd_test, "test" }, // 19 |
| 354 | { &psxcd_device::cdcmd_id, "id" }, // 1a |
| 355 | { &psxcd_device::cdcmd_reads, "reads" }, // 1b |
| 356 | { &psxcd_device::cdcmd_reset, "reset" }, // 1c |
| 357 | { &psxcd_device::cdcmd_illegal, "illegal" }, // 1d |
| 358 | { &psxcd_device::cdcmd_readtoc, "readtoc" }, // 1e |
| 359 | }; |
| 360 | |
| 361 | // |
| 362 | // |
| 363 | // |
| 364 | |
| 365 | void psxcd_device::write_command(const unsigned char byte) |
| 366 | { |
| 367 | assert(byte<num_commands); |
| 368 | (this->*cmd_table[byte].func)(); |
| 369 | } |
| 370 | |
| 371 | // |
| 372 | // |
| 373 | // |
| 374 | |
| 375 | void psxcd_device::cdcmd_sync() |
| 376 | { |
| 377 | #ifdef debug_cdrom |
| 378 | printf("cdrom: sync\n"); |
| 379 | #endif |
| 380 | |
| 381 | stop_read(); |
| 382 | send_result(intr_acknowledge); |
| 383 | } |
| 384 | |
| 385 | static int open_nops=0; |
| 386 | |
| 387 | void psxcd_device::cdcmd_nop() |
| 388 | { |
| 389 | #ifdef debug_cdrom |
| 390 | printf("cdrom: nop\n"); |
| 391 | #endif |
| 392 | |
| 393 | //stop_read(); |
| 394 | |
| 395 | if ((! open) && (driver)) |
| 396 | { |
| 397 | if (open_nops==0) |
| 398 | { |
| 399 | open=driver->read_toc(); |
| 400 | } else |
| 401 | { |
| 402 | open_nops--; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | send_result(intr_complete); |
| 407 | } |
| 408 | |
| 409 | void psxcd_device::cdcmd_setloc() |
| 410 | { |
| 411 | #ifdef debug_cdrom |
| 412 | printf("cdrom: setloc %08x:%08x:%08x\n", |
| 413 | cmdbuf[0], |
| 414 | cmdbuf[1], |
| 415 | cmdbuf[2]); |
| 416 | #endif |
| 417 | |
| 418 | stop_read(); |
| 419 | |
| 420 | unsigned char l[3]; |
| 421 | l[0]=bcd_to_decimal(cmdbuf[0]); |
| 422 | l[1]=bcd_to_decimal(cmdbuf[1]); |
| 423 | l[2]=bcd_to_decimal(cmdbuf[2]); |
| 424 | |
| 425 | if ((l[0]>0) || (l[1]>=2)) |
| 426 | { |
| 427 | loc[0]=l[0]; |
| 428 | loc[1]=l[1]; |
| 429 | loc[2]=l[2]; |
| 430 | } else |
| 431 | { |
| 432 | printf("setloc out of range: %02d:%02d:%02d\n", |
| 433 | l[0],l[1],l[2]); |
| 434 | } |
| 435 | |
| 436 | send_result(intr_complete); |
| 437 | } |
| 438 | |
| 439 | void psxcd_device::cdcmd_play() |
| 440 | { |
| 441 | #ifdef debug_cdrom |
| 442 | printf("cdrom: play %02x %02x %02x => %d\n", loc[0], loc[1], loc[2], msf_to_sector(loc)); |
| 443 | #endif |
| 444 | |
| 445 | curpos[0]=loc[0]; |
| 446 | curpos[1]=loc[1]; |
| 447 | curpos[2]=loc[2]; |
| 448 | |
| 449 | if ((curpos[0]==0) && |
| 450 | (curpos[1]==0) && |
| 451 | (curpos[2]==0)) |
| 452 | { |
| 453 | send_result(intr_acknowledge); |
| 454 | } else |
| 455 | { |
| 456 | stop_read(); |
| 457 | start_play(); |
| 458 | send_result(intr_acknowledge); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void psxcd_device::cdcmd_forward() |
| 463 | { |
| 464 | #ifdef debug_cdrom |
| 465 | printf("cdrom: forward\n"); |
| 466 | #endif |
| 467 | } |
| 468 | |
| 469 | void psxcd_device::cdcmd_backward() |
| 470 | { |
| 471 | #ifdef debug_cdrom |
| 472 | printf("cdrom: backward\n"); |
| 473 | #endif |
| 474 | } |
| 475 | |
| 476 | void psxcd_device::cdcmd_readn() |
| 477 | { |
| 478 | if (driver) |
| 479 | { |
| 480 | #ifdef debug_cdrom |
| 481 | printf("cdrom: readn\n"); |
| 482 | #endif |
| 483 | |
| 484 | curpos[0]=loc[0]; |
| 485 | curpos[1]=loc[1]; |
| 486 | curpos[2]=loc[2]; |
| 487 | |
| 488 | stop_read(); |
| 489 | start_read(); |
| 490 | send_result(intr_complete); |
| 491 | } else |
| 492 | { |
| 493 | printf("read without driver\n"); |
| 494 | send_result(intr_diskerror); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | void psxcd_device::cdcmd_standby() |
| 499 | { |
| 500 | #ifdef debug_cdrom |
| 501 | printf("cdrom: standby\n"); |
| 502 | #endif |
| 503 | |
| 504 | stop_read(); |
| 505 | send_result(intr_acknowledge); |
| 506 | } |
| 507 | |
| 508 | void psxcd_device::cdcmd_stop() |
| 509 | { |
| 510 | #ifdef debug_cdrom |
| 511 | printf("cdrom: stop\n"); |
| 512 | #endif |
| 513 | |
| 514 | stop_read(); |
| 515 | send_result(intr_acknowledge); |
| 516 | } |
| 517 | |
| 518 | void psxcd_device::cdcmd_pause() |
| 519 | { |
| 520 | #ifdef debug_cdrom |
| 521 | printf("cdrom: pause\n"); |
| 522 | #endif |
| 523 | |
| 524 | stop_read(); |
| 525 | |
| 526 | send_result(intr_acknowledge); |
| 527 | } |
| 528 | |
| 529 | void psxcd_device::cdcmd_init() |
| 530 | { |
| 531 | #ifdef debug_cdrom |
| 532 | printf("cdrom: init\n"); |
| 533 | #endif |
| 534 | |
| 535 | stop_read(); |
| 536 | mode=0; |
| 537 | sr|=0x10; |
| 538 | |
| 539 | send_result(intr_acknowledge); |
| 540 | } |
| 541 | |
| 542 | void psxcd_device::cdcmd_mute() |
| 543 | { |
| 544 | #ifdef debug_cdrom |
| 545 | printf("cdrom: mute\n"); |
| 546 | #endif |
| 547 | |
| 548 | send_result(intr_acknowledge); |
| 549 | } |
| 550 | |
| 551 | void psxcd_device::cdcmd_demute() |
| 552 | { |
| 553 | #ifdef debug_cdrom |
| 554 | printf("cdrom: demute\n"); |
| 555 | #endif |
| 556 | |
| 557 | send_result(intr_acknowledge); |
| 558 | } |
| 559 | |
| 560 | void psxcd_device::cdcmd_setfilter() |
| 561 | { |
| 562 | #ifdef debug_cdrom |
| 563 | printf("cdrom: setfilter %08x,%08x\n",cmdbuf[0],cmdbuf[1]); |
| 564 | #endif |
| 565 | |
| 566 | filter_file=cmdbuf[0]; |
| 567 | filter_channel=cmdbuf[1]; |
| 568 | |
| 569 | send_result(intr_acknowledge); |
| 570 | } |
| 571 | |
| 572 | void psxcd_device::cdcmd_setmode() |
| 573 | { |
| 574 | #ifdef debug_cdrom |
| 575 | printf("cdrom: setmode %08x\n",cmdbuf[0]); |
| 576 | #endif |
| 577 | |
| 578 | mode=cmdbuf[0]; |
| 579 | |
| 580 | switch ((mode&mode_size_mask)>>mode_size_shift) |
| 581 | { |
| 582 | case 1: |
| 583 | secsize=2328; |
| 584 | secskip=24; |
| 585 | break; |
| 586 | |
| 587 | case 2: |
| 588 | secsize=2340; |
| 589 | secskip=12; |
| 590 | break; |
| 591 | |
| 592 | default: |
| 593 | secsize=2048; |
| 594 | secskip=24; |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | send_result(intr_complete); |
| 599 | } |
| 600 | |
| 601 | void psxcd_device::cdcmd_getparam() |
| 602 | { |
| 603 | unsigned char data[6]= |
| 604 | { |
| 605 | status, |
| 606 | mode, |
| 607 | filter_file, |
| 608 | filter_channel, |
| 609 | 0, |
| 610 | 0 |
| 611 | }; |
| 612 | |
| 613 | #ifdef debug_cdrom |
| 614 | printf("cdrom: getparam [%02x %02x %02x %02x %02x %02x]\n", |
| 615 | data[0], |
| 616 | data[1], |
| 617 | data[2], |
| 618 | data[3], |
| 619 | data[4], |
| 620 | data[5]); |
| 621 | #endif |
| 622 | |
| 623 | send_result(intr_complete,data,6); |
| 624 | } |
| 625 | |
| 626 | #if 0 |
| 627 | static void add_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2) |
| 628 | { |
| 629 | int f=src1[2]+src2[2], |
| 630 | s=src1[1]+src2[1], |
| 631 | m=src1[0]+src2[0]; |
| 632 | while (f>=75) { s++; f-=75; } |
| 633 | while (s>=60) { m++; s-=60; } |
| 634 | |
| 635 | dst[0]=m; |
| 636 | dst[1]=s; |
| 637 | dst[2]=f; |
| 638 | } |
| 639 | #endif |
| 640 | static void sub_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2) |
| 641 | { |
| 642 | int f=src1[2]-src2[2], |
| 643 | s=src1[1]-src2[1], |
| 644 | m=src1[0]-src2[0]; |
| 645 | while (f<0) { s--; f+=75; } |
| 646 | while (s<0) { m--; s+=60; } |
| 647 | |
| 648 | if (m<0) |
| 649 | m=s=f=0; |
| 650 | |
| 651 | dst[0]=m; |
| 652 | dst[1]=s; |
| 653 | dst[2]=f; |
| 654 | } |
| 655 | |
| 656 | void psxcd_device::cdcmd_getlocl() |
| 657 | { |
| 658 | #ifdef debug_cdrom |
| 659 | printf("cdrom: getlocl\n"); |
| 660 | #endif |
| 661 | |
| 662 | #ifdef debug_cdrom |
| 663 | printf("cdrom: getlocl [%02x %02x %02x %02x %02x %02x %02x %02x]\n", |
| 664 | lastsechdr[0], |
| 665 | lastsechdr[1], |
| 666 | lastsechdr[2], |
| 667 | lastsechdr[3], |
| 668 | lastsechdr[4], |
| 669 | lastsechdr[5], |
| 670 | lastsechdr[6], |
| 671 | lastsechdr[7]); |
| 672 | #endif |
| 673 | |
| 674 | send_result(intr_complete,lastsechdr,8); |
| 675 | } |
| 676 | |
| 677 | void psxcd_device::cdcmd_getlocp() |
| 678 | { |
| 679 | unsigned char tloc[3], |
| 680 | twosec[3]={ 0,2,0 }; |
| 681 | sub_loc(tloc,loc,twosec); |
| 682 | |
| 683 | unsigned char data[8]= |
| 684 | { |
| 685 | 0x01, // track |
| 686 | 0x01, // index |
| 687 | decimal_to_bcd(tloc[0]), // min |
| 688 | decimal_to_bcd(tloc[1]), // sec |
| 689 | decimal_to_bcd(tloc[2]), // frame |
| 690 | decimal_to_bcd(loc[0]), // amin |
| 691 | decimal_to_bcd(loc[1]), // asec |
| 692 | decimal_to_bcd(loc[2]) // aframe |
| 693 | }; |
| 694 | |
| 695 | //unsigned char data[8]={ 2,1,0,0xff,0xff,0xff,0xff,0xff }; |
| 696 | |
| 697 | #ifdef debug_cdrom |
| 698 | printf("cdrom: getlocp [%02x %02x %02x %02x %02x %02x %02x %02x]\n", |
| 699 | data[0], |
| 700 | data[1], |
| 701 | data[2], |
| 702 | data[3], |
| 703 | data[4], |
| 704 | data[5], |
| 705 | data[6], |
| 706 | data[7]); |
| 707 | #endif |
| 708 | |
| 709 | send_result(intr_complete,data,8); |
| 710 | } |
| 711 | |
| 712 | void psxcd_device::cdcmd_illegal() |
| 713 | { |
| 714 | assert(0); |
| 715 | } |
| 716 | |
| 717 | void psxcd_device::cdcmd_gettn() |
| 718 | { |
| 719 | #ifdef debug_cdrom |
| 720 | printf("cdrom: gettn\n"); |
| 721 | #endif |
| 722 | |
| 723 | assert(driver); |
| 724 | |
| 725 | unsigned char data[3]= |
| 726 | { |
| 727 | status, |
| 728 | decimal_to_bcd(driver->get_first_track()), |
| 729 | decimal_to_bcd(driver->get_num_tracks()) |
| 730 | }; |
| 731 | |
| 732 | //stop_read(); |
| 733 | send_result(intr_acknowledge,data,3); |
| 734 | } |
| 735 | |
| 736 | void psxcd_device::cdcmd_gettd() |
| 737 | { |
| 738 | unsigned char addr[3]; |
| 739 | driver->get_track_address(bcd_to_decimal(cmdbuf[0]), addr); |
| 740 | |
| 741 | unsigned char data[3]= |
| 742 | { |
| 743 | status, |
| 744 | decimal_to_bcd(addr[0]), |
| 745 | decimal_to_bcd(addr[1]) |
| 746 | }; |
| 747 | |
| 748 | #ifdef debug_cdrom |
| 749 | printf("cdrom: gettd %02x [%02x %02x %02x]\n", |
| 750 | cmdbuf[0], |
| 751 | data[0], |
| 752 | data[1], |
| 753 | data[2]); |
| 754 | #endif |
| 755 | |
| 756 | //stop_read(); |
| 757 | send_result(intr_acknowledge,data,3); |
| 758 | } |
| 759 | |
| 760 | void psxcd_device::cdcmd_seekl() |
| 761 | { |
| 762 | #ifdef debug_cdrom |
| 763 | printf("cdrom: seekl [%02d:%02d:%02d]\n",loc[0],loc[1],loc[2]); |
| 764 | #endif |
| 765 | |
| 766 | curpos[0]=loc[0]; |
| 767 | curpos[1]=loc[1]; |
| 768 | curpos[2]=loc[2]; |
| 769 | |
| 770 | send_result(intr_acknowledge); |
| 771 | } |
| 772 | |
| 773 | void psxcd_device::cdcmd_seekp() |
| 774 | { |
| 775 | #ifdef debug_cdrom |
| 776 | printf("cdrom: seekp\n"); |
| 777 | #endif |
| 778 | |
| 779 | curpos[0]=loc[0]; |
| 780 | curpos[1]=loc[1]; |
| 781 | curpos[2]=loc[2]; |
| 782 | |
| 783 | send_result(intr_acknowledge); |
| 784 | } |
| 785 | |
| 786 | void psxcd_device::cdcmd_test() |
| 787 | { |
| 788 | #ifdef debug_cdrom |
| 789 | printf("cdrom: test %08x\n",cmdbuf[0]); |
| 790 | #endif |
| 791 | |
| 792 | static unsigned char data[4]= |
| 793 | { |
| 794 | 0x95, |
| 795 | 0x07, |
| 796 | 0x06, |
| 797 | 0xff |
| 798 | }; |
| 799 | |
| 800 | send_result(intr_complete,data,4); |
| 801 | } |
| 802 | |
| 803 | void psxcd_device::cdcmd_id() |
| 804 | { |
| 805 | #ifdef debug_cdrom |
| 806 | printf("cdrom: id\n"); |
| 807 | #endif |
| 808 | |
| 809 | if (! open) |
| 810 | { |
| 811 | if (driver) |
| 812 | open=driver->read_toc(); |
| 813 | } |
| 814 | |
| 815 | if (open) |
| 816 | { |
| 817 | static unsigned char gamedata[8] = { 0x08, 0x00, 0x00, 0x00, 'S', 'C', 'E', 'A' }; |
| 818 | static unsigned char audiodata[8] = { 0x08, 0x90, 0x00, 0x00, 'S', 'C', 'E', 'A' }; // drops into the audio CD player. 08 80 goes to the menu. |
| 819 | |
| 820 | if (cdrom_get_track_type(m_cd, 0) == CD_TRACK_AUDIO) |
| 821 | { |
| 822 | send_result(intr_acknowledge,audiodata,8); |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | send_result(intr_acknowledge,gamedata,8); |
| 827 | } |
| 828 | } else |
| 829 | { |
| 830 | status=status_error|status_shellopen; |
| 831 | send_result(intr_diskerror); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | void psxcd_device::cdcmd_reads() |
| 836 | { |
| 837 | curpos[0]=loc[0]; |
| 838 | curpos[1]=loc[1]; |
| 839 | curpos[2]=loc[2]; |
| 840 | |
| 841 | #ifdef skip_reads |
| 842 | #ifdef debug_cdrom |
| 843 | log("cdrom: reads [SKIPPING - RETURN COMPLETE]\n"); |
| 844 | #endif |
| 845 | |
| 846 | send_result(intr_complete); |
| 847 | #else |
| 848 | #ifdef debug_cdrom |
| 849 | printf("cdrom: reads\n"); |
| 850 | #endif |
| 851 | |
| 852 | stop_read(); |
| 853 | start_streaming(); |
| 854 | #endif |
| 855 | } |
| 856 | |
| 857 | void psxcd_device::cdcmd_reset() |
| 858 | { |
| 859 | #ifdef debug_cdrom |
| 860 | printf("cdrom: reset\n"); |
| 861 | #endif |
| 862 | } |
| 863 | |
| 864 | void psxcd_device::cdcmd_readtoc() |
| 865 | { |
| 866 | #ifdef debug_cdrom |
| 867 | printf("cdrom: readtoc\n"); |
| 868 | #endif |
| 869 | |
| 870 | static unsigned char data[4]= |
| 871 | { |
| 872 | 0x00, |
| 873 | 0x00, |
| 874 | 0xff, |
| 875 | 0xfe |
| 876 | }; |
| 877 | |
| 878 | send_result(intr_complete|0x10,data,2); |
| 879 | } |
| 880 | |
| 881 | // |
| 882 | // |
| 883 | // |
| 884 | |
| 885 | void psxcd_device::cmd_complete(command_result *res) |
| 886 | { |
| 887 | bool doint=((res->res&0x10)==0); |
| 888 | #ifdef debug_cdrom |
| 889 | command_result *rf; |
| 890 | #endif |
| 891 | |
| 892 | if (doint) |
| 893 | { |
| 894 | psx_irq_set(machine(), 0x0004); |
| 895 | } |
| 896 | |
| 897 | add_result(res); |
| 898 | |
| 899 | #ifdef debug_cdrom |
| 900 | if (doint) |
| 901 | { |
| 902 | printf("cdrom: irq ["); |
| 903 | for (rf=res_queue; ((rf) && (rf->next)); rf=rf->next); |
| 904 | printf("%d ",rf->res); |
| 905 | printf("]\n"); |
| 906 | } |
| 907 | #endif |
| 908 | } |
| 909 | |
| 910 | // |
| 911 | // |
| 912 | // |
| 913 | |
| 914 | void psxcd_device::add_result(command_result *res) |
| 915 | { |
| 916 | command_result *rf; |
| 917 | |
| 918 | if (res_queue) |
| 919 | { |
| 920 | for (rf=res_queue; rf->next; rf=rf->next); |
| 921 | rf->next=res; |
| 922 | } else |
| 923 | { |
| 924 | res_queue=res; |
| 925 | } |
| 926 | |
| 927 | res->next=NULL; |
| 928 | } |
| 929 | |
| 930 | // |
| 931 | // |
| 932 | // |
| 933 | |
| 934 | event *psxcd_device::send_result(const unsigned int res, |
| 935 | const unsigned char *data, |
| 936 | const unsigned int sz, |
| 937 | const unsigned int delay) |
| 938 | { |
| 939 | // Update shell open status |
| 940 | |
| 941 | if (! open) |
| 942 | { |
| 943 | status=status_error|status_shellopen; |
| 944 | } |
| 945 | else |
| 946 | { |
| 947 | if (status&status_shellopen) |
| 948 | status=status_standby; |
| 949 | } |
| 950 | |
| 951 | // Prepare event |
| 952 | |
| 953 | event *ev=new event; |
| 954 | ev->t=delay; |
| 955 | ev->type=event_cmd_complete; |
| 956 | |
| 957 | command_result *cr=(command_result *)ev->data; |
| 958 | |
| 959 | cr->res=res; |
| 960 | if (sz) |
| 961 | { |
| 962 | assert(sz<sizeof(cr->data)); |
| 963 | memcpy(cr->data,data,sz); |
| 964 | cr->sz=sz; |
| 965 | } else |
| 966 | { |
| 967 | cr->data[0]=status; |
| 968 | cr->sz=1; |
| 969 | } |
| 970 | |
| 971 | // Avoid returning results after sector read results - |
| 972 | // delay the sector read slightly if necessary |
| 973 | |
| 974 | UINT64 systime = machine().device<cpu_device>("maincpu")->total_cycles(); |
| 975 | if ((next_read_event) && ((systime+ev->t)>(next_sector_t))) |
| 976 | { |
| 977 | UINT32 hz = m_sysclock / (delay + 2000); |
| 978 | next_read_event->timer->adjust(attotime::from_hz(hz), 0, attotime::never); |
| 979 | |
| 980 | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 981 | { |
| 982 | if (m_eventfortimer[i] == next_read_event) |
| 983 | { |
| 984 | printf("Adjusting timer %d to %d hz]n", i, hz); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | add_system_event(ev); |
| 990 | return ev; |
| 991 | } |
| 992 | |
| 993 | // |
| 994 | // |
| 995 | // |
| 996 | |
| 997 | void psxcd_device::start_dma(UINT8 *mainram, UINT32 size) |
| 998 | { |
| 999 | if ((int)size>secleft) |
| 1000 | { |
| 1001 | printf("cdrom: dma past end of sector (secleft=%d sz=%d)\n",secleft,size); |
| 1002 | } |
| 1003 | |
| 1004 | // printf("cdrom: start dma %d bytes, %d remaining, secptr %p\n", size, secleft, secptr); |
| 1005 | #ifdef debug_cdrom |
| 1006 | if (size==12) |
| 1007 | { |
| 1008 | char poo[1024],*pp=poo; |
| 1009 | for (unsigned int i=0; i<12; i++) |
| 1010 | { |
| 1011 | sprintf(pp,"%02x ",secptr[i]); |
| 1012 | pp+=3; |
| 1013 | } |
| 1014 | printf("cdrom: data=%s\n",poo); |
| 1015 | } |
| 1016 | #endif |
| 1017 | |
| 1018 | memcpy(mainram, secptr, size); |
| 1019 | memset(secptr, 0xff, size); |
| 1020 | |
| 1021 | secptr += size; |
| 1022 | secleft -= size; |
| 1023 | |
| 1024 | if (secleft<0) secleft=0; |
| 1025 | if (secleft==0) sr&=~0x40; |
| 1026 | } |
| 1027 | |
| 1028 | // |
| 1029 | // |
| 1030 | // |
| 1031 | |
| 1032 | void psxcd_device::prefetch_next_sector() |
| 1033 | { |
| 1034 | unsigned int pos=msf_to_sector(curpos); |
| 1035 | assert(driver); |
| 1036 | driver->prefetch_sector(pos); |
| 1037 | } |
| 1038 | |
| 1039 | // |
| 1040 | // |
| 1041 | // |
| 1042 | |
| 1043 | bool psxcd_device::read_next_sector(const bool block) |
| 1044 | { |
| 1045 | unsigned int pos=msf_to_sector(curpos); |
| 1046 | unsigned char *buf=&secbuf[sechead*raw_sector_size]; |
| 1047 | assert(driver); |
| 1048 | assert(secin<sector_buffer_size); |
| 1049 | |
| 1050 | // printf("read_next_sector: sec %d, sechead %d, raw_sector_size %d\n", pos, sechead, raw_sector_size); |
| 1051 | if (driver->read_sector(pos, buf, block)) |
| 1052 | { |
| 1053 | // printf("buf contents = %02x %02x | %02x %02x\n", buf[0], buf[1], buf[0x20], buf[0x21]); |
| 1054 | |
| 1055 | sechead=(sechead+1)&(sector_buffer_size-1); |
| 1056 | secin++; |
| 1057 | |
| 1058 | memcpy(lastsechdr,&secbuf[raw_sector_size*sectail]+12,8); |
| 1059 | |
| 1060 | return true; |
| 1061 | } else |
| 1062 | { |
| 1063 | return false; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | // |
| 1068 | // |
| 1069 | // |
| 1070 | |
| 1071 | void psxcd_device::read_sector() |
| 1072 | { |
| 1073 | next_read_event=NULL; |
| 1074 | |
| 1075 | if (status & status_reading) |
| 1076 | { |
| 1077 | bool isend=false; |
| 1078 | |
| 1079 | if (read_next_sector(false)) |
| 1080 | { |
| 1081 | unsigned char *rawsec; |
| 1082 | |
| 1083 | if ((mode&mode_adpcm) && (streaming)) |
| 1084 | { |
| 1085 | rawsec=&secbuf[raw_sector_size*sectail]; |
| 1086 | secptr=rawsec+24; |
| 1087 | secleft=2048; |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | rawsec=&secbuf[raw_sector_size*sectail]; |
| 1092 | secptr=rawsec+secskip; |
| 1093 | secleft=secsize; |
| 1094 | } |
| 1095 | |
| 1096 | secin--; |
| 1097 | sectail=(sectail+1)&(sector_buffer_size-1); |
| 1098 | |
| 1099 | // |
| 1100 | |
| 1101 | bool isxa=false; |
| 1102 | |
| 1103 | subheader *sub=(subheader *)(rawsec+16); |
| 1104 | |
| 1105 | #ifdef dump_subheader |
| 1106 | printf("cdrom: subheader file=%02x chan=%02x submode=%02x coding=%02x [%02x%02x%02x%02x]\n", |
| 1107 | sub->file, |
| 1108 | sub->channel, |
| 1109 | sub->submode, |
| 1110 | sub->coding, |
| 1111 | rawsec[0xc], |
| 1112 | rawsec[0xd], |
| 1113 | rawsec[0xe], |
| 1114 | rawsec[0xf]); |
| 1115 | #endif |
| 1116 | |
| 1117 | status&=~status_playing; |
| 1118 | isxa=((mode&mode_adpcm) && (sub->submode&submode_audio)); |
| 1119 | |
| 1120 | if (((mode&mode_channel)==0) || |
| 1121 | ((sub->file==filter_file) && (sub->channel==filter_channel))) |
| 1122 | { |
| 1123 | if (isxa) |
| 1124 | { |
| 1125 | if (sub->submode&submode_eof) |
| 1126 | { |
| 1127 | isend=true; |
| 1128 | //printf("end of file\n"); |
| 1129 | } |
| 1130 | |
| 1131 | #ifndef disable_xa_prefetch |
| 1132 | unsigned int cursec=msf_to_sector(curpos); |
| 1133 | |
| 1134 | if (xa_prefetch_sector==-1) |
| 1135 | { |
| 1136 | xa_prefetch_sector=cursec; |
| 1137 | machine().device<spu_device>("spu")->flush_xa(); |
| 1138 | } |
| 1139 | |
| 1140 | unsigned char *xaptr; |
| 1141 | unsigned int xasecsz; |
| 1142 | |
| 1143 | while (1) |
| 1144 | { |
| 1145 | int dist=xa_prefetch_sector-cursec; |
| 1146 | if (dist>max_xa_prefetch_distance) break; |
| 1147 | |
| 1148 | xaptr=driver->get_prefetch_sector(xa_prefetch_sector,&xasecsz); |
| 1149 | if (! xaptr) break; |
| 1150 | |
| 1151 | switch (xasecsz) |
| 1152 | { |
| 1153 | case 2336: |
| 1154 | break; |
| 1155 | |
| 1156 | default: |
| 1157 | xaptr+=16; |
| 1158 | break; |
| 1159 | } |
| 1160 | |
| 1161 | subheader *xasub=(subheader *)xaptr; |
| 1162 | |
| 1163 | if ((xasub->submode&submode_audio) && |
| 1164 | (((mode&mode_channel)==0) || |
| 1165 | ((xasub->file==sub->file) && |
| 1166 | (xasub->channel==sub->channel)))) |
| 1167 | { |
| 1168 | if (! machine().device<spu_device>("spu")->play_xa(xa_prefetch_sector,xaptr)) |
| 1169 | break; |
| 1170 | } |
| 1171 | xa_prefetch_sector++; |
| 1172 | } |
| 1173 | #else |
| 1174 | machine().device<spu_device>("spu")->play_xa(0,rawsec+16); |
| 1175 | #endif |
| 1176 | |
| 1177 | status|=status_playing; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | if ((mode&mode_autopause)==0) |
| 1182 | isend=false; |
| 1183 | |
| 1184 | // |
| 1185 | |
| 1186 | curpos[2]++; |
| 1187 | if (curpos[2]==75) |
| 1188 | { |
| 1189 | curpos[2]=0; |
| 1190 | curpos[1]++; |
| 1191 | if (curpos[1]==60) |
| 1192 | { |
| 1193 | curpos[1]=0; |
| 1194 | curpos[0]++; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | loc[0]=curpos[0]; |
| 1199 | loc[1]=curpos[1]; |
| 1200 | loc[2]=curpos[2]; |
| 1201 | |
| 1202 | // |
| 1203 | |
| 1204 | command_result *res=new command_result; |
| 1205 | res->res=isend?intr_dataend:intr_dataready; |
| 1206 | res->data[0]=status; |
| 1207 | res->sz=1; |
| 1208 | |
| 1209 | sr|=0x40; |
| 1210 | |
| 1211 | if ((streaming) && (isxa)) |
| 1212 | { |
| 1213 | global_free(res); |
| 1214 | res=NULL; |
| 1215 | } |
| 1216 | |
| 1217 | if (res) |
| 1218 | { |
| 1219 | #ifdef debug_cdrom |
| 1220 | printf("cdrom:: data ready\n"); |
| 1221 | #endif |
| 1222 | |
| 1223 | cmd_complete(res); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | if (! isend) |
| 1228 | { |
| 1229 | unsigned int cyc=read_sector_cycles; |
| 1230 | if (mode&mode_double_speed) cyc>>=1; |
| 1231 | |
| 1232 | next_sector_t+=cyc; |
| 1233 | |
| 1234 | event *ev=new event; |
| 1235 | ev->t=cyc; |
| 1236 | ev->type=event_read_sector; |
| 1237 | next_read_event=ev; |
| 1238 | add_system_event(ev); |
| 1239 | |
| 1240 | //read_next_sector(); |
| 1241 | } else |
| 1242 | { |
| 1243 | printf("autopause xa\n"); |
| 1244 | stop_read(); |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // |
| 1250 | // |
| 1251 | // |
| 1252 | |
| 1253 | bool psxcd_device::play_cdda_sector(const unsigned int sector, |
| 1254 | unsigned char *rawsec) |
| 1255 | { |
| 1256 | bool isdata=true; |
| 1257 | |
| 1258 | if (rawsec[0]!=0) |
| 1259 | { |
| 1260 | isdata=false; |
| 1261 | } else |
| 1262 | { |
| 1263 | for (int i=0; i<10; i++) |
| 1264 | if (rawsec[i+1]!=0xff) |
| 1265 | { |
| 1266 | isdata=false; |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if (! isdata) |
| 1272 | { |
| 1273 | return machine().device<spu_device>("spu")->play_cdda(sector,rawsec); |
| 1274 | } else |
| 1275 | { |
| 1276 | return true; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | // |
| 1281 | // |
| 1282 | // |
| 1283 | |
| 1284 | void psxcd_device::play_sector() |
| 1285 | { |
| 1286 | next_read_event=NULL; |
| 1287 | |
| 1288 | if (status&status_playing) |
| 1289 | { |
| 1290 | #ifdef disable_cdda_prefetch |
| 1291 | unsigned char *rawsec=&secbuf[raw_sector_size*sectail]; |
| 1292 | #endif |
| 1293 | secin--; |
| 1294 | sectail=(sectail+1)&(sector_buffer_size-1); |
| 1295 | |
| 1296 | // |
| 1297 | |
| 1298 | #ifndef disable_cdda_prefetch |
| 1299 | unsigned int cursec=msf_to_sector(curpos); |
| 1300 | |
| 1301 | if (cdda_prefetch_sector==-1) |
| 1302 | { |
| 1303 | cdda_prefetch_sector=cursec; |
| 1304 | machine().device<spu_device>("spu")->flush_cdda(); |
| 1305 | } |
| 1306 | |
| 1307 | unsigned char *cddaptr; |
| 1308 | // bool full=false; |
| 1309 | unsigned int cddasecsz; |
| 1310 | |
| 1311 | while (1) |
| 1312 | { |
| 1313 | int dist=cdda_prefetch_sector-cursec; |
| 1314 | if (dist>max_cdda_prefetch_distance) break; |
| 1315 | |
| 1316 | cddaptr=driver->get_prefetch_sector(cdda_prefetch_sector,&cddasecsz); |
| 1317 | if (! cddaptr) break; |
| 1318 | |
| 1319 | if (! play_cdda_sector(cdda_prefetch_sector,cddaptr)) |
| 1320 | break; |
| 1321 | |
| 1322 | cdda_prefetch_sector++; |
| 1323 | } |
| 1324 | #else |
| 1325 | play_cdda_sector(0,rawsec); |
| 1326 | #endif |
| 1327 | |
| 1328 | // |
| 1329 | |
| 1330 | curpos[2]++; |
| 1331 | if (curpos[2]==75) |
| 1332 | { |
| 1333 | curpos[2]=0; |
| 1334 | curpos[1]++; |
| 1335 | if (curpos[1]==60) |
| 1336 | { |
| 1337 | curpos[1]=0; |
| 1338 | curpos[0]++; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | loc[0]=curpos[0]; |
| 1343 | loc[1]=curpos[1]; |
| 1344 | loc[2]=curpos[2]; |
| 1345 | |
| 1346 | // |
| 1347 | |
| 1348 | if (mode&mode_autopause) |
| 1349 | { |
| 1350 | if (msf_to_sector(loc)>=autopause_sector) |
| 1351 | { |
| 1352 | printf("autopause cdda\n"); |
| 1353 | |
| 1354 | command_result *res=new command_result; |
| 1355 | res->res=intr_dataend; |
| 1356 | res->data[0]=status_standby; |
| 1357 | res->sz=1; |
| 1358 | cmd_complete(res); |
| 1359 | stop_read(); |
| 1360 | return; |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | if (mode&mode_report) |
| 1365 | { |
| 1366 | command_result *res=new command_result; |
| 1367 | res->res=intr_complete; //dataready; |
| 1368 | |
| 1369 | res->data[0]=status_playing|status_standby; |
| 1370 | res->data[1]=0x01; |
| 1371 | res->data[2]=0x80; |
| 1372 | res->data[3]=decimal_to_bcd(loc[0]); |
| 1373 | res->data[4]=decimal_to_bcd(loc[1])|0x80; |
| 1374 | res->data[5]=decimal_to_bcd(loc[2]); |
| 1375 | |
| 1376 | res->sz=8; |
| 1377 | |
| 1378 | cmd_complete(res); |
| 1379 | } |
| 1380 | |
| 1381 | unsigned int cyc=read_sector_cycles; |
| 1382 | |
| 1383 | event *ev=new event; |
| 1384 | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1385 | ev->type=event_play_sector; |
| 1386 | |
| 1387 | next_sector_t+=cyc; |
| 1388 | |
| 1389 | next_read_event=ev; |
| 1390 | add_system_event(ev); |
| 1391 | |
| 1392 | read_next_sector(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | // |
| 1398 | // |
| 1399 | // |
| 1400 | |
| 1401 | void psxcd_device::preread_sector() |
| 1402 | { |
| 1403 | next_read_event=NULL; |
| 1404 | |
| 1405 | // |
| 1406 | |
| 1407 | event *ev=new event; |
| 1408 | |
| 1409 | unsigned int pos=msf_to_sector(curpos); |
| 1410 | unsigned char *buf=&secbuf[sechead*raw_sector_size]; |
| 1411 | if (! driver->read_sector(pos,buf,false)) |
| 1412 | { |
| 1413 | ev->t=(m_sysclock/60); |
| 1414 | ev->type=event_preread_sector; |
| 1415 | |
| 1416 | unsigned int cyc=read_sector_cycles; |
| 1417 | if (mode&mode_double_speed) cyc>>=1; |
| 1418 | next_sector_t=ev->t+(cyc-preread_delay)+machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1419 | } else |
| 1420 | { |
| 1421 | memcpy(lastsechdr,buf+12,8); |
| 1422 | |
| 1423 | // |
| 1424 | |
| 1425 | command_result *res=new command_result; |
| 1426 | res->res=intr_complete; |
| 1427 | res->data[0]=status; |
| 1428 | res->sz=1; |
| 1429 | |
| 1430 | #ifdef debug_cdrom |
| 1431 | printf("cdrom: read acknowledge\n"); |
| 1432 | #endif |
| 1433 | |
| 1434 | cmd_complete(res); |
| 1435 | |
| 1436 | // |
| 1437 | |
| 1438 | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1439 | ev->type=event_read_sector; |
| 1440 | |
| 1441 | //read_next_sector(); |
| 1442 | } |
| 1443 | |
| 1444 | next_read_event=ev; |
| 1445 | add_system_event(ev); |
| 1446 | } |
| 1447 | |
| 1448 | // |
| 1449 | // |
| 1450 | // |
| 1451 | |
| 1452 | void psxcd_device::start_read() |
| 1453 | { |
| 1454 | #ifdef debug_cdrom |
| 1455 | printf("cdrom: start read\n"); |
| 1456 | #endif |
| 1457 | |
| 1458 | assert((status&(status_reading|status_playing))==0); |
| 1459 | |
| 1460 | status|=status_reading; |
| 1461 | |
| 1462 | secin=sechead=sectail=0; |
| 1463 | xa_prefetch_sector=-1; |
| 1464 | |
| 1465 | unsigned int cyc=read_sector_cycles; |
| 1466 | if (mode&mode_double_speed) cyc>>=1; |
| 1467 | |
| 1468 | INT64 systime=machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1469 | |
| 1470 | systime+=start_read_delay; |
| 1471 | |
| 1472 | event *ev=new event; |
| 1473 | ev->t=start_read_delay+preread_delay; |
| 1474 | ev->type=event_preread_sector; |
| 1475 | |
| 1476 | next_sector_t=systime+cyc; |
| 1477 | next_read_event=ev; |
| 1478 | add_system_event(ev); |
| 1479 | |
| 1480 | prefetch_next_sector(); |
| 1481 | } |
| 1482 | |
| 1483 | // |
| 1484 | // |
| 1485 | // |
| 1486 | |
| 1487 | void psxcd_device::start_streaming() |
| 1488 | { |
| 1489 | assert(! streaming); |
| 1490 | |
| 1491 | streaming=true; |
| 1492 | start_read(); |
| 1493 | } |
| 1494 | |
| 1495 | // |
| 1496 | // |
| 1497 | // |
| 1498 | |
| 1499 | void psxcd_device::start_play() |
| 1500 | { |
| 1501 | #ifdef debug_cdrom |
| 1502 | printf("cdrom: start play\n"); |
| 1503 | #endif |
| 1504 | |
| 1505 | status|=status_playing; |
| 1506 | |
| 1507 | secin=sechead=sectail=0; |
| 1508 | cdda_prefetch_sector=-1; |
| 1509 | |
| 1510 | if (mode&mode_autopause) |
| 1511 | { |
| 1512 | unsigned int pos=msf_to_sector(curpos); |
| 1513 | driver->find_track(pos+150,NULL,&autopause_sector); |
| 1514 | // printf("pos=%d auto=%d\n",pos,autopause_sector); |
| 1515 | } |
| 1516 | |
| 1517 | unsigned int cyc=read_sector_cycles; |
| 1518 | |
| 1519 | next_sector_t=machine().device<cpu_device>("maincpu")->total_cycles()+cyc; |
| 1520 | |
| 1521 | event *ev=new event; |
| 1522 | ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles(); |
| 1523 | ev->type=event_play_sector; |
| 1524 | |
| 1525 | next_sector_t+=cyc; |
| 1526 | |
| 1527 | next_read_event=ev; |
| 1528 | add_system_event(ev); |
| 1529 | |
| 1530 | read_next_sector(); |
| 1531 | } |
| 1532 | |
| 1533 | // |
| 1534 | // |
| 1535 | // |
| 1536 | |
| 1537 | void psxcd_device::stop_read() |
| 1538 | { |
| 1539 | #ifdef debug_cdrom |
| 1540 | if (status&status_reading) |
| 1541 | printf("cdrom: stop read\n"); |
| 1542 | #endif |
| 1543 | status&=~(status_reading|status_playing); |
| 1544 | streaming=false; |
| 1545 | |
| 1546 | if (next_read_event) |
| 1547 | { |
| 1548 | next_read_event->timer->adjust(attotime::never, 0, attotime::never); |
| 1549 | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 1550 | { |
| 1551 | if (m_timers[i] == next_read_event->timer) |
| 1552 | { |
| 1553 | m_timerinuse[i] = false; |
| 1554 | m_eventfortimer[i] = false; |
| 1555 | break; |
| 1556 | } |
| 1557 | } |
| 1558 | global_free(next_read_event); |
| 1559 | next_read_event=NULL; |
| 1560 | } |
| 1561 | |
| 1562 | unsigned int sector=msf_to_sector(curpos); |
| 1563 | machine().device<spu_device>("spu")->flush_xa(sector); |
| 1564 | machine().device<spu_device>("spu")->flush_cdda(sector); |
| 1565 | } |
| 1566 | |
| 1567 | // |
| 1568 | // |
| 1569 | // |
| 1570 | |
| 1571 | void psxcd_device::set_driver(cdrom_driver *d) |
| 1572 | { |
| 1573 | char err[1024]; |
| 1574 | |
| 1575 | if (d) |
| 1576 | { |
| 1577 | if (d->is_usable(err,1024)) |
| 1578 | { |
| 1579 | driver=d; |
| 1580 | open=false; |
| 1581 | |
| 1582 | if (! first_open) |
| 1583 | { |
| 1584 | command_result *res=new command_result; |
| 1585 | res->res=intr_acknowledge; |
| 1586 | res->data[0]=status_standby; |
| 1587 | res->sz=1; |
| 1588 | |
| 1589 | cmd_complete(res); |
| 1590 | |
| 1591 | open_nops=10; |
| 1592 | } |
| 1593 | |
| 1594 | first_open=false; |
| 1595 | } |
| 1596 | } else |
| 1597 | { |
| 1598 | driver=NULL; |
| 1599 | open=false; |
| 1600 | |
| 1601 | command_result *res=new command_result; |
| 1602 | res->res=intr_acknowledge; |
| 1603 | res->data[0]=status_shellopen; |
| 1604 | res->sz=1; |
| 1605 | |
| 1606 | cmd_complete(res); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | // |
| 1611 | // |
| 1612 | // |
| 1613 | void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 1614 | { |
| 1615 | event *ev = m_eventfortimer[tid]; |
| 1616 | |
| 1617 | // printf("timer %d fired, performing event type %d\n", tid, ev->type); |
| 1618 | |
| 1619 | switch (ev->type) |
| 1620 | { |
| 1621 | case event_cmd_complete: |
| 1622 | { |
| 1623 | #ifdef debug_cdrom |
| 1624 | printf("cdrom:: event cmd complete\n"); |
| 1625 | #endif |
| 1626 | |
| 1627 | command_result *res=new command_result; |
| 1628 | memcpy(res,ev->data,sizeof(command_result)); |
| 1629 | cmd_complete(res); |
| 1630 | break; |
| 1631 | } |
| 1632 | |
| 1633 | case event_preread_sector: |
| 1634 | preread_sector(); |
| 1635 | break; |
| 1636 | |
| 1637 | case event_read_sector: |
| 1638 | read_sector(); |
| 1639 | break; |
| 1640 | |
| 1641 | case event_play_sector: |
| 1642 | play_sector(); |
| 1643 | break; |
| 1644 | } |
| 1645 | |
| 1646 | // free the timer |
| 1647 | // printf("Freeing timer %d\n", tid); |
| 1648 | m_timers[tid]->adjust(attotime::never, 0, attotime::never); |
| 1649 | m_timerinuse[tid] = false; |
| 1650 | m_eventfortimer[tid] = NULL; |
| 1651 | |
| 1652 | global_free(ev); |
| 1653 | } |
| 1654 | |
| 1655 | void psxcd_device::add_system_event(event *ev) |
| 1656 | { |
| 1657 | emu_timer *timer = NULL; |
| 1658 | int tnum = -1; |
| 1659 | |
| 1660 | // allocate a timer for this event |
| 1661 | for (int i = 0; i < MAX_PSXCD_TIMERS; i++) |
| 1662 | { |
| 1663 | if (!m_timerinuse[i]) |
| 1664 | { |
| 1665 | tnum = i; |
| 1666 | timer = m_timers[i]; |
| 1667 | m_timerinuse[i] = true; |
| 1668 | m_eventfortimer[i] = ev; |
| 1669 | break; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | if (tnum == -1) |
| 1674 | { |
| 1675 | fatalerror("PSXCD: ran out of timers!\n"); |
| 1676 | } |
| 1677 | |
| 1678 | // ev->t is in maincpu clock cycles |
| 1679 | UINT32 hz = m_sysclock / ev->t; |
| 1680 | // printf("add_system_event: event type %d for %d hz (using timer %d)\n", ev->type, hz, tnum); |
| 1681 | timer->adjust(attotime::from_hz(hz), tnum, attotime::never); |
| 1682 | |
| 1683 | // back-reference the timer from the event |
| 1684 | ev->timer = timer; |
| 1685 | } |
| 1686 | |
src/mess/machine/psxcddrv.c
| r0 | r11506 | |
| 1 | #include "emu.h" |
| 2 | #include "includes/psx.h" |
| 3 | #include "psxcd.h" |
| 4 | #include "psxcddrv.h" |
| 5 | |
| 6 | //#define debug_mess_driver |
| 7 | |
| 8 | // |
| 9 | // |
| 10 | // |
| 11 | |
| 12 | static const unsigned int num_pf_sectors=32, num_pf_buffers=16; |
| 13 | |
| 14 | // |
| 15 | // |
| 16 | // |
| 17 | |
| 18 | cdrom_driver::cdrom_driver() |
| 19 | { |
| 20 | pf_head = 0; |
| 21 | pf_tail = 0; |
| 22 | num_pf = 0; |
| 23 | pf_head_sector = 0; |
| 24 | pf_status = NULL; |
| 25 | native_sector_size = raw_sector_size; |
| 26 | last_pf_status = NULL; |
| 27 | m_cd = NULL; |
| 28 | m_machine = NULL; |
| 29 | |
| 30 | // printf("cdrom_driver base class init, pf_buffer size is %d\n", num_pf_sectors*num_pf_buffers*raw_sector_size); |
| 31 | |
| 32 | pf_buffer=new unsigned char [num_pf_sectors*num_pf_buffers*raw_sector_size]; |
| 33 | |
| 34 | timestamp_frequency = 1; |
| 35 | } |
| 36 | |
| 37 | cdrom_driver::~cdrom_driver() |
| 38 | { |
| 39 | global_free(pf_buffer); |
| 40 | } |
| 41 | |
| 42 | // |
| 43 | // |
| 44 | // |
| 45 | |
| 46 | void cdrom_driver::set_native_sector_size(const unsigned int sz) |
| 47 | { |
| 48 | native_sector_size=sz; |
| 49 | } |
| 50 | |
| 51 | // |
| 52 | // |
| 53 | // |
| 54 | |
| 55 | void cdrom_driver::cancel_io() |
| 56 | { |
| 57 | if (pf_status) |
| 58 | { |
| 59 | pf_status->cancel(); |
| 60 | pf_status->release(); |
| 61 | } |
| 62 | |
| 63 | pf_status=NULL; |
| 64 | } |
| 65 | |
| 66 | // |
| 67 | // |
| 68 | // |
| 69 | |
| 70 | void cdrom_driver::prefetch_sector(const unsigned int sec) |
| 71 | { |
| 72 | int numpfsec=num_pf*num_pf_sectors, |
| 73 | pfsec=sec-pf_head_sector; |
| 74 | |
| 75 | // printf("prefetch_sector: %d\n", sec); |
| 76 | |
| 77 | if ((pfsec<0) || (pfsec>numpfsec)) |
| 78 | { |
| 79 | // Sector is not in prefetch buffer, abort current prefetch |
| 80 | |
| 81 | if (pf_status) |
| 82 | { |
| 83 | pf_status->cancel(); |
| 84 | pf_status->release(); |
| 85 | } |
| 86 | |
| 87 | // Reset the buffer and begin a new prefetch |
| 88 | |
| 89 | pf_head=0; |
| 90 | pf_tail=0; |
| 91 | num_pf=1; |
| 92 | pf_head_sector=sec; |
| 93 | |
| 94 | last_pf_status=NULL; |
| 95 | pf_status=read_sectors(sec, num_pf_sectors, pf_buffer); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // |
| 100 | // |
| 101 | // |
| 102 | |
| 103 | bool cdrom_driver::is_prefetch_sector_loaded(const unsigned int sec) |
| 104 | { |
| 105 | int numpfsec=num_pf*num_pf_sectors, |
| 106 | pfsec=sec-pf_head_sector; |
| 107 | |
| 108 | if ((pfsec<0) || (pfsec>=numpfsec)) |
| 109 | { |
| 110 | // Requested sector is not in prefetch buffer, begin a new prefetch |
| 111 | |
| 112 | prefetch_sector(sec); |
| 113 | pfsec=sec-pf_head_sector; |
| 114 | numpfsec=num_pf*num_pf_sectors; |
| 115 | } |
| 116 | |
| 117 | int blk=pfsec/num_pf_sectors; |
| 118 | |
| 119 | if (blk>0) |
| 120 | { |
| 121 | // Discard blocks below the prefetch point |
| 122 | |
| 123 | pf_head=(pf_head+blk)%num_pf_buffers; |
| 124 | pf_head_sector+=num_pf_sectors*blk; |
| 125 | pfsec-=num_pf_sectors*blk; |
| 126 | num_pf-=blk; |
| 127 | blk=0; |
| 128 | } |
| 129 | |
| 130 | bool comp=((! pf_status) || (pf_status->complete())); |
| 131 | |
| 132 | if (! comp) |
| 133 | { |
| 134 | INT64 curtime=m_machine->device<cpu_device>("maincpu")->total_cycles(); |
| 135 | |
| 136 | if (last_pf_status!=pf_status) |
| 137 | { |
| 138 | last_pf_status=pf_status; |
| 139 | pf_timeout_begin=curtime; |
| 140 | } |
| 141 | |
| 142 | INT64 timeout=curtime-pf_timeout_begin; |
| 143 | int timeout_sec=(int)(timeout/timestamp_frequency); |
| 144 | if (timeout_sec>20) |
| 145 | { |
| 146 | printf("cdrom: prefetch timed out, trying again...\n"); |
| 147 | num_pf=0; |
| 148 | pf_head_sector=-1; |
| 149 | prefetch_sector(sec); |
| 150 | return is_prefetch_sector_loaded(sec); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if ((num_pf<num_pf_buffers) && (comp)) |
| 155 | { |
| 156 | // The prefetch buffer is not full and we are not waiting on IO, |
| 157 | // prefetch the next block |
| 158 | |
| 159 | pf_tail=(pf_tail+1)%num_pf_buffers; |
| 160 | num_pf++; |
| 161 | |
| 162 | int nxtsec=pf_head_sector+((num_pf-1)*num_pf_sectors); |
| 163 | unsigned char *ptr=pf_buffer+((pf_tail*num_pf_sectors)*native_sector_size); |
| 164 | |
| 165 | if (pf_status) |
| 166 | { |
| 167 | pf_status->release(); |
| 168 | pf_status=last_pf_status=NULL; |
| 169 | } |
| 170 | |
| 171 | pf_status=read_sectors(nxtsec, num_pf_sectors, ptr); |
| 172 | } |
| 173 | |
| 174 | if (blk==(num_pf-1)) |
| 175 | { |
| 176 | // The sector we want is in the last block in the prefetch buffer |
| 177 | // which might still be loading, check if the sector we want is loaded |
| 178 | #if 0 // we do not load async in MESS |
| 179 | INT64 trans=pf_status->bytes_transferred(); |
| 180 | unsigned int secmod=pfsec%num_pf_sectors, |
| 181 | needbytes=(secmod+1)*native_sector_size; |
| 182 | |
| 183 | if (trans<needbytes) |
| 184 | { |
| 185 | // The sector is not loaded yet |
| 186 | |
| 187 | return false; |
| 188 | } else |
| 189 | #endif |
| 190 | { |
| 191 | // The sector is loaded |
| 192 | |
| 193 | return true; |
| 194 | } |
| 195 | } else |
| 196 | { |
| 197 | // The sector is not in the last block so it must be loaded |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // |
| 204 | // |
| 205 | // |
| 206 | |
| 207 | unsigned char *cdrom_driver::get_prefetch_sector(const unsigned int sec, unsigned int *sz) |
| 208 | { |
| 209 | int numpfsec=num_pf*num_pf_sectors, |
| 210 | pfsec=sec-pf_head_sector; |
| 211 | if ((pfsec>=0) && (pfsec<numpfsec)) |
| 212 | { |
| 213 | int blk=(pf_head+(pfsec/num_pf_sectors))%num_pf_buffers, |
| 214 | off=((blk*num_pf_sectors)+(pfsec%num_pf_sectors))*native_sector_size; |
| 215 | *sz=native_sector_size; |
| 216 | return pf_buffer+off; |
| 217 | } else |
| 218 | { |
| 219 | return NULL; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // |
| 224 | // |
| 225 | // |
| 226 | |
| 227 | bool cdrom_driver::read_sector(const unsigned int sec, unsigned char *buf, const bool block) |
| 228 | { |
| 229 | bool loaded=is_prefetch_sector_loaded(sec); |
| 230 | |
| 231 | // printf("read_sector: %d (loaded=%c)\n", sec, loaded ? 'Y' : 'N'); |
| 232 | |
| 233 | if ((! loaded) && (block)) |
| 234 | { |
| 235 | pf_status->block_until_complete(); |
| 236 | loaded=true; |
| 237 | } |
| 238 | |
| 239 | if (loaded) |
| 240 | { |
| 241 | unsigned int secsz=0; |
| 242 | unsigned char *ptr=get_prefetch_sector(sec,&secsz); |
| 243 | assert(ptr); |
| 244 | |
| 245 | // printf("got sector %d @ %p, size %d = %02x %02x | %02x %02x\n", sec, ptr, secsz, ptr[0], ptr[1], ptr[0x20], ptr[0x21]); |
| 246 | |
| 247 | if (secsz<2352) |
| 248 | { |
| 249 | // Add sector header |
| 250 | |
| 251 | buf[0]=0; |
| 252 | memset(buf+1,0xff,10); |
| 253 | buf[11]=0; |
| 254 | sector_to_msf(sec,buf+12); |
| 255 | buf[12]=decimal_to_bcd(buf[12]); |
| 256 | buf[13]=decimal_to_bcd(buf[13]); |
| 257 | buf[14]=decimal_to_bcd(buf[14]); |
| 258 | buf[15]=2; |
| 259 | |
| 260 | if (secsz<2336) |
| 261 | { |
| 262 | memset(buf+16,0xff,8); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | switch (secsz) |
| 267 | { |
| 268 | case 2048: |
| 269 | memcpy(buf+24,ptr,2048); |
| 270 | break; |
| 271 | |
| 272 | case 2336: |
| 273 | memcpy(buf+16,ptr,2336); |
| 274 | break; |
| 275 | |
| 276 | case 2352: |
| 277 | memcpy(buf,ptr,raw_sector_size); |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | return true; |
| 282 | } else |
| 283 | { |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void cdrom_driver::set_machine(const running_machine &machine) |
| 289 | { |
| 290 | m_machine = (running_machine *)&machine; |
| 291 | |
| 292 | timestamp_frequency = m_machine->device<cpu_device>("maincpu")->clock(); |
| 293 | |
| 294 | // printf("cdrom_driver::set_machine: timestamp frequency = %d\n", timestamp_frequency); |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | MAME/MESS driver implementation |
| 299 | */ |
| 300 | |
| 301 | class mess_cdrom_driver : public cdrom_driver |
| 302 | { |
| 303 | enum track_type |
| 304 | { |
| 305 | track_illegal=-1, |
| 306 | track_mode1_2048=0, |
| 307 | track_mode2_2352, |
| 308 | track_mode2_2336, |
| 309 | track_audio |
| 310 | }; |
| 311 | |
| 312 | struct toc_entry |
| 313 | { |
| 314 | unsigned int type; |
| 315 | unsigned char address[3]; |
| 316 | }; |
| 317 | |
| 318 | int num_sectors, num_tracks; |
| 319 | toc_entry toc[100]; |
| 320 | int bin_sector_size; |
| 321 | const char *err; |
| 322 | |
| 323 | io_status *read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf); |
| 324 | |
| 325 | public: |
| 326 | mess_cdrom_driver(); |
| 327 | ~mess_cdrom_driver(); |
| 328 | |
| 329 | bool is_usable(char *error_msg, const int msglen) const |
| 330 | { |
| 331 | return true; |
| 332 | } |
| 333 | |
| 334 | bool read_toc(); |
| 335 | unsigned int get_first_track() const; |
| 336 | unsigned int get_num_tracks() const; |
| 337 | bool get_track_address(const unsigned int track,unsigned char *address) const; |
| 338 | tracktype get_track_type(const unsigned int track) const; |
| 339 | unsigned int find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const; |
| 340 | cdromtype get_type() const; |
| 341 | }; |
| 342 | |
| 343 | mess_cdrom_driver::mess_cdrom_driver() |
| 344 | : err(NULL) |
| 345 | { |
| 346 | for (int i=0; i<100; i++) |
| 347 | toc[i].type=track_illegal; |
| 348 | num_tracks=0; |
| 349 | num_sectors=0; |
| 350 | } |
| 351 | |
| 352 | // |
| 353 | // |
| 354 | // |
| 355 | |
| 356 | mess_cdrom_driver::~mess_cdrom_driver() |
| 357 | { |
| 358 | cancel_io(); |
| 359 | } |
| 360 | |
| 361 | // |
| 362 | // |
| 363 | // |
| 364 | |
| 365 | bool mess_cdrom_driver::read_toc() |
| 366 | { |
| 367 | if (m_cd) |
| 368 | { |
| 369 | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 370 | |
| 371 | num_tracks = cdrom_get_last_track(m_cd); |
| 372 | |
| 373 | switch (toc->tracks[0].trktype) |
| 374 | { |
| 375 | case CD_TRACK_MODE1: bin_sector_size=2048; break; |
| 376 | case CD_TRACK_MODE2_FORM1: bin_sector_size=2048; break; |
| 377 | case CD_TRACK_MODE2: bin_sector_size=2336; break; |
| 378 | case CD_TRACK_MODE2_FORM_MIX: bin_sector_size=2336; break; |
| 379 | default: bin_sector_size=2352; break; |
| 380 | } |
| 381 | |
| 382 | set_native_sector_size(bin_sector_size); |
| 383 | num_sectors = cdrom_get_track_start(m_cd, num_tracks) + toc->tracks[num_tracks].frames; |
| 384 | |
| 385 | // printf("mess_cdrom_driver: %d sectors, native size %d\n",num_sectors, bin_sector_size); |
| 386 | |
| 387 | return true; |
| 388 | } |
| 389 | |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | // |
| 394 | // |
| 395 | // |
| 396 | |
| 397 | io_status *mess_cdrom_driver::read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf) |
| 398 | { |
| 399 | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 400 | UINT32 track = cdrom_get_track(m_cd, startsec); |
| 401 | UINT32 secsize = toc->tracks[track].datasize; |
| 402 | |
| 403 | #ifdef debug_mess_driver |
| 404 | printf("mess: read %d sectors from %d (secsize %d)\n",numsec,startsec,secsize); |
| 405 | #endif |
| 406 | |
| 407 | if ((startsec>=0)) // && ((int)startsec<num_sectors)) |
| 408 | { |
| 409 | // fin->seek((INT64)startsec*(INT64)bin_sector_size); |
| 410 | |
| 411 | // io_status *ios=fin->async_read(buf,numsec*bin_sector_size); |
| 412 | // if (! ios) |
| 413 | for (int i = 0; i < numsec; i++) |
| 414 | { |
| 415 | // printf("[%d/%d] Reading to pf_buffer %p at offset %d, size %d\n", i, numsec, &buf[secsize*i], secsize*i, secsize); |
| 416 | cdrom_read_data(m_cd, startsec+i, &buf[secsize*i], CD_TRACK_RAW_DONTCARE); |
| 417 | } |
| 418 | |
| 419 | return NULL; |
| 420 | |
| 421 | // return ios; |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | printf("mess: read sector out of range (%d, max=%d)\n", |
| 426 | startsec, |
| 427 | num_sectors); |
| 428 | |
| 429 | memset(buf,0xff,numsec*bin_sector_size); |
| 430 | return NULL; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | // |
| 435 | // |
| 436 | // |
| 437 | |
| 438 | unsigned int mess_cdrom_driver::get_first_track() const |
| 439 | { |
| 440 | return 1; |
| 441 | } |
| 442 | |
| 443 | unsigned int mess_cdrom_driver::get_num_tracks() const |
| 444 | { |
| 445 | // printf("get_num_tracks = %d\n", num_tracks); |
| 446 | return num_tracks; |
| 447 | } |
| 448 | |
| 449 | bool mess_cdrom_driver::get_track_address(const unsigned int track, unsigned char *address) const |
| 450 | { |
| 451 | if ((track>=1) && ((int)track<=num_tracks)) |
| 452 | { |
| 453 | UINT32 trkstart = cdrom_get_track_start(m_cd, track); |
| 454 | |
| 455 | sector_to_msf(trkstart, address); |
| 456 | |
| 457 | address[0] = address[0]; |
| 458 | address[1] = address[1]; |
| 459 | address[2] = address[2]; |
| 460 | |
| 461 | // printf("get_track_address %d = %02x:%02x:%02x\n", track, address[0], address[1], address[2]); |
| 462 | |
| 463 | return true; |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | address[0]=address[1]=address[2]=0; |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | unsigned int mess_cdrom_driver::find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const |
| 473 | { |
| 474 | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 475 | UINT32 track = cdrom_get_track(m_cd, sector); |
| 476 | int start; |
| 477 | |
| 478 | start = cdrom_get_track_start(m_cd, track); |
| 479 | |
| 480 | if (start_sector != NULL) |
| 481 | { |
| 482 | *start_sector = start; |
| 483 | } |
| 484 | |
| 485 | if (end_sector != NULL) |
| 486 | { |
| 487 | *end_sector = start + toc->tracks[track].frames; |
| 488 | } |
| 489 | |
| 490 | printf("find_track: track %d start %d end %d\n", track, start, *end_sector); |
| 491 | |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | // |
| 496 | // |
| 497 | // |
| 498 | |
| 499 | cdromtype mess_cdrom_driver::get_type() const |
| 500 | { |
| 501 | // printf("get_type\n"); |
| 502 | return cdromtype_cd; |
| 503 | } |
| 504 | |
| 505 | // |
| 506 | // |
| 507 | // |
| 508 | |
| 509 | tracktype mess_cdrom_driver::get_track_type(const unsigned int track) const |
| 510 | { |
| 511 | const cdrom_toc *toc = cdrom_get_toc(m_cd); |
| 512 | |
| 513 | // printf("get_track_type %d = %d\n", track, toc->tracks[track].trktype); |
| 514 | |
| 515 | switch (toc->tracks[track].trktype) |
| 516 | { |
| 517 | case CD_TRACK_MODE1: return tracktype_mode1; |
| 518 | case CD_TRACK_MODE2_RAW: return tracktype_mode2; |
| 519 | case CD_TRACK_MODE2_FORM_MIX: return tracktype_mode2; |
| 520 | case CD_TRACK_AUDIO: return tracktype_audio; |
| 521 | default: return tracktype_unknown; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // |
| 526 | // |
| 527 | // |
| 528 | |
| 529 | cdrom_driver *open_mess_drv() |
| 530 | { |
| 531 | return new mess_cdrom_driver(); |
| 532 | } |
| 533 | |
src/mess/drivers/psx.c
| r0 | r11506 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | Sony Playstaion |
| 4 | =============== |
| 5 | Preliminary driver by smf |
| 6 | Additional development by pSXAuthor and R. Belmont |
| 7 | |
| 8 | ***************************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "cpu/psx/psx.h" |
| 12 | #include "imagedev/snapquik.h" |
| 13 | #include "imagedev/chd_cd.h" |
| 14 | #include "includes/psx.h" |
| 15 | #include "sound/spu.h" |
| 16 | #include "debugger.h" |
| 17 | #include "zlib.h" |
| 18 | #include "machine/psxcd.h" |
| 19 | #include "machine/psxcard.h" |
| 20 | |
| 21 | typedef struct |
| 22 | { |
| 23 | UINT8 n_shiftin; |
| 24 | UINT8 n_shiftout; |
| 25 | int n_bits; |
| 26 | int n_state; |
| 27 | int n_byte; |
| 28 | int b_lastclock; |
| 29 | int b_ack; |
| 30 | } pad_t; |
| 31 | |
| 32 | |
| 33 | class psx1_state : public psx_state |
| 34 | { |
| 35 | public: |
| 36 | psx1_state(const machine_config &mconfig, device_type type, const char *tag) |
| 37 | : psx_state(mconfig, type, tag) { } |
| 38 | |
| 39 | UINT8 *m_exe_buffer; |
| 40 | int m_exe_size; |
| 41 | pad_t m_pad[ 2 ]; |
| 42 | int m_cd_param_p; |
| 43 | int m_cd_result_p; |
| 44 | int m_cd_result_c; |
| 45 | int m_cd_result_ready; |
| 46 | int m_cd_reset; |
| 47 | UINT8 m_cd_stat; |
| 48 | UINT8 m_cd_io_status; |
| 49 | UINT8 m_cd_param[8]; |
| 50 | UINT8 m_cd_result[8]; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | #define VERBOSE_LEVEL ( 0 ) |
| 55 | |
| 56 | INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ... ) |
| 57 | { |
| 58 | if( VERBOSE_LEVEL >= n_level ) |
| 59 | { |
| 60 | va_list v; |
| 61 | char buf[ 32768 ]; |
| 62 | va_start( v, s_fmt ); |
| 63 | vsprintf( buf, s_fmt, v ); |
| 64 | va_end( v ); |
| 65 | logerror( "%s: %s", machine.describe_context(), buf ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | static void psxexe_conv32( UINT32 *p_uint32 ) |
| 71 | { |
| 72 | UINT8 *p_uint8; |
| 73 | |
| 74 | p_uint8 = (UINT8 *)p_uint32; |
| 75 | |
| 76 | *( p_uint32 ) = p_uint8[ 0 ] | |
| 77 | ( p_uint8[ 1 ] << 8 ) | |
| 78 | ( p_uint8[ 2 ] << 16 ) | |
| 79 | ( p_uint8[ 3 ] << 24 ); |
| 80 | } |
| 81 | |
| 82 | static int load_psxexe( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 83 | { |
| 84 | psx_state *state = cpu->machine().driver_data<psx_state>(); |
| 85 | struct PSXEXE_HEADER |
| 86 | { |
| 87 | UINT8 id[ 8 ]; |
| 88 | UINT32 text; /* SCE only */ |
| 89 | UINT32 data; /* SCE only */ |
| 90 | UINT32 pc0; |
| 91 | UINT32 gp0; /* SCE only */ |
| 92 | UINT32 t_addr; |
| 93 | UINT32 t_size; |
| 94 | UINT32 d_addr; /* SCE only */ |
| 95 | UINT32 d_size; /* SCE only */ |
| 96 | UINT32 b_addr; /* SCE only */ |
| 97 | UINT32 b_size; /* SCE only */ |
| 98 | UINT32 s_addr; |
| 99 | UINT32 s_size; |
| 100 | UINT32 SavedSP; |
| 101 | UINT32 SavedFP; |
| 102 | UINT32 SavedGP; |
| 103 | UINT32 SavedRA; |
| 104 | UINT32 SavedS0; |
| 105 | UINT8 dummy[ 0x800 - 76 ]; |
| 106 | }; |
| 107 | |
| 108 | struct PSXEXE_HEADER *psxexe_header = (struct PSXEXE_HEADER *)p_n_file; |
| 109 | |
| 110 | if( n_len >= sizeof( struct PSXEXE_HEADER ) && |
| 111 | memcmp( psxexe_header->id, "PS-X EXE", 8 ) == 0 ) |
| 112 | { |
| 113 | UINT8 *p_ram; |
| 114 | UINT8 *p_psxexe; |
| 115 | UINT32 n_stack; |
| 116 | UINT32 n_ram; |
| 117 | UINT32 n_address; |
| 118 | UINT32 n_size; |
| 119 | |
| 120 | psxexe_conv32( &psxexe_header->text ); |
| 121 | psxexe_conv32( &psxexe_header->data ); |
| 122 | psxexe_conv32( &psxexe_header->pc0 ); |
| 123 | psxexe_conv32( &psxexe_header->gp0 ); |
| 124 | psxexe_conv32( &psxexe_header->t_addr ); |
| 125 | psxexe_conv32( &psxexe_header->t_size ); |
| 126 | psxexe_conv32( &psxexe_header->d_addr ); |
| 127 | psxexe_conv32( &psxexe_header->d_size ); |
| 128 | psxexe_conv32( &psxexe_header->b_addr ); |
| 129 | psxexe_conv32( &psxexe_header->b_size ); |
| 130 | psxexe_conv32( &psxexe_header->s_addr ); |
| 131 | psxexe_conv32( &psxexe_header->s_size ); |
| 132 | psxexe_conv32( &psxexe_header->SavedSP ); |
| 133 | psxexe_conv32( &psxexe_header->SavedFP ); |
| 134 | psxexe_conv32( &psxexe_header->SavedGP ); |
| 135 | psxexe_conv32( &psxexe_header->SavedRA ); |
| 136 | psxexe_conv32( &psxexe_header->SavedS0 ); |
| 137 | |
| 138 | /* todo: check size.. */ |
| 139 | |
| 140 | logerror( "psx_exe_load: pc %08x\n", psxexe_header->pc0 ); |
| 141 | logerror( "psx_exe_load: org %08x\n", psxexe_header->t_addr ); |
| 142 | logerror( "psx_exe_load: len %08x\n", psxexe_header->t_size ); |
| 143 | logerror( "psx_exe_load: sp %08x\n", psxexe_header->s_addr ); |
| 144 | logerror( "psx_exe_load: len %08x\n", psxexe_header->s_size ); |
| 145 | |
| 146 | p_ram = (UINT8 *)state->m_p_n_psxram; |
| 147 | n_ram = state->m_n_psxramsize; |
| 148 | |
| 149 | p_psxexe = p_n_file + sizeof( struct PSXEXE_HEADER ); |
| 150 | |
| 151 | n_address = psxexe_header->t_addr; |
| 152 | n_size = psxexe_header->t_size; |
| 153 | while( n_size != 0 ) |
| 154 | { |
| 155 | p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = *( p_psxexe ); |
| 156 | n_address++; |
| 157 | p_psxexe++; |
| 158 | n_size--; |
| 159 | } |
| 160 | |
| 161 | cpu_set_reg( cpu, PSXCPU_PC, psxexe_header->pc0 ); |
| 162 | cpu_set_reg( cpu, PSXCPU_R28, psxexe_header->gp0 ); |
| 163 | n_stack = psxexe_header->s_addr + psxexe_header->s_size; |
| 164 | if( n_stack != 0 ) |
| 165 | { |
| 166 | cpu_set_reg( cpu, PSXCPU_R29, n_stack ); |
| 167 | cpu_set_reg( cpu, PSXCPU_R30, n_stack ); |
| 168 | } |
| 169 | |
| 170 | return 1; |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static void cpe_set_register( device_t *cpu, int n_reg, int n_value ) |
| 176 | { |
| 177 | if( n_reg < 0x80 && ( n_reg % 4 ) == 0 ) |
| 178 | { |
| 179 | logerror( "psx_exe_load: r%-2d %08x\n", n_reg / 4, n_value ); |
| 180 | cpu_set_reg( cpu, PSXCPU_R0 + ( n_reg / 4 ), n_value ); |
| 181 | } |
| 182 | else if( n_reg == 0x80 ) |
| 183 | { |
| 184 | logerror( "psx_exe_load: lo %08x\n", n_value ); |
| 185 | cpu_set_reg( cpu, PSXCPU_LO, n_value ); |
| 186 | } |
| 187 | else if( n_reg == 0x84 ) |
| 188 | { |
| 189 | logerror( "psx_exe_load: hi %08x\n", n_value ); |
| 190 | cpu_set_reg( cpu, PSXCPU_HI, n_value ); |
| 191 | } |
| 192 | else if( n_reg == 0x88 ) |
| 193 | { |
| 194 | logerror( "psx_exe_load: sr %08x\n", n_value ); |
| 195 | cpu_set_reg( cpu, PSXCPU_CP0R12, n_value ); |
| 196 | } |
| 197 | else if( n_reg == 0x8c ) |
| 198 | { |
| 199 | logerror( "psx_exe_load: cause %08x\n", n_value ); |
| 200 | cpu_set_reg( cpu, PSXCPU_CP0R13, n_value ); |
| 201 | } |
| 202 | else if( n_reg == 0x90 ) |
| 203 | { |
| 204 | logerror( "psx_exe_load: pc %08x\n", n_value ); |
| 205 | cpu_set_reg( cpu, PSXCPU_PC, n_value ); |
| 206 | } |
| 207 | else if( n_reg == 0x94 ) |
| 208 | { |
| 209 | logerror( "psx_exe_load: prid %08x\n", n_value ); |
| 210 | cpu_set_reg( cpu, PSXCPU_CP0R15, n_value ); |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | logerror( "psx_exe_load: invalid register %04x/%08x\n", n_reg, n_value ); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static int load_cpe( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 219 | { |
| 220 | psx_state *state = cpu->machine().driver_data<psx_state>(); |
| 221 | if( n_len >= 4 && |
| 222 | memcmp( p_n_file, "CPE\001", 4 ) == 0 ) |
| 223 | { |
| 224 | int n_offset = 4; |
| 225 | |
| 226 | for( ;; ) |
| 227 | { |
| 228 | if( n_offset >= n_len || p_n_file[ n_offset ] > 8 ) |
| 229 | { |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | switch( p_n_file[ n_offset++ ] ) |
| 234 | { |
| 235 | case 0: |
| 236 | /* end of file */ |
| 237 | return 1; |
| 238 | case 1: |
| 239 | /* read bytes */ |
| 240 | { |
| 241 | int n_address = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 242 | ( (int)p_n_file[ n_offset + 1 ] << 8 ) | |
| 243 | ( (int)p_n_file[ n_offset + 2 ] << 16 ) | |
| 244 | ( (int)p_n_file[ n_offset + 3 ] << 24 ); |
| 245 | int n_size = ( (int)p_n_file[ n_offset + 4 ] << 0 ) | |
| 246 | ( (int)p_n_file[ n_offset + 5 ] << 8 ) | |
| 247 | ( (int)p_n_file[ n_offset + 6 ] << 16 ) | |
| 248 | ( (int)p_n_file[ n_offset + 7 ] << 24 ); |
| 249 | |
| 250 | UINT8 *p_ram = (UINT8 *)state->m_p_n_psxram; |
| 251 | UINT32 n_ram = state->m_n_psxramsize; |
| 252 | |
| 253 | n_offset += 8; |
| 254 | |
| 255 | logerror( "psx_exe_load: org %08x\n", n_address ); |
| 256 | logerror( "psx_exe_load: len %08x\n", n_size ); |
| 257 | |
| 258 | while( n_size > 0 ) |
| 259 | { |
| 260 | p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = p_n_file[ n_offset++ ]; |
| 261 | n_address++; |
| 262 | n_size--; |
| 263 | } |
| 264 | break; |
| 265 | } |
| 266 | case 2: |
| 267 | /* run address: not tested */ |
| 268 | { |
| 269 | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 270 | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 271 | ( (int)p_n_file[ n_offset + 4 ] << 16 ) | |
| 272 | ( (int)p_n_file[ n_offset + 5 ] << 24 ); |
| 273 | |
| 274 | n_offset += 4; |
| 275 | |
| 276 | cpe_set_register( cpu, 0x90, n_value ); |
| 277 | break; |
| 278 | } |
| 279 | case 3: |
| 280 | /* set reg to longword */ |
| 281 | { |
| 282 | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 283 | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 284 | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 285 | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 286 | ( (int)p_n_file[ n_offset + 4 ] << 16 ) | |
| 287 | ( (int)p_n_file[ n_offset + 5 ] << 24 ); |
| 288 | |
| 289 | n_offset += 6; |
| 290 | |
| 291 | cpe_set_register( cpu, n_reg, n_value ); |
| 292 | break; |
| 293 | } |
| 294 | case 4: |
| 295 | /* set reg to word: not tested */ |
| 296 | { |
| 297 | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 298 | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 299 | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 300 | ( (int)p_n_file[ n_offset + 3 ] << 8 ); |
| 301 | |
| 302 | n_offset += 4; |
| 303 | |
| 304 | cpe_set_register( cpu, n_reg, n_value ); |
| 305 | break; |
| 306 | } |
| 307 | case 5: |
| 308 | /* set reg to byte: not tested */ |
| 309 | { |
| 310 | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 311 | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 312 | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ); |
| 313 | |
| 314 | n_offset += 3; |
| 315 | |
| 316 | cpe_set_register( cpu, n_reg, n_value ); |
| 317 | break; |
| 318 | } |
| 319 | case 6: |
| 320 | /* set reg to 3-byte: not tested */ |
| 321 | { |
| 322 | int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) | |
| 323 | ( (int)p_n_file[ n_offset + 1 ] << 8 ); |
| 324 | int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) | |
| 325 | ( (int)p_n_file[ n_offset + 3 ] << 8 ) | |
| 326 | ( (int)p_n_file[ n_offset + 4 ] << 16 ); |
| 327 | |
| 328 | n_offset += 5; |
| 329 | |
| 330 | cpe_set_register( cpu, n_reg, n_value ); |
| 331 | break; |
| 332 | } |
| 333 | case 7: |
| 334 | /* workspace: not tested */ |
| 335 | n_offset += 4; |
| 336 | break; |
| 337 | case 8: |
| 338 | /* unit */ |
| 339 | { |
| 340 | int n_unit = p_n_file[ n_offset + 0 ]; |
| 341 | |
| 342 | n_offset++; |
| 343 | |
| 344 | logerror( "psx_exe_load: unit %08x\n", n_unit ); |
| 345 | } |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int load_psf( device_t *cpu, unsigned char *p_n_file, int n_len ) |
| 354 | { |
| 355 | int n_return; |
| 356 | unsigned long n_crc; |
| 357 | unsigned long n_compressed; |
| 358 | unsigned char *p_n_compressed; |
| 359 | unsigned long n_uncompressed; |
| 360 | unsigned char *p_n_uncompressed; |
| 361 | |
| 362 | struct PSF_HEADER |
| 363 | { |
| 364 | unsigned char id[ 4 ]; |
| 365 | UINT32 reserved_size; |
| 366 | UINT32 exe_size; |
| 367 | UINT32 exe_crc; |
| 368 | }; |
| 369 | |
| 370 | struct PSF_HEADER *psf_header = (struct PSF_HEADER *)p_n_file; |
| 371 | |
| 372 | n_return = 0; |
| 373 | |
| 374 | if( n_len >= sizeof( struct PSF_HEADER ) && |
| 375 | memcmp( p_n_file, "PSF", 3 ) == 0 ) |
| 376 | { |
| 377 | psxexe_conv32( &psf_header->reserved_size ); |
| 378 | psxexe_conv32( &psf_header->exe_size ); |
| 379 | psxexe_conv32( &psf_header->exe_crc ); |
| 380 | |
| 381 | logerror( "psx_exe_load: reserved_size %08x\n", psf_header->reserved_size ); |
| 382 | logerror( "psx_exe_load: exe_size %08x\n", psf_header->exe_size ); |
| 383 | logerror( "psx_exe_load: exe_crc %08x\n", psf_header->exe_crc ); |
| 384 | |
| 385 | n_compressed = psf_header->exe_size; |
| 386 | p_n_compressed = p_n_file + sizeof( struct PSF_HEADER ) + psf_header->reserved_size; |
| 387 | |
| 388 | n_crc = crc32( crc32( 0L, Z_NULL, 0 ), p_n_compressed, n_compressed ); |
| 389 | if( n_crc != psf_header->exe_crc ) |
| 390 | { |
| 391 | logerror( "psx_exe_load: psf invalid crc\n" ); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | n_uncompressed = 0x200000; |
| 396 | p_n_uncompressed = (unsigned char *)malloc( n_uncompressed ); |
| 397 | |
| 398 | if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK ) |
| 399 | { |
| 400 | logerror( "psx_exe_load: psf uncompress failed\n" ); |
| 401 | } |
| 402 | else if( !load_psxexe( cpu, p_n_uncompressed, n_uncompressed ) ) |
| 403 | { |
| 404 | logerror( "psx_exe_load: psf load failed\n" ); |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | n_return = 1; |
| 409 | } |
| 410 | |
| 411 | free( p_n_uncompressed ); |
| 412 | } |
| 413 | return n_return; |
| 414 | } |
| 415 | |
| 416 | DIRECT_UPDATE_HANDLER( psx_default ) |
| 417 | { |
| 418 | return address; |
| 419 | } |
| 420 | |
| 421 | DIRECT_UPDATE_HANDLER( psx_setopbase ) |
| 422 | { |
| 423 | psx1_state *state = machine.driver_data<psx1_state>(); |
| 424 | if( address == 0x80030000 ) |
| 425 | { |
| 426 | device_t *cpu = machine.device("maincpu"); |
| 427 | |
| 428 | machine.device("maincpu")->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate(FUNC(psx_default), &machine)); |
| 429 | |
| 430 | if( load_psxexe( cpu, state->m_exe_buffer, state->m_exe_size ) || |
| 431 | load_cpe( cpu, state->m_exe_buffer, state->m_exe_size ) || |
| 432 | load_psf( cpu, state->m_exe_buffer, state->m_exe_size ) ) |
| 433 | { |
| 434 | /* DEBUGGER_BREAK; */ |
| 435 | |
| 436 | address = cpu_get_reg( cpu, PSXCPU_PC ); |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | logerror( "psx_exe_load: invalid exe\n" ); |
| 441 | } |
| 442 | |
| 443 | state->m_exe_size = 0; |
| 444 | free( state->m_exe_buffer ); |
| 445 | } |
| 446 | return address; |
| 447 | } |
| 448 | |
| 449 | static QUICKLOAD_LOAD( psx_exe_load ) |
| 450 | { |
| 451 | psx1_state *state = image.device().machine().driver_data<psx1_state>(); |
| 452 | address_space *space = image.device().machine().device( "maincpu")->memory().space( AS_PROGRAM ); |
| 453 | |
| 454 | state->m_exe_size = 0; |
| 455 | state->m_exe_buffer = (UINT8*)malloc( quickload_size ); |
| 456 | if( state->m_exe_buffer == NULL ) |
| 457 | { |
| 458 | logerror( "psx_exe_load: out of memory\n" ); |
| 459 | return IMAGE_INIT_FAIL; |
| 460 | } |
| 461 | if( image.fread( state->m_exe_buffer, quickload_size ) != quickload_size ) |
| 462 | { |
| 463 | free( state->m_exe_buffer ); |
| 464 | return IMAGE_INIT_FAIL; |
| 465 | } |
| 466 | state->m_exe_size = quickload_size; |
| 467 | space->set_direct_update_handler(direct_update_delegate(FUNC(psx_setopbase), &image.device().machine())); |
| 468 | |
| 469 | return IMAGE_INIT_PASS; |
| 470 | } |
| 471 | |
| 472 | /* PAD emulation */ |
| 473 | |
| 474 | #define PAD_STATE_IDLE ( 0 ) |
| 475 | #define PAD_STATE_LISTEN ( 1 ) |
| 476 | #define PAD_STATE_ACTIVE ( 2 ) |
| 477 | #define PAD_STATE_READ ( 3 ) |
| 478 | #define PAD_STATE_UNLISTEN ( 4 ) |
| 479 | #define PAD_STATE_MEMCARD ( 5 ) |
| 480 | |
| 481 | #define PAD_TYPE_STANDARD ( 4 ) |
| 482 | #define PAD_BYTES_STANDARD ( 2 ) |
| 483 | |
| 484 | #define PAD_CMD_START ( 0x01 ) |
| 485 | #define PAD_CMD_READ ( 0x42 ) /* B */ |
| 486 | |
| 487 | #define PAD_DATA_OK ( 0x5a ) /* Z */ |
| 488 | #define PAD_DATA_IDLE ( 0xff ) |
| 489 | |
| 490 | static TIMER_CALLBACK(psx_pad_ack) |
| 491 | { |
| 492 | psx1_state *state = machine.driver_data<psx1_state>(); |
| 493 | int n_port = param; |
| 494 | pad_t *pad = &state->m_pad[ n_port ]; |
| 495 | |
| 496 | if( pad->n_state != PAD_STATE_IDLE ) |
| 497 | { |
| 498 | psx_sio_input( machine, 0, PSX_SIO_IN_DSR, pad->b_ack * PSX_SIO_IN_DSR ); |
| 499 | if( !pad->b_ack ) |
| 500 | { |
| 501 | pad->b_ack = 1; |
| 502 | machine.scheduler().timer_set(attotime::from_usec( 2 ), FUNC(psx_pad_ack) , n_port); |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static void psx_pad( running_machine &machine, int n_port, int n_data ) |
| 508 | { |
| 509 | psx1_state *state = machine.driver_data<psx1_state>(); |
| 510 | pad_t *pad = &state->m_pad[ n_port ]; |
| 511 | int b_sel; |
| 512 | int b_clock; |
| 513 | int b_data; |
| 514 | int b_ack; |
| 515 | int b_ready; |
| 516 | static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" }; |
| 517 | psxcard_device *psxcard = NULL; |
| 518 | |
| 519 | if (n_port == 0) |
| 520 | { |
| 521 | psxcard = machine.device<psxcard_device>("card1"); |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | psxcard = machine.device<psxcard_device>("card2"); |
| 526 | } |
| 527 | |
| 528 | b_sel = ( n_data & PSX_SIO_OUT_DTR ) / PSX_SIO_OUT_DTR; |
| 529 | b_clock = ( n_data & PSX_SIO_OUT_CLOCK ) / PSX_SIO_OUT_CLOCK; |
| 530 | b_data = ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA; |
| 531 | b_ready = 0; |
| 532 | b_ack = 0; |
| 533 | |
| 534 | if( b_sel ) |
| 535 | { |
| 536 | pad->n_state = PAD_STATE_IDLE; |
| 537 | } |
| 538 | |
| 539 | switch( pad->n_state ) |
| 540 | { |
| 541 | case PAD_STATE_LISTEN: |
| 542 | case PAD_STATE_ACTIVE: |
| 543 | case PAD_STATE_READ: |
| 544 | case PAD_STATE_MEMCARD: |
| 545 | if( pad->b_lastclock && !b_clock ) |
| 546 | { |
| 547 | psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( pad->n_shiftout & 1 ) * PSX_SIO_IN_DATA ); |
| 548 | pad->n_shiftout >>= 1; |
| 549 | } |
| 550 | if( !pad->b_lastclock && b_clock ) |
| 551 | { |
| 552 | pad->n_shiftin >>= 1; |
| 553 | pad->n_shiftin |= b_data << 7; |
| 554 | pad->n_bits++; |
| 555 | |
| 556 | if( pad->n_bits == 8 ) |
| 557 | { |
| 558 | pad->n_bits = 0; |
| 559 | b_ready = 1; |
| 560 | } |
| 561 | } |
| 562 | break; |
| 563 | } |
| 564 | |
| 565 | pad->b_lastclock = b_clock; |
| 566 | |
| 567 | switch( pad->n_state ) |
| 568 | { |
| 569 | case PAD_STATE_IDLE: |
| 570 | if( !b_sel ) |
| 571 | { |
| 572 | pad->n_state = PAD_STATE_LISTEN; |
| 573 | pad->n_shiftout = PAD_DATA_IDLE; |
| 574 | pad->n_bits = 0; |
| 575 | } |
| 576 | break; |
| 577 | case PAD_STATE_LISTEN: |
| 578 | if( b_ready ) |
| 579 | { |
| 580 | if( pad->n_shiftin == PAD_CMD_START ) |
| 581 | { |
| 582 | pad->n_state = PAD_STATE_ACTIVE; |
| 583 | pad->n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 ); |
| 584 | b_ack = 1; |
| 585 | } |
| 586 | else if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) ) |
| 587 | { |
| 588 | pad->n_state = PAD_STATE_MEMCARD; |
| 589 | b_ack = 1; |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | pad->n_state = PAD_STATE_UNLISTEN; |
| 594 | } |
| 595 | } |
| 596 | break; |
| 597 | case PAD_STATE_MEMCARD: |
| 598 | if( b_ready ) |
| 599 | { |
| 600 | if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) ) |
| 601 | { |
| 602 | b_ack = 1; |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | b_ack = 0; |
| 607 | pad->n_state = PAD_STATE_IDLE; |
| 608 | } |
| 609 | } |
| 610 | break; |
| 611 | case PAD_STATE_ACTIVE: |
| 612 | if( b_ready ) |
| 613 | { |
| 614 | if( pad->n_shiftin == PAD_CMD_READ ) |
| 615 | { |
| 616 | pad->n_state = PAD_STATE_READ; |
| 617 | pad->n_shiftout = PAD_DATA_OK; |
| 618 | pad->n_byte = 0; |
| 619 | b_ack = 1; |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | pad->n_state = PAD_STATE_UNLISTEN; |
| 624 | } |
| 625 | } |
| 626 | break; |
| 627 | case PAD_STATE_READ: |
| 628 | if( b_ready ) |
| 629 | { |
| 630 | if( pad->n_byte < PAD_BYTES_STANDARD ) |
| 631 | { |
| 632 | pad->n_shiftout = input_port_read(machine, portnames[pad->n_byte + ( n_port * PAD_BYTES_STANDARD )]); |
| 633 | pad->n_byte++; |
| 634 | b_ack = 1; |
| 635 | } |
| 636 | else |
| 637 | { |
| 638 | pad->n_state = PAD_STATE_LISTEN; |
| 639 | } |
| 640 | } |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | if( b_ack ) |
| 645 | { |
| 646 | pad->b_ack = 0; |
| 647 | machine.scheduler().timer_set(attotime::from_usec( 10 ), FUNC(psx_pad_ack), n_port); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | static void psx_sio0( running_machine &machine, int n_data ) |
| 652 | { |
| 653 | /* todo: raise data & ack when nothing is driving it low */ |
| 654 | psx_pad( machine, 0, n_data ); |
| 655 | psx_pad( machine, 1, n_data ^ PSX_SIO_OUT_DTR ); |
| 656 | } |
| 657 | |
| 658 | /* ----------------------------------------------------------------------- */ |
| 659 | |
| 660 | static void cd_dma_read( psxcd_device *psxcd, UINT32 n_address, INT32 n_size ) |
| 661 | { |
| 662 | UINT8 *psxram = (UINT8 *)memory_get_shared(psxcd->machine(), "share1"); |
| 663 | |
| 664 | psxcd->start_dma(psxram + n_address, n_size*4); |
| 665 | } |
| 666 | |
| 667 | static void cd_dma_write( psxcd_device *psxcd, UINT32 n_address, INT32 n_size ) |
| 668 | { |
| 669 | printf("cd_dma_write?!: addr %x, size %x\n", n_address, n_size); |
| 670 | } |
| 671 | |
| 672 | static READ8_HANDLER( psx_cd_r ) |
| 673 | { |
| 674 | psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG); |
| 675 | |
| 676 | return psxcd->read_byte(offset); |
| 677 | } |
| 678 | |
| 679 | static WRITE8_HANDLER( psx_cd_w ) |
| 680 | { |
| 681 | psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG); |
| 682 | |
| 683 | psxcd->write_byte(offset, data); |
| 684 | } |
| 685 | |
| 686 | static ADDRESS_MAP_START( psx_map, AS_PROGRAM, 32 ) |
| 687 | AM_RANGE(0x00000000, 0x001fffff) AM_RAM AM_SHARE("share1") /* ram */ |
| 688 | AM_RANGE(0x1f801800, 0x1f801803) AM_READWRITE8(psx_cd_r, psx_cd_w, 0xffffffff) |
| 689 | AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */ |
| 690 | AM_RANGE(0x80000000, 0x801fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 691 | AM_RANGE(0x80600000, 0x807fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 692 | AM_RANGE(0x9fc00000, 0x9fc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */ |
| 693 | AM_RANGE(0xa0000000, 0xa01fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ |
| 694 | AM_RANGE(0xbfc00000, 0xbfc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */ |
| 695 | AM_RANGE(0xfffe0130, 0xfffe0133) AM_WRITENOP |
| 696 | ADDRESS_MAP_END |
| 697 | |
| 698 | |
| 699 | static MACHINE_RESET( psx ) |
| 700 | { |
| 701 | psx_machine_init(machine); |
| 702 | psx_sio_install_handler( machine, 0, psx_sio0 ); |
| 703 | |
| 704 | psx_dma_install_read_handler(machine, 3, psx_dma_read_delegate(FUNC(cd_dma_read),machine.device<psxcd_device>("psxcd"))); |
| 705 | psx_dma_install_write_handler(machine, 3, psx_dma_write_delegate(FUNC(cd_dma_write),machine.device<psxcd_device>("psxcd"))); |
| 706 | } |
| 707 | |
| 708 | static DRIVER_INIT( psx ) |
| 709 | { |
| 710 | psx_driver_init(machine); |
| 711 | } |
| 712 | |
| 713 | static INPUT_PORTS_START( psx ) |
| 714 | PORT_START("IN0") |
| 715 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) |
| 716 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) |
| 717 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) |
| 718 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) |
| 719 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1) |
| 720 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1) |
| 721 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1) |
| 722 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(1) |
| 723 | |
| 724 | PORT_START("IN1") |
| 725 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Square") |
| 726 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Cross") |
| 727 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Circle") |
| 728 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 Triangle") |
| 729 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 R1") |
| 730 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 L1") |
| 731 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 R2") |
| 732 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 L2") |
| 733 | |
| 734 | PORT_START("IN2") |
| 735 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) |
| 736 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) |
| 737 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) |
| 738 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) |
| 739 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2) |
| 740 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) |
| 741 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) |
| 742 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(2) |
| 743 | |
| 744 | PORT_START("IN3") |
| 745 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Square") |
| 746 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Cross") |
| 747 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Circle") |
| 748 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 Triangle") |
| 749 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 R1") |
| 750 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 L1") |
| 751 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 R2") |
| 752 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 L2") |
| 753 | INPUT_PORTS_END |
| 754 | |
| 755 | static void spu_irq(device_t *device, UINT32 data) |
| 756 | { |
| 757 | if (data) |
| 758 | { |
| 759 | psx_irq_set(device->machine(), 1<<9); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | static MACHINE_CONFIG_START( psxntsc, psx1_state ) |
| 764 | /* basic machine hardware */ |
| 765 | MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz ) |
| 766 | MCFG_CPU_PROGRAM_MAP( psx_map) |
| 767 | MCFG_CPU_VBLANK_INT("screen", psx_vblank) |
| 768 | |
| 769 | MCFG_SCREEN_ADD("screen", RASTER) |
| 770 | MCFG_SCREEN_REFRESH_RATE( 60 ) |
| 771 | MCFG_SCREEN_VBLANK_TIME(0) |
| 772 | |
| 773 | MCFG_MACHINE_RESET( psx ) |
| 774 | |
| 775 | /* video hardware */ |
| 776 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 777 | MCFG_SCREEN_SIZE( 1024, 512 ) |
| 778 | MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 479 ) |
| 779 | MCFG_SCREEN_UPDATE( psx ) |
| 780 | |
| 781 | MCFG_PALETTE_LENGTH( 65536 ) |
| 782 | |
| 783 | MCFG_PALETTE_INIT( psx ) |
| 784 | MCFG_VIDEO_START( psx_type2 ) |
| 785 | |
| 786 | /* sound hardware */ |
| 787 | MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 788 | MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq ) |
| 789 | MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 ) |
| 790 | MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 ) |
| 791 | |
| 792 | /* quickload */ |
| 793 | MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0) |
| 794 | |
| 795 | MCFG_CDROM_ADD("cdrom") |
| 796 | MCFG_PSXCD_ADD("cdrom") |
| 797 | MCFG_PSXCARD_ADD("card1") |
| 798 | MCFG_PSXCARD_ADD("card2") |
| 799 | MACHINE_CONFIG_END |
| 800 | |
| 801 | static MACHINE_CONFIG_START( psxpal, psx1_state ) |
| 802 | /* basic machine hardware */ |
| 803 | MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz ) |
| 804 | MCFG_CPU_PROGRAM_MAP( psx_map) |
| 805 | MCFG_CPU_VBLANK_INT("screen", psx_vblank) |
| 806 | |
| 807 | MCFG_SCREEN_ADD("screen", RASTER) |
| 808 | MCFG_SCREEN_REFRESH_RATE( 50 ) |
| 809 | MCFG_SCREEN_VBLANK_TIME(0) |
| 810 | |
| 811 | MCFG_MACHINE_RESET( psx ) |
| 812 | |
| 813 | /* video hardware */ |
| 814 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 815 | MCFG_SCREEN_SIZE( 1024, 512 ) |
| 816 | MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 511 ) |
| 817 | MCFG_SCREEN_UPDATE( psx ) |
| 818 | MCFG_PALETTE_LENGTH( 65536 ) |
| 819 | |
| 820 | MCFG_PALETTE_INIT( psx ) |
| 821 | MCFG_VIDEO_START( psx_type2 ) |
| 822 | |
| 823 | /* sound hardware */ |
| 824 | MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 825 | MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq ) |
| 826 | MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 ) |
| 827 | MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 ) |
| 828 | |
| 829 | /* quickload */ |
| 830 | MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0) |
| 831 | |
| 832 | MCFG_CDROM_ADD("cdrom") |
| 833 | MCFG_PSXCD_ADD("cdrom") |
| 834 | MCFG_PSXCARD_ADD("card1") |
| 835 | MCFG_PSXCARD_ADD("card2") |
| 836 | MACHINE_CONFIG_END |
| 837 | |
| 838 | ROM_START( psj ) |
| 839 | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 840 | |
| 841 | ROM_SYSTEM_BIOS( 0, "1.0J", "SCPH-1000/DTL-H1000" ) // 22091994 |
| 842 | ROMX_LOAD( "ps-10j.bin", 0x0000000, 0x080000, CRC(3b601fc8) SHA1(343883a7b555646da8cee54aadd2795b6e7dd070), ROM_BIOS(1) ) |
| 843 | |
| 844 | ROM_SYSTEM_BIOS( 1, "1.1J", "SCPH-3000/DTL-H1000H (Version 1.1 01/22/95)" ) // 22091994 |
| 845 | ROMX_LOAD( "ps-11j.bin", 0x0000000, 0x080000, CRC(3539def6) SHA1(b06f4a861f74270be819aa2a07db8d0563a7cc4e), ROM_BIOS(2) ) |
| 846 | |
| 847 | ROM_SYSTEM_BIOS( 2, "2.1J", "SCPH-3500 (Version 2.1 07/17/95 J)" ) // 22091994 |
| 848 | ROMX_LOAD( "ps-21j.bin", 0x0000000, 0x080000, CRC(bc190209) SHA1(e38466a4ba8005fba7e9e3c7b9efeba7205bee3f), ROM_BIOS(3) ) |
| 849 | |
| 850 | ROM_SYSTEM_BIOS( 3, "2.2J", "SCPH-5000/DTL-H1200 (Version 2.2 12/04/95 J)" ) // 04121995 |
| 851 | /* ROMX_LOAD( "ps-22j.bad", 0x0000000, 0x080000, BAD_DUMP CRC(8c93a399) SHA1(e340db2696274dda5fdc25e434a914db71e8b02b), ROM_BIOS(4) ) */ |
| 852 | ROMX_LOAD( "ps-22j.bin", 0x0000000, 0x080000, CRC(24fc7e17) SHA1(ffa7f9a7fb19d773a0c3985a541c8e5623d2c30d), ROM_BIOS(4) ) |
| 853 | |
| 854 | ROM_SYSTEM_BIOS( 4, "2.2D", "DTL-H1100 (Version 2.2 03/06/96 D)" ) // 04121995 |
| 855 | ROMX_LOAD( "ps-22d.bin", 0x0000000, 0x080000, CRC(decb22f5) SHA1(73107d468fc7cb1d2c5b18b269715dd889ecef06), ROM_BIOS(5) ) |
| 856 | |
| 857 | ROM_SYSTEM_BIOS( 5, "3.0J", "SCPH-5500 (Version 3.0 09/09/96 J)" ) // 04121995 |
| 858 | ROMX_LOAD( "ps-30j.bin", 0x0000000, 0x080000, CRC(ff3eeb8c) SHA1(b05def971d8ec59f346f2d9ac21fb742e3eb6917), ROM_BIOS(6) ) |
| 859 | |
| 860 | ROM_SYSTEM_BIOS( 6, "4.0J", "SCPH-7000/SCPH-9000 (Version 4.0 08/18/97 J)" ) // 29051997 |
| 861 | ROMX_LOAD( "ps-40j.bin", 0x0000000, 0x080000, CRC(ec541cd0) SHA1(77b10118d21ac7ffa9b35f9c4fd814da240eb3e9), ROM_BIOS(7) ) |
| 862 | |
| 863 | ROM_SYSTEM_BIOS( 7, "4.3J", "SCPH-100 (Version 4.3 03/11/00 J)" ) // 04121995 |
| 864 | ROMX_LOAD( "psone-43j.bin", 0x0000000, 0x080000, CRC(f2af798b) SHA1(339a48f4fcf63e10b5b867b8c93cfd40945faf6c), ROM_BIOS(8) ) |
| 865 | ROM_END |
| 866 | |
| 867 | ROM_START( psu ) |
| 868 | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 869 | |
| 870 | ROM_SYSTEM_BIOS( 0, "2.0A", "DTL-H1001 (Version 2.0 05/07/95 A)" ) // 22091994 |
| 871 | ROMX_LOAD( "ps-20a.bin", 0x0000000, 0x080000, CRC(55847d8c) SHA1(649895efd79d14790eabb362e94eb0622093dfb9), ROM_BIOS(1) ) |
| 872 | |
| 873 | ROM_SYSTEM_BIOS( 1, "2.1A", "DTL-H1101 (Version 2.1 07/17/95 A)" ) // 22091994 |
| 874 | ROMX_LOAD( "ps-21a.bin", 0x0000000, 0x080000, CRC(aff00f2f) SHA1(ca7af30b50d9756cbd764640126c454cff658479), ROM_BIOS(2) ) |
| 875 | |
| 876 | ROM_SYSTEM_BIOS( 2, "2.2A", "SCPH-1001/DTL-H1201/DTL-H3001 (Version 2.2 12/04/95 A)" ) // 04121995 |
| 877 | ROMX_LOAD( "ps-22a.bin", 0x0000000, 0x080000, CRC(37157331) SHA1(10155d8d6e6e832d6ea66db9bc098321fb5e8ebf), ROM_BIOS(3) ) |
| 878 | |
| 879 | ROM_SYSTEM_BIOS( 3, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995 |
| 880 | ROMX_LOAD( "ps-30a.bin", 0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(4) ) |
| 881 | |
| 882 | ROM_SYSTEM_BIOS( 4, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995 |
| 883 | ROMX_LOAD( "ps-41a.bin", 0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(5) ) |
| 884 | |
| 885 | ROM_SYSTEM_BIOS( 5, "4.5A", "SCPH-101 (Version 4.5 05/25/00 A)" ) // 04121995 |
| 886 | ROMX_LOAD( "psone-45a.bin", 0x0000000, 0x080000, CRC(171bdcec) SHA1(dcffe16bd90a723499ad46c641424981338d8378), ROM_BIOS(6) ) |
| 887 | ROM_END |
| 888 | |
| 889 | ROM_START( pse ) |
| 890 | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 891 | |
| 892 | ROM_SYSTEM_BIOS( 0, "2.0E", "DTL-H1002/SCPH-1002 (Version 2.0 05/10/95 E)" ) // 22091994 |
| 893 | ROMX_LOAD( "ps-20e.bin", 0x0000000, 0x080000, CRC(9bb87c4b) SHA1(20b98f3d80f11cbf5a7bfd0779b0e63760ecc62c), ROM_BIOS(1) ) |
| 894 | |
| 895 | ROM_SYSTEM_BIOS( 1, "2.1E", "SCPH-1002/DTL-H1102 (Version 2.1 07/17/95 E)" ) // 22091994 |
| 896 | ROMX_LOAD( "ps-21e.bin", 0x0000000, 0x080000, CRC(86c30531) SHA1(76cf6b1b2a7c571a6ad07f2bac0db6cd8f71e2cc), ROM_BIOS(2) ) |
| 897 | |
| 898 | ROM_SYSTEM_BIOS( 2, "2.2E", "SCPH-1002/DTL-H1202/DTL-H3002 (Version 2.2 12/04/95 E)" ) // 04121995 |
| 899 | ROMX_LOAD( "ps-22e.bin", 0x0000000, 0x080000, CRC(1e26792f) SHA1(b6a11579caef3875504fcf3831b8e3922746df2c), ROM_BIOS(3) ) |
| 900 | |
| 901 | ROM_SYSTEM_BIOS( 3, "3.0E", "SCPH-5502/SCPH-5552 (Version 3.0 01/06/97 E)" ) // 04121995 |
| 902 | /* ROMX_LOAD( "ps-30e.bad", 0x0000000, 0x080000, BAD_DUMP CRC(4d9e7c86) SHA1(f8de9325fc36fcfa4b29124d291c9251094f2e54), ROM_BIOS(4) ) */ |
| 903 | ROMX_LOAD( "ps-30e.bin", 0x0000000, 0x080000, CRC(d786f0b9) SHA1(f6bc2d1f5eb6593de7d089c425ac681d6fffd3f0), ROM_BIOS(4) ) |
| 904 | |
| 905 | ROM_SYSTEM_BIOS( 4, "4.1E", "SCPH-7002/SCPH-7502/SCPH-9002 (Version 4.1 12/16/97 E)" ) // 04121995 |
| 906 | ROMX_LOAD( "ps-41e.bin", 0x0000000, 0x080000, CRC(318178bf) SHA1(8d5de56a79954f29e9006929ba3fed9b6a418c1d), ROM_BIOS(5) ) |
| 907 | |
| 908 | ROM_SYSTEM_BIOS( 5, "4.4E", "SCPH-102 (Version 4.4 03/24/00 E)" ) // 04121995 |
| 909 | ROMX_LOAD( "psone-44e.bin", 0x0000000, 0x080000, CRC(0bad7ea9) SHA1(beb0ac693c0dc26daf5665b3314db81480fa5c7c), ROM_BIOS(6) ) |
| 910 | |
| 911 | ROM_SYSTEM_BIOS( 6, "4.5E", "SCPH-102 (Version 4.5 05/25/00 E)" ) // 04121995 |
| 912 | ROMX_LOAD( "psone-45e.bin", 0x0000000, 0x080000, CRC(76b880e5) SHA1(dbc7339e5d85827c095764fc077b41f78fd2ecae), ROM_BIOS(7) ) |
| 913 | ROM_END |
| 914 | |
| 915 | ROM_START( psa ) |
| 916 | ROM_REGION32_LE( 0x080000, "user1", 0 ) |
| 917 | |
| 918 | ROM_SYSTEM_BIOS( 0, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995 |
| 919 | ROMX_LOAD( "ps-30a.bin", 0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(1) ) |
| 920 | |
| 921 | ROM_SYSTEM_BIOS( 1, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995 |
| 922 | ROMX_LOAD( "ps-41a.bin", 0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(2) ) |
| 923 | ROM_END |
| 924 | |
| 925 | /* |
| 926 | The version number & release date is stored in ascii text at the end of every bios, except for scph1000. |
| 927 | There is also a BCD encoded date at offset 0x100, but this is set to 22091994 for versions prior to 2.2 |
| 928 | and 04121995 for all versions from 2.2 ( except Version 4.0J which is 29051997 ). |
| 929 | |
| 930 | Consoles not dumped: |
| 931 | |
| 932 | DTL-H1001H |
| 933 | DTL-H3000 |
| 934 | SCPH-5001 |
| 935 | SCPH-5002 |
| 936 | SCPH-5003 |
| 937 | SCPH-5503 |
| 938 | SCPH-7500 |
| 939 | SCPH-9003 |
| 940 | SCPH-103 |
| 941 | |
| 942 | Holes in version numbers: |
| 943 | |
| 944 | Version 2.0 J |
| 945 | Version 4.1 J |
| 946 | Version 4.2 J |
| 947 | Version 4.4 J |
| 948 | Version 4.5 J |
| 949 | Version 4.0 A |
| 950 | Version 4.2 A |
| 951 | Version 4.3 A |
| 952 | Version 4.4 A |
| 953 | Version 4.0 E |
| 954 | Version 4.2 E |
| 955 | Version 4.3 E |
| 956 | |
| 957 | */ |
| 958 | |
| 959 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME FLAGS */ |
| 960 | CONS( 1994, psj, 0, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Japan)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 961 | CONS( 1995, pse, psj, 0, psxpal, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Europe)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 962 | CONS( 1995, psu, psj, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (USA)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 963 | CONS( 1995, psa, psj, 0, psxntsc, psx, psx, "Sony Computer Entertainment Inc", "Sony PlayStation (Asia-Pacific)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) |