src/mame/machine/smpc.c
| r12482 | r12483 | |
| 153 | 153 | #include "machine/eeprom.h" |
| 154 | 154 | |
| 155 | 155 | #define LOG_SMPC 0 |
| 156 | #define LOG_PAD_CMD 0 |
| 156 | 157 | |
| 157 | 158 | READ8_HANDLER( stv_SMPC_r ) |
| 158 | 159 | { |
| r12482 | r12483 | |
| 262 | 263 | /* TODO: VDP1 / VDP2 / SCU / SCSP default power ON values */ |
| 263 | 264 | } |
| 264 | 265 | |
| 265 | | static void smpc_intbackhelper(running_machine &machine) |
| 266 | static TIMER_CALLBACK( stv_smpc_intback ) |
| 266 | 267 | { |
| 267 | 268 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 268 | | int pad,i; |
| 269 | | static const char *const padnames[] = { "JOY1", "JOY2" }; |
| 270 | | |
| 271 | | if (state->m_smpc.intback_stage == 1) |
| 272 | | { |
| 273 | | state->m_smpc.intback_stage++; |
| 274 | | return; |
| 275 | | } |
| 276 | | |
| 277 | | // if (LOG_SMPC) logerror("SMPC: providing PAD data for intback, pad %d\n", intback_stage-2); |
| 278 | | for(i=0;i<2;i++) |
| 279 | | { |
| 280 | | pad = input_port_read(machine, padnames[i]); |
| 281 | | state->m_smpc_ram[0x21+i*8] = 0xf1; // no tap, direct connect |
| 282 | | state->m_smpc_ram[0x23+i*8] = 0x02; // saturn pad |
| 283 | | state->m_smpc_ram[0x25+i*8] = pad>>8; |
| 284 | | state->m_smpc_ram[0x27+i*8] = pad & 0xff; |
| 285 | | } |
| 286 | | |
| 287 | | if (state->m_smpc.intback_stage == 3) |
| 288 | | { |
| 289 | | state->m_smpc.smpcSR = (0x80 | state->m_smpc.pmode); // pad 2, no more data, echo back pad mode set by intback |
| 290 | | } |
| 291 | | else |
| 292 | | { |
| 293 | | state->m_smpc.smpcSR = (0xe0 | state->m_smpc.pmode); // pad 1, more data, echo back pad mode set by intback |
| 294 | | } |
| 295 | | |
| 296 | | state->m_smpc.intback_stage++; |
| 297 | | } |
| 298 | | |
| 299 | | /* sys_type 1 == STV, 0 == SATURN */ |
| 300 | | static TIMER_CALLBACK( smpc_intback ) |
| 301 | | { |
| 302 | | saturn_state *state = machine.driver_data<saturn_state>(); |
| 303 | 269 | system_time systime; |
| 304 | 270 | machine.base_datetime(systime); |
| 305 | | UINT8 sys_type = param; |
| 306 | 271 | |
| 307 | 272 | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 308 | 273 | |
| 309 | | if(sys_type == 0) |
| 310 | | { |
| 311 | | state->m_smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100); |
| 312 | | state->m_smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100); |
| 313 | | state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1); |
| 314 | | state->m_smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday); |
| 315 | | state->m_smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour); |
| 316 | | state->m_smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute); |
| 317 | | state->m_smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second); |
| 318 | | } |
| 319 | | |
| 320 | 274 | state->m_smpc_ram[0x31]=0x00; //? |
| 321 | 275 | |
| 322 | 276 | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| r12482 | r12483 | |
| 331 | 285 | 0 << 0; //SOUNDRES |
| 332 | 286 | state->m_smpc_ram[0x37]= 0 << 6; //CDRES |
| 333 | 287 | |
| 334 | | state->m_smpc_ram[0x39]=sys_type ? 0xff : state->m_smpc.SMEM[0]; |
| 335 | | state->m_smpc_ram[0x3b]=sys_type ? 0xff : state->m_smpc.SMEM[1]; |
| 336 | | state->m_smpc_ram[0x3d]=sys_type ? 0xff : state->m_smpc.SMEM[2]; |
| 337 | | state->m_smpc_ram[0x3f]=sys_type ? 0xff : state->m_smpc.SMEM[3]; |
| 288 | state->m_smpc_ram[0x39]=0xff; |
| 289 | state->m_smpc_ram[0x3b]=0xff; |
| 290 | state->m_smpc_ram[0x3d]=0xff; |
| 291 | state->m_smpc_ram[0x3f]=0xff; |
| 338 | 292 | |
| 339 | 293 | state->m_smpc_ram[0x41]=0xff; |
| 340 | 294 | state->m_smpc_ram[0x43]=0xff; |
| r12482 | r12483 | |
| 352 | 306 | state->m_smpc_ram[0x5b]=0xff; |
| 353 | 307 | state->m_smpc_ram[0x5d]=0xff; |
| 354 | 308 | |
| 355 | | if(sys_type == 0) |
| 356 | | { |
| 357 | | state->m_smpc.smpcSR = 0x60; // peripheral data ready, no reset, etc. |
| 358 | | state->m_smpc.pmode = state->m_smpc_ram[1]>>4; |
| 309 | // /*This is for RTC,cartridge code and similar stuff...*/ |
| 310 | //if(LOG_SMPC) printf ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline); |
| 311 | if(!(state->m_scu.ism & IRQ_SMPC)) |
| 312 | device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47); |
| 313 | else |
| 314 | state->m_scu.ist |= (IRQ_SMPC); |
| 359 | 315 | |
| 360 | | state->m_smpc.intback_stage = 1; |
| 316 | /* clear hand-shake flag */ |
| 317 | state->m_smpc_ram[0x63] = 0x00; |
| 318 | } |
| 361 | 319 | |
| 362 | | smpc_intbackhelper(machine); |
| 320 | static TIMER_CALLBACK( intback_peripheral ) |
| 321 | { |
| 322 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 323 | int pad,pad_num; |
| 324 | static const char *const padnames[] = { "JOY1", "JOY2" }; |
| 325 | |
| 326 | /* doesn't work? */ |
| 327 | //pad_num = state->m_smpc.intback_stage - 1; |
| 328 | |
| 329 | if(LOG_PAD_CMD) printf("%d\n",pad_num); |
| 330 | |
| 331 | // if (LOG_SMPC) logerror("SMPC: providing PAD data for intback, pad %d\n", intback_stage-2); |
| 332 | for(pad_num=0;pad_num<2;pad_num++) |
| 333 | { |
| 334 | pad = input_port_read(machine, padnames[pad_num]); |
| 335 | state->m_smpc_ram[0x21+pad_num*8] = 0xf1; // no tap, direct connect |
| 336 | state->m_smpc_ram[0x23+pad_num*8] = 0x02; // saturn pad |
| 337 | state->m_smpc_ram[0x25+pad_num*8] = pad>>8; |
| 338 | state->m_smpc_ram[0x27+pad_num*8] = pad & 0xff; |
| 363 | 339 | } |
| 364 | 340 | |
| 365 | | // /*This is for RTC,cartridge code and similar stuff...*/ |
| 366 | | //if(LOG_SMPC) printf ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline); |
| 341 | if (state->m_smpc.intback_stage == 2) |
| 342 | { |
| 343 | state->m_smpc.smpcSR = (0x80 | state->m_smpc.pmode); // pad 2, no more data, echo back pad mode set by intback |
| 344 | state->m_smpc.intback_stage = 0; |
| 345 | } |
| 346 | else |
| 347 | { |
| 348 | state->m_smpc.smpcSR = (0xc0 | state->m_smpc.pmode); // pad 1, more data, echo back pad mode set by intback |
| 349 | state->m_smpc.intback_stage ++; |
| 350 | } |
| 351 | |
| 367 | 352 | if(!(state->m_scu.ism & IRQ_SMPC)) |
| 368 | 353 | device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47); |
| 369 | 354 | else |
| r12482 | r12483 | |
| 371 | 356 | |
| 372 | 357 | /* clear hand-shake flag */ |
| 373 | 358 | state->m_smpc_ram[0x63] = 0x00; |
| 359 | |
| 374 | 360 | } |
| 375 | 361 | |
| 362 | static TIMER_CALLBACK( saturn_smpc_intback ) |
| 363 | { |
| 364 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 365 | system_time systime; |
| 366 | machine.base_datetime(systime); |
| 367 | |
| 368 | if(state->m_smpc_ram[1] != 0) |
| 369 | { |
| 370 | { |
| 371 | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 372 | |
| 373 | state->m_smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100); |
| 374 | state->m_smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100); |
| 375 | state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1); |
| 376 | state->m_smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday); |
| 377 | state->m_smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour); |
| 378 | state->m_smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute); |
| 379 | state->m_smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second); |
| 380 | |
| 381 | state->m_smpc_ram[0x31]=0x00; //? |
| 382 | |
| 383 | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| 384 | |
| 385 | state->m_smpc_ram[0x35]= 0 << 7 | |
| 386 | state->m_vdp2.dotsel << 6 | |
| 387 | 1 << 5 | |
| 388 | 1 << 4 | |
| 389 | 0 << 3 | //MSHNMI |
| 390 | 1 << 2 | |
| 391 | 0 << 1 | //SYSRES |
| 392 | 0 << 0; //SOUNDRES |
| 393 | state->m_smpc_ram[0x37]= 0 << 6; //CDRES |
| 394 | |
| 395 | state->m_smpc_ram[0x39]=state->m_smpc.SMEM[0]; |
| 396 | state->m_smpc_ram[0x3b]=state->m_smpc.SMEM[1]; |
| 397 | state->m_smpc_ram[0x3d]=state->m_smpc.SMEM[2]; |
| 398 | state->m_smpc_ram[0x3f]=state->m_smpc.SMEM[3]; |
| 399 | |
| 400 | state->m_smpc_ram[0x41]=0xff; |
| 401 | state->m_smpc_ram[0x43]=0xff; |
| 402 | state->m_smpc_ram[0x45]=0xff; |
| 403 | state->m_smpc_ram[0x47]=0xff; |
| 404 | state->m_smpc_ram[0x49]=0xff; |
| 405 | state->m_smpc_ram[0x4b]=0xff; |
| 406 | state->m_smpc_ram[0x4d]=0xff; |
| 407 | state->m_smpc_ram[0x4f]=0xff; |
| 408 | state->m_smpc_ram[0x51]=0xff; |
| 409 | state->m_smpc_ram[0x53]=0xff; |
| 410 | state->m_smpc_ram[0x55]=0xff; |
| 411 | state->m_smpc_ram[0x57]=0xff; |
| 412 | state->m_smpc_ram[0x59]=0xff; |
| 413 | state->m_smpc_ram[0x5b]=0xff; |
| 414 | state->m_smpc_ram[0x5d]=0xff; |
| 415 | } |
| 416 | |
| 417 | state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral |
| 418 | state->m_smpc.smpcSR = 0x40 | state->m_smpc.intback_stage << 5; |
| 419 | state->m_smpc.pmode = state->m_smpc_ram[1]>>4; |
| 420 | |
| 421 | if(!(state->m_scu.ism & IRQ_SMPC)) |
| 422 | device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47); |
| 423 | else |
| 424 | state->m_scu.ist |= (IRQ_SMPC); |
| 425 | |
| 426 | /* clear hand-shake flag */ |
| 427 | state->m_smpc_ram[0x63] = 0x00; |
| 428 | } |
| 429 | else if(state->m_smpc_ram[3] & 8) |
| 430 | { |
| 431 | state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral |
| 432 | state->m_smpc.smpcSR = 0x40; |
| 433 | machine.scheduler().timer_set(attotime::from_usec(0), FUNC(intback_peripheral),0); |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]); |
| 438 | } |
| 439 | |
| 440 | } |
| 441 | |
| 376 | 442 | static void smpc_rtc_write(running_machine &machine) |
| 377 | 443 | { |
| 378 | 444 | saturn_state *state = machine.driver_data<saturn_state>(); |
| r12482 | r12483 | |
| 505 | 571 | /*"Interrupt Back"*/ |
| 506 | 572 | case 0x10: |
| 507 | 573 | if(LOG_SMPC) printf ("SMPC: Status Acquire\n"); |
| 508 | | space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(smpc_intback),1); //TODO: variable time |
| 574 | space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time |
| 509 | 575 | break; |
| 510 | 576 | /* RTC write*/ |
| 511 | 577 | case 0x16: |
| r12482 | r12483 | |
| 606 | 672 | |
| 607 | 673 | last = state->m_smpc_ram[offset]; |
| 608 | 674 | |
| 609 | | if ((state->m_smpc.intback_stage > 0) && (offset == 1) && (((data ^ 0x80)&0x80) == (last&0x80))) |
| 675 | if (offset == 1) |
| 610 | 676 | { |
| 611 | | if (LOG_SMPC) logerror("SMPC: CONTINUE request, stage %d\n", state->m_smpc.intback_stage); |
| 612 | | if (state->m_smpc.intback_stage != 3) |
| 677 | if(state->m_smpc.intback_stage) |
| 613 | 678 | { |
| 614 | | state->m_smpc.intback_stage = 2; |
| 679 | if(data & 0x40) |
| 680 | { |
| 681 | if(LOG_PAD_CMD) printf("SMPC: BREAK request\n"); |
| 682 | state->m_smpc.smpcSR &= 0x0f; |
| 683 | state->m_smpc.intback_stage = 0; |
| 684 | } |
| 685 | else if(data & 0x80) |
| 686 | { |
| 687 | if(LOG_PAD_CMD) printf("SMPC: CONTINUE request\n"); |
| 688 | space->machine().scheduler().timer_set(attotime::from_usec(200), FUNC(intback_peripheral),0); /* TODO: is timing correct? */ |
| 689 | state->m_smpc_ram[0x63] = 0x01; //TODO: set hand-shake flag? |
| 690 | } |
| 615 | 691 | } |
| 616 | | smpc_intbackhelper(machine); |
| 617 | | device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47); |
| 618 | 692 | } |
| 619 | 693 | |
| 620 | | if ((offset == 1) && (data & 0x40)) |
| 621 | | { |
| 622 | | if (LOG_SMPC) logerror("SMPC: BREAK request\n"); |
| 623 | | state->m_smpc.intback_stage = 0; |
| 624 | | } |
| 625 | | |
| 626 | 694 | state->m_smpc_ram[offset] = data; |
| 627 | 695 | |
| 628 | 696 | if (offset == 0x75) // PDR1 |
| r12482 | r12483 | |
| 686 | 754 | |
| 687 | 755 | timing = 100; |
| 688 | 756 | |
| 689 | | if(state->m_smpc_ram[1] == 0x01) // non-peripheral data |
| 757 | if(state->m_smpc_ram[1] != 0) // non-peripheral data |
| 690 | 758 | timing = 200; |
| 691 | 759 | |
| 692 | 760 | if(state->m_smpc_ram[3] & 8) // peripheral data |
| 693 | 761 | timing = 15000; |
| 694 | 762 | |
| 695 | | space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(smpc_intback),0); //TODO: is variable time correct |
| 763 | if(LOG_PAD_CMD) printf("INTBACK %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]); |
| 764 | |
| 765 | space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct? |
| 696 | 766 | break; |
| 697 | 767 | /* RTC write*/ |
| 698 | 768 | case 0x16: |