src/mame/video/n64.c
| r7676 | r7677 | |
| 1 | | /* |
| 2 | | Nintendo 64 Video Hardware |
| 1 | /****************************************************************************** |
| 3 | 2 | |
| 4 | | Initial version by Ville Linde |
| 5 | | Many improvements by Harmony |
| 6 | | Many improvements by angrylion, Ziggy, Gonetz, Orkin |
| 7 | | */ |
| 8 | 3 | |
| 4 | SGI/Nintendo Reality Display Processor |
| 5 | ------------------- |
| 6 | |
| 7 | Initial revision by Ville Linde |
| 8 | Many improvements by Harmony, angrylion, Ziggy, Gonetz and Orkin |
| 9 | |
| 10 | Class re-write by Harmony |
| 11 | |
| 12 | |
| 13 | ******************************************************************************* |
| 14 | |
| 15 | STATUS: |
| 16 | |
| 17 | Much behavior needs verification against real hardware. Many literal edge |
| 18 | cases must be verified on real hardware as well. |
| 19 | |
| 20 | TODO: |
| 21 | |
| 22 | - Further re-work class structure to avoid dependencies |
| 23 | |
| 24 | *******************************************************************************/ |
| 25 | |
| 9 | 26 | #include "emu.h" |
| 10 | 27 | #include "includes/n64.h" |
| 11 | 28 | #include "video/n64.h" |
| r7676 | r7677 | |
| 21 | 38 | // The functions in this file should be moved into the parent Processor class. |
| 22 | 39 | #include "rdpfiltr.c" |
| 23 | 40 | |
| 24 | | void N64::RDP::Processor::GetAlphaCvg(UINT8 *comb_alpha) |
| 41 | namespace N64 |
| 25 | 42 | { |
| 43 | |
| 44 | namespace RDP |
| 45 | { |
| 46 | |
| 47 | void Processor::GetAlphaCvg(UINT8 *comb_alpha) |
| 48 | { |
| 26 | 49 | if(m_other_modes.cvg_times_alpha) |
| 27 | 50 | { |
| 28 | 51 | if(m_other_modes.alpha_cvg_select) |
| r7676 | r7677 | |
| 83 | 106 | |
| 84 | 107 | /*****************************************************************************/ |
| 85 | 108 | |
| 86 | | void N64::RDP::Processor::VideoUpdate(bitmap_t *bitmap) |
| 109 | void Processor::VideoUpdate(bitmap_t *bitmap) |
| 87 | 110 | { |
| 88 | 111 | switch(n64_vi_control & 0x3) |
| 89 | 112 | { |
| r7676 | r7677 | |
| 101 | 124 | } |
| 102 | 125 | } |
| 103 | 126 | |
| 104 | | void N64::RDP::Processor::VideoUpdate16(bitmap_t *bitmap) |
| 127 | void Processor::VideoUpdate16(bitmap_t *bitmap) |
| 105 | 128 | { |
| 106 | 129 | int fsaa = (((n64_vi_control >> 8) & 3) < 2); |
| 107 | 130 | int divot = (n64_vi_control >> 4) & 1; |
| r7676 | r7677 | |
| 145 | 168 | |
| 146 | 169 | for(int i = 0; i < hres; i++) |
| 147 | 170 | { |
| 148 | | N64::RDP::Color c; |
| 171 | Color c; |
| 149 | 172 | //int r, g, b; |
| 150 | 173 | |
| 151 | 174 | UINT16 pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; |
| r7676 | r7677 | |
| 236 | 259 | } |
| 237 | 260 | } |
| 238 | 261 | |
| 239 | | void N64::RDP::Processor::VideoUpdate32(bitmap_t *bitmap) |
| 262 | void Processor::VideoUpdate32(bitmap_t *bitmap) |
| 240 | 263 | { |
| 241 | 264 | int gamma = (n64_vi_control >> 3) & 1; |
| 242 | 265 | int gamma_dither = (n64_vi_control >> 2) & 1; |
| r7676 | r7677 | |
| 319 | 342 | |
| 320 | 343 | /*****************************************************************************/ |
| 321 | 344 | |
| 322 | | void N64::RDP::Processor::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 345 | void Processor::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 323 | 346 | { |
| 324 | 347 | int shift; |
| 325 | 348 | |
| r7676 | r7677 | |
| 345 | 368 | } |
| 346 | 369 | } |
| 347 | 370 | |
| 348 | | void N64::RDP::Processor::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 371 | void Processor::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 349 | 372 | { |
| 350 | 373 | switch (code & 0xf) |
| 351 | 374 | { |
| r7676 | r7677 | |
| 364 | 387 | } |
| 365 | 388 | } |
| 366 | 389 | |
| 367 | | void N64::RDP::Processor::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 390 | void Processor::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 368 | 391 | { |
| 369 | 392 | switch (code & 0xf) |
| 370 | 393 | { |
| r7676 | r7677 | |
| 383 | 406 | } |
| 384 | 407 | } |
| 385 | 408 | |
| 386 | | void N64::RDP::Processor::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 409 | void Processor::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 387 | 410 | { |
| 388 | 411 | switch (code & 0x1f) |
| 389 | 412 | { |
| r7676 | r7677 | |
| 411 | 434 | } |
| 412 | 435 | } |
| 413 | 436 | |
| 414 | | void N64::RDP::Processor::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 437 | void Processor::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 415 | 438 | { |
| 416 | 439 | switch (code & 0x7) |
| 417 | 440 | { |
| r7676 | r7677 | |
| 426 | 449 | } |
| 427 | 450 | } |
| 428 | 451 | |
| 429 | | void N64::RDP::Processor::SetSubInputAlpha(UINT8 **input, int code) |
| 452 | void Processor::SetSubInputAlpha(UINT8 **input, int code) |
| 430 | 453 | { |
| 431 | 454 | switch (code & 0x7) |
| 432 | 455 | { |
| r7676 | r7677 | |
| 441 | 464 | } |
| 442 | 465 | } |
| 443 | 466 | |
| 444 | | void N64::RDP::Processor::SetMulInputAlpha(UINT8 **input, int code) |
| 467 | void Processor::SetMulInputAlpha(UINT8 **input, int code) |
| 445 | 468 | { |
| 446 | 469 | switch (code & 0x7) |
| 447 | 470 | { |
| r7676 | r7677 | |
| 456 | 479 | } |
| 457 | 480 | } |
| 458 | 481 | |
| 459 | | void N64::RDP::Processor::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b) |
| 482 | void Processor::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b) |
| 460 | 483 | { |
| 461 | 484 | switch (a & 0x3) |
| 462 | 485 | { |
| r7676 | r7677 | |
| 524 | 547 | } |
| 525 | 548 | } |
| 526 | 549 | |
| 527 | | const UINT8 N64::RDP::Processor::s_bayer_matrix[16] = |
| 550 | const UINT8 Processor::s_bayer_matrix[16] = |
| 528 | 551 | { /* Bayer matrix */ |
| 529 | 552 | 0, 4, 1, 5, |
| 530 | 553 | 6, 2, 7, 3, |
| r7676 | r7677 | |
| 532 | 555 | 7, 3, 6, 2 |
| 533 | 556 | }; |
| 534 | 557 | |
| 535 | | const UINT8 N64::RDP::Processor::s_magic_matrix[16] = |
| 558 | const UINT8 Processor::s_magic_matrix[16] = |
| 536 | 559 | { /* Magic square matrix */ |
| 537 | 560 | 0, 6, 1, 7, |
| 538 | 561 | 4, 2, 5, 3, |
| r7676 | r7677 | |
| 540 | 563 | 7, 1, 6, 0 |
| 541 | 564 | }; |
| 542 | 565 | |
| 543 | | const N64::RDP::Processor::ZDecompressEntry N64::RDP::Processor::m_z_decompress_table[8] = |
| 566 | const Processor::ZDecompressEntry Processor::m_z_decompress_table[8] = |
| 544 | 567 | { |
| 545 | 568 | { 6, 0x00000 }, |
| 546 | 569 | { 5, 0x20000 }, |
| r7676 | r7677 | |
| 554 | 577 | |
| 555 | 578 | /*****************************************************************************/ |
| 556 | 579 | |
| 557 | | void N64::RDP::Processor::BuildCompressedZTable() |
| 580 | void Processor::BuildCompressedZTable() |
| 558 | 581 | { |
| 559 | 582 | for(int j = 0; j < 0x40000; j++) |
| 560 | 583 | { |
| r7676 | r7677 | |
| 572 | 595 | } |
| 573 | 596 | } |
| 574 | 597 | |
| 575 | | void N64::RDP::Processor::ZStore(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz) |
| 598 | void Processor::ZStore(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz) |
| 576 | 599 | { |
| 577 | 600 | UINT8 deltazmem = 15; |
| 578 | 601 | z &= 0x3ffff; |
| r7676 | r7677 | |
| 596 | 619 | *zhb = (deltazmem & 3); |
| 597 | 620 | } |
| 598 | 621 | |
| 599 | | UINT32 N64::RDP::Processor::DecompressZ(UINT16 *zb) |
| 622 | UINT32 Processor::DecompressZ(UINT16 *zb) |
| 600 | 623 | { |
| 601 | 624 | UINT32 exponent = (*zb >> 13) & 7; |
| 602 | 625 | UINT32 mantissa = (*zb >> 2) & 0x7ff; |
| 603 | 626 | return ((mantissa << m_z_decompress_table[exponent].shift) + m_z_decompress_table[exponent].add); |
| 604 | 627 | } |
| 605 | 628 | |
| 606 | | UINT16 N64::RDP::Processor::DecompressDZ(UINT16* zb, UINT8* zhb) |
| 629 | UINT16 Processor::DecompressDZ(UINT16* zb, UINT8* zhb) |
| 607 | 630 | { |
| 608 | 631 | UINT32 dz_compressed = (((*zb & 3) << 2)|(*zhb & 3)); |
| 609 | 632 | return (1 << dz_compressed); |
| 610 | 633 | } |
| 611 | 634 | |
| 612 | | INT32 N64::RDP::Processor::NormalizeDZPix(INT32 sum) |
| 635 | INT32 Processor::NormalizeDZPix(INT32 sum) |
| 613 | 636 | { |
| 614 | 637 | if (sum & 0xc000) |
| 615 | 638 | { |
| r7676 | r7677 | |
| 629 | 652 | return 0; |
| 630 | 653 | } |
| 631 | 654 | |
| 632 | | bool N64::RDP::Processor::ZCompare(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix) |
| 655 | bool Processor::ZCompare(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix) |
| 633 | 656 | { |
| 634 | 657 | int force_coplanar = 0; |
| 635 | 658 | UINT32 oz = DecompressZ(zb); |
| r7676 | r7677 | |
| 738 | 761 | } |
| 739 | 762 | } |
| 740 | 763 | |
| 741 | | UINT32 N64::RDP::Processor::GetLog2(UINT32 lod_clamp) |
| 764 | UINT32 Processor::GetLog2(UINT32 lod_clamp) |
| 742 | 765 | { |
| 743 | 766 | if (lod_clamp < 2) |
| 744 | 767 | { |
| r7676 | r7677 | |
| 760 | 783 | |
| 761 | 784 | /*****************************************************************************/ |
| 762 | 785 | |
| 763 | | static void fill_rectangle_32bit(running_machine *machine, N64::RDP::Rectangle *rect) |
| 764 | | { |
| 765 | | _n64_state *state = (_n64_state *)machine->driver_data; |
| 766 | | |
| 767 | | UINT32 *fb = (UINT32*)&rdram[(state->m_rdp.GetMiscState()->m_fb_address / 4)]; |
| 768 | | int x1 = rect->m_xh; |
| 769 | | int x2 = rect->m_xl; |
| 770 | | int y1 = rect->m_yh; |
| 771 | | int y2 = rect->m_yl; |
| 772 | | int fill_cvg = 0; |
| 773 | | |
| 774 | | // clip |
| 775 | | if (x1 < state->m_rdp.GetScissor()->m_xh) |
| 776 | | { |
| 777 | | x1 = state->m_rdp.GetScissor()->m_xh; |
| 778 | | } |
| 779 | | if (y1 < state->m_rdp.GetScissor()->m_yh) |
| 780 | | { |
| 781 | | y1 = state->m_rdp.GetScissor()->m_yh; |
| 782 | | } |
| 783 | | if (x2 >= state->m_rdp.GetScissor()->m_xl) |
| 784 | | { |
| 785 | | x2 = state->m_rdp.GetScissor()->m_xl - 1; |
| 786 | | } |
| 787 | | if (y2 >= state->m_rdp.GetScissor()->m_yl) |
| 788 | | { |
| 789 | | y2 = state->m_rdp.GetScissor()->m_yl - 1; |
| 790 | | } |
| 791 | | |
| 792 | | state->m_rdp.GetShadeColor()->c = 0; |
| 793 | | |
| 794 | | fill_cvg = ((state->m_rdp.GetFillColor32() >> 5) & 7) + 1; |
| 795 | | |
| 796 | | if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_FILL) |
| 797 | | { |
| 798 | | for (int j = y1; j <= y2; j++) |
| 799 | | { |
| 800 | | int index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 801 | | |
| 802 | | for (int i = x1; i <= x2; i++) |
| 803 | | { |
| 804 | | fb[(index + i)^1] = state->m_rdp.GetFillColor32(); |
| 805 | | } |
| 806 | | } |
| 807 | | } |
| 808 | | else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_1) |
| 809 | | { |
| 810 | | for (int j = y1; j <= y2; j++) |
| 811 | | { |
| 812 | | N64::RDP::Color c1; |
| 813 | | int index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 814 | | for (int i = x1; i <= x2; i++) |
| 815 | | { |
| 816 | | state->m_rdp.GetMiscState()->m_curpixel_cvg = fill_cvg; |
| 817 | | |
| 818 | | c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1], |
| 819 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1], |
| 820 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1], |
| 821 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]); |
| 822 | | c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1], |
| 823 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1], |
| 824 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1], |
| 825 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]); |
| 826 | | c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1], |
| 827 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1], |
| 828 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1], |
| 829 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]); |
| 830 | | c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1], |
| 831 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1], |
| 832 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[1], |
| 833 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]); |
| 834 | | state->m_rdp.GetAlphaCvg(&c1.i.a); |
| 835 | | |
| 836 | | state->m_rdp.GetBlender()->Blend(&fb[(index + i)], NULL, c1, *state->m_rdp.GetZero(), 0); |
| 837 | | } |
| 838 | | } |
| 839 | | } |
| 840 | | else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2) |
| 841 | | { |
| 842 | | for (int j = y1; j <= y2; j++) |
| 843 | | { |
| 844 | | N64::RDP::Color c1, c2; |
| 845 | | int index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 846 | | for (int i = x1; i <= x2; i++) |
| 847 | | { |
| 848 | | state->m_rdp.GetMiscState()->m_curpixel_cvg = fill_cvg; |
| 849 | | |
| 850 | | c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[0], |
| 851 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[0], |
| 852 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[0], |
| 853 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[0]); |
| 854 | | c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[0], |
| 855 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[0], |
| 856 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[0], |
| 857 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[0]); |
| 858 | | c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[0], |
| 859 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[0], |
| 860 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[0], |
| 861 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[0]); |
| 862 | | c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[0], |
| 863 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[0], |
| 864 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[0], |
| 865 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[0]); |
| 866 | | state->m_rdp.GetCombinedColor()->c = c1.c; |
| 867 | | c2.c = state->m_rdp.GetTexel0Color()->c; |
| 868 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexel1Color()->c; |
| 869 | | state->m_rdp.GetTexel1Color()->c = c2.c; |
| 870 | | c2.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1], |
| 871 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1], |
| 872 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1], |
| 873 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]); |
| 874 | | c2.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1], |
| 875 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1], |
| 876 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1], |
| 877 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]); |
| 878 | | c2.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1], |
| 879 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1], |
| 880 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1], |
| 881 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]); |
| 882 | | c2.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1], |
| 883 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1], |
| 884 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[1], |
| 885 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]); |
| 886 | | state->m_rdp.GetAlphaCvg(&c2.i.a); |
| 887 | | |
| 888 | | state->m_rdp.GetBlender()->Blend(&fb[(index + i)], NULL, c1, c2, 0); |
| 889 | | //BLENDER2_32(&fb[(index + i)], c1, c2); |
| 890 | | } |
| 891 | | } |
| 892 | | } |
| 893 | | else |
| 894 | | { |
| 895 | | fatalerror("fill_rectangle_32bit: cycle type copy"); |
| 896 | | } |
| 897 | | } |
| 898 | | |
| 899 | | INLINE void texture_rectangle_32bit(running_machine *machine, N64::RDP::TexRectangle *rect) |
| 900 | | { // TODO: Z-compare and Z-update |
| 901 | | _n64_state *state = (_n64_state *)machine->driver_data; |
| 902 | | |
| 903 | | UINT32 *fb = (UINT32*)&rdram[(state->m_rdp.GetMiscState()->m_fb_address / 4)]; |
| 904 | | |
| 905 | | UINT32 tilenum = rect->m_tilenum; |
| 906 | | UINT32 tilenum2 = 0; |
| 907 | | N64::RDP::Tile *tex_tile = &state->m_rdp.GetTiles()[rect->m_tilenum]; |
| 908 | | N64::RDP::Tile *tex_tile2 = NULL; |
| 909 | | |
| 910 | | int x1 = rect->m_xh; |
| 911 | | int x2 = rect->m_xl; |
| 912 | | int y1 = rect->m_yh; |
| 913 | | int y2 = rect->m_yl; |
| 914 | | |
| 915 | | if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_FILL || state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_COPY) |
| 916 | | { |
| 917 | | rect->m_dsdx /= 4; |
| 918 | | x2 += 1; |
| 919 | | y2 += 1; |
| 920 | | } |
| 921 | | |
| 922 | | // clip |
| 923 | | if (x1 < state->m_rdp.GetScissor()->m_xh) |
| 924 | | { |
| 925 | | x1 = state->m_rdp.GetScissor()->m_xh; |
| 926 | | } |
| 927 | | if (y1 < state->m_rdp.GetScissor()->m_yh) |
| 928 | | { |
| 929 | | y1 = state->m_rdp.GetScissor()->m_yh; |
| 930 | | } |
| 931 | | if (x2 >= state->m_rdp.GetScissor()->m_xl) |
| 932 | | { |
| 933 | | x2 = state->m_rdp.GetScissor()->m_xl - 1; |
| 934 | | } |
| 935 | | if (y2 >= state->m_rdp.GetScissor()->m_yl) |
| 936 | | { |
| 937 | | y2 = state->m_rdp.GetScissor()->m_yl - 1; |
| 938 | | } |
| 939 | | |
| 940 | | state->m_rdp.GetTexPipe()->CalculateClampDiffs(tex_tile->num); |
| 941 | | |
| 942 | | if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2) |
| 943 | | { |
| 944 | | if (!state->m_rdp.GetOtherModes()->tex_lod_en) |
| 945 | | { |
| 946 | | tilenum2 = (tilenum + 1) & 7; |
| 947 | | tex_tile2 = &state->m_rdp.GetTiles()[tilenum2]; |
| 948 | | } |
| 949 | | else |
| 950 | | { |
| 951 | | tilenum2 = (tilenum + 1) & 7; |
| 952 | | tex_tile2 = &state->m_rdp.GetTiles()[tilenum2]; |
| 953 | | } |
| 954 | | } |
| 955 | | |
| 956 | | state->m_rdp.GetShadeColor()->c = 0; // Needed by Pilotwings 64 |
| 957 | | |
| 958 | | int t = (int)(rect->m_t) << 5; |
| 959 | | |
| 960 | | if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_1) |
| 961 | | { |
| 962 | | for (int j = y1; j < y2; j++) |
| 963 | | { |
| 964 | | int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 965 | | |
| 966 | | int s = (int)(rect->m_s) << 5; |
| 967 | | |
| 968 | | for (int i = x1; i < x2; i++) |
| 969 | | { |
| 970 | | N64::RDP::Color c1; |
| 971 | | int ss = s >> 5; |
| 972 | | int st = t >> 5; |
| 973 | | |
| 974 | | state->m_rdp.GetMiscState()->m_curpixel_cvg = 8; |
| 975 | | |
| 976 | | if (rect->m_flip) |
| 977 | | { |
| 978 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile); |
| 979 | | } |
| 980 | | else |
| 981 | | { |
| 982 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile); |
| 983 | | } |
| 984 | | |
| 985 | | c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1], |
| 986 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1], |
| 987 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1], |
| 988 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]); |
| 989 | | c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1], |
| 990 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1], |
| 991 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1], |
| 992 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]); |
| 993 | | c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1], |
| 994 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1], |
| 995 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1], |
| 996 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]); |
| 997 | | c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1], |
| 998 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1], |
| 999 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[1], |
| 1000 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]); |
| 1001 | | state->m_rdp.GetAlphaCvg(&c1.i.a); |
| 1002 | | |
| 1003 | | state->m_rdp.GetBlender()->Blend(&fb[(fb_index + i)], NULL, c1, *state->m_rdp.GetZero(), 0); |
| 1004 | | |
| 1005 | | s += rect->m_dsdx; |
| 1006 | | } |
| 1007 | | |
| 1008 | | t += rect->m_dtdy; |
| 1009 | | } |
| 1010 | | } |
| 1011 | | else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2) |
| 1012 | | { |
| 1013 | | for (int j = y1; j < y2; j++) |
| 1014 | | { |
| 1015 | | int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 1016 | | |
| 1017 | | int s = (int)(rect->m_s) << 5; |
| 1018 | | |
| 1019 | | for (int i = x1; i < x2; i++) |
| 1020 | | { |
| 1021 | | N64::RDP::Color c1, c2; |
| 1022 | | int ss = s >> 5; |
| 1023 | | int st = t >> 5; |
| 1024 | | |
| 1025 | | state->m_rdp.GetMiscState()->m_curpixel_cvg = 8; |
| 1026 | | |
| 1027 | | if (rect->m_flip) |
| 1028 | | { |
| 1029 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile); |
| 1030 | | state->m_rdp.GetTexel1Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile2); |
| 1031 | | } |
| 1032 | | else |
| 1033 | | { |
| 1034 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile); |
| 1035 | | state->m_rdp.GetTexel1Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile2); |
| 1036 | | } |
| 1037 | | |
| 1038 | | c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[0], |
| 1039 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[0], |
| 1040 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[0], |
| 1041 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[0]); |
| 1042 | | c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[0], |
| 1043 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[0], |
| 1044 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[0], |
| 1045 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[0]); |
| 1046 | | c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[0], |
| 1047 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[0], |
| 1048 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[0], |
| 1049 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[0]); |
| 1050 | | c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[0], |
| 1051 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[0], |
| 1052 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[0], |
| 1053 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[0]); |
| 1054 | | state->m_rdp.GetCombinedColor()->c = c1.c; |
| 1055 | | c2.c = state->m_rdp.GetTexel0Color()->c; |
| 1056 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexel1Color()->c; |
| 1057 | | state->m_rdp.GetTexel1Color()->c = c2.c; |
| 1058 | | c2.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1], |
| 1059 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1], |
| 1060 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1], |
| 1061 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]); |
| 1062 | | c2.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1], |
| 1063 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1], |
| 1064 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1], |
| 1065 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]); |
| 1066 | | c2.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1], |
| 1067 | | *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1], |
| 1068 | | *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1], |
| 1069 | | *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]); |
| 1070 | | c2.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1], |
| 1071 | | *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1], |
| 1072 | | *state->m_rdp.GetColorInputs()->combiner_alphamul[1], |
| 1073 | | *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]); |
| 1074 | | state->m_rdp.GetAlphaCvg(&c2.i.a); |
| 1075 | | |
| 1076 | | state->m_rdp.GetBlender()->Blend(&fb[(fb_index + i)], NULL, c1, c2, 0); |
| 1077 | | |
| 1078 | | s += rect->m_dsdx; |
| 1079 | | } |
| 1080 | | |
| 1081 | | t += rect->m_dtdy; |
| 1082 | | } |
| 1083 | | } |
| 1084 | | else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_COPY) |
| 1085 | | { |
| 1086 | | for (int j = y1; j < y2; j++) |
| 1087 | | { |
| 1088 | | int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width; |
| 1089 | | |
| 1090 | | int s = (int)(rect->m_s) << 5; |
| 1091 | | |
| 1092 | | for (int i = x1; i < x2; i++) |
| 1093 | | { |
| 1094 | | int ss = s >> 5; |
| 1095 | | int st = t >> 5; |
| 1096 | | if (rect->m_flip) |
| 1097 | | { |
| 1098 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile); |
| 1099 | | } |
| 1100 | | else |
| 1101 | | { |
| 1102 | | state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile); |
| 1103 | | } |
| 1104 | | |
| 1105 | | fb[fb_index + i] = (state->m_rdp.GetTexel0Color()->i.r << 24) | (state->m_rdp.GetTexel0Color()->i.g << 16) | (state->m_rdp.GetTexel0Color()->i.b << 8)|1; |
| 1106 | | |
| 1107 | | s += rect->m_dsdx; |
| 1108 | | } |
| 1109 | | |
| 1110 | | t += rect->m_dtdy; |
| 1111 | | } |
| 1112 | | } |
| 1113 | | else |
| 1114 | | { |
| 1115 | | fatalerror("texture_rectangle_32bit: unknown cycle type %d\n", state->m_rdp.GetOtherModes()->cycle_type); |
| 1116 | | } |
| 1117 | | } |
| 1118 | | |
| 1119 | | /*****************************************************************************/ |
| 1120 | | |
| 1121 | 786 | UINT32 N64::RDP::Processor::ReadData(UINT32 address) |
| 1122 | 787 | { |
| 1123 | 788 | if (m_status & 0x1) // XBUS_DMEM_DMA enabled |
| r7676 | r7677 | |
| 2116 | 1781 | void N64::RDP::Processor::CmdTexRect(UINT32 w1, UINT32 w2) |
| 2117 | 1782 | { |
| 2118 | 1783 | N64::RDP::TexRectangle rect(m_machine, m_cmd_data + m_cmd_cur, 0); |
| 2119 | | |
| 2120 | | switch (m_misc_state.m_fb_size) |
| 2121 | | { |
| 2122 | | case PIXEL_SIZE_16BIT: |
| 2123 | | rect.Draw(); |
| 2124 | | break; |
| 2125 | | case PIXEL_SIZE_32BIT: |
| 2126 | | texture_rectangle_32bit(m_machine, &rect); |
| 2127 | | break; |
| 2128 | | } |
| 1784 | rect.Draw(); |
| 2129 | 1785 | } |
| 2130 | 1786 | |
| 2131 | 1787 | void N64::RDP::Processor::CmdTexRectFlip(UINT32 w1, UINT32 w2) |
| 2132 | 1788 | { |
| 2133 | 1789 | N64::RDP::TexRectangle rect(m_machine, m_cmd_data + m_cmd_cur, 1); |
| 2134 | | |
| 2135 | | switch (m_misc_state.m_fb_size) |
| 2136 | | { |
| 2137 | | case PIXEL_SIZE_16BIT: rect.Draw(); break; |
| 2138 | | case PIXEL_SIZE_32BIT: texture_rectangle_32bit(m_machine, &rect); break; |
| 2139 | | } |
| 1790 | rect.Draw(); |
| 2140 | 1791 | } |
| 2141 | 1792 | |
| 2142 | 1793 | void N64::RDP::Processor::CmdSyncLoad(UINT32 w1, UINT32 w2) |
| r7676 | r7677 | |
| 2542 | 2193 | { |
| 2543 | 2194 | N64::RDP::Rectangle rect(m_machine, m_cmd_data + m_cmd_cur); |
| 2544 | 2195 | |
| 2545 | | switch (m_misc_state.m_fb_size) |
| 2546 | | { |
| 2547 | | case PIXEL_SIZE_16BIT: |
| 2548 | | rect.Draw(); |
| 2549 | | break; |
| 2550 | | case PIXEL_SIZE_32BIT: |
| 2551 | | fill_rectangle_32bit(m_machine, &rect); |
| 2552 | | break; |
| 2553 | | } |
| 2196 | rect.Draw(); |
| 2554 | 2197 | } |
| 2555 | 2198 | |
| 2556 | 2199 | void N64::RDP::Processor::CmdSetFogColor(UINT32 w1, UINT32 w2) |
| r7676 | r7677 | |
| 2853 | 2496 | m_start = m_current = m_end; |
| 2854 | 2497 | } |
| 2855 | 2498 | |
| 2499 | } // namespace RDP |
| 2500 | |
| 2501 | } // namespace N64 |
| 2502 | |
| 2856 | 2503 | /*****************************************************************************/ |
| 2857 | 2504 | |
| 2858 | 2505 | VIDEO_START(n64) |