trunk/src/mame/machine/raiden2cop.c
| r32328 | r32329 | |
| 25 | 25 | cop_itoa(0), |
| 26 | 26 | cop_itoa_digit_count(0), |
| 27 | 27 | m_cop_itoa_unused_digit_value(0x30), |
| 28 | |
| 29 | cop_status(0), |
| 30 | cop_scale(0), |
| 31 | |
| 32 | cop_angle(0), |
| 33 | cop_dist(0), |
| 34 | |
| 35 | cop_angle_target(0), |
| 36 | cop_angle_step(0), |
| 37 | |
| 38 | cop_hit_status(0), |
| 39 | cop_hit_baseadr(0), |
| 40 | cop_sort_ram_addr(0), |
| 41 | cop_sort_lookup(0), |
| 42 | cop_sort_param(0), |
| 43 | |
| 28 | 44 | m_videoramout_cb(*this), |
| 29 | 45 | m_palette(*this, ":palette") |
| 30 | 46 | { |
| r32328 | r32329 | |
| 38 | 54 | memset(cop_dma_size, 0, sizeof(UINT16)*(0x200)); |
| 39 | 55 | |
| 40 | 56 | memset(cop_itoa_digits, 0, sizeof(UINT8)*10); |
| 57 | |
| 58 | memset(cop_regs, 0, sizeof(UINT32)*8); |
| 59 | |
| 60 | |
| 61 | memset(cop_collision_info, 0, sizeof(colinfo)*2); |
| 41 | 62 | } |
| 42 | 63 | |
| 43 | 64 | |
| r32328 | r32329 | |
| 71 | 92 | save_item(NAME(cop_itoa_digit_count)); |
| 72 | 93 | save_item(NAME(cop_itoa_digits)); |
| 73 | 94 | |
| 95 | save_item(NAME(cop_status)); |
| 96 | save_item(NAME(cop_scale)); |
| 97 | |
| 98 | save_item(NAME(cop_angle)); |
| 99 | save_item(NAME(cop_dist)); |
| 100 | |
| 101 | save_item(NAME(cop_angle_target)); |
| 102 | save_item(NAME(cop_angle_step)); |
| 103 | |
| 104 | save_item(NAME(cop_hit_status)); |
| 105 | save_item(NAME(cop_hit_baseadr)); |
| 106 | save_item(NAME(cop_hit_val)); |
| 107 | save_item(NAME(cop_hit_val_stat)); |
| 108 | save_item(NAME(cop_sort_ram_addr)); |
| 109 | save_item(NAME(cop_sort_lookup)); |
| 110 | save_item(NAME(cop_sort_param)); |
| 111 | |
| 112 | save_item(NAME(cop_regs)); |
| 113 | |
| 114 | save_item(NAME(cop_collision_info[0].pos)); |
| 115 | save_item(NAME(cop_collision_info[0].dx)); |
| 116 | save_item(NAME(cop_collision_info[0].size)); |
| 117 | save_item(NAME(cop_collision_info[0].spradr)); |
| 118 | save_item(NAME(cop_collision_info[0].allow_swap)); |
| 119 | save_item(NAME(cop_collision_info[0].flags_swap)); |
| 120 | |
| 121 | save_item(NAME(cop_collision_info[1].pos)); |
| 122 | save_item(NAME(cop_collision_info[1].dx)); |
| 123 | save_item(NAME(cop_collision_info[1].size)); |
| 124 | save_item(NAME(cop_collision_info[1].spradr)); |
| 125 | save_item(NAME(cop_collision_info[1].allow_swap)); |
| 126 | save_item(NAME(cop_collision_info[1].flags_swap)); |
| 127 | |
| 74 | 128 | m_videoramout_cb.resolve_safe(); |
| 75 | 129 | |
| 76 | 130 | cop_itoa_digit_count = 4; //TODO: Raiden 2 never inits the BCD register, value here is a guess (8 digits, as WR is 10.000.000 + a) |
| r32328 | r32329 | |
| 605 | 659 | { |
| 606 | 660 | return cop_itoa_digits[offset*2] | (cop_itoa_digits[offset*2+1] << 8); |
| 607 | 661 | } |
| 662 | |
| 663 | /* Main COP functionality */ |
| 664 | |
| 665 | |
| 666 | READ16_MEMBER( raiden2cop_device::cop_status_r) |
| 667 | { |
| 668 | return cop_status; |
| 669 | } |
| 670 | |
| 671 | READ16_MEMBER( raiden2cop_device::cop_angle_r) |
| 672 | { |
| 673 | return cop_angle; |
| 674 | } |
| 675 | |
| 676 | READ16_MEMBER( raiden2cop_device::cop_dist_r) |
| 677 | { |
| 678 | return cop_dist; |
| 679 | } |
| 680 | |
| 681 | WRITE16_MEMBER( raiden2cop_device::cop_scale_w) |
| 682 | { |
| 683 | COMBINE_DATA(&cop_scale); |
| 684 | cop_scale &= 3; |
| 685 | } |
| 686 | |
| 687 | WRITE16_MEMBER( raiden2cop_device::cop_angle_target_w) |
| 688 | { |
| 689 | COMBINE_DATA(&cop_angle_target); |
| 690 | } |
| 691 | |
| 692 | WRITE16_MEMBER( raiden2cop_device::cop_angle_step_w) |
| 693 | { |
| 694 | COMBINE_DATA(&cop_angle_step); |
| 695 | } |
| 696 | |
| 697 | READ16_MEMBER( raiden2cop_device::cop_reg_high_r) |
| 698 | { |
| 699 | return cop_regs[offset] >> 16; |
| 700 | } |
| 701 | |
| 702 | WRITE16_MEMBER( raiden2cop_device::cop_reg_high_w) |
| 703 | { |
| 704 | cop_regs[offset] = (cop_regs[offset] & ~(mem_mask << 16)) | ((data & mem_mask) << 16); |
| 705 | } |
| 706 | |
| 707 | READ16_MEMBER( raiden2cop_device::cop_reg_low_r) |
| 708 | { |
| 709 | return cop_regs[offset]; |
| 710 | } |
| 711 | |
| 712 | WRITE16_MEMBER( raiden2cop_device::cop_reg_low_w) |
| 713 | { |
| 714 | cop_regs[offset] = (cop_regs[offset] & ~UINT32(mem_mask)) | (data & mem_mask); |
| 715 | } |
| 716 | |
| 717 | WRITE16_MEMBER( raiden2cop_device::cop_hitbox_baseadr_w) |
| 718 | { |
| 719 | COMBINE_DATA(&cop_hit_baseadr); |
| 720 | } |
| 721 | |
| 722 | void raiden2cop_device::cop_collision_read_pos(address_space &space, int slot, UINT32 spradr, bool allow_swap) |
| 723 | { |
| 724 | cop_collision_info[slot].allow_swap = allow_swap; |
| 725 | cop_collision_info[slot].flags_swap = space.read_word(spradr+2); |
| 726 | cop_collision_info[slot].spradr = spradr; |
| 727 | for(int i=0; i<3; i++) |
| 728 | cop_collision_info[slot].pos[i] = space.read_word(spradr+6+4*i); |
| 729 | } |
| 730 | |
| 731 | void raiden2cop_device::cop_collision_update_hitbox(address_space &space, int slot, UINT32 hitadr) |
| 732 | { |
| 733 | UINT32 hitadr2 = space.read_word(hitadr) | (cop_hit_baseadr << 16); |
| 734 | |
| 735 | for(int i=0; i<3; i++) { |
| 736 | cop_collision_info[slot].dx[i] = space.read_byte(hitadr2++); |
| 737 | cop_collision_info[slot].size[i] = space.read_byte(hitadr2++); |
| 738 | } |
| 739 | |
| 740 | cop_hit_status = 7; |
| 741 | |
| 742 | for(int i=0; i<3; i++) { |
| 743 | int min[2], max[2]; |
| 744 | for(int j=0; j<2; j++) { |
| 745 | if(cop_collision_info[j].allow_swap && (cop_collision_info[j].flags_swap & (1 << i))) { |
| 746 | max[j] = cop_collision_info[j].pos[i] - cop_collision_info[j].dx[i]; |
| 747 | min[j] = max[j] - cop_collision_info[j].size[i]; |
| 748 | } else { |
| 749 | min[j] = cop_collision_info[j].pos[i] + cop_collision_info[j].dx[i]; |
| 750 | max[j] = min[j] + cop_collision_info[j].size[i]; |
| 751 | } |
| 752 | } |
| 753 | if(max[0] > min[1] && min[0] < max[1]) |
| 754 | cop_hit_status &= ~(1 << i); |
| 755 | cop_hit_val[i] = cop_collision_info[0].pos[i] - cop_collision_info[1].pos[i]; |
| 756 | } |
| 757 | |
| 758 | cop_hit_val_stat = cop_hit_status ? 0xffff : 0x0000; |
| 759 | } |
| 760 | |
| 761 | WRITE16_MEMBER( raiden2cop_device::cop_cmd_w) |
| 762 | { |
| 763 | cop_status &= 0x7fff; |
| 764 | |
| 765 | switch(data) { |
| 766 | case 0x0205: { // 0205 0006 ffeb 0000 - 0188 0282 0082 0b8e 098e 0000 0000 0000 |
| 767 | int ppos = space.read_dword(cop_regs[0] + 4 + offset*4); |
| 768 | int npos = ppos + space.read_dword(cop_regs[0] + 0x10 + offset*4); |
| 769 | int delta = (npos >> 16) - (ppos >> 16); |
| 770 | space.write_dword(cop_regs[0] + 4 + offset*4, npos); |
| 771 | space.write_word(cop_regs[0] + 0x1e + offset*4, space.read_word(cop_regs[0] + 0x1e + offset*4) + delta); |
| 772 | break; |
| 773 | } |
| 774 | |
| 775 | case 0x0904: { /* X Se Dae and Zero Team uses this variant */ |
| 776 | space.write_dword(cop_regs[0] + 16 + offset*4, space.read_dword(cop_regs[0] + 16 + offset*4) - space.read_dword(cop_regs[0] + 0x28 + offset*4)); |
| 777 | break; |
| 778 | } |
| 779 | case 0x0905: // 0905 0006 fbfb 0008 - 0194 0288 0088 0000 0000 0000 0000 0000 |
| 780 | space.write_dword(cop_regs[0] + 16 + offset*4, space.read_dword(cop_regs[0] + 16 + offset*4) + space.read_dword(cop_regs[0] + 0x28 + offset*4)); |
| 781 | break; |
| 782 | |
| 783 | case 0x130e: // 130e 0005 bf7f 0010 - 0984 0aa4 0d82 0aa2 039b 0b9a 0b9a 0a9a |
| 784 | case 0x138e: |
| 785 | case 0x338e: { // 338e 0005 bf7f 0030 - 0984 0aa4 0d82 0aa2 039c 0b9c 0b9c 0a9a |
| 786 | int dx = space.read_dword(cop_regs[1]+4) - space.read_dword(cop_regs[0]+4); |
| 787 | int dy = space.read_dword(cop_regs[1]+8) - space.read_dword(cop_regs[0]+8); |
| 788 | |
| 789 | if(!dy) { |
| 790 | cop_status |= 0x8000; |
| 791 | cop_angle = 0; |
| 792 | } else { |
| 793 | cop_angle = atan(double(dx)/double(dy)) * 128 / M_PI; |
| 794 | if(dy<0) |
| 795 | cop_angle += 0x80; |
| 796 | } |
| 797 | |
| 798 | if(data & 0x0080) { |
| 799 | space.write_byte(cop_regs[0]+0x34, cop_angle); |
| 800 | } |
| 801 | break; |
| 802 | } |
| 803 | |
| 804 | case 0x2208: |
| 805 | case 0x2288: { // 2208 0005 f5df 0020 - 0f8a 0b8a 0388 0b9a 0b9a 0a9a 0000 0000 |
| 806 | int dx = space.read_word(cop_regs[0]+0x12); |
| 807 | int dy = space.read_word(cop_regs[0]+0x16); |
| 808 | |
| 809 | if(!dy) { |
| 810 | cop_status |= 0x8000; |
| 811 | cop_angle = 0; |
| 812 | } else { |
| 813 | cop_angle = atan(double(dx)/double(dy)) * 128 / M_PI; |
| 814 | if(dy<0) |
| 815 | cop_angle += 0x80; |
| 816 | } |
| 817 | |
| 818 | if(data & 0x0080) { |
| 819 | space.write_byte(cop_regs[0]+0x34, cop_angle); |
| 820 | } |
| 821 | break; |
| 822 | } |
| 823 | |
| 824 | case 0x2a05: { // 2a05 0006 ebeb 0028 - 09af 0a82 0082 0a8f 018e 0000 0000 0000 |
| 825 | int delta = space.read_word(cop_regs[1] + 0x1e + offset*4); |
| 826 | space.write_dword(cop_regs[0] + 4+2 + offset*4, space.read_word(cop_regs[0] + 4+2 + offset*4) + delta); |
| 827 | space.write_dword(cop_regs[0] + 0x1e + offset*4, space.read_word(cop_regs[0] + 0x1e + offset*4) + delta); |
| 828 | break; |
| 829 | } |
| 830 | |
| 831 | case 0x39b0: |
| 832 | case 0x3b30: |
| 833 | case 0x3bb0: { // 3bb0 0004 007f 0038 - 0f9c 0b9c 0b9c 0b9c 0b9c 0b9c 0b9c 099c |
| 834 | /* TODO: these are actually internally loaded via 0x130e command */ |
| 835 | int dx,dy; |
| 836 | |
| 837 | dx = space.read_dword(cop_regs[1]+4) - space.read_dword(cop_regs[0]+4); |
| 838 | dy = space.read_dword(cop_regs[1]+8) - space.read_dword(cop_regs[0]+8); |
| 839 | |
| 840 | dx = dx >> 16; |
| 841 | dy = dy >> 16; |
| 842 | cop_dist = sqrt((double)(dx*dx+dy*dy)); |
| 843 | |
| 844 | if(data & 0x0080) |
| 845 | space.write_word(cop_regs[0]+(data & 0x200 ? 0x3a : 0x38), cop_dist); |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | case 0x42c2: { // 42c2 0005 fcdd 0040 - 0f9a 0b9a 0b9c 0b9c 0b9c 029c 0000 0000 |
| 850 | int div = space.read_word(cop_regs[0]+(0x36)); |
| 851 | if(!div) |
| 852 | div = 1; |
| 853 | |
| 854 | /* TODO: bits 5-6-15 */ |
| 855 | cop_status = 7; |
| 856 | |
| 857 | space.write_word(cop_regs[0]+(0x38), (cop_dist << (5 - cop_scale)) / div); |
| 858 | break; |
| 859 | } |
| 860 | |
| 861 | case 0x4aa0: { // 4aa0 0005 fcdd 0048 - 0f9a 0b9a 0b9c 0b9c 0b9c 099b 0000 0000 |
| 862 | int div = space.read_word(cop_regs[0]+(0x38)); |
| 863 | if(!div) |
| 864 | div = 1; |
| 865 | |
| 866 | /* TODO: bits 5-6-15 */ |
| 867 | cop_status = 7; |
| 868 | |
| 869 | space.write_word(cop_regs[0]+(0x36), (cop_dist << (5 - cop_scale)) / div); |
| 870 | break; |
| 871 | } |
| 872 | |
| 873 | case 0x6200: { |
| 874 | UINT8 angle = space.read_byte(cop_regs[0]+0x34); |
| 875 | UINT16 flags = space.read_word(cop_regs[0]); |
| 876 | cop_angle_target &= 0xff; |
| 877 | cop_angle_step &= 0xff; |
| 878 | flags &= ~0x0004; |
| 879 | int delta = angle - cop_angle_target; |
| 880 | if(delta >= 128) |
| 881 | delta -= 256; |
| 882 | else if(delta < -128) |
| 883 | delta += 256; |
| 884 | if(delta < 0) { |
| 885 | if(delta >= -cop_angle_step) { |
| 886 | angle = cop_angle_target; |
| 887 | flags |= 0x0004; |
| 888 | } else |
| 889 | angle += cop_angle_step; |
| 890 | } else { |
| 891 | if(delta <= cop_angle_step) { |
| 892 | angle = cop_angle_target; |
| 893 | flags |= 0x0004; |
| 894 | } else |
| 895 | angle -= cop_angle_step; |
| 896 | } |
| 897 | space.write_word(cop_regs[0], flags); |
| 898 | space.write_byte(cop_regs[0]+0x34, angle); |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | case 0x8100: { // 8100 0007 fdfb 0080 - 0b9a 0b88 0888 0000 0000 0000 0000 0000 |
| 903 | int raw_angle = (space.read_word(cop_regs[0]+(0x34)) & 0xff); |
| 904 | double angle = raw_angle * M_PI / 128; |
| 905 | double amp = (65536 >> 5)*(space.read_word(cop_regs[0]+(0x36)) & 0xff); |
| 906 | int res; |
| 907 | /* TODO: up direction, why? (check machine/seicop.c) */ |
| 908 | if(raw_angle == 0xc0) |
| 909 | amp*=2; |
| 910 | res = int(amp*sin(angle)) << cop_scale; |
| 911 | space.write_dword(cop_regs[0] + 16, res); |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | case 0x8900: { // 8900 0007 fdfb 0088 - 0b9a 0b8a 088a 0000 0000 0000 0000 0000 |
| 916 | int raw_angle = (space.read_word(cop_regs[0]+(0x34)) & 0xff); |
| 917 | double angle = raw_angle * M_PI / 128; |
| 918 | double amp = (65536 >> 5)*(space.read_word(cop_regs[0]+(0x36)) & 0xff); |
| 919 | int res; |
| 920 | /* TODO: left direction, why? (check machine/seicop.c) */ |
| 921 | if(raw_angle == 0x80) |
| 922 | amp*=2; |
| 923 | res = int(amp*cos(angle)) << cop_scale; |
| 924 | space.write_dword(cop_regs[0] + 20, res); |
| 925 | break; |
| 926 | } |
| 927 | |
| 928 | case 0x5205: // 5205 0006 fff7 0050 - 0180 02e0 03a0 00a0 03a0 0000 0000 0000 |
| 929 | // fprintf(stderr, "sprcpt 5205 %04x %04x %04x %08x %08x\n", cop_regs[0], cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]), space.read_dword(cop_regs[3])); |
| 930 | space.write_dword(cop_regs[1], space.read_dword(cop_regs[0])); |
| 931 | break; |
| 932 | |
| 933 | case 0x5a05: // 5a05 0006 fff7 0058 - 0180 02e0 03a0 00a0 03a0 0000 0000 0000 |
| 934 | // fprintf(stderr, "sprcpt 5a05 %04x %04x %04x %08x %08x\n", cop_regs[0], cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]), space.read_dword(cop_regs[3])); |
| 935 | space.write_dword(cop_regs[1], space.read_dword(cop_regs[0])); |
| 936 | break; |
| 937 | |
| 938 | case 0xf205: // f205 0006 fff7 00f0 - 0182 02e0 03c0 00c0 03c0 0000 0000 0000 |
| 939 | // fprintf(stderr, "sprcpt f205 %04x %04x %04x %08x %08x\n", cop_regs[0]+4, cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]+4), space.read_dword(cop_regs[3])); |
| 940 | space.write_dword(cop_regs[2], space.read_dword(cop_regs[0]+4)); |
| 941 | break; |
| 942 | |
| 943 | // raidendx only |
| 944 | case 0x7e05: |
| 945 | space.write_byte(0x470, space.read_byte(cop_regs[4])); |
| 946 | break; |
| 947 | |
| 948 | case 0xa100: |
| 949 | case 0xa180: |
| 950 | cop_collision_read_pos(space, 0, cop_regs[0], data & 0x0080); |
| 951 | break; |
| 952 | |
| 953 | case 0xa900: |
| 954 | case 0xa980: |
| 955 | cop_collision_read_pos(space, 1, cop_regs[1], data & 0x0080); |
| 956 | break; |
| 957 | |
| 958 | case 0xb100: { |
| 959 | cop_collision_update_hitbox(space, 0, cop_regs[2]); |
| 960 | break; |
| 961 | } |
| 962 | |
| 963 | case 0xb900: { |
| 964 | cop_collision_update_hitbox(space, 1, cop_regs[3]); |
| 965 | break; |
| 966 | } |
| 967 | |
| 968 | default: |
| 969 | logerror("pcall %04x [%x %x %x %x]\n", data, /*rps(), rpc(),*/ cop_regs[0], cop_regs[1], cop_regs[2], cop_regs[3]); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | READ16_MEMBER( raiden2cop_device::cop_collision_status_r) |
| 974 | { |
| 975 | return cop_hit_status; |
| 976 | } |
| 977 | |
| 978 | |
| 979 | READ16_MEMBER( raiden2cop_device::cop_collision_status_val_r) |
| 980 | { |
| 981 | return cop_hit_val[offset]; |
| 982 | } |
| 983 | |
| 984 | READ16_MEMBER( raiden2cop_device::cop_collision_status_stat_r) |
| 985 | { |
| 986 | return cop_hit_val_stat; |
| 987 | } |
| 988 | |
| 989 | WRITE16_MEMBER( raiden2cop_device::cop_sort_lookup_hi_w) |
| 990 | { |
| 991 | cop_sort_lookup = (cop_sort_lookup&0x0000ffff)|(data<<16); |
| 992 | } |
| 993 | |
| 994 | WRITE16_MEMBER( raiden2cop_device::cop_sort_lookup_lo_w) |
| 995 | { |
| 996 | cop_sort_lookup = (cop_sort_lookup&0xffff0000)|(data&0xffff); |
| 997 | } |
| 998 | |
| 999 | WRITE16_MEMBER( raiden2cop_device::cop_sort_ram_addr_hi_w) |
| 1000 | { |
| 1001 | cop_sort_ram_addr = (cop_sort_ram_addr&0x0000ffff)|(data<<16); |
| 1002 | } |
| 1003 | |
| 1004 | WRITE16_MEMBER( raiden2cop_device::cop_sort_ram_addr_lo_w) |
| 1005 | { |
| 1006 | cop_sort_ram_addr = (cop_sort_ram_addr&0xffff0000)|(data&0xffff); |
| 1007 | } |
| 1008 | |
| 1009 | WRITE16_MEMBER( raiden2cop_device::cop_sort_param_w) |
| 1010 | { |
| 1011 | cop_sort_param = data; |
| 1012 | } |
| 1013 | |
| 1014 | WRITE16_MEMBER( raiden2cop_device::cop_sort_dma_trig_w) |
| 1015 | { |
| 1016 | UINT16 sort_size; |
| 1017 | |
| 1018 | sort_size = data; |
| 1019 | |
| 1020 | //printf("%04x %04x %04x %04x\n",cop_sort_ram_addr,cop_sort_lookup,cop_sort_param,data); |
| 1021 | |
| 1022 | { |
| 1023 | int i,j; |
| 1024 | UINT8 xchg_flag; |
| 1025 | UINT32 addri,addrj; |
| 1026 | UINT16 vali,valj; |
| 1027 | |
| 1028 | /* TODO: use a better algorithm than bubble sort! */ |
| 1029 | for(i=2;i<sort_size;i+=2) |
| 1030 | { |
| 1031 | for(j=i-2;j<sort_size;j+=2) |
| 1032 | { |
| 1033 | addri = cop_sort_ram_addr+space.read_word(cop_sort_lookup+i); |
| 1034 | addrj = cop_sort_ram_addr+space.read_word(cop_sort_lookup+j); |
| 1035 | |
| 1036 | vali = space.read_word(addri); |
| 1037 | valj = space.read_word(addrj); |
| 1038 | |
| 1039 | //printf("%08x %08x %04x %04x\n",addri,addrj,vali,valj); |
| 1040 | |
| 1041 | switch(cop_sort_param) |
| 1042 | { |
| 1043 | case 2: xchg_flag = (vali > valj); break; |
| 1044 | case 1: xchg_flag = (vali < valj); break; |
| 1045 | default: xchg_flag = 0; /* printf("Warning: sort-DMA used with param %02x\n",cop_sort_param); */ break; |
| 1046 | } |
| 1047 | |
| 1048 | if(xchg_flag) |
| 1049 | { |
| 1050 | UINT16 xch_val; |
| 1051 | |
| 1052 | xch_val = space.read_word(cop_sort_lookup+i); |
| 1053 | space.write_word(cop_sort_lookup+i,space.read_word(cop_sort_lookup+j)); |
| 1054 | space.write_word(cop_sort_lookup+j,xch_val); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | |
trunk/src/mame/drivers/raiden2.c
| r32328 | r32329 | |
| 173 | 173 | save_item(NAME(raiden2_tilemap_enable)); |
| 174 | 174 | save_item(NAME(prg_bank)); |
| 175 | 175 | save_item(NAME(cop_bank)); |
| 176 | | save_item(NAME(cop_status)); |
| 177 | | save_item(NAME(cop_scale)); |
| 178 | 176 | |
| 179 | | save_item(NAME(cop_angle)); |
| 180 | | save_item(NAME(cop_dist)); |
| 181 | | |
| 182 | | save_item(NAME(cop_angle_target)); |
| 183 | | save_item(NAME(cop_angle_step)); |
| 184 | 177 | save_item(NAME(sprite_prot_x)); |
| 185 | 178 | save_item(NAME(sprite_prot_y)); |
| 186 | 179 | save_item(NAME(dst1)); |
| 187 | 180 | save_item(NAME(cop_spr_maxx)); |
| 188 | 181 | save_item(NAME(cop_spr_off)); |
| 189 | | save_item(NAME(cop_hit_status)); |
| 190 | | save_item(NAME(cop_hit_baseadr)); |
| 191 | | save_item(NAME(cop_hit_val)); |
| 192 | | save_item(NAME(cop_hit_val_stat)); |
| 193 | | save_item(NAME(cop_sort_ram_addr)); |
| 194 | | save_item(NAME(cop_sort_lookup)); |
| 195 | | save_item(NAME(cop_sort_param)); |
| 182 | |
| 196 | 183 | |
| 197 | 184 | save_item(NAME(scrollvals)); |
| 198 | | save_item(NAME(cop_regs)); |
| 199 | 185 | |
| 200 | | |
| 201 | | |
| 202 | 186 | save_item(NAME(sprite_prot_src_addr)); |
| 203 | 187 | |
| 204 | | save_item(NAME(cop_collision_info[0].pos)); |
| 205 | | save_item(NAME(cop_collision_info[0].dx)); |
| 206 | | save_item(NAME(cop_collision_info[0].size)); |
| 207 | | save_item(NAME(cop_collision_info[0].spradr)); |
| 208 | | save_item(NAME(cop_collision_info[0].allow_swap)); |
| 209 | | save_item(NAME(cop_collision_info[0].flags_swap)); |
| 210 | | |
| 211 | | save_item(NAME(cop_collision_info[1].pos)); |
| 212 | | save_item(NAME(cop_collision_info[1].dx)); |
| 213 | | save_item(NAME(cop_collision_info[1].size)); |
| 214 | | save_item(NAME(cop_collision_info[1].spradr)); |
| 215 | | save_item(NAME(cop_collision_info[1].allow_swap)); |
| 216 | | save_item(NAME(cop_collision_info[1].flags_swap)); |
| 217 | 188 | } |
| 218 | 189 | |
| 190 | /* |
| 219 | 191 | UINT16 raiden2_state::rps() |
| 220 | 192 | { |
| 221 | 193 | return m_maincpu->state_int(NEC_CS); |
| r32328 | r32329 | |
| 225 | 197 | { |
| 226 | 198 | return m_maincpu->state_int(NEC_IP); |
| 227 | 199 | } |
| 200 | */ |
| 228 | 201 | |
| 229 | 202 | int cnt=0, ccol = -1; |
| 230 | 203 | |
| r32328 | r32329 | |
| 258 | 231 | } |
| 259 | 232 | |
| 260 | 233 | |
| 261 | | READ16_MEMBER(raiden2_state::cop_status_r) |
| 262 | | { |
| 263 | | return cop_status; |
| 264 | | } |
| 265 | 234 | |
| 266 | | READ16_MEMBER(raiden2_state::cop_angle_r) |
| 267 | | { |
| 268 | | return cop_angle; |
| 269 | | } |
| 270 | | |
| 271 | | READ16_MEMBER(raiden2_state::cop_dist_r) |
| 272 | | { |
| 273 | | return cop_dist; |
| 274 | | } |
| 275 | | |
| 276 | | WRITE16_MEMBER(raiden2_state::cop_scale_w) |
| 277 | | { |
| 278 | | COMBINE_DATA(&cop_scale); |
| 279 | | cop_scale &= 3; |
| 280 | | } |
| 281 | | |
| 282 | | WRITE16_MEMBER(raiden2_state::cop_angle_target_w) |
| 283 | | { |
| 284 | | COMBINE_DATA(&cop_angle_target); |
| 285 | | } |
| 286 | | |
| 287 | | WRITE16_MEMBER(raiden2_state::cop_angle_step_w) |
| 288 | | { |
| 289 | | COMBINE_DATA(&cop_angle_step); |
| 290 | | } |
| 291 | | |
| 292 | | READ16_MEMBER(raiden2_state::cop_reg_high_r) |
| 293 | | { |
| 294 | | return cop_regs[offset] >> 16; |
| 295 | | } |
| 296 | | |
| 297 | | WRITE16_MEMBER(raiden2_state::cop_reg_high_w) |
| 298 | | { |
| 299 | | cop_regs[offset] = (cop_regs[offset] & ~(mem_mask << 16)) | ((data & mem_mask) << 16); |
| 300 | | } |
| 301 | | |
| 302 | | READ16_MEMBER(raiden2_state::cop_reg_low_r) |
| 303 | | { |
| 304 | | return cop_regs[offset]; |
| 305 | | } |
| 306 | | |
| 307 | | WRITE16_MEMBER(raiden2_state::cop_reg_low_w) |
| 308 | | { |
| 309 | | cop_regs[offset] = (cop_regs[offset] & ~UINT32(mem_mask)) | (data & mem_mask); |
| 310 | | } |
| 311 | | |
| 312 | | WRITE16_MEMBER(raiden2_state::cop_hitbox_baseadr_w) |
| 313 | | { |
| 314 | | COMBINE_DATA(&cop_hit_baseadr); |
| 315 | | } |
| 316 | | |
| 317 | | void raiden2_state::cop_collision_read_pos(address_space &space, int slot, UINT32 spradr, bool allow_swap) |
| 318 | | { |
| 319 | | cop_collision_info[slot].allow_swap = allow_swap; |
| 320 | | cop_collision_info[slot].flags_swap = space.read_word(spradr+2); |
| 321 | | cop_collision_info[slot].spradr = spradr; |
| 322 | | for(int i=0; i<3; i++) |
| 323 | | cop_collision_info[slot].pos[i] = space.read_word(spradr+6+4*i); |
| 324 | | } |
| 325 | | |
| 326 | | void raiden2_state::cop_collision_update_hitbox(address_space &space, int slot, UINT32 hitadr) |
| 327 | | { |
| 328 | | UINT32 hitadr2 = space.read_word(hitadr) | (cop_hit_baseadr << 16); |
| 329 | | |
| 330 | | for(int i=0; i<3; i++) { |
| 331 | | cop_collision_info[slot].dx[i] = space.read_byte(hitadr2++); |
| 332 | | cop_collision_info[slot].size[i] = space.read_byte(hitadr2++); |
| 333 | | } |
| 334 | | |
| 335 | | cop_hit_status = 7; |
| 336 | | |
| 337 | | for(int i=0; i<3; i++) { |
| 338 | | int min[2], max[2]; |
| 339 | | for(int j=0; j<2; j++) { |
| 340 | | if(cop_collision_info[j].allow_swap && (cop_collision_info[j].flags_swap & (1 << i))) { |
| 341 | | max[j] = cop_collision_info[j].pos[i] - cop_collision_info[j].dx[i]; |
| 342 | | min[j] = max[j] - cop_collision_info[j].size[i]; |
| 343 | | } else { |
| 344 | | min[j] = cop_collision_info[j].pos[i] + cop_collision_info[j].dx[i]; |
| 345 | | max[j] = min[j] + cop_collision_info[j].size[i]; |
| 346 | | } |
| 347 | | } |
| 348 | | if(max[0] > min[1] && min[0] < max[1]) |
| 349 | | cop_hit_status &= ~(1 << i); |
| 350 | | cop_hit_val[i] = cop_collision_info[0].pos[i] - cop_collision_info[1].pos[i]; |
| 351 | | } |
| 352 | | |
| 353 | | cop_hit_val_stat = cop_hit_status ? 0xffff : 0x0000; |
| 354 | | } |
| 355 | | |
| 356 | | WRITE16_MEMBER(raiden2_state::cop_cmd_w) |
| 357 | | { |
| 358 | | cop_status &= 0x7fff; |
| 359 | | |
| 360 | | switch(data) { |
| 361 | | case 0x0205: { // 0205 0006 ffeb 0000 - 0188 0282 0082 0b8e 098e 0000 0000 0000 |
| 362 | | int ppos = space.read_dword(cop_regs[0] + 4 + offset*4); |
| 363 | | int npos = ppos + space.read_dword(cop_regs[0] + 0x10 + offset*4); |
| 364 | | int delta = (npos >> 16) - (ppos >> 16); |
| 365 | | space.write_dword(cop_regs[0] + 4 + offset*4, npos); |
| 366 | | space.write_word(cop_regs[0] + 0x1e + offset*4, space.read_word(cop_regs[0] + 0x1e + offset*4) + delta); |
| 367 | | break; |
| 368 | | } |
| 369 | | |
| 370 | | case 0x0904: { /* X Se Dae and Zero Team uses this variant */ |
| 371 | | space.write_dword(cop_regs[0] + 16 + offset*4, space.read_dword(cop_regs[0] + 16 + offset*4) - space.read_dword(cop_regs[0] + 0x28 + offset*4)); |
| 372 | | break; |
| 373 | | } |
| 374 | | case 0x0905: // 0905 0006 fbfb 0008 - 0194 0288 0088 0000 0000 0000 0000 0000 |
| 375 | | space.write_dword(cop_regs[0] + 16 + offset*4, space.read_dword(cop_regs[0] + 16 + offset*4) + space.read_dword(cop_regs[0] + 0x28 + offset*4)); |
| 376 | | break; |
| 377 | | |
| 378 | | case 0x130e: // 130e 0005 bf7f 0010 - 0984 0aa4 0d82 0aa2 039b 0b9a 0b9a 0a9a |
| 379 | | case 0x138e: |
| 380 | | case 0x338e: { // 338e 0005 bf7f 0030 - 0984 0aa4 0d82 0aa2 039c 0b9c 0b9c 0a9a |
| 381 | | int dx = space.read_dword(cop_regs[1]+4) - space.read_dword(cop_regs[0]+4); |
| 382 | | int dy = space.read_dword(cop_regs[1]+8) - space.read_dword(cop_regs[0]+8); |
| 383 | | |
| 384 | | if(!dy) { |
| 385 | | cop_status |= 0x8000; |
| 386 | | cop_angle = 0; |
| 387 | | } else { |
| 388 | | cop_angle = atan(double(dx)/double(dy)) * 128 / M_PI; |
| 389 | | if(dy<0) |
| 390 | | cop_angle += 0x80; |
| 391 | | } |
| 392 | | |
| 393 | | if(data & 0x0080) { |
| 394 | | space.write_byte(cop_regs[0]+0x34, cop_angle); |
| 395 | | } |
| 396 | | break; |
| 397 | | } |
| 398 | | |
| 399 | | case 0x2208: |
| 400 | | case 0x2288: { // 2208 0005 f5df 0020 - 0f8a 0b8a 0388 0b9a 0b9a 0a9a 0000 0000 |
| 401 | | int dx = space.read_word(cop_regs[0]+0x12); |
| 402 | | int dy = space.read_word(cop_regs[0]+0x16); |
| 403 | | |
| 404 | | if(!dy) { |
| 405 | | cop_status |= 0x8000; |
| 406 | | cop_angle = 0; |
| 407 | | } else { |
| 408 | | cop_angle = atan(double(dx)/double(dy)) * 128 / M_PI; |
| 409 | | if(dy<0) |
| 410 | | cop_angle += 0x80; |
| 411 | | } |
| 412 | | |
| 413 | | if(data & 0x0080) { |
| 414 | | space.write_byte(cop_regs[0]+0x34, cop_angle); |
| 415 | | } |
| 416 | | break; |
| 417 | | } |
| 418 | | |
| 419 | | case 0x2a05: { // 2a05 0006 ebeb 0028 - 09af 0a82 0082 0a8f 018e 0000 0000 0000 |
| 420 | | int delta = space.read_word(cop_regs[1] + 0x1e + offset*4); |
| 421 | | space.write_dword(cop_regs[0] + 4+2 + offset*4, space.read_word(cop_regs[0] + 4+2 + offset*4) + delta); |
| 422 | | space.write_dword(cop_regs[0] + 0x1e + offset*4, space.read_word(cop_regs[0] + 0x1e + offset*4) + delta); |
| 423 | | break; |
| 424 | | } |
| 425 | | |
| 426 | | case 0x39b0: |
| 427 | | case 0x3b30: |
| 428 | | case 0x3bb0: { // 3bb0 0004 007f 0038 - 0f9c 0b9c 0b9c 0b9c 0b9c 0b9c 0b9c 099c |
| 429 | | /* TODO: these are actually internally loaded via 0x130e command */ |
| 430 | | int dx,dy; |
| 431 | | |
| 432 | | dx = space.read_dword(cop_regs[1]+4) - space.read_dword(cop_regs[0]+4); |
| 433 | | dy = space.read_dword(cop_regs[1]+8) - space.read_dword(cop_regs[0]+8); |
| 434 | | |
| 435 | | dx = dx >> 16; |
| 436 | | dy = dy >> 16; |
| 437 | | cop_dist = sqrt((double)(dx*dx+dy*dy)); |
| 438 | | |
| 439 | | if(data & 0x0080) |
| 440 | | space.write_word(cop_regs[0]+(data & 0x200 ? 0x3a : 0x38), cop_dist); |
| 441 | | break; |
| 442 | | } |
| 443 | | |
| 444 | | case 0x42c2: { // 42c2 0005 fcdd 0040 - 0f9a 0b9a 0b9c 0b9c 0b9c 029c 0000 0000 |
| 445 | | int div = space.read_word(cop_regs[0]+(0x36)); |
| 446 | | if(!div) |
| 447 | | div = 1; |
| 448 | | |
| 449 | | /* TODO: bits 5-6-15 */ |
| 450 | | cop_status = 7; |
| 451 | | |
| 452 | | space.write_word(cop_regs[0]+(0x38), (cop_dist << (5 - cop_scale)) / div); |
| 453 | | break; |
| 454 | | } |
| 455 | | |
| 456 | | case 0x4aa0: { // 4aa0 0005 fcdd 0048 - 0f9a 0b9a 0b9c 0b9c 0b9c 099b 0000 0000 |
| 457 | | int div = space.read_word(cop_regs[0]+(0x38)); |
| 458 | | if(!div) |
| 459 | | div = 1; |
| 460 | | |
| 461 | | /* TODO: bits 5-6-15 */ |
| 462 | | cop_status = 7; |
| 463 | | |
| 464 | | space.write_word(cop_regs[0]+(0x36), (cop_dist << (5 - cop_scale)) / div); |
| 465 | | break; |
| 466 | | } |
| 467 | | |
| 468 | | case 0x6200: { |
| 469 | | UINT8 angle = space.read_byte(cop_regs[0]+0x34); |
| 470 | | UINT16 flags = space.read_word(cop_regs[0]); |
| 471 | | cop_angle_target &= 0xff; |
| 472 | | cop_angle_step &= 0xff; |
| 473 | | flags &= ~0x0004; |
| 474 | | int delta = angle - cop_angle_target; |
| 475 | | if(delta >= 128) |
| 476 | | delta -= 256; |
| 477 | | else if(delta < -128) |
| 478 | | delta += 256; |
| 479 | | if(delta < 0) { |
| 480 | | if(delta >= -cop_angle_step) { |
| 481 | | angle = cop_angle_target; |
| 482 | | flags |= 0x0004; |
| 483 | | } else |
| 484 | | angle += cop_angle_step; |
| 485 | | } else { |
| 486 | | if(delta <= cop_angle_step) { |
| 487 | | angle = cop_angle_target; |
| 488 | | flags |= 0x0004; |
| 489 | | } else |
| 490 | | angle -= cop_angle_step; |
| 491 | | } |
| 492 | | space.write_word(cop_regs[0], flags); |
| 493 | | space.write_byte(cop_regs[0]+0x34, angle); |
| 494 | | break; |
| 495 | | } |
| 496 | | |
| 497 | | case 0x8100: { // 8100 0007 fdfb 0080 - 0b9a 0b88 0888 0000 0000 0000 0000 0000 |
| 498 | | int raw_angle = (space.read_word(cop_regs[0]+(0x34)) & 0xff); |
| 499 | | double angle = raw_angle * M_PI / 128; |
| 500 | | double amp = (65536 >> 5)*(space.read_word(cop_regs[0]+(0x36)) & 0xff); |
| 501 | | int res; |
| 502 | | /* TODO: up direction, why? (check machine/seicop.c) */ |
| 503 | | if(raw_angle == 0xc0) |
| 504 | | amp*=2; |
| 505 | | res = int(amp*sin(angle)) << cop_scale; |
| 506 | | space.write_dword(cop_regs[0] + 16, res); |
| 507 | | break; |
| 508 | | } |
| 509 | | |
| 510 | | case 0x8900: { // 8900 0007 fdfb 0088 - 0b9a 0b8a 088a 0000 0000 0000 0000 0000 |
| 511 | | int raw_angle = (space.read_word(cop_regs[0]+(0x34)) & 0xff); |
| 512 | | double angle = raw_angle * M_PI / 128; |
| 513 | | double amp = (65536 >> 5)*(space.read_word(cop_regs[0]+(0x36)) & 0xff); |
| 514 | | int res; |
| 515 | | /* TODO: left direction, why? (check machine/seicop.c) */ |
| 516 | | if(raw_angle == 0x80) |
| 517 | | amp*=2; |
| 518 | | res = int(amp*cos(angle)) << cop_scale; |
| 519 | | space.write_dword(cop_regs[0] + 20, res); |
| 520 | | break; |
| 521 | | } |
| 522 | | |
| 523 | | case 0x5205: // 5205 0006 fff7 0050 - 0180 02e0 03a0 00a0 03a0 0000 0000 0000 |
| 524 | | // fprintf(stderr, "sprcpt 5205 %04x %04x %04x %08x %08x\n", cop_regs[0], cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]), space.read_dword(cop_regs[3])); |
| 525 | | space.write_dword(cop_regs[1], space.read_dword(cop_regs[0])); |
| 526 | | break; |
| 527 | | |
| 528 | | case 0x5a05: // 5a05 0006 fff7 0058 - 0180 02e0 03a0 00a0 03a0 0000 0000 0000 |
| 529 | | // fprintf(stderr, "sprcpt 5a05 %04x %04x %04x %08x %08x\n", cop_regs[0], cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]), space.read_dword(cop_regs[3])); |
| 530 | | space.write_dword(cop_regs[1], space.read_dword(cop_regs[0])); |
| 531 | | break; |
| 532 | | |
| 533 | | case 0xf205: // f205 0006 fff7 00f0 - 0182 02e0 03c0 00c0 03c0 0000 0000 0000 |
| 534 | | // fprintf(stderr, "sprcpt f205 %04x %04x %04x %08x %08x\n", cop_regs[0]+4, cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]+4), space.read_dword(cop_regs[3])); |
| 535 | | space.write_dword(cop_regs[2], space.read_dword(cop_regs[0]+4)); |
| 536 | | break; |
| 537 | | |
| 538 | | // raidendx only |
| 539 | | case 0x7e05: |
| 540 | | space.write_byte(0x470, space.read_byte(cop_regs[4])); |
| 541 | | break; |
| 542 | | |
| 543 | | case 0xa100: |
| 544 | | case 0xa180: |
| 545 | | cop_collision_read_pos(space, 0, cop_regs[0], data & 0x0080); |
| 546 | | break; |
| 547 | | |
| 548 | | case 0xa900: |
| 549 | | case 0xa980: |
| 550 | | cop_collision_read_pos(space, 1, cop_regs[1], data & 0x0080); |
| 551 | | break; |
| 552 | | |
| 553 | | case 0xb100: { |
| 554 | | cop_collision_update_hitbox(space, 0, cop_regs[2]); |
| 555 | | break; |
| 556 | | } |
| 557 | | |
| 558 | | case 0xb900: { |
| 559 | | cop_collision_update_hitbox(space, 1, cop_regs[3]); |
| 560 | | break; |
| 561 | | } |
| 562 | | |
| 563 | | default: |
| 564 | | logerror("pcall %04x (%04x:%04x) [%x %x %x %x]\n", data, rps(), rpc(), cop_regs[0], cop_regs[1], cop_regs[2], cop_regs[3]); |
| 565 | | } |
| 566 | | } |
| 567 | | |
| 568 | | |
| 569 | 235 | void raiden2_state::combine32(UINT32 *val, int offset, UINT16 data, UINT16 mem_mask) |
| 570 | 236 | { |
| 571 | 237 | UINT16 *dest = (UINT16 *)val + BYTE_XOR_LE(offset); |
| r32328 | r32329 | |
| 1123 | 789 | } |
| 1124 | 790 | } |
| 1125 | 791 | |
| 1126 | | READ16_MEMBER(raiden2_state::cop_collision_status_r) |
| 1127 | | { |
| 1128 | | return cop_hit_status; |
| 1129 | | } |
| 1130 | 792 | |
| 1131 | 793 | WRITE16_MEMBER(raiden2_state::sprite_prot_x_w) |
| 1132 | 794 | { |
| r32328 | r32329 | |
| 1212 | 874 | cop_spr_off = data; |
| 1213 | 875 | } |
| 1214 | 876 | |
| 1215 | | READ16_MEMBER(raiden2_state::cop_collision_status_val_r) |
| 1216 | | { |
| 1217 | | return cop_hit_val[offset]; |
| 1218 | | } |
| 1219 | | |
| 1220 | | READ16_MEMBER(raiden2_state::cop_collision_status_stat_r) |
| 1221 | | { |
| 1222 | | return cop_hit_val_stat; |
| 1223 | | } |
| 1224 | | |
| 1225 | | WRITE16_MEMBER(raiden2_state::cop_sort_lookup_hi_w) |
| 1226 | | { |
| 1227 | | cop_sort_lookup = (cop_sort_lookup&0x0000ffff)|(data<<16); |
| 1228 | | } |
| 1229 | | |
| 1230 | | WRITE16_MEMBER(raiden2_state::cop_sort_lookup_lo_w) |
| 1231 | | { |
| 1232 | | cop_sort_lookup = (cop_sort_lookup&0xffff0000)|(data&0xffff); |
| 1233 | | } |
| 1234 | | |
| 1235 | | WRITE16_MEMBER(raiden2_state::cop_sort_ram_addr_hi_w) |
| 1236 | | { |
| 1237 | | cop_sort_ram_addr = (cop_sort_ram_addr&0x0000ffff)|(data<<16); |
| 1238 | | } |
| 1239 | | |
| 1240 | | WRITE16_MEMBER(raiden2_state::cop_sort_ram_addr_lo_w) |
| 1241 | | { |
| 1242 | | cop_sort_ram_addr = (cop_sort_ram_addr&0xffff0000)|(data&0xffff); |
| 1243 | | } |
| 1244 | | |
| 1245 | | WRITE16_MEMBER(raiden2_state::cop_sort_param_w) |
| 1246 | | { |
| 1247 | | cop_sort_param = data; |
| 1248 | | } |
| 1249 | | |
| 1250 | | WRITE16_MEMBER(raiden2_state::cop_sort_dma_trig_w) |
| 1251 | | { |
| 1252 | | UINT16 sort_size; |
| 1253 | | |
| 1254 | | sort_size = data; |
| 1255 | | |
| 1256 | | //printf("%04x %04x %04x %04x\n",cop_sort_ram_addr,cop_sort_lookup,cop_sort_param,data); |
| 1257 | | |
| 1258 | | { |
| 1259 | | int i,j; |
| 1260 | | UINT8 xchg_flag; |
| 1261 | | UINT32 addri,addrj; |
| 1262 | | UINT16 vali,valj; |
| 1263 | | |
| 1264 | | /* TODO: use a better algorithm than bubble sort! */ |
| 1265 | | for(i=2;i<sort_size;i+=2) |
| 1266 | | { |
| 1267 | | for(j=i-2;j<sort_size;j+=2) |
| 1268 | | { |
| 1269 | | addri = cop_sort_ram_addr+space.read_word(cop_sort_lookup+i); |
| 1270 | | addrj = cop_sort_ram_addr+space.read_word(cop_sort_lookup+j); |
| 1271 | | |
| 1272 | | vali = space.read_word(addri); |
| 1273 | | valj = space.read_word(addrj); |
| 1274 | | |
| 1275 | | //printf("%08x %08x %04x %04x\n",addri,addrj,vali,valj); |
| 1276 | | |
| 1277 | | switch(cop_sort_param) |
| 1278 | | { |
| 1279 | | case 2: xchg_flag = (vali > valj); break; |
| 1280 | | case 1: xchg_flag = (vali < valj); break; |
| 1281 | | default: xchg_flag = 0; /* printf("Warning: sort-DMA used with param %02x\n",cop_sort_param); */ break; |
| 1282 | | } |
| 1283 | | |
| 1284 | | if(xchg_flag) |
| 1285 | | { |
| 1286 | | UINT16 xch_val; |
| 1287 | | |
| 1288 | | xch_val = space.read_word(cop_sort_lookup+i); |
| 1289 | | space.write_word(cop_sort_lookup+i,space.read_word(cop_sort_lookup+j)); |
| 1290 | | space.write_word(cop_sort_lookup+j,xch_val); |
| 1291 | | } |
| 1292 | | } |
| 1293 | | } |
| 1294 | | } |
| 1295 | | } |
| 1296 | | |
| 1297 | 877 | /* MEMORY MAPS */ |
| 1298 | 878 | static ADDRESS_MAP_START( raiden2_cop_mem, AS_PROGRAM, 16, raiden2_state ) |
| 1299 | | AM_RANGE(0x0041c, 0x0041d) AM_WRITE(cop_angle_target_w) // angle target (for 0x6200 COP macro) |
| 1300 | | AM_RANGE(0x0041e, 0x0041f) AM_WRITE(cop_angle_step_w) // angle step (for 0x6200 COP macro) |
| 879 | AM_RANGE(0x0041c, 0x0041d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_angle_target_w) // angle target (for 0x6200 COP macro) |
| 880 | AM_RANGE(0x0041e, 0x0041f) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_angle_step_w) // angle step (for 0x6200 COP macro) |
| 1301 | 881 | AM_RANGE(0x00420, 0x00421) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_low_w) |
| 1302 | 882 | AM_RANGE(0x00422, 0x00423) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_high_w) |
| 1303 | 883 | AM_RANGE(0x00424, 0x00425) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_digit_count_w) |
| r32328 | r32329 | |
| 1305 | 885 | AM_RANGE(0x0042a, 0x0042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w) |
| 1306 | 886 | AM_RANGE(0x00432, 0x00433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w) |
| 1307 | 887 | AM_RANGE(0x00434, 0x00435) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_addr_w) |
| 1308 | | AM_RANGE(0x00436, 0x00437) AM_WRITE(cop_hitbox_baseadr_w) |
| 888 | AM_RANGE(0x00436, 0x00437) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_hitbox_baseadr_w) |
| 1309 | 889 | AM_RANGE(0x00438, 0x00439) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_value_w) |
| 1310 | 890 | AM_RANGE(0x0043a, 0x0043b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_mask_w) |
| 1311 | 891 | AM_RANGE(0x0043c, 0x0043d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_trigger_w) |
| 1312 | | AM_RANGE(0x00444, 0x00445) AM_WRITE(cop_scale_w) |
| 1313 | | AM_RANGE(0x00450, 0x00451) AM_WRITE(cop_sort_ram_addr_hi_w) |
| 1314 | | AM_RANGE(0x00452, 0x00453) AM_WRITE(cop_sort_ram_addr_lo_w) |
| 1315 | | AM_RANGE(0x00454, 0x00455) AM_WRITE(cop_sort_lookup_hi_w) |
| 1316 | | AM_RANGE(0x00456, 0x00457) AM_WRITE(cop_sort_lookup_lo_w) |
| 1317 | | AM_RANGE(0x00458, 0x00459) AM_WRITE(cop_sort_param_w) |
| 892 | AM_RANGE(0x00444, 0x00445) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_scale_w) |
| 893 | AM_RANGE(0x00450, 0x00451) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_ram_addr_hi_w) |
| 894 | AM_RANGE(0x00452, 0x00453) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_ram_addr_lo_w) |
| 895 | AM_RANGE(0x00454, 0x00455) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_lookup_hi_w) |
| 896 | AM_RANGE(0x00456, 0x00457) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_lookup_lo_w) |
| 897 | AM_RANGE(0x00458, 0x00459) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_param_w) |
| 1318 | 898 | AM_RANGE(0x0045a, 0x0045b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pal_brightness_val_w) //palette DMA brightness val, used by X Se Dae / Zero Team |
| 1319 | 899 | AM_RANGE(0x0045c, 0x0045d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pal_brightness_mode_w) //palette DMA brightness mode, used by X Se Dae / Zero Team (sets to 5) |
| 1320 | | AM_RANGE(0x00470, 0x00471) AM_READWRITE(cop_tile_bank_2_r,cop_tile_bank_2_w) |
| 900 | AM_RANGE(0x00470, 0x00471) AM_READWRITE(cop_tile_bank_2_r,cop_tile_bank_2_w) // implementaton of this varies between games, external hookup? |
| 1321 | 901 | |
| 1322 | 902 | AM_RANGE(0x00476, 0x00477) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_adr_rel_w) |
| 1323 | 903 | AM_RANGE(0x00478, 0x00479) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_src_w) |
| 1324 | 904 | AM_RANGE(0x0047a, 0x0047b) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_size_w) |
| 1325 | 905 | AM_RANGE(0x0047c, 0x0047d) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_dst_w) |
| 1326 | 906 | AM_RANGE(0x0047e, 0x0047f) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_dma_mode_r, cop_dma_mode_w) |
| 1327 | | AM_RANGE(0x004a0, 0x004a9) AM_READWRITE(cop_reg_high_r, cop_reg_high_w) |
| 1328 | | AM_RANGE(0x004c0, 0x004c9) AM_READWRITE(cop_reg_low_r, cop_reg_low_w) |
| 1329 | | AM_RANGE(0x00500, 0x00505) AM_WRITE(cop_cmd_w) |
| 1330 | | AM_RANGE(0x00580, 0x00581) AM_READ(cop_collision_status_r) |
| 1331 | | AM_RANGE(0x00582, 0x00587) AM_READ(cop_collision_status_val_r) |
| 1332 | | AM_RANGE(0x00588, 0x00589) AM_READ(cop_collision_status_stat_r) |
| 907 | AM_RANGE(0x004a0, 0x004a9) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_reg_high_r, cop_reg_high_w) |
| 908 | AM_RANGE(0x004c0, 0x004c9) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_reg_low_r, cop_reg_low_w) |
| 909 | AM_RANGE(0x00500, 0x00505) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_cmd_w) |
| 910 | AM_RANGE(0x00580, 0x00581) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_collision_status_r) |
| 911 | AM_RANGE(0x00582, 0x00587) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_collision_status_val_r) |
| 912 | AM_RANGE(0x00588, 0x00589) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_collision_status_stat_r) |
| 1333 | 913 | AM_RANGE(0x00590, 0x00599) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_itoa_digits_r) |
| 1334 | | AM_RANGE(0x005b0, 0x005b1) AM_READ(cop_status_r) |
| 1335 | | AM_RANGE(0x005b2, 0x005b3) AM_READ(cop_dist_r) |
| 1336 | | AM_RANGE(0x005b4, 0x005b5) AM_READ(cop_angle_r) |
| 914 | AM_RANGE(0x005b0, 0x005b1) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_status_r) |
| 915 | AM_RANGE(0x005b2, 0x005b3) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_dist_r) |
| 916 | AM_RANGE(0x005b4, 0x005b5) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_angle_r) |
| 1337 | 917 | |
| 918 | /* I think all this block is part of the video chip */ |
| 1338 | 919 | AM_RANGE(0x00600, 0x0064f) AM_DEVREADWRITE("crtc", seibu_crtc_device, read, write) |
| 1339 | 920 | // AM_RANGE(0x0061c, 0x0061d) AM_WRITE(tilemap_enable_w) |
| 1340 | 921 | // AM_RANGE(0x00620, 0x0062b) AM_WRITE(tile_scroll_w) |
| r32328 | r32329 | |
| 1356 | 937 | AM_RANGE(0x006da, 0x006db) AM_WRITE(sprite_prot_y_w) |
| 1357 | 938 | AM_RANGE(0x006dc, 0x006dd) AM_READWRITE(sprite_prot_maxx_r, sprite_prot_maxx_w) |
| 1358 | 939 | AM_RANGE(0x006de, 0x006df) AM_WRITE(sprite_prot_src_w) |
| 940 | /* end video block */ |
| 941 | |
| 1359 | 942 | AM_RANGE(0x006fc, 0x006fd) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_trigger_w) |
| 1360 | | AM_RANGE(0x006fe, 0x006ff) AM_WRITE(cop_sort_dma_trig_w) // sort-DMA trigger |
| 943 | AM_RANGE(0x006fe, 0x006ff) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_dma_trig_w) // sort-DMA trigger |
| 1361 | 944 | |
| 1362 | 945 | AM_RANGE(0x00762, 0x00763) AM_READ(sprite_prot_dst1_r) |
| 1363 | 946 | ADDRESS_MAP_END |