trunk/src/mame/machine/n64.c
r241686 | r241687 | |
267 | 267 | pif_ram[0x27] = 0x3f; |
268 | 268 | cic_type=6; |
269 | 269 | } |
270 | | else |
271 | | { |
272 | | //printf("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
273 | | } |
274 | 270 | } |
275 | 271 | |
276 | 272 | // Memory Interface (MI) |
r241686 | r241687 | |
312 | 308 | break; |
313 | 309 | } |
314 | 310 | |
315 | | //printf("mi_reg_r %08x = %08x\n", offset * 4, ret); fflush(stdout); |
316 | 311 | return ret; |
317 | 312 | } |
318 | 313 | |
319 | 314 | WRITE32_MEMBER( n64_periphs::mi_reg_w ) |
320 | 315 | { |
321 | | //printf("mi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout); |
322 | 316 | switch (offset) |
323 | 317 | { |
324 | 318 | case 0x00/4: // MI_INIT_MODE_REG |
r241686 | r241687 | |
409 | 403 | { |
410 | 404 | if (mi_intr_mask & mi_interrupt) |
411 | 405 | { |
412 | | //printf("Asserting IRQ, %02x : %02x\n", mi_intr_mask, mi_interrupt); fflush(stdout); |
413 | 406 | machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE); |
414 | 407 | } |
415 | 408 | else |
416 | 409 | { |
417 | | //printf("Deasserting IRQ, %02x : %02x\n", mi_intr_mask, mi_interrupt); fflush(stdout); |
418 | 410 | machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE); |
419 | 411 | } |
420 | 412 | } |
r241686 | r241687 | |
466 | 458 | case 0x0014/4: |
467 | 459 | for(i = 0x20; i < (0x20 + data); i++) |
468 | 460 | { |
469 | | //printf( "%c", is64_buffer[i] ); |
470 | 461 | if(is64_buffer[i] == 0x0a) |
471 | 462 | { |
472 | | //printf( "%c", 0x0d ); |
| 463 | printf( "%c", 0x0d ); |
473 | 464 | } |
474 | 465 | is64_buffer[i] = 0; |
475 | 466 | } |
r241686 | r241687 | |
511 | 502 | |
512 | 503 | READ32_MEMBER( n64_periphs::rdram_reg_r ) |
513 | 504 | { |
514 | | //printf("rdram_reg_r %08x = %08x\n", offset * 4, rdram_regs[offset]); fflush(stdout); |
515 | 505 | if(offset > 0x24/4) |
516 | 506 | { |
517 | 507 | logerror("rdram_reg_r: %08X, %08X at %08X\n", offset, mem_mask, maincpu->safe_pc()); |
r241686 | r241687 | |
522 | 512 | |
523 | 513 | WRITE32_MEMBER( n64_periphs::rdram_reg_w ) |
524 | 514 | { |
525 | | //printf("rdram_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout); |
526 | 515 | if(offset > 0x24/4) |
527 | 516 | { |
528 | 517 | logerror("rdram_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, maincpu->safe_pc()); |
r241686 | r241687 | |
542 | 531 | length = (length + 7) & ~7; |
543 | 532 | } |
544 | 533 | |
545 | | //printf("Length %08x Skip %08x Count %08x\n", length, sp_dma_skip, sp_dma_count); fflush(stdout); |
546 | 534 | if (sp_mem_addr & 0x3) |
547 | 535 | { |
548 | 536 | sp_mem_addr = sp_mem_addr & ~3; |
r241686 | r241687 | |
554 | 542 | |
555 | 543 | if ((sp_mem_addr & 0xfff) + (length) > 0x1000) |
556 | 544 | { |
557 | | //printf("sp_dma: dma out of memory area: %08X, %08X, %08X\n", sp_mem_addr, sp_dram_addr, length); |
558 | | //fatalerror("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, length); |
559 | 545 | length = 0x1000 - (sp_mem_addr & 0xfff); |
560 | 546 | } |
561 | 547 | |
r241686 | r241687 | |
602 | 588 | |
603 | 589 | WRITE32_MEMBER(n64_periphs::sp_set_status) |
604 | 590 | { |
605 | | //printf("sp_set_status: %08x\n", data); |
606 | 591 | if (data & 0x1) |
607 | 592 | { |
608 | 593 | rspcpu->execute().set_input_line(INPUT_LINE_HALT, ASSERT_LINE); |
r241686 | r241687 | |
638 | 623 | break; |
639 | 624 | |
640 | 625 | case 0x10/4: // SP_STATUS_REG |
641 | | //machine().scheduler().synchronize(); |
642 | | //machine().scheduler().boost_interleave(attotime::from_msec(1), attotime::from_msec(m)); |
643 | 626 | ret = rspcpu->state().state_int(RSP_SR); |
644 | 627 | break; |
645 | 628 | |
r241686 | r241687 | |
652 | 635 | break; |
653 | 636 | |
654 | 637 | case 0x1c/4: // SP_SEMAPHORE_REG |
655 | | //machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(1)); |
656 | 638 | machine().device("maincpu")->execute().yield(); |
657 | 639 | if( sp_semaphore ) |
658 | 640 | { |
r241686 | r241687 | |
660 | 642 | } |
661 | 643 | else |
662 | 644 | { |
663 | | //printf("Semaphore is now acquired, returning 0\n"); |
664 | 645 | sp_semaphore = 1; |
665 | 646 | ret = 0; |
666 | 647 | } |
r241686 | r241687 | |
718 | 699 | break; |
719 | 700 | } |
720 | 701 | |
721 | | //printf("%08x sp_reg_r %08x = %08x\n", (UINT32)maincpu->state().state_int(MIPS3_PC), offset * 4, ret); fflush(stdout); |
722 | 702 | return ret; |
723 | 703 | } |
724 | 704 | |
725 | 705 | |
726 | 706 | WRITE32_MEMBER(n64_periphs::sp_reg_w ) |
727 | 707 | { |
728 | | //printf("%08x sp_reg_w %08x %08x %08x\n", (UINT32)maincpu->state().state_int(MIPS3_PC), offset * 4, data, mem_mask); fflush(stdout); |
729 | | |
730 | 708 | if ((offset & 0x10000) == 0) |
731 | 709 | { |
732 | 710 | switch (offset & 0xffff) |
r241686 | r241687 | |
758 | 736 | UINT32 oldstatus = rspcpu->state().state_int(RSP_SR); |
759 | 737 | UINT32 newstatus = oldstatus; |
760 | 738 | |
761 | | // printf( "RSP_STATUS_REG Write; %08x\n", data ); |
762 | 739 | if (data & 0x00000001) // clear halt |
763 | 740 | { |
764 | 741 | rspcpu->execute().set_input_line(INPUT_LINE_HALT, CLEAR_LINE); |
765 | 742 | newstatus &= ~RSP_STATUS_HALT; |
766 | | //printf("***SP HALT CLR***\n"); fflush(stdout); |
| 743 | machine().scheduler().abort_timeslice(); |
| 744 | machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(100)); |
767 | 745 | } |
768 | 746 | if (data & 0x00000002) // set halt |
769 | 747 | { |
770 | 748 | rspcpu->execute().set_input_line(INPUT_LINE_HALT, ASSERT_LINE); |
771 | 749 | newstatus |= RSP_STATUS_HALT; |
772 | | //printf("***SP HALT SET***\n"); fflush(stdout); |
773 | 750 | } |
774 | 751 | if (data & 0x00000004) |
775 | 752 | { |
776 | 753 | newstatus &= ~RSP_STATUS_BROKE; |
777 | | //printf("***SP BROKE CLR***\n"); fflush(stdout); |
778 | 754 | } |
779 | 755 | if (data & 0x00000008) // clear interrupt |
780 | 756 | { |
781 | | //printf("***SP INT CLR***\n"); fflush(stdout); |
782 | 757 | clear_rcp_interrupt(SP_INTERRUPT); |
783 | 758 | } |
784 | 759 | if (data & 0x00000010) // set interrupt |
785 | 760 | { |
786 | | //printf("***SP INT SET***\n"); fflush(stdout); |
787 | 761 | signal_rcp_interrupt(SP_INTERRUPT); |
788 | 762 | } |
789 | 763 | if (data & 0x00000020) |
790 | 764 | { |
791 | 765 | newstatus &= ~RSP_STATUS_SSTEP; |
792 | | //printf("***SP SSTEP CLR***\n"); fflush(stdout); |
793 | 766 | } |
794 | 767 | if (data & 0x00000040) |
795 | 768 | { |
796 | 769 | newstatus |= RSP_STATUS_SSTEP; // set single step |
797 | | //printf("***SP SSTEP SET***\n"); fflush(stdout); |
798 | 770 | if(!(oldstatus & (RSP_STATUS_BROKE | RSP_STATUS_HALT))) |
799 | 771 | { |
800 | 772 | rspcpu->state().set_state_int(RSP_STEPCNT, 1 ); |
r241686 | r241687 | |
804 | 776 | if (data & 0x00000080) |
805 | 777 | { |
806 | 778 | newstatus &= ~RSP_STATUS_INTR_BREAK; // clear interrupt on break |
807 | | //printf("***SP INTRBRK CLR***\n"); fflush(stdout); |
808 | 779 | } |
809 | 780 | if (data & 0x00000100) |
810 | 781 | { |
811 | 782 | newstatus |= RSP_STATUS_INTR_BREAK; // set interrupt on break |
812 | | //printf("***SP INTRBRK SET***\n"); fflush(stdout); |
813 | 783 | } |
814 | 784 | if (data & 0x00000200) |
815 | 785 | { |
816 | 786 | newstatus &= ~RSP_STATUS_SIGNAL0; // clear signal 0 |
817 | | //printf("***SP YIELD CLR***\n"); fflush(stdout); |
818 | 787 | } |
819 | 788 | if (data & 0x00000400) |
820 | 789 | { |
821 | 790 | newstatus |= RSP_STATUS_SIGNAL0; // set signal 0 |
822 | | //printf("***SP YIELD SET***\n"); fflush(stdout); |
823 | 791 | } |
824 | 792 | if (data & 0x00000800) |
825 | 793 | { |
826 | 794 | newstatus &= ~RSP_STATUS_SIGNAL1; // clear signal 1 |
827 | | //printf("***SP YIELDED CLR***\n"); fflush(stdout); |
828 | 795 | } |
829 | 796 | if (data & 0x00001000) |
830 | 797 | { |
831 | 798 | newstatus |= RSP_STATUS_SIGNAL1; // set signal 1 |
832 | | //printf("***SP YIELDED SET***\n"); fflush(stdout); |
833 | 799 | } |
834 | 800 | if (data & 0x00002000) |
835 | 801 | { |
836 | 802 | newstatus &= ~RSP_STATUS_SIGNAL2 ; // clear signal 2 |
837 | | //printf("***SP TASKDONE CLR***\n"); fflush(stdout); |
838 | 803 | } |
839 | 804 | if (data & 0x00004000) |
840 | 805 | { |
841 | 806 | newstatus |= RSP_STATUS_SIGNAL2; // set signal 2 |
842 | | //printf("***SP TASKDONE SET***\n"); fflush(stdout); |
843 | 807 | } |
844 | 808 | if (data & 0x00008000) |
845 | 809 | { |
846 | 810 | newstatus &= ~RSP_STATUS_SIGNAL3; // clear signal 3 |
847 | | //printf("***SP SIG3 CLR***\n"); fflush(stdout); |
848 | 811 | } |
849 | 812 | if (data & 0x00010000) |
850 | 813 | { |
851 | 814 | newstatus |= RSP_STATUS_SIGNAL3; // set signal 3 |
852 | | //printf("***SP SIG3 SET***\n"); fflush(stdout); |
853 | 815 | } |
854 | 816 | if (data & 0x00020000) |
855 | 817 | { |
856 | 818 | newstatus &= ~RSP_STATUS_SIGNAL4; // clear signal 4 |
857 | | //printf("***SP SIG4 CLR***\n"); fflush(stdout); |
858 | 819 | } |
859 | 820 | if (data & 0x00040000) |
860 | 821 | { |
861 | 822 | newstatus |= RSP_STATUS_SIGNAL4; // set signal 4 |
862 | | //printf("***SP SIG4 SET***\n"); fflush(stdout); |
863 | 823 | } |
864 | 824 | if (data & 0x00080000) |
865 | 825 | { |
866 | 826 | newstatus &= ~RSP_STATUS_SIGNAL5; // clear signal 5 |
867 | | //printf("***SP SIG5 CLR***\n"); fflush(stdout); |
868 | 827 | } |
869 | 828 | if (data & 0x00100000) |
870 | 829 | { |
871 | 830 | newstatus |= RSP_STATUS_SIGNAL5; // set signal 5 |
872 | | //printf("***SP SIG5 SET***\n"); fflush(stdout); |
873 | 831 | } |
874 | 832 | if (data & 0x00200000) |
875 | 833 | { |
876 | 834 | newstatus &= ~RSP_STATUS_SIGNAL6; // clear signal 6 |
877 | | //printf("***SP SIG6 CLR***\n"); fflush(stdout); |
878 | 835 | } |
879 | 836 | if (data & 0x00400000) |
880 | 837 | { |
881 | 838 | newstatus |= RSP_STATUS_SIGNAL6; // set signal 6 |
882 | | //printf("***SP SIG6 SET***\n"); fflush(stdout); |
883 | 839 | } |
884 | 840 | if (data & 0x00800000) |
885 | 841 | { |
886 | 842 | newstatus &= ~RSP_STATUS_SIGNAL7; // clear signal 7 |
887 | | //printf("***SP SIG7 CLR***\n"); fflush(stdout); |
888 | 843 | } |
889 | 844 | if (data & 0x01000000) |
890 | 845 | { |
891 | 846 | newstatus |= RSP_STATUS_SIGNAL7; // set signal 7 |
892 | | //printf("***SP SIG7 SET***\n"); fflush(stdout); |
893 | 847 | } |
894 | 848 | rspcpu->state().set_state_int(RSP_SR, newstatus); |
895 | 849 | break; |
896 | 850 | } |
897 | 851 | |
898 | 852 | case 0x1c/4: // SP_SEMAPHORE_REG |
899 | | //machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(1)); |
900 | | //printf("Semaphore is being released\n"); |
901 | 853 | if(data == 0) |
902 | 854 | { |
903 | 855 | sp_semaphore = 0; |
r241686 | r241687 | |
976 | 928 | break; |
977 | 929 | } |
978 | 930 | |
979 | | //printf("%08x dp_reg_r %08x = %08x\n", (UINT32)space.machine().device("rsp")->state().state_int(RSP_PC), offset, ret); fflush(stdout); |
980 | 931 | return ret; |
981 | 932 | } |
982 | 933 | |
r241686 | r241687 | |
984 | 935 | { |
985 | 936 | n64_state *state = space.machine().driver_data<n64_state>(); |
986 | 937 | |
987 | | //printf("%08x dp_reg_w %08x %08x %08x\n", (UINT32)space.machine().device("rsp")->state().state_int(RSP_PC), offset, data, mem_mask); fflush(stdout); |
988 | 938 | switch (offset) |
989 | 939 | { |
990 | 940 | case 0x00/4: // DP_START_REG |
r241686 | r241687 | |
993 | 943 | break; |
994 | 944 | |
995 | 945 | case 0x04/4: // DP_END_REG |
996 | | //printf("dp_end_reg %08x\n", data); |
997 | 946 | state->m_rdp->SetEndReg(data); |
998 | 947 | g_profiler.start(PROFILER_USER1); |
999 | 948 | state->m_rdp->ProcessList(); |
r241686 | r241687 | |
1042 | 991 | int y_end = (vi_vstart & 0x000003ff) / 2; |
1043 | 992 | int width = ((vi_xscale & 0x00000fff) * (x_end - x_start)) / 0x400; |
1044 | 993 | int height = ((vi_yscale & 0x00000fff) * (y_end - y_start)) / 0x400; |
1045 | | //printf("%04x | %02x | ", vi_xscale >> 16, vi_burst & 0x000000ff); |
| 994 | |
1046 | 995 | rectangle visarea = m_screen->visible_area(); |
1047 | 996 | attoseconds_t period = m_screen->frame_period().attoseconds; |
1048 | 997 | |
r241686 | r241687 | |
1070 | 1019 | |
1071 | 1020 | visarea.max_x = width - 1; |
1072 | 1021 | visarea.max_y = height - 1; |
1073 | | //printf("Reconfig %d, %d (%d - %d), %08x, %08x, %08x, %08x, %08x\n", width, height, x_start, x_end, vi_width, vi_xscale, vi_hsync, vi_hstart, vi_burst); |
1074 | 1022 | m_screen->configure(width, 525, visarea, period); |
1075 | 1023 | } |
1076 | 1024 | |
r241686 | r241687 | |
1140 | 1088 | break; |
1141 | 1089 | } |
1142 | 1090 | |
1143 | | //printf("vi_reg_r %08x = %08x\n", offset * 4, ret); |
1144 | 1091 | return ret; |
1145 | 1092 | } |
1146 | 1093 | |
1147 | 1094 | WRITE32_MEMBER( n64_periphs::vi_reg_w ) |
1148 | 1095 | { |
1149 | | //printf("vi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); |
1150 | 1096 | n64_state *state = machine().driver_data<n64_state>(); |
1151 | 1097 | |
1152 | 1098 | switch (offset) |
r241686 | r241687 | |
1379 | 1325 | break; |
1380 | 1326 | } |
1381 | 1327 | |
1382 | | //printf("ai_reg_r %08x = %08x\n", offset * 4, ret); |
1383 | 1328 | return ret; |
1384 | 1329 | } |
1385 | 1330 | |
1386 | 1331 | WRITE32_MEMBER( n64_periphs::ai_reg_w ) |
1387 | 1332 | { |
1388 | | //printf("ai_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); |
1389 | 1333 | switch (offset) |
1390 | 1334 | { |
1391 | 1335 | case 0x00/4: // AI_DRAM_ADDR_REG |
r241686 | r241687 | |
1408 | 1352 | case 0x10/4: // AI_DACRATE_REG |
1409 | 1353 | ai_dacrate = data & 0x3fff; |
1410 | 1354 | dmadac_set_frequency(&ai_dac[0], 2, (double)DACRATE_NTSC / (double)(ai_dacrate+1)); |
1411 | | //printf( "frequency: %f\n", (double)DACRATE_NTSC / (double)(ai_dacrate+1) ); |
1412 | 1355 | dmadac_enable(&ai_dac[0], 2, 1); |
1413 | 1356 | break; |
1414 | 1357 | |
r241686 | r241687 | |
1455 | 1398 | cart_addr &= ((machine().root_device().memregion("user2")->bytes() >> 1) - 1); |
1456 | 1399 | } |
1457 | 1400 | |
1458 | | //printf("%08x Cart, %08x Dram\n", cart_addr << 1, dram_addr << 1); fflush(stdout); |
1459 | | |
1460 | 1401 | if(pi_dma_dir == 1) |
1461 | 1402 | { |
1462 | 1403 | UINT32 dma_length = pi_wr_len + 1; |
r241686 | r241687 | |
1558 | 1499 | break; |
1559 | 1500 | } |
1560 | 1501 | |
1561 | | //printf("pi_reg_r %08x = %08x\n", offset * 4, ret); |
1562 | 1502 | return ret; |
1563 | 1503 | } |
1564 | 1504 | |
1565 | 1505 | WRITE32_MEMBER( n64_periphs::pi_reg_w ) |
1566 | 1506 | { |
1567 | | //printf("pi_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout); |
1568 | 1507 | switch (offset) |
1569 | 1508 | { |
1570 | 1509 | case 0x00/4: // PI_DRAM_ADDR_REG |
r241686 | r241687 | |
1586 | 1525 | pi_status |= 1; |
1587 | 1526 | |
1588 | 1527 | attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_rd_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte |
1589 | | //printf("want read dma in %d\n", (pi_rd_len + 1)); |
1590 | 1528 | pi_dma_timer->adjust(dma_period); |
1591 | 1529 | //pi_dma_tick(); |
1592 | 1530 | break; |
r241686 | r241687 | |
1599 | 1537 | pi_status |= 1; |
1600 | 1538 | |
1601 | 1539 | attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_wr_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte |
1602 | | //printf("want write dma in %d\n", (pi_wr_len + 1)); |
1603 | 1540 | pi_dma_timer->adjust(dma_period); |
1604 | 1541 | |
1605 | 1542 | //pi_dma_tick(); |
r241686 | r241687 | |
1658 | 1595 | |
1659 | 1596 | READ32_MEMBER( n64_periphs::ri_reg_r ) |
1660 | 1597 | { |
1661 | | //printf("ri_reg_r %08x = %08x\n", offset * 4, ri_regs[offset]); |
1662 | 1598 | if(offset > 0x1c/4) |
1663 | 1599 | { |
1664 | 1600 | logerror("ri_reg_r: %08X, %08X at %08X\n", offset, mem_mask, maincpu->safe_pc()); |
r241686 | r241687 | |
1669 | 1605 | |
1670 | 1606 | WRITE32_MEMBER( n64_periphs::ri_reg_w ) |
1671 | 1607 | { |
1672 | | //printf("ri_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); |
1673 | 1608 | if(offset > 0x1c/4) |
1674 | 1609 | { |
1675 | 1610 | logerror("ri_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, maincpu->safe_pc()); |
r241686 | r241687 | |
1732 | 1667 | case 0x00: // Read status |
1733 | 1668 | case 0xff: // Reset |
1734 | 1669 | { |
1735 | | if(command == 0) |
1736 | | { |
1737 | | //printf("Read status\n"); |
1738 | | } |
1739 | | else |
1740 | | { |
1741 | | //printf("Reset\n"); |
1742 | | } |
1743 | 1670 | switch (channel) |
1744 | 1671 | { |
1745 | 1672 | case 0: |
1746 | 1673 | case 1: |
1747 | 1674 | { |
1748 | | //printf("Read controller %d status\n", channel + 1); |
| 1675 | // Read status |
1749 | 1676 | rdata[0] = 0x05; |
1750 | 1677 | rdata[1] = 0x00; |
1751 | 1678 | rdata[2] = 0x01; |
r241686 | r241687 | |
1754 | 1681 | case 2: |
1755 | 1682 | case 3: |
1756 | 1683 | { |
1757 | | //printf("Read controller %d status (NC)\n", channel + 1); |
1758 | | // not connected |
| 1684 | // Read status (unconnected) |
1759 | 1685 | return 1; |
1760 | 1686 | } |
1761 | 1687 | case 4: |
1762 | 1688 | { |
1763 | | //printf("Read EEPROM status\n"); |
| 1689 | // Read EEPROM status |
1764 | 1690 | rdata[0] = 0x00; |
1765 | 1691 | rdata[1] = 0x80; |
1766 | 1692 | rdata[2] = 0x00; |
r241686 | r241687 | |
1791 | 1717 | |
1792 | 1718 | switch (channel) |
1793 | 1719 | { |
1794 | | case 0: //p1 inputs |
1795 | | case 1: //p2 inputs |
| 1720 | case 0: // P1 Inputs |
| 1721 | case 1: // P2 Inputs |
1796 | 1722 | { |
1797 | | //printf("Read p%d inputs\n", channel + 1); |
1798 | 1723 | buttons = machine().root_device().ioport(portnames[(channel*3) + 0])->read(); |
1799 | 1724 | x = machine().root_device().ioport(portnames[(channel*3) + 1])->read() - 128; |
1800 | 1725 | y = machine().root_device().ioport(portnames[(channel*3) + 2])->read() - 128; |
r241686 | r241687 | |
1808 | 1733 | case 2: |
1809 | 1734 | case 3: |
1810 | 1735 | { |
1811 | | //printf("Controller %d not connected\n", channel + 1); |
1812 | | // not connected |
| 1736 | // P3/P4 Inputs (not connected) |
1813 | 1737 | return 1; |
1814 | 1738 | } |
1815 | 1739 | } |
r241686 | r241687 | |
1824 | 1748 | address = (sdata[1] << 8) | (sdata[2]); |
1825 | 1749 | address &= ~0x1f; |
1826 | 1750 | |
1827 | | ////printf("Read mempak at %04x\n", address); |
1828 | | |
1829 | 1751 | if(address == 0x8000) |
1830 | 1752 | { |
1831 | 1753 | for(int i = 0; i < rlength-1; i++) |
r241686 | r241687 | |
1854 | 1776 | UINT32 address = (sdata[1] << 8) | (sdata[2]); |
1855 | 1777 | address &= ~0x1f; |
1856 | 1778 | |
1857 | | ////printf("Write mempak at %04x\n", address); |
1858 | | if (address >= 0x8000) |
| 1779 | if (address < 0x8000) |
1859 | 1780 | { |
1860 | | } |
1861 | | else |
1862 | | { |
1863 | 1781 | for(int i = 3; i < slength; i++) |
1864 | 1782 | { |
1865 | 1783 | m_save_data.mempak[channel & 1][address++] = sdata[i]; |
r241686 | r241687 | |
1885 | 1803 | |
1886 | 1804 | UINT16 block_offset = sdata[1] * 8; |
1887 | 1805 | |
1888 | | //printf("Read EEPROM at %04x\n", block_offset); |
1889 | | |
1890 | 1806 | for(int i=0; i < 8; i++) |
1891 | 1807 | { |
1892 | 1808 | rdata[i] = m_save_data.eeprom[block_offset+i]; |
r241686 | r241687 | |
1909 | 1825 | |
1910 | 1826 | UINT16 block_offset = sdata[1] * 8; |
1911 | 1827 | |
1912 | | //printf("Write EEPROM at %04x\n", block_offset); |
1913 | | |
1914 | 1828 | for(int i = 0; i < 8; i++) |
1915 | 1829 | { |
1916 | 1830 | m_save_data.eeprom[block_offset+i] = sdata[2+i]; |
r241686 | r241687 | |
1921 | 1835 | |
1922 | 1836 | case 0x06: // Read RTC Status |
1923 | 1837 | { |
1924 | | //printf("Read RTC Status\n"); |
1925 | 1838 | rdata[0] = 0x00; |
1926 | 1839 | rdata[1] = 0x10; |
1927 | 1840 | rdata[2] = 0x00; |
r241686 | r241687 | |
1933 | 1846 | switch(sdata[1]) |
1934 | 1847 | { |
1935 | 1848 | case 0: |
1936 | | //printf("Read RTC Block Header\n"); |
1937 | 1849 | rdata[0] = 0x00; |
1938 | 1850 | rdata[1] = 0x02; |
1939 | 1851 | rdata[8] = 0x00; |
r241686 | r241687 | |
1954 | 1866 | rdata[6] = convert_to_bcd(systime.local_time.year % 100); // Year |
1955 | 1867 | rdata[7] = convert_to_bcd(systime.local_time.year / 100); // Century |
1956 | 1868 | rdata[8] = 0x00; |
1957 | | //printf("Read RTC Time\n"); |
1958 | 1869 | return 0; |
1959 | 1870 | } |
1960 | 1871 | return 1; |
r241686 | r241687 | |
1982 | 1893 | while(cmd_ptr < 0x3f && !end) |
1983 | 1894 | { |
1984 | 1895 | INT8 bytes_to_send = (INT8)pif_cmd[cmd_ptr++]; |
1985 | | //printf("bytes to send: 0x%02x\n", bytes_to_send); |
1986 | 1896 | |
1987 | 1897 | if (bytes_to_send == -2) |
1988 | 1898 | { |
1989 | 1899 | end = 1; |
1990 | | //printf("end\n"); |
1991 | 1900 | } |
1992 | 1901 | else if (bytes_to_send < 0) |
1993 | 1902 | { |
1994 | | //printf("do nothing\n"); |
1995 | 1903 | // do nothing |
1996 | 1904 | } |
1997 | 1905 | else |
r241686 | r241687 | |
2002 | 1910 | UINT8 send_buffer[0x40]; |
2003 | 1911 | |
2004 | 1912 | INT8 bytes_to_recv = pif_cmd[cmd_ptr++]; |
2005 | | //printf("bytes to receive: 0x%02x\n", bytes_to_recv); |
2006 | 1913 | |
2007 | 1914 | if (bytes_to_recv == -2) |
2008 | 1915 | { |
r241686 | r241687 | |
2015 | 1922 | } |
2016 | 1923 | |
2017 | 1924 | int res = pif_channel_handle_command(channel, bytes_to_send, send_buffer, bytes_to_recv, recv_buffer); |
2018 | | //printf("result: %d\n", res); |
2019 | 1925 | |
2020 | 1926 | if (res == 0) |
2021 | 1927 | { |
2022 | | //printf("cmd_ptr (%d) + bytes_to_recv (%d) = %d\n", cmd_ptr, bytes_to_recv, cmd_ptr + bytes_to_recv); |
2023 | 1928 | if (cmd_ptr + bytes_to_recv > 0x3f) |
2024 | 1929 | { |
2025 | 1930 | fatalerror("cmd_ptr overflow\n"); |
r241686 | r241687 | |
2110 | 2015 | ret = si_status; |
2111 | 2016 | } |
2112 | 2017 | |
2113 | | //printf("si_reg_r %08x = %08x\n", offset * 4, ret); fflush(stdout); |
2114 | 2018 | return ret; |
2115 | 2019 | } |
2116 | 2020 | |
2117 | 2021 | WRITE32_MEMBER( n64_periphs::si_reg_w ) |
2118 | 2022 | { |
2119 | | //printf("si_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); fflush(stdout); |
2120 | 2023 | switch (offset) |
2121 | 2024 | { |
2122 | 2025 | case 0x00/4: // SI_DRAM_ADDR_REG |
r241686 | r241687 | |
2396 | 2299 | return; |
2397 | 2300 | |
2398 | 2301 | device_image_interface *image = dynamic_cast<device_image_interface *>(periphs->m_nvram_image); |
2399 | | //printf("Saving stuff\n"); |
| 2302 | |
2400 | 2303 | UINT8 data[0x30800]; |
2401 | 2304 | memcpy(data, n64_sram, 0x20000); |
2402 | 2305 | memcpy(data + 0x20000, periphs->m_save_data.eeprom, 0x800); |