trunk/src/mess/machine/nes.c
| r20489 | r20490 | |
| 304 | 304 | m_sound = machine().device("nessound"); |
| 305 | 305 | m_cart = machine().device("cart"); |
| 306 | 306 | m_io_ctrlsel = ioport("CTRLSEL"); |
| 307 | m_io_fckey[0] = ioport("FCKEY0"); |
| 308 | m_io_fckey[1] = ioport("FCKEY1"); |
| 309 | m_io_fckey[2] = ioport("FCKEY2"); |
| 310 | m_io_fckey[3] = ioport("FCKEY3"); |
| 311 | m_io_fckey[4] = ioport("FCKEY4"); |
| 312 | m_io_fckey[5] = ioport("FCKEY5"); |
| 313 | m_io_fckey[6] = ioport("FCKEY6"); |
| 314 | m_io_fckey[7] = ioport("FCKEY7"); |
| 315 | m_io_fckey[8] = ioport("FCKEY8"); |
| 316 | m_io_subkey[0 ] = ioport("SUBKEY0"); |
| 317 | m_io_subkey[1 ] = ioport("SUBKEY1"); |
| 318 | m_io_subkey[2 ] = ioport("SUBKEY2"); |
| 319 | m_io_subkey[3 ] = ioport("SUBKEY3"); |
| 320 | m_io_subkey[4 ] = ioport("SUBKEY4"); |
| 321 | m_io_subkey[5 ] = ioport("SUBKEY5"); |
| 322 | m_io_subkey[6 ] = ioport("SUBKEY6"); |
| 323 | m_io_subkey[7 ] = ioport("SUBKEY7"); |
| 324 | m_io_subkey[8 ] = ioport("SUBKEY8"); |
| 325 | m_io_subkey[9 ] = ioport("SUBKEY9"); |
| 326 | m_io_subkey[10] = ioport("SUBKEY10"); |
| 327 | m_io_subkey[11] = ioport("SUBKEY11"); |
| 328 | m_io_subkey[12] = ioport("SUBKEY12"); |
| 329 | m_io_pad[0] = ioport("PAD1"); |
| 330 | m_io_pad[1] = ioport("PAD2"); |
| 331 | m_io_pad[2] = ioport("PAD3"); |
| 332 | m_io_pad[3] = ioport("PAD4"); |
| 333 | m_io_cc_left = ioport("CC_LEFT"); |
| 334 | m_io_cc_right = ioport("CC_RIGHT"); |
| 335 | m_io_zapper1_t = ioport("ZAPPER1_T"); |
| 336 | m_io_zapper1_x = ioport("ZAPPER1_X"); |
| 337 | m_io_zapper1_y = ioport("ZAPPER1_Y"); |
| 338 | m_io_zapper2_t = ioport("ZAPPER2_T"); |
| 339 | m_io_zapper2_x = ioport("ZAPPER2_X"); |
| 340 | m_io_zapper2_y = ioport("ZAPPER2_Y"); |
| 341 | m_io_paddle = ioport("PADDLE"); |
| 307 | 342 | m_prg_bank_mem[0] = membank("bank1"); |
| 308 | 343 | m_prg_bank_mem[1] = membank("bank2"); |
| 309 | 344 | m_prg_bank_mem[2] = membank("bank3"); |
| r20489 | r20490 | |
| 416 | 451 | return ret; |
| 417 | 452 | } |
| 418 | 453 | |
| 419 | | // row of the keyboard matrix are read 4-bits at time, and gets returned as bit1->bit4 |
| 420 | | static UINT8 nes_read_fc_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode ) |
| 421 | | { |
| 422 | | static const char *const fc_keyport_names[] = { "FCKEY0", "FCKEY1", "FCKEY2", "FCKEY3", "FCKEY4", "FCKEY5", "FCKEY6", "FCKEY7", "FCKEY8" }; |
| 423 | | nes_state *state = machine.driver_data<nes_state>(); |
| 424 | | return ((state->ioport(fc_keyport_names[scan])->read() >> (mode * 4)) & 0x0f) << 1; |
| 425 | | } |
| 426 | | |
| 427 | | static UINT8 nes_read_subor_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode ) |
| 428 | | { |
| 429 | | static const char *const sub_keyport_names[] = { "SUBKEY0", "SUBKEY1", "SUBKEY2", "SUBKEY3", "SUBKEY4", |
| 430 | | "SUBKEY5", "SUBKEY6", "SUBKEY7", "SUBKEY8", "SUBKEY9", "SUBKEY10", "SUBKEY11", "SUBKEY12" }; |
| 431 | | nes_state *state = machine.driver_data<nes_state>(); |
| 432 | | return ((state->ioport(sub_keyport_names[scan])->read() >> (mode * 4)) & 0x0f) << 1; |
| 433 | | } |
| 434 | | |
| 435 | 454 | READ8_MEMBER(nes_state::nes_IN1_r) |
| 436 | 455 | { |
| 437 | 456 | int cfg = m_io_ctrlsel->read(); |
| 438 | 457 | int ret; |
| 439 | 458 | |
| 459 | // row of the keyboard matrix are read 4-bits at time, and gets returned as bit1->bit4 |
| 440 | 460 | if ((cfg & 0x000f) == 0x08) // for now we treat the FC keyboard separately from other inputs! |
| 441 | 461 | { |
| 442 | 462 | if (m_fck_scan < 9) |
| 443 | | ret = ~nes_read_fc_keyboard_line(machine(), m_fck_scan, m_fck_mode) & 0x1e; |
| 463 | ret = ~(((m_io_fckey[m_fck_scan]->read() >> (m_fck_mode * 4)) & 0x0f) << 1) & 0x1e; |
| 444 | 464 | else |
| 445 | 465 | ret = 0x1e; |
| 446 | 466 | } |
| 447 | 467 | else if ((cfg & 0x000f) == 0x09) // for now we treat the Subor keyboard separately from other inputs! |
| 448 | 468 | { |
| 449 | 469 | if (m_fck_scan < 12) |
| 450 | | ret = ~nes_read_subor_keyboard_line(machine(), m_fck_scan, m_fck_mode) & 0x1e; |
| 470 | ret = ~(((m_io_subkey[m_fck_scan]->read() >> (m_fck_mode * 4)) & 0x0f) << 1) & 0x1e; |
| 451 | 471 | else |
| 452 | 472 | ret = 0x1e; |
| 453 | 473 | } |
| r20489 | r20490 | |
| 513 | 533 | static void nes_read_input_device( running_machine &machine, int cfg, nes_input *vals, int pad_port, int supports_zapper ) |
| 514 | 534 | { |
| 515 | 535 | nes_state *state = machine.driver_data<nes_state>(); |
| 516 | | static const char *const padnames[] = { "PAD1", "PAD2", "PAD3", "PAD4", "CC_LEFT", "CC_RIGHT" }; |
| 517 | 536 | |
| 518 | 537 | vals->i0 = 0; |
| 519 | 538 | vals->i1 = 0; |
| r20489 | r20490 | |
| 523 | 542 | { |
| 524 | 543 | case 0x01: /* gamepad */ |
| 525 | 544 | if (pad_port >= 0) |
| 526 | | vals->i0 = machine.root_device().ioport(padnames[pad_port])->read(); |
| 545 | vals->i0 = state->m_io_pad[pad_port]->read(); |
| 527 | 546 | break; |
| 528 | 547 | |
| 529 | 548 | case 0x02: /* zapper 1 */ |
| 530 | 549 | if (supports_zapper) |
| 531 | 550 | { |
| 532 | | vals->i0 = machine.root_device().ioport("ZAPPER1_T")->read(); |
| 533 | | vals->i1 = machine.root_device().ioport("ZAPPER1_X")->read(); |
| 534 | | vals->i2 = machine.root_device().ioport("ZAPPER1_Y")->read(); |
| 551 | vals->i0 = state->m_io_zapper1_t->read(); |
| 552 | vals->i1 = state->m_io_zapper1_x->read(); |
| 553 | vals->i2 = state->m_io_zapper1_y->read(); |
| 535 | 554 | } |
| 536 | 555 | break; |
| 537 | 556 | |
| 538 | 557 | case 0x03: /* zapper 2 */ |
| 539 | 558 | if (supports_zapper) |
| 540 | 559 | { |
| 541 | | vals->i0 = machine.root_device().ioport("ZAPPER2_T")->read(); |
| 542 | | vals->i1 = machine.root_device().ioport("ZAPPER2_X")->read(); |
| 543 | | vals->i2 = machine.root_device().ioport("ZAPPER2_Y")->read(); |
| 560 | vals->i0 = state->m_io_zapper2_t->read(); |
| 561 | vals->i1 = state->m_io_zapper2_x->read(); |
| 562 | vals->i2 = state->m_io_zapper2_y->read(); |
| 544 | 563 | } |
| 545 | 564 | break; |
| 546 | 565 | |
| 547 | 566 | case 0x04: /* arkanoid paddle */ |
| 548 | 567 | if (pad_port == 1) |
| 549 | | vals->i0 = (UINT8) ((UINT8) machine.root_device().ioport("PADDLE")->read() + (UINT8)0x52) ^ 0xff; |
| 568 | vals->i0 = (UINT8) ((UINT8) state->m_io_paddle->read() + (UINT8)0x52) ^ 0xff; |
| 550 | 569 | break; |
| 551 | 570 | |
| 552 | 571 | case 0x06: /* crazy climber controller */ |
| 553 | 572 | if (pad_port == 0) |
| 554 | 573 | { |
| 555 | | state->m_in_0.i0 = machine.root_device().ioport(padnames[4])->read(); |
| 556 | | state->m_in_1.i0 = machine.root_device().ioport(padnames[5])->read(); |
| 574 | state->m_in_0.i0 = state->m_io_cc_left->read(); |
| 575 | state->m_in_1.i0 = state->m_io_cc_right->read(); |
| 557 | 576 | } |
| 558 | 577 | break; |
| 559 | 578 | } |