src/mame/machine/n64.c
| r6173 | r6174 | |
| 2 | 2 | |
| 3 | 3 | #include "driver.h" |
| 4 | 4 | #include "cpu/mips/mips3.h" |
| 5 | #include "cpu/mips/mips3com.h" |
| 5 | 6 | #include "streams.h" |
| 6 | 7 | #include "includes/n64.h" |
| 7 | 8 | #include "sound/dmadac.h" |
| r6173 | r6174 | |
| 38 | 39 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ0, CLEAR_LINE); |
| 39 | 40 | } |
| 40 | 41 | } |
| 42 | UINT8 is64_buffer[0x10000]; |
| 41 | 43 | |
| 44 | READ32_HANDLER( n64_is64_r ) |
| 45 | { |
| 46 | switch(offset) |
| 47 | { |
| 48 | case 0x0000/4: |
| 49 | return 0x49533634; |
| 50 | |
| 51 | case 0x0004/4: |
| 52 | case 0x0008/4: |
| 53 | case 0x000c/4: |
| 54 | case 0x0010/4: |
| 55 | case 0x0014/4: |
| 56 | case 0x0018/4: |
| 57 | case 0x001c/4: |
| 58 | return 0; |
| 59 | |
| 60 | default: |
| 61 | return ( is64_buffer[(offset << 2) + 0] << 24 ) | |
| 62 | ( is64_buffer[(offset << 2) + 1] << 16 ) | |
| 63 | ( is64_buffer[(offset << 2) + 2] << 8 ) | |
| 64 | ( is64_buffer[(offset << 2) + 3] << 0 ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | WRITE32_HANDLER( n64_is64_w ) |
| 69 | { |
| 70 | int i = 0; |
| 71 | |
| 72 | switch(offset) |
| 73 | { |
| 74 | case 0x0014/4: |
| 75 | for(i = 0x20; i < (0x20 + data); i++) |
| 76 | { |
| 77 | printf( "%c", is64_buffer[i] ); |
| 78 | if(is64_buffer[i] == 0x0a) |
| 79 | { |
| 80 | printf( "%c", 0x0d ); |
| 81 | } |
| 82 | is64_buffer[i] = 0; |
| 83 | } |
| 84 | break; |
| 85 | |
| 86 | default: |
| 87 | is64_buffer[(offset << 2) + 0] = (data >> 24) & 0x000000ff; |
| 88 | is64_buffer[(offset << 2) + 1] = (data >> 16) & 0x000000ff; |
| 89 | is64_buffer[(offset << 2) + 2] = (data >> 8) & 0x000000ff; |
| 90 | is64_buffer[(offset << 2) + 3] = (data >> 0) & 0x000000ff; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | READ32_HANDLER( n64_open_r ) |
| 96 | { |
| 97 | UINT32 retval = (offset << 2) & 0x0000ffff; |
| 98 | retval = (retval << 16) | retval; |
| 99 | return retval; |
| 100 | } |
| 101 | |
| 102 | WRITE32_HANDLER( n64_open_w ) |
| 103 | { |
| 104 | // Do nothing |
| 105 | } |
| 106 | |
| 107 | // RDRAM registers |
| 108 | static UINT32 rdram_config; |
| 109 | static UINT32 rdram_device_id; |
| 110 | static UINT32 rdram_delay; |
| 111 | static UINT32 rdram_mode; |
| 112 | static UINT32 rdram_ref_interval; |
| 113 | static UINT32 rdram_ref_row; |
| 114 | static UINT32 rdram_ras_interval; |
| 115 | static UINT32 rdram_min_interval; |
| 116 | static UINT32 rdram_addr_select; |
| 117 | static UINT32 rdram_device_manuf; |
| 118 | |
| 119 | READ32_HANDLER( n64_rdram_reg_r ) |
| 120 | { |
| 121 | switch (offset) |
| 122 | { |
| 123 | case 0x00/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 124 | return rdram_config; |
| 125 | |
| 126 | case 0x04/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 127 | return rdram_device_id; |
| 128 | |
| 129 | case 0x08/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 130 | return rdram_delay; |
| 131 | |
| 132 | case 0x0c/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 133 | return rdram_mode; |
| 134 | |
| 135 | case 0x10/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 136 | return rdram_ref_interval; |
| 137 | |
| 138 | case 0x14/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 139 | return rdram_ref_row; |
| 140 | |
| 141 | case 0x18/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 142 | return rdram_ras_interval; |
| 143 | |
| 144 | case 0x1c/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 145 | return rdram_min_interval; |
| 146 | |
| 147 | case 0x20/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 148 | return rdram_addr_select; |
| 149 | |
| 150 | case 0x24/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 151 | return rdram_device_manuf; |
| 152 | |
| 153 | default: |
| 154 | logerror("rdram_reg_r: %08X, %08X at %08X\n", offset, mem_mask, cpu_get_pc(space->cpu)); |
| 155 | break; |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | WRITE32_HANDLER( n64_rdram_reg_w ) |
| 161 | { |
| 162 | switch (offset) |
| 163 | { |
| 164 | case 0x00/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 165 | rdram_config = data; |
| 166 | break; |
| 167 | |
| 168 | case 0x04/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 169 | rdram_device_id = data; |
| 170 | break; |
| 171 | |
| 172 | case 0x08/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 173 | rdram_delay = data; |
| 174 | break; |
| 175 | |
| 176 | case 0x0c/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 177 | rdram_mode = data; |
| 178 | break; |
| 179 | |
| 180 | case 0x10/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 181 | rdram_ref_interval = data; |
| 182 | break; |
| 183 | |
| 184 | case 0x14/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 185 | rdram_ref_row = data; |
| 186 | break; |
| 187 | |
| 188 | case 0x18/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 189 | rdram_ras_interval = data; |
| 190 | break; |
| 191 | |
| 192 | case 0x1c/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 193 | rdram_min_interval = data; |
| 194 | break; |
| 195 | |
| 196 | case 0x20/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 197 | rdram_addr_select = data; |
| 198 | break; |
| 199 | |
| 200 | case 0x24/4: // RDRAM_CONFIG_REG / RDRAM_DEVICE_TYPE_REG |
| 201 | rdram_device_manuf = data; |
| 202 | break; |
| 203 | |
| 204 | default: |
| 205 | logerror("mi_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Memory Interface (MI) |
| 211 | |
| 212 | UINT32 mi_mode; |
| 213 | |
| 214 | #define MI_CLR_INIT 0x0080 /* Bit 7: clear init mode */ |
| 215 | #define MI_SET_INIT 0x0100 /* Bit 8: set init mode */ |
| 216 | #define MI_CLR_EBUS 0x0200 /* Bit 9: clear ebus test */ |
| 217 | #define MI_SET_EBUS 0x0400 /* Bit 10: set ebus test mode */ |
| 218 | #define MI_CLR_DP_INTR 0x0800 /* Bit 11: clear dp interrupt */ |
| 219 | #define MI_CLR_RDRAM 0x1000 /* Bit 12: clear RDRAM reg */ |
| 220 | #define MI_SET_RDRAM 0x2000 /* Bit 13: set RDRAM reg mode */ |
| 221 | #define MI_MODE_INIT 0x0080 /* Bit 7: init mode */ |
| 222 | #define MI_MODE_EBUS 0x0100 /* Bit 8: ebus test mode */ |
| 223 | #define MI_MODE_RDRAM 0x0200 /* Bit 9: RDRAM reg mode */ |
| 224 | |
| 42 | 225 | READ32_HANDLER( n64_mi_reg_r ) |
| 43 | 226 | { |
| 44 | 227 | switch (offset) |
| 45 | 228 | { |
| 229 | case 0x00/4: // MI_MODE_REG |
| 230 | return mi_mode; |
| 231 | |
| 46 | 232 | case 0x04/4: // MI_VERSION_REG |
| 47 | 233 | return mi_version; |
| 48 | 234 | |
| r6173 | r6174 | |
| 65 | 251 | switch (offset) |
| 66 | 252 | { |
| 67 | 253 | case 0x00/4: // MI_INIT_MODE_REG |
| 68 | | if (data & 0x0800) |
| 254 | if (data & MI_CLR_INIT) mi_mode &= ~MI_MODE_INIT; |
| 255 | if (data & MI_SET_INIT) mi_mode |= MI_MODE_INIT; |
| 256 | if (data & MI_CLR_EBUS) mi_mode &= ~MI_MODE_EBUS; |
| 257 | if (data & MI_SET_EBUS) mi_mode |= MI_MODE_EBUS; |
| 258 | if (data & MI_CLR_RDRAM) mi_mode &= ~MI_MODE_RDRAM; |
| 259 | if (data & MI_SET_RDRAM) mi_mode |= MI_MODE_RDRAM; |
| 260 | if (data & MI_CLR_DP_INTR) |
| 69 | 261 | { |
| 70 | 262 | clear_rcp_interrupt(space->machine, DP_INTERRUPT); |
| 71 | 263 | } |
| r6173 | r6174 | |
| 77 | 269 | |
| 78 | 270 | case 0x0c/4: // MI_INTR_MASK_REG |
| 79 | 271 | { |
| 80 | | if (data & 0x0001) mi_intr_mask &= ~0x1; // clear SP mask |
| 81 | | if (data & 0x0002) mi_intr_mask |= 0x1; // set SP mask |
| 82 | | if (data & 0x0004) mi_intr_mask &= ~0x2; // clear SI mask |
| 83 | | if (data & 0x0008) mi_intr_mask |= 0x2; // set SI mask |
| 84 | | if (data & 0x0010) mi_intr_mask &= ~0x4; // clear AI mask |
| 85 | | if (data & 0x0020) mi_intr_mask |= 0x4; // set AI mask |
| 86 | | if (data & 0x0040) mi_intr_mask &= ~0x8; // clear VI mask |
| 87 | | if (data & 0x0080) mi_intr_mask |= 0x8; // set VI mask |
| 88 | | if (data & 0x0100) mi_intr_mask &= ~0x10; // clear PI mask |
| 89 | | if (data & 0x0200) mi_intr_mask |= 0x10; // set PI mask |
| 90 | | if (data & 0x0400) mi_intr_mask &= ~0x20; // clear DP mask |
| 91 | | if (data & 0x0800) mi_intr_mask |= 0x20; // set DP mask |
| 272 | if (data & 0x0001) |
| 273 | { |
| 274 | mi_intr_mask &= ~0x1; // clear SP mask |
| 275 | } |
| 276 | if (data & 0x0002) |
| 277 | { |
| 278 | mi_intr_mask |= 0x1; // set SP mask |
| 279 | } |
| 280 | if (data & 0x0004) |
| 281 | { |
| 282 | mi_intr_mask &= ~0x2; // clear SI mask |
| 283 | } |
| 284 | if (data & 0x0008) |
| 285 | { |
| 286 | mi_intr_mask |= 0x2; // set SI mask |
| 287 | } |
| 288 | if (data & 0x0010) |
| 289 | { |
| 290 | mi_intr_mask &= ~0x4; // clear AI mask |
| 291 | } |
| 292 | if (data & 0x0020) |
| 293 | { |
| 294 | mi_intr_mask |= 0x4; // set AI mask |
| 295 | } |
| 296 | if (data & 0x0040) |
| 297 | { |
| 298 | mi_intr_mask &= ~0x8; // clear VI mask |
| 299 | } |
| 300 | if (data & 0x0080) |
| 301 | { |
| 302 | mi_intr_mask |= 0x8; // set VI mask |
| 303 | } |
| 304 | if (data & 0x0100) |
| 305 | { |
| 306 | mi_intr_mask &= ~0x10; // clear PI mask |
| 307 | } |
| 308 | if (data & 0x0200) |
| 309 | { |
| 310 | mi_intr_mask |= 0x10; // set PI mask |
| 311 | } |
| 312 | if (data & 0x0400) |
| 313 | { |
| 314 | mi_intr_mask &= ~0x20; // clear DP mask |
| 315 | } |
| 316 | if (data & 0x0800) |
| 317 | { |
| 318 | mi_intr_mask |= 0x20; // set DP mask |
| 319 | } |
| 92 | 320 | break; |
| 93 | 321 | } |
| 94 | 322 | |
| r6173 | r6174 | |
| 128 | 356 | { |
| 129 | 357 | //fatalerror("sp_dma (%s): sp_dma_length unaligned %08X\n", cpu ? "RSP" : "R4300i", sp_dma_length); |
| 130 | 358 | //sp_dma_length = sp_dma_length & ~3; |
| 131 | | sp_dma_length = (sp_dma_length + 3) & ~3; |
| 359 | sp_dma_length = (sp_dma_length + 7) & ~7; |
| 132 | 360 | |
| 133 | 361 | //sp_dma_length &= ~3; |
| 134 | 362 | } |
| r6173 | r6174 | |
| 156 | 384 | |
| 157 | 385 | if ((sp_mem_addr & 0xfff) + (sp_dma_length) > 0x1000) |
| 158 | 386 | { |
| 159 | | fatalerror("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 387 | printf("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 388 | //fatalerror("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 389 | sp_dma_length = 0x1000 - (sp_mem_addr & 0xfff); |
| 160 | 390 | } |
| 161 | 391 | |
| 162 | 392 | if (direction == 0) // RDRAM -> I/DMEM |
| r6173 | r6174 | |
| 242 | 472 | return 0; |
| 243 | 473 | |
| 244 | 474 | case 0x1c/4: // SP_SEMAPHORE_REG |
| 245 | | return sp_semaphore; |
| 475 | if( sp_semaphore ) |
| 476 | { |
| 477 | return 0; |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | sp_semaphore = 1; |
| 482 | return 1; |
| 483 | } |
| 246 | 484 | |
| 247 | 485 | case 0x20/4: // DP_CMD_START |
| 248 | 486 | case 0x24/4: // DP_CMD_END |
| r6173 | r6174 | |
| 443 | 681 | } |
| 444 | 682 | |
| 445 | 683 | case 0x1c/4: // SP_SEMAPHORE_REG |
| 446 | | sp_semaphore = data; |
| 684 | sp_semaphore = 0; |
| 447 | 685 | // mame_printf_debug("sp_semaphore = %08X\n", sp_semaphore); |
| 448 | 686 | break; |
| 449 | 687 | |
| r6173 | r6174 | |
| 555 | 793 | UINT32 n64_vi_width; // This needs to be non-static |
| 556 | 794 | UINT32 n64_vi_origin; |
| 557 | 795 | UINT32 n64_vi_control; |
| 796 | UINT32 n64_vi_blank; |
| 558 | 797 | static UINT32 n64_vi_burst, n64_vi_vsync, n64_vi_hsync, n64_vi_leap, n64_vi_hstart, n64_vi_vstart; |
| 559 | 798 | static UINT32 n64_vi_intr, n64_vi_vburst, n64_vi_xscale, n64_vi_yscale; |
| 560 | 799 | |
| 800 | |
| 801 | static void n64_vi_recalculate_resolution(running_machine *machine) |
| 802 | { |
| 803 | int x_start = (n64_vi_hstart & 0x03ff0000) >> 16; |
| 804 | int x_end = n64_vi_hstart & 0x000003ff; |
| 805 | int y_start = ((n64_vi_vstart & 0x03ff0000) >> 16) / 2; |
| 806 | int y_end = (n64_vi_vstart & 0x000003ff) / 2; |
| 807 | int width = ((n64_vi_xscale & 0x00000fff) * (x_end - x_start)) / 0x400; |
| 808 | int height = ((n64_vi_yscale & 0x00000fff) * (y_end - y_start)) / 0x400; |
| 809 | rectangle visarea = *video_screen_get_visible_area(machine->primary_screen); |
| 810 | attoseconds_t period = video_screen_get_frame_period(machine->primary_screen).attoseconds; |
| 811 | |
| 812 | if (width == 0 || height == 0) |
| 813 | { |
| 814 | n64_vi_blank = 1; |
| 815 | } |
| 816 | else |
| 817 | { |
| 818 | n64_vi_blank = 0; |
| 819 | } |
| 820 | |
| 821 | if (width == 0) |
| 822 | width = 1; |
| 823 | |
| 824 | if (height == 0) |
| 825 | height = 1; |
| 826 | |
| 827 | if (width > 640) |
| 828 | width = 640; |
| 829 | |
| 830 | if (height > 480) |
| 831 | height = 480; |
| 832 | |
| 833 | visarea.max_x = width - 1; |
| 834 | visarea.max_y = height - 1; |
| 835 | video_screen_configure(machine->primary_screen, width, 525, &visarea, period); |
| 836 | } |
| 837 | |
| 561 | 838 | READ32_HANDLER( n64_vi_reg_r ) |
| 562 | 839 | { |
| 563 | 840 | switch (offset) |
| r6173 | r6174 | |
| 615 | 892 | case 0x00/4: // VI_CONTROL_REG |
| 616 | 893 | if ((n64_vi_control & 0x40) != (data & 0x40)) |
| 617 | 894 | { |
| 618 | | int width = video_screen_get_width(space->machine->primary_screen); |
| 619 | | rectangle visarea = *video_screen_get_visible_area(space->machine->primary_screen); |
| 620 | | attoseconds_t period = video_screen_get_frame_period(space->machine->primary_screen).attoseconds; |
| 621 | | |
| 622 | | visarea.max_y = (data & 0x40) ? 479 : 239; |
| 623 | | video_screen_configure(space->machine->primary_screen, width, visarea.max_y + 1, &visarea, period); |
| 895 | n64_vi_recalculate_resolution(space->machine); |
| 624 | 896 | } |
| 625 | 897 | n64_vi_control = data; |
| 626 | 898 | break; |
| r6173 | r6174 | |
| 632 | 904 | case 0x08/4: // VI_WIDTH_REG |
| 633 | 905 | if (n64_vi_width != data && data > 0) |
| 634 | 906 | { |
| 635 | | int height = video_screen_get_height(space->machine->primary_screen); |
| 636 | | rectangle visarea = *video_screen_get_visible_area(space->machine->primary_screen); |
| 637 | | attoseconds_t period = video_screen_get_frame_period(space->machine->primary_screen).attoseconds; |
| 638 | | |
| 639 | | visarea.max_x = data-1; |
| 640 | | video_screen_configure(space->machine->primary_screen, visarea.max_x + 1, height, &visarea, period); |
| 907 | n64_vi_recalculate_resolution(space->machine); |
| 641 | 908 | } |
| 642 | 909 | n64_vi_width = data; |
| 643 | 910 | fb_width = data; |
| r6173 | r6174 | |
| 669 | 936 | |
| 670 | 937 | case 0x24/4: // VI_H_START_REG |
| 671 | 938 | n64_vi_hstart = data; |
| 939 | n64_vi_recalculate_resolution(space->machine); |
| 672 | 940 | break; |
| 673 | 941 | |
| 674 | 942 | case 0x28/4: // VI_V_START_REG |
| 675 | 943 | n64_vi_vstart = data; |
| 944 | n64_vi_recalculate_resolution(space->machine); |
| 676 | 945 | break; |
| 677 | 946 | |
| 678 | 947 | case 0x2c/4: // VI_V_BURST_REG |
| r6173 | r6174 | |
| 681 | 950 | |
| 682 | 951 | case 0x30/4: // VI_X_SCALE_REG |
| 683 | 952 | n64_vi_xscale = data; |
| 953 | n64_vi_recalculate_resolution(space->machine); |
| 684 | 954 | break; |
| 685 | 955 | |
| 686 | 956 | case 0x34/4: // VI_Y_SCALE_REG |
| 687 | 957 | n64_vi_yscale = data; |
| 958 | n64_vi_recalculate_resolution(space->machine); |
| 688 | 959 | break; |
| 689 | 960 | |
| 690 | 961 | /* |
| r6173 | r6174 | |
| 918 | 1189 | |
| 919 | 1190 | static UINT32 pi_dram_addr, pi_cart_addr; |
| 920 | 1191 | static UINT32 pi_first_dma = 1; |
| 1192 | static UINT32 pi_rd_len = 0; |
| 1193 | static UINT32 pi_wr_len = 0; |
| 1194 | static UINT32 pi_status = 0; |
| 1195 | static UINT32 pi_bsd_dom1_lat = 0; |
| 1196 | static UINT32 pi_bsd_dom1_pwd = 0; |
| 1197 | static UINT32 pi_bsd_dom1_pgs = 0; |
| 1198 | static UINT32 pi_bsd_dom1_rls = 0; |
| 1199 | static UINT32 pi_bsd_dom2_lat = 0; |
| 1200 | static UINT32 pi_bsd_dom2_pwd = 0; |
| 1201 | static UINT32 pi_bsd_dom2_pgs = 0; |
| 1202 | static UINT32 pi_bsd_dom2_rls = 0; |
| 921 | 1203 | |
| 922 | 1204 | READ32_HANDLER( n64_pi_reg_r ) |
| 923 | 1205 | { |
| r6173 | r6174 | |
| 930 | 1212 | return pi_cart_addr; |
| 931 | 1213 | |
| 932 | 1214 | case 0x10/4: // PI_STATUS_REG |
| 933 | | return 0; |
| 1215 | return pi_status; |
| 934 | 1216 | |
| 1217 | case 0x14/4: // PI_BSD_DOM1_LAT |
| 1218 | return pi_bsd_dom1_lat; |
| 1219 | |
| 1220 | case 0x18/4: // PI_BSD_DOM1_PWD |
| 1221 | return pi_bsd_dom1_pwd; |
| 1222 | |
| 1223 | case 0x1c/4: // PI_BSD_DOM1_PGS |
| 1224 | return pi_bsd_dom1_pgs; |
| 1225 | |
| 1226 | case 0x20/4: // PI_BSD_DOM1_RLS |
| 1227 | return pi_bsd_dom1_rls; |
| 1228 | |
| 1229 | case 0x24/4: // PI_BSD_DOM2_LAT |
| 1230 | return pi_bsd_dom2_lat; |
| 1231 | |
| 1232 | case 0x28/4: // PI_BSD_DOM2_PWD |
| 1233 | return pi_bsd_dom2_pwd; |
| 1234 | |
| 1235 | case 0x2c/4: // PI_BSD_DOM2_PGS |
| 1236 | return pi_bsd_dom2_pgs; |
| 1237 | |
| 1238 | case 0x30/4: // PI_BSD_DOM2_RLS |
| 1239 | return pi_bsd_dom2_rls; |
| 1240 | |
| 935 | 1241 | default: |
| 936 | 1242 | logerror("pi_reg_r: %08X, %08X at %08X\n", offset, mem_mask, cpu_get_pc(space->cpu)); |
| 937 | 1243 | break; |
| r6173 | r6174 | |
| 959 | 1265 | { |
| 960 | 1266 | int i; |
| 961 | 1267 | UINT32 dma_length = (data + 1); |
| 1268 | pi_rd_len = data; |
| 962 | 1269 | |
| 963 | 1270 | /*if (dma_length & 3) |
| 964 | 1271 | { |
| r6173 | r6174 | |
| 986 | 1293 | { |
| 987 | 1294 | int i; |
| 988 | 1295 | UINT32 dma_length = (data + 1); |
| 1296 | pi_wr_len = data; |
| 989 | 1297 | |
| 990 | 1298 | if (dma_length & 3) |
| 991 | 1299 | { |
| r6173 | r6174 | |
| 1031 | 1339 | break; |
| 1032 | 1340 | } |
| 1033 | 1341 | |
| 1342 | case 0x14/4: // PI_BSD_DOM1_LAT |
| 1343 | pi_bsd_dom1_lat = data; |
| 1344 | break; |
| 1345 | |
| 1346 | case 0x18/4: // PI_BSD_DOM1_PWD |
| 1347 | pi_bsd_dom1_pwd = data; |
| 1348 | break; |
| 1349 | |
| 1350 | case 0x1c/4: // PI_BSD_DOM1_PGS |
| 1351 | pi_bsd_dom1_pgs = data; |
| 1352 | break; |
| 1353 | |
| 1354 | case 0x20/4: // PI_BSD_DOM1_RLS |
| 1355 | pi_bsd_dom1_rls = data; |
| 1356 | break; |
| 1357 | |
| 1358 | case 0x24/4: // PI_BSD_DOM2_LAT |
| 1359 | pi_bsd_dom2_lat = data; |
| 1360 | break; |
| 1361 | |
| 1362 | case 0x28/4: // PI_BSD_DOM2_PWD |
| 1363 | pi_bsd_dom2_pwd = data; |
| 1364 | break; |
| 1365 | |
| 1366 | case 0x2c/4: // PI_BSD_DOM2_PGS |
| 1367 | pi_bsd_dom2_pgs = data; |
| 1368 | break; |
| 1369 | |
| 1370 | case 0x30/4: // PI_BSD_DOM2_RLS |
| 1371 | pi_bsd_dom2_rls = data; |
| 1372 | break; |
| 1373 | |
| 1034 | 1374 | default: |
| 1035 | 1375 | logerror("pi_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); |
| 1036 | 1376 | break; |
| r6173 | r6174 | |
| 1038 | 1378 | } |
| 1039 | 1379 | |
| 1040 | 1380 | // RDRAM Interface |
| 1381 | UINT32 ri_mode = 0; |
| 1382 | UINT32 ri_config = 0; |
| 1383 | UINT32 ri_current_load = 0; |
| 1384 | UINT32 ri_select = 0; |
| 1385 | UINT32 ri_count = 0; |
| 1386 | UINT32 ri_latency = 0; |
| 1387 | UINT32 ri_rerror = 0; |
| 1388 | UINT32 ri_werror = 0; |
| 1389 | |
| 1041 | 1390 | READ32_HANDLER( n64_ri_reg_r ) |
| 1042 | 1391 | { |
| 1392 | //printf( "n64_ri_reg_r: 0x%02x/4 (%08x)\n", offset << 2, mem_mask ); |
| 1043 | 1393 | switch (offset) |
| 1044 | 1394 | { |
| 1395 | case 0x00/4: // RI_MODE_REG |
| 1396 | return ri_mode; |
| 1397 | |
| 1398 | case 0x04/4: // RI_CONFIG_REG |
| 1399 | return ri_config; |
| 1400 | |
| 1401 | case 0x08/4: // RI_CURRENT_LOAD_REG |
| 1402 | return ri_current_load; |
| 1403 | |
| 1404 | case 0x0c/4: // RI_SELECT_REG |
| 1405 | return ri_select; |
| 1406 | |
| 1407 | case 0x10/4: // RI_COUNT_REG |
| 1408 | return ri_count; |
| 1409 | |
| 1410 | case 0x14/4: // RI_LATENCY_REG |
| 1411 | return ri_latency; |
| 1412 | |
| 1413 | case 0x18/4: // RI_RERROR_REG |
| 1414 | return ri_rerror; |
| 1415 | |
| 1416 | case 0x1c/4: // RI_WERROR_REG |
| 1417 | return ri_werror; |
| 1418 | |
| 1045 | 1419 | default: |
| 1046 | 1420 | logerror("ri_reg_r: %08X, %08X at %08X\n", offset, mem_mask, cpu_get_pc(space->cpu)); |
| 1047 | 1421 | break; |
| r6173 | r6174 | |
| 1052 | 1426 | |
| 1053 | 1427 | WRITE32_HANDLER( n64_ri_reg_w ) |
| 1054 | 1428 | { |
| 1429 | //printf( "n64_ri_reg_w: 0x%02x/4 = %08x (%08x)\n", offset << 2, data, mem_mask ); |
| 1055 | 1430 | switch (offset) |
| 1056 | 1431 | { |
| 1432 | case 0x00/4: // RI_MODE_REG |
| 1433 | ri_mode = data; |
| 1434 | break; |
| 1435 | |
| 1436 | case 0x04/4: // RI_CONFIG_REG |
| 1437 | ri_config = data; |
| 1438 | break; |
| 1439 | |
| 1440 | case 0x08/4: // RI_CURRENT_LOAD_REG |
| 1441 | ri_current_load = data; |
| 1442 | break; |
| 1443 | |
| 1444 | case 0x0c/4: // RI_SELECT_REG |
| 1445 | ri_select = data; |
| 1446 | break; |
| 1447 | |
| 1448 | case 0x10/4: // RI_COUNT_REG |
| 1449 | ri_count = data; |
| 1450 | break; |
| 1451 | |
| 1452 | case 0x14/4: // RI_LATENCY_REG |
| 1453 | ri_latency = data; |
| 1454 | break; |
| 1455 | |
| 1456 | case 0x18/4: // RI_RERROR_REG |
| 1457 | ri_rerror = data; |
| 1458 | break; |
| 1459 | |
| 1460 | case 0x1c/4: // RI_WERROR_REG |
| 1461 | ri_werror = data; |
| 1462 | break; |
| 1463 | |
| 1057 | 1464 | default: |
| 1058 | 1465 | logerror("ri_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); |
| 1059 | 1466 | break; |
| r6173 | r6174 | |
| 1065 | 1472 | static UINT8 pif_cmd[0x40]; |
| 1066 | 1473 | static UINT32 si_dram_addr = 0; |
| 1067 | 1474 | static UINT32 si_pif_addr = 0; |
| 1475 | static UINT32 si_pif_addr_rd64b = 0; |
| 1476 | static UINT32 si_pif_addr_wr64b = 0; |
| 1068 | 1477 | static UINT32 si_status = 0; |
| 1069 | 1478 | |
| 1070 | 1479 | static UINT8 eeprom[512]; |
| r6173 | r6174 | |
| 1317 | 1726 | } |
| 1318 | 1727 | //mame_printf_debug("\n"); |
| 1319 | 1728 | |
| 1320 | | rdata[0] = 0; |
| 1729 | //rdata[0] = 0; |
| 1321 | 1730 | |
| 1322 | 1731 | return 1; |
| 1323 | 1732 | } |
| r6173 | r6174 | |
| 1483 | 1892 | { |
| 1484 | 1893 | switch (offset) |
| 1485 | 1894 | { |
| 1486 | | case 0x00/4: // SI_DRAM_ADDR_REG |
| 1487 | | return si_dram_addr; |
| 1895 | //case 0x00/4: // SI_DRAM_ADDR_REG |
| 1896 | //return si_dram_addr; |
| 1488 | 1897 | |
| 1489 | 1898 | case 0x18/4: // SI_STATUS_REG |
| 1490 | 1899 | return si_status; |
| r6173 | r6174 | |
| 1504 | 1913 | case 0x04/4: // SI_PIF_ADDR_RD64B_REG |
| 1505 | 1914 | // PIF RAM -> RDRAM |
| 1506 | 1915 | si_pif_addr = data; |
| 1916 | si_pif_addr_rd64b = data; |
| 1507 | 1917 | pif_dma(space->machine, 0); |
| 1508 | 1918 | break; |
| 1509 | 1919 | |
| 1510 | 1920 | case 0x10/4: // SI_PIF_ADDR_WR64B_REG |
| 1511 | 1921 | // RDRAM -> PIF RAM |
| 1512 | 1922 | si_pif_addr = data; |
| 1923 | si_pif_addr_wr64b = data; |
| 1513 | 1924 | pif_dma(space->machine, 1); |
| 1514 | 1925 | break; |
| 1515 | 1926 | |
| r6173 | r6174 | |
| 1529 | 1940 | READ32_HANDLER( n64_pif_ram_r ) |
| 1530 | 1941 | { |
| 1531 | 1942 | /*mame_printf_debug( "pif_ram_r: %08X, %08X = %08X\n", offset << 2, mem_mask, ( ( pif_ram[offset*4+0] << 24 ) | ( pif_ram[offset*4+1] << 16 ) | ( pif_ram[offset*4+2] << 8 ) | ( pif_ram[offset*4+3] << 0 ) ) & mem_mask );*/ |
| 1532 | | if( offset == ( 0x24 / 4 ) ) |
| 1943 | if(!space->debugger_access) |
| 1533 | 1944 | { |
| 1534 | | cic_status = 0x00000080; |
| 1535 | | } |
| 1536 | | if( offset == ( 0x3C / 4 ) ) |
| 1537 | | { |
| 1538 | | return cic_status; |
| 1539 | | } |
| 1945 | if( offset == ( 0x24 / 4 ) ) |
| 1946 | { |
| 1947 | cic_status = 0x00000080; |
| 1948 | } |
| 1949 | if( offset == ( 0x3C / 4 ) ) |
| 1950 | { |
| 1951 | return cic_status; |
| 1952 | } |
| 1953 | } |
| 1540 | 1954 | return ( ( pif_ram[offset*4+0] << 24 ) | ( pif_ram[offset*4+1] << 16 ) | ( pif_ram[offset*4+2] << 8 ) | ( pif_ram[offset*4+3] << 0 ) ) & mem_mask; |
| 1541 | 1955 | } |
| 1542 | 1956 | |
| 1543 | 1957 | WRITE32_HANDLER( n64_pif_ram_w ) |
| 1544 | 1958 | { |
| 1545 | 1959 | /*mame_printf_debug("pif_ram_w: %08X, %08X, %08X\n", data, offset << 4, mem_mask);*/ |
| 1546 | | /* |
| 1547 | 1960 | if( mem_mask & 0xff000000 ) |
| 1548 | 1961 | { |
| 1549 | 1962 | pif_ram[offset*4+0] = ( data >> 24 ) & 0x000000ff; |
| r6173 | r6174 | |
| 1560 | 1973 | { |
| 1561 | 1974 | pif_ram[offset*4+3] = ( data >> 0 ) & 0x000000ff; |
| 1562 | 1975 | } |
| 1563 | | */ |
| 1564 | 1976 | |
| 1565 | 1977 | signal_rcp_interrupt(space->machine, SI_INTERRUPT); |
| 1566 | 1978 | } |
| r6173 | r6174 | |
| 1646 | 2058 | if (boot_checksum == U64(0x000000d057e84864)) |
| 1647 | 2059 | { |
| 1648 | 2060 | // CIC-NUS-6101 |
| 1649 | | mame_printf_debug("CIC-NUS-6101 detected\n"); |
| 2061 | printf("CIC-NUS-6102 detected\n"); |
| 2062 | pif_ram[0x24] = 0x00; |
| 2063 | pif_ram[0x25] = 0x02; |
| 2064 | pif_ram[0x26] = 0x3f; |
| 2065 | pif_ram[0x27] = 0x3f; |
| 1650 | 2066 | // crc_seed = 0x3f; |
| 2067 | } |
| 2068 | else if (boot_checksum == U64(0x000000cffb830843) || boot_checksum == U64(0x000000d0027fdf31)) |
| 2069 | { |
| 2070 | // CIC-NUS-6103 |
| 2071 | printf("CIC-NUS-6101 detected\n"); |
| 2072 | // crc_seed = 0x78; |
| 1651 | 2073 | pif_ram[0x24] = 0x00; |
| 1652 | | pif_ram[0x25] = 0x04; |
| 2074 | pif_ram[0x25] = 0x06; |
| 1653 | 2075 | pif_ram[0x26] = 0x3f; |
| 1654 | 2076 | pif_ram[0x27] = 0x3f; |
| 1655 | 2077 | } |
| 1656 | 2078 | else if (boot_checksum == U64(0x000000d6499e376b)) |
| 1657 | 2079 | { |
| 1658 | 2080 | // CIC-NUS-6103 |
| 1659 | | mame_printf_debug("CIC-NUS-6103 detected\n"); |
| 2081 | printf("CIC-NUS-6103 detected\n"); |
| 1660 | 2082 | // crc_seed = 0x78; |
| 1661 | 2083 | pif_ram[0x24] = 0x00; |
| 1662 | | pif_ram[0x25] = 0x04; |
| 2084 | pif_ram[0x25] = 0x02; |
| 1663 | 2085 | pif_ram[0x26] = 0x78; |
| 1664 | | pif_ram[0x27] = 0x78; |
| 2086 | pif_ram[0x27] = 0x3f; |
| 1665 | 2087 | } |
| 1666 | 2088 | else if (boot_checksum == U64(0x0000011a4a1604b6)) |
| 1667 | 2089 | { |
| 1668 | 2090 | // CIC-NUS-6105 |
| 1669 | | mame_printf_debug("CIC-NUS-6105 detected\n"); |
| 2091 | printf("CIC-NUS-6105 detected\n"); |
| 1670 | 2092 | // crc_seed = 0x91; |
| 1671 | 2093 | |
| 1672 | 2094 | // first_rsp = 0; |
| 1673 | 2095 | pif_ram[0x24] = 0x00; |
| 1674 | | pif_ram[0x25] = 0x04; |
| 2096 | pif_ram[0x25] = 0x02; |
| 1675 | 2097 | pif_ram[0x26] = 0x91; |
| 1676 | | pif_ram[0x27] = 0x91; |
| 2098 | pif_ram[0x27] = 0x3f; |
| 1677 | 2099 | } |
| 1678 | 2100 | else if (boot_checksum == U64(0x000000d6d5de4ba0)) |
| 1679 | 2101 | { |
| 1680 | 2102 | // CIC-NUS-6106 |
| 1681 | | mame_printf_debug("CIC-NUS-6106 detected\n"); |
| 2103 | printf("CIC-NUS-6106 detected\n"); |
| 1682 | 2104 | // crc_seed = 0x85; |
| 1683 | 2105 | pif_ram[0x24] = 0x00; |
| 1684 | | pif_ram[0x25] = 0x04; |
| 2106 | pif_ram[0x25] = 0x02; |
| 1685 | 2107 | pif_ram[0x26] = 0x85; |
| 1686 | | pif_ram[0x27] = 0x85; |
| 2108 | pif_ram[0x27] = 0x3f; |
| 1687 | 2109 | } |
| 1688 | 2110 | else |
| 1689 | 2111 | { |
| 1690 | | mame_printf_debug("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
| 2112 | printf("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
| 1691 | 2113 | } |
| 1692 | | |
| 1693 | | /* |
| 1694 | | // bootcode differs between CIC-chips, so we can use its checksum to detect the CIC-chip |
| 1695 | | boot_checksum = 0; |
| 1696 | | for (i=0x40; i < 0x1000; i+=4) |
| 1697 | | { |
| 1698 | | boot_checksum += cart[i/4]+i; |
| 1699 | | } |
| 1700 | | |
| 1701 | | if (boot_checksum == U64(0x000000d057e84864)) |
| 1702 | | { |
| 1703 | | // CIC-NUS-6101 |
| 1704 | | mame_printf_debug("CIC-NUS-6101 detected\n"); |
| 1705 | | crc_seed = 0x3f; |
| 1706 | | } |
| 1707 | | else if (boot_checksum == U64(0x000000d6499e376b)) |
| 1708 | | { |
| 1709 | | // CIC-NUS-6103 |
| 1710 | | mame_printf_debug("CIC-NUS-6103 detected\n"); |
| 1711 | | crc_seed = 0x78; |
| 1712 | | } |
| 1713 | | else if (boot_checksum == U64(0x0000011a4a1604b6)) |
| 1714 | | { |
| 1715 | | // CIC-NUS-6105 |
| 1716 | | mame_printf_debug("CIC-NUS-6105 detected\n"); |
| 1717 | | crc_seed = 0x91; |
| 1718 | | |
| 1719 | | first_rsp = 0; |
| 1720 | | } |
| 1721 | | else if (boot_checksum == U64(0x000000d6d5de4ba0)) |
| 1722 | | { |
| 1723 | | // CIC-NUS-6106 |
| 1724 | | mame_printf_debug("CIC-NUS-6106 detected\n"); |
| 1725 | | crc_seed = 0x85; |
| 1726 | | } |
| 1727 | | else |
| 1728 | | { |
| 1729 | | mame_printf_debug("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
| 1730 | | } |
| 1731 | | |
| 1732 | | // The PIF Boot ROM is not dumped, the following code simulates it |
| 1733 | | |
| 1734 | | // clear all registers |
| 1735 | | for (i=1; i < 32; i++) |
| 1736 | | { |
| 1737 | | *pif_rom++ = 0x00000000 | 0 << 21 | 0 << 16 | i << 11 | 0x20; // ADD ri, r0, r0 |
| 1738 | | } |
| 1739 | | |
| 1740 | | // R20 <- 0x00000001 |
| 1741 | | *pif_rom++ = 0x34000000 | 20 << 16 | 0x0001; // ORI r20, r0, 0x0001 |
| 1742 | | |
| 1743 | | // R22 <- 0x0000003F |
| 1744 | | *pif_rom++ = 0x34000000 | 22 << 16 | crc_seed; // ORI r22, r0, 0x003f |
| 1745 | | |
| 1746 | | // R29 <- 0xA4001FF0 |
| 1747 | | *pif_rom++ = 0x3c000000 | 29 << 16 | 0xa400; // LUI r29, 0xa400 |
| 1748 | | *pif_rom++ = 0x34000000 | 29 << 21 | 29 << 16 | 0x1ff0; // ORI r29, r29, 0x1ff0 |
| 1749 | | |
| 1750 | | // clear CP0 registers |
| 1751 | | for (i=0; i < 32; i++) |
| 1752 | | { |
| 1753 | | *pif_rom++ = 0x40000000 | 4 << 21 | 0 << 16 | i << 11; // MTC2 cp0ri, r0 |
| 1754 | | } |
| 1755 | | |
| 1756 | | // Random <- 0x0000001F |
| 1757 | | *pif_rom++ = 0x34000000 | 1 << 16 | 0x001f; |
| 1758 | | *pif_rom++ = 0x40000000 | 4 << 21 | 1 << 16 | 1 << 11; // MTC2 Random, r1 |
| 1759 | | |
| 1760 | | // Status <- 0x70400004 |
| 1761 | | *pif_rom++ = 0x3c000000 | 1 << 16 | 0x7040; // LUI r1, 0x7040 |
| 1762 | | *pif_rom++ = 0x34000000 | 1 << 21 | 1 << 16 | 0x0004; // ORI r1, r1, 0x0004 |
| 1763 | | *pif_rom++ = 0x40000000 | 4 << 21 | 1 << 16 | 12 << 11; // MTC2 Status, r1 |
| 1764 | | |
| 1765 | | // PRId <- 0x00000B00 |
| 1766 | | *pif_rom++ = 0x34000000 | 1 << 16 | 0x0b00; // ORI r1, r0, 0x0b00 |
| 1767 | | *pif_rom++ = 0x40000000 | 4 << 21 | 1 << 16 | 15 << 11; // MTC2 PRId, r1 |
| 1768 | | |
| 1769 | | // Config <- 0x0006E463 |
| 1770 | | *pif_rom++ = 0x3c000000 | 1 << 16 | 0x0006; // LUI r1, 0x0006 |
| 1771 | | *pif_rom++ = 0x34000000 | 1 << 21 | 1 << 16 | 0xe463; // ORI r1, r1, 0xe463 |
| 1772 | | *pif_rom++ = 0x40000000 | 4 << 21 | 1 << 16 | 16 << 11; // MTC2 Config, r1 |
| 1773 | | |
| 1774 | | // (0xa4300004) <- 0x01010101 |
| 1775 | | *pif_rom++ = 0x3c000000 | 1 << 16 | 0x0101; // LUI r1, 0x0101 |
| 1776 | | *pif_rom++ = 0x34000000 | 1 << 21 | 1 << 16 | 0x0101; // ORI r1, r1, 0x0101 |
| 1777 | | *pif_rom++ = 0x3c000000 | 3 << 16 | 0xa430; // LUI r3, 0xa430 |
| 1778 | | *pif_rom++ = 0xac000000 | 3 << 21 | 1 << 16 | 0x0004; // SW r1, 0x0004(r3) |
| 1779 | | |
| 1780 | | // Copy 0xb0000000...1fff -> 0xa4000000...1fff |
| 1781 | | *pif_rom++ = 0x34000000 | 3 << 16 | 0x0400; // ORI r3, r0, 0x0400 |
| 1782 | | *pif_rom++ = 0x3c000000 | 4 << 16 | 0xb000; // LUI r4, 0xb000 |
| 1783 | | *pif_rom++ = 0x3c000000 | 5 << 16 | 0xa400; // LUI r5, 0xa400 |
| 1784 | | *pif_rom++ = 0x8c000000 | 4 << 21 | 1 << 16; // LW r1, 0x0000(r4) |
| 1785 | | *pif_rom++ = 0xac000000 | 5 << 21 | 1 << 16; // SW r1, 0x0000(r5) |
| 1786 | | *pif_rom++ = 0x20000000 | 4 << 21 | 4 << 16 | 0x0004; // ADDI r4, r4, 0x0004 |
| 1787 | | *pif_rom++ = 0x20000000 | 5 << 21 | 5 << 16 | 0x0004; // ADDI r5, r5, 0x0004 |
| 1788 | | *pif_rom++ = 0x20000000 | 3 << 21 | 3 << 16 | 0xffff; // ADDI r3, r3, -1 |
| 1789 | | *pif_rom++ = 0x14000000 | 3 << 21 | 0 << 16 | 0xfffa; // BNE r3, r0, -6 |
| 1790 | | *pif_rom++ = 0x00000000; |
| 1791 | | |
| 1792 | | *pif_rom++ = 0x34000000 | 3 << 16 | 0x0000; // ORI r3, r0, 0x0000 |
| 1793 | | *pif_rom++ = 0x34000000 | 4 << 16 | 0x0000; // ORI r4, r0, 0x0000 |
| 1794 | | *pif_rom++ = 0x34000000 | 5 << 16 | 0x0000; // ORI r5, r0, 0x0000 |
| 1795 | | |
| 1796 | | // Zelda and DK64 need these |
| 1797 | | *pif_rom++ = 0x3c000000 | 9 << 16 | 0xa400; |
| 1798 | | *pif_rom++ = 0x34000000 | 9 << 21 | 9 << 16 | 0x1ff0; |
| 1799 | | *pif_rom++ = 0x3c000000 | 11 << 16 | 0xa400; |
| 1800 | | *pif_rom++ = 0x3c000000 | 31 << 16 | 0xffff; |
| 1801 | | *pif_rom++ = 0x34000000 | 31 << 21 | 31 << 16 | 0xffff; |
| 1802 | | |
| 1803 | | *pif_rom++ = 0x3c000000 | 1 << 16 | 0xa400; // LUI r1, 0xa400 |
| 1804 | | *pif_rom++ = 0x34000000 | 1 << 21 | 1 << 16 | 0x0040; // ORI r1, r1, 0x0040 |
| 1805 | | *pif_rom++ = 0x00000000 | 1 << 21 | 0x8; // JR r1 |
| 1806 | | */ |
| 1807 | 2114 | } |
src/mame/video/n64.c
| r6173 | r6174 | |
| 13 | 13 | static int rdp_cmd_ptr = 0; |
| 14 | 14 | static int rdp_cmd_cur = 0; |
| 15 | 15 | |
| 16 | #define RDP_CVG_SPAN_MAX 1024 |
| 17 | |
| 16 | 18 | typedef struct |
| 17 | 19 | { |
| 18 | 20 | int lx, rx; |
| r6173 | r6174 | |
| 24 | 26 | int b, db; |
| 25 | 27 | int a, da; |
| 26 | 28 | int z, dz; |
| 29 | UINT8 cvg[RDP_CVG_SPAN_MAX]; |
| 27 | 30 | } SPAN; |
| 28 | 31 | |
| 29 | | static SPAN span[1024]; |
| 32 | UINT8 cvg_mem[8*1048576]; |
| 30 | 33 | |
| 34 | static SPAN span[4096]; |
| 35 | |
| 31 | 36 | /*****************************************************************************/ |
| 32 | 37 | |
| 33 | 38 | #define BYTE_ADDR_XOR BYTE4_XOR_BE(0) |
| r6173 | r6174 | |
| 110 | 115 | int blend_m2a_1; |
| 111 | 116 | int blend_m2b_0; |
| 112 | 117 | int blend_m2b_1; |
| 118 | int tex_edge; |
| 113 | 119 | int force_blend; |
| 114 | 120 | int alpha_cvg_select; |
| 115 | 121 | int cvg_times_alpha; |
| r6173 | r6174 | |
| 137 | 143 | #define CYCLE_TYPE_COPY 2 |
| 138 | 144 | #define CYCLE_TYPE_FILL 3 |
| 139 | 145 | |
| 146 | #define SAMPLE_TYPE_1x1 0 |
| 147 | #define SAMPLE_TYPE_2x2 1 |
| 148 | |
| 140 | 149 | static COMBINE_MODES combine; |
| 141 | 150 | static OTHER_MODES other_modes; |
| 142 | 151 | |
| r6173 | r6174 | |
| 181 | 190 | static UINT8 *blender2a_b[2]; |
| 182 | 191 | static UINT8 *blender2b_a[2]; |
| 183 | 192 | |
| 184 | | |
| 185 | 193 | static COLOR pixel_color; |
| 186 | 194 | static COLOR inv_pixel_color; |
| 187 | 195 | static COLOR blended_pixel_color; |
| 188 | 196 | static COLOR memory_color; |
| 189 | 197 | |
| 190 | | |
| 191 | | |
| 192 | 198 | static UINT32 fill_color; // packed 16-bit or 32-bit, depending on framebuffer format |
| 193 | 199 | |
| 194 | 200 | static UINT16 primitive_z; |
| r6173 | r6174 | |
| 213 | 219 | static UINT8 *texture_cache; |
| 214 | 220 | static UINT32 tlut[256]; |
| 215 | 221 | |
| 216 | | #define MASK(S, T) \ |
| 217 | | do \ |
| 218 | | { \ |
| 219 | | if (mask_s != 0) \ |
| 220 | | { \ |
| 221 | | S &= (((UINT32)(0xffffffff) >> (32-mask_s))); \ |
| 222 | | } \ |
| 223 | | if (mask_t != 0) \ |
| 224 | | { \ |
| 225 | | T &= (((UINT32)(0xffffffff) >> (32-mask_t))); \ |
| 226 | | } \ |
| 227 | | } \ |
| 222 | #define MASK(S, T, CYCLE) \ |
| 223 | do \ |
| 224 | { \ |
| 225 | if (mask_s[CYCLE] != 0) \ |
| 226 | { \ |
| 227 | S &= (1 << mask_s[CYCLE]) - 1; \ |
| 228 | } \ |
| 229 | if (mask_t[CYCLE] != 0) \ |
| 230 | { \ |
| 231 | T &= (1 << mask_t[CYCLE]) - 1; \ |
| 232 | } \ |
| 233 | } \ |
| 228 | 234 | while (0) |
| 229 | 235 | |
| 230 | | #define CLAMP(S, T) \ |
| 231 | | do \ |
| 232 | | { \ |
| 233 | | if (clamp_s) \ |
| 234 | | { \ |
| 235 | | if (S < (tsl >> 2)) S = (tsl >> 2); \ |
| 236 | | if (S > (tsh >> 2)) S = (tsh >> 2); \ |
| 237 | | } \ |
| 238 | | if (mirror_s) \ |
| 239 | | { \ |
| 240 | | if (S < (tsl >> 2)) S = abs(S - (tsl >> 2)); \ |
| 241 | | if (S > (tsh >> 2)) S = abs(S - (tsh >> 2)); \ |
| 242 | | } \ |
| 243 | | if (clamp_t) \ |
| 244 | | { \ |
| 245 | | if (T < (ttl >> 2)) T = (ttl >> 2); \ |
| 246 | | if (T > (tth >> 2)) T = (tth >> 2); \ |
| 247 | | } \ |
| 248 | | if (mirror_t) \ |
| 249 | | { \ |
| 250 | | if (T < (ttl >> 2)) T = abs(T - (ttl >> 2)); \ |
| 251 | | if (T > (tth >> 2)) T = abs(T - (tth >> 2)); \ |
| 252 | | } \ |
| 253 | | } \ |
| 236 | #define CLAMP(S, T, CYCLE) \ |
| 237 | do \ |
| 238 | { \ |
| 239 | if (mask_s[CYCLE] != 0 && clamp_s[CYCLE]) \ |
| 240 | { \ |
| 241 | if (S < (tsl[CYCLE] >> 2)) S = (tsl[CYCLE] >> 2); \ |
| 242 | if (S > (tsh[CYCLE] >> 2)) S = (tsh[CYCLE] >> 2); \ |
| 243 | } \ |
| 244 | if (mask_s[CYCLE] != 0 && mirror_s[CYCLE]) \ |
| 245 | { \ |
| 246 | if (S & (1 << mask_s[CYCLE])) S ^= (1 << mask_s[CYCLE]) - 1; \ |
| 247 | } \ |
| 248 | if (mask_t[CYCLE] != 0 && clamp_t[CYCLE]) \ |
| 249 | { \ |
| 250 | if (T < (ttl[CYCLE] >> 2)) T = (ttl[CYCLE] >> 2); \ |
| 251 | if (T > (tth[CYCLE] >> 2)) T = (tth[CYCLE] >> 2); \ |
| 252 | } \ |
| 253 | if (mask_t[CYCLE] != 0 && mirror_t[CYCLE]) \ |
| 254 | { \ |
| 255 | if (T & (1 << mask_t[CYCLE])) T ^= (1 << mask_t[CYCLE]) - 1; \ |
| 256 | } \ |
| 257 | } \ |
| 254 | 258 | while (0) |
| 255 | 259 | |
| 256 | 260 | /*****************************************************************************/ |
| r6173 | r6174 | |
| 292 | 296 | blender2b_a[0] = blender2b_a[1] = &pixel_color.r; |
| 293 | 297 | } |
| 294 | 298 | |
| 299 | static void vi_filter_16( INT32 x, INT32 y, UINT16 *out ) |
| 300 | { |
| 301 | UINT8 *cvg_buffer = &cvg_mem[n64_vi_origin / 4]; |
| 302 | UINT16 *frame_buffer = (UINT16*)&rdram[n64_vi_origin / 4]; |
| 303 | INT32 i_start = x - 2; |
| 304 | INT32 i_end = x + 2; |
| 305 | INT32 j_start = y - 1; |
| 306 | INT32 j_end = y + 1; |
| 307 | INT32 r_sum = 0; |
| 308 | INT32 g_sum = 0; |
| 309 | INT32 b_sum = 0; |
| 310 | INT32 covered_count = 0; |
| 311 | INT32 i = 0; |
| 312 | INT32 j = 0; |
| 313 | |
| 314 | if (cvg_buffer[y*fb_width + x] == 8) |
| 315 | { |
| 316 | *out = frame_buffer[y*fb_width + x]; |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | if (i_start < 0) |
| 321 | { |
| 322 | i_start = 0; |
| 323 | } |
| 324 | if (j_start < 0) |
| 325 | { |
| 326 | j_start = 0; |
| 327 | } |
| 328 | if (i_end >= fb_width) |
| 329 | { |
| 330 | i_end = fb_width - 1; |
| 331 | } |
| 332 | if (j_end >= ((n64_vi_control & 0x40) ? 480 : 240)) |
| 333 | { |
| 334 | j_end = (n64_vi_control & 0x40) ? 479 : 239; |
| 335 | } |
| 336 | |
| 337 | for (j = j_start; j <= j_end; j++) |
| 338 | { |
| 339 | for (i = i_start; i <= i_end; i++) |
| 340 | { |
| 341 | if (cvg_buffer[j*fb_width + x] == 8) |
| 342 | { |
| 343 | UINT16 color = frame_buffer[j*fb_width + x]; |
| 344 | covered_count++; |
| 345 | r_sum += (color >> 11) & 0x1f; |
| 346 | g_sum += (color >> 6) & 0x1f; |
| 347 | b_sum += (color >> 1) & 0x1f; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if (covered_count) |
| 353 | { |
| 354 | UINT16 fb = frame_buffer[y*fb_width + x]; |
| 355 | r_sum /= covered_count; |
| 356 | g_sum /= covered_count; |
| 357 | b_sum /= covered_count; |
| 358 | if (r_sum > 0x1f) r_sum = 0x1f; |
| 359 | if (g_sum > 0x1f) g_sum = 0x1f; |
| 360 | if (b_sum > 0x1f) b_sum = 0x1f; |
| 361 | r_sum = (UINT32)(((float)r_sum / 8.0f) * (float)(8 - cvg_buffer[y*fb_width + x]) + |
| 362 | ((float)((fb >> 11) & 0x1f) / 8.0f) * (float)cvg_buffer[y*fb_width + x]); |
| 363 | g_sum = (UINT32)(((float)g_sum / 8.0f) * (float)(8 - cvg_buffer[y*fb_width + x]) + |
| 364 | ((float)((fb >> 6) & 0x1f) / 8.0f) * (float)cvg_buffer[y*fb_width + x]); |
| 365 | b_sum = (UINT32)(((float)b_sum / 8.0f) * (float)(8 - cvg_buffer[y*fb_width + x]) + |
| 366 | ((float)((fb >> 1) & 0x1f) / 8.0f) * (float)cvg_buffer[y*fb_width + x]); |
| 367 | *out = (r_sum << 11) | (g_sum << 6) | (b_sum << 1); |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | *out = frame_buffer[y*fb_width + x]; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static void vi_filter_32( INT32 x, INT32 y, UINT32 *out ) |
| 376 | { |
| 377 | UINT8 *cvg_buffer = &cvg_mem[n64_vi_origin / 4]; |
| 378 | UINT32 *frame_buffer = (UINT32*)&rdram[n64_vi_origin / 4]; |
| 379 | INT32 i_start = x - 2; |
| 380 | INT32 i_end = x + 2; |
| 381 | INT32 j_start = y - 1; |
| 382 | INT32 j_end = y + 1; |
| 383 | UINT32 r_sum = 0; |
| 384 | UINT32 g_sum = 0; |
| 385 | UINT32 b_sum = 0; |
| 386 | INT32 covered_count = 0; |
| 387 | INT32 i = 0; |
| 388 | INT32 j = 0; |
| 389 | |
| 390 | if (cvg_buffer[y*fb_width + x] == 8) |
| 391 | { |
| 392 | *out = frame_buffer[y*fb_width + x]; |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | if (i_start < 0) |
| 397 | { |
| 398 | i_start = 0; |
| 399 | } |
| 400 | if (j_start < 0) |
| 401 | { |
| 402 | j_start = 0; |
| 403 | } |
| 404 | if (i_end >= fb_width) |
| 405 | { |
| 406 | i_end = fb_width - 1; |
| 407 | } |
| 408 | if (j_end >= ((n64_vi_control & 0x40) ? 480 : 240)) |
| 409 | { |
| 410 | j_end = (n64_vi_control & 0x40) ? 479 : 239; |
| 411 | } |
| 412 | |
| 413 | for (j = j_start; j <= j_end; j++) |
| 414 | { |
| 415 | for (i = i_start; i <= i_end; i++) |
| 416 | { |
| 417 | if (cvg_buffer[j*fb_width + x] == 8) |
| 418 | { |
| 419 | UINT32 color = frame_buffer[j*fb_width + x]; |
| 420 | covered_count++; |
| 421 | r_sum += (color >> 16) & 0xff; |
| 422 | g_sum += (color >> 8) & 0xff; |
| 423 | b_sum += (color >> 0) & 0xff; |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | if (covered_count) |
| 429 | { |
| 430 | r_sum /= covered_count; |
| 431 | g_sum /= covered_count; |
| 432 | b_sum /= covered_count; |
| 433 | if (r_sum > 0xff) r_sum = 0xff; |
| 434 | if (g_sum > 0xff) g_sum = 0xff; |
| 435 | if (b_sum > 0xff) b_sum = 0xff; |
| 436 | *out = (r_sum << 24) | (g_sum << 16) | (b_sum << 8) | 0xe0; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | *out = frame_buffer[y*fb_width + x]; |
| 441 | } |
| 442 | } |
| 443 | |
| 295 | 444 | VIDEO_UPDATE(n64) |
| 296 | 445 | { |
| 297 | 446 | int i, j; |
| 298 | 447 | int height = (n64_vi_control & 0x40) ? 479 : 239; |
| 299 | 448 | |
| 449 | if (n64_vi_blank) |
| 450 | { |
| 451 | for (j=0; j <height; j++) |
| 452 | { |
| 453 | UINT32 *d = BITMAP_ADDR32(bitmap, j, 0); |
| 454 | for (i=0; i < fb_width; i++) |
| 455 | { |
| 456 | d[BYTE_XOR_BE(i)] = 0; |
| 457 | } |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 300 | 462 | switch (n64_vi_control & 0x3) |
| 301 | 463 | { |
| 302 | 464 | case 0: // blank/no signal |
| r6173 | r6174 | |
| 309 | 471 | UINT16 *frame_buffer = (UINT16*)&rdram[n64_vi_origin / 4]; |
| 310 | 472 | if (frame_buffer) |
| 311 | 473 | { |
| 312 | | for (j=0; j <height; j++) |
| 474 | for (j=0; j <= height; j++) |
| 313 | 475 | { |
| 314 | 476 | UINT32 *d = BITMAP_ADDR32(bitmap, j, 0); |
| 315 | 477 | for (i=0; i < fb_width; i++) |
| 316 | 478 | { |
| 317 | | UINT16 pix = *frame_buffer++; |
| 318 | | int r = ((pix >> 11) & 0x1f) << 3; |
| 319 | | int g = ((pix >> 6) & 0x1f) << 3; |
| 320 | | int b = ((pix >> 1) & 0x1f) << 3; |
| 479 | //UINT16 pix = *frame_buffer++; |
| 480 | UINT16 pix = 0; |
| 481 | int r, g, b; |
| 482 | vi_filter_16( i, j, &pix ); |
| 483 | r = ((pix >> 11) & 0x1f) << 3; |
| 484 | g = ((pix >> 6) & 0x1f) << 3; |
| 485 | b = ((pix >> 1) & 0x1f) << 3; |
| 321 | 486 | d[BYTE_XOR_BE(i)] = (r << 16) | (g << 8) | b; |
| 322 | 487 | } |
| 323 | 488 | } |
| r6173 | r6174 | |
| 330 | 495 | UINT32 *frame_buffer = (UINT32*)&rdram[n64_vi_origin / 4]; |
| 331 | 496 | if (frame_buffer) |
| 332 | 497 | { |
| 333 | | for (j=0; j < height; j++) |
| 498 | for (j=0; j <= height; j++) |
| 334 | 499 | { |
| 335 | 500 | UINT32 *d = BITMAP_ADDR32(bitmap, j, 0); |
| 336 | 501 | for (i=0; i < fb_width; i++) |
| 337 | 502 | { |
| 338 | | UINT32 pix = *frame_buffer++; |
| 339 | | *d++ = pix & 0xffffff; |
| 503 | //UINT32 pix = *frame_buffer++; |
| 504 | UINT32 pix = 0; |
| 505 | vi_filter_32( i, j, &pix ); |
| 506 | *d++ = (pix >> 8) & 0x00ffffff; |
| 340 | 507 | } |
| 341 | 508 | } |
| 342 | 509 | } |
| r6173 | r6174 | |
| 468 | 635 | COLOR c; |
| 469 | 636 | UINT32 r, g, b, a; |
| 470 | 637 | |
| 471 | | r = (((int)((UINT8)(*combiner_rgbsub_a_r[cycle]) - (UINT8)(*combiner_rgbsub_b_r[cycle])) * |
| 472 | | *combiner_rgbmul_r[cycle]) >> 8) + *combiner_rgbadd_r[cycle]; |
| 638 | r = (((UINT32)((UINT32)(*combiner_rgbsub_a_r[cycle]) - (UINT32)(*combiner_rgbsub_b_r[cycle])) * |
| 639 | *combiner_rgbmul_r[cycle]) >> 8); |
| 473 | 640 | |
| 474 | | g = (((int)((UINT8)(*combiner_rgbsub_a_g[cycle]) - (UINT8)(*combiner_rgbsub_b_g[cycle])) * |
| 475 | | *combiner_rgbmul_g[cycle]) >> 8) + *combiner_rgbadd_g[cycle]; |
| 641 | g = (((UINT32)((UINT32)(*combiner_rgbsub_a_g[cycle]) - (UINT32)(*combiner_rgbsub_b_g[cycle])) * |
| 642 | *combiner_rgbmul_g[cycle]) >> 8); |
| 476 | 643 | |
| 477 | | b = (((int)((UINT8)(*combiner_rgbsub_a_b[cycle]) - (UINT8)(*combiner_rgbsub_b_b[cycle])) * |
| 478 | | *combiner_rgbmul_b[cycle]) >> 8) + *combiner_rgbadd_b[cycle]; |
| 644 | b = (((UINT32)((UINT32)(*combiner_rgbsub_a_b[cycle]) - (UINT32)(*combiner_rgbsub_b_b[cycle])) * |
| 645 | *combiner_rgbmul_b[cycle]) >> 8); |
| 479 | 646 | |
| 480 | | a = (((int)((UINT8)(*combiner_alphasub_a[cycle]) - (UINT8)(*combiner_alphasub_b[cycle])) * |
| 481 | | *combiner_alphamul[cycle]) >> 8) + *combiner_alphaadd[cycle]; |
| 647 | a = (((UINT32)((UINT32)(*combiner_alphasub_a[cycle]) - (UINT32)(*combiner_alphasub_b[cycle])) * |
| 648 | *combiner_alphamul[cycle]) >> 8); |
| 482 | 649 | |
| 483 | | if (r > 255) r = 255; |
| 484 | | if (g > 255) g = 255; |
| 485 | | if (b > 255) b = 255; |
| 486 | | if (a > 255) a = 255; |
| 650 | if (r & 0xffffff00) |
| 651 | { |
| 652 | if(r & 0x00000080) |
| 653 | { |
| 654 | r = 0; |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | r = 255; |
| 659 | } |
| 660 | } |
| 661 | if (g & 0xffffff00) |
| 662 | { |
| 663 | if(g & 0x00000080) |
| 664 | { |
| 665 | g = 0; |
| 666 | } |
| 667 | else |
| 668 | { |
| 669 | g = 255; |
| 670 | } |
| 671 | } |
| 672 | if (b & 0xffffff00) |
| 673 | { |
| 674 | if(b & 0x00000080) |
| 675 | { |
| 676 | b = 0; |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | b = 255; |
| 681 | } |
| 682 | } |
| 683 | if (a & 0xffffff00) |
| 684 | { |
| 685 | if(a & 0x00000080) |
| 686 | { |
| 687 | a = 0; |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | a = 255; |
| 692 | } |
| 693 | } |
| 487 | 694 | |
| 488 | | c.r = r; c.g = g; c.b = b; c.a = a; |
| 489 | | return c; |
| 490 | | } |
| 695 | c.r = r; c.g = g; c.b = b; c.a = a; |
| 491 | 696 | |
| 697 | r += *combiner_rgbadd_r[cycle]; |
| 698 | g += *combiner_rgbadd_g[cycle]; |
| 699 | b += *combiner_rgbadd_b[cycle]; |
| 700 | a += *combiner_alphaadd[cycle]; |
| 492 | 701 | |
| 702 | r &= 0x000000ff; |
| 703 | g &= 0x000000ff; |
| 704 | b &= 0x000000ff; |
| 705 | a &= 0x000000ff; |
| 493 | 706 | |
| 707 | /* |
| 708 | if (r > 255) r = 255; |
| 709 | if (g > 255) g = 255; |
| 710 | if (b > 255) b = 255; |
| 711 | if (a > 255) a = 255; |
| 712 | */ |
| 713 | |
| 714 | c.r = r; c.g = g; c.b = b; c.a = a; |
| 715 | |
| 716 | combined_color.r = r; |
| 717 | combined_color.g = g; |
| 718 | combined_color.b = b; |
| 719 | combined_color.a = a; |
| 720 | |
| 721 | return c; |
| 722 | } |
| 723 | |
| 494 | 724 | INLINE void SET_BLENDER_INPUT(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b) |
| 495 | 725 | { |
| 496 | 726 | switch (a & 0x3) |
| r6173 | r6174 | |
| 568 | 798 | #define DITHER_RB(val,dith) ((((val) << 1) - ((val) >> 4) + ((val) >> 7) + (dith)) >> 1) |
| 569 | 799 | #define DITHER_G(val,dith) ((((val) << 2) - ((val) >> 4) + ((val) >> 6) + (dith)) >> 2) |
| 570 | 800 | |
| 571 | | INLINE void BLENDER1_16(UINT16 *fb, COLOR c, int dith) |
| 801 | INLINE void BLENDER1_16(UINT16 *fb, COLOR c, int dith, UINT8 *new_cvg, UINT8 *old_cvg, int *alpha_reject) |
| 572 | 802 | { |
| 573 | | int r, g, b; |
| 803 | int r, g, b; |
| 574 | 804 | |
| 575 | | pixel_color.r = c.r; inv_pixel_color.r = 0xff - c.r; |
| 576 | | pixel_color.g = c.g; inv_pixel_color.g = 0xff - c.g; |
| 577 | | pixel_color.b = c.b; inv_pixel_color.b = 0xff - c.b; |
| 578 | | pixel_color.a = c.a; inv_pixel_color.a = 0xff - c.a; |
| 805 | if (other_modes.force_blend ) |
| 806 | { |
| 807 | blend_color.r = c.r; |
| 808 | blend_color.g = c.g; |
| 809 | blend_color.b = c.b; |
| 810 | } |
| 579 | 811 | |
| 812 | pixel_color.r = c.r; |
| 813 | pixel_color.g = c.g; |
| 814 | pixel_color.b = c.b; |
| 815 | pixel_color.a = c.a; |
| 816 | inv_pixel_color.r = 0xff - *blender1a_r[0]; |
| 817 | inv_pixel_color.g = 0xff - *blender1a_g[0]; |
| 818 | inv_pixel_color.b = 0xff - *blender1a_b[0]; |
| 819 | inv_pixel_color.a = 0xff - *blender1b_a[0]; |
| 580 | 820 | |
| 821 | if( other_modes.alpha_cvg_select ) |
| 822 | { |
| 823 | if( other_modes.cvg_times_alpha ) |
| 824 | { |
| 825 | pixel_color.a = (UINT8)( ( (INT32)(c.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 826 | } |
| 827 | else |
| 828 | { |
| 829 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 830 | } |
| 831 | inv_pixel_color.a = 0xff - pixel_color.a; |
| 581 | 832 | |
| 582 | | if (other_modes.image_read_en) |
| 583 | | { |
| 584 | | UINT16 mem = *fb; |
| 585 | | memory_color.r = ((mem >> 11) & 0x1f) << 3; |
| 586 | | memory_color.g = ((mem >> 6) & 0x1f) << 3; |
| 587 | | memory_color.b = ((mem >> 1) & 0x1f) << 3; |
| 588 | | memory_color.a = 0; |
| 589 | | } |
| 833 | if( pixel_color.a == 0 ) |
| 834 | { |
| 835 | *alpha_reject = 1; |
| 836 | return; |
| 837 | } |
| 838 | } |
| 590 | 839 | |
| 591 | | r = (((int)(*blender1a_r[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 592 | | (((int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) >> 8); |
| 840 | if (other_modes.image_read_en) |
| 841 | { |
| 842 | UINT16 mem = *fb; |
| 843 | memory_color.r = (((mem >> 11) & 0x1f) << 3) | ((mem >> 13) & 0x07); |
| 844 | memory_color.g = (((mem >> 6) & 0x1f) << 3) | ((mem >> 8) & 0x07); |
| 845 | memory_color.b = (((mem >> 1) & 0x1f) << 3) | ((mem >> 3) & 0x07); |
| 846 | memory_color.a = /*(UINT8)((INT32)(*old_cvg) * 0x20 - 1)*/0; |
| 847 | } |
| 593 | 848 | |
| 594 | | g = (((int)(*blender1a_g[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 595 | | (((int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) >> 8); |
| 849 | if (((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])) > 0) |
| 850 | { |
| 851 | r = ((int)(*blender1a_r[0]) * (int)(*blender1b_a[0]) + |
| 852 | (int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) / |
| 853 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 596 | 854 | |
| 597 | | b = (((int)(*blender1a_b[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 598 | | (((int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) >> 8); |
| 855 | g = ((int)(*blender1a_g[0]) * (int)(*blender1b_a[0]) + |
| 856 | (int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) / |
| 857 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 599 | 858 | |
| 600 | | //r = g = b = 0xff; |
| 859 | b = ((int)(*blender1a_b[0]) * (int)(*blender1b_a[0]) + |
| 860 | (int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) / |
| 861 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 862 | } |
| 863 | else |
| 864 | { |
| 865 | r = g = b = 0; |
| 866 | } |
| 601 | 867 | |
| 602 | | if (r > 255) r = 255; |
| 603 | | if (g > 255) g = 255; |
| 604 | | if (b > 255) b = 255; |
| 868 | //r = g = b = 0xff; |
| 605 | 869 | |
| 606 | | if (other_modes.rgb_dither_sel != 3) |
| 607 | | { |
| 608 | | r = DITHER_RB(r, dith); |
| 609 | | g = DITHER_G (g, dith); |
| 610 | | b = DITHER_RB(b, dith); |
| 611 | | } |
| 870 | if (r > 255) r = 255; |
| 871 | if (g > 255) g = 255; |
| 872 | if (b > 255) b = 255; |
| 612 | 873 | |
| 613 | | if (c.a != 0) |
| 614 | | { |
| 615 | | *fb = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 616 | | } |
| 874 | if (other_modes.rgb_dither_sel != 3) |
| 875 | { |
| 876 | r = DITHER_RB(r, dith); |
| 877 | g = DITHER_G (g, dith); |
| 878 | b = DITHER_RB(b, dith); |
| 879 | } |
| 880 | |
| 881 | *fb = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | 1; |
| 617 | 882 | } |
| 618 | 883 | |
| 619 | | INLINE void BLENDER2_16(UINT16 *fb, COLOR c1, COLOR c2, int dith) |
| 884 | INLINE void BLENDER2_16(UINT16 *fb, COLOR c1, COLOR c2, int dith, UINT8 *new_cvg, UINT8 *old_cvg, int *alpha_reject) |
| 620 | 885 | { |
| 621 | | int r, g, b; |
| 886 | int r, g, b; |
| 622 | 887 | |
| 623 | | pixel_color.r = c1.r; inv_pixel_color.r = 0xff - c1.r; |
| 624 | | pixel_color.g = c1.g; inv_pixel_color.g = 0xff - c1.g; |
| 625 | | pixel_color.b = c1.b; inv_pixel_color.b = 0xff - c1.b; |
| 626 | | pixel_color.a = c1.a; inv_pixel_color.a = 0xff - c1.a; |
| 888 | if( other_modes.force_blend ) |
| 889 | { |
| 890 | blend_color.r = c2.r; |
| 891 | blend_color.g = c2.g; |
| 892 | blend_color.b = c2.b; |
| 893 | } |
| 627 | 894 | |
| 628 | | if (other_modes.image_read_en) |
| 629 | | { |
| 630 | | UINT16 mem = *fb; |
| 631 | | memory_color.r = ((mem >> 11) & 0x1f) << 3; |
| 632 | | memory_color.g = ((mem >> 6) & 0x1f) << 3; |
| 633 | | memory_color.b = ((mem >> 1) & 0x1f) << 3; |
| 634 | | memory_color.a = 0; |
| 635 | | } |
| 895 | pixel_color.r = c2.r; |
| 896 | pixel_color.g = c2.g; |
| 897 | pixel_color.b = c2.b; |
| 898 | pixel_color.a = c2.a; |
| 899 | inv_pixel_color.r = 0xff - *blender1a_r[0]; |
| 900 | inv_pixel_color.g = 0xff - *blender1a_g[0]; |
| 901 | inv_pixel_color.b = 0xff - *blender1a_b[0]; |
| 902 | inv_pixel_color.a = 0xff - *blender1b_a[0]; |
| 903 | *alpha_reject = 0; |
| 636 | 904 | |
| 637 | | r = (((int)(*blender1a_r[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 638 | | (((int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) >> 8); |
| 905 | if( other_modes.alpha_cvg_select ) |
| 906 | { |
| 907 | if( other_modes.cvg_times_alpha ) |
| 908 | { |
| 909 | pixel_color.a = (UINT8)( ( (INT32)(c2.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 914 | } |
| 915 | //inv_pixel_color.a = 0xff - pixel_color.a; |
| 639 | 916 | |
| 640 | | g = (((int)(*blender1a_g[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 641 | | (((int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) >> 8); |
| 917 | if( pixel_color.a == 0 ) |
| 918 | { |
| 919 | *alpha_reject = 1; |
| 920 | return; |
| 921 | } |
| 922 | } |
| 642 | 923 | |
| 643 | | b = (((int)(*blender1a_b[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 644 | | (((int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) >> 8); |
| 924 | if (other_modes.image_read_en) |
| 925 | { |
| 926 | UINT16 mem = *fb; |
| 927 | memory_color.r = (((mem >> 11) & 0x1f) << 3) | ((mem >> 13) & 0x07); |
| 928 | memory_color.g = (((mem >> 6) & 0x1f) << 3) | ((mem >> 8) & 0x07); |
| 929 | memory_color.b = (((mem >> 1) & 0x1f) << 3) | ((mem >> 3) & 0x07); |
| 930 | memory_color.a = /*(UINT8)((INT32)(*old_cvg) * 0x20 - 1)*/0; |
| 931 | } |
| 645 | 932 | |
| 646 | | blended_pixel_color.r = r; |
| 647 | | blended_pixel_color.g = g; |
| 648 | | blended_pixel_color.b = b; |
| 933 | if (((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])) > 0) |
| 934 | { |
| 935 | r = ((int)(*blender1a_r[0]) * (int)(*blender1b_a[0]) + |
| 936 | (int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) / |
| 937 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 649 | 938 | |
| 650 | | pixel_color.r = c2.r; inv_pixel_color.r = 0xff - c2.r; |
| 651 | | pixel_color.g = c2.g; inv_pixel_color.g = 0xff - c2.g; |
| 652 | | pixel_color.b = c2.b; inv_pixel_color.b = 0xff - c2.b; |
| 653 | | pixel_color.a = c2.a; inv_pixel_color.a = 0xff - c2.a; |
| 939 | g = ((int)(*blender1a_g[0]) * (int)(*blender1b_a[0]) + |
| 940 | (int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) / |
| 941 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 654 | 942 | |
| 655 | | r = (((int)(*blender1a_r[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 656 | | (((int)(*blender2a_r[1]) * (int)(*blender2b_a[1])) >> 8); |
| 943 | b = ((int)(*blender1a_b[0]) * (int)(*blender1b_a[0]) + |
| 944 | (int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) / |
| 945 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | r = g = b = 0; |
| 950 | } |
| 657 | 951 | |
| 658 | | g = (((int)(*blender1a_g[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 659 | | (((int)(*blender2a_g[1]) * (int)(*blender2b_a[1])) >> 8); |
| 952 | blended_pixel_color.r = r; |
| 953 | blended_pixel_color.g = g; |
| 954 | blended_pixel_color.b = b; |
| 660 | 955 | |
| 661 | | b = (((int)(*blender1a_b[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 662 | | (((int)(*blender2a_b[1]) * (int)(*blender2b_a[1])) >> 8); |
| 956 | pixel_color.r = c2.r; |
| 957 | pixel_color.g = c2.g; |
| 958 | pixel_color.b = c2.b; |
| 959 | pixel_color.a = c2.a; |
| 960 | inv_pixel_color.r = 0xff - *blender1a_r[1]; |
| 961 | inv_pixel_color.g = 0xff - *blender1a_g[1]; |
| 962 | inv_pixel_color.b = 0xff - *blender1a_b[1]; |
| 963 | inv_pixel_color.a = 0xff - *blender1b_a[1]; |
| 663 | 964 | |
| 664 | | r = c1.r; |
| 665 | | g = c1.g; |
| 666 | | b = c1.b; |
| 965 | if( other_modes.alpha_cvg_select ) |
| 966 | { |
| 967 | if( other_modes.cvg_times_alpha ) |
| 968 | { |
| 969 | pixel_color.a = (UINT8)( ( (INT32)(c2.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 970 | } |
| 971 | else |
| 972 | { |
| 973 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 974 | } |
| 667 | 975 | |
| 668 | | if (r > 255) r = 255; |
| 669 | | if (g > 255) g = 255; |
| 670 | | if (b > 255) b = 255; |
| 976 | if( pixel_color.a == 0 ) |
| 977 | { |
| 978 | *alpha_reject = 1; |
| 979 | return; |
| 980 | } |
| 981 | } |
| 671 | 982 | |
| 672 | | if (other_modes.rgb_dither_sel != 3) |
| 673 | | { |
| 674 | | r = DITHER_RB(r, dith); |
| 675 | | g = DITHER_G (g, dith); |
| 676 | | b = DITHER_RB(b, dith); |
| 677 | | } |
| 983 | if (((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])) > 0) |
| 984 | { |
| 985 | r = ((int)(*blender1a_r[1]) * (int)(*blender1b_a[1]) + |
| 986 | (int)(*blender2a_r[1]) * (int)(*blender2b_a[1])) / |
| 987 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 678 | 988 | |
| 679 | | { |
| 680 | | *fb = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 681 | | } |
| 989 | g = ((int)(*blender1a_g[1]) * (int)(*blender1b_a[1]) + |
| 990 | (int)(*blender2a_g[1]) * (int)(*blender2b_a[1])) / |
| 991 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 992 | |
| 993 | b = ((int)(*blender1a_b[1]) * (int)(*blender1b_a[1]) + |
| 994 | (int)(*blender2a_b[1]) * (int)(*blender2b_a[1])) / |
| 995 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 996 | } |
| 997 | |
| 998 | //if (r > 255) r = 255; |
| 999 | //if (g > 255) g = 255; |
| 1000 | //if (b > 255) b = 255; |
| 1001 | if (r > 255) r = 255; |
| 1002 | if (g > 255) g = 255; |
| 1003 | if (b > 255) b = 255; |
| 1004 | if (r < 0) r = 0; |
| 1005 | if (g < 0) g = 0; |
| 1006 | if (b < 0) b = 0; |
| 1007 | //r &= 0x000000ff; |
| 1008 | //g &= 0x000000ff; |
| 1009 | //b &= 0x000000ff; |
| 1010 | |
| 1011 | if (other_modes.rgb_dither_sel != 3) |
| 1012 | { |
| 1013 | r = DITHER_RB(r, dith); |
| 1014 | g = DITHER_G (g, dith); |
| 1015 | b = DITHER_RB(b, dith); |
| 1016 | } |
| 1017 | |
| 1018 | *fb = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | 1; |
| 682 | 1019 | } |
| 683 | 1020 | |
| 684 | 1021 | /*****************************************************************************/ |
| r6173 | r6174 | |
| 686 | 1023 | static void fill_rectangle_16bit(RECTANGLE *rect) |
| 687 | 1024 | { |
| 688 | 1025 | UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)]; |
| 1026 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 689 | 1027 | int index, i, j; |
| 690 | 1028 | int x1 = rect->xh / 4; |
| 691 | 1029 | int x2 = rect->xl / 4; |
| 692 | 1030 | int y1 = rect->yh / 4; |
| 693 | 1031 | int y2 = rect->yl / 4; |
| 694 | 1032 | int clipx1, clipx2, clipy1, clipy2; |
| 1033 | int alpha_reject = 0; |
| 1034 | COLOR c1, c2; |
| 695 | 1035 | |
| 696 | 1036 | UINT16 fill_color1, fill_color2; |
| 697 | 1037 | fill_color1 = (fill_color >> 16) & 0xffff; |
| 698 | 1038 | fill_color2 = (fill_color >> 0) & 0xffff; |
| 699 | 1039 | |
| 1040 | c1.r = c1.g = c1.b = c1.a = 0; |
| 1041 | c2.r = c2.g = c2.b = c2.a = 0; |
| 1042 | |
| 700 | 1043 | // TODO: clip |
| 701 | 1044 | clipx1 = clip.xh / 4; |
| 702 | 1045 | clipx2 = clip.xl / 4; |
| r6173 | r6174 | |
| 728 | 1071 | index = j * fb_width; |
| 729 | 1072 | for (i=x1; i <= x2; i++) |
| 730 | 1073 | { |
| 1074 | cvg_buf[(index + i) ^ 1] = (i & 1) ? ( ( fill_color1 & 1 ) ? 8 : 1 ) : ( ( fill_color2 & 1 ) ? 8 : 1 ); |
| 731 | 1075 | fb[(index + i) ^ 1] = (i & 1) ? fill_color1 : fill_color2; |
| 732 | 1076 | } |
| 733 | 1077 | } |
| 734 | 1078 | } |
| 735 | | else if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 736 | | { |
| 737 | | shade_color.r = prim_color.r; |
| 738 | | shade_color.g = prim_color.g; |
| 739 | | shade_color.b = prim_color.b; |
| 740 | | shade_color.a = prim_color.a; |
| 1079 | else if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1080 | { |
| 1081 | shade_color.r = prim_color.r; |
| 1082 | shade_color.g = prim_color.g; |
| 1083 | shade_color.b = prim_color.b; |
| 1084 | shade_color.a = prim_color.a; |
| 741 | 1085 | |
| 742 | | for (j=y1; j <= y2; j++) |
| 743 | | { |
| 744 | | index = j * fb_width; |
| 745 | | for (i=x1; i <= x2; i++) |
| 746 | | { |
| 747 | | COLOR c = COLOR_COMBINER(0); |
| 1086 | for (j=y1; j <= y2; j++) |
| 1087 | { |
| 1088 | index = j * fb_width; |
| 1089 | for (i=x1; i <= x2; i++) |
| 1090 | { |
| 1091 | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 748 | 1092 | |
| 749 | | //BLENDER1_16(&fb[(index + i) ^ 1], c); |
| 750 | | { |
| 751 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 752 | | BLENDER1_16(&fb[(index + i) ^ WORD_ADDR_XOR], c, dith); |
| 753 | | } |
| 754 | | } |
| 755 | | } |
| 756 | | } |
| 757 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 758 | | { |
| 759 | | shade_color.r = prim_color.r; |
| 760 | | shade_color.g = prim_color.g; |
| 761 | | shade_color.b = prim_color.b; |
| 762 | | shade_color.a = prim_color.a; |
| 1093 | c1 = COLOR_COMBINER(0); |
| 763 | 1094 | |
| 764 | | for (j=y1; j <= y2; j++) |
| 765 | | { |
| 766 | | index = j * fb_width; |
| 767 | | for (i=x1; i <= x2; i++) |
| 768 | | { |
| 769 | | COLOR c1 = COLOR_COMBINER(0); |
| 770 | | COLOR c2 = COLOR_COMBINER(1); |
| 1095 | cvg_buf[(index + i) ^ WORD_ADDR_XOR] = 8; // Wrong |
| 1096 | BLENDER1_16(&fb[(index + i) ^ WORD_ADDR_XOR], c1, dith, &cvg_buf[(index + i) ^ WORD_ADDR_XOR], &cvg_buf[(index + i) ^ WORD_ADDR_XOR], &alpha_reject); |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1101 | { |
| 1102 | shade_color.r = prim_color.r; |
| 1103 | shade_color.g = prim_color.g; |
| 1104 | shade_color.b = prim_color.b; |
| 1105 | shade_color.a = prim_color.a; |
| 771 | 1106 | |
| 772 | | //BLENDER1_16(&fb[(index + i) ^ 1], c); |
| 773 | | { |
| 774 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 775 | | BLENDER2_16(&fb[(index + i) ^ WORD_ADDR_XOR], c1, c2, dith); |
| 776 | | } |
| 777 | | } |
| 778 | | } |
| 779 | | } |
| 780 | | else |
| 781 | | { |
| 782 | | fatalerror("fill_rectangle_16bit: cycle type copy"); |
| 783 | | } |
| 1107 | for (j=y1; j <= y2; j++) |
| 1108 | { |
| 1109 | index = j * fb_width; |
| 1110 | for (i=x1; i <= x2; i++) |
| 1111 | { |
| 1112 | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 1113 | |
| 1114 | c1 = COLOR_COMBINER(0); |
| 1115 | c2 = COLOR_COMBINER(1); |
| 1116 | |
| 1117 | cvg_buf[(index + i) ^ WORD_ADDR_XOR] = 8; // Wrong |
| 1118 | BLENDER2_16(&fb[(index + i) ^ WORD_ADDR_XOR], c1, c2, dith, &cvg_buf[(index + i) ^ WORD_ADDR_XOR], &cvg_buf[(index + i) ^ WORD_ADDR_XOR], &alpha_reject); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | else |
| 1123 | { |
| 1124 | fatalerror("fill_rectangle_16bit: cycle type copy"); |
| 1125 | } |
| 784 | 1126 | } |
| 785 | 1127 | |
| 786 | 1128 | #define XOR_SWAP_BYTE 4 |
| 787 | 1129 | #define XOR_SWAP_WORD 2 |
| 788 | 1130 | #define XOR_SWAP_DWORD 1 |
| 789 | 1131 | |
| 790 | | INLINE void FETCH_TEXEL(COLOR *color, int s, int t, UINT32 twidth, UINT32 tformat, UINT32 tsize, UINT32 tbase) |
| 1132 | INLINE int taddr_clamp(int addr) |
| 791 | 1133 | { |
| 1134 | return (addr > 0x100000) ? 0 : addr; |
| 1135 | } |
| 1136 | |
| 1137 | INLINE void FETCH_TEXEL(COLOR *color, int s, int t, UINT32 twidth, UINT32 tformat, UINT32 tsize, UINT32 tbase, UINT8 tpal) |
| 1138 | { |
| 792 | 1139 | if (t < 0) t = 0; |
| 793 | 1140 | if (s < 0) s = 0; |
| 794 | 1141 | |
| r6173 | r6174 | |
| 798 | 1145 | { |
| 799 | 1146 | switch (tsize) |
| 800 | 1147 | { |
| 801 | | case 0: |
| 802 | | color->r = color->g = color->b = color->a = 0xff; |
| 803 | | break; |
| 804 | | case 1: |
| 805 | | // FIXME?: Extreme-G 2 does this |
| 806 | | color->r = color->g = color->b = color->a = 0xff; |
| 807 | | break; |
| 1148 | case PIXEL_SIZE_4BIT: |
| 1149 | { |
| 1150 | // 4-bit RGBA is a "valid" mode; some games use it, it behaves the same as 4-bit CI |
| 1151 | UINT8 *tc = (UINT8*)texture_cache; |
| 1152 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 1153 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 1154 | UINT16 c = tlut[(p + (tpal << 4))^ WORD_ADDR_XOR]; |
| 1155 | |
| 1156 | if (other_modes.tlut_type == 0) |
| 1157 | { |
| 1158 | color->r = ((c >> 11) & 0x1f) << 3; |
| 1159 | color->g = ((c >> 6) & 0x1f) << 3; |
| 1160 | color->b = ((c >> 1) & 0x1f) << 3; |
| 1161 | color->a = (c & 1) ? 0xff : 0; |
| 1162 | } |
| 1163 | else |
| 1164 | { |
| 1165 | color->r = color->g = color->b = (c >> 8) & 0xff; |
| 1166 | color->a = c & 0xff; |
| 1167 | } |
| 1168 | break; |
| 1169 | } |
| 1170 | case PIXEL_SIZE_8BIT: |
| 1171 | { |
| 1172 | // 8-bit RGBA is a "valid" mode; some games use it, it behaves the same as 8-bit CI |
| 1173 | UINT8 *tc = (UINT8*)texture_cache; |
| 1174 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 1175 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 1176 | UINT16 c = tlut[p ^ WORD_ADDR_XOR]; |
| 1177 | |
| 1178 | if (other_modes.tlut_type == 0) |
| 1179 | { |
| 1180 | color->r = ((c >> 11) & 0x1f) << 3; |
| 1181 | color->g = ((c >> 6) & 0x1f) << 3; |
| 1182 | color->b = ((c >> 1) & 0x1f) << 3; |
| 1183 | color->a = (c & 1) ? 0xff : 0; |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 1187 | color->r = color->g = color->b = (c >> 8) & 0xff; |
| 1188 | color->a = c & 0xff; |
| 1189 | } |
| 1190 | break; |
| 1191 | } |
| 808 | 1192 | case PIXEL_SIZE_16BIT: |
| 809 | 1193 | { |
| 810 | 1194 | UINT16 *tc = (UINT16*)texture_cache; |
| 811 | | int taddr = ((tbase/2) + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1195 | int taddr = taddr_clamp(((tbase/2) + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0)); |
| 812 | 1196 | UINT16 c = tc[taddr ^ WORD_ADDR_XOR]; |
| 813 | 1197 | |
| 814 | 1198 | color->r = ((c >> 11) & 0x1f) << 3; |
| r6173 | r6174 | |
| 820 | 1204 | case PIXEL_SIZE_32BIT: |
| 821 | 1205 | { |
| 822 | 1206 | UINT32 *tc = (UINT32*)texture_cache; |
| 823 | | int taddr = ((tbase/4) + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_DWORD : 0); |
| 1207 | int taddr = taddr_clamp(((tbase/4) + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_DWORD : 0)); |
| 824 | 1208 | UINT32 c = tc[taddr]; |
| 825 | 1209 | |
| 826 | 1210 | color->r = ((c >> 24) & 0xff); |
| r6173 | r6174 | |
| 843 | 1227 | case PIXEL_SIZE_4BIT: |
| 844 | 1228 | { |
| 845 | 1229 | UINT8 *tc = (UINT8*)texture_cache; |
| 846 | | int taddr = (tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1230 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 847 | 1231 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 848 | 1232 | UINT16 c = tlut[p ^ WORD_ADDR_XOR]; |
| 849 | 1233 | |
| r6173 | r6174 | |
| 864 | 1248 | case PIXEL_SIZE_8BIT: |
| 865 | 1249 | { |
| 866 | 1250 | UINT8 *tc = (UINT8*)texture_cache; |
| 867 | | int taddr = (tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1251 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 868 | 1252 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 869 | 1253 | UINT16 c = tlut[p ^ WORD_ADDR_XOR]; |
| 870 | 1254 | |
| r6173 | r6174 | |
| 882 | 1266 | } |
| 883 | 1267 | break; |
| 884 | 1268 | } |
| 885 | | case 2: |
| 886 | | // FIXME?: Clay Fighter Sculptor's Cut does this.. |
| 887 | | color->r = color->g = color->b = color->a = 0xff; |
| 888 | | break; |
| 1269 | case PIXEL_SIZE_16BIT: |
| 1270 | { |
| 1271 | // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA |
| 1272 | UINT16 *tc = (UINT16*)texture_cache; |
| 1273 | int taddr = taddr_clamp(((tbase/2) + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0)); |
| 1274 | UINT16 c = tc[taddr ^ WORD_ADDR_XOR]; |
| 1275 | |
| 1276 | color->r = ((c >> 11) & 0x1f) << 3; |
| 1277 | color->g = ((c >> 6) & 0x1f) << 3; |
| 1278 | color->b = ((c >> 1) & 0x1f) << 3; |
| 1279 | color->a = (c & 1) ? 0xff : 0; |
| 1280 | break; |
| 1281 | } |
| 889 | 1282 | default: |
| 890 | 1283 | color->r = color->g = color->b = color->a = 0xff; |
| 891 | 1284 | fatalerror("FETCH_TEXEL: unknown CI texture size %d\n", tsize); |
| r6173 | r6174 | |
| 900 | 1293 | case PIXEL_SIZE_4BIT: |
| 901 | 1294 | { |
| 902 | 1295 | UINT8 *tc = (UINT8*)texture_cache; |
| 903 | | int taddr = (tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1296 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 904 | 1297 | UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 905 | 1298 | UINT8 i = ((p & 0xe) << 4) | ((p & 0xe) << 1) | (p & 0xe >> 2); |
| 906 | 1299 | |
| r6173 | r6174 | |
| 913 | 1306 | case PIXEL_SIZE_8BIT: |
| 914 | 1307 | { |
| 915 | 1308 | UINT8 *tc = (UINT8*)texture_cache; |
| 916 | | int taddr = (tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1309 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 917 | 1310 | UINT8 p = tc[taddr ^ BYTE_ADDR_XOR]; |
| 918 | 1311 | UINT8 i = (p >> 4) | (p & 0xf0); |
| 919 | 1312 | |
| r6173 | r6174 | |
| 926 | 1319 | case PIXEL_SIZE_16BIT: |
| 927 | 1320 | { |
| 928 | 1321 | UINT16 *tc = (UINT16*)texture_cache; |
| 929 | | int taddr = (tbase + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0); |
| 1322 | int taddr = taddr_clamp((tbase + ((t) * (twidth/2)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0)); |
| 930 | 1323 | UINT16 c = tc[taddr ^ WORD_ADDR_XOR]; |
| 931 | 1324 | UINT8 i = (c >> 8); |
| 932 | 1325 | |
| r6173 | r6174 | |
| 950 | 1343 | case PIXEL_SIZE_4BIT: |
| 951 | 1344 | { |
| 952 | 1345 | UINT8 *tc = (UINT8*)texture_cache; |
| 953 | | int taddr = (tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1346 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 954 | 1347 | UINT8 c = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4); |
| 955 | 1348 | c |= (c << 4); |
| 956 | 1349 | |
| r6173 | r6174 | |
| 963 | 1356 | case PIXEL_SIZE_8BIT: |
| 964 | 1357 | { |
| 965 | 1358 | UINT8 *tc = (UINT8*)texture_cache; |
| 966 | | int taddr = (tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0); |
| 1359 | int taddr = taddr_clamp((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)); |
| 967 | 1360 | UINT8 c = tc[taddr ^ BYTE_ADDR_XOR]; |
| 968 | 1361 | |
| 969 | 1362 | color->r = c; |
| r6173 | r6174 | |
| 989 | 1382 | } |
| 990 | 1383 | |
| 991 | 1384 | #if 1 |
| 992 | | #define TEXTURE_PIPELINE(TEX, SSS, SST, NOBILINEAR) \ |
| 993 | | do \ |
| 994 | | { \ |
| 995 | | if (other_modes.sample_type && !NOBILINEAR) \ |
| 996 | | { \ |
| 997 | | COLOR t0, t1, t2, t3; \ |
| 998 | | int sss1, sst1, sss2, sst2; \ |
| 999 | | \ |
| 1000 | | /* bilinear */ \ |
| 1001 | | \ |
| 1385 | #define TEXTURE_PIPELINE(TEX, SSS, SST, NOBILINEAR, CYCLE) \ |
| 1386 | do \ |
| 1387 | { \ |
| 1388 | if (other_modes.sample_type && !NOBILINEAR) \ |
| 1389 | { \ |
| 1390 | COLOR t0, t1, t2, t3; \ |
| 1391 | int sss1, sst1, sss2, sst2; \ |
| 1392 | \ |
| 1393 | /* bilinear */ \ |
| 1394 | \ |
| 1002 | 1395 | sss1 = SSS >> 10; \ |
| 1003 | 1396 | sss2 = sss1 + 1; \ |
| 1004 | 1397 | \ |
| 1005 | 1398 | sst1 = SST >> 10; \ |
| 1006 | 1399 | sst2 = sst1 + 1; \ |
| 1007 | 1400 | \ |
| 1008 | | CLAMP(sss1, sst1); \ |
| 1009 | | CLAMP(sss2, sst2); \ |
| 1010 | | \ |
| 1011 | | sss1 -= tsl >> 2; \ |
| 1012 | | sss2 -= tsl >> 2; \ |
| 1401 | sss1 -= tsl[CYCLE] >> 2; \ |
| 1402 | sss2 -= tsl[CYCLE] >> 2; \ |
| 1013 | 1403 | \ |
| 1014 | | sst1 -= ttl >> 2; \ |
| 1015 | | sst2 -= ttl >> 2; \ |
| 1404 | sst1 -= ttl[CYCLE] >> 2; \ |
| 1405 | sst2 -= ttl[CYCLE] >> 2; \ |
| 1016 | 1406 | \ |
| 1017 | | MASK(sss1, sst1); \ |
| 1018 | | MASK(sss2, sst2); \ |
| 1407 | CLAMP(sss1, sst1, CYCLE); \ |
| 1408 | CLAMP(sss2, sst2, CYCLE); \ |
| 1019 | 1409 | \ |
| 1020 | | FETCH_TEXEL(&t0, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1021 | | FETCH_TEXEL(&t1, sss2, sst1, twidth, tformat, tsize, tbase); \ |
| 1022 | | FETCH_TEXEL(&t2, sss1, sst2, twidth, tformat, tsize, tbase); \ |
| 1023 | | FETCH_TEXEL(&t3, sss2, sst2, twidth, tformat, tsize, tbase); \ |
| 1024 | | \ |
| 1025 | | TEX.r = (((( (t0.r * (0x3ff - (SSS & 0x3ff))) + (t1.r * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1026 | | (((( (t2.r * (0x3ff - (SSS & 0x3ff))) + (t3.r * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1027 | | \ |
| 1028 | | TEX.g = (((( (t0.g * (0x3ff - (SSS & 0x3ff))) + (t1.g * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1029 | | (((( (t2.g * (0x3ff - (SSS & 0x3ff))) + (t3.g * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1030 | | \ |
| 1031 | | TEX.b = (((( (t0.b * (0x3ff - (SSS & 0x3ff))) + (t1.b * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1032 | | (((( (t2.b * (0x3ff - (SSS & 0x3ff))) + (t3.b * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1033 | | \ |
| 1034 | | TEX.a = (((( (t0.a * (0x3ff - (SSS & 0x3ff))) + (t1.a * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1035 | | (((( (t2.a * (0x3ff - (SSS & 0x3ff))) + (t3.a * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1036 | | } \ |
| 1037 | | else \ |
| 1038 | | { \ |
| 1039 | | int sss1, sst1; \ |
| 1410 | MASK(sss1, sst1, CYCLE); \ |
| 1411 | MASK(sss2, sst2, CYCLE); \ |
| 1412 | \ |
| 1413 | FETCH_TEXEL(&t0, sss1, sst1, twidth[CYCLE], tformat[CYCLE], tsize[CYCLE], tbase[CYCLE], tpal[CYCLE]); \ |
| 1414 | FETCH_TEXEL(&t1, sss2, sst1, twidth[CYCLE], tformat[CYCLE], tsize[CYCLE], tbase[CYCLE], tpal[CYCLE]); \ |
| 1415 | FETCH_TEXEL(&t2, sss1, sst2, twidth[CYCLE], tformat[CYCLE], tsize[CYCLE], tbase[CYCLE], tpal[CYCLE]); \ |
| 1416 | FETCH_TEXEL(&t3, sss2, sst2, twidth[CYCLE], tformat[CYCLE], tsize[CYCLE], tbase[CYCLE], tpal[CYCLE]); \ |
| 1417 | \ |
| 1418 | TEX.r = (((( (t0.r * (0x3ff - (SSS & 0x3ff))) + (t1.r * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1419 | (((( (t2.r * (0x3ff - (SSS & 0x3ff))) + (t3.r * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1420 | \ |
| 1421 | TEX.g = (((( (t0.g * (0x3ff - (SSS & 0x3ff))) + (t1.g * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1422 | (((( (t2.g * (0x3ff - (SSS & 0x3ff))) + (t3.g * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1423 | \ |
| 1424 | TEX.b = (((( (t0.b * (0x3ff - (SSS & 0x3ff))) + (t1.b * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1425 | (((( (t2.b * (0x3ff - (SSS & 0x3ff))) + (t3.b * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1426 | \ |
| 1427 | TEX.a = (((( (t0.a * (0x3ff - (SSS & 0x3ff))) + (t1.a * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1428 | (((( (t2.a * (0x3ff - (SSS & 0x3ff))) + (t3.a * ((SSS & 0x3ff))) ) >> 10) * ((SST & 0x3ff))) >> 10); \ |
| 1429 | } \ |
| 1430 | else \ |
| 1431 | { \ |
| 1432 | int sss1, sst1; \ |
| 1040 | 1433 | sss1 = SSS >> 10; \ |
| 1041 | 1434 | if ((SSS & 0x3ff) >= 0x200) sss1++; \ |
| 1042 | 1435 | \ |
| 1043 | 1436 | sst1 = SST >> 10; \ |
| 1044 | 1437 | if ((SST & 0x3ff) >= 0x200) sst1++; \ |
| 1045 | 1438 | \ |
| 1046 | | CLAMP(sss1, sst1); \ |
| 1047 | | \ |
| 1048 | | sss1 -= tsl >> 2; \ |
| 1049 | | sst1 -= ttl >> 2; \ |
| 1439 | sss1 -= tsl[CYCLE] >> 2; \ |
| 1440 | sst1 -= ttl[CYCLE] >> 2; \ |
| 1050 | 1441 | \ |
| 1051 | | MASK(sss1, sst1); \ |
| 1442 | CLAMP(sss1, sst1, CYCLE); \ |
| 1052 | 1443 | \ |
| 1053 | | /* point sample */ \ |
| 1054 | | FETCH_TEXEL(&TEX, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1055 | | } \ |
| 1056 | | } \ |
| 1444 | MASK(sss1, sst1, CYCLE); \ |
| 1445 | \ |
| 1446 | /* point sample */ \ |
| 1447 | FETCH_TEXEL(&TEX, sss1, sst1, twidth[CYCLE], tformat[CYCLE], tsize[CYCLE], tbase[CYCLE], tpal[CYCLE]); \ |
| 1448 | } \ |
| 1449 | } \ |
| 1057 | 1450 | while(0) |
| 1058 | 1451 | #endif |
| 1059 | 1452 | |
| r6173 | r6174 | |
| 1061 | 1454 | // TODO: check the correct texel samples and weighting values |
| 1062 | 1455 | |
| 1063 | 1456 | #if 0 |
| 1064 | | #define TEXTURE_PIPELINE(TEX, SSS, SST, NOBILINEAR) \ |
| 1065 | | do \ |
| 1066 | | { \ |
| 1067 | | if (other_modes.sample_type && !NOBILINEAR) \ |
| 1068 | | { \ |
| 1069 | | COLOR t0, t1, t2; \ |
| 1070 | | int sss1, sst1, sss2, sst2; \ |
| 1071 | | \ |
| 1072 | | /* bilinear */ \ |
| 1073 | | \ |
| 1074 | | sss1 = (SSS >> 10) - (tsl >> 2); \ |
| 1075 | | sss2 = sss1 + 1; \ |
| 1076 | | \ |
| 1077 | | sst1 = (SST >> 10) - (ttl >> 2); \ |
| 1078 | | sst2 = sst1 + 1; \ |
| 1079 | | \ |
| 1080 | | CLAMP(sss1, sst1); \ |
| 1081 | | CLAMP(sss2, sst2); \ |
| 1082 | | \ |
| 1083 | | FETCH_TEXEL(&t0, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1084 | | FETCH_TEXEL(&t1, sss2, sst1, twidth, tformat, tsize, tbase); \ |
| 1085 | | FETCH_TEXEL(&t2, sss2, sst2, twidth, tformat, tsize, tbase); \ |
| 1086 | | \ |
| 1087 | | TEX.r = (((( (t0.r * (0x3ff - (SSS & 0x3ff))) + (t1.r * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1088 | | (( (t2.r) * ((SST & 0x3ff))) >> 10); \ |
| 1089 | | \ |
| 1090 | | TEX.g = (((( (t0.g * (0x3ff - (SSS & 0x3ff))) + (t1.g * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1091 | | (( (t2.g) * ((SST & 0x3ff))) >> 10); \ |
| 1092 | | \ |
| 1093 | | TEX.b = (((( (t0.b * (0x3ff - (SSS & 0x3ff))) + (t1.b * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1094 | | (( (t2.b) * ((SST & 0x3ff))) >> 10); \ |
| 1095 | | \ |
| 1096 | | TEX.a = (((( (t0.a * (0x3ff - (SSS & 0x3ff))) + (t1.a * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1097 | | (( (t2.a) * ((SST & 0x3ff))) >> 10); \ |
| 1098 | | } \ |
| 1099 | | else \ |
| 1100 | | { \ |
| 1101 | | int sss1, sst1; \ |
| 1102 | | sss1 = (SSS >> 10) - (tsl >> 2); \ |
| 1103 | | if ((SSS & 0x3ff) >= 0x200) sss1++; \ |
| 1104 | | \ |
| 1105 | | sst1 = (SST >> 10) - (ttl >> 2); \ |
| 1106 | | if ((SST & 0x3ff) >= 0x200) sst1++; \ |
| 1107 | | \ |
| 1108 | | CLAMP(sss1, sst1); \ |
| 1109 | | \ |
| 1110 | | /* point sample */ \ |
| 1111 | | FETCH_TEXEL(&TEX, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1112 | | } \ |
| 1113 | | } \ |
| 1457 | #define TEXTURE_PIPELINE(TEX, SSS, SST, NOBILINEAR) \ |
| 1458 | do \ |
| 1459 | { \ |
| 1460 | if (other_modes.sample_type && !NOBILINEAR) \ |
| 1461 | { \ |
| 1462 | COLOR t0, t1, t2; \ |
| 1463 | int sss1, sst1, sss2, sst2; \ |
| 1464 | \ |
| 1465 | /* bilinear */ \ |
| 1466 | \ |
| 1467 | sss1 = (SSS >> 10) - (tsl >> 2); \ |
| 1468 | sss2 = sss1 + 1; \ |
| 1469 | \ |
| 1470 | sst1 = (SST >> 10) - (ttl >> 2); \ |
| 1471 | sst2 = sst1 + 1; \ |
| 1472 | \ |
| 1473 | CLAMP(sss1, sst1); \ |
| 1474 | CLAMP(sss2, sst2); \ |
| 1475 | \ |
| 1476 | FETCH_TEXEL(&t0, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1477 | FETCH_TEXEL(&t1, sss2, sst1, twidth, tformat, tsize, tbase); \ |
| 1478 | FETCH_TEXEL(&t2, sss2, sst2, twidth, tformat, tsize, tbase); \ |
| 1479 | \ |
| 1480 | TEX.r = (((( (t0.r * (0x3ff - (SSS & 0x3ff))) + (t1.r * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1481 | (( (t2.r) * ((SST & 0x3ff))) >> 10); \ |
| 1482 | \ |
| 1483 | TEX.g = (((( (t0.g * (0x3ff - (SSS & 0x3ff))) + (t1.g * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1484 | (( (t2.g) * ((SST & 0x3ff))) >> 10); \ |
| 1485 | \ |
| 1486 | TEX.b = (((( (t0.b * (0x3ff - (SSS & 0x3ff))) + (t1.b * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1487 | (( (t2.b) * ((SST & 0x3ff))) >> 10); \ |
| 1488 | \ |
| 1489 | TEX.a = (((( (t0.a * (0x3ff - (SSS & 0x3ff))) + (t1.a * ((SSS & 0x3ff))) ) >> 10) * (0x3ff - (SST & 0x3ff))) >> 10) + \ |
| 1490 | (( (t2.a) * ((SST & 0x3ff))) >> 10); \ |
| 1491 | } \ |
| 1492 | else \ |
| 1493 | { \ |
| 1494 | int sss1, sst1; \ |
| 1495 | sss1 = (SSS >> 10) - (tsl >> 2); \ |
| 1496 | if ((SSS & 0x3ff) >= 0x200) sss1++; \ |
| 1497 | \ |
| 1498 | sst1 = (SST >> 10) - (ttl >> 2); \ |
| 1499 | if ((SST & 0x3ff) >= 0x200) sst1++; \ |
| 1500 | \ |
| 1501 | CLAMP(sss1, sst1); \ |
| 1502 | \ |
| 1503 | /* point sample */ \ |
| 1504 | FETCH_TEXEL(&TEX, sss1, sst1, twidth, tformat, tsize, tbase); \ |
| 1505 | } \ |
| 1506 | } \ |
| 1114 | 1507 | while(0) |
| 1115 | 1508 | #endif |
| 1116 | 1509 | |
| 1117 | | #define TEXTURE_PIPELINE1(SSS, SST, NOBILINEAR) \ |
| 1118 | | do \ |
| 1119 | | { \ |
| 1120 | | TEXTURE_PIPELINE(texel0_color, SSS, SST, NOBILINEAR); \ |
| 1121 | | } \ |
| 1510 | #define TEXTURE_PIPELINE1(SSS, SST, NOBILINEAR) \ |
| 1511 | do \ |
| 1512 | { \ |
| 1513 | TEXTURE_PIPELINE(texel0_color, SSS, SST, NOBILINEAR, 0);\ |
| 1514 | } \ |
| 1122 | 1515 | while(0) |
| 1123 | 1516 | |
| 1124 | | #define TEXTURE_PIPELINE2(SSS, SST, NOBILINEAR) \ |
| 1125 | | do \ |
| 1126 | | { \ |
| 1127 | | TEXTURE_PIPELINE(texel0_color, SSS, SST, NOBILINEAR); \ |
| 1128 | | TEXTURE_PIPELINE(texel1_color, SSS, SST, NOBILINEAR); \ |
| 1129 | | } \ |
| 1517 | #define TEXTURE_PIPELINE2(SSS, SST, NOBILINEAR) \ |
| 1518 | do \ |
| 1519 | { \ |
| 1520 | TEXTURE_PIPELINE(texel0_color, SSS, SST, NOBILINEAR, 0);\ |
| 1521 | TEXTURE_PIPELINE(texel1_color, SSS, SST, NOBILINEAR, 1);\ |
| 1522 | } \ |
| 1130 | 1523 | while(0) |
| 1131 | 1524 | |
| 1525 | static int alpha_compare_success(COLOR c1, COLOR c2) |
| 1526 | { |
| 1527 | if( other_modes.alpha_compare_en ) |
| 1528 | { |
| 1529 | if( other_modes.cycle_type == CYCLE_TYPE_1 ) |
| 1530 | { |
| 1531 | if( c1.a > blend_color.a ) |
| 1532 | { |
| 1533 | return 1; |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | return 0; |
| 1538 | } |
| 1539 | } |
| 1540 | if( other_modes.cycle_type == CYCLE_TYPE_2 ) |
| 1541 | { |
| 1542 | if( c2.a > blend_color.a ) |
| 1543 | { |
| 1544 | return 1; |
| 1545 | } |
| 1546 | else |
| 1547 | { |
| 1548 | return 0; |
| 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | else |
| 1553 | { |
| 1554 | return 1; |
| 1555 | } |
| 1556 | return 0; |
| 1557 | } |
| 1132 | 1558 | |
| 1559 | /* Does not yet work properly */ |
| 1560 | static void compress_z(UINT32 in, UINT16 *out_z, UINT8 *out_dz) |
| 1561 | { |
| 1562 | UINT32 rounded = (in >> 13) & 0x0003ffff; |
| 1563 | UINT16 full_delta = in & 0x0000ffff; |
| 1564 | UINT8 exponent = 0; |
| 1565 | UINT8 high_delta_bit = 15; |
| 1566 | UINT16 mantissa = 0; |
| 1567 | UINT32 final_value = 0; |
| 1133 | 1568 | |
| 1569 | // Determine exponent and mantissa |
| 1570 | for (exponent = 0; exponent < 7; exponent++) |
| 1571 | { |
| 1572 | if (!(rounded & (0x00020000 >> exponent))) |
| 1573 | { |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
| 1577 | mantissa = (rounded >> ((exponent != 7) ? (6 - exponent) : 0)) & 0x000007ff; |
| 1578 | |
| 1579 | // Determine the high bit of Z delta |
| 1580 | for (high_delta_bit = 15; high_delta_bit > 0; high_delta_bit--) |
| 1581 | { |
| 1582 | if (full_delta & (1 << high_delta_bit)) |
| 1583 | { |
| 1584 | break; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | // Composite the final value |
| 1589 | final_value = (mantissa << 7) | (exponent << 4) | (high_delta_bit & 0x0f); |
| 1590 | *out_z = (final_value >> 2) & 0xfffc; |
| 1591 | *out_dz = final_value & 0x000f; |
| 1592 | } |
| 1593 | |
| 1594 | /* Does not yet work properly */ |
| 1595 | static void decompress_z(UINT16 in, UINT32 *out) |
| 1596 | { |
| 1597 | UINT16 mantissa = (in >> 5) & 0x07ff; |
| 1598 | UINT8 exponent = (in >> 2) & 0x0007; |
| 1599 | switch (exponent) |
| 1600 | { |
| 1601 | case 0: |
| 1602 | (*out) = (mantissa << 6); |
| 1603 | break; |
| 1604 | case 1: |
| 1605 | (*out) = 0x20000 | (mantissa << 5); |
| 1606 | break; |
| 1607 | case 2: |
| 1608 | (*out) = 0x30000 | (mantissa << 4); |
| 1609 | break; |
| 1610 | case 3: |
| 1611 | (*out) = 0x38000 | (mantissa << 3); |
| 1612 | break; |
| 1613 | case 4: |
| 1614 | (*out) = 0x3c000 | (mantissa << 2); |
| 1615 | break; |
| 1616 | case 5: |
| 1617 | (*out) = 0x3e000 | (mantissa << 1); |
| 1618 | break; |
| 1619 | case 6: |
| 1620 | (*out) = 0x3f000 | mantissa; |
| 1621 | break; |
| 1622 | case 7: |
| 1623 | (*out) = 0x3f800 | mantissa; |
| 1624 | break; |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | static void calculate_coverage( UINT8 *out, UINT8 in, int* ovf, UINT8 *old ) |
| 1629 | { |
| 1630 | (*old) = (*out); |
| 1631 | if (((*out) + in) > 8) |
| 1632 | { |
| 1633 | (*ovf) = 1; |
| 1634 | } |
| 1635 | switch (other_modes.cvg_dest) |
| 1636 | { |
| 1637 | case 0: // Clamp |
| 1638 | if (other_modes.image_read_en) |
| 1639 | { |
| 1640 | (*out) = (*out) + in; |
| 1641 | } |
| 1642 | else |
| 1643 | { |
| 1644 | (*out) = in; |
| 1645 | } |
| 1646 | if (*out > 8) |
| 1647 | { |
| 1648 | *out = 8; |
| 1649 | } |
| 1650 | break; |
| 1651 | case 1: // Wrap |
| 1652 | if (other_modes.image_read_en) |
| 1653 | { |
| 1654 | (*out) = ( (*out) - 1 ) + in; |
| 1655 | } |
| 1656 | else |
| 1657 | { |
| 1658 | (*out) = in; |
| 1659 | } |
| 1660 | (*out) &= 0x07; |
| 1661 | (*out)++; |
| 1662 | break; |
| 1663 | case 2: // Zap |
| 1664 | (*out) = 8; |
| 1665 | break; |
| 1666 | case 3: // Save |
| 1667 | (*out) = (*out); |
| 1668 | break; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1134 | 1672 | static void texture_rectangle_16bit(TEX_RECTANGLE *rect) |
| 1135 | 1673 | { |
| 1136 | | UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)]; |
| 1137 | | int i, j; |
| 1138 | | int x1, x2, y1, y2; |
| 1139 | | int tsl, tsh, ttl, tth; |
| 1140 | | int s, t; |
| 1141 | | int twidth, tformat, tsize, tbase; |
| 1142 | | int clamp_s, clamp_t, mask_s, mask_t, mirror_s, mirror_t; |
| 1143 | | int clipx1, clipx2, clipy1, clipy2; |
| 1674 | UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)]; |
| 1675 | UINT16 *zb = (UINT16*)&rdram[(zb_address / 4)]; |
| 1676 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 1677 | int i, j; |
| 1678 | int x1, x2, y1, y2; |
| 1679 | int tsl[2], tsh[2], ttl[2], tth[2]; |
| 1680 | int s, t; |
| 1681 | int twidth[2], tformat[2], tsize[2], tbase[2], tpal[2]; |
| 1682 | int clamp_s[2], clamp_t[2], mask_s[2], mask_t[2], mirror_s[2], mirror_t[2]; |
| 1683 | int clipx1, clipx2, clipy1, clipy2; |
| 1684 | int cycle; |
| 1685 | UINT8 cvg_span[RDP_CVG_SPAN_MAX]; |
| 1686 | int span_index = 0; |
| 1687 | int alpha_reject = 0; |
| 1688 | COLOR c1, c2; |
| 1689 | c1.r = c1.g = c1.b = c1.a = 0; |
| 1690 | c2.r = c2.g = c2.b = c2.a = 0; |
| 1144 | 1691 | |
| 1145 | | x1 = (rect->xh / 4); |
| 1146 | | x2 = (rect->xl / 4); |
| 1147 | | y1 = (rect->yh / 4); |
| 1148 | | y2 = (rect->yl / 4); |
| 1692 | x1 = rect->xh; |
| 1693 | x2 = rect->xl; |
| 1694 | y1 = rect->yh; |
| 1695 | y2 = rect->yl; |
| 1149 | 1696 | |
| 1150 | | if (other_modes.cycle_type == CYCLE_TYPE_FILL || other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1151 | | { |
| 1152 | | rect->dsdx /= 4; |
| 1153 | | x2 += 1; |
| 1154 | | y2 += 1; |
| 1155 | | } |
| 1697 | if (other_modes.cycle_type == CYCLE_TYPE_FILL || other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1698 | { |
| 1699 | rect->dsdx /= 4; |
| 1700 | x2 += 1; |
| 1701 | y2 += 1; |
| 1702 | } |
| 1156 | 1703 | |
| 1157 | | clipx1 = clip.xh / 4; |
| 1158 | | clipx2 = clip.xl / 4; |
| 1159 | | clipy1 = clip.yh / 4; |
| 1160 | | clipy2 = clip.yl / 4; |
| 1704 | clipx1 = clip.xh; |
| 1705 | clipx2 = clip.xl; |
| 1706 | clipy1 = clip.yh; |
| 1707 | clipy2 = clip.yl; |
| 1161 | 1708 | |
| 1162 | | // clip |
| 1163 | | if (x1 < clipx1) |
| 1164 | | { |
| 1165 | | x1 = clipx1; |
| 1166 | | } |
| 1167 | | if (y1 < clipy1) |
| 1168 | | { |
| 1169 | | y1 = clipy1; |
| 1170 | | } |
| 1171 | | if (x2 >= clipx2) |
| 1172 | | { |
| 1173 | | x2 = clipx2-1; |
| 1174 | | } |
| 1175 | | if (y2 >= clipy2) |
| 1176 | | { |
| 1177 | | y2 = clipy2-1; |
| 1178 | | } |
| 1709 | // clip |
| 1710 | if (x1 < clipx1) |
| 1711 | { |
| 1712 | x1 = clipx1; |
| 1713 | } |
| 1714 | if (y1 < clipy1) |
| 1715 | { |
| 1716 | y1 = clipy1; |
| 1717 | } |
| 1718 | if (x2 >= clipx2) |
| 1719 | { |
| 1720 | x2 = clipx2-1; |
| 1721 | } |
| 1722 | if (y2 >= clipy2) |
| 1723 | { |
| 1724 | y2 = clipy2-1; |
| 1725 | } |
| 1179 | 1726 | |
| 1180 | | tsl = tile[rect->tilenum].sl; |
| 1181 | | tsh = tile[rect->tilenum].sh; |
| 1182 | | ttl = tile[rect->tilenum].tl; |
| 1183 | | tth = tile[rect->tilenum].th; |
| 1727 | for( cycle = 0; cycle < 2; cycle++ ) |
| 1728 | { |
| 1729 | tsl[cycle] = tile[rect->tilenum + cycle].sl; |
| 1730 | tsh[cycle] = tile[rect->tilenum + cycle].sh; |
| 1731 | ttl[cycle] = tile[rect->tilenum + cycle].tl; |
| 1732 | tth[cycle] = tile[rect->tilenum + cycle].th; |
| 1184 | 1733 | |
| 1185 | | twidth = tile[rect->tilenum].line; |
| 1186 | | tformat = tile[rect->tilenum].format; |
| 1187 | | tsize = tile[rect->tilenum].size; |
| 1188 | | tbase = tile[rect->tilenum].tmem; |
| 1734 | twidth[cycle] = tile[rect->tilenum + cycle].line; |
| 1735 | tformat[cycle] = tile[rect->tilenum + cycle].format; |
| 1736 | tsize[cycle] = tile[rect->tilenum + cycle].size; |
| 1737 | tbase[cycle] = tile[rect->tilenum + cycle].tmem; |
| 1738 | tpal[cycle] = tile[rect->tilenum + cycle].palette; |
| 1189 | 1739 | |
| 1190 | | clamp_t = tile[rect->tilenum].ct; |
| 1191 | | clamp_s = tile[rect->tilenum].cs; |
| 1740 | clamp_t[cycle] = tile[rect->tilenum + cycle].ct; |
| 1741 | clamp_s[cycle] = tile[rect->tilenum + cycle].cs; |
| 1192 | 1742 | |
| 1193 | | mirror_t = tile[rect->tilenum].mt; |
| 1194 | | mirror_s = tile[rect->tilenum].ms; |
| 1195 | | mask_t = tile[rect->tilenum].mask_t; |
| 1196 | | mask_s = tile[rect->tilenum].mask_s; |
| 1743 | mirror_t[cycle] = tile[rect->tilenum + cycle].mt; |
| 1744 | mirror_s[cycle] = tile[rect->tilenum + cycle].ms; |
| 1745 | mask_t[cycle] = tile[rect->tilenum + cycle].mask_t; |
| 1746 | mask_s[cycle] = tile[rect->tilenum + cycle].mask_s; |
| 1747 | } |
| 1197 | 1748 | |
| 1198 | | t = (int)(rect->t) << 5; |
| 1749 | t = (int)(rect->t) << 5; |
| 1199 | 1750 | |
| 1200 | | if (other_modes.cycle_type == CYCLE_TYPE_1 || other_modes.cycle_type == CYCLE_TYPE_2) |
| 1201 | | { |
| 1202 | | } |
| 1751 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1752 | { |
| 1753 | for (j = y1; j < y2; j += ((j == y1) ? (4 - (y1 & 0x0003)) : 4) ) |
| 1754 | { |
| 1755 | int fb_index = (j >> 2) * fb_width; |
| 1203 | 1756 | |
| 1204 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1205 | | { |
| 1206 | | for (j = y1; j < y2; j++) |
| 1207 | | { |
| 1208 | | int fb_index = j * fb_width; |
| 1757 | s = (int)(rect->s) << 5; |
| 1209 | 1758 | |
| 1210 | | s = (int)(rect->s) << 5; |
| 1759 | memset( cvg_span, 0, RDP_CVG_SPAN_MAX ); |
| 1211 | 1760 | |
| 1212 | | for (i = x1; i < x2; i++) |
| 1213 | | { |
| 1214 | | COLOR c; |
| 1761 | for (span_index = j; span_index < ((j &~ 0x0003) + 4) && span_index < y2; span_index++) |
| 1762 | { |
| 1763 | int span_start = x1; |
| 1764 | int span_end = x2; |
| 1765 | int span_iter = 0; |
| 1766 | if (x1 < 0) |
| 1767 | { |
| 1768 | span_start = 0; |
| 1769 | } |
| 1770 | if (x2 >= (RDP_CVG_SPAN_MAX << 2)) |
| 1771 | { |
| 1772 | span_end = (RDP_CVG_SPAN_MAX << 2) - 1; |
| 1773 | } |
| 1774 | //printf( "%d: Span from %d to %d\n", j, span_start, span_end ); |
| 1775 | for (span_iter=span_start; span_iter < span_end; span_iter++) |
| 1776 | { |
| 1777 | if ((span_iter & 1) == (span_index & 1)) |
| 1778 | { |
| 1779 | cvg_span[span_iter >> 2]++; |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1215 | 1783 | |
| 1216 | | //ss = (s >> 10) - (tsl >> 2); |
| 1217 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1218 | | //st = (t >> 10) - (ttl >> 2); |
| 1219 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 1784 | for (i = x1; i < x2; i += 4) |
| 1785 | { |
| 1786 | if (i >= 0 && i < (RDP_CVG_SPAN_MAX << 2) && cvg_span[i >> 2] > 0) |
| 1787 | { |
| 1788 | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1220 | 1789 | |
| 1221 | | //CLAMP(ss, st); |
| 1222 | | //FETCH_TEXEL(&texel0_color, ss, st, twidth, tformat, tsize, tbase); |
| 1790 | c1 = COLOR_COMBINER(0); |
| 1223 | 1791 | |
| 1224 | | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1792 | if( alpha_compare_success(c1, c2) ) |
| 1793 | { |
| 1794 | int dith = dither_matrix_4x4[(((j >> 2) & 3) << 2) + (((i >> 2)^WORD_ADDR_XOR) & 3)]; |
| 1795 | int cvg_ovf = 0; |
| 1796 | UINT8 cvg_old = 0; |
| 1797 | calculate_coverage( &cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], cvg_span[i >> 2], &cvg_ovf, &cvg_old ); |
| 1798 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 1799 | { |
| 1800 | BLENDER1_16(&fb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], c1, dith, &cvg_span[i >> 2], &cvg_old, &alpha_reject); |
| 1225 | 1801 | |
| 1226 | | c = COLOR_COMBINER(0); |
| 1802 | if( other_modes.z_update_en && other_modes.z_source_sel && !alpha_reject ) |
| 1803 | { |
| 1804 | zb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = primitive_z; |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1227 | 1809 | |
| 1228 | | { |
| 1229 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 1230 | | BLENDER1_16(&fb[(fb_index + i) ^ WORD_ADDR_XOR], c, dith); |
| 1231 | | } |
| 1810 | s += rect->dsdx; |
| 1811 | } |
| 1232 | 1812 | |
| 1233 | | s += rect->dsdx; |
| 1234 | | } |
| 1813 | t += rect->dtdy; |
| 1814 | } |
| 1815 | } |
| 1816 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1817 | { |
| 1818 | for (j = y1; j < y2; j += (j == y1) ? (4 - (y1 & 0x0003)): 4 ) |
| 1819 | { |
| 1820 | int fb_index = (j >> 2) * fb_width; |
| 1235 | 1821 | |
| 1236 | | t += rect->dtdy; |
| 1237 | | } |
| 1238 | | } |
| 1239 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1240 | | { |
| 1241 | | for (j = y1; j < y2; j++) |
| 1242 | | { |
| 1243 | | int fb_index = j * fb_width; |
| 1822 | s = (int)(rect->s) << 5; |
| 1244 | 1823 | |
| 1245 | | s = (int)(rect->s) << 5; |
| 1824 | memset( cvg_span, 0, RDP_CVG_SPAN_MAX ); |
| 1246 | 1825 | |
| 1247 | | for (i = x1; i < x2; i++) |
| 1248 | | { |
| 1249 | | COLOR c1, c2; |
| 1826 | for (span_index = j; span_index < ((j &~ 0x0003) + 4) && span_index < y2; span_index++) |
| 1827 | { |
| 1828 | int span_start = x1; |
| 1829 | int span_end = x2; |
| 1830 | int span_iter = 0; |
| 1831 | if (x1 < 0) |
| 1832 | { |
| 1833 | span_start = 0; |
| 1834 | } |
| 1835 | if (x2 >= (RDP_CVG_SPAN_MAX << 2)) |
| 1836 | { |
| 1837 | span_end = (RDP_CVG_SPAN_MAX << 2) - 1; |
| 1838 | } |
| 1839 | for (span_iter=span_start; span_iter < span_end; span_iter++) |
| 1840 | { |
| 1841 | if ((span_iter & 1) == (span_index & 1)) |
| 1842 | { |
| 1843 | cvg_span[span_iter >> 2]++; |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1250 | 1847 | |
| 1251 | | //ss = (s >> 10) - (tsl >> 2); |
| 1252 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1253 | | //st = (t >> 10) - (ttl >> 2); |
| 1254 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 1848 | for (i = x1; i < x2; i += 4) |
| 1849 | { |
| 1850 | if (i >= 0 && i < (RDP_CVG_SPAN_MAX << 2) && cvg_span[i >> 2] > 0) |
| 1851 | { |
| 1852 | TEXTURE_PIPELINE2(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1255 | 1853 | |
| 1256 | | //CLAMP(ss, st); |
| 1257 | | //FETCH_TEXEL(&texel0_color, ss, st, twidth, tformat, tsize, tbase); |
| 1258 | | //FETCH_TEXEL(&texel1_color, ss, st, twidth, tformat, tsize, tbase); |
| 1854 | c1 = COLOR_COMBINER(0); |
| 1855 | c2 = COLOR_COMBINER(1); |
| 1259 | 1856 | |
| 1260 | | TEXTURE_PIPELINE2(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1857 | if( alpha_compare_success(c1, c2) ) |
| 1858 | { |
| 1859 | int dith = dither_matrix_4x4[((((j >> 2)) & 3) << 2) + (((i >> 2)^WORD_ADDR_XOR) & 3)]; |
| 1860 | int cvg_ovf = 0; |
| 1861 | UINT8 cvg_old = 0; |
| 1862 | calculate_coverage( &cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], cvg_span[i >> 2], &cvg_ovf, &cvg_old ); |
| 1863 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 1864 | { |
| 1865 | BLENDER2_16(&fb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], c1, c2, dith, &cvg_span[i >> 2], &cvg_old, &alpha_reject); |
| 1261 | 1866 | |
| 1262 | | c1 = COLOR_COMBINER(0); |
| 1263 | | c2 = COLOR_COMBINER(1); |
| 1867 | if( other_modes.z_update_en && other_modes.z_source_sel && !alpha_reject ) |
| 1868 | { |
| 1869 | zb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = primitive_z; |
| 1870 | } |
| 1871 | } |
| 1872 | } |
| 1873 | } |
| 1264 | 1874 | |
| 1265 | | //BLENDER2_16(&fb[(fb_index + i) ^ WORD_ADDR_XOR], c1, c2); |
| 1266 | | { |
| 1267 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 1268 | | BLENDER2_16(&fb[(fb_index + i) ^ WORD_ADDR_XOR], c1, c2, dith); |
| 1269 | | } |
| 1875 | s += rect->dsdx; |
| 1876 | } |
| 1270 | 1877 | |
| 1271 | | s += rect->dsdx; |
| 1272 | | } |
| 1878 | t += rect->dtdy; |
| 1879 | } |
| 1880 | } |
| 1881 | else if (other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1882 | { |
| 1883 | for (j = y1; j < y2; j += (j == y1) ? (4 - (y1 & 0x0003)): 4 ) |
| 1884 | { |
| 1885 | int fb_index = (j >> 2) * fb_width; |
| 1273 | 1886 | |
| 1274 | | t += rect->dtdy; |
| 1275 | | } |
| 1276 | | } |
| 1277 | | else if (other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1278 | | { |
| 1279 | | for (j = y1; j < y2; j++) |
| 1280 | | { |
| 1281 | | int fb_index = j * fb_width; |
| 1887 | s = (int)(rect->s) << 5; |
| 1282 | 1888 | |
| 1283 | | s = (int)(rect->s) << 5; |
| 1889 | memset( cvg_span, 0, RDP_CVG_SPAN_MAX ); |
| 1284 | 1890 | |
| 1285 | | for (i = x1; i < x2; i++) |
| 1286 | | { |
| 1287 | | /* |
| 1288 | | if (clamp_s) |
| 1891 | for (span_index = j; span_index < ((j &~ 0x0003) + 4) && span_index < y2; span_index++) |
| 1892 | { |
| 1893 | int span_start = x1; |
| 1894 | int span_end = x2; |
| 1895 | int span_iter = 0; |
| 1896 | if (x1 < 0) |
| 1289 | 1897 | { |
| 1290 | | if (s < (tsl << 8)) s = (tsl << 8); |
| 1291 | | if (s > (tsh << 8)) s = (tsh << 8); |
| 1898 | span_start = 0; |
| 1292 | 1899 | } |
| 1293 | | if (clamp_t) |
| 1900 | if (x2 >= (RDP_CVG_SPAN_MAX << 2)) |
| 1294 | 1901 | { |
| 1295 | | if (t < (ttl << 8)) t = (ttl << 8); |
| 1296 | | if (t > (tth << 8)) t = (tth << 8); |
| 1902 | span_end = (RDP_CVG_SPAN_MAX << 2) - 1; |
| 1297 | 1903 | } |
| 1298 | | if (mask_s) |
| 1904 | for (span_iter=span_start; span_iter < span_end; span_iter++) |
| 1299 | 1905 | { |
| 1300 | | s &= (((UINT32)(0xffffffff) >> (32-mask_s)) << 10) | 0x3ff; |
| 1906 | if ((span_iter & 1) == (span_index & 1)) |
| 1907 | { |
| 1908 | cvg_span[span_iter >> 2]++; |
| 1909 | } |
| 1301 | 1910 | } |
| 1302 | | if (mask_t) |
| 1303 | | { |
| 1304 | | t &= (((UINT32)(0xffffffff) >> (32-mask_t)) << 10) | 0x3ff; |
| 1305 | | } |
| 1911 | } |
| 1306 | 1912 | |
| 1307 | | FETCH_TEXEL(&c, (s-tile[rect->tilenum].sl) >> 10, (t-tile[rect->tilenum].tl) >> 10, twidth, tformat, tsize, tbase); |
| 1308 | | */ |
| 1309 | | //ss = (s >> 10) - (tsl >> 2); |
| 1310 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1311 | | //st = (t >> 10) - (ttl >> 2); |
| 1312 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 1913 | // MooglyGuy note: Fix this, this is probably completely wrong |
| 1313 | 1914 | |
| 1314 | | //CLAMP(ss, st); |
| 1315 | | //FETCH_TEXEL(&c, ss, st, twidth, tformat, tsize, tbase); |
| 1915 | for (i = x1; i < x2; i += 4) |
| 1916 | { |
| 1917 | if (i >= 0 && i < (RDP_CVG_SPAN_MAX << 2) && cvg_span[i >> 2] > 0) |
| 1918 | { |
| 1919 | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1316 | 1920 | |
| 1317 | | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1921 | if( texel0_color.a != 0 ) |
| 1922 | { |
| 1923 | int cvg_ovf = 0; |
| 1924 | UINT8 cvg_old = 0; |
| 1925 | calculate_coverage( &cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], cvg_span[i >> 2], &cvg_ovf, &cvg_old ); |
| 1926 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 1927 | { |
| 1928 | fb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = ((texel0_color.r >> 3) << 11) | ((texel0_color.g >> 3) << 6) | ((texel0_color.b >> 3) << 1) | ((cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] - 1) >> 2); |
| 1929 | if( other_modes.z_update_en && other_modes.z_source_sel ) |
| 1930 | { |
| 1931 | zb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = primitive_z; |
| 1932 | } |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1318 | 1936 | |
| 1319 | | if (texel0_color.a != 0) |
| 1320 | | { |
| 1321 | | fb[(fb_index + i) ^ WORD_ADDR_XOR] = ((texel0_color.r >> 3) << 11) | ((texel0_color.g >> 3) << 6) | ((texel0_color.b >> 3) << 1); |
| 1322 | | } |
| 1937 | s += rect->dsdx; |
| 1938 | } |
| 1323 | 1939 | |
| 1324 | | s += rect->dsdx; |
| 1325 | | } |
| 1326 | | |
| 1327 | | t += rect->dtdy; |
| 1328 | | } |
| 1329 | | } |
| 1330 | | else |
| 1331 | | { |
| 1332 | | fatalerror("texture_rectangle_16bit: unknown cycle type %d\n", other_modes.cycle_type); |
| 1333 | | } |
| 1940 | t += rect->dtdy; |
| 1941 | } |
| 1942 | } |
| 1943 | else |
| 1944 | { |
| 1945 | fatalerror("texture_rectangle_16bit: unknown cycle type %d\n", other_modes.cycle_type); |
| 1946 | } |
| 1334 | 1947 | } |
| 1335 | 1948 | |
| 1336 | 1949 | /*****************************************************************************/ |
| 1337 | 1950 | |
| 1338 | | INLINE void BLENDER1_32(UINT32 *fb, COLOR c) |
| 1951 | INLINE void BLENDER1_32(UINT32 *fb, COLOR c, UINT8 *new_cvg, UINT8 *old_cvg, int *alpha_reject) |
| 1339 | 1952 | { |
| 1340 | | int r, g, b; |
| 1953 | int r, g, b; |
| 1341 | 1954 | |
| 1342 | | pixel_color.r = c.r; inv_pixel_color.r = 0xff - c.r; |
| 1343 | | pixel_color.g = c.g; inv_pixel_color.g = 0xff - c.g; |
| 1344 | | pixel_color.b = c.b; inv_pixel_color.b = 0xff - c.b; |
| 1345 | | pixel_color.a = c.a; inv_pixel_color.a = 0xff - c.a; |
| 1955 | if( other_modes.force_blend ) |
| 1956 | { |
| 1957 | blend_color.r = c.r; |
| 1958 | blend_color.g = c.g; |
| 1959 | blend_color.b = c.b; |
| 1960 | } |
| 1346 | 1961 | |
| 1347 | | if (other_modes.image_read_en) |
| 1348 | | { |
| 1349 | | UINT32 mem = *fb; |
| 1350 | | memory_color.r = ((mem >> 16) & 0xff); |
| 1351 | | memory_color.g = ((mem >> 8) & 0xff); |
| 1352 | | memory_color.b = ((mem >> 0) & 0xff); |
| 1353 | | memory_color.a = 0; |
| 1354 | | } |
| 1962 | pixel_color.r = c.r; |
| 1963 | pixel_color.g = c.g; |
| 1964 | pixel_color.b = c.b; |
| 1965 | pixel_color.a = c.a; |
| 1966 | inv_pixel_color.r = 0xff - *blender1a_r[0]; |
| 1967 | inv_pixel_color.g = 0xff - *blender1a_g[0]; |
| 1968 | inv_pixel_color.b = 0xff - *blender1a_b[0]; |
| 1969 | inv_pixel_color.a = 0xff - *blender1b_a[0]; |
| 1355 | 1970 | |
| 1356 | | r = (((int)(*blender1a_r[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1357 | | (((int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) >> 8); |
| 1971 | if( other_modes.alpha_cvg_select ) |
| 1972 | { |
| 1973 | if( other_modes.cvg_times_alpha ) |
| 1974 | { |
| 1975 | pixel_color.a = (UINT8)( ( (INT32)(c.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 1980 | } |
| 1358 | 1981 | |
| 1359 | | g = (((int)(*blender1a_g[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1360 | | (((int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) >> 8); |
| 1982 | if( pixel_color.a == 0 ) |
| 1983 | { |
| 1984 | *alpha_reject = 1; |
| 1985 | return; |
| 1986 | } |
| 1987 | } |
| 1361 | 1988 | |
| 1362 | | b = (((int)(*blender1a_b[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1363 | | (((int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) >> 8); |
| 1989 | if (other_modes.image_read_en) |
| 1990 | { |
| 1991 | UINT32 mem = *fb; |
| 1992 | memory_color.r = ((mem >> 24) & 0xff); |
| 1993 | memory_color.g = ((mem >> 16) & 0xff); |
| 1994 | memory_color.b = ((mem >> 8) & 0xff); |
| 1995 | memory_color.a = /*(UINT8)((INT32)(*old_cvg) * 0x20 - 1)*/0; |
| 1996 | } |
| 1364 | 1997 | |
| 1365 | | //r = g = b = 0xff; |
| 1998 | if (((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])) > 0) |
| 1999 | { |
| 2000 | r = ((int)(*blender1a_r[0]) * (int)(*blender1b_a[0]) + |
| 2001 | (int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) / |
| 2002 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 1366 | 2003 | |
| 1367 | | if (r > 255) r = 255; |
| 1368 | | if (g > 255) g = 255; |
| 1369 | | if (b > 255) b = 255; |
| 2004 | g = ((int)(*blender1a_g[0]) * (int)(*blender1b_a[0]) + |
| 2005 | (int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) / |
| 2006 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 1370 | 2007 | |
| 1371 | | *fb = (r << 16) | (g << 8) | b; |
| 2008 | b = ((int)(*blender1a_b[0]) * (int)(*blender1b_a[0]) + |
| 2009 | (int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) / |
| 2010 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 2011 | } |
| 2012 | else |
| 2013 | { |
| 2014 | r = g = b = 0; |
| 2015 | } |
| 2016 | |
| 2017 | //r = g = b = 0xff; |
| 2018 | |
| 2019 | if (r > 255) r = 255; |
| 2020 | if (g > 255) g = 255; |
| 2021 | if (b > 255) b = 255; |
| 2022 | |
| 2023 | *fb = (r << 24) | (g << 16) | (b << 8) | 0xe0; |
| 1372 | 2024 | } |
| 1373 | 2025 | |
| 1374 | | INLINE void BLENDER2_32(UINT32 *fb, COLOR c1, COLOR c2) |
| 2026 | INLINE void BLENDER2_32(UINT32 *fb, COLOR c1, COLOR c2, UINT8 *new_cvg, UINT8 *old_cvg, int *alpha_reject) |
| 1375 | 2027 | { |
| 1376 | | int r, g, b; |
| 2028 | int r, g, b; |
| 1377 | 2029 | |
| 1378 | | pixel_color.r = c1.r; inv_pixel_color.r = 0xff - c1.r; |
| 1379 | | pixel_color.g = c1.g; inv_pixel_color.g = 0xff - c1.g; |
| 1380 | | pixel_color.b = c1.b; inv_pixel_color.b = 0xff - c1.b; |
| 1381 | | pixel_color.a = c1.a; inv_pixel_color.a = 0xff - c1.a; |
| 2030 | if( other_modes.force_blend ) |
| 2031 | { |
| 2032 | blend_color.r = c2.r; |
| 2033 | blend_color.g = c2.g; |
| 2034 | blend_color.b = c2.b; |
| 2035 | } |
| 1382 | 2036 | |
| 1383 | | if (other_modes.image_read_en) |
| 1384 | | { |
| 1385 | | UINT32 mem = *fb; |
| 1386 | | memory_color.r = ((mem >> 16) & 0xff); |
| 1387 | | memory_color.g = ((mem >> 8) & 0xff); |
| 1388 | | memory_color.b = ((mem >> 0) & 0xff); |
| 1389 | | memory_color.a = 0; |
| 1390 | | } |
| 2037 | pixel_color.r = c2.r; |
| 2038 | pixel_color.g = c2.g; |
| 2039 | pixel_color.b = c2.b; |
| 2040 | pixel_color.a = c2.a; |
| 2041 | inv_pixel_color.r = 0xff - *blender1a_r[0]; |
| 2042 | inv_pixel_color.g = 0xff - *blender1a_g[0]; |
| 2043 | inv_pixel_color.b = 0xff - *blender1a_b[0]; |
| 2044 | inv_pixel_color.a = 0xff - *blender1b_a[0]; |
| 1391 | 2045 | |
| 1392 | | r = (((int)(*blender1a_r[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1393 | | (((int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) >> 8); |
| 2046 | if( other_modes.alpha_cvg_select ) |
| 2047 | { |
| 2048 | if( other_modes.cvg_times_alpha ) |
| 2049 | { |
| 2050 | pixel_color.a = (UINT8)( ( (INT32)(c2.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 2051 | } |
| 2052 | else |
| 2053 | { |
| 2054 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 2055 | } |
| 1394 | 2056 | |
| 1395 | | g = (((int)(*blender1a_g[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1396 | | (((int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) >> 8); |
| 2057 | if( pixel_color.a == 0 ) |
| 2058 | { |
| 2059 | *alpha_reject = 1; |
| 2060 | return; |
| 2061 | } |
| 2062 | } |
| 1397 | 2063 | |
| 1398 | | b = (((int)(*blender1a_b[0]) * (int)(*blender1b_a[0])) >> 8) + |
| 1399 | | (((int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) >> 8); |
| 2064 | if (other_modes.image_read_en) |
| 2065 | { |
| 2066 | UINT32 mem = *fb; |
| 2067 | memory_color.r = ((mem >> 24) & 0xff); |
| 2068 | memory_color.g = ((mem >> 16) & 0xff); |
| 2069 | memory_color.b = ((mem >> 8) & 0xff); |
| 2070 | memory_color.a = /*(UINT8)((INT32)(*old_cvg) * 0x20 - 1)*/0; |
| 2071 | } |
| 1400 | 2072 | |
| 1401 | | blended_pixel_color.r = r; |
| 1402 | | blended_pixel_color.g = g; |
| 1403 | | blended_pixel_color.b = b; |
| 2073 | if (((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])) > 0) |
| 2074 | { |
| 2075 | r = ((int)(*blender1a_r[0]) * (int)(*blender1b_a[0]) + |
| 2076 | (int)(*blender2a_r[0]) * (int)(*blender2b_a[0])) / |
| 2077 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 1404 | 2078 | |
| 1405 | | pixel_color.r = c2.r; inv_pixel_color.r = 0xff - c2.r; |
| 1406 | | pixel_color.g = c2.g; inv_pixel_color.g = 0xff - c2.g; |
| 1407 | | pixel_color.b = c2.b; inv_pixel_color.b = 0xff - c2.b; |
| 1408 | | pixel_color.a = c2.a; inv_pixel_color.a = 0xff - c2.a; |
| 2079 | g = ((int)(*blender1a_g[0]) * (int)(*blender1b_a[0]) + |
| 2080 | (int)(*blender2a_g[0]) * (int)(*blender2b_a[0])) / |
| 2081 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 1409 | 2082 | |
| 1410 | | r = (((int)(*blender1a_r[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 1411 | | (((int)(*blender2a_r[1]) * (int)(*blender2b_a[1])) >> 8); |
| 2083 | b = ((int)(*blender1a_b[0]) * (int)(*blender1b_a[0]) + |
| 2084 | (int)(*blender2a_b[0]) * (int)(*blender2b_a[0])) / |
| 2085 | ((int)(*blender1b_a[0]) + (int)(*blender2b_a[0])); |
| 2086 | } |
| 2087 | else |
| 2088 | { |
| 2089 | r = g = b = 0; |
| 2090 | } |
| 1412 | 2091 | |
| 1413 | | g = (((int)(*blender1a_g[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 1414 | | (((int)(*blender2a_g[1]) * (int)(*blender2b_a[1])) >> 8); |
| 2092 | blended_pixel_color.r = r; |
| 2093 | blended_pixel_color.g = g; |
| 2094 | blended_pixel_color.b = b; |
| 1415 | 2095 | |
| 1416 | | b = (((int)(*blender1a_b[1]) * (int)(*blender1b_a[1])) >> 8) + |
| 1417 | | (((int)(*blender2a_b[1]) * (int)(*blender2b_a[1])) >> 8); |
| 2096 | pixel_color.r = c2.r; |
| 2097 | pixel_color.g = c2.g; |
| 2098 | pixel_color.b = c2.b; |
| 2099 | pixel_color.a = c2.a; |
| 2100 | if( other_modes.alpha_cvg_select ) |
| 2101 | { |
| 2102 | if( other_modes.cvg_times_alpha ) |
| 2103 | { |
| 2104 | pixel_color.a = (UINT8)( ( (INT32)(c2.a) * (INT32)( (*new_cvg) * 0x20 - 1 ) ) >> 8 ); |
| 2105 | } |
| 2106 | else |
| 2107 | { |
| 2108 | pixel_color.a = (UINT8)( (INT32)(*new_cvg) * 0x20 - 1 ); |
| 2109 | } |
| 1418 | 2110 | |
| 1419 | | if (r > 255) r = 255; |
| 1420 | | if (g > 255) g = 255; |
| 1421 | | if (b > 255) b = 255; |
| 2111 | if( pixel_color.a == 0 ) |
| 2112 | { |
| 2113 | *alpha_reject = 1; |
| 2114 | return; |
| 2115 | } |
| 2116 | } |
| 2117 | inv_pixel_color.r = 0xff - *blender1a_r[0]; |
| 2118 | inv_pixel_color.g = 0xff - *blender1a_g[0]; |
| 2119 | inv_pixel_color.b = 0xff - *blender1a_b[0]; |
| 2120 | inv_pixel_color.a = 0xff - *blender1b_a[0]; |
| 1422 | 2121 | |
| 1423 | | *fb = (r << 16) | (g << 8) | b; |
| 2122 | if (((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])) > 0) |
| 2123 | { |
| 2124 | r = ((int)(*blender1a_r[1]) * (int)(*blender1b_a[1]) + |
| 2125 | (int)(*blender2a_r[1]) * (int)(*blender2b_a[1])) / |
| 2126 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 2127 | |
| 2128 | g = ((int)(*blender1a_g[1]) * (int)(*blender1b_a[1]) + |
| 2129 | (int)(*blender2a_g[1]) * (int)(*blender2b_a[1])) / |
| 2130 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 2131 | |
| 2132 | b = ((int)(*blender1a_b[1]) * (int)(*blender1b_a[1]) + |
| 2133 | (int)(*blender2a_b[1]) * (int)(*blender2b_a[1])) / |
| 2134 | ((int)(*blender1b_a[1]) + (int)(*blender2b_a[1])); |
| 2135 | } |
| 2136 | else |
| 2137 | { |
| 2138 | r = g = b = 0; |
| 2139 | } |
| 2140 | |
| 2141 | if (r > 255) r = 255; |
| 2142 | if (g > 255) g = 255; |
| 2143 | if (b > 255) b = 255; |
| 2144 | |
| 2145 | *fb = (r << 24) | (g << 16) | (b << 8) | 0xe0; |
| 1424 | 2146 | } |
| 1425 | 2147 | |
| 1426 | 2148 | static void fill_rectangle_32bit(RECTANGLE *rect) |
| 1427 | 2149 | { |
| 1428 | | UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)]; |
| 1429 | | int index, i, j; |
| 1430 | | int x1 = rect->xh / 4; |
| 1431 | | int x2 = rect->xl / 4; |
| 1432 | | int y1 = rect->yh / 4; |
| 1433 | | int y2 = rect->yl / 4; |
| 1434 | | int clipx1, clipx2, clipy1, clipy2; |
| 2150 | UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)]; |
| 2151 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 2152 | int index, i, j; |
| 2153 | int x1 = rect->xh / 4; |
| 2154 | int x2 = rect->xl / 4; |
| 2155 | int y1 = rect->yh / 4; |
| 2156 | int y2 = rect->yl / 4; |
| 2157 | int clipx1, clipx2, clipy1, clipy2; |
| 2158 | int alpha_reject = 0; |
| 2159 | COLOR c1, c2; |
| 2160 | c1.r = c1.g = c1.b = c1.a = 0; |
| 2161 | c2.r = c2.g = c2.b = c2.a = 0; |
| 1435 | 2162 | |
| 1436 | | // TODO: clip |
| 1437 | | clipx1 = clip.xh / 4; |
| 1438 | | clipx2 = clip.xl / 4; |
| 1439 | | clipy1 = clip.yh / 4; |
| 1440 | | clipy2 = clip.yl / 4; |
| 2163 | // TODO: clip |
| 2164 | clipx1 = clip.xh / 4; |
| 2165 | clipx2 = clip.xl / 4; |
| 2166 | clipy1 = clip.yh / 4; |
| 2167 | clipy2 = clip.yl / 4; |
| 1441 | 2168 | |
| 1442 | | // clip |
| 1443 | | if (x1 < clipx1) |
| 1444 | | { |
| 1445 | | x1 = clipx1; |
| 1446 | | } |
| 1447 | | if (y1 < clipy1) |
| 1448 | | { |
| 1449 | | y1 = clipy1; |
| 1450 | | } |
| 1451 | | if (x2 >= clipx2) |
| 1452 | | { |
| 1453 | | x2 = clipx2-1; |
| 1454 | | } |
| 1455 | | if (y2 >= clipy2) |
| 1456 | | { |
| 1457 | | y2 = clipy2-1; |
| 1458 | | } |
| 2169 | // clip |
| 2170 | if (x1 < clipx1) |
| 2171 | { |
| 2172 | x1 = clipx1; |
| 2173 | } |
| 2174 | if (y1 < clipy1) |
| 2175 | { |
| 2176 | y1 = clipy1; |
| 2177 | } |
| 2178 | if (x2 >= clipx2) |
| 2179 | { |
| 2180 | x2 = clipx2-1; |
| 2181 | } |
| 2182 | if (y2 >= clipy2) |
| 2183 | { |
| 2184 | y2 = clipy2-1; |
| 2185 | } |
| 1459 | 2186 | |
| 1460 | | if (other_modes.cycle_type == CYCLE_TYPE_FILL) |
| 1461 | | { |
| 1462 | | for (j=y1; j <= y2; j++) |
| 1463 | | { |
| 1464 | | index = j * fb_width; |
| 1465 | | for (i=x1; i <= x2; i++) |
| 1466 | | { |
| 1467 | | fb[(index + i) ^ 1] = fill_color; |
| 1468 | | } |
| 1469 | | } |
| 1470 | | } |
| 1471 | | else if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1472 | | { |
| 1473 | | shade_color.r = prim_color.r; |
| 1474 | | shade_color.g = prim_color.g; |
| 1475 | | shade_color.b = prim_color.b; |
| 1476 | | shade_color.a = prim_color.a; |
| 2187 | if (other_modes.cycle_type == CYCLE_TYPE_FILL) |
| 2188 | { |
| 2189 | for (j=y1; j <= y2; j++) |
| 2190 | { |
| 2191 | index = j * fb_width; |
| 2192 | for (i=x1; i <= x2; i++) |
| 2193 | { |
| 2194 | cvg_buf[(index + i)] = (fill_color & 0x000000ff) ? 8 : 1; // Wrong |
| 2195 | fb[(index + i) ^ 1] = fill_color; |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | else if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2200 | { |
| 2201 | shade_color.r = prim_color.r; |
| 2202 | shade_color.g = prim_color.g; |
| 2203 | shade_color.b = prim_color.b; |
| 2204 | shade_color.a = prim_color.a; |
| 1477 | 2205 | |
| 1478 | | for (j=y1; j <= y2; j++) |
| 1479 | | { |
| 1480 | | index = j * fb_width; |
| 1481 | | for (i=x1; i <= x2; i++) |
| 1482 | | { |
| 1483 | | COLOR c = COLOR_COMBINER(0); |
| 2206 | for (j=y1; j <= y2; j++) |
| 2207 | { |
| 2208 | index = j * fb_width; |
| 2209 | for (i=x1; i <= x2; i++) |
| 2210 | { |
| 2211 | c1 = COLOR_COMBINER(0); |
| 1484 | 2212 | |
| 1485 | | BLENDER1_32(&fb[(index + i)], c); |
| 1486 | | } |
| 1487 | | } |
| 1488 | | } |
| 1489 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1490 | | { |
| 1491 | | shade_color.r = prim_color.r; |
| 1492 | | shade_color.g = prim_color.g; |
| 1493 | | shade_color.b = prim_color.b; |
| 1494 | | shade_color.a = prim_color.a; |
| 2213 | cvg_buf[(index + i)] = 8; // Wrong |
| 2214 | BLENDER1_32(&fb[(index + i)], c1, &cvg_buf[(index + i)], &cvg_buf[(index + i)], &alpha_reject); |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 2219 | { |
| 2220 | shade_color.r = prim_color.r; |
| 2221 | shade_color.g = prim_color.g; |
| 2222 | shade_color.b = prim_color.b; |
| 2223 | shade_color.a = prim_color.a; |
| 1495 | 2224 | |
| 1496 | | for (j=y1; j <= y2; j++) |
| 1497 | | { |
| 1498 | | index = j * fb_width; |
| 1499 | | for (i=x1; i <= x2; i++) |
| 1500 | | { |
| 1501 | | COLOR c1 = COLOR_COMBINER(0); |
| 1502 | | COLOR c2 = COLOR_COMBINER(1); |
| 2225 | for (j=y1; j <= y2; j++) |
| 2226 | { |
| 2227 | index = j * fb_width; |
| 2228 | for (i=x1; i <= x2; i++) |
| 2229 | { |
| 2230 | c1 = COLOR_COMBINER(0); |
| 2231 | c2 = COLOR_COMBINER(1); |
| 1503 | 2232 | |
| 1504 | | BLENDER2_32(&fb[(index + i)], c1, c2); |
| 1505 | | } |
| 1506 | | } |
| 1507 | | } |
| 1508 | | else |
| 1509 | | { |
| 1510 | | fatalerror("fill_rectangle_32bit: cycle type copy"); |
| 1511 | | } |
| 2233 | cvg_buf[(index + i)] = 8; // Wrong |
| 2234 | BLENDER2_32(&fb[(index + i)], c1, c2, &cvg_buf[(index + i)], &cvg_buf[(index + i)], &alpha_reject); |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | else |
| 2239 | { |
| 2240 | fatalerror("fill_rectangle_32bit: cycle type copy"); |
| 2241 | } |
| 1512 | 2242 | } |
| 1513 | 2243 | |
| 1514 | 2244 | static void texture_rectangle_32bit(TEX_RECTANGLE *rect) |
| 1515 | 2245 | { |
| 1516 | | UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)]; |
| 1517 | | int i, j; |
| 1518 | | int x1, x2, y1, y2; |
| 1519 | | int tsl, tsh, ttl, tth; |
| 1520 | | int s, t; |
| 1521 | | int twidth, tformat, tsize, tbase; |
| 1522 | | int clamp_s, clamp_t, mask_s, mask_t, mirror_s, mirror_t; |
| 1523 | | int clipx1, clipx2, clipy1, clipy2; |
| 2246 | UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)]; |
| 2247 | UINT16 *zb = (UINT16*)&rdram[(zb_address / 4)]; |
| 2248 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 2249 | int i, j; |
| 2250 | int x1, x2, y1, y2; |
| 2251 | int tsl[2], tsh[2], ttl[2], tth[2]; |
| 2252 | int s, t; |
| 2253 | int twidth[2], tformat[2], tsize[2], tbase[2], tpal[2]; |
| 2254 | int clamp_s[2], clamp_t[2], mask_s[2], mask_t[2], mirror_s[2], mirror_t[2]; |
| 2255 | int clipx1, clipx2, clipy1, clipy2; |
| 2256 | int cycle; |
| 2257 | UINT8 cvg_span[RDP_CVG_SPAN_MAX]; |
| 2258 | int span_index = 0; |
| 2259 | int alpha_reject = 0; |
| 2260 | COLOR c1, c2; |
| 2261 | c1.r = c1.g = c1.b = c1.a = 0; |
| 2262 | c2.r = c2.g = c2.b = c2.a = 0; |
| 1524 | 2263 | |
| 1525 | | x1 = (rect->xh / 4); |
| 1526 | | x2 = (rect->xl / 4); |
| 1527 | | y1 = (rect->yh / 4); |
| 1528 | | y2 = (rect->yl / 4); |
| 2264 | x1 = rect->xh; |
| 2265 | x2 = rect->xl; |
| 2266 | y1 = rect->yh; |
| 2267 | y2 = rect->yl; |
| 1529 | 2268 | |
| 1530 | | if (other_modes.cycle_type == CYCLE_TYPE_FILL || other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1531 | | { |
| 1532 | | rect->dsdx /= 4; |
| 1533 | | x2 += 1; |
| 1534 | | y2 += 1; |
| 1535 | | } |
| 2269 | if (other_modes.cycle_type == CYCLE_TYPE_FILL || other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 2270 | { |
| 2271 | rect->dsdx /= 4; |
| 2272 | x2 += 1; |
| 2273 | y2 += 1; |
| 2274 | } |
| 1536 | 2275 | |
| 1537 | | clipx1 = clip.xh / 4; |
| 1538 | | clipx2 = clip.xl / 4; |
| 1539 | | clipy1 = clip.yh / 4; |
| 1540 | | clipy2 = clip.yl / 4; |
| 2276 | clipx1 = clip.xh; |
| 2277 | clipx2 = clip.xl; |
| 2278 | clipy1 = clip.yh; |
| 2279 | clipy2 = clip.yl; |
| 1541 | 2280 | |
| 1542 | | // clip |
| 1543 | | if (x1 < clipx1) |
| 1544 | | { |
| 1545 | | x1 = clipx1; |
| 1546 | | } |
| 1547 | | if (y1 < clipy1) |
| 1548 | | { |
| 1549 | | y1 = clipy1; |
| 1550 | | } |
| 1551 | | if (x2 >= clipx2) |
| 1552 | | { |
| 1553 | | x2 = clipx2-1; |
| 1554 | | } |
| 1555 | | if (y2 >= clipy2) |
| 1556 | | { |
| 1557 | | y2 = clipy2-1; |
| 1558 | | } |
| 2281 | // clip |
| 2282 | if (x1 < clipx1) |
| 2283 | { |
| 2284 | x1 = clipx1; |
| 2285 | } |
| 2286 | if (y1 < clipy1) |
| 2287 | { |
| 2288 | y1 = clipy1; |
| 2289 | } |
| 2290 | if (x2 >= clipx2) |
| 2291 | { |
| 2292 | x2 = clipx2-1; |
| 2293 | } |
| 2294 | if (y2 >= clipy2) |
| 2295 | { |
| 2296 | y2 = clipy2-1; |
| 2297 | } |
| 1559 | 2298 | |
| 1560 | | tsl = tile[rect->tilenum].sl; |
| 1561 | | tsh = tile[rect->tilenum].sh; |
| 1562 | | ttl = tile[rect->tilenum].tl; |
| 1563 | | tth = tile[rect->tilenum].th; |
| 2299 | for( cycle = 0; cycle < 2; cycle++ ) |
| 2300 | { |
| 2301 | tsl[cycle] = tile[rect->tilenum + cycle].sl; |
| 2302 | tsh[cycle] = tile[rect->tilenum + cycle].sh; |
| 2303 | ttl[cycle] = tile[rect->tilenum + cycle].tl; |
| 2304 | tth[cycle] = tile[rect->tilenum + cycle].th; |
| 1564 | 2305 | |
| 1565 | | twidth = tile[rect->tilenum].line; |
| 1566 | | tformat = tile[rect->tilenum].format; |
| 1567 | | tsize = tile[rect->tilenum].size; |
| 1568 | | tbase = tile[rect->tilenum].tmem; |
| 2306 | twidth[cycle] = tile[rect->tilenum + cycle].line; |
| 2307 | tformat[cycle] = tile[rect->tilenum + cycle].format; |
| 2308 | tsize[cycle] = tile[rect->tilenum + cycle].size; |
| 2309 | tbase[cycle] = tile[rect->tilenum + cycle].tmem; |
| 2310 | tpal[cycle] = tile[rect->tilenum + cycle].palette; |
| 1569 | 2311 | |
| 1570 | | clamp_t = tile[rect->tilenum].ct; |
| 1571 | | clamp_s = tile[rect->tilenum].cs; |
| 2312 | clamp_t[cycle] = tile[rect->tilenum + cycle].ct; |
| 2313 | clamp_s[cycle] = tile[rect->tilenum + cycle].cs; |
| 1572 | 2314 | |
| 1573 | | mirror_t = tile[rect->tilenum].mt; |
| 1574 | | mirror_s = tile[rect->tilenum].ms; |
| 1575 | | mask_t = tile[rect->tilenum].mask_t; |
| 1576 | | mask_s = tile[rect->tilenum].mask_s; |
| 2315 | mirror_t[cycle] = tile[rect->tilenum + cycle].mt; |
| 2316 | mirror_s[cycle] = tile[rect->tilenum + cycle].ms; |
| 2317 | mask_t[cycle] = tile[rect->tilenum + cycle].mask_t; |
| 2318 | mask_s[cycle] = tile[rect->tilenum + cycle].mask_s; |
| 2319 | } |
| 1577 | 2320 | |
| 1578 | | t = (int)(rect->t) << 5; |
| 2321 | t = (int)(rect->t) << 5; |
| 1579 | 2322 | |
| 1580 | | if (other_modes.cycle_type == CYCLE_TYPE_1 || other_modes.cycle_type == CYCLE_TYPE_2) |
| 1581 | | { |
| 1582 | | } |
| 2323 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2324 | { |
| 2325 | for (j = y1; j < y2; j += ((j == y1) ? (4 - (y1 & 0x0003)) : 4) ) |
| 2326 | { |
| 2327 | int fb_index = (j >> 2) * fb_width; |
| 1583 | 2328 | |
| 1584 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1585 | | { |
| 1586 | | for (j = y1; j < y2; j++) |
| 1587 | | { |
| 1588 | | int fb_index = j * fb_width; |
| 2329 | s = (int)(rect->s) << 5; |
| 1589 | 2330 | |
| 1590 | | s = (int)(rect->s) << 5; |
| 2331 | memset( cvg_span, 0, RDP_CVG_SPAN_MAX ); |
| 1591 | 2332 | |
| 1592 | | for (i = x1; i < x2; i++) |
| 1593 | | { |
| 1594 | | COLOR c; |
| 2333 | for (span_index = j; span_index < ((j &~ 0x0003) + 4) && span_index < y2; span_index++) |
| 2334 | { |
| 2335 | int span_start = x1; |
| 2336 | int span_end = x2; |
| 2337 | int span_iter = 0; |
| 2338 | if (x1 < 0) |
| 2339 | { |
| 2340 | span_start = 0; |
| 2341 | } |
| 2342 | if (x2 >= (RDP_CVG_SPAN_MAX << 2)) |
| 2343 | { |
| 2344 | span_end = (RDP_CVG_SPAN_MAX << 2) - 1; |
| 2345 | } |
| 2346 | //printf( "%d: Span from %d to %d\n", j, span_start, span_end ); |
| 2347 | for (span_iter=span_start; span_iter < span_end; span_iter++) |
| 2348 | { |
| 2349 | if ((span_iter & 1) == (span_index & 1)) |
| 2350 | { |
| 2351 | cvg_span[span_iter >> 2]++; |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 1595 | 2355 | |
| 1596 | | //ss = (s >> 10) - (tsl >> 2); |
| 1597 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1598 | | //st = (t >> 10) - (ttl >> 2); |
| 1599 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 2356 | for (i = x1; i < x2; i += 4) |
| 2357 | { |
| 2358 | if (i >= 0 && i < (RDP_CVG_SPAN_MAX << 2) && cvg_span[i >> 2] > 0) |
| 2359 | { |
| 2360 | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1600 | 2361 | |
| 1601 | | //CLAMP(ss, st); |
| 1602 | | //FETCH_TEXEL(&texel0_color, ss, st, twidth, tformat, tsize, tbase); |
| 2362 | c1 = COLOR_COMBINER(0); |
| 1603 | 2363 | |
| 1604 | | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 2364 | if( alpha_compare_success(c1, c2) ) |
| 2365 | { |
| 2366 | int cvg_ovf = 0; |
| 2367 | UINT8 cvg_old = 0; |
| 2368 | calculate_coverage( &cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], cvg_span[i >> 2], &cvg_ovf, &cvg_old ); |
| 2369 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 2370 | { |
| 2371 | BLENDER1_32(&fb[(fb_index + (i >> 2))], c1, &cvg_span[i >> 2], &cvg_old, &alpha_reject); |
| 1605 | 2372 | |
| 1606 | | c = COLOR_COMBINER(0); |
| 2373 | if( other_modes.z_update_en && other_modes.z_source_sel && !alpha_reject ) |
| 2374 | { |
| 2375 | zb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = primitive_z; |
| 2376 | } |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 1607 | 2380 | |
| 1608 | | BLENDER1_32(&fb[(fb_index + i)], c); |
| 2381 | s += rect->dsdx; |
| 2382 | } |
| 1609 | 2383 | |
| 1610 | | s += rect->dsdx; |
| 1611 | | } |
| 2384 | t += rect->dtdy; |
| 2385 | } |
| 2386 | } |
| 2387 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 2388 | { |
| 2389 | for (j = y1; j < y2; j += (j == y1) ? (4 - (y1 & 0x0003)): 4 ) |
| 2390 | { |
| 2391 | int fb_index = (j >> 2) * fb_width; |
| 1612 | 2392 | |
| 1613 | | t += rect->dtdy; |
| 1614 | | } |
| 1615 | | } |
| 1616 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1617 | | { |
| 1618 | | for (j = y1; j < y2; j++) |
| 1619 | | { |
| 1620 | | int fb_index = j * fb_width; |
| 2393 | s = (int)(rect->s) << 5; |
| 1621 | 2394 | |
| 1622 | | s = (int)(rect->s) << 5; |
| 2395 | memset( cvg_span, 0, RDP_CVG_SPAN_MAX ); |
| 1623 | 2396 | |
| 1624 | | for (i = x1; i < x2; i++) |
| 1625 | | { |
| 1626 | | COLOR c1, c2; |
| 2397 | for (span_index = j; span_index < ((j &~ 0x0003) + 4) && span_index < y2; span_index++) |
| 2398 | { |
| 2399 | int span_start = x1; |
| 2400 | int span_end = x2; |
| 2401 | int span_iter = 0; |
| 2402 | if (x1 < 0) |
| 2403 | { |
| 2404 | span_start = 0; |
| 2405 | } |
| 2406 | if (x2 >= (RDP_CVG_SPAN_MAX << 2)) |
| 2407 | { |
| 2408 | span_end = (RDP_CVG_SPAN_MAX << 2) - 1; |
| 2409 | } |
| 2410 | for (span_iter=span_start; span_iter < span_end; span_iter++) |
| 2411 | { |
| 2412 | if ((span_iter & 1) == (span_index & 1)) |
| 2413 | { |
| 2414 | cvg_span[span_iter >> 2]++; |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 1627 | 2418 | |
| 1628 | | //ss = (s >> 10) - (tsl >> 2); |
| 1629 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1630 | | //st = (t >> 10) - (ttl >> 2); |
| 1631 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 2419 | for (i = x1; i < x2; i += 4) |
| 2420 | { |
| 2421 | if (i >= 0 && i < (RDP_CVG_SPAN_MAX << 2) && cvg_span[i >> 2] > 0) |
| 2422 | { |
| 2423 | TEXTURE_PIPELINE2(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1632 | 2424 | |
| 1633 | | //CLAMP(ss, st); |
| 1634 | | //FETCH_TEXEL(&texel0_color, ss, st, twidth, tformat, tsize, tbase); |
| 1635 | | //FETCH_TEXEL(&texel1_color, ss, st, twidth, tformat, tsize, tbase); |
| 2425 | c1 = COLOR_COMBINER(0); |
| 2426 | c2 = COLOR_COMBINER(1); |
| 1636 | 2427 | |
| 1637 | | TEXTURE_PIPELINE2(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 2428 | if( alpha_compare_success(c1, c2) ) |
| 2429 | { |
| 2430 | int cvg_ovf = 0; |
| 2431 | UINT8 cvg_old = 0; |
| 2432 | calculate_coverage( &cvg_buf[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR], cvg_span[i >> 2], &cvg_ovf, &cvg_old ); |
| 2433 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 2434 | { |
| 2435 | BLENDER2_32(&fb[fb_index + (i >> 2)], c1, c2, &cvg_span[i >> 2], &cvg_old, &alpha_reject); |
| 1638 | 2436 | |
| 1639 | | c1 = COLOR_COMBINER(0); |
| 1640 | | c2 = COLOR_COMBINER(1); |
| 2437 | if( other_modes.z_update_en && other_modes.z_source_sel && !alpha_reject ) |
| 2438 | { |
| 2439 | zb[(fb_index + (i >> 2)) ^ WORD_ADDR_XOR] = primitive_z; |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | } |
| 1641 | 2444 | |
| 1642 | | BLENDER2_32(&fb[(fb_index + i)], c1, c2); |
| 2445 | s += rect->dsdx; |
| 2446 | } |
| 1643 | 2447 | |
| 1644 | | s += rect->dsdx; |
| 1645 | | } |
| 2448 | t += rect->dtdy; |
| 2449 | } |
| 2450 | } |
| 2451 | else if (other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 2452 | { |
| 2453 | for (j = y1; j < y2; j++) |
| 2454 | { |
| 2455 | int fb_index = j * fb_width; |
| 1646 | 2456 | |
| 1647 | | t += rect->dtdy; |
| 1648 | | } |
| 1649 | | } |
| 1650 | | else if (other_modes.cycle_type == CYCLE_TYPE_COPY) |
| 1651 | | { |
| 1652 | | for (j = y1; j < y2; j++) |
| 1653 | | { |
| 1654 | | int fb_index = j * fb_width; |
| 2457 | s = (int)(rect->s) << 5; |
| 1655 | 2458 | |
| 1656 | | s = (int)(rect->s) << 5; |
| 2459 | // MooglyGuy note: This is probably completely wrong, fix it |
| 1657 | 2460 | |
| 1658 | | for (i = x1; i < x2; i++) |
| 1659 | | { |
| 1660 | | /* |
| 2461 | for (i = x1; i < x2; i++) |
| 2462 | { |
| 2463 | /* |
| 1661 | 2464 | if (clamp_s) |
| 1662 | 2465 | { |
| 1663 | 2466 | if (s < (tsl << 8)) s = (tsl << 8); |
| r6173 | r6174 | |
| 1675 | 2478 | if (mask_t) |
| 1676 | 2479 | { |
| 1677 | 2480 | t &= (((UINT32)(0xffffffff) >> (32-mask_t)) << 10) | 0x3ff; |
| 1678 | | } |
| 1679 | 2481 | |
| 2482 | |
| 1680 | 2483 | FETCH_TEXEL(&c, (s-tile[rect->tilenum].sl) >> 10, (t-tile[rect->tilenum].tl) >> 10, twidth, tformat, tsize, tbase); |
| 1681 | 2484 | */ |
| 1682 | | //ss = (s >> 10) - (tsl >> 2); |
| 1683 | | //if ((s & 0x3ff) >= 0x200) ss++; |
| 1684 | | //st = (t >> 10) - (ttl >> 2); |
| 1685 | | //if ((t & 0x3ff) >= 0x200) st++; |
| 2485 | //ss = (s >> 10) - (tsl >> 2); |
| 2486 | //if ((s & 0x3ff) >= 0x200) ss++; |
| 2487 | //st = (t >> 10) - (ttl >> 2); |
| 2488 | //if ((t & 0x3ff) >= 0x200) st++; |
| 1686 | 2489 | |
| 1687 | | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 2490 | TEXTURE_PIPELINE1(s, t, (rect->dsdx == (1 << 10)) && (rect->dtdy == (1 << 10))); |
| 1688 | 2491 | |
| 1689 | | //CLAMP(ss, st); |
| 1690 | | //FETCH_TEXEL(&c, ss, st, twidth, tformat, tsize, tbase); |
| 2492 | //CLAMP(ss, st); |
| 2493 | //FETCH_TEXEL(&c, ss, st, twidth, tformat, tsize, tbase); |
| 1691 | 2494 | |
| 1692 | | if (texel0_color.a != 0) |
| 1693 | | { |
| 1694 | | fb[(fb_index + i) ^ WORD_ADDR_XOR] = (texel0_color.r << 16) | (texel0_color.g << 8) | (texel0_color.b << 0); |
| 1695 | | } |
| 2495 | if (texel0_color.a != 0) |
| 2496 | { |
| 2497 | fb[(fb_index + i) ^ WORD_ADDR_XOR] = (texel0_color.r << 24) | (texel0_color.g << 16) | (texel0_color.b << 8) | 0xe0; |
| 2498 | } |
| 1696 | 2499 | |
| 1697 | | s += rect->dsdx; |
| 1698 | | } |
| 2500 | s += rect->dsdx; |
| 2501 | } |
| 1699 | 2502 | |
| 1700 | | t += rect->dtdy; |
| 1701 | | } |
| 1702 | | } |
| 1703 | | else |
| 1704 | | { |
| 1705 | | fatalerror("texture_rectangle_32bit: unknown cycle type %d\n", other_modes.cycle_type); |
| 1706 | | } |
| 2503 | t += rect->dtdy; |
| 2504 | } |
| 2505 | } |
| 2506 | else |
| 2507 | { |
| 2508 | fatalerror("texture_rectangle_32bit: unknown cycle type %d\n", other_modes.cycle_type); |
| 2509 | } |
| 1707 | 2510 | } |
| 1708 | 2511 | |
| 1709 | 2512 | |
| 1710 | 2513 | static void render_spans_32(int start, int end, int tilenum, int shade, int texture, int zbuffer, int flip) |
| 1711 | 2514 | { |
| 1712 | | UINT32 *fb = (UINT32*)&rdram[fb_address / 4]; |
| 1713 | | UINT16 *zb = (UINT16*)&rdram[zb_address / 4]; |
| 1714 | | int i, j; |
| 1715 | | int tsl, tsh, ttl, tth; |
| 1716 | | int twidth, tformat, tsize, tbase; |
| 1717 | | int clamp_s, clamp_t, mask_s, mask_t, mirror_s, mirror_t; |
| 2515 | UINT32 *fb = (UINT32*)&rdram[fb_address / 4]; |
| 2516 | UINT16 *zb = (UINT16*)&rdram[zb_address / 4]; |
| 2517 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 2518 | int i, j; |
| 2519 | int tsl[2], tsh[2], ttl[2], tth[2]; |
| 2520 | int twidth[2], tformat[2], tsize[2], tbase[2], tpal[2]; |
| 2521 | int clamp_s[2], clamp_t[2], mask_s[2], mask_t[2], mirror_s[2], mirror_t[2]; |
| 2522 | int cycle; |
| 2523 | int alpha_reject = 0; |
| 1718 | 2524 | |
| 1719 | | int clipx1, clipx2, clipy1, clipy2; |
| 2525 | int clipx1, clipx2, clipy1, clipy2; |
| 1720 | 2526 | |
| 1721 | | clipx1 = clip.xh / 4; |
| 1722 | | clipx2 = clip.xl / 4; |
| 1723 | | clipy1 = clip.yh / 4; |
| 1724 | | clipy2 = clip.yl / 4; |
| 2527 | clipx1 = clip.xh / 4; |
| 2528 | clipx2 = clip.xl / 4; |
| 2529 | clipy1 = clip.yh / 4; |
| 2530 | clipy2 = clip.yl / 4; |
| 1725 | 2531 | |
| 1726 | | tsl = tile[tilenum].sl; |
| 1727 | | tsh = tile[tilenum].sh; |
| 1728 | | ttl = tile[tilenum].tl; |
| 1729 | | tth = tile[tilenum].th; |
| 2532 | for( cycle = 0; cycle < 2; cycle++ ) |
| 2533 | { |
| 2534 | tsl[cycle] = tile[tilenum + cycle].sl; |
| 2535 | tsh[cycle] = tile[tilenum + cycle].sh; |
| 2536 | ttl[cycle] = tile[tilenum + cycle].tl; |
| 2537 | tth[cycle] = tile[tilenum + cycle].th; |
| 1730 | 2538 | |
| 1731 | | twidth = tile[tilenum].line; |
| 1732 | | tformat = tile[tilenum].format; |
| 1733 | | tsize = tile[tilenum].size; |
| 1734 | | tbase = tile[tilenum].tmem; |
| 2539 | twidth[cycle] = tile[tilenum + cycle].line; |
| 2540 | tformat[cycle] = tile[tilenum + cycle].format; |
| 2541 | tsize[cycle] = tile[tilenum + cycle].size; |
| 2542 | tbase[cycle] = tile[tilenum + cycle].tmem; |
| 2543 | tpal[cycle] = tile[tilenum + cycle].palette; |
| 1735 | 2544 | |
| 1736 | | clamp_t = tile[tilenum].ct; |
| 1737 | | clamp_s = tile[tilenum].cs; |
| 1738 | | mirror_t = tile[tilenum].mt; |
| 1739 | | mirror_s = tile[tilenum].ms; |
| 1740 | | mask_t = tile[tilenum].mask_t; |
| 1741 | | mask_s = tile[tilenum].mask_s; |
| 2545 | clamp_t[cycle] = tile[tilenum + cycle].ct; |
| 2546 | clamp_s[cycle] = tile[tilenum + cycle].cs; |
| 2547 | mirror_t[cycle] = tile[tilenum + cycle].mt; |
| 2548 | mirror_s[cycle] = tile[tilenum + cycle].ms; |
| 2549 | mask_t[cycle] = tile[tilenum + cycle].mask_t; |
| 2550 | mask_s[cycle] = tile[tilenum + cycle].mask_s; |
| 2551 | } |
| 1742 | 2552 | |
| 1743 | | if (start < clipy1) |
| 1744 | | { |
| 1745 | | start = clipy1; |
| 1746 | | } |
| 1747 | | if (start >= clipy2) |
| 1748 | | { |
| 1749 | | start = clipy2-1; |
| 1750 | | } |
| 1751 | | if (end < clipy1) |
| 1752 | | { |
| 1753 | | end = clipy1; |
| 1754 | | } |
| 1755 | | if (end >= clipy2) |
| 1756 | | { |
| 1757 | | end = clipy2-1; |
| 1758 | | } |
| 2553 | if (start < clipy1) |
| 2554 | { |
| 2555 | start = clipy1; |
| 2556 | } |
| 2557 | if (start >= clipy2) |
| 2558 | { |
| 2559 | start = clipy2-1; |
| 2560 | } |
| 2561 | if (end < clipy1) |
| 2562 | { |
| 2563 | end = clipy1; |
| 2564 | } |
| 2565 | if (end >= clipy2) |
| 2566 | { |
| 2567 | end = clipy2-1; |
| 2568 | } |
| 1759 | 2569 | |
| 1760 | | for (i=start; i <= end; i++) |
| 1761 | | { |
| 1762 | | int xstart = span[i].lx; |
| 1763 | | int xend = span[i].rx; |
| 1764 | | int r = span[i].r; |
| 1765 | | int g = span[i].g; |
| 1766 | | int b = span[i].b; |
| 1767 | | int a = span[i].a; |
| 1768 | | int z = span[i].z; |
| 1769 | | int s = span[i].s; |
| 1770 | | int t = span[i].t; |
| 1771 | | int w = span[i].w; |
| 1772 | | int dr = span[i].dr; |
| 1773 | | int dg = span[i].dg; |
| 1774 | | int db = span[i].db; |
| 1775 | | int da = span[i].da; |
| 1776 | | int dz = span[i].dz; |
| 1777 | | int ds = span[i].ds; |
| 1778 | | int dt = span[i].dt; |
| 1779 | | int dw = span[i].dw; |
| 1780 | | int drinc, dginc, dbinc, dainc, dzinc, dsinc, dtinc, dwinc; |
| 2570 | for (i=start; i <= end; i++) |
| 2571 | { |
| 2572 | int xstart = span[i].lx; |
| 2573 | int xend = span[i].rx; |
| 2574 | int r = span[i].r; |
| 2575 | int g = span[i].g; |
| 2576 | int b = span[i].b; |
| 2577 | int a = span[i].a; |
| 2578 | int z = span[i].z; |
| 2579 | int s = span[i].s; |
| 2580 | int t = span[i].t; |
| 2581 | int w = span[i].w; |
| 2582 | int dr = span[i].dr; |
| 2583 | int dg = span[i].dg; |
| 2584 | int db = span[i].db; |
| 2585 | int da = span[i].da; |
| 2586 | int dz = span[i].dz; |
| 2587 | int ds = span[i].ds; |
| 2588 | int dt = span[i].dt; |
| 2589 | int dw = span[i].dw; |
| 2590 | int drinc, dginc, dbinc, dainc, dzinc, dsinc, dtinc, dwinc; |
| 1781 | 2591 | |
| 1782 | | int x; |
| 1783 | | int xinc; |
| 2592 | int x; |
| 2593 | int xinc; |
| 1784 | 2594 | |
| 1785 | | int fb_index = fb_width * i; |
| 1786 | | int length; |
| 2595 | int fb_index = fb_width * i; |
| 2596 | int length; |
| 1787 | 2597 | |
| 1788 | | drinc = flip ? (dr) : -dr; |
| 1789 | | dginc = flip ? (dg) : -dg; |
| 1790 | | dbinc = flip ? (db) : -db; |
| 1791 | | dainc = flip ? (da) : -da; |
| 1792 | | dzinc = flip ? (dz) : -dz; |
| 1793 | | dsinc = flip ? (ds) : -ds; |
| 1794 | | dtinc = flip ? (dt) : -dt; |
| 1795 | | dwinc = flip ? (dw) : -dw; |
| 2598 | drinc = flip ? (dr) : -dr; |
| 2599 | dginc = flip ? (dg) : -dg; |
| 2600 | dbinc = flip ? (db) : -db; |
| 2601 | dainc = flip ? (da) : -da; |
| 2602 | dzinc = flip ? (dz) : -dz; |
| 2603 | dsinc = flip ? (ds) : -ds; |
| 2604 | dtinc = flip ? (dt) : -dt; |
| 2605 | dwinc = flip ? (dw) : -dw; |
| 1796 | 2606 | |
| 1797 | | xinc = flip ? 1 : -1; |
| 1798 | | x = xend; |
| 2607 | xinc = flip ? 1 : -1; |
| 2608 | x = xend; |
| 1799 | 2609 | |
| 1800 | | length = flip ? (xstart - xend) : (xend - xstart); |
| 2610 | length = flip ? (xstart - xend) : (xend - xstart); |
| 1801 | 2611 | |
| 1802 | | for (j=0; j <= length; j++) |
| 1803 | | { |
| 1804 | | int sr = r >> 16; |
| 1805 | | int sg = g >> 16; |
| 1806 | | int sb = b >> 16; |
| 1807 | | int sa = a >> 16; |
| 1808 | | int ss = s >> 16; |
| 1809 | | int st = t >> 16; |
| 1810 | | int sw = w >> 16; |
| 1811 | | UINT16 sz = z >> 16; |
| 1812 | | int oz; |
| 1813 | | int sss = 0, sst = 0; |
| 2612 | for (j=0; j <= length; j++) |
| 2613 | { |
| 2614 | int sr = r >> 16; |
| 2615 | int sg = g >> 16; |
| 2616 | int sb = b >> 16; |
| 2617 | int sa = a >> 16; |
| 2618 | int ss = s >> 16; |
| 2619 | int st = t >> 16; |
| 2620 | int sw = w >> 16; |
| 2621 | UINT16 sz = (other_modes.z_source_sel) ? primitive_z : (z >> 16); |
| 2622 | int oz; |
| 2623 | int sss = 0, sst = 0; |
| 1814 | 2624 | |
| 1815 | | if (x >= clipx1 && x < clipx2) |
| 1816 | | { |
| 1817 | | //int alpha_out = 0; |
| 1818 | | COLOR c1, c2; |
| 1819 | | c1.r = c1.g = c1.b = c1.a = 0; |
| 1820 | | c2.r = c2.g = c2.b = c2.a = 0; |
| 2625 | if (x >= clipx1 && x < clipx2) |
| 2626 | { |
| 2627 | COLOR c1, c2; |
| 2628 | c1.r = c1.g = c1.b = c1.a = 0; |
| 2629 | c2.r = c2.g = c2.b = c2.a = 0; |
| 1821 | 2630 | |
| 1822 | | if ((z & 0xffff) >= 0x8000) sz++; |
| 1823 | | if ((w & 0xffff) >= 0x8000) sw++; |
| 2631 | if ((z & 0xffff) >= 0x8000) sz++; |
| 2632 | if ((w & 0xffff) >= 0x8000) sw++; |
| 1824 | 2633 | |
| 1825 | | if (other_modes.persp_tex_en) |
| 1826 | | { |
| 1827 | | if (sw != 0) |
| 1828 | | { |
| 1829 | | sss = (((INT64)(ss) << 20) / sw); |
| 1830 | | sst = (((INT64)(st) << 20) / sw); |
| 1831 | | } |
| 1832 | | } |
| 1833 | | else |
| 1834 | | { |
| 1835 | | sss = ss; |
| 1836 | | sst = st; |
| 1837 | | } |
| 1838 | | |
| 1839 | | if (sr > 0xff) sr = 0xff; if (sg > 0xff) sg = 0xff; if (sb > 0xff) sb = 0xff; |
| 1840 | | |
| 1841 | | shade_color.r = sr; shade_color.g = sg; shade_color.b = sb; shade_color.a = sa; |
| 1842 | | |
| 1843 | | if (texture) |
| 1844 | | { |
| 1845 | | /*if (other_modes.sample_type) |
| 2634 | if (other_modes.persp_tex_en) |
| 2635 | { |
| 2636 | if (sw != 0) |
| 1846 | 2637 | { |
| 1847 | | // bilinear |
| 1848 | | |
| 1849 | | sss1 = (sss >> 10) - (tsl >> 2); |
| 1850 | | sss2 = sss1 + 1; |
| 1851 | | |
| 1852 | | sst1 = (sst >> 10) - (ttl >> 2); |
| 1853 | | sst2 = sst1 + 1; |
| 1854 | | |
| 1855 | | CLAMP(sss1, sst1); |
| 1856 | | CLAMP(sss2, sst2); |
| 1857 | | |
| 1858 | | FETCH_TEXEL(&t0, sss1, sst1, twidth, tformat, tsize, tbase); |
| 1859 | | FETCH_TEXEL(&t1, sss2, sst1, twidth, tformat, tsize, tbase); |
| 1860 | | FETCH_TEXEL(&t2, sss1, sst2, twidth, tformat, tsize, tbase); |
| 1861 | | FETCH_TEXEL(&t3, sss2, sst2, twidth, tformat, tsize, tbase); |
| 1862 | | |
| 1863 | | texel0_color.r = (((( (t0.r * (0x3ff - (sss & 0x3ff))) + (t1.r * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 1864 | | (((( (t2.r * (0x3ff - (sss & 0x3ff))) + (t3.r * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 1865 | | |
| 1866 | | texel0_color.g = (((( (t0.g * (0x3ff - (sss & 0x3ff))) + (t1.g * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 1867 | | (((( (t2.g * (0x3ff - (sss & 0x3ff))) + (t3.g * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 1868 | | |
| 1869 | | texel0_color.b = (((( (t0.b * (0x3ff - (sss & 0x3ff))) + (t1.b * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 1870 | | (((( (t2.b * (0x3ff - (sss & 0x3ff))) + (t3.b * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 1871 | | |
| 1872 | | texel0_color.a = (((( (t0.a * (0x3ff - (sss & 0x3ff))) + (t1.a * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 1873 | | (((( (t2.a * (0x3ff - (sss & 0x3ff))) + (t3.a * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 2638 | sss = (((INT64)(ss) << 20) / sw); |
| 2639 | sst = (((INT64)(st) << 20) / sw); |
| 1874 | 2640 | } |
| 1875 | | else |
| 1876 | | { |
| 1877 | | sss1 = (sss >> 10) - (tsl >> 2); |
| 1878 | | if ((sss & 0x3ff) >= 0x200) sss1++; |
| 2641 | } |
| 2642 | else |
| 2643 | { |
| 2644 | sss = ss; |
| 2645 | sst = st; |
| 2646 | } |
| 1879 | 2647 | |
| 1880 | | sst1 = (sst >> 10) - (ttl >> 2); |
| 1881 | | if ((sst & 0x3ff) >= 0x200) sst1++; |
| 2648 | if (sr > 0xff) sr = 0xff; if (sg > 0xff) sg = 0xff; if (sb > 0xff) sb = 0xff; |
| 1882 | 2649 | |
| 1883 | | CLAMP(sss1, sst1); |
| 2650 | shade_color.r = sr; shade_color.g = sg; shade_color.b = sb; shade_color.a = sa; |
| 1884 | 2651 | |
| 1885 | | // point sample |
| 1886 | | FETCH_TEXEL(&texel0_color, sss1, sst1, twidth, tformat, tsize, tbase); |
| 1887 | | }*/ |
| 1888 | | |
| 1889 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1890 | | { |
| 1891 | | TEXTURE_PIPELINE1(sss, sst, 0); |
| 1892 | | } |
| 1893 | | else |
| 1894 | | { |
| 1895 | | TEXTURE_PIPELINE2(sss, sst, 0); |
| 1896 | | } |
| 1897 | | } |
| 1898 | | |
| 1899 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1900 | | { |
| 1901 | | c1 = COLOR_COMBINER(0); |
| 1902 | | if( c1.a == 0 ) |
| 2652 | if (texture) |
| 2653 | { |
| 2654 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1903 | 2655 | { |
| 1904 | | //alpha_out = 1; |
| 2656 | TEXTURE_PIPELINE1(sss, sst, other_modes.sample_type == 0); |
| 1905 | 2657 | } |
| 1906 | | } |
| 1907 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 1908 | | { |
| 1909 | | c1 = COLOR_COMBINER(0); |
| 1910 | | c2 = COLOR_COMBINER(1); |
| 1911 | | if( c2.a == 0 ) |
| 2658 | else |
| 1912 | 2659 | { |
| 1913 | | //alpha_out = 1; |
| 2660 | TEXTURE_PIPELINE2(sss, sst, other_modes.sample_type == 0); |
| 1914 | 2661 | } |
| 1915 | | } |
| 2662 | } |
| 1916 | 2663 | |
| 1917 | | /* SGINUT 1/6/08: This fixes things in some games and breaks things in others. |
| 1918 | | I believe the pixels should be discarded based on the alpha |
| 1919 | | value stored in memory, but alpha and coverage are stored in |
| 1920 | | anciliary bits in the framebuffer which are not currently |
| 1921 | | emulated by MESS. */ |
| 1922 | | if( /*!alpha_out*/ 1 ) |
| 2664 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 1923 | 2665 | { |
| 1924 | | oz = (UINT16)zb[(fb_index + x) ^ WORD_ADDR_XOR]; |
| 1925 | | if (zbuffer) |
| 2666 | c1 = COLOR_COMBINER(0); |
| 2667 | } |
| 2668 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 2669 | { |
| 2670 | c1 = COLOR_COMBINER(0); |
| 2671 | c2 = COLOR_COMBINER(1); |
| 2672 | } |
| 2673 | |
| 2674 | if( alpha_compare_success(c1, c2) ) |
| 2675 | { |
| 2676 | oz = (other_modes.z_source_sel) ? primitive_z : (UINT16)zb[(fb_index + x) ^ WORD_ADDR_XOR]; |
| 2677 | if (other_modes.z_compare_en && zbuffer) |
| 1926 | 2678 | { |
| 1927 | | if (sz < oz /*&& c.a != 0*/) |
| 2679 | if (sz < oz) |
| 1928 | 2680 | { |
| 1929 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2681 | int cvg_ovf = 0; |
| 2682 | UINT8 cvg_old = 0; |
| 2683 | calculate_coverage( &cvg_buf[(fb_index + x) ^ WORD_ADDR_XOR], span[i].cvg[x], &cvg_ovf, &cvg_old ); |
| 2684 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 1930 | 2685 | { |
| 1931 | | BLENDER1_32(&fb[(fb_index + x)], c1); |
| 1932 | | } |
| 1933 | | else |
| 1934 | | { |
| 1935 | | BLENDER2_32(&fb[(fb_index + x)], c1, c2); |
| 1936 | | } |
| 2686 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2687 | { |
| 2688 | BLENDER1_32(&fb[(fb_index + x)], c1, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2689 | } |
| 2690 | else |
| 2691 | { |
| 2692 | BLENDER2_32(&fb[(fb_index + x)], c1, c2, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2693 | } |
| 1937 | 2694 | |
| 1938 | | if (other_modes.z_compare_en && other_modes.z_update_en) |
| 1939 | | { |
| 1940 | | zb[(fb_index + x) ^ WORD_ADDR_XOR] = sz; |
| 2695 | if (other_modes.z_update_en && !alpha_reject) |
| 2696 | { |
| 2697 | zb[(fb_index + x) ^ WORD_ADDR_XOR] = sz; |
| 2698 | } |
| 1941 | 2699 | } |
| 1942 | 2700 | } |
| 1943 | 2701 | } |
| 1944 | 2702 | else |
| 1945 | 2703 | { |
| 1946 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2704 | int cvg_ovf = 0; |
| 2705 | UINT8 cvg_old = 0; |
| 2706 | calculate_coverage( &cvg_buf[(fb_index + x) ^ WORD_ADDR_XOR], span[i].cvg[x], &cvg_ovf, &cvg_old ); |
| 2707 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 1947 | 2708 | { |
| 1948 | | BLENDER1_32(&fb[(fb_index + x)], c1); |
| 2709 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2710 | { |
| 2711 | BLENDER1_32(&fb[(fb_index + x)], c1, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2712 | } |
| 2713 | else |
| 2714 | { |
| 2715 | BLENDER2_32(&fb[(fb_index + x)], c1, c2, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2716 | } |
| 1949 | 2717 | } |
| 1950 | | else |
| 1951 | | { |
| 1952 | | BLENDER2_32(&fb[(fb_index + x)], c1, c2); |
| 1953 | | } |
| 1954 | 2718 | } |
| 1955 | 2719 | } |
| 1956 | | } |
| 2720 | } |
| 1957 | 2721 | |
| 1958 | | r += drinc; |
| 1959 | | g += dginc; |
| 1960 | | b += dbinc; |
| 1961 | | a += dainc; |
| 1962 | | z += dzinc; |
| 1963 | | s += dsinc; |
| 1964 | | t += dtinc; |
| 1965 | | w += dwinc; |
| 2722 | r += drinc; |
| 2723 | g += dginc; |
| 2724 | b += dbinc; |
| 2725 | a += dainc; |
| 2726 | z += dzinc; |
| 2727 | s += dsinc; |
| 2728 | t += dtinc; |
| 2729 | w += dwinc; |
| 1966 | 2730 | |
| 1967 | | x += xinc; |
| 1968 | | } |
| 1969 | | } |
| 2731 | x += xinc; |
| 2732 | } |
| 2733 | } |
| 1970 | 2734 | } |
| 1971 | 2735 | |
| 1972 | 2736 | /*****************************************************************************/ |
| 1973 | 2737 | |
| 1974 | | |
| 1975 | | |
| 1976 | 2738 | static void render_spans_16(int start, int end, int tilenum, int shade, int texture, int zbuffer, int flip) |
| 1977 | 2739 | { |
| 1978 | | UINT16 *fb = (UINT16*)&rdram[fb_address / 4]; |
| 1979 | | UINT16 *zb = (UINT16*)&rdram[zb_address / 4]; |
| 1980 | | int i, j; |
| 1981 | | int tsl, tsh, ttl, tth; |
| 1982 | | int twidth, tformat, tsize, tbase; |
| 1983 | | int clamp_s, clamp_t, mask_s, mask_t, mirror_s, mirror_t; |
| 2740 | UINT16 *fb = (UINT16*)&rdram[fb_address / 4]; |
| 2741 | UINT16 *zb = (UINT16*)&rdram[zb_address / 4]; |
| 2742 | UINT8* cvg_buf = (UINT8*)&cvg_mem[fb_address]; |
| 2743 | UINT8* zd_buf = (UINT8*)&cvg_mem[zb_address]; |
| 2744 | int i, j; |
| 2745 | int tsl[2], tsh[2], ttl[2], tth[2]; |
| 2746 | int twidth[2], tformat[2], tsize[2], tbase[2], tpal[2]; |
| 2747 | int clamp_s[2], clamp_t[2], mask_s[2], mask_t[2], mirror_s[2], mirror_t[2]; |
| 2748 | int cycle; |
| 2749 | int alpha_reject = 0; |
| 1984 | 2750 | |
| 1985 | | int clipx1, clipx2, clipy1, clipy2; |
| 2751 | int clipx1, clipx2, clipy1, clipy2; |
| 1986 | 2752 | |
| 1987 | | clipx1 = clip.xh / 4; |
| 1988 | | clipx2 = clip.xl / 4; |
| 1989 | | clipy1 = clip.yh / 4; |
| 1990 | | clipy2 = clip.yl / 4; |
| 2753 | clipx1 = clip.xh / 4; |
| 2754 | clipx2 = clip.xl / 4; |
| 2755 | clipy1 = clip.yh / 4; |
| 2756 | clipy2 = clip.yl / 4; |
| 1991 | 2757 | |
| 1992 | | tsl = tile[tilenum].sl; |
| 1993 | | tsh = tile[tilenum].sh; |
| 1994 | | ttl = tile[tilenum].tl; |
| 1995 | | tth = tile[tilenum].th; |
| 2758 | for( cycle = 0; cycle < 2; cycle++ ) |
| 2759 | { |
| 2760 | tsl[cycle] = tile[tilenum + cycle].sl; |
| 2761 | tsh[cycle] = tile[tilenum + cycle].sh; |
| 2762 | ttl[cycle] = tile[tilenum + cycle].tl; |
| 2763 | tth[cycle] = tile[tilenum + cycle].th; |
| 1996 | 2764 | |
| 1997 | | twidth = tile[tilenum].line; |
| 1998 | | tformat = tile[tilenum].format; |
| 1999 | | tsize = tile[tilenum].size; |
| 2000 | | tbase = tile[tilenum].tmem; |
| 2765 | twidth[cycle] = tile[tilenum + cycle].line; |
| 2766 | tformat[cycle] = tile[tilenum + cycle].format; |
| 2767 | tsize[cycle] = tile[tilenum + cycle].size; |
| 2768 | tbase[cycle] = tile[tilenum + cycle].tmem; |
| 2769 | tpal[cycle] = tile[tilenum + cycle].palette; |
| 2001 | 2770 | |
| 2002 | | clamp_t = tile[tilenum].ct; |
| 2003 | | clamp_s = tile[tilenum].cs; |
| 2004 | | mirror_t = tile[tilenum].mt; |
| 2005 | | mirror_s = tile[tilenum].ms; |
| 2006 | | mask_t = tile[tilenum].mask_t; |
| 2007 | | mask_s = tile[tilenum].mask_s; |
| 2771 | clamp_t[cycle] = tile[tilenum + cycle].ct; |
| 2772 | clamp_s[cycle] = tile[tilenum + cycle].cs; |
| 2773 | mirror_t[cycle] = tile[tilenum + cycle].mt; |
| 2774 | mirror_s[cycle] = tile[tilenum + cycle].ms; |
| 2775 | mask_t[cycle] = tile[tilenum + cycle].mask_t; |
| 2776 | mask_s[cycle] = tile[tilenum + cycle].mask_s; |
| 2777 | } |
| 2008 | 2778 | |
| 2009 | | if (start < clipy1) |
| 2010 | | { |
| 2011 | | start = clipy1; |
| 2012 | | } |
| 2013 | | if (start >= clipy2) |
| 2014 | | { |
| 2015 | | start = clipy2-1; |
| 2016 | | } |
| 2017 | | if (end < clipy1) |
| 2018 | | { |
| 2019 | | end = clipy1; |
| 2020 | | } |
| 2021 | | if (end >= clipy2) |
| 2022 | | { |
| 2023 | | end = clipy2-1; |
| 2024 | | } |
| 2779 | if (start < clipy1) |
| 2780 | { |
| 2781 | start = clipy1; |
| 2782 | } |
| 2783 | if (start >= clipy2) |
| 2784 | { |
| 2785 | start = clipy2-1; |
| 2786 | } |
| 2787 | if (end < clipy1) |
| 2788 | { |
| 2789 | end = clipy1; |
| 2790 | } |
| 2791 | if (end >= clipy2) |
| 2792 | { |
| 2793 | end = clipy2-1; |
| 2794 | } |
| 2025 | 2795 | |
| 2026 | | for (i=start; i <= end; i++) |
| 2027 | | { |
| 2028 | | int xstart = span[i].lx; |
| 2029 | | int xend = span[i].rx; |
| 2030 | | int r = span[i].r; |
| 2031 | | int g = span[i].g; |
| 2032 | | int b = span[i].b; |
| 2033 | | int a = span[i].a; |
| 2034 | | int z = span[i].z; |
| 2035 | | int s = span[i].s; |
| 2036 | | int t = span[i].t; |
| 2037 | | int w = span[i].w; |
| 2038 | | int dr = span[i].dr; |
| 2039 | | int dg = span[i].dg; |
| 2040 | | int db = span[i].db; |
| 2041 | | int da = span[i].da; |
| 2042 | | int dz = span[i].dz; |
| 2043 | | int ds = span[i].ds; |
| 2044 | | int dt = span[i].dt; |
| 2045 | | int dw = span[i].dw; |
| 2046 | | int drinc, dginc, dbinc, dainc, dzinc, dsinc, dtinc, dwinc; |
| 2796 | for (i=start; i <= end; i++) |
| 2797 | { |
| 2798 | int xstart = span[i].lx; |
| 2799 | int xend = span[i].rx; |
| 2800 | int r = span[i].r; |
| 2801 | int g = span[i].g; |
| 2802 | int b = span[i].b; |
| 2803 | int a = span[i].a; |
| 2804 | int z = span[i].z; |
| 2805 | int s = span[i].s; |
| 2806 | int t = span[i].t; |
| 2807 | int w = span[i].w; |
| 2808 | int dr = span[i].dr; |
| 2809 | int dg = span[i].dg; |
| 2810 | int db = span[i].db; |
| 2811 | int da = span[i].da; |
| 2812 | int dz = span[i].dz; |
| 2813 | int ds = span[i].ds; |
| 2814 | int dt = span[i].dt; |
| 2815 | int dw = span[i].dw; |
| 2816 | int drinc, dginc, dbinc, dainc, dzinc, dsinc, dtinc, dwinc; |
| 2047 | 2817 | |
| 2048 | | int x; |
| 2049 | | int xinc; |
| 2818 | int x; |
| 2819 | int xinc; |
| 2050 | 2820 | |
| 2051 | | int fb_index = fb_width * i; |
| 2052 | | int length; |
| 2821 | int fb_index = fb_width * i; |
| 2822 | int length; |
| 2053 | 2823 | |
| 2054 | | drinc = flip ? (dr) : -dr; |
| 2055 | | dginc = flip ? (dg) : -dg; |
| 2056 | | dbinc = flip ? (db) : -db; |
| 2057 | | dainc = flip ? (da) : -da; |
| 2058 | | dzinc = flip ? (dz) : -dz; |
| 2059 | | dsinc = flip ? (ds) : -ds; |
| 2060 | | dtinc = flip ? (dt) : -dt; |
| 2061 | | dwinc = flip ? (dw) : -dw; |
| 2824 | drinc = flip ? (dr) : -dr; |
| 2825 | dginc = flip ? (dg) : -dg; |
| 2826 | dbinc = flip ? (db) : -db; |
| 2827 | dainc = flip ? (da) : -da; |
| 2828 | dzinc = flip ? (dz) : -dz; |
| 2829 | dsinc = flip ? (ds) : -ds; |
| 2830 | dtinc = flip ? (dt) : -dt; |
| 2831 | dwinc = flip ? (dw) : -dw; |
| 2062 | 2832 | |
| 2063 | | /*if (flip) |
| 2833 | xinc = flip ? 1 : -1; |
| 2834 | x = xend; |
| 2835 | |
| 2836 | length = flip ? (xstart - xend) : (xend - xstart); |
| 2837 | |
| 2838 | for (j=0; j <= length; j++) |
| 2064 | 2839 | { |
| 2065 | | if (xend > clipx2) |
| 2840 | int sr = r >> 16; |
| 2841 | int sg = g >> 16; |
| 2842 | int sb = b >> 16; |
| 2843 | int sa = a >> 16; |
| 2844 | int ss = s >> 16; |
| 2845 | int st = t >> 16; |
| 2846 | int sw = w >> 16; |
| 2847 | //UINT16 sz; |
| 2848 | int sz = (other_modes.z_source_sel) ? (int)((primitive_z << 16) | primitive_delta_z) : (int)z; |
| 2849 | UINT32 oz = 0; |
| 2850 | int sss = 0, sst = 0; |
| 2851 | COLOR c1, c2; |
| 2852 | //UINT8 old_delta_z; |
| 2853 | c1.r = c1.g = c1.b = c1.a = 0; |
| 2854 | c2.r = c2.g = c2.b = c2.a = 0; |
| 2855 | |
| 2856 | /* |
| 2857 | if (other_modes.z_source_sel) |
| 2066 | 2858 | { |
| 2067 | | int d = xend-clipx2; |
| 2068 | | r += d * drinc; |
| 2069 | | g += d * dginc; |
| 2070 | | b += d * dbinc; |
| 2071 | | a += d * dainc; |
| 2072 | | z += d * dzinc; |
| 2073 | | s += d * dsinc; |
| 2074 | | t += d * dtinc; |
| 2075 | | w += d * dwinc; |
| 2076 | | |
| 2077 | | xend = clipx2; |
| 2859 | compress_z((primitive_z << 16) | primitive_delta_z, &sz, &old_delta_z); |
| 2078 | 2860 | } |
| 2079 | | if (xstart < clipx1) |
| 2861 | else |
| 2080 | 2862 | { |
| 2081 | | xstart = clipx1; |
| 2863 | compress_z(z, &sz, &old_delta_z); |
| 2082 | 2864 | } |
| 2083 | | } |
| 2084 | | else |
| 2085 | | { |
| 2086 | | if (xstart > clipx2) |
| 2087 | | { |
| 2088 | | int d = xstart-clipx2; |
| 2089 | | r += d * drinc; |
| 2090 | | g += d * dginc; |
| 2091 | | b += d * dbinc; |
| 2092 | | a += d * dainc; |
| 2093 | | z += d * dzinc; |
| 2094 | | s += d * dsinc; |
| 2095 | | t += d * dtinc; |
| 2096 | | w += d * dwinc; |
| 2865 | */ |
| 2097 | 2866 | |
| 2098 | | xstart = clipx2; |
| 2099 | | } |
| 2100 | | if (xend < clipx1) |
| 2867 | if (x >= clipx1 && x < clipx2) |
| 2101 | 2868 | { |
| 2102 | | xend = clipx1; |
| 2103 | | } |
| 2104 | | }*/ |
| 2869 | //if ((z & 0xffff) >= 0x8000) sz++; |
| 2870 | if ((w & 0xffff) >= 0x8000) sw++; |
| 2105 | 2871 | |
| 2106 | | xinc = flip ? 1 : -1; |
| 2107 | | x = xend; |
| 2108 | | |
| 2109 | | length = flip ? (xstart - xend) : (xend - xstart); |
| 2110 | | |
| 2111 | | for (j=0; j <= length; j++) |
| 2112 | | { |
| 2113 | | int sr = r >> 16; |
| 2114 | | int sg = g >> 16; |
| 2115 | | int sb = b >> 16; |
| 2116 | | int sa = a >> 16; |
| 2117 | | int ss = s >> 16; |
| 2118 | | int st = t >> 16; |
| 2119 | | int sw = w >> 16; |
| 2120 | | UINT16 sz = z >> 16; |
| 2121 | | int oz; |
| 2122 | | int sss = 0, sst = 0; |
| 2123 | | //int alpha_out = 0; |
| 2124 | | COLOR c1, c2; |
| 2125 | | c1.r = c1.g = c1.b = c1.a = 0; |
| 2126 | | c2.r = c2.g = c2.b = c2.a = 0; |
| 2127 | | |
| 2128 | | if (x >= clipx1 && x < clipx2) |
| 2129 | | { |
| 2130 | | if ((z & 0xffff) >= 0x8000) sz++; |
| 2131 | | if ((w & 0xffff) >= 0x8000) sw++; |
| 2132 | | |
| 2133 | | if (other_modes.persp_tex_en) |
| 2134 | | { |
| 2135 | | if (sw != 0) |
| 2136 | | { |
| 2137 | | sss = (((INT64)(ss) << 20) / sw); |
| 2138 | | sst = (((INT64)(st) << 20) / sw); |
| 2139 | | } |
| 2140 | | } |
| 2141 | | else |
| 2142 | | { |
| 2143 | | sss = ss; |
| 2144 | | sst = st; |
| 2145 | | } |
| 2146 | | |
| 2147 | | if (sr > 0xff) sr = 0xff; if (sg > 0xff) sg = 0xff; if (sb > 0xff) sb = 0xff; |
| 2148 | | |
| 2149 | | shade_color.r = sr; shade_color.g = sg; shade_color.b = sb; shade_color.a = sa; |
| 2150 | | |
| 2151 | | if (texture) |
| 2152 | | { |
| 2153 | | /*if (other_modes.sample_type) |
| 2872 | if (other_modes.persp_tex_en) |
| 2873 | { |
| 2874 | if (sw != 0) |
| 2154 | 2875 | { |
| 2155 | | // bilinear |
| 2156 | | |
| 2157 | | sss1 = (sss >> 10) - (tsl >> 2); |
| 2158 | | sss2 = sss1 + 1; |
| 2159 | | |
| 2160 | | sst1 = (sst >> 10) - (ttl >> 2); |
| 2161 | | sst2 = sst1 + 1; |
| 2162 | | |
| 2163 | | CLAMP(sss1, sst1); |
| 2164 | | CLAMP(sss2, sst2); |
| 2165 | | |
| 2166 | | FETCH_TEXEL(&t0, sss1, sst1, twidth, tformat, tsize, tbase); |
| 2167 | | FETCH_TEXEL(&t1, sss2, sst1, twidth, tformat, tsize, tbase); |
| 2168 | | FETCH_TEXEL(&t2, sss1, sst2, twidth, tformat, tsize, tbase); |
| 2169 | | FETCH_TEXEL(&t3, sss2, sst2, twidth, tformat, tsize, tbase); |
| 2170 | | |
| 2171 | | texel0_color.r = (((( (t0.r * (0x3ff - (sss & 0x3ff))) + (t1.r * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 2172 | | (((( (t2.r * (0x3ff - (sss & 0x3ff))) + (t3.r * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 2173 | | |
| 2174 | | texel0_color.g = (((( (t0.g * (0x3ff - (sss & 0x3ff))) + (t1.g * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 2175 | | (((( (t2.g * (0x3ff - (sss & 0x3ff))) + (t3.g * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 2176 | | |
| 2177 | | texel0_color.b = (((( (t0.b * (0x3ff - (sss & 0x3ff))) + (t1.b * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 2178 | | (((( (t2.b * (0x3ff - (sss & 0x3ff))) + (t3.b * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 2179 | | |
| 2180 | | texel0_color.a = (((( (t0.a * (0x3ff - (sss & 0x3ff))) + (t1.a * ((sss & 0x3ff))) ) >> 10) * (0x3ff - (sst & 0x3ff))) >> 10) + |
| 2181 | | (((( (t2.a * (0x3ff - (sss & 0x3ff))) + (t3.a * ((sss & 0x3ff))) ) >> 10) * ((sst & 0x3ff))) >> 10); |
| 2876 | sss = (((INT64)(ss) << 20) / sw); |
| 2877 | sst = (((INT64)(st) << 20) / sw); |
| 2182 | 2878 | } |
| 2183 | | else |
| 2184 | | { |
| 2185 | | sss1 = (sss >> 10) - (tsl >> 2); |
| 2186 | | if ((sss & 0x3ff) >= 0x200) sss1++; |
| 2879 | } |
| 2880 | else |
| 2881 | { |
| 2882 | sss = ss; |
| 2883 | sst = st; |
| 2884 | } |
| 2187 | 2885 | |
| 2188 | | sst1 = (sst >> 10) - (ttl >> 2); |
| 2189 | | if ((sst & 0x3ff) >= 0x200) sst1++; |
| 2886 | if (sr > 0xff) sr = 0xff; if (sg > 0xff) sg = 0xff; if (sb > 0xff) sb = 0xff; |
| 2190 | 2887 | |
| 2191 | | CLAMP(sss1, sst1); |
| 2888 | shade_color.r = sr; shade_color.g = sg; shade_color.b = sb; shade_color.a = sa; |
| 2192 | 2889 | |
| 2193 | | // point sample |
| 2194 | | FETCH_TEXEL(&texel0_color, sss1, sst1, twidth, tformat, tsize, tbase); |
| 2195 | | }*/ |
| 2196 | | |
| 2197 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2198 | | { |
| 2199 | | TEXTURE_PIPELINE1(sss, sst, 0); |
| 2200 | | } |
| 2201 | | else |
| 2202 | | { |
| 2203 | | TEXTURE_PIPELINE2(sss, sst, 0); |
| 2204 | | } |
| 2205 | | } |
| 2206 | | |
| 2207 | | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2208 | | { |
| 2209 | | c1 = COLOR_COMBINER(0); |
| 2210 | | if( c1.a == 0 ) |
| 2890 | if (texture) |
| 2891 | { |
| 2892 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2211 | 2893 | { |
| 2212 | | //alpha_out = 1; |
| 2894 | TEXTURE_PIPELINE1(sss, sst, other_modes.sample_type == 0); |
| 2213 | 2895 | } |
| 2214 | | } |
| 2215 | | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 2216 | | { |
| 2217 | | c1 = COLOR_COMBINER(0); |
| 2218 | | c2 = COLOR_COMBINER(1); |
| 2219 | | if( c2.a == 0 ) |
| 2896 | else |
| 2220 | 2897 | { |
| 2221 | | //alpha_out = 1; |
| 2898 | TEXTURE_PIPELINE2(sss, sst, other_modes.sample_type == 0); |
| 2222 | 2899 | } |
| 2223 | | } |
| 2900 | } |
| 2224 | 2901 | |
| 2225 | | /* SGINUT 1/6/08: This fixes things in some games and breaks things in others. |
| 2226 | | I believe the pixels should be discarded based on the alpha |
| 2227 | | value stored in memory, but alpha and coverage are stored in |
| 2228 | | anciliary bits in the framebuffer which are not currently |
| 2229 | | emulated by MESS. */ |
| 2230 | | if( /*!alpha_out*/ 1 ) |
| 2902 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2231 | 2903 | { |
| 2232 | | oz = (UINT16)zb[(fb_index + x) ^ WORD_ADDR_XOR]; |
| 2233 | | if (zbuffer) |
| 2904 | c1 = COLOR_COMBINER(0); |
| 2905 | } |
| 2906 | else if (other_modes.cycle_type == CYCLE_TYPE_2) |
| 2907 | { |
| 2908 | c1 = COLOR_COMBINER(0); |
| 2909 | c2 = COLOR_COMBINER(1); |
| 2910 | } |
| 2911 | |
| 2912 | if( alpha_compare_success(c1, c2) ) |
| 2913 | { |
| 2914 | decompress_z(zb[(fb_index + x) ^ WORD_ADDR_XOR], &oz); |
| 2915 | //oz = (UINT16)zb[(fb_index + x) ^ WORD_ADDR_XOR]; |
| 2916 | |
| 2917 | if (other_modes.z_compare_en && zbuffer) |
| 2234 | 2918 | { |
| 2235 | | if (sz < oz /*&& c.a != 0*/) |
| 2919 | if (((sz >> 13) < oz) || ((other_modes.z_mode == 3) && ((sz >> 13) == oz))) |
| 2236 | 2920 | { |
| 2237 | | //BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c); |
| 2921 | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 2922 | int cvg_ovf = 0; |
| 2923 | UINT8 cvg_old = 0; |
| 2924 | calculate_coverage( &cvg_buf[(fb_index + x) ^ WORD_ADDR_XOR], span[i].cvg[x], &cvg_ovf, &cvg_old ); |
| 2925 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 2238 | 2926 | { |
| 2239 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 2240 | 2927 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2241 | 2928 | { |
| 2242 | | BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, dith); |
| 2929 | BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, dith, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2243 | 2930 | } |
| 2244 | 2931 | else |
| 2245 | 2932 | { |
| 2246 | | BLENDER2_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, c2, dith); |
| 2933 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 2934 | { |
| 2935 | BLENDER2_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, c2, dith, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2936 | } |
| 2247 | 2937 | } |
| 2248 | | } |
| 2249 | 2938 | |
| 2250 | | if (other_modes.z_compare_en && other_modes.z_update_en) |
| 2251 | | { |
| 2252 | | zb[(fb_index + x) ^ WORD_ADDR_XOR] = sz; |
| 2939 | if (other_modes.z_update_en && !alpha_reject) |
| 2940 | { |
| 2941 | //zb[(fb_index + x) ^ WORD_ADDR_XOR] = sz; |
| 2942 | compress_z(sz, &zb[(fb_index + x) ^ WORD_ADDR_XOR], &zd_buf[(fb_index + x) ^ WORD_ADDR_XOR] ); |
| 2943 | } |
| 2253 | 2944 | } |
| 2254 | 2945 | } |
| 2255 | 2946 | } |
| 2256 | 2947 | else |
| 2257 | 2948 | { |
| 2258 | | //BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c); |
| 2259 | | |
| 2949 | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 2950 | int cvg_ovf = 0; |
| 2951 | UINT8 cvg_old = 0; |
| 2952 | calculate_coverage( &cvg_buf[(fb_index + x) ^ WORD_ADDR_XOR], span[i].cvg[x], &cvg_ovf, &cvg_old ); |
| 2953 | if ((other_modes.color_on_cvg && cvg_ovf) || !other_modes.color_on_cvg) |
| 2260 | 2954 | { |
| 2261 | | int dith = dither_matrix_4x4[(((j) & 3) << 2) + ((i^WORD_ADDR_XOR) & 3)]; |
| 2262 | 2955 | if (other_modes.cycle_type == CYCLE_TYPE_1) |
| 2263 | 2956 | { |
| 2264 | | BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, dith); |
| 2957 | BLENDER1_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, dith, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2265 | 2958 | } |
| 2266 | 2959 | else |
| 2267 | 2960 | { |
| 2268 | | BLENDER2_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, c2, dith); |
| 2961 | BLENDER2_16(&fb[(fb_index + x) ^ WORD_ADDR_XOR], c1, c2, dith, &span[i].cvg[x], &cvg_old, &alpha_reject); |
| 2269 | 2962 | } |
| 2270 | 2963 | } |
| 2271 | 2964 | } |
| 2272 | 2965 | } |
| 2273 | | } |
| 2966 | } |
| 2274 | 2967 | |
| 2275 | | r += drinc; |
| 2276 | | g += dginc; |
| 2277 | | b += dbinc; |
| 2278 | | a += dainc; |
| 2279 | | z += dzinc; |
| 2280 | | s += dsinc; |
| 2281 | | t += dtinc; |
| 2282 | | w += dwinc; |
| 2968 | r += drinc; |
| 2969 | g += dginc; |
| 2970 | b += dbinc; |
| 2971 | a += dainc; |
| 2972 | z += dzinc; |
| 2973 | s += dsinc; |
| 2974 | t += dtinc; |
| 2975 | w += dwinc; |
| 2283 | 2976 | |
| 2284 | | x += xinc; |
| 2285 | | } |
| 2286 | | } |
| 2977 | x += xinc; |
| 2978 | } |
| 2979 | } |
| 2287 | 2980 | } |
| 2288 | 2981 | |
| 2289 | | static void triangle(UINT32 w1, UINT32 w2, int shade, int texture, int zbuffer) |
| 2982 | typedef struct |
| 2290 | 2983 | { |
| 2291 | | int j; |
| 2292 | | int xleft, xright, xleft_inc, xright_inc; |
| 2293 | | int xstart, xend; |
| 2294 | | int r, g, b, a, z, s, t, w; |
| 2295 | | //int dr, dg, db, da; |
| 2296 | | int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0, dzdx = 0, dsdx = 0, dtdx = 0, dwdx = 0; |
| 2297 | | //int drdy = 0, dgdy = 0, dbdy = 0, dady = 0, dzdy = 0, dsdy = 0, dtdy = 0, dwdy = 0; |
| 2298 | | int drde = 0, dgde = 0, dbde = 0, dade = 0, dzde = 0, dsde = 0, dtde = 0, dwde = 0; |
| 2299 | | int tile; |
| 2300 | | int flip = (w1 & 0x800000) ? 1 : 0; |
| 2984 | INT32 xl, xm, xh; |
| 2985 | INT32 yl, ym, yh; |
| 2986 | INT64 dxldy, dxhdy, dxmdy; |
| 2987 | int r, g, b, a, s, t, w, z; |
| 2988 | int drdx, dgdx, dbdx, dadx, dsdx, dtdx, dwdx, dzdx; |
| 2989 | int drdy, dgdy, dbdy, dady, dsdy, dtdy, dwdy, dzdy; |
| 2990 | int drde, dgde, dbde, dade, dsde, dtde, dwde, dzde; |
| 2991 | int tile; |
| 2992 | int flip; |
| 2301 | 2993 | |
| 2302 | | INT32 yl, ym, yh; |
| 2303 | | INT32 xl, xm, xh; |
| 2304 | | INT64 dxldy, dxhdy, dxmdy; |
| 2305 | | UINT32 w3, w4, w5, w6, w7, w8; |
| 2994 | } triangle_data; |
| 2306 | 2995 | |
| 2307 | | int shade_base = rdp_cmd_cur + 8; |
| 2308 | | int texture_base = rdp_cmd_cur + 8; |
| 2309 | | int zbuffer_base = rdp_cmd_cur + 8; |
| 2310 | | if (shade) |
| 2311 | | { |
| 2312 | | texture_base += 16; |
| 2313 | | zbuffer_base += 16; |
| 2314 | | } |
| 2315 | | if (texture) |
| 2316 | | { |
| 2317 | | zbuffer_base += 16; |
| 2318 | | } |
| 2996 | static void fill_span_buffer_1x1( triangle_data* tri, int* span_start, int* span_end ) |
| 2997 | { |
| 2998 | int j; |
| 2999 | int cvg_idx; |
| 3000 | int xleft, xright, xleft_inc, xright_inc; |
| 3001 | int xstart, xend; |
| 2319 | 3002 | |
| 2320 | | w3 = rdp_cmd_data[rdp_cmd_cur+2]; |
| 2321 | | w4 = rdp_cmd_data[rdp_cmd_cur+3]; |
| 2322 | | w5 = rdp_cmd_data[rdp_cmd_cur+4]; |
| 2323 | | w6 = rdp_cmd_data[rdp_cmd_cur+5]; |
| 2324 | | w7 = rdp_cmd_data[rdp_cmd_cur+6]; |
| 2325 | | w8 = rdp_cmd_data[rdp_cmd_cur+7]; |
| 3003 | tri->yl >>= 2; |
| 3004 | tri->ym >>= 2; |
| 3005 | tri->yh >>= 2; |
| 2326 | 3006 | |
| 2327 | | yl = (w1 & 0x3fff) >> 2; |
| 2328 | | ym = ((w2 >> 16) & 0x3fff) >> 2; |
| 2329 | | yh = ((w2 >> 0) & 0x3fff) >> 2; |
| 2330 | | xl = (INT32)(w3); |
| 2331 | | xh = (INT32)(w5); |
| 2332 | | xm = (INT32)(w7); |
| 2333 | | dxldy = (INT32)(w4); |
| 2334 | | dxhdy = (INT32)(w6); |
| 2335 | | dxmdy = (INT32)(w8); |
| 3007 | xleft = tri->xm; |
| 3008 | xright = tri->xh; |
| 3009 | xleft_inc = tri->dxmdy; |
| 3010 | xright_inc = tri->dxhdy; |
| 2336 | 3011 | |
| 2337 | | if (yl & 0x800) yl |= 0xfffff000; |
| 2338 | | if (ym & 0x800) ym |= 0xfffff000; |
| 2339 | | if (yh & 0x800) yh |= 0xfffff000; |
| 3012 | for(j = tri->yh; j <= tri->yl; j++) |
| 3013 | { |
| 3014 | if(j == tri->ym) |
| 3015 | { |
| 3016 | xleft = tri->xl; |
| 3017 | xleft_inc = tri->dxldy; |
| 3018 | xright_inc = tri->dxhdy; |
| 3019 | } |
| 2340 | 3020 | |
| 2341 | | yl += (w1 >> 1) & 1; |
| 2342 | | ym += (w2 >> 17) & 1; |
| 2343 | | yh += (w2 >> 1) & 1; |
| 3021 | xstart = xleft >> 16; |
| 3022 | xend = xright >> 16; |
| 2344 | 3023 | |
| 2345 | | tile = (w1 >> 16) & 0x7; |
| 3024 | if(j >= 0) |
| 3025 | { |
| 3026 | span[j].lx = xstart; |
| 3027 | span[j].rx = xend; |
| 3028 | span[j].s = tri->s; span[j].ds = tri->dsdx; |
| 3029 | span[j].t = tri->t; span[j].dt = tri->dtdx; |
| 3030 | span[j].w = tri->w; span[j].dw = tri->dwdx; |
| 3031 | span[j].r = tri->r; span[j].dr = tri->drdx; |
| 3032 | span[j].g = tri->g; span[j].dg = tri->dgdx; |
| 3033 | span[j].b = tri->b; span[j].db = tri->dbdx; |
| 3034 | span[j].a = tri->a; span[j].da = tri->dadx; |
| 3035 | span[j].z = tri->z; span[j].dz = tri->dzdx; |
| 3036 | if(tri->flip) |
| 3037 | { |
| 3038 | for(cvg_idx = xend; cvg_idx <= xstart; cvg_idx++) |
| 3039 | { |
| 3040 | span[j].cvg[cvg_idx] = 8; |
| 3041 | } |
| 3042 | } |
| 3043 | else |
| 3044 | { |
| 3045 | for(cvg_idx = xstart; cvg_idx <= xend; cvg_idx++) |
| 3046 | { |
| 3047 | span[j].cvg[cvg_idx] = 8; |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 2346 | 3051 | |
| 2347 | | r = 0xff; g = 0xff; b = 0xff; a = 0xff; z = 0; s = 0; t = 0; w = 0; |
| 2348 | | //dr = 0; dg = 0; db = 0; da = 0; |
| 3052 | xleft += xleft_inc; |
| 3053 | xright += xright_inc; |
| 3054 | tri->s += tri->dsde; |
| 3055 | tri->t += tri->dtde; |
| 3056 | tri->w += tri->dwde; |
| 3057 | tri->r += tri->drde; |
| 3058 | tri->g += tri->dgde; |
| 3059 | tri->b += tri->dbde; |
| 3060 | tri->a += tri->dade; |
| 3061 | tri->z += tri->dzde; |
| 3062 | } |
| 2349 | 3063 | |
| 2350 | | if (shade) |
| 2351 | | { |
| 2352 | | r = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff); |
| 2353 | | g = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff); |
| 2354 | | b = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff); |
| 2355 | | a = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff); |
| 2356 | | drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff); |
| 2357 | | dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff); |
| 2358 | | dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff); |
| 2359 | | dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff); |
| 2360 | | drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff); |
| 2361 | | dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff); |
| 2362 | | dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff); |
| 2363 | | dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff); |
| 2364 | | //drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff); |
| 2365 | | //dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff); |
| 2366 | | //dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff); |
| 2367 | | //dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff); |
| 2368 | | } |
| 2369 | | if (texture) |
| 2370 | | { |
| 2371 | | s = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff); |
| 2372 | | t = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff); |
| 2373 | | w = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff); |
| 2374 | | dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff); |
| 2375 | | dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff); |
| 2376 | | dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff); |
| 2377 | | dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff); |
| 2378 | | dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+12] & 0x0000ffff); |
| 2379 | | dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff); |
| 2380 | | //dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff); |
| 2381 | | //dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+14] & 0x0000ffff); |
| 2382 | | //dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff); |
| 2383 | | } |
| 2384 | | if (zbuffer) |
| 2385 | | { |
| 2386 | | z = rdp_cmd_data[zbuffer_base+0]; |
| 2387 | | dzdx = rdp_cmd_data[zbuffer_base+1]; |
| 2388 | | dzde = rdp_cmd_data[zbuffer_base+2]; |
| 2389 | | //dzdy = rdp_cmd_data[zbuffer_base+3]; |
| 2390 | | } |
| 3064 | *span_start = tri->yh; |
| 3065 | *span_end = tri->yl; |
| 3066 | } |
| 2391 | 3067 | |
| 2392 | | xleft = xm; |
| 2393 | | xright = xh; |
| 2394 | | xleft_inc = dxmdy; |
| 2395 | | xright_inc = dxhdy; |
| 3068 | static void fill_span_buffer_2x2( triangle_data* tri, int* span_start, int* span_end ) |
| 3069 | { |
| 3070 | int j; |
| 3071 | int xleft, xright, xleft_inc, xright_inc; |
| 3072 | int xstart, xend; |
| 3073 | int covered_pixels = 0; |
| 2396 | 3074 | |
| 2397 | | for (j=yh; j < ym; j++) |
| 2398 | | { |
| 2399 | | xstart = xleft >> 16; |
| 2400 | | xend = xright >> 16; |
| 3075 | tri->xm += (tri->dxmdy >> 2) * (tri->yh & 0x0003); |
| 3076 | tri->xh += (tri->dxhdy >> 2) * (tri->yh & 0x0003); |
| 2401 | 3077 | |
| 2402 | | if (j >= 0) |
| 2403 | | { |
| 2404 | | span[j].lx = xstart; |
| 2405 | | span[j].rx = xend; |
| 2406 | | span[j].s = s; span[j].ds = dsdx; |
| 2407 | | span[j].t = t; span[j].dt = dtdx; |
| 2408 | | span[j].w = w; span[j].dw = dwdx; |
| 2409 | | span[j].r = r; span[j].dr = drdx; |
| 2410 | | span[j].g = g; span[j].dg = dgdx; |
| 2411 | | span[j].b = b; span[j].db = dbdx; |
| 2412 | | span[j].a = a; span[j].da = dadx; |
| 2413 | | span[j].z = z; span[j].dz = dzdx; |
| 2414 | | } |
| 3078 | tri->r += (tri->drde >> 2) * (tri->yh & 0x0003); |
| 3079 | tri->g += (tri->dgde >> 2) * (tri->yh & 0x0003); |
| 3080 | tri->b += (tri->dbde >> 2) * (tri->yh & 0x0003); |
| 3081 | tri->a += (tri->dade >> 2) * (tri->yh & 0x0003); |
| 3082 | tri->s += (tri->dsde >> 2) * (tri->yh & 0x0003); |
| 3083 | tri->t += (tri->dtde >> 2) * (tri->yh & 0x0003); |
| 3084 | tri->w += (tri->dwde >> 2) * (tri->yh & 0x0003); |
| 3085 | tri->z += (tri->dzde >> 2) * (tri->yh & 0x0003); |
| 2415 | 3086 | |
| 2416 | | xleft += xleft_inc; |
| 2417 | | xright += xright_inc; |
| 2418 | | s += dsde; |
| 2419 | | t += dtde; |
| 2420 | | w += dwde; |
| 2421 | | r += drde; |
| 2422 | | g += dgde; |
| 2423 | | b += dbde; |
| 2424 | | a += dade; |
| 2425 | | z += dzde; |
| 2426 | | } |
| 3087 | xleft = tri->xm; |
| 3088 | xright = tri->xh; |
| 3089 | xleft_inc = tri->dxmdy; |
| 3090 | xright_inc = tri->dxhdy; |
| 2427 | 3091 | |
| 2428 | | xleft = xl; |
| 2429 | | xleft_inc = dxldy; |
| 2430 | | xright_inc = dxhdy; |
| 3092 | for( j = tri->yh; j <= tri->yl; j++ ) |
| 3093 | { |
| 3094 | if (j == tri->ym) |
| 3095 | { |
| 3096 | xleft = tri->xl; |
| 3097 | xleft_inc = tri->dxldy; |
| 3098 | xright_inc = tri->dxhdy; |
| 3099 | } |
| 2431 | 3100 | |
| 2432 | | for (j=ym; j <= yl; j++) |
| 2433 | | { |
| 2434 | | xstart = xleft >> 16; |
| 2435 | | xend = xright >> 16; |
| 3101 | xstart = xleft >> 14; |
| 3102 | xend = xright >> 14; |
| 2436 | 3103 | |
| 2437 | | if (j >= 0) |
| 2438 | | { |
| 2439 | | span[j].lx = xstart; |
| 2440 | | span[j].rx = xend; |
| 2441 | | span[j].s = s; span[j].ds = dsdx; |
| 2442 | | span[j].t = t; span[j].dt = dtdx; |
| 2443 | | span[j].w = w; span[j].dw = dwdx; |
| 2444 | | span[j].r = r; span[j].dr = drdx; |
| 2445 | | span[j].g = g; span[j].dg = dgdx; |
| 2446 | | span[j].b = b; span[j].db = dbdx; |
| 2447 | | span[j].a = a; span[j].da = dadx; |
| 2448 | | span[j].z = z; span[j].dz = dzdx; |
| 2449 | | } |
| 3104 | if( j >= 0 && ((j == tri->yh) || ((j & 3) == 0)) ) |
| 3105 | { |
| 3106 | memset( span[j >> 2].cvg, 0, RDP_CVG_SPAN_MAX ); |
| 3107 | covered_pixels = 0; |
| 3108 | } |
| 2450 | 3109 | |
| 2451 | | xleft += xleft_inc; |
| 2452 | | xright += xright_inc; |
| 2453 | | s += dsde; |
| 2454 | | t += dtde; |
| 2455 | | w += dwde; |
| 2456 | | r += drde; |
| 2457 | | g += dgde; |
| 2458 | | b += dbde; |
| 2459 | | a += dade; |
| 2460 | | z += dzde; |
| 2461 | | } |
| 3110 | if( j >= 0 ) |
| 3111 | { |
| 3112 | if( tri->flip ) |
| 3113 | { |
| 3114 | int cvg_iter = 0; |
| 2462 | 3115 | |
| 2463 | | switch (fb_size) |
| 2464 | | { |
| 2465 | | case PIXEL_SIZE_16BIT: render_spans_16(yh, yl, tile, shade, texture, zbuffer, flip); break; |
| 2466 | | case PIXEL_SIZE_32BIT: render_spans_32(yh, yl, tile, shade, texture, zbuffer, flip); break; |
| 2467 | | } |
| 3116 | if( xend & 0x0003 ) |
| 3117 | { |
| 3118 | // Round up to the next pixel |
| 3119 | xend &= ~0x0003; |
| 3120 | xend += 4; |
| 3121 | } |
| 3122 | if( xleft & ((1 << 14) - 1) ) |
| 3123 | { |
| 3124 | xstart++; |
| 3125 | } |
| 3126 | for( cvg_iter=xend; cvg_iter < xstart; cvg_iter++ ) |
| 3127 | { |
| 3128 | if( (cvg_iter < 0) || (cvg_iter >= (RDP_CVG_SPAN_MAX << 2)) ) |
| 3129 | { |
| 3130 | continue; |
| 3131 | } |
| 3132 | if( (cvg_iter & 1) == (j & 1) ) |
| 3133 | { |
| 3134 | span[j >> 2].cvg[cvg_iter >> 2]++; |
| 3135 | covered_pixels++; |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | else |
| 3140 | { |
| 3141 | int cvg_iter = 0; |
| 3142 | |
| 3143 | if( xstart & 0x0003 ) |
| 3144 | { |
| 3145 | // Round up to the next pixel |
| 3146 | xstart &= ~0x0003; |
| 3147 | xstart += 4; |
| 3148 | } |
| 3149 | if( xright & ((1 << 14) - 1) ) |
| 3150 | { |
| 3151 | xend++; |
| 3152 | } |
| 3153 | for( cvg_iter = xstart; cvg_iter < xend; cvg_iter++ ) |
| 3154 | { |
| 3155 | if( cvg_iter < 0 || cvg_iter >= (RDP_CVG_SPAN_MAX << 2) ) |
| 3156 | { |
| 3157 | continue; |
| 3158 | } |
| 3159 | if( (cvg_iter & 1) == (j & 1) ) |
| 3160 | { |
| 3161 | span[j >> 2].cvg[cvg_iter >> 2]++; |
| 3162 | covered_pixels++; |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | if( (j & 3) == 3 ) |
| 3168 | { |
| 3169 | span[j >> 2].s = tri->s; span[j >> 2].ds = tri->dsdx; |
| 3170 | span[j >> 2].t = tri->t; span[j >> 2].dt = tri->dtdx; |
| 3171 | span[j >> 2].w = tri->w; span[j >> 2].dw = tri->dwdx; |
| 3172 | span[j >> 2].r = tri->r; span[j >> 2].dr = tri->drdx; |
| 3173 | span[j >> 2].g = tri->g; span[j >> 2].dg = tri->dgdx; |
| 3174 | span[j >> 2].b = tri->b; span[j >> 2].db = tri->dbdx; |
| 3175 | span[j >> 2].a = tri->a; span[j >> 2].da = tri->dadx; |
| 3176 | span[j >> 2].z = tri->z; span[j >> 2].dz = tri->dzdx; |
| 3177 | } |
| 3178 | |
| 3179 | if( (j & 3) == 3 ) |
| 3180 | { |
| 3181 | int cvg_start = 0; |
| 3182 | int cvg_end = 0; |
| 3183 | int cvg_iter = 0; |
| 3184 | |
| 3185 | for( cvg_iter = 0; cvg_iter < (RDP_CVG_SPAN_MAX - 1); cvg_iter++ ) |
| 3186 | { |
| 3187 | if( span[j >> 2].cvg[cvg_iter] == 0 && span[j >> 2].cvg[cvg_iter + 1] > 0 ) |
| 3188 | { |
| 3189 | cvg_start = cvg_iter + 1; |
| 3190 | } |
| 3191 | if( span[j >> 2].cvg[cvg_iter] > 0 && span[j >> 2].cvg[cvg_iter + 1] == 0 ) |
| 3192 | { |
| 3193 | break; |
| 3194 | } |
| 3195 | } |
| 3196 | cvg_end = cvg_iter; |
| 3197 | |
| 3198 | span[j >> 2].lx = xstart >> 2; |
| 3199 | span[j >> 2].rx = xend >> 2; |
| 3200 | |
| 3201 | if( covered_pixels == 0 ) |
| 3202 | { |
| 3203 | span[j >> 2].lx = -1; |
| 3204 | span[j >> 2].rx = -1; |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | xleft += xleft_inc >> 2; |
| 3210 | xright += xright_inc >> 2; |
| 3211 | tri->s += tri->dsde >> 2; |
| 3212 | tri->t += tri->dtde >> 2; |
| 3213 | tri->w += tri->dwde >> 2; |
| 3214 | tri->r += tri->drde >> 2; |
| 3215 | tri->g += tri->dgde >> 2; |
| 3216 | tri->b += tri->dbde >> 2; |
| 3217 | tri->a += tri->dade >> 2; |
| 3218 | tri->z += tri->dzde >> 2; |
| 3219 | } |
| 3220 | |
| 3221 | *span_start = tri->yh >> 2; |
| 3222 | *span_end = ((tri->yl & 0x0003) == 3) ? (tri->yl >> 2) : ((tri->yl >> 2) - 1); |
| 2468 | 3223 | } |
| 2469 | 3224 | |
| 3225 | static void triangle(UINT32 w1, UINT32 w2, int shade, int texture, int zbuffer) |
| 3226 | { |
| 3227 | UINT32 w3, w4, w5, w6, w7, w8; |
| 3228 | |
| 3229 | int shade_base = rdp_cmd_cur + 8; |
| 3230 | int texture_base = rdp_cmd_cur + 8; |
| 3231 | int zbuffer_base = rdp_cmd_cur + 8; |
| 3232 | |
| 3233 | int span_start = 0; |
| 3234 | int span_end = 0; |
| 3235 | |
| 3236 | triangle_data tri; |
| 3237 | |
| 3238 | tri.yl = tri.ym = tri.yh = 0; |
| 3239 | tri.xl = tri.xm = tri.xh = 0; |
| 3240 | tri.dxldy = tri.dxhdy = tri.dxmdy = 0; |
| 3241 | tri.r = tri.g = tri.b = tri.a = tri.s = tri.t = tri.w = tri.z = 0; |
| 3242 | tri.drdx = tri.dgdx = tri.dbdx = tri.dadx = tri.dsdx = tri.dtdx = tri.dwdx = tri.dzdx = 0; |
| 3243 | tri.drdy = tri.dgdy = tri.dbdy = tri.dady = tri.dsdy = tri.dtdy = tri.dwdy = tri.dzdy = 0; |
| 3244 | tri.drde = tri.dgde = tri.dbde = tri.dade = tri.dsde = tri.dtde = tri.dwde = tri.dzde = 0; |
| 3245 | tri.tile = (w1 >> 16) & 0x7;; |
| 3246 | tri.flip = (w1 & 0x800000) ? 1 : 0; |
| 3247 | |
| 3248 | if (shade) |
| 3249 | { |
| 3250 | texture_base += 16; |
| 3251 | zbuffer_base += 16; |
| 3252 | } |
| 3253 | if (texture) |
| 3254 | { |
| 3255 | zbuffer_base += 16; |
| 3256 | } |
| 3257 | |
| 3258 | w3 = rdp_cmd_data[rdp_cmd_cur+2]; |
| 3259 | w4 = rdp_cmd_data[rdp_cmd_cur+3]; |
| 3260 | w5 = rdp_cmd_data[rdp_cmd_cur+4]; |
| 3261 | w6 = rdp_cmd_data[rdp_cmd_cur+5]; |
| 3262 | w7 = rdp_cmd_data[rdp_cmd_cur+6]; |
| 3263 | w8 = rdp_cmd_data[rdp_cmd_cur+7]; |
| 3264 | |
| 3265 | tri.yl = (w1 & 0x3fff); |
| 3266 | tri.ym = ((w2 >> 16) & 0x3fff); |
| 3267 | tri.yh = ((w2 >> 0) & 0x3fff); |
| 3268 | tri.xl = (INT32)(w3); |
| 3269 | tri.xh = (INT32)(w5); |
| 3270 | tri.xm = (INT32)(w7); |
| 3271 | tri.dxldy = (INT32)(w4); |
| 3272 | tri.dxhdy = (INT32)(w6); |
| 3273 | tri.dxmdy = (INT32)(w8); |
| 3274 | |
| 3275 | if (tri.yl & 0x2000) tri.yl |= 0xffffc000; |
| 3276 | if (tri.ym & 0x2000) tri.ym |= 0xffffc000; |
| 3277 | if (tri.yh & 0x2000) tri.yh |= 0xffffc000; |
| 3278 | |
| 3279 | tri.r = tri.g = tri.b = tri.a = 0xff; |
| 3280 | tri.s = tri.t = tri.w = 0; |
| 3281 | tri.z = 0; |
| 3282 | |
| 3283 | if (shade) |
| 3284 | { |
| 3285 | tri.r = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff); |
| 3286 | tri.g = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff); |
| 3287 | tri.b = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff); |
| 3288 | tri.a = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff); |
| 3289 | tri.drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff); |
| 3290 | tri.dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff); |
| 3291 | tri.dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff); |
| 3292 | tri.dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff); |
| 3293 | tri.drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff); |
| 3294 | tri.dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff); |
| 3295 | tri.dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff); |
| 3296 | tri.dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff); |
| 3297 | tri.drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff); |
| 3298 | tri.dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff); |
| 3299 | tri.dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff); |
| 3300 | tri.dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff); |
| 3301 | } |
| 3302 | if (texture) |
| 3303 | { |
| 3304 | tri.s = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff); |
| 3305 | tri.t = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff); |
| 3306 | tri.w = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff); |
| 3307 | tri.dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff); |
| 3308 | tri.dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff); |
| 3309 | tri.dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff); |
| 3310 | tri.dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff); |
| 3311 | tri.dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+12] & 0x0000ffff); |
| 3312 | tri.dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff); |
| 3313 | tri.dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff); |
| 3314 | tri.dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+14] & 0x0000ffff); |
| 3315 | tri.dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff); |
| 3316 | } |
| 3317 | if (zbuffer) |
| 3318 | { |
| 3319 | tri.z = rdp_cmd_data[zbuffer_base+0]; |
| 3320 | tri.dzdx = rdp_cmd_data[zbuffer_base+1]; |
| 3321 | tri.dzde = rdp_cmd_data[zbuffer_base+2]; |
| 3322 | tri.dzdy = rdp_cmd_data[zbuffer_base+3]; |
| 3323 | } |
| 3324 | |
| 3325 | if( other_modes.sample_type == SAMPLE_TYPE_1x1 ) |
| 3326 | { |
| 3327 | fill_span_buffer_1x1( &tri, &span_start, &span_end ); |
| 3328 | } |
| 3329 | else |
| 3330 | { |
| 3331 | fill_span_buffer_2x2( &tri, &span_start, &span_end ); |
| 3332 | } |
| 3333 | |
| 3334 | switch (fb_size) |
| 3335 | { |
| 3336 | case PIXEL_SIZE_16BIT: render_spans_16(span_start, span_end, tri.tile, shade, texture, zbuffer, tri.flip); break; |
| 3337 | case PIXEL_SIZE_32BIT: render_spans_32(span_start, span_end, tri.tile, shade, texture, zbuffer, tri.flip); break; |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 2470 | 3341 | /*****************************************************************************/ |
| 2471 | 3342 | |
| 2472 | 3343 | INLINE UINT32 READ_RDP_DATA(UINT32 address) |