src/mame/video/rdptpipe.c
| r14423 | r14424 | |
| 2 | 2 | #include "includes/n64.h" |
| 3 | 3 | #include "video/n64.h" |
| 4 | 4 | |
| 5 | | namespace N64 |
| 6 | | { |
| 7 | | |
| 8 | | namespace RDP |
| 9 | | { |
| 10 | | |
| 11 | 5 | #define RELATIVE(x, y) ((((x) >> 3) - (y)) << 3) | (x & 7); |
| 12 | 6 | |
| 13 | | void TexturePipeT::SetMachine(running_machine &machine) |
| 7 | void N64TexturePipeT::SetMachine(running_machine &machine) |
| 14 | 8 | { |
| 15 | | _n64_state *state = machine.driver_data<_n64_state>(); |
| 9 | n64_state *state = machine.driver_data<n64_state>(); |
| 16 | 10 | |
| 17 | | m_machine = &machine; |
| 18 | | m_rdp = &state->m_rdp; |
| 11 | m_rdp = state->m_rdp; |
| 19 | 12 | |
| 20 | 13 | for(int i = 0; i < 0x10000; i++) |
| 21 | 14 | { |
| r14423 | r14424 | |
| 28 | 21 | } |
| 29 | 22 | } |
| 30 | 23 | |
| 31 | | void TexturePipeT::Mask(INT32* S, INT32* T, INT32 num) |
| 24 | void N64TexturePipeT::Mask(INT32* S, INT32* T, INT32 num, const rdp_poly_state& object) |
| 32 | 25 | { |
| 33 | | Tile* tile = m_rdp->GetTiles(); |
| 26 | const N64Tile* tile = object.m_tiles; |
| 34 | 27 | |
| 35 | 28 | if (tile[num].mask_s) |
| 36 | 29 | { |
| r14423 | r14424 | |
| 55 | 48 | } |
| 56 | 49 | } |
| 57 | 50 | |
| 58 | | void TexturePipeT::MaskCoupled(INT32* S, INT32* S1, INT32* T, INT32* T1, INT32 num) |
| 51 | void N64TexturePipeT::MaskCoupled(INT32* S, INT32* S1, INT32* T, INT32* T1, INT32 num, const rdp_poly_state& object) |
| 59 | 52 | { |
| 60 | | Tile* tile = m_rdp->GetTiles(); |
| 53 | const N64Tile* tile = object.m_tiles; |
| 61 | 54 | |
| 62 | 55 | if (tile[num].mask_s) |
| 63 | 56 | { |
| r14423 | r14424 | |
| 102 | 95 | } |
| 103 | 96 | } |
| 104 | 97 | |
| 105 | | void TexturePipeT::ShiftCycle(INT32* S, INT32* T, INT32* maxs, INT32* maxt, UINT32 num) |
| 98 | void N64TexturePipeT::ShiftCycle(INT32* S, INT32* T, INT32* maxs, INT32* maxt, UINT32 num, const rdp_poly_state& object) |
| 106 | 99 | { |
| 107 | | Tile* tile = m_rdp->GetTiles(); |
| 100 | const N64Tile* tile = object.m_tiles; |
| 108 | 101 | *S = SIGN16(*S); |
| 109 | 102 | *T = SIGN16(*T); |
| 110 | 103 | if (tile[num].shift_s < 11) |
| r14423 | r14424 | |
| 130 | 123 | *maxt = ((*T >> 3) >= tile[num].th); |
| 131 | 124 | } |
| 132 | 125 | |
| 133 | | void TexturePipeT::ShiftCopy(INT32* S, INT32* T, UINT32 num) |
| 126 | void N64TexturePipeT::ShiftCopy(INT32* S, INT32* T, UINT32 num, const rdp_poly_state& object) |
| 134 | 127 | { |
| 135 | | Tile* tile = m_rdp->GetTiles(); |
| 128 | const N64Tile* tile = object.m_tiles; |
| 136 | 129 | *S = SIGN16(*S); |
| 137 | 130 | *T = SIGN16(*T); |
| 138 | 131 | if (tile[num].shift_s < 11)//?-? tcu_tile |
| r14423 | r14424 | |
| 155 | 148 | *T = SIGN16(*T); |
| 156 | 149 | } |
| 157 | 150 | |
| 158 | | void TexturePipeT::ClampCycle(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, INT32 num) |
| 151 | void N64TexturePipeT::ClampCycle(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, INT32 num, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 159 | 152 | { |
| 160 | | Tile* tile = m_rdp->GetTiles(); |
| 153 | const N64Tile* tile = object.m_tiles; |
| 161 | 154 | int dos = tile[num].cs || !tile[num].mask_s; |
| 162 | 155 | int dot = tile[num].ct || !tile[num].mask_t; |
| 163 | 156 | |
| r14423 | r14424 | |
| 170 | 163 | } |
| 171 | 164 | else if (maxs) |
| 172 | 165 | { |
| 173 | | *S = m_clamp_s_diff[num]; |
| 166 | *S = userdata->m_clamp_s_diff[num]; |
| 174 | 167 | *SFRAC = 0; |
| 175 | 168 | } |
| 176 | 169 | else |
| r14423 | r14424 | |
| 192 | 185 | } |
| 193 | 186 | else if (maxt) |
| 194 | 187 | { |
| 195 | | *T = m_clamp_t_diff[num]; |
| 188 | *T = userdata->m_clamp_t_diff[num]; |
| 196 | 189 | *TFRAC = 0; |
| 197 | 190 | } |
| 198 | 191 | else |
| r14423 | r14424 | |
| 206 | 199 | } |
| 207 | 200 | } |
| 208 | 201 | |
| 209 | | void TexturePipeT::ClampCycleLight(INT32* S, INT32* T, bool maxs, bool maxt, INT32 num) |
| 202 | void N64TexturePipeT::ClampCycleLight(INT32* S, INT32* T, bool maxs, bool maxt, INT32 num, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 210 | 203 | { |
| 211 | | Tile* tile = m_rdp->GetTiles(); |
| 204 | const N64Tile* tile = object.m_tiles; |
| 212 | 205 | int dos = tile[num].cs || !tile[num].mask_s; |
| 213 | 206 | int dot = tile[num].ct || !tile[num].mask_t; |
| 214 | 207 | |
| r14423 | r14424 | |
| 220 | 213 | } |
| 221 | 214 | else if (maxs) |
| 222 | 215 | { |
| 223 | | *S = m_clamp_s_diff[num]; |
| 216 | *S = userdata->m_clamp_s_diff[num]; |
| 224 | 217 | } |
| 225 | 218 | else |
| 226 | 219 | { |
| r14423 | r14424 | |
| 240 | 233 | } |
| 241 | 234 | else if (maxt) |
| 242 | 235 | { |
| 243 | | *T = m_clamp_t_diff[num]; |
| 236 | *T = userdata->m_clamp_t_diff[num]; |
| 244 | 237 | } |
| 245 | 238 | else |
| 246 | 239 | { |
| r14423 | r14424 | |
| 253 | 246 | } |
| 254 | 247 | } |
| 255 | 248 | |
| 256 | | void TexturePipeT::Cycle(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle) |
| 249 | void N64TexturePipeT::Cycle(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 257 | 250 | { |
| 258 | | Tile* tile = m_rdp->GetTiles(); |
| 251 | const N64Tile* tile = object.m_tiles; |
| 259 | 252 | |
| 260 | 253 | #define TRELATIVE(x, y) ((((x) >> 3) - (y)) << 3) | (x & 7); |
| 261 | | INT32 bilerp = cycle ? m_rdp->OtherModes.bi_lerp1 : m_rdp->OtherModes.bi_lerp0; |
| 262 | | int convert = m_rdp->OtherModes.convert_one && cycle; |
| 254 | INT32 bilerp = cycle ? object.OtherModes.bi_lerp1 : object.OtherModes.bi_lerp0; |
| 255 | int convert = object.OtherModes.convert_one && cycle; |
| 263 | 256 | Color t0; |
| 264 | 257 | Color t1; |
| 265 | 258 | Color t2; |
| 266 | 259 | Color t3; |
| 267 | | if (m_rdp->OtherModes.sample_type) |
| 260 | if (object.OtherModes.sample_type) |
| 268 | 261 | { |
| 269 | 262 | int sss1, sst1, sss2, sst2; |
| 270 | 263 | |
| r14423 | r14424 | |
| 278 | 271 | INT32 maxs; |
| 279 | 272 | INT32 maxt; |
| 280 | 273 | |
| 281 | | ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum); |
| 274 | ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum, object); |
| 282 | 275 | |
| 283 | 276 | sss1 = TRELATIVE(sss1, tile[tilenum].sl); |
| 284 | 277 | sst1 = TRELATIVE(sst1, tile[tilenum].tl); |
| r14423 | r14424 | |
| 286 | 279 | INT32 sfrac = sss1 & 0x1f; |
| 287 | 280 | INT32 tfrac = sst1 & 0x1f; |
| 288 | 281 | |
| 289 | | ClampCycle(&sss1, &sst1, &sfrac, &tfrac, maxs, maxt, tilenum); |
| 282 | ClampCycle(&sss1, &sst1, &sfrac, &tfrac, maxs, maxt, tilenum, userdata, object); |
| 290 | 283 | |
| 291 | 284 | sss2 = sss1 + 1; |
| 292 | 285 | sst2 = sst1 + 1; |
| 293 | 286 | |
| 294 | | MaskCoupled(&sss1, &sss2, &sst1, &sst2, tilenum); |
| 287 | MaskCoupled(&sss1, &sss2, &sst1, &sst2, tilenum, object); |
| 295 | 288 | |
| 296 | 289 | bool upper = ((sfrac + tfrac) >= 0x20); |
| 297 | 290 | |
| r14423 | r14424 | |
| 301 | 294 | invtf = 0x20 - tfrac; |
| 302 | 295 | } |
| 303 | 296 | |
| 304 | | center = (sfrac == 0x10) && (tfrac == 0x10) && m_rdp->OtherModes.mid_texel; |
| 297 | center = (sfrac == 0x10) && (tfrac == 0x10) && object.OtherModes.mid_texel; |
| 305 | 298 | |
| 306 | 299 | invsf <<= 3; |
| 307 | 300 | invtf <<= 3; |
| 308 | 301 | sfrac <<= 3; |
| 309 | 302 | tfrac <<= 3; |
| 310 | 303 | |
| 311 | | t0.c = Fetch(sss1, sst1, tilenum); |
| 304 | t0.c = Fetch(sss1, sst1, tilenum, object, userdata); |
| 312 | 305 | |
| 313 | 306 | if (bilerp) |
| 314 | 307 | { |
| 315 | | t1.c = Fetch(sss2, sst1, tilenum); |
| 316 | | t2.c = Fetch(sss1, sst2, tilenum); |
| 317 | | t3.c = Fetch(sss2, sst2, tilenum); |
| 308 | t1.c = Fetch(sss2, sst1, tilenum, object, userdata); |
| 309 | t2.c = Fetch(sss1, sst2, tilenum, object, userdata); |
| 310 | t3.c = Fetch(sss2, sst2, tilenum, object, userdata); |
| 318 | 311 | if (!center) |
| 319 | 312 | { |
| 320 | 313 | if (upper) |
| r14423 | r14424 | |
| 336 | 329 | TEX->i.b &= 0x1ff; |
| 337 | 330 | TEX->i.a &= 0x1ff; |
| 338 | 331 | } |
| 339 | | else//tf.c,24 |
| 332 | else |
| 340 | 333 | { |
| 341 | 334 | TEX->i.r = (t0.i.r + t1.i.r + t2.i.r + t3.i.r) >> 2; |
| 342 | 335 | TEX->i.g = (t0.i.g + t1.i.g + t2.i.g + t3.i.g) >> 2; |
| r14423 | r14424 | |
| 377 | 370 | INT32 maxs; |
| 378 | 371 | INT32 maxt; |
| 379 | 372 | |
| 380 | | ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum); |
| 373 | ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum, object); |
| 381 | 374 | sss1 = TRELATIVE(sss1, tile[tilenum].sl); |
| 382 | 375 | sst1 = TRELATIVE(sst1, tile[tilenum].tl); |
| 383 | 376 | |
| 384 | | ClampCycleLight(&sss1, &sst1, maxs, maxt, tilenum); |
| 377 | ClampCycleLight(&sss1, &sst1, maxs, maxt, tilenum, userdata, object); |
| 385 | 378 | |
| 386 | | Mask(&sss1, &sst1, tilenum); |
| 379 | Mask(&sss1, &sst1, tilenum, object); |
| 387 | 380 | |
| 388 | | t0.c = Fetch(sss1, sst1, tilenum); |
| 381 | t0.c = Fetch(sss1, sst1, tilenum, object, userdata); |
| 389 | 382 | if (bilerp) |
| 390 | 383 | { |
| 391 | 384 | *TEX = t0; |
| r14423 | r14424 | |
| 419 | 412 | } |
| 420 | 413 | } |
| 421 | 414 | |
| 422 | | void TexturePipeT::Copy(Color* TEX, INT32 SSS, INT32 SST, UINT32 tilenum) |
| 415 | void N64TexturePipeT::Copy(Color* TEX, INT32 SSS, INT32 SST, UINT32 tilenum, const rdp_poly_state& object, rdp_span_aux *userdata) |
| 423 | 416 | { |
| 424 | | Tile* tile = m_rdp->GetTiles(); |
| 417 | const N64Tile* tile = object.m_tiles; |
| 425 | 418 | INT32 sss1 = SSS; |
| 426 | 419 | INT32 sst1 = SST; |
| 427 | | ShiftCopy(&sss1, &sst1, tilenum); |
| 420 | ShiftCopy(&sss1, &sst1, tilenum, object); |
| 428 | 421 | sss1 = TRELATIVE(sss1, tile[tilenum].sl); |
| 429 | 422 | sst1 = TRELATIVE(sst1, tile[tilenum].tl); |
| 430 | 423 | sss1 = (SIGN17(sss1) >> 5) & 0x1fff; |
| 431 | 424 | sst1 = (SIGN17(sst1) >> 5) & 0x1fff; |
| 432 | | Mask(&sss1, &sst1, tilenum); |
| 433 | | TEX->c = Fetch(sss1, sst1, tilenum); |
| 425 | Mask(&sss1, &sst1, tilenum, object); |
| 426 | TEX->c = Fetch(sss1, sst1, tilenum, object, userdata); |
| 434 | 427 | } |
| 435 | 428 | |
| 436 | | void TexturePipeT::LOD1Cycle(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc) |
| 429 | void N64TexturePipeT::LOD1Cycle(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 437 | 430 | { |
| 438 | 431 | INT32 nextsw = (w + dwinc) >> 16; |
| 439 | 432 | INT32 nexts = (s + dsinc) >> 16; |
| 440 | 433 | INT32 nextt = (t + dtinc) >> 16; |
| 441 | 434 | |
| 442 | | if (m_rdp->OtherModes.persp_tex_en) |
| 435 | if (object.OtherModes.persp_tex_en) |
| 443 | 436 | { |
| 444 | 437 | m_rdp->TCDiv(nexts, nextt, nextsw, &nexts, &nextt); |
| 445 | 438 | } |
| r14423 | r14424 | |
| 448 | 441 | m_rdp->TCDivNoPersp(nexts, nextt, nextsw, &nexts, &nextt); |
| 449 | 442 | } |
| 450 | 443 | |
| 451 | | m_start_span = false; |
| 452 | | m_precomp_s = nexts; |
| 453 | | m_precomp_t = nextt; |
| 444 | userdata->m_start_span = false; |
| 445 | userdata->m_precomp_s = nexts; |
| 446 | userdata->m_precomp_t = nextt; |
| 454 | 447 | |
| 455 | 448 | int tempanded; |
| 456 | 449 | if (*sss & 0x40000) |
| r14423 | r14424 | |
| 504 | 497 | } |
| 505 | 498 | } |
| 506 | 499 | |
| 507 | | void TexturePipeT::LOD2Cycle(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, INT32* t2) |
| 500 | void N64TexturePipeT::LOD2Cycle(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, INT32* t2, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 508 | 501 | { |
| 509 | 502 | INT32 nextsw = (w + dwinc) >> 16; |
| 510 | 503 | INT32 nexts = (s + dsinc) >> 16; |
| 511 | 504 | INT32 nextt = (t + dtinc) >> 16; |
| 512 | 505 | |
| 513 | | if (m_rdp->OtherModes.persp_tex_en) |
| 506 | if (object.OtherModes.persp_tex_en) |
| 514 | 507 | { |
| 515 | 508 | m_rdp->TCDiv(nexts, nextt, nextsw, &nexts, &nextt); |
| 516 | 509 | } |
| r14423 | r14424 | |
| 519 | 512 | m_rdp->TCDivNoPersp(nexts, nextt, nextsw, &nexts, &nextt); |
| 520 | 513 | } |
| 521 | 514 | |
| 522 | | m_start_span = false; |
| 523 | | m_precomp_s = nexts; |
| 524 | | m_precomp_t = nextt; |
| 515 | userdata->m_start_span = false; |
| 516 | userdata->m_precomp_s = nexts; |
| 517 | userdata->m_precomp_t = nextt; |
| 525 | 518 | |
| 526 | 519 | INT32 lodclamp = (((*sst & 0x60000) > 0) | ((nextt & 0x60000) > 0)) || (((*sss & 0x60000) > 0) | ((nexts & 0x60000) > 0)); |
| 527 | 520 | |
| r14423 | r14424 | |
| 593 | 586 | { |
| 594 | 587 | lod = 0x7fff; |
| 595 | 588 | } |
| 596 | | else if (lod < m_rdp->MiscState.MinLevel) |
| 589 | else if (lod < object.MiscState.MinLevel) |
| 597 | 590 | { |
| 598 | | lod = m_rdp->MiscState.MinLevel; |
| 591 | lod = object.MiscState.MinLevel; |
| 599 | 592 | } |
| 600 | 593 | |
| 601 | 594 | bool magnify = (lod < 32); |
| 602 | 595 | INT32 l_tile = m_rdp->GetLog2((lod >> 5) & 0xff); |
| 603 | | bool distant = ((lod & 0x6000) || (l_tile >= m_rdp->MiscState.MaxLevel)); |
| 596 | bool distant = ((lod & 0x6000) || (l_tile >= object.MiscState.MaxLevel)); |
| 604 | 597 | |
| 605 | | m_rdp->LODFraction = ((lod << 3) >> l_tile) & 0xff; |
| 598 | userdata->LODFraction = ((lod << 3) >> l_tile) & 0xff; |
| 606 | 599 | |
| 607 | | if(!m_rdp->OtherModes.sharpen_tex_en && !m_rdp->OtherModes.detail_tex_en) |
| 600 | if(!object.OtherModes.sharpen_tex_en && !object.OtherModes.detail_tex_en) |
| 608 | 601 | { |
| 609 | 602 | if (distant) |
| 610 | 603 | { |
| 611 | | m_rdp->LODFraction = 0xff; |
| 604 | userdata->LODFraction = 0xff; |
| 612 | 605 | } |
| 613 | 606 | else if (magnify) |
| 614 | 607 | { |
| 615 | | m_rdp->LODFraction = 0; |
| 608 | userdata->LODFraction = 0; |
| 616 | 609 | } |
| 617 | 610 | } |
| 618 | 611 | |
| 619 | | if(m_rdp->OtherModes.sharpen_tex_en && magnify) |
| 612 | if(object.OtherModes.sharpen_tex_en && magnify) |
| 620 | 613 | { |
| 621 | | m_rdp->LODFraction = m_rdp->LODFraction | 0x100; |
| 614 | userdata->LODFraction = userdata->LODFraction | 0x100; |
| 622 | 615 | } |
| 623 | 616 | |
| 624 | | if (m_rdp->OtherModes.tex_lod_en) |
| 617 | if (object.OtherModes.tex_lod_en) |
| 625 | 618 | { |
| 626 | 619 | if (distant) |
| 627 | 620 | { |
| 628 | | l_tile = m_rdp->MiscState.MaxLevel; |
| 621 | l_tile = object.MiscState.MaxLevel; |
| 629 | 622 | } |
| 630 | | if (!m_rdp->OtherModes.detail_tex_en) |
| 623 | if (!object.OtherModes.detail_tex_en) |
| 631 | 624 | { |
| 632 | 625 | *t1 = (prim_tile + l_tile) & 7; |
| 633 | | if (!(distant || (!m_rdp->OtherModes.sharpen_tex_en && magnify))) |
| 626 | if (!(distant || (!object.OtherModes.sharpen_tex_en && magnify))) |
| 634 | 627 | { |
| 635 | 628 | *t2 = (*t1 + 1) & 7; |
| 636 | 629 | } |
| r14423 | r14424 | |
| 662 | 655 | } |
| 663 | 656 | } |
| 664 | 657 | |
| 665 | | void TexturePipeT::LOD2CycleLimited(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1) |
| 658 | void N64TexturePipeT::LOD2CycleLimited(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, const rdp_poly_state& object) |
| 666 | 659 | { |
| 667 | 660 | INT32 nextsw = (w + dwinc) >> 16; |
| 668 | 661 | INT32 nexts = (s + dsinc) >> 16; |
| 669 | 662 | INT32 nextt = (t + dtinc) >> 16; |
| 670 | 663 | |
| 671 | | if (m_rdp->OtherModes.persp_tex_en) |
| 664 | if (object.OtherModes.persp_tex_en) |
| 672 | 665 | { |
| 673 | 666 | m_rdp->TCDiv(nexts, nextt, nextsw, &nexts, &nextt); |
| 674 | 667 | } |
| r14423 | r14424 | |
| 747 | 740 | { |
| 748 | 741 | lod = 0x7fff; |
| 749 | 742 | } |
| 750 | | else if (lod < m_rdp->MiscState.MinLevel) |
| 743 | else if (lod < object.MiscState.MinLevel) |
| 751 | 744 | { |
| 752 | | lod = m_rdp->MiscState.MinLevel; |
| 745 | lod = object.MiscState.MinLevel; |
| 753 | 746 | } |
| 754 | 747 | |
| 755 | 748 | bool magnify = (lod < 32); |
| 756 | 749 | INT32 l_tile = m_rdp->GetLog2((lod >> 5) & 0xff); |
| 757 | | bool distant = (lod & 0x6000) || (l_tile >= m_rdp->MiscState.MaxLevel); |
| 750 | bool distant = (lod & 0x6000) || (l_tile >= object.MiscState.MaxLevel); |
| 758 | 751 | |
| 759 | | if (m_rdp->OtherModes.tex_lod_en) |
| 752 | if (object.OtherModes.tex_lod_en) |
| 760 | 753 | { |
| 761 | 754 | if (distant) |
| 762 | 755 | { |
| 763 | | l_tile = m_rdp->MiscState.MaxLevel; |
| 756 | l_tile = object.MiscState.MaxLevel; |
| 764 | 757 | } |
| 765 | | if (!m_rdp->OtherModes.detail_tex_en) |
| 758 | if (!object.OtherModes.detail_tex_en) |
| 766 | 759 | { |
| 767 | 760 | *t1 = (prim_tile + l_tile) & 7; |
| 768 | 761 | } |
| r14423 | r14424 | |
| 781 | 774 | } |
| 782 | 775 | } |
| 783 | 776 | |
| 784 | | void TexturePipeT::CalculateClampDiffs(UINT32 prim_tile) |
| 777 | void N64TexturePipeT::CalculateClampDiffs(UINT32 prim_tile, rdp_span_aux *userdata, const rdp_poly_state& object) |
| 785 | 778 | { |
| 786 | | Tile* tile = m_rdp->GetTiles(); |
| 787 | | if (m_rdp->OtherModes.cycle_type == CYCLE_TYPE_2) |
| 779 | const N64Tile* tile = object.m_tiles; |
| 780 | if (object.OtherModes.cycle_type == CYCLE_TYPE_2) |
| 788 | 781 | { |
| 789 | | if (m_rdp->OtherModes.tex_lod_en) |
| 782 | if (object.OtherModes.tex_lod_en) |
| 790 | 783 | { |
| 791 | 784 | int start = 0; |
| 792 | 785 | int end = 7; |
| 793 | 786 | for (; start <= end; start++) |
| 794 | 787 | { |
| 795 | | m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2); |
| 796 | | m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2); |
| 788 | userdata->m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2); |
| 789 | userdata->m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2); |
| 797 | 790 | } |
| 798 | 791 | } |
| 799 | 792 | else |
| 800 | 793 | { |
| 801 | 794 | int start = prim_tile; |
| 802 | 795 | int end = (prim_tile + 1) & 7; |
| 803 | | m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2); |
| 804 | | m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2); |
| 805 | | m_clamp_s_diff[end] = (tile[end].sh >> 2) - (tile[end].sl >> 2); |
| 806 | | m_clamp_t_diff[end] = (tile[end].th >> 2) - (tile[end].tl >> 2); |
| 796 | userdata->m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2); |
| 797 | userdata->m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2); |
| 798 | userdata->m_clamp_s_diff[end] = (tile[end].sh >> 2) - (tile[end].sl >> 2); |
| 799 | userdata->m_clamp_t_diff[end] = (tile[end].th >> 2) - (tile[end].tl >> 2); |
| 807 | 800 | } |
| 808 | 801 | } |
| 809 | 802 | else//1-cycle or copy |
| 810 | 803 | { |
| 811 | | m_clamp_s_diff[prim_tile] = (tile[prim_tile].sh >> 2) - (tile[prim_tile].sl >> 2); |
| 812 | | m_clamp_t_diff[prim_tile] = (tile[prim_tile].th >> 2) - (tile[prim_tile].tl >> 2); |
| 804 | userdata->m_clamp_s_diff[prim_tile] = (tile[prim_tile].sh >> 2) - (tile[prim_tile].sl >> 2); |
| 805 | userdata->m_clamp_t_diff[prim_tile] = (tile[prim_tile].th >> 2) - (tile[prim_tile].tl >> 2); |
| 813 | 806 | } |
| 814 | 807 | } |
| 815 | 808 | |
| r14423 | r14424 | |
| 818 | 811 | static INT32 sTexAddrSwap16[2] = { WORD_ADDR_XOR, WORD_XOR_DWORD_SWAP }; |
| 819 | 812 | static INT32 sTexAddrSwap8[2] = { BYTE_ADDR_XOR, BYTE_XOR_DWORD_SWAP }; |
| 820 | 813 | |
| 821 | | UINT32 TexturePipeT::_FetchRGBA_16_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 814 | UINT32 N64TexturePipeT::_FetchRGBA_16_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 822 | 815 | { |
| 823 | 816 | int taddr = (tbase << 2) + s; |
| 824 | 817 | taddr ^= sTexAddrSwap16[t & 1]; |
| 825 | 818 | taddr &= 0x7ff; |
| 826 | 819 | |
| 827 | | UINT16 c = m_rdp->GetTMEM16()[taddr]; |
| 828 | | c = m_rdp->GetTLUT()[(c >> 8) << 2]; |
| 820 | UINT16 c = ((UINT16*)userdata->m_tmem)[taddr]; |
| 821 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; |
| 829 | 822 | |
| 830 | 823 | #if USE_64K_LUT |
| 831 | 824 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 839 | 832 | #endif |
| 840 | 833 | } |
| 841 | 834 | |
| 842 | | UINT32 TexturePipeT::_FetchRGBA_16_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 835 | UINT32 N64TexturePipeT::_FetchRGBA_16_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 843 | 836 | { |
| 844 | 837 | int taddr = (tbase << 2) + s; |
| 845 | 838 | taddr ^= sTexAddrSwap16[t & 1]; |
| 846 | 839 | taddr &= 0x7ff; |
| 847 | 840 | |
| 848 | | UINT16 c = m_rdp->GetTMEM16()[taddr]; |
| 849 | | c = m_rdp->GetTLUT()[(c >> 8) << 2]; |
| 841 | UINT16 c = ((UINT16*)userdata->m_tmem)[taddr]; |
| 842 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; |
| 850 | 843 | |
| 851 | 844 | Color color; |
| 852 | 845 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 854 | 847 | return color.c; |
| 855 | 848 | } |
| 856 | 849 | |
| 857 | | UINT32 TexturePipeT::_FetchRGBA_16_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 850 | UINT32 N64TexturePipeT::_FetchRGBA_16_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 858 | 851 | { |
| 859 | 852 | int taddr = (tbase << 2) + s; |
| 860 | 853 | taddr ^= sTexAddrSwap16[t & 1]; |
| 861 | 854 | taddr &= 0x7ff; |
| 862 | 855 | |
| 863 | 856 | #if USE_64K_LUT |
| 864 | | return Expand16To32Table[m_rdp->GetTMEM16()[taddr]]; |
| 857 | return Expand16To32Table[((UINT16*)userdata->m_tmem)[taddr]]; |
| 865 | 858 | #else |
| 866 | | UINT16 c = m_rdp->GetTMEM16()[taddr]; |
| 859 | UINT16 c = ((UINT16*)userdata->m_tmem)[taddr]; |
| 867 | 860 | Color color; |
| 868 | 861 | color.i.r = GET_HI_RGBA16_TMEM(c); |
| 869 | 862 | color.i.g = GET_MED_RGBA16_TMEM(c); |
| r14423 | r14424 | |
| 873 | 866 | #endif |
| 874 | 867 | } |
| 875 | 868 | |
| 876 | | UINT32 TexturePipeT::_FetchRGBA_32_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 869 | UINT32 N64TexturePipeT::_FetchRGBA_32_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 877 | 870 | { |
| 878 | | UINT32 *tc = m_rdp->GetTMEM32(); |
| 871 | UINT32 *tc = ((UINT32*)userdata->m_tmem); |
| 879 | 872 | int taddr = (tbase << 2) + s; |
| 880 | 873 | taddr ^= sTexAddrSwap16[t & 1]; |
| 881 | 874 | |
| 882 | 875 | taddr &= 0x3ff; |
| 883 | 876 | UINT32 c = tc[taddr]; |
| 884 | | c = m_rdp->GetTLUT()[(c >> 24) << 2]; |
| 877 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 24) << 2]; |
| 885 | 878 | |
| 886 | 879 | #if USE_64K_LUT |
| 887 | 880 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 895 | 888 | #endif |
| 896 | 889 | } |
| 897 | 890 | |
| 898 | | UINT32 TexturePipeT::_FetchRGBA_32_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 891 | UINT32 N64TexturePipeT::_FetchRGBA_32_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 899 | 892 | { |
| 900 | | UINT32 *tc = m_rdp->GetTMEM32(); |
| 893 | UINT32 *tc = ((UINT32*)userdata->m_tmem); |
| 901 | 894 | int taddr = (tbase << 2) + s; |
| 902 | 895 | taddr ^= sTexAddrSwap16[t & 1]; |
| 903 | 896 | |
| 904 | 897 | taddr &= 0x3ff; |
| 905 | 898 | UINT32 c = tc[taddr]; |
| 906 | | c = m_rdp->GetTLUT()[(c >> 24) << 2]; |
| 899 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 24) << 2]; |
| 907 | 900 | |
| 908 | 901 | Color color; |
| 909 | 902 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 912 | 905 | return color.c; |
| 913 | 906 | } |
| 914 | 907 | |
| 915 | | UINT32 TexturePipeT::_FetchRGBA_32_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 908 | UINT32 N64TexturePipeT::_FetchRGBA_32_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 916 | 909 | { |
| 917 | 910 | int taddr = (tbase << 2) + s; |
| 918 | 911 | taddr ^= sTexAddrSwap16[t & 1]; |
| 919 | 912 | |
| 920 | 913 | taddr &= 0x3ff; |
| 921 | 914 | |
| 922 | | UINT32 c = m_rdp->GetTMEM16()[taddr]; |
| 915 | UINT32 c = ((UINT16*)userdata->m_tmem)[taddr]; |
| 923 | 916 | Color color; |
| 924 | 917 | color.i.r = (c >> 8) & 0xff; |
| 925 | 918 | color.i.g = c & 0xff; |
| 926 | | c = m_rdp->GetTMEM16()[taddr | 0x400]; |
| 919 | c = ((UINT16*)userdata->m_tmem)[taddr | 0x400]; |
| 927 | 920 | color.i.b = (c >> 8) & 0xff; |
| 928 | 921 | color.i.a = c & 0xff; |
| 929 | 922 | |
| 930 | 923 | return color.c; |
| 931 | 924 | } |
| 932 | 925 | |
| 933 | | UINT32 TexturePipeT::_FetchNOP(INT32 s, INT32 t, INT32 tbase, INT32 tpal) { return 0; } |
| 926 | UINT32 N64TexturePipeT::_FetchNOP(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) { return 0; } |
| 934 | 927 | |
| 935 | | UINT32 TexturePipeT::_FetchYUV(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 928 | UINT32 N64TexturePipeT::_FetchYUV(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 936 | 929 | { |
| 937 | | UINT16 *tc = m_rdp->GetTMEM16(); |
| 930 | UINT16 *tc = ((UINT16*)userdata->m_tmem); |
| 938 | 931 | |
| 939 | 932 | int taddr = (tbase << 3) + s; |
| 940 | 933 | int taddrlow = taddr >> 1; |
| r14423 | r14424 | |
| 947 | 940 | |
| 948 | 941 | UINT16 c = tc[taddrlow]; |
| 949 | 942 | |
| 950 | | INT32 y = m_rdp->GetTMEM()[taddr | 0x800]; |
| 943 | INT32 y = userdata->m_tmem[taddr | 0x800]; |
| 951 | 944 | INT32 u = c >> 8; |
| 952 | 945 | INT32 v = c & 0xff; |
| 953 | 946 | |
| r14423 | r14424 | |
| 964 | 957 | return color.c; |
| 965 | 958 | } |
| 966 | 959 | |
| 967 | | UINT32 TexturePipeT::_FetchCI_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 960 | UINT32 N64TexturePipeT::_FetchCI_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 968 | 961 | { |
| 969 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 962 | UINT8 *tc = userdata->m_tmem; |
| 970 | 963 | int taddr = ((tbase << 4) + s) >> 1; |
| 971 | 964 | taddr ^= sTexAddrSwap8[t & 1]; |
| 972 | 965 | taddr &= 0xfff; |
| 973 | 966 | |
| 974 | 967 | taddr &= 0x7ff; |
| 975 | 968 | UINT8 p = (s & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); |
| 976 | | UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2]; |
| 969 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; |
| 977 | 970 | |
| 978 | 971 | #if USE_64K_LUT |
| 979 | 972 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 987 | 980 | #endif |
| 988 | 981 | } |
| 989 | 982 | |
| 990 | | UINT32 TexturePipeT::_FetchCI_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 983 | UINT32 N64TexturePipeT::_FetchCI_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 991 | 984 | { |
| 992 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 985 | UINT8 *tc = userdata->m_tmem; |
| 993 | 986 | int taddr = ((tbase << 4) + s) >> 1; |
| 994 | 987 | taddr ^= sTexAddrSwap8[t & 1]; |
| 995 | 988 | taddr &= 0xfff; |
| 996 | 989 | |
| 997 | 990 | taddr &= 0x7ff; |
| 998 | 991 | UINT8 p = (s & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); |
| 999 | | UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2]; |
| 992 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; |
| 1000 | 993 | |
| 1001 | 994 | Color color; |
| 1002 | 995 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 1005 | 998 | return color.c; |
| 1006 | 999 | } |
| 1007 | 1000 | |
| 1008 | | UINT32 TexturePipeT::_FetchCI_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1001 | UINT32 N64TexturePipeT::_FetchCI_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1009 | 1002 | { |
| 1010 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1003 | UINT8 *tc = userdata->m_tmem; |
| 1011 | 1004 | int taddr = ((tbase << 4) + s) >> 1; |
| 1012 | 1005 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1013 | 1006 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1021 | 1014 | return color.c; |
| 1022 | 1015 | } |
| 1023 | 1016 | |
| 1024 | | UINT32 TexturePipeT::_FetchCI_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1017 | UINT32 N64TexturePipeT::_FetchCI_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1025 | 1018 | { |
| 1026 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1019 | UINT8 *tc = userdata->m_tmem; |
| 1027 | 1020 | int taddr = (tbase << 3) + s; |
| 1028 | 1021 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1029 | 1022 | taddr &= 0x7ff; |
| 1030 | 1023 | |
| 1031 | 1024 | UINT8 p = tc[taddr]; |
| 1032 | | UINT16 c = m_rdp->GetTLUT()[p << 2]; |
| 1025 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[p << 2]; |
| 1033 | 1026 | |
| 1034 | 1027 | #if USE_64K_LUT |
| 1035 | 1028 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 1043 | 1036 | #endif |
| 1044 | 1037 | } |
| 1045 | 1038 | |
| 1046 | | UINT32 TexturePipeT::_FetchCI_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1039 | UINT32 N64TexturePipeT::_FetchCI_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1047 | 1040 | { |
| 1048 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1041 | UINT8 *tc = userdata->m_tmem; |
| 1049 | 1042 | int taddr = (tbase << 3) + s; |
| 1050 | 1043 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1051 | 1044 | taddr &= 0x7ff; |
| 1052 | 1045 | |
| 1053 | 1046 | UINT8 p = tc[taddr]; |
| 1054 | | UINT16 c = m_rdp->GetTLUT()[p << 2]; |
| 1047 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[p << 2]; |
| 1055 | 1048 | |
| 1056 | 1049 | Color color; |
| 1057 | 1050 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 1060 | 1053 | return color.c; |
| 1061 | 1054 | } |
| 1062 | 1055 | |
| 1063 | | UINT32 TexturePipeT::_FetchCI_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1056 | UINT32 N64TexturePipeT::_FetchCI_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1064 | 1057 | { |
| 1065 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1058 | UINT8 *tc = userdata->m_tmem; |
| 1066 | 1059 | int taddr = (tbase << 3) + s; |
| 1067 | 1060 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1068 | 1061 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1075 | 1068 | return color.c; |
| 1076 | 1069 | } |
| 1077 | 1070 | |
| 1078 | | UINT32 TexturePipeT::_FetchIA_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1071 | UINT32 N64TexturePipeT::_FetchIA_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1079 | 1072 | { |
| 1080 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1073 | UINT8 *tc = userdata->m_tmem; |
| 1081 | 1074 | int taddr = ((tbase << 4) + s) >> 1; |
| 1082 | 1075 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1083 | 1076 | taddr &= 0x7ff; |
| 1084 | 1077 | |
| 1085 | 1078 | UINT8 p = ((s) & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); |
| 1086 | | UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2]; |
| 1079 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; |
| 1087 | 1080 | |
| 1088 | 1081 | #if USE_64K_LUT |
| 1089 | 1082 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 1097 | 1090 | #endif |
| 1098 | 1091 | } |
| 1099 | 1092 | |
| 1100 | | UINT32 TexturePipeT::_FetchIA_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1093 | UINT32 N64TexturePipeT::_FetchIA_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1101 | 1094 | { |
| 1102 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1095 | UINT8 *tc = userdata->m_tmem; |
| 1103 | 1096 | int taddr = ((tbase << 4) + s) >> 1; |
| 1104 | 1097 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1105 | 1098 | taddr &= 0x7ff; |
| 1106 | 1099 | |
| 1107 | 1100 | UINT8 p = ((s) & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); |
| 1108 | | UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2]; |
| 1101 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; |
| 1109 | 1102 | |
| 1110 | 1103 | Color color; |
| 1111 | 1104 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 1114 | 1107 | return color.c; |
| 1115 | 1108 | } |
| 1116 | 1109 | |
| 1117 | | UINT32 TexturePipeT::_FetchIA_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1110 | UINT32 N64TexturePipeT::_FetchIA_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1118 | 1111 | { |
| 1119 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1112 | UINT8 *tc = userdata->m_tmem; |
| 1120 | 1113 | int taddr = ((tbase << 4) + s) >> 1; |
| 1121 | 1114 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1122 | 1115 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1134 | 1127 | return color.c; |
| 1135 | 1128 | } |
| 1136 | 1129 | |
| 1137 | | UINT32 TexturePipeT::_FetchIA_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1130 | UINT32 N64TexturePipeT::_FetchIA_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1138 | 1131 | { |
| 1139 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1132 | UINT8 *tc = userdata->m_tmem; |
| 1140 | 1133 | int taddr = (tbase << 3) + s; |
| 1141 | 1134 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1142 | 1135 | taddr &= 0x7ff; |
| 1143 | 1136 | |
| 1144 | 1137 | UINT8 p = tc[taddr]; |
| 1145 | | UINT16 c = m_rdp->GetTLUT()[p << 2]; |
| 1138 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[p << 2]; |
| 1146 | 1139 | |
| 1147 | 1140 | #if USE_64K_LUT |
| 1148 | 1141 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 1156 | 1149 | #endif |
| 1157 | 1150 | } |
| 1158 | 1151 | |
| 1159 | | UINT32 TexturePipeT::_FetchIA_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1152 | UINT32 N64TexturePipeT::_FetchIA_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1160 | 1153 | { |
| 1161 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1154 | UINT8 *tc = userdata->m_tmem; |
| 1162 | 1155 | int taddr = (tbase << 3) + s; |
| 1163 | 1156 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1164 | 1157 | taddr &= 0x7ff; |
| 1165 | 1158 | |
| 1166 | 1159 | UINT8 p = tc[taddr]; |
| 1167 | | UINT16 c = m_rdp->GetTLUT()[p << 2]; |
| 1160 | UINT16 c = ((UINT16*)(userdata->m_tmem + 0x800))[p << 2]; |
| 1168 | 1161 | |
| 1169 | 1162 | Color color; |
| 1170 | 1163 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 1173 | 1166 | return color.c; |
| 1174 | 1167 | } |
| 1175 | 1168 | |
| 1176 | | UINT32 TexturePipeT::_FetchIA_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1169 | UINT32 N64TexturePipeT::_FetchIA_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1177 | 1170 | { |
| 1178 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1171 | UINT8 *tc = userdata->m_tmem; |
| 1179 | 1172 | int taddr = (tbase << 3) + s; |
| 1180 | 1173 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1181 | 1174 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1193 | 1186 | return color.c; |
| 1194 | 1187 | } |
| 1195 | 1188 | |
| 1196 | | UINT32 TexturePipeT::_FetchIA_16_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1189 | UINT32 N64TexturePipeT::_FetchIA_16_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1197 | 1190 | { |
| 1198 | | UINT16 *tc = m_rdp->GetTMEM16(); |
| 1191 | UINT16 *tc = ((UINT16*)userdata->m_tmem); |
| 1199 | 1192 | int taddr = (tbase << 2) + s; |
| 1200 | 1193 | taddr ^= sTexAddrSwap16[t & 1]; |
| 1201 | 1194 | taddr &= 0x3ff; |
| 1202 | 1195 | |
| 1203 | 1196 | UINT16 c = tc[taddr]; |
| 1204 | | c = m_rdp->GetTLUT()[(c >> 8) << 2]; |
| 1197 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; |
| 1205 | 1198 | |
| 1206 | 1199 | #if USE_64K_LUT |
| 1207 | 1200 | return Expand16To32Table[c]; |
| r14423 | r14424 | |
| 1215 | 1208 | #endif |
| 1216 | 1209 | } |
| 1217 | 1210 | |
| 1218 | | UINT32 TexturePipeT::_FetchIA_16_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1211 | UINT32 N64TexturePipeT::_FetchIA_16_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1219 | 1212 | { |
| 1220 | | UINT16 *tc = m_rdp->GetTMEM16(); |
| 1213 | UINT16 *tc = ((UINT16*)userdata->m_tmem); |
| 1221 | 1214 | int taddr = (tbase << 2) + s; |
| 1222 | 1215 | taddr ^= sTexAddrSwap16[t & 1]; |
| 1223 | 1216 | taddr &= 0x3ff; |
| 1224 | 1217 | |
| 1225 | 1218 | UINT16 c = tc[taddr]; |
| 1226 | | c = m_rdp->GetTLUT()[(c >> 8) << 2]; |
| 1219 | c = ((UINT16*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; |
| 1227 | 1220 | |
| 1228 | 1221 | Color color; |
| 1229 | 1222 | color.i.r = color.i.g = color.i.b = (c >> 8) & 0xff; |
| r14423 | r14424 | |
| 1232 | 1225 | return color.c; |
| 1233 | 1226 | } |
| 1234 | 1227 | |
| 1235 | | UINT32 TexturePipeT::_FetchIA_16_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1228 | UINT32 N64TexturePipeT::_FetchIA_16_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1236 | 1229 | { |
| 1237 | | UINT16 *tc = m_rdp->GetTMEM16(); |
| 1230 | UINT16 *tc = ((UINT16*)userdata->m_tmem); |
| 1238 | 1231 | int taddr = (tbase << 2) + s; |
| 1239 | 1232 | taddr ^= sTexAddrSwap16[t & 1]; |
| 1240 | 1233 | taddr &= 0x7ff; |
| r14423 | r14424 | |
| 1251 | 1244 | return color.c; |
| 1252 | 1245 | } |
| 1253 | 1246 | |
| 1254 | | UINT32 TexturePipeT::_FetchI_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1247 | UINT32 N64TexturePipeT::_FetchI_4_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1255 | 1248 | { |
| 1256 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1249 | UINT8 *tc = userdata->m_tmem; |
| 1257 | 1250 | int taddr = ((tbase << 4) + s) >> 1; |
| 1258 | 1251 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1259 | 1252 | taddr &= 0x7ff; |
| 1260 | 1253 | |
| 1261 | 1254 | UINT8 byteval = tc[taddr]; |
| 1262 | 1255 | UINT8 c = ((s & 1)) ? (byteval & 0xf) : ((byteval >> 4) & 0xf); |
| 1263 | | UINT16 k = m_rdp->GetTLUT()[((tpal << 4) | c) << 2]; |
| 1256 | UINT16 k = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | c) << 2]; |
| 1264 | 1257 | |
| 1265 | 1258 | #if USE_64K_LUT |
| 1266 | 1259 | return Expand16To32Table[k]; |
| r14423 | r14424 | |
| 1274 | 1267 | #endif |
| 1275 | 1268 | } |
| 1276 | 1269 | |
| 1277 | | UINT32 TexturePipeT::_FetchI_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1270 | UINT32 N64TexturePipeT::_FetchI_4_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1278 | 1271 | { |
| 1279 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1272 | UINT8 *tc = userdata->m_tmem; |
| 1280 | 1273 | int taddr = ((tbase << 4) + s) >> 1; |
| 1281 | 1274 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1282 | 1275 | taddr &= 0x7ff; |
| 1283 | 1276 | |
| 1284 | 1277 | UINT8 byteval = tc[taddr]; |
| 1285 | 1278 | UINT8 c = ((s & 1)) ? (byteval & 0xf) : ((byteval >> 4) & 0xf); |
| 1286 | | UINT16 k = m_rdp->GetTLUT()[((tpal << 4) | c) << 2]; |
| 1279 | UINT16 k = ((UINT16*)(userdata->m_tmem + 0x800))[((tpal << 4) | c) << 2]; |
| 1287 | 1280 | |
| 1288 | 1281 | Color color; |
| 1289 | 1282 | color.i.r = color.i.g = color.i.b = (k >> 8) & 0xff; |
| r14423 | r14424 | |
| 1292 | 1285 | return color.c; |
| 1293 | 1286 | } |
| 1294 | 1287 | |
| 1295 | | UINT32 TexturePipeT::_FetchI_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1288 | UINT32 N64TexturePipeT::_FetchI_4_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1296 | 1289 | { |
| 1297 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1290 | UINT8 *tc = userdata->m_tmem; |
| 1298 | 1291 | int taddr = ((tbase << 4) + s) >> 1; |
| 1299 | 1292 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1300 | 1293 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1312 | 1305 | return color.c; |
| 1313 | 1306 | } |
| 1314 | 1307 | |
| 1315 | | UINT32 TexturePipeT::_FetchI_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1308 | UINT32 N64TexturePipeT::_FetchI_8_TLUT0(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1316 | 1309 | { |
| 1317 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1310 | UINT8 *tc = userdata->m_tmem; |
| 1318 | 1311 | int taddr = (tbase << 3) + s; |
| 1319 | 1312 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1320 | 1313 | taddr &= 0x7ff; |
| 1321 | 1314 | |
| 1322 | 1315 | UINT8 c = tc[taddr]; |
| 1323 | | UINT16 k = m_rdp->GetTLUT()[c << 2]; |
| 1316 | UINT16 k = ((UINT16*)(userdata->m_tmem + 0x800))[c << 2]; |
| 1324 | 1317 | |
| 1325 | 1318 | #if USE_64K_LUT |
| 1326 | 1319 | return Expand16To32Table[k]; |
| r14423 | r14424 | |
| 1334 | 1327 | #endif |
| 1335 | 1328 | } |
| 1336 | 1329 | |
| 1337 | | UINT32 TexturePipeT::_FetchI_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1330 | UINT32 N64TexturePipeT::_FetchI_8_TLUT1(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1338 | 1331 | { |
| 1339 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1332 | UINT8 *tc = userdata->m_tmem; |
| 1340 | 1333 | int taddr = (tbase << 3) + s; |
| 1341 | 1334 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1342 | 1335 | taddr &= 0x7ff; |
| 1343 | 1336 | |
| 1344 | 1337 | UINT8 c = tc[taddr]; |
| 1345 | | UINT16 k = m_rdp->GetTLUT()[c << 2]; |
| 1338 | UINT16 k = ((UINT16*)(userdata->m_tmem + 0x800))[c << 2]; |
| 1346 | 1339 | |
| 1347 | 1340 | Color color; |
| 1348 | 1341 | color.i.r = color.i.g = color.i.b = (k >> 8) & 0xff; |
| r14423 | r14424 | |
| 1351 | 1344 | return color.c; |
| 1352 | 1345 | } |
| 1353 | 1346 | |
| 1354 | | UINT32 TexturePipeT::_FetchI_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal) |
| 1347 | UINT32 N64TexturePipeT::_FetchI_8_RAW(INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata) |
| 1355 | 1348 | { |
| 1356 | | UINT8 *tc = m_rdp->GetTMEM(); |
| 1349 | UINT8 *tc = userdata->m_tmem; |
| 1357 | 1350 | int taddr = (tbase << 3) + s; |
| 1358 | 1351 | taddr ^= sTexAddrSwap8[t & 1]; |
| 1359 | 1352 | taddr &= 0xfff; |
| r14423 | r14424 | |
| 1369 | 1362 | return color.c; |
| 1370 | 1363 | } |
| 1371 | 1364 | |
| 1372 | | UINT32 TexturePipeT::Fetch(INT32 s, INT32 t, INT32 tilenum) |
| 1365 | UINT32 N64TexturePipeT::Fetch(INT32 s, INT32 t, INT32 tilenum, const rdp_poly_state& object, rdp_span_aux *userdata) |
| 1373 | 1366 | { |
| 1374 | | Tile* tile = m_rdp->GetTiles(); |
| 1367 | const N64Tile* tile = object.m_tiles; |
| 1375 | 1368 | UINT32 tformat = tile[tilenum].format; |
| 1376 | 1369 | UINT32 tsize = tile[tilenum].size; |
| 1377 | 1370 | |
| r14423 | r14424 | |
| 1379 | 1372 | tbase += tile[tilenum].tmem; |
| 1380 | 1373 | UINT32 tpal = tile[tilenum].palette; |
| 1381 | 1374 | |
| 1382 | | UINT32 index = (tformat << 4) | (tsize << 2) | (m_rdp->OtherModes.en_tlut << 1) | m_rdp->OtherModes.tlut_type; |
| 1375 | UINT32 index = (tformat << 4) | (tsize << 2) | (object.OtherModes.en_tlut << 1) | object.OtherModes.tlut_type; |
| 1383 | 1376 | |
| 1384 | | return ((this)->*(TexelFetch[index]))(s, t, tbase, tpal); |
| 1377 | return ((this)->*(TexelFetch[index]))(s, t, tbase, tpal, userdata); |
| 1385 | 1378 | } |
| 1386 | | |
| 1387 | | } // namespace RDP |
| 1388 | | |
| 1389 | | } // namespace N64 |
src/mame/video/rdpspn16.c
| r14423 | r14424 | |
| 2 | 2 | #include "includes/n64.h" |
| 3 | 3 | #include "video/n64.h" |
| 4 | 4 | |
| 5 | | namespace N64 |
| 6 | | { |
| 7 | | |
| 8 | | namespace RDP |
| 9 | | { |
| 10 | | |
| 11 | 5 | #define LookUpCC(A, B, C, D) m_rdp->GetCCLUT2()[(m_rdp->GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D] |
| 12 | 6 | |
| 13 | | void Processor::RenderSpans(int start, int end, int tilenum, bool flip) |
| 7 | void n64_rdp::RenderSpans(int start, int end, int tilenum, bool flip, extent_t *Spans, bool rect, rdp_poly_state &object) |
| 14 | 8 | { |
| 15 | | int clipy1 = GetScissor()->m_yh; |
| 16 | | int clipy2 = GetScissor()->m_yl; |
| 9 | int clipy1 = Scissor.m_yh; |
| 10 | int clipy2 = Scissor.m_yl; |
| 11 | int offset = 0; |
| 17 | 12 | |
| 18 | 13 | if (clipy2 <= 0) |
| 19 | 14 | { |
| r14423 | r14424 | |
| 22 | 17 | |
| 23 | 18 | if (start < clipy1) |
| 24 | 19 | { |
| 20 | offset = clipy1 - start; |
| 25 | 21 | start = clipy1; |
| 26 | 22 | } |
| 27 | 23 | if (start >= clipy2) |
| 28 | 24 | { |
| 25 | offset = start - (clipy2 - 1); |
| 29 | 26 | start = clipy2 - 1; |
| 30 | 27 | } |
| 31 | 28 | if (end < clipy1) |
| 32 | 29 | { |
| 33 | 30 | end = clipy1; |
| 34 | 31 | } |
| 35 | | if (end >= clipy2) // Needed by 40 Winks |
| 32 | if (end >= clipy2) |
| 36 | 33 | { |
| 37 | 34 | end = clipy2 - 1; |
| 38 | 35 | } |
| 39 | 36 | |
| 40 | | for(int i = start; i <= end; i++) |
| 37 | object.m_rdp = this; |
| 38 | memcpy(&object.MiscState, &MiscState, sizeof(MiscStateT)); |
| 39 | memcpy(&object.OtherModes, &OtherModes, sizeof(OtherModesT)); |
| 40 | memcpy(&object.SpanBase, &SpanBase, sizeof(SpanBaseT)); |
| 41 | memcpy(&object.Scissor, &Scissor, sizeof(Rectangle)); |
| 42 | memcpy(&object.m_tiles, &m_tiles, 8 * sizeof(N64Tile)); |
| 43 | object.tilenum = tilenum; |
| 44 | object.flip = flip; |
| 45 | object.FillColor = FillColor; |
| 46 | object.rect = rect; |
| 47 | |
| 48 | switch(OtherModes.cycle_type) |
| 41 | 49 | { |
| 42 | | switch(OtherModes.cycle_type) |
| 43 | | { |
| 44 | | case CYCLE_TYPE_1: Spans[i].Draw1Cycle(i, tilenum, flip); break; |
| 45 | | case CYCLE_TYPE_2: Spans[i].Draw2Cycle(i, tilenum, flip); break; |
| 46 | | case CYCLE_TYPE_COPY: Spans[i].DrawCopy(i, tilenum, flip); break; |
| 47 | | case CYCLE_TYPE_FILL: Spans[i].DrawFill(i, tilenum, flip); break; |
| 48 | | } |
| 49 | | } |
| 50 | | } |
| 50 | case CYCLE_TYPE_1: |
| 51 | render_triangle_custom(visarea, render_delegate(FUNC(n64_rdp::SpanDraw1Cycle), this), start, (end - start) + 1, Spans + offset); |
| 52 | break; |
| 53 | case CYCLE_TYPE_2: |
| 54 | render_triangle_custom(visarea, render_delegate(FUNC(n64_rdp::SpanDraw2Cycle), this), start, (end - start) + 1, Spans + offset); |
| 55 | break; |
| 51 | 56 | |
| 52 | | void Span::Dump() |
| 53 | | { |
| 54 | | printf(" m_lx = %d\n", m_lx); |
| 55 | | printf(" m_rx = %d\n", m_rx); |
| 56 | | printf(" m_s.w = %08x\n", m_s.w); |
| 57 | | printf(" m_t.w = %08x\n", m_t.w); |
| 58 | | printf(" m_w.w = %08x\n", m_w.w); |
| 59 | | printf(" m_r.w = %08x\n", m_r.w); |
| 60 | | printf(" m_g.w = %08x\n", m_g.w); |
| 61 | | printf(" m_b.w = %08x\n", m_b.w); |
| 62 | | printf(" m_a.w = %08x\n", m_a.w); |
| 63 | | printf(" m_z.w = %08x\n", m_z.w); |
| 57 | case CYCLE_TYPE_COPY: |
| 58 | render_triangle_custom(visarea, render_delegate(FUNC(n64_rdp::SpanDrawCopy), this), start, (end - start) + 1, Spans + offset); |
| 59 | break; |
| 64 | 60 | |
| 65 | | printf(" CVG: "); |
| 66 | | for(int index = 0; index < RDP_CVG_SPAN_MAX; index++) |
| 67 | | { |
| 68 | | printf("%d", m_cvg[index]); |
| 61 | case CYCLE_TYPE_FILL: |
| 62 | render_triangle_custom(visarea, render_delegate(FUNC(n64_rdp::SpanDrawFill), this), start, (end - start) + 1, Spans + offset); |
| 63 | break; |
| 69 | 64 | } |
| 70 | | printf("\n"); |
| 71 | 65 | } |
| 72 | 66 | |
| 73 | | void Span::SetMachine(running_machine &machine) |
| 67 | void n64_rdp::RGBAZClip(int sr, int sg, int sb, int sa, int *sz, rdp_span_aux *userdata) |
| 74 | 68 | { |
| 75 | | _n64_state *state = machine.driver_data<_n64_state>(); |
| 69 | userdata->ShadeColor.i.r = m_special_9bit_clamptable[sr & 0x1ff]; |
| 70 | userdata->ShadeColor.i.g = m_special_9bit_clamptable[sg & 0x1ff]; |
| 71 | userdata->ShadeColor.i.b = m_special_9bit_clamptable[sb & 0x1ff]; |
| 72 | userdata->ShadeColor.i.a = m_special_9bit_clamptable[sa & 0x1ff]; |
| 76 | 73 | |
| 77 | | m_machine = &machine; |
| 78 | | m_rdp = &state->m_rdp; |
| 79 | | } |
| 80 | | |
| 81 | | void Span::RGBAZClip(int sr, int sg, int sb, int sa, int *sz) |
| 82 | | { |
| 83 | | m_rdp->ShadeColor.i.r = m_rdp->GetSpecial9BitClampTable()[sr & 0x1ff]; |
| 84 | | m_rdp->ShadeColor.i.g = m_rdp->GetSpecial9BitClampTable()[sg & 0x1ff]; |
| 85 | | m_rdp->ShadeColor.i.b = m_rdp->GetSpecial9BitClampTable()[sb & 0x1ff]; |
| 86 | | m_rdp->ShadeColor.i.a = m_rdp->GetSpecial9BitClampTable()[sa & 0x1ff]; |
| 87 | | |
| 88 | 74 | INT32 zanded = (*sz) & 0x60000; |
| 89 | 75 | |
| 90 | 76 | zanded >>= 17; |
| r14423 | r14424 | |
| 97 | 83 | } |
| 98 | 84 | } |
| 99 | 85 | |
| 100 | | void Span::RGBAZCorrectTriangle(INT32 offx, INT32 offy, INT32* r, INT32* g, INT32* b, INT32* a, INT32* z) |
| 86 | void n64_rdp::RGBAZCorrectTriangle(INT32 offx, INT32 offy, INT32* r, INT32* g, INT32* b, INT32* a, INT32* z, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 101 | 87 | { |
| 102 | | if (m_rdp->MiscState.CurrentPixCvg == 8) |
| 88 | if (userdata->CurrentPixCvg == 8) |
| 103 | 89 | { |
| 104 | 90 | *r >>= 2; |
| 105 | 91 | *g >>= 2; |
| r14423 | r14424 | |
| 109 | 95 | } |
| 110 | 96 | else |
| 111 | 97 | { |
| 112 | | INT32 summand_xr = offx * SIGN13(m_rdp->m_span_dr >> 14); |
| 113 | | INT32 summand_yr = offy * SIGN13(m_rdp->m_span_drdy >> 14); |
| 114 | | INT32 summand_xb = offx * SIGN13(m_rdp->m_span_db >> 14); |
| 115 | | INT32 summand_yb = offy * SIGN13(m_rdp->m_span_dbdy >> 14); |
| 116 | | INT32 summand_xg = offx * SIGN13(m_rdp->m_span_dg >> 14); |
| 117 | | INT32 summand_yg = offy * SIGN13(m_rdp->m_span_dgdy >> 14); |
| 118 | | INT32 summand_xa = offx * SIGN13(m_rdp->m_span_da >> 14); |
| 119 | | INT32 summand_ya = offy * SIGN13(m_rdp->m_span_dady >> 14); |
| 98 | INT32 summand_xr = offx * SIGN13(object.SpanBase.m_span_dr >> 14); |
| 99 | INT32 summand_yr = offy * SIGN13(object.SpanBase.m_span_drdy >> 14); |
| 100 | INT32 summand_xb = offx * SIGN13(object.SpanBase.m_span_db >> 14); |
| 101 | INT32 summand_yb = offy * SIGN13(object.SpanBase.m_span_dbdy >> 14); |
| 102 | INT32 summand_xg = offx * SIGN13(object.SpanBase.m_span_dg >> 14); |
| 103 | INT32 summand_yg = offy * SIGN13(object.SpanBase.m_span_dgdy >> 14); |
| 104 | INT32 summand_xa = offx * SIGN13(object.SpanBase.m_span_da >> 14); |
| 105 | INT32 summand_ya = offy * SIGN13(object.SpanBase.m_span_dady >> 14); |
| 120 | 106 | |
| 121 | | INT32 summand_xz = offx * SIGN22(m_rdp->m_span_dz >> 10); |
| 122 | | INT32 summand_yz = offy * SIGN22(m_rdp->m_span_dzdy >> 10); |
| 107 | INT32 summand_xz = offx * SIGN22(object.SpanBase.m_span_dz >> 10); |
| 108 | INT32 summand_yz = offy * SIGN22(object.SpanBase.m_span_dzdy >> 10); |
| 123 | 109 | |
| 124 | 110 | *r = ((*r << 2) + summand_xr + summand_yr) >> 4; |
| 125 | 111 | *g = ((*g << 2) + summand_xg + summand_yg) >> 4; |
| r14423 | r14424 | |
| 129 | 115 | } |
| 130 | 116 | } |
| 131 | 117 | |
| 132 | | void Span::Draw1Cycle(int index, int tilenum, bool flip) |
| 118 | void n64_rdp::SpanDraw1Cycle(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid) |
| 133 | 119 | { |
| 134 | | int clipx1 = m_rdp->GetScissor()->m_xh; |
| 135 | | int clipx2 = m_rdp->GetScissor()->m_xl; |
| 120 | int clipx1 = object.Scissor.m_xh; |
| 121 | int clipx2 = object.Scissor.m_xl; |
| 122 | n64_rdp *m_rdp = object.m_rdp; |
| 123 | int tilenum = object.tilenum; |
| 124 | bool flip = object.flip; |
| 136 | 125 | |
| 137 | | SpanParam r = m_r; |
| 138 | | SpanParam g = m_g; |
| 139 | | SpanParam b = m_b; |
| 140 | | SpanParam a = m_a; |
| 141 | | SpanParam z = m_z; |
| 142 | | SpanParam s = m_s; |
| 143 | | SpanParam t = m_t; |
| 144 | | SpanParam w = m_w; |
| 126 | SpanParam r; r.w = extent.param[SPAN_R].start; |
| 127 | SpanParam g; g.w = extent.param[SPAN_G].start; |
| 128 | SpanParam b; b.w = extent.param[SPAN_B].start; |
| 129 | SpanParam a; a.w = extent.param[SPAN_A].start; |
| 130 | SpanParam z; z.w = extent.param[SPAN_Z].start; |
| 131 | SpanParam s; s.w = extent.param[SPAN_S].start; |
| 132 | SpanParam t; t.w = extent.param[SPAN_T].start; |
| 133 | SpanParam w; w.w = extent.param[SPAN_W].start; |
| 145 | 134 | |
| 146 | | UINT32 zb = m_rdp->MiscState.ZBAddress >> 1; |
| 135 | UINT32 zb = object.MiscState.ZBAddress >> 1; |
| 147 | 136 | UINT32 zhb = zb; |
| 148 | 137 | UINT8 offx = 0, offy = 0; |
| 149 | 138 | |
| 150 | 139 | INT32 tile1 = tilenum; |
| 151 | 140 | |
| 152 | | m_rdp->TexPipe.CalculateClampDiffs(tile1); |
| 141 | rdp_span_aux *userdata = (rdp_span_aux*)extent.userdata; |
| 153 | 142 | |
| 154 | | bool noisecompute = m_rdp->ColorInputs.combiner_rgbsub_a_r[1] == &m_rdp->NoiseColor.i.r; |
| 155 | | bool partialreject = (m_rdp->ColorInputs.blender2b_a[0] == &m_rdp->InvPixelColor.i.a && m_rdp->ColorInputs.blender1b_a[0] == &m_rdp->PixelColor.i.a); |
| 156 | | bool bsel0 = (m_rdp->ColorInputs.blender2b_a[0] == &m_rdp->MemoryColor.i.a); |
| 143 | m_rdp->TexPipe.CalculateClampDiffs(tile1, userdata, object); |
| 157 | 144 | |
| 158 | | int drinc = flip ? (m_rdp->m_span_dr) : -m_rdp->m_span_dr; |
| 159 | | int dginc = flip ? (m_rdp->m_span_dg) : -m_rdp->m_span_dg; |
| 160 | | int dbinc = flip ? (m_rdp->m_span_db) : -m_rdp->m_span_db; |
| 161 | | int dainc = flip ? (m_rdp->m_span_da) : -m_rdp->m_span_da; |
| 162 | | int dzinc = flip ? (m_rdp->m_span_dz) : -m_rdp->m_span_dz; |
| 163 | | int dsinc = flip ? (m_rdp->m_span_ds) : -m_rdp->m_span_ds; |
| 164 | | int dtinc = flip ? (m_rdp->m_span_dt) : -m_rdp->m_span_dt; |
| 165 | | int dwinc = flip ? (m_rdp->m_span_dw) : -m_rdp->m_span_dw; |
| 166 | | int dzpix = m_rdp->m_span_dzpix; |
| 145 | bool partialreject = (userdata->ColorInputs.blender2b_a[0] == &userdata->InvPixelColor.i.a && userdata->ColorInputs.blender1b_a[0] == &userdata->PixelColor.i.a); |
| 146 | bool bsel0 = (userdata->ColorInputs.blender2b_a[0] == &userdata->MemoryColor.i.a); |
| 147 | |
| 148 | int drinc = flip ? (object.SpanBase.m_span_dr) : -object.SpanBase.m_span_dr; |
| 149 | int dginc = flip ? (object.SpanBase.m_span_dg) : -object.SpanBase.m_span_dg; |
| 150 | int dbinc = flip ? (object.SpanBase.m_span_db) : -object.SpanBase.m_span_db; |
| 151 | int dainc = flip ? (object.SpanBase.m_span_da) : -object.SpanBase.m_span_da; |
| 152 | int dzinc = flip ? (object.SpanBase.m_span_dz) : -object.SpanBase.m_span_dz; |
| 153 | int dsinc = flip ? (object.SpanBase.m_span_ds) : -object.SpanBase.m_span_ds; |
| 154 | int dtinc = flip ? (object.SpanBase.m_span_dt) : -object.SpanBase.m_span_dt; |
| 155 | int dwinc = flip ? (object.SpanBase.m_span_dw) : -object.SpanBase.m_span_dw; |
| 156 | int dzpix = object.SpanBase.m_span_dzpix; |
| 167 | 157 | int xinc = flip ? 1 : -1; |
| 168 | 158 | |
| 169 | | int fb_index = m_rdp->MiscState.FBWidth * index; |
| 159 | int fb_index = object.MiscState.FBWidth * scanline; |
| 170 | 160 | |
| 171 | 161 | int cdith = 0; |
| 172 | 162 | int adith = 0; |
| 173 | 163 | |
| 174 | | int xstart = m_lx; |
| 175 | | int xend = m_unscissored_rx; |
| 176 | | int xend_scissored = m_rx; |
| 164 | int xstart = extent.startx; |
| 165 | int xend = userdata->m_unscissored_rx; |
| 166 | int xend_scissored = extent.stopx; |
| 177 | 167 | |
| 178 | 168 | int x = xend; |
| 179 | 169 | |
| 180 | 170 | int length = flip ? (xstart - xend) : (xend - xstart); |
| 181 | | m_rdp->TexPipe.m_start_span = true; |
| 182 | 171 | UINT32 fir, fig, fib; |
| 183 | 172 | |
| 173 | //if(object.rect) printf("(%s) Scan %d Span %d to %d %d, length %d\n", flip ? "Flip" : "NoFlip", scanline, xstart, xend_scissored, xend, length); fflush(stdout); |
| 174 | |
| 175 | if(object.OtherModes.z_source_sel) |
| 176 | { |
| 177 | z.w = ((UINT32)object.MiscState.PrimitiveZ) << 16; |
| 178 | dzpix = object.MiscState.PrimitiveDZ; |
| 179 | dzinc = 0; |
| 180 | } |
| 181 | |
| 182 | userdata->m_start_span = true; |
| 184 | 183 | for (int j = 0; j <= length; j++) |
| 185 | 184 | { |
| 186 | 185 | int sr = r.w >> 14; |
| r14423 | r14424 | |
| 194 | 193 | INT32 sss = 0; |
| 195 | 194 | INT32 sst = 0; |
| 196 | 195 | |
| 197 | | if (m_rdp->OtherModes.z_source_sel) |
| 198 | | { |
| 199 | | sz = (((UINT32)m_rdp->MiscState.PrimitiveZ) << 6) & 0x3fffff; |
| 200 | | dzpix = m_rdp->MiscState.PrimitiveDZ; |
| 201 | | dzinc = m_rdp->m_span_dz = m_rdp->m_span_dzdy = 0; |
| 202 | | } |
| 203 | | |
| 204 | 196 | bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored); |
| 205 | 197 | |
| 206 | 198 | if (x >= clipx1 && x < clipx2 && valid_x) |
| 207 | 199 | { |
| 208 | | m_rdp->lookup_cvmask_derivatives(m_cvg[x], &offx, &offy); |
| 200 | m_rdp->lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata); |
| 209 | 201 | |
| 210 | | if (m_rdp->TexPipe.m_start_span) |
| 202 | if (userdata->m_start_span) |
| 211 | 203 | { |
| 212 | | if (m_rdp->OtherModes.persp_tex_en) |
| 204 | if (object.OtherModes.persp_tex_en) |
| 213 | 205 | { |
| 214 | 206 | m_rdp->TCDiv(ss, st, sw, &sss, &sst); |
| 215 | 207 | } |
| r14423 | r14424 | |
| 220 | 212 | } |
| 221 | 213 | else |
| 222 | 214 | { |
| 223 | | sss = m_rdp->TexPipe.m_precomp_s; |
| 224 | | sst = m_rdp->TexPipe.m_precomp_t; |
| 215 | sss = userdata->m_precomp_s; |
| 216 | sst = userdata->m_precomp_t; |
| 225 | 217 | } |
| 226 | 218 | |
| 227 | | m_rdp->TexPipe.LOD1Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc); |
| 219 | m_rdp->TexPipe.LOD1Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, userdata, object); |
| 228 | 220 | |
| 229 | | RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz); |
| 230 | | RGBAZClip(sr, sg, sb, sa, &sz); |
| 221 | RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object); |
| 222 | RGBAZClip(sr, sg, sb, sa, &sz, userdata); |
| 231 | 223 | |
| 232 | | m_rdp->TexPipe.Cycle(&m_rdp->Texel0Color, &m_rdp->Texel0Color, sss, sst, tilenum, 0); |
| 224 | m_rdp->TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tilenum, 0, userdata, object); |
| 233 | 225 | |
| 234 | | m_rdp->ColorCombiner1Cycle(noisecompute); |
| 226 | m_rdp->ColorCombiner1Cycle(userdata); |
| 235 | 227 | |
| 228 | //Alpha coverage combiner |
| 229 | GetAlphaCvg(&userdata->PixelColor.i.a, userdata, object); |
| 230 | |
| 236 | 231 | UINT32 curpixel = fb_index + x; |
| 237 | 232 | UINT32 zbcur = zb + curpixel; |
| 238 | 233 | UINT32 zhbcur = zhb + curpixel; |
| 239 | 234 | |
| 240 | | m_rdp->Framebuffer.Read(curpixel); |
| 235 | ((this)->*(_Read[((object.MiscState.FBSize - 2) << 1) | object.OtherModes.image_read_en]))(curpixel, userdata, object); |
| 241 | 236 | |
| 242 | | if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix)) |
| 237 | if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object)) |
| 243 | 238 | { |
| 244 | | m_rdp->GetDitherValues(index, j, &cdith, &adith); |
| 239 | m_rdp->GetDitherValues(scanline, j, &cdith, &adith, object); |
| 245 | 240 | |
| 246 | | bool rendered = m_rdp->Blender.Blend1Cycle(&fir, &fig, &fib, cdith, adith, partialreject, bsel0); |
| 241 | bool rendered = m_rdp->Blender.Blend1Cycle(&fir, &fig, &fib, cdith, adith, partialreject, bsel0, userdata, object); |
| 247 | 242 | |
| 248 | 243 | if (rendered) |
| 249 | 244 | { |
| 250 | | m_rdp->Framebuffer.Write(curpixel, fir, fig, fib); |
| 251 | | if (m_rdp->OtherModes.z_update_en) |
| 245 | ((this)->*(_Write[((object.MiscState.FBSize - 2) << 3) | (object.OtherModes.cvg_dest << 1) | userdata->BlendEnable]))(curpixel, fir, fig, fib, userdata, object); |
| 246 | if (object.OtherModes.z_update_en) |
| 252 | 247 | { |
| 253 | | m_rdp->ZStore(zbcur, zhbcur, sz); |
| 248 | m_rdp->ZStore(zbcur, zhbcur, sz, userdata->m_dzpix_enc); |
| 254 | 249 | } |
| 255 | 250 | } |
| 256 | 251 | } |
| r14423 | r14424 | |
| 267 | 262 | |
| 268 | 263 | x += xinc; |
| 269 | 264 | } |
| 265 | |
| 266 | //printf("\n"); |
| 270 | 267 | } |
| 271 | 268 | |
| 272 | | void Span::Draw2Cycle(int index, int tilenum, bool flip) |
| 269 | void n64_rdp::SpanDraw2Cycle(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid) |
| 273 | 270 | { |
| 274 | | int clipx1 = m_rdp->GetScissor()->m_xh; |
| 275 | | int clipx2 = m_rdp->GetScissor()->m_xl; |
| 271 | int clipx1 = object.Scissor.m_xh; |
| 272 | int clipx2 = object.Scissor.m_xl; |
| 273 | n64_rdp *m_rdp = object.m_rdp; |
| 274 | int tilenum = object.tilenum; |
| 275 | bool flip = object.flip; |
| 276 | 276 | |
| 277 | | SpanParam r = m_r; |
| 278 | | SpanParam g = m_g; |
| 279 | | SpanParam b = m_b; |
| 280 | | SpanParam a = m_a; |
| 281 | | SpanParam z = m_z; |
| 282 | | SpanParam s = m_s; |
| 283 | | SpanParam t = m_t; |
| 284 | | SpanParam w = m_w; |
| 277 | SpanParam r; r.w = extent.param[SPAN_R].start; |
| 278 | SpanParam g; g.w = extent.param[SPAN_G].start; |
| 279 | SpanParam b; b.w = extent.param[SPAN_B].start; |
| 280 | SpanParam a; a.w = extent.param[SPAN_A].start; |
| 281 | SpanParam z; z.w = extent.param[SPAN_Z].start; |
| 282 | SpanParam s; s.w = extent.param[SPAN_S].start; |
| 283 | SpanParam t; t.w = extent.param[SPAN_T].start; |
| 284 | SpanParam w; w.w = extent.param[SPAN_W].start; |
| 285 | 285 | |
| 286 | | UINT32 zb = m_rdp->MiscState.ZBAddress >> 1; |
| 286 | UINT32 zb = object.MiscState.ZBAddress >> 1; |
| 287 | 287 | UINT32 zhb = zb; |
| 288 | 288 | UINT8 offx = 0, offy = 0; |
| 289 | 289 | |
| r14423 | r14424 | |
| 295 | 295 | INT32 news = 0; |
| 296 | 296 | INT32 newt = 0; |
| 297 | 297 | |
| 298 | | m_rdp->TexPipe.CalculateClampDiffs(tile1); |
| 298 | rdp_span_aux *userdata = (rdp_span_aux*)extent.userdata; |
| 299 | 299 | |
| 300 | | bool noisecompute = (m_rdp->ColorInputs.combiner_rgbsub_a_r[0] == &m_rdp->NoiseColor.i.r || m_rdp->ColorInputs.combiner_rgbsub_a_r[1] == &m_rdp->PixelColor.i.r); |
| 301 | | bool partialreject = (m_rdp->ColorInputs.blender2b_a[1] == &m_rdp->InvPixelColor.i.a && m_rdp->ColorInputs.blender1b_a[1] == &m_rdp->PixelColor.i.a); |
| 302 | | bool bsel0 = (m_rdp->ColorInputs.blender2b_a[0] == &m_rdp->MemoryColor.i.a); |
| 303 | | bool bsel1 = (m_rdp->ColorInputs.blender2b_a[1] == &m_rdp->MemoryColor.i.a); |
| 300 | m_rdp->TexPipe.CalculateClampDiffs(tile1, userdata, object); |
| 304 | 301 | |
| 305 | | int dzpix = m_rdp->m_span_dzpix; |
| 306 | | int drinc = flip ? (m_rdp->m_span_dr) : -m_rdp->m_span_dr; |
| 307 | | int dginc = flip ? (m_rdp->m_span_dg) : -m_rdp->m_span_dg; |
| 308 | | int dbinc = flip ? (m_rdp->m_span_db) : -m_rdp->m_span_db; |
| 309 | | int dainc = flip ? (m_rdp->m_span_da) : -m_rdp->m_span_da; |
| 310 | | int dzinc = flip ? (m_rdp->m_span_dz) : -m_rdp->m_span_dz; |
| 311 | | int dsinc = flip ? (m_rdp->m_span_ds) : -m_rdp->m_span_ds; |
| 312 | | int dtinc = flip ? (m_rdp->m_span_dt) : -m_rdp->m_span_dt; |
| 313 | | int dwinc = flip ? (m_rdp->m_span_dw) : -m_rdp->m_span_dw; |
| 302 | bool partialreject = (userdata->ColorInputs.blender2b_a[1] == &userdata->InvPixelColor.i.a && userdata->ColorInputs.blender1b_a[1] == &userdata->PixelColor.i.a); |
| 303 | bool bsel0 = (userdata->ColorInputs.blender2b_a[0] == &userdata->MemoryColor.i.a); |
| 304 | bool bsel1 = (userdata->ColorInputs.blender2b_a[1] == &userdata->MemoryColor.i.a); |
| 305 | |
| 306 | int dzpix = object.SpanBase.m_span_dzpix; |
| 307 | int drinc = flip ? (object.SpanBase.m_span_dr) : -object.SpanBase.m_span_dr; |
| 308 | int dginc = flip ? (object.SpanBase.m_span_dg) : -object.SpanBase.m_span_dg; |
| 309 | int dbinc = flip ? (object.SpanBase.m_span_db) : -object.SpanBase.m_span_db; |
| 310 | int dainc = flip ? (object.SpanBase.m_span_da) : -object.SpanBase.m_span_da; |
| 311 | int dzinc = flip ? (object.SpanBase.m_span_dz) : -object.SpanBase.m_span_dz; |
| 312 | int dsinc = flip ? (object.SpanBase.m_span_ds) : -object.SpanBase.m_span_ds; |
| 313 | int dtinc = flip ? (object.SpanBase.m_span_dt) : -object.SpanBase.m_span_dt; |
| 314 | int dwinc = flip ? (object.SpanBase.m_span_dw) : -object.SpanBase.m_span_dw; |
| 314 | 315 | int xinc = flip ? 1 : -1; |
| 315 | 316 | |
| 316 | | int fb_index = m_rdp->MiscState.FBWidth * index; |
| 317 | int fb_index = object.MiscState.FBWidth * scanline; |
| 317 | 318 | |
| 318 | 319 | int cdith = 0; |
| 319 | 320 | int adith = 0; |
| 320 | 321 | |
| 321 | | int xstart = m_lx; |
| 322 | | int xend = m_unscissored_rx; |
| 323 | | int xend_scissored = m_rx; |
| 322 | int xstart = extent.startx; |
| 323 | int xend = userdata->m_unscissored_rx; |
| 324 | int xend_scissored = extent.stopx; |
| 324 | 325 | |
| 325 | 326 | int x = xend; |
| 326 | 327 | |
| 327 | 328 | int length = flip ? (xstart - xend) : (xend - xstart); |
| 328 | | m_rdp->TexPipe.m_start_span = true; |
| 329 | 329 | UINT32 fir, fig, fib; |
| 330 | 330 | |
| 331 | | //printf( "Span length: %d\n", length); |
| 331 | if(object.OtherModes.z_source_sel) |
| 332 | { |
| 333 | z.w = ((UINT32)object.MiscState.PrimitiveZ) << 16; |
| 334 | dzpix = object.MiscState.PrimitiveDZ; |
| 335 | dzinc = 0; |
| 336 | } |
| 332 | 337 | |
| 338 | userdata->m_start_span = true; |
| 333 | 339 | for (int j = 0; j <= length; j++) |
| 334 | 340 | { |
| 335 | 341 | int sr = r.w >> 14; |
| r14423 | r14424 | |
| 345 | 351 | Color c1; |
| 346 | 352 | Color c2; |
| 347 | 353 | |
| 348 | | if (m_rdp->OtherModes.z_source_sel) |
| 349 | | { |
| 350 | | sz = (((UINT32)m_rdp->MiscState.PrimitiveZ) << 6) & 0x3fffff; |
| 351 | | dzpix = m_rdp->MiscState.PrimitiveDZ; |
| 352 | | dzinc = m_rdp->m_span_dz = m_rdp->m_span_dzdy = 0; |
| 353 | | } |
| 354 | | |
| 355 | 354 | bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored); |
| 356 | 355 | |
| 357 | 356 | if (x >= clipx1 && x < clipx2 && valid_x) |
| 358 | 357 | { |
| 359 | | m_rdp->lookup_cvmask_derivatives(m_cvg[x], &offx, &offy); |
| 358 | m_rdp->lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata); |
| 360 | 359 | |
| 361 | | if (m_rdp->TexPipe.m_start_span) |
| 360 | if (userdata->m_start_span) |
| 362 | 361 | { |
| 363 | | if (m_rdp->OtherModes.persp_tex_en) |
| 362 | if (object.OtherModes.persp_tex_en) |
| 364 | 363 | { |
| 365 | 364 | m_rdp->TCDiv(ss, st, sw, &sss, &sst); |
| 366 | 365 | } |
| r14423 | r14424 | |
| 371 | 370 | } |
| 372 | 371 | else |
| 373 | 372 | { |
| 374 | | sss = m_rdp->TexPipe.m_precomp_s; |
| 375 | | sst = m_rdp->TexPipe.m_precomp_t; |
| 373 | sss = userdata->m_precomp_s; |
| 374 | sst = userdata->m_precomp_t; |
| 376 | 375 | } |
| 377 | 376 | |
| 378 | | m_rdp->TexPipe.LOD2Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, prim_tile, &tile1, &tile2); |
| 377 | m_rdp->TexPipe.LOD2Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, prim_tile, &tile1, &tile2, userdata, object); |
| 379 | 378 | |
| 380 | | news = m_rdp->TexPipe.m_precomp_s; |
| 381 | | newt = m_rdp->TexPipe.m_precomp_t; |
| 382 | | m_rdp->TexPipe.LOD2CycleLimited(&news, &newt, s.w + dsinc, t.w + dtinc, w.w + dwinc, dsinc, dtinc, dwinc, prim_tile, &newtile1); |
| 379 | news = userdata->m_precomp_s; |
| 380 | newt = userdata->m_precomp_t; |
| 381 | m_rdp->TexPipe.LOD2CycleLimited(&news, &newt, s.w + dsinc, t.w + dtinc, w.w + dwinc, dsinc, dtinc, dwinc, prim_tile, &newtile1, object); |
| 383 | 382 | |
| 384 | | RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz); |
| 385 | | RGBAZClip(sr, sg, sb, sa, &sz); |
| 383 | RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object); |
| 384 | RGBAZClip(sr, sg, sb, sa, &sz, userdata); |
| 386 | 385 | |
| 387 | | m_rdp->TexPipe.Cycle(&m_rdp->Texel0Color, &m_rdp->Texel0Color, sss, sst, tile1, 0); |
| 388 | | m_rdp->TexPipe.Cycle(&m_rdp->Texel1Color, &m_rdp->Texel0Color, sss, sst, tile2, 1); |
| 386 | m_rdp->TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tile1, 0, userdata, object); |
| 387 | m_rdp->TexPipe.Cycle(&userdata->Texel1Color, &userdata->Texel0Color, sss, sst, tile2, 1, userdata, object); |
| 389 | 388 | |
| 390 | | m_rdp->TexPipe.Cycle(&m_rdp->NextTexelColor, &m_rdp->NextTexelColor, sss, sst, tile2, 1); |
| 389 | m_rdp->TexPipe.Cycle(&userdata->NextTexelColor, &userdata->NextTexelColor, sss, sst, tile2, 1, userdata, object); |
| 391 | 390 | |
| 392 | | m_rdp->ColorCombiner2Cycle(noisecompute); |
| 391 | m_rdp->ColorCombiner2Cycle(userdata); |
| 393 | 392 | |
| 393 | //Alpha coverage combiner |
| 394 | GetAlphaCvg(&userdata->PixelColor.i.a, userdata, object); |
| 395 | |
| 394 | 396 | UINT32 curpixel = fb_index + x; |
| 395 | 397 | UINT32 zbcur = zb + curpixel; |
| 396 | 398 | UINT32 zhbcur = zhb + curpixel; |
| 397 | 399 | |
| 398 | | m_rdp->Framebuffer.Read(curpixel); |
| 400 | ((this)->*(_Read[((object.MiscState.FBSize - 2) << 1) | object.OtherModes.image_read_en]))(curpixel, userdata, object); |
| 399 | 401 | |
| 400 | | if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix)) |
| 402 | if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object)) |
| 401 | 403 | { |
| 402 | | m_rdp->GetDitherValues(index, j, &cdith, &adith); |
| 404 | m_rdp->GetDitherValues(scanline, j, &cdith, &adith, object); |
| 403 | 405 | |
| 404 | | bool rendered = m_rdp->Blender.Blend2Cycle(&fir, &fig, &fib, cdith, adith, partialreject, bsel0, bsel1); |
| 406 | bool rendered = m_rdp->Blender.Blend2Cycle(&fir, &fig, &fib, cdith, adith, partialreject, bsel0, bsel1, userdata, object); |
| 405 | 407 | |
| 406 | 408 | if (rendered) |
| 407 | 409 | { |
| 408 | | m_rdp->Framebuffer.Write(curpixel, fir, fig, fib); |
| 409 | | if (m_rdp->OtherModes.z_update_en) |
| 410 | ((this)->*(_Write[((object.MiscState.FBSize - 2) << 3) | (object.OtherModes.cvg_dest << 1) | userdata->BlendEnable]))(curpixel, fir, fig, fib, userdata, object); |
| 411 | if (object.OtherModes.z_update_en) |
| 410 | 412 | { |
| 411 | | m_rdp->ZStore(zbcur, zhbcur, sz); |
| 413 | m_rdp->ZStore(zbcur, zhbcur, sz, userdata->m_dzpix_enc); |
| 412 | 414 | } |
| 413 | 415 | } |
| 414 | 416 | } |
| r14423 | r14424 | |
| 427 | 429 | } |
| 428 | 430 | } |
| 429 | 431 | |
| 430 | | void Span::DrawCopy(int index, int tilenum, bool flip) |
| 432 | void n64_rdp::SpanDrawCopy(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid) |
| 431 | 433 | { |
| 432 | | int clipx1 = m_rdp->GetScissor()->m_xh; |
| 433 | | int clipx2 = m_rdp->GetScissor()->m_xl; |
| 434 | int clipx1 = object.Scissor.m_xh; |
| 435 | int clipx2 = object.Scissor.m_xl; |
| 436 | n64_rdp *m_rdp = object.m_rdp; |
| 437 | int tilenum = object.tilenum; |
| 438 | bool flip = object.flip; |
| 434 | 439 | |
| 435 | | SpanParam s = m_s; |
| 436 | | SpanParam t = m_t; |
| 440 | SpanParam s; s.w = extent.param[SPAN_S].start; |
| 441 | SpanParam t; t.w = extent.param[SPAN_T].start; |
| 437 | 442 | |
| 438 | | int ds = m_rdp->m_span_ds / 4; |
| 439 | | int dt = m_rdp->m_span_dt / 4; |
| 443 | int ds = object.SpanBase.m_span_ds / 4; |
| 444 | int dt = object.SpanBase.m_span_dt / 4; |
| 440 | 445 | int dsinc = flip ? (ds) : -ds; |
| 441 | 446 | int dtinc = flip ? (dt) : -dt; |
| 442 | 447 | int xinc = flip ? 1 : -1; |
| 443 | 448 | |
| 444 | | int fb_index = m_rdp->MiscState.FBWidth * index; |
| 449 | int fb_index = object.MiscState.FBWidth * scanline; |
| 445 | 450 | |
| 446 | | int xstart = m_lx; |
| 447 | | int xend = m_unscissored_rx; |
| 448 | | int xend_scissored = m_rx; |
| 451 | rdp_span_aux *userdata = (rdp_span_aux*)extent.userdata; |
| 452 | int xstart = extent.startx; |
| 453 | int xend = userdata->m_unscissored_rx; |
| 454 | int xend_scissored = extent.stopx; |
| 449 | 455 | |
| 450 | 456 | int x = xend; |
| 451 | 457 | |
| r14423 | r14424 | |
| 459 | 465 | { |
| 460 | 466 | INT32 sss = s.h.h; |
| 461 | 467 | INT32 sst = t.h.h; |
| 462 | | m_rdp->TexPipe.Copy(&m_rdp->Texel0Color, sss, sst, tilenum); |
| 468 | m_rdp->TexPipe.Copy(&userdata->Texel0Color, sss, sst, tilenum, object, userdata); |
| 463 | 469 | |
| 464 | 470 | UINT32 curpixel = fb_index + x; |
| 465 | | m_rdp->MiscState.CurrentPixCvg = m_rdp->Texel0Color.i.a ? 7 : 0; |
| 466 | | if ((m_rdp->Texel0Color.i.a != 0) || (!m_rdp->OtherModes.alpha_compare_en)) |
| 471 | if ((userdata->Texel0Color.i.a != 0) || (!object.OtherModes.alpha_compare_en)) |
| 467 | 472 | { |
| 468 | | m_rdp->Framebuffer.Copy(curpixel, m_rdp->Texel0Color.i.r, m_rdp->Texel0Color.i.g, m_rdp->Texel0Color.i.b); |
| 473 | ((this)->*(_Copy[object.MiscState.FBSize - 2]))(curpixel, userdata->Texel0Color.i.r, userdata->Texel0Color.i.g, userdata->Texel0Color.i.b, userdata->Texel0Color.i.a ? 7 : 0, object); |
| 469 | 474 | } |
| 470 | 475 | } |
| 471 | 476 | |
| r14423 | r14424 | |
| 475 | 480 | } |
| 476 | 481 | } |
| 477 | 482 | |
| 478 | | void Span::DrawFill(int index, int tilenum, bool flip) |
| 483 | void n64_rdp::SpanDrawFill(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid) |
| 479 | 484 | { |
| 480 | | int clipx1 = m_rdp->GetScissor()->m_xh; |
| 481 | | int clipx2 = m_rdp->GetScissor()->m_xl; |
| 485 | bool flip = object.flip; |
| 482 | 486 | |
| 487 | int clipx1 = object.Scissor.m_xh; |
| 488 | int clipx2 = object.Scissor.m_xl; |
| 489 | |
| 483 | 490 | int xinc = flip ? 1 : -1; |
| 484 | 491 | |
| 485 | | int fb_index = m_rdp->MiscState.FBWidth * index; |
| 492 | int fb_index = object.MiscState.FBWidth * scanline; |
| 486 | 493 | |
| 487 | | int xstart = m_lx; |
| 488 | | int xend_scissored = m_rx; |
| 494 | int xstart = extent.startx; |
| 495 | int xend_scissored = extent.stopx; |
| 489 | 496 | |
| 490 | 497 | int x = xend_scissored; |
| 491 | 498 | |
| r14423 | r14424 | |
| 495 | 502 | { |
| 496 | 503 | if (x >= clipx1 && x < clipx2) |
| 497 | 504 | { |
| 498 | | UINT32 curpixel = fb_index + x; |
| 499 | | m_rdp->Framebuffer.Fill(curpixel); |
| 505 | ((this)->*(_Fill[object.MiscState.FBSize - 2]))(fb_index + x, object); |
| 500 | 506 | } |
| 501 | 507 | |
| 502 | 508 | x += xinc; |
| 503 | 509 | } |
| 504 | 510 | } |
| 505 | | |
| 506 | | } |
| 507 | | |
| 508 | | } |
src/mame/video/n64.c
| r14423 | r14424 | |
| 36 | 36 | // The functions in this file should be moved into the parent Processor class. |
| 37 | 37 | #include "rdpfiltr.c" |
| 38 | 38 | |
| 39 | | namespace N64 |
| 39 | void n64_rdp::GetAlphaCvg(UINT8 *comb_alpha, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 40 | 40 | { |
| 41 | | |
| 42 | | namespace RDP |
| 43 | | { |
| 44 | | |
| 45 | | void Processor::GetAlphaCvg(UINT8 *comb_alpha) |
| 46 | | { |
| 47 | 41 | INT32 temp = *comb_alpha; |
| 48 | | INT32 temp2 = MiscState.CurrentPixCvg; |
| 42 | INT32 temp2 = userdata->CurrentPixCvg; |
| 49 | 43 | INT32 temp3 = 0; |
| 50 | 44 | |
| 51 | | if (OtherModes.cvg_times_alpha) |
| 45 | if (object.OtherModes.cvg_times_alpha) |
| 52 | 46 | { |
| 53 | 47 | temp3 = (temp * temp2) + 4; |
| 54 | | MiscState.CurrentPixCvg = (temp3 >> 8) & 0xf; |
| 55 | | } |
| 56 | | if (OtherModes.alpha_cvg_select) |
| 48 | userdata->CurrentPixCvg = (temp3 >> 8) & 0xf; |
| 49 | } |
| 50 | if (object.OtherModes.alpha_cvg_select) |
| 57 | 51 | { |
| 58 | 52 | temp = (OtherModes.cvg_times_alpha) ? (temp3 >> 3) : (temp2 << 5); |
| 59 | 53 | } |
| r14423 | r14424 | |
| 66 | 60 | |
| 67 | 61 | /*****************************************************************************/ |
| 68 | 62 | |
| 69 | | void Processor::VideoUpdate(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 63 | void n64_rdp::VideoUpdate(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 70 | 64 | { |
| 71 | 65 | switch(n64->vi_control & 0x3) |
| 72 | 66 | { |
| r14423 | r14424 | |
| 84 | 78 | } |
| 85 | 79 | } |
| 86 | 80 | |
| 87 | | void Processor::VideoUpdate16(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 81 | void n64_rdp::VideoUpdate16(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 88 | 82 | { |
| 89 | 83 | //int fsaa = (((n64->vi_control >> 8) & 3) < 2); |
| 90 | 84 | //int divot = (n64->vi_control >> 4) & 1; |
| r14423 | r14424 | |
| 95 | 89 | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot); |
| 96 | 90 | |
| 97 | 91 | UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; |
| 98 | | UINT32 hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1; |
| 99 | | UINT8* hidden_buffer = &HiddenBits[hb]; |
| 92 | //UINT32 hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1; |
| 93 | //UINT8* hidden_buffer = &HiddenBits[hb]; |
| 100 | 94 | |
| 101 | 95 | INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff); |
| 102 | 96 | float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10)); |
| r14423 | r14424 | |
| 118 | 112 | hres = 640; |
| 119 | 113 | } |
| 120 | 114 | |
| 121 | | if (vres > bitmap.height()) // makes Perfect Dark boot w/o crashing |
| 122 | | { |
| 123 | | vres = bitmap.height(); |
| 124 | | } |
| 125 | | |
| 126 | 115 | UINT32 pixels = 0; |
| 127 | 116 | |
| 128 | 117 | if (frame_buffer) |
| r14423 | r14424 | |
| 137 | 126 | //int r, g, b; |
| 138 | 127 | |
| 139 | 128 | UINT16 pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; |
| 140 | | MiscState.CurrentPixCvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3); |
| 129 | //MiscState.CurrentPixCvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3); |
| 141 | 130 | |
| 142 | 131 | //if(divot) |
| 143 | 132 | //{ |
| 144 | | // if(i > 0 && i < (hres - 1)) |
| 145 | | // { |
| 146 | | // prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3); |
| 147 | | // next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3); |
| 148 | | // } |
| 133 | // if(i > 0 && i < (hres - 1)) |
| 134 | // { |
| 135 | // prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3); |
| 136 | // next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3); |
| 137 | // } |
| 149 | 138 | //} |
| 150 | 139 | c.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); |
| 151 | 140 | c.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); |
| r14423 | r14424 | |
| 223 | 212 | } |
| 224 | 213 | } |
| 225 | 214 | |
| 226 | | void Processor::VideoUpdate32(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 215 | void n64_rdp::VideoUpdate32(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 227 | 216 | { |
| 228 | 217 | int gamma = (n64->vi_control >> 3) & 1; |
| 229 | 218 | int gamma_dither = (n64->vi_control >> 2) & 1; |
| r14423 | r14424 | |
| 306 | 295 | |
| 307 | 296 | /*****************************************************************************/ |
| 308 | 297 | |
| 309 | | void Processor::TCDivNoPersp(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 298 | void n64_rdp::TCDivNoPersp(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 310 | 299 | { |
| 311 | 300 | *sss = (SIGN16(ss)) & 0x1ffff; |
| 312 | 301 | *sst = (SIGN16(st)) & 0x1ffff; |
| 313 | 302 | } |
| 314 | 303 | |
| 315 | | void Processor::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 304 | void n64_rdp::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 316 | 305 | { |
| 317 | 306 | int w_carry = 0; |
| 318 | 307 | if ((sw & 0x8000) || !(sw & 0x7fff)) |
| r14423 | r14424 | |
| 337 | 326 | |
| 338 | 327 | int sprod = SIGN16(ss) * tlu_rcp; |
| 339 | 328 | int tprod = SIGN16(st) * tlu_rcp; |
| 340 | | int tempmask = ((1 << (shift + 1)) - 1) << (29 - shift);//tc.c,658 |
| 341 | | int shift_value = 13 - shift;//tc.c,653 |
| 329 | int tempmask = ((1 << (shift + 1)) - 1) << (29 - shift); |
| 330 | int shift_value = 13 - shift; |
| 342 | 331 | |
| 343 | | int outofbounds_s = sprod & tempmask;//tc.c, 661 |
| 332 | int outofbounds_s = sprod & tempmask; |
| 344 | 333 | int outofbounds_t = tprod & tempmask; |
| 345 | | if (shift == 0xe)//tc.c, 664 |
| 334 | if (shift == 0xe) |
| 346 | 335 | { |
| 347 | | *sss = sprod << 1;//sw, tw ????? ?? ?????????? |
| 336 | *sss = sprod << 1; |
| 348 | 337 | *sst = tprod << 1; |
| 349 | 338 | } |
| 350 | 339 | else |
| r14423 | r14424 | |
| 389 | 378 | *sst = (*sst & 0x1ffff) | (over_s << 18) | (under_s << 17); |
| 390 | 379 | } |
| 391 | 380 | |
| 392 | | INT32 Processor::ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 381 | INT32 n64_rdp::ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 393 | 382 | { |
| 394 | 383 | a = KURT_AKELEY_SIGN9(a); |
| 395 | 384 | b = KURT_AKELEY_SIGN9(b); |
| r14423 | r14424 | |
| 401 | 390 | return a; |
| 402 | 391 | } |
| 403 | 392 | |
| 404 | | INT32 Processor::AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 393 | INT32 n64_rdp::AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 405 | 394 | { |
| 406 | 395 | a = KURT_AKELEY_SIGN9(a); |
| 407 | 396 | b = KURT_AKELEY_SIGN9(b); |
| r14423 | r14424 | |
| 413 | 402 | return a; |
| 414 | 403 | } |
| 415 | 404 | |
| 416 | | void Processor::ColorCombiner1Cycle(bool noisecompute) |
| 405 | void n64_rdp::ColorCombiner1Cycle(rdp_span_aux *userdata) |
| 417 | 406 | { |
| 418 | | if (noisecompute) |
| 419 | | { |
| 420 | | NoiseColor.i.r = NoiseColor.i.g = NoiseColor.i.b = machine().rand() & 0xff; // Not accurate... |
| 421 | | } |
| 407 | userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = GetRandom() << 3; // Not accurate |
| 422 | 408 | |
| 423 | | PixelColor.i.r = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_r[1],*ColorInputs.combiner_rgbsub_b_r[1],*ColorInputs.combiner_rgbmul_r[1],*ColorInputs.combiner_rgbadd_r[1]); |
| 424 | | PixelColor.i.g = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_g[1],*ColorInputs.combiner_rgbsub_b_g[1],*ColorInputs.combiner_rgbmul_g[1],*ColorInputs.combiner_rgbadd_g[1]); |
| 425 | | PixelColor.i.b = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_b[1],*ColorInputs.combiner_rgbsub_b_b[1],*ColorInputs.combiner_rgbmul_b[1],*ColorInputs.combiner_rgbadd_b[1]); |
| 426 | | PixelColor.i.a = AlphaCombinerEquation(*ColorInputs.combiner_alphasub_a[1],*ColorInputs.combiner_alphasub_b[1],*ColorInputs.combiner_alphamul[1],*ColorInputs.combiner_alphaadd[1]); |
| 427 | | |
| 428 | | //Alpha coverage combiner |
| 429 | | GetAlphaCvg(&PixelColor.i.a); |
| 409 | userdata->PixelColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[1],*userdata->ColorInputs.combiner_rgbsub_b_r[1],*userdata->ColorInputs.combiner_rgbmul_r[1],*userdata->ColorInputs.combiner_rgbadd_r[1]); |
| 410 | userdata->PixelColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[1],*userdata->ColorInputs.combiner_rgbsub_b_g[1],*userdata->ColorInputs.combiner_rgbmul_g[1],*userdata->ColorInputs.combiner_rgbadd_g[1]); |
| 411 | userdata->PixelColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[1],*userdata->ColorInputs.combiner_rgbsub_b_b[1],*userdata->ColorInputs.combiner_rgbmul_b[1],*userdata->ColorInputs.combiner_rgbadd_b[1]); |
| 412 | userdata->PixelColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[1],*userdata->ColorInputs.combiner_alphasub_b[1],*userdata->ColorInputs.combiner_alphamul[1],*userdata->ColorInputs.combiner_alphaadd[1]); |
| 430 | 413 | } |
| 431 | 414 | |
| 432 | | void Processor::ColorCombiner2Cycle(bool noisecompute) |
| 415 | void n64_rdp::ColorCombiner2Cycle(rdp_span_aux *userdata) |
| 433 | 416 | { |
| 434 | | if (noisecompute) |
| 435 | | { |
| 436 | | NoiseColor.i.r = NoiseColor.i.g = NoiseColor.i.b = machine().rand() & 0xff; // HACK |
| 437 | | } |
| 417 | userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = GetRandom() << 3; // Not accurate |
| 418 | userdata->CombinedColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[0], |
| 419 | *userdata->ColorInputs.combiner_rgbsub_b_r[0], |
| 420 | *userdata->ColorInputs.combiner_rgbmul_r[0], |
| 421 | *userdata->ColorInputs.combiner_rgbadd_r[0]); |
| 422 | userdata->CombinedColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[0], |
| 423 | *userdata->ColorInputs.combiner_rgbsub_b_g[0], |
| 424 | *userdata->ColorInputs.combiner_rgbmul_g[0], |
| 425 | *userdata->ColorInputs.combiner_rgbadd_g[0]); |
| 426 | userdata->CombinedColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[0], |
| 427 | *userdata->ColorInputs.combiner_rgbsub_b_b[0], |
| 428 | *userdata->ColorInputs.combiner_rgbmul_b[0], |
| 429 | *userdata->ColorInputs.combiner_rgbadd_b[0]); |
| 430 | userdata->CombinedColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[0], |
| 431 | *userdata->ColorInputs.combiner_alphasub_b[0], |
| 432 | *userdata->ColorInputs.combiner_alphamul[0], |
| 433 | *userdata->ColorInputs.combiner_alphaadd[0]); |
| 438 | 434 | |
| 439 | | CombinedColor.i.r = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_r[0],*ColorInputs.combiner_rgbsub_b_r[0],*ColorInputs.combiner_rgbmul_r[0],*ColorInputs.combiner_rgbadd_r[0]); |
| 440 | | CombinedColor.i.g = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_g[0],*ColorInputs.combiner_rgbsub_b_g[0],*ColorInputs.combiner_rgbmul_g[0],*ColorInputs.combiner_rgbadd_g[0]); |
| 441 | | CombinedColor.i.b = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_b[0],*ColorInputs.combiner_rgbsub_b_b[0],*ColorInputs.combiner_rgbmul_b[0],*ColorInputs.combiner_rgbadd_b[0]); |
| 442 | | CombinedColor.i.a = AlphaCombinerEquation(*ColorInputs.combiner_alphasub_a[0],*ColorInputs.combiner_alphasub_b[0],*ColorInputs.combiner_alphamul[0],*ColorInputs.combiner_alphaadd[0]); |
| 435 | userdata->Texel0Color = userdata->Texel1Color; |
| 436 | userdata->Texel1Color = userdata->NextTexelColor; |
| 443 | 437 | |
| 444 | | Texel0Color = Texel1Color; |
| 445 | | Texel1Color = NextTexelColor; |
| 446 | | |
| 447 | | PixelColor.i.r = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_r[1],*ColorInputs.combiner_rgbsub_b_r[1],*ColorInputs.combiner_rgbmul_r[1],*ColorInputs.combiner_rgbadd_r[1]); |
| 448 | | PixelColor.i.g = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_g[1],*ColorInputs.combiner_rgbsub_b_g[1],*ColorInputs.combiner_rgbmul_g[1],*ColorInputs.combiner_rgbadd_g[1]); |
| 449 | | PixelColor.i.b = ColorCombinerEquation(*ColorInputs.combiner_rgbsub_a_b[1],*ColorInputs.combiner_rgbsub_b_b[1],*ColorInputs.combiner_rgbmul_b[1],*ColorInputs.combiner_rgbadd_b[1]); |
| 450 | | PixelColor.i.a = AlphaCombinerEquation(*ColorInputs.combiner_alphasub_a[1],*ColorInputs.combiner_alphasub_b[1],*ColorInputs.combiner_alphamul[1],*ColorInputs.combiner_alphaadd[1]); |
| 451 | | |
| 452 | | GetAlphaCvg(&PixelColor.i.a); |
| 438 | userdata->PixelColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[1], |
| 439 | *userdata->ColorInputs.combiner_rgbsub_b_r[1], |
| 440 | *userdata->ColorInputs.combiner_rgbmul_r[1], |
| 441 | *userdata->ColorInputs.combiner_rgbadd_r[1]); |
| 442 | userdata->PixelColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[1], |
| 443 | *userdata->ColorInputs.combiner_rgbsub_b_g[1], |
| 444 | *userdata->ColorInputs.combiner_rgbmul_g[1], |
| 445 | *userdata->ColorInputs.combiner_rgbadd_g[1]); |
| 446 | userdata->PixelColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[1], |
| 447 | *userdata->ColorInputs.combiner_rgbsub_b_b[1], |
| 448 | *userdata->ColorInputs.combiner_rgbmul_b[1], |
| 449 | *userdata->ColorInputs.combiner_rgbadd_b[1]); |
| 450 | userdata->PixelColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[1], |
| 451 | *userdata->ColorInputs.combiner_alphasub_b[1], |
| 452 | *userdata->ColorInputs.combiner_alphamul[1], |
| 453 | *userdata->ColorInputs.combiner_alphaadd[1]); |
| 453 | 454 | } |
| 454 | 455 | |
| 455 | | void Processor::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 456 | void n64_rdp::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 456 | 457 | { |
| 457 | 458 | switch (code & 0xf) |
| 458 | 459 | { |
| 459 | | case 0: *input_r = &CombinedColor.i.r; *input_g = &CombinedColor.i.g; *input_b = &CombinedColor.i.b; break; |
| 460 | | case 1: *input_r = &Texel0Color.i.r; *input_g = &Texel0Color.i.g; *input_b = &Texel0Color.i.b; break; |
| 461 | | case 2: *input_r = &Texel1Color.i.r; *input_g = &Texel1Color.i.g; *input_b = &Texel1Color.i.b; break; |
| 462 | | case 3: *input_r = &PrimColor.i.r; *input_g = &PrimColor.i.g; *input_b = &PrimColor.i.b; break; |
| 463 | | case 4: *input_r = &ShadeColor.i.r; *input_g = &ShadeColor.i.g; *input_b = &ShadeColor.i.b; break; |
| 464 | | case 5: *input_r = &EnvColor.i.r; *input_g = &EnvColor.i.g; *input_b = &EnvColor.i.b; break; |
| 465 | | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 466 | | case 7: *input_r = &NoiseColor.i.r; *input_g = &NoiseColor.i.g; *input_b = &NoiseColor.i.b; break; |
| 460 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 461 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 462 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 463 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 464 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 465 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 466 | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 467 | case 7: *input_r = &userdata->NoiseColor.i.r; *input_g = &userdata->NoiseColor.i.g; *input_b = &userdata->NoiseColor.i.b; break; |
| 467 | 468 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
| 468 | 469 | { |
| 469 | 470 | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| r14423 | r14424 | |
| 471 | 472 | } |
| 472 | 473 | } |
| 473 | 474 | |
| 474 | | void Processor::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 475 | void n64_rdp::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 475 | 476 | { |
| 476 | 477 | switch (code & 0xf) |
| 477 | 478 | { |
| 478 | | case 0: *input_r = &CombinedColor.i.r; *input_g = &CombinedColor.i.g; *input_b = &CombinedColor.i.b; break; |
| 479 | | case 1: *input_r = &Texel0Color.i.r; *input_g = &Texel0Color.i.g; *input_b = &Texel0Color.i.b; break; |
| 480 | | case 2: *input_r = &Texel1Color.i.r; *input_g = &Texel1Color.i.g; *input_b = &Texel1Color.i.b; break; |
| 481 | | case 3: *input_r = &PrimColor.i.r; *input_g = &PrimColor.i.g; *input_b = &PrimColor.i.b; break; |
| 482 | | case 4: *input_r = &ShadeColor.i.r; *input_g = &ShadeColor.i.g; *input_b = &ShadeColor.i.b; break; |
| 483 | | case 5: *input_r = &EnvColor.i.r; *input_g = &EnvColor.i.g; *input_b = &EnvColor.i.b; break; |
| 479 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 480 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 481 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 482 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 483 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 484 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 484 | 485 | case 6: fatalerror("SET_SUBB_RGB_INPUT: key_center\n"); break; |
| 485 | 486 | case 7: *input_r = (UINT8*)&m_k4; *input_g = (UINT8*)&m_k4; *input_b = (UINT8*)&m_k4; break; |
| 486 | 487 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
| r14423 | r14424 | |
| 490 | 491 | } |
| 491 | 492 | } |
| 492 | 493 | |
| 493 | | void Processor::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 494 | void n64_rdp::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 494 | 495 | { |
| 495 | 496 | switch (code & 0x1f) |
| 496 | 497 | { |
| 497 | | case 0: *input_r = &CombinedColor.i.r; *input_g = &CombinedColor.i.g; *input_b = &CombinedColor.i.b; break; |
| 498 | | case 1: *input_r = &Texel0Color.i.r; *input_g = &Texel0Color.i.g; *input_b = &Texel0Color.i.b; break; |
| 499 | | case 2: *input_r = &Texel1Color.i.r; *input_g = &Texel1Color.i.g; *input_b = &Texel1Color.i.b; break; |
| 500 | | case 3: *input_r = &PrimColor.i.r; *input_g = &PrimColor.i.g; *input_b = &PrimColor.i.b; break; |
| 501 | | case 4: *input_r = &ShadeColor.i.r; *input_g = &ShadeColor.i.g; *input_b = &ShadeColor.i.b; break; |
| 502 | | case 5: *input_r = &EnvColor.i.r; *input_g = &EnvColor.i.g; *input_b = &EnvColor.i.b; break; |
| 503 | | case 6: *input_r = &KeyScale.i.r; *input_g = &KeyScale.i.g; *input_b = &KeyScale.i.b; break; |
| 504 | | case 7: *input_r = &CombinedColor.i.a; *input_g = &CombinedColor.i.a; *input_b = &CombinedColor.i.a; break; |
| 505 | | case 8: *input_r = &Texel0Color.i.a; *input_g = &Texel0Color.i.a; *input_b = &Texel0Color.i.a; break; |
| 506 | | case 9: *input_r = &Texel1Color.i.a; *input_g = &Texel1Color.i.a; *input_b = &Texel1Color.i.a; break; |
| 507 | | case 10: *input_r = &PrimColor.i.a; *input_g = &PrimColor.i.a; *input_b = &PrimColor.i.a; break; |
| 508 | | case 11: *input_r = &ShadeColor.i.a; *input_g = &ShadeColor.i.a; *input_b = &ShadeColor.i.a; break; |
| 509 | | case 12: *input_r = &EnvColor.i.a; *input_g = &EnvColor.i.a; *input_b = &EnvColor.i.a; break; |
| 510 | | case 13: *input_r = &LODFraction; *input_g = &LODFraction; *input_b = &LODFraction; break; |
| 511 | | case 14: *input_r = &PrimLODFraction; *input_g = &PrimLODFraction; *input_b = &PrimLODFraction; break; |
| 512 | | case 15: *input_r = (UINT8*)&m_k5; *input_g = (UINT8*)&m_k5; *input_b = (UINT8*)&m_k5; break; |
| 498 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 499 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 500 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 501 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 502 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 503 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 504 | case 6: *input_r = &userdata->KeyScale.i.r; *input_g = &userdata->KeyScale.i.g; *input_b = &userdata->KeyScale.i.b; break; |
| 505 | case 7: *input_r = &userdata->CombinedColor.i.a; *input_g = &userdata->CombinedColor.i.a; *input_b = &userdata->CombinedColor.i.a; break; |
| 506 | case 8: *input_r = &userdata->Texel0Color.i.a; *input_g = &userdata->Texel0Color.i.a; *input_b = &userdata->Texel0Color.i.a; break; |
| 507 | case 9: *input_r = &userdata->Texel1Color.i.a; *input_g = &userdata->Texel1Color.i.a; *input_b = &userdata->Texel1Color.i.a; break; |
| 508 | case 10: *input_r = &userdata->PrimColor.i.a; *input_g = &userdata->PrimColor.i.a; *input_b = &userdata->PrimColor.i.a; break; |
| 509 | case 11: *input_r = &userdata->ShadeColor.i.a; *input_g = &userdata->ShadeColor.i.a; *input_b = &userdata->ShadeColor.i.a; break; |
| 510 | case 12: *input_r = &userdata->EnvColor.i.a; *input_g = &userdata->EnvColor.i.a; *input_b = &userdata->EnvColor.i.a; break; |
| 511 | case 13: *input_r = &userdata->LODFraction; *input_g = &userdata->LODFraction; *input_b = &userdata->LODFraction; break; |
| 512 | case 14: *input_r = &userdata->PrimLODFraction; *input_g = &userdata->PrimLODFraction; *input_b = &userdata->PrimLODFraction; break; |
| 513 | case 15: *input_r = (UINT8*)&m_k5; *input_g = (UINT8*)&m_k5; *input_b = (UINT8*)&m_k5; break; |
| 513 | 514 | case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: |
| 514 | 515 | case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: |
| 515 | 516 | { |
| r14423 | r14424 | |
| 518 | 519 | } |
| 519 | 520 | } |
| 520 | 521 | |
| 521 | | void Processor::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code) |
| 522 | void n64_rdp::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 522 | 523 | { |
| 523 | 524 | switch (code & 0x7) |
| 524 | 525 | { |
| 525 | | case 0: *input_r = &CombinedColor.i.r; *input_g = &CombinedColor.i.g; *input_b = &CombinedColor.i.b; break; |
| 526 | | case 1: *input_r = &Texel0Color.i.r; *input_g = &Texel0Color.i.g; *input_b = &Texel0Color.i.b; break; |
| 527 | | case 2: *input_r = &Texel1Color.i.r; *input_g = &Texel1Color.i.g; *input_b = &Texel1Color.i.b; break; |
| 528 | | case 3: *input_r = &PrimColor.i.r; *input_g = &PrimColor.i.g; *input_b = &PrimColor.i.b; break; |
| 529 | | case 4: *input_r = &ShadeColor.i.r; *input_g = &ShadeColor.i.g; *input_b = &ShadeColor.i.b; break; |
| 530 | | case 5: *input_r = &EnvColor.i.r; *input_g = &EnvColor.i.g; *input_b = &EnvColor.i.b; break; |
| 531 | | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 532 | | case 7: *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 526 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 527 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 528 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 529 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 530 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 531 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 532 | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 533 | case 7: *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 533 | 534 | } |
| 534 | 535 | } |
| 535 | 536 | |
| 536 | | void Processor::SetSubInputAlpha(UINT8 **input, int code) |
| 537 | void n64_rdp::SetSubInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata) |
| 537 | 538 | { |
| 538 | 539 | switch (code & 0x7) |
| 539 | 540 | { |
| 540 | | case 0: *input = &CombinedColor.i.a; break; |
| 541 | | case 1: *input = &Texel0Color.i.a; break; |
| 542 | | case 2: *input = &Texel1Color.i.a; break; |
| 543 | | case 3: *input = &PrimColor.i.a; break; |
| 544 | | case 4: *input = &ShadeColor.i.a; break; |
| 545 | | case 5: *input = &EnvColor.i.a; break; |
| 541 | case 0: *input = &userdata->CombinedColor.i.a; break; |
| 542 | case 1: *input = &userdata->Texel0Color.i.a; break; |
| 543 | case 2: *input = &userdata->Texel1Color.i.a; break; |
| 544 | case 3: *input = &userdata->PrimColor.i.a; break; |
| 545 | case 4: *input = &userdata->ShadeColor.i.a; break; |
| 546 | case 5: *input = &userdata->EnvColor.i.a; break; |
| 546 | 547 | case 6: *input = &OneColor.i.a; break; |
| 547 | 548 | case 7: *input = &ZeroColor.i.a; break; |
| 548 | 549 | } |
| 549 | 550 | } |
| 550 | 551 | |
| 551 | | void Processor::SetMulInputAlpha(UINT8 **input, int code) |
| 552 | void n64_rdp::SetMulInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata) |
| 552 | 553 | { |
| 553 | 554 | switch (code & 0x7) |
| 554 | 555 | { |
| 555 | | case 0: *input = &LODFraction; break; |
| 556 | | case 1: *input = &Texel0Color.i.a; break; |
| 557 | | case 2: *input = &Texel1Color.i.a; break; |
| 558 | | case 3: *input = &PrimColor.i.a; break; |
| 559 | | case 4: *input = &ShadeColor.i.a; break; |
| 560 | | case 5: *input = &EnvColor.i.a; break; |
| 561 | | case 6: *input = &PrimLODFraction; break; |
| 556 | case 0: *input = &userdata->LODFraction; break; |
| 557 | case 1: *input = &userdata->Texel0Color.i.a; break; |
| 558 | case 2: *input = &userdata->Texel1Color.i.a; break; |
| 559 | case 3: *input = &userdata->PrimColor.i.a; break; |
| 560 | case 4: *input = &userdata->ShadeColor.i.a; break; |
| 561 | case 5: *input = &userdata->EnvColor.i.a; break; |
| 562 | case 6: *input = &userdata->PrimLODFraction; break; |
| 562 | 563 | case 7: *input = &ZeroColor.i.a; break; |
| 563 | 564 | } |
| 564 | 565 | } |
| 565 | 566 | |
| 566 | | void Processor::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b) |
| 567 | void n64_rdp::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b, rdp_span_aux *userdata) |
| 567 | 568 | { |
| 568 | 569 | switch (a & 0x3) |
| 569 | 570 | { |
| r14423 | r14424 | |
| 571 | 572 | { |
| 572 | 573 | if (cycle == 0) |
| 573 | 574 | { |
| 574 | | *input_r = &PixelColor.i.r; |
| 575 | | *input_g = &PixelColor.i.g; |
| 576 | | *input_b = &PixelColor.i.b; |
| 575 | *input_r = &userdata->PixelColor.i.r; |
| 576 | *input_g = &userdata->PixelColor.i.g; |
| 577 | *input_b = &userdata->PixelColor.i.b; |
| 577 | 578 | } |
| 578 | 579 | else |
| 579 | 580 | { |
| 580 | | *input_r = &BlendedPixelColor.i.r; |
| 581 | | *input_g = &BlendedPixelColor.i.g; |
| 582 | | *input_b = &BlendedPixelColor.i.b; |
| 581 | *input_r = &userdata->BlendedPixelColor.i.r; |
| 582 | *input_g = &userdata->BlendedPixelColor.i.g; |
| 583 | *input_b = &userdata->BlendedPixelColor.i.b; |
| 583 | 584 | } |
| 584 | 585 | break; |
| 585 | 586 | } |
| 586 | 587 | |
| 587 | 588 | case 1: |
| 588 | 589 | { |
| 589 | | *input_r = &MemoryColor.i.r; |
| 590 | | *input_g = &MemoryColor.i.g; |
| 591 | | *input_b = &MemoryColor.i.b; |
| 590 | *input_r = &userdata->MemoryColor.i.r; |
| 591 | *input_g = &userdata->MemoryColor.i.g; |
| 592 | *input_b = &userdata->MemoryColor.i.b; |
| 592 | 593 | break; |
| 593 | 594 | } |
| 594 | 595 | |
| 595 | 596 | case 2: |
| 596 | 597 | { |
| 597 | | *input_r = &BlendColor.i.r; |
| 598 | | *input_g = &BlendColor.i.g; |
| 599 | | *input_b = &BlendColor.i.b; |
| 598 | *input_r = &userdata->BlendColor.i.r; |
| 599 | *input_g = &userdata->BlendColor.i.g; |
| 600 | *input_b = &userdata->BlendColor.i.b; |
| 600 | 601 | break; |
| 601 | 602 | } |
| 602 | 603 | |
| 603 | 604 | case 3: |
| 604 | 605 | { |
| 605 | | *input_r = &FogColor.i.r; |
| 606 | | *input_g = &FogColor.i.g; |
| 607 | | *input_b = &FogColor.i.b; |
| 606 | *input_r = &userdata->FogColor.i.r; |
| 607 | *input_g = &userdata->FogColor.i.g; |
| 608 | *input_b = &userdata->FogColor.i.b; |
| 608 | 609 | break; |
| 609 | 610 | } |
| 610 | 611 | } |
| r14423 | r14424 | |
| 613 | 614 | { |
| 614 | 615 | switch (b & 0x3) |
| 615 | 616 | { |
| 616 | | case 0: *input_a = &PixelColor.i.a; break; |
| 617 | | case 1: *input_a = &FogColor.i.a; break; |
| 618 | | case 2: *input_a = &ShadeColor.i.a; break; |
| 617 | case 0: *input_a = &userdata->PixelColor.i.a; break; |
| 618 | case 1: *input_a = &userdata->FogColor.i.a; break; |
| 619 | case 2: *input_a = &userdata->ShadeColor.i.a; break; |
| 619 | 620 | case 3: *input_a = &ZeroColor.i.a; break; |
| 620 | 621 | } |
| 621 | 622 | } |
| r14423 | r14424 | |
| 623 | 624 | { |
| 624 | 625 | switch (b & 0x3) |
| 625 | 626 | { |
| 626 | | case 0: *input_a = &InvPixelColor.i.a; break; |
| 627 | | case 1: *input_a = &MemoryColor.i.a; break; |
| 627 | case 0: *input_a = &userdata->InvPixelColor.i.a; break; |
| 628 | case 1: *input_a = &userdata->MemoryColor.i.a; break; |
| 628 | 629 | case 2: *input_a = &OneColor.i.a; break; |
| 629 | 630 | case 3: *input_a = &ZeroColor.i.a; break; |
| 630 | 631 | } |
| 631 | 632 | } |
| 632 | 633 | } |
| 633 | 634 | |
| 634 | | const UINT8 Processor::s_bayer_matrix[16] = |
| 635 | const UINT8 n64_rdp::s_bayer_matrix[16] = |
| 635 | 636 | { /* Bayer matrix */ |
| 636 | 637 | 0, 4, 1, 5, |
| 637 | 638 | 6, 2, 7, 3, |
| r14423 | r14424 | |
| 639 | 640 | 7, 3, 6, 2 |
| 640 | 641 | }; |
| 641 | 642 | |
| 642 | | const UINT8 Processor::s_magic_matrix[16] = |
| 643 | const UINT8 n64_rdp::s_magic_matrix[16] = |
| 643 | 644 | { /* Magic square matrix */ |
| 644 | 645 | 0, 6, 1, 7, |
| 645 | 646 | 4, 2, 5, 3, |
| r14423 | r14424 | |
| 647 | 648 | 7, 1, 6, 0 |
| 648 | 649 | }; |
| 649 | 650 | |
| 650 | | const Processor::ZDecompressEntry Processor::z_dec_table[8] = |
| 651 | const n64_rdp::ZDecompressEntry n64_rdp::z_dec_table[8] = |
| 651 | 652 | { |
| 652 | 653 | { 6, 0x00000 }, |
| 653 | 654 | { 5, 0x20000 }, |
| r14423 | r14424 | |
| 661 | 662 | |
| 662 | 663 | /*****************************************************************************/ |
| 663 | 664 | |
| 664 | | void Processor::z_build_com_table(void) |
| 665 | void n64_rdp::z_build_com_table(void) |
| 665 | 666 | { |
| 666 | 667 | UINT16 altmem = 0; |
| 667 | 668 | for(int z = 0; z < 0x40000; z++) |
| r14423 | r14424 | |
| 819 | 820 | } |
| 820 | 821 | } |
| 821 | 822 | |
| 822 | | void Processor::precalc_cvmask_derivatives(void) |
| 823 | void n64_rdp::precalc_cvmask_derivatives(void) |
| 823 | 824 | { |
| 824 | 825 | const UINT8 yarray[16] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}; |
| 825 | 826 | const UINT8 xarray[16] = {0, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; |
| r14423 | r14424 | |
| 855 | 856 | } |
| 856 | 857 | } |
| 857 | 858 | |
| 858 | | UINT16 Processor::decompress_cvmask_frombyte(UINT8 x) |
| 859 | UINT16 n64_rdp::decompress_cvmask_frombyte(UINT8 x) |
| 859 | 860 | { |
| 860 | 861 | UINT16 y = (x & 1) | ((x & 2) << 1) | ((x & 4) << 3) | ((x & 8) << 4) | |
| 861 | 862 | ((x & 0x10) << 4) | ((x & 0x20) << 5) | ((x & 0x40) << 7) | ((x & 0x80) << 8); |
| 862 | 863 | return y; |
| 863 | 864 | } |
| 864 | 865 | |
| 865 | | void Processor::lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy) |
| 866 | void n64_rdp::lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy, rdp_span_aux *userdata) |
| 866 | 867 | { |
| 867 | 868 | UINT32 index = compressed_cvmasks[mask]; |
| 868 | | MiscState.CurrentPixCvg = cvarray[index].cvg; |
| 869 | | MiscState.CurrentCvgBit = cvarray[index].cvbit; |
| 869 | userdata->CurrentPixCvg = cvarray[index].cvg; |
| 870 | userdata->CurrentCvgBit = cvarray[index].cvbit; |
| 870 | 871 | *offx = cvarray[index].xoff; |
| 871 | 872 | *offy = cvarray[index].yoff; |
| 872 | 873 | } |
| 873 | 874 | |
| 874 | | void Processor::ZStore(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z) |
| 875 | void n64_rdp::ZStore(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z, UINT32 enc) |
| 875 | 876 | { |
| 876 | | UINT16 zval = z_com_table[z & 0x3ffff]|(m_dzpix_enc >> 2); |
| 877 | UINT16 zval = z_com_table[z & 0x3ffff]|(enc >> 2); |
| 877 | 878 | if(zcurpixel <= MEM16_LIMIT) |
| 878 | 879 | { |
| 879 | 880 | ((UINT16*)rdram)[zcurpixel ^ WORD_ADDR_XOR] = zval; |
| 880 | 881 | } |
| 881 | 882 | if(dzcurpixel <= MEM8_LIMIT) |
| 882 | 883 | { |
| 883 | | HiddenBits[dzcurpixel ^ BYTE_ADDR_XOR] = m_dzpix_enc & 3; |
| 884 | HiddenBits[dzcurpixel ^ BYTE_ADDR_XOR] = enc & 3; |
| 884 | 885 | } |
| 885 | 886 | } |
| 886 | 887 | |
| 887 | | INT32 Processor::NormalizeDZPix(INT32 sum) |
| 888 | INT32 n64_rdp::NormalizeDZPix(INT32 sum) |
| 888 | 889 | { |
| 889 | 890 | if (sum & 0xc000) |
| 890 | 891 | { |
| r14423 | r14424 | |
| 904 | 905 | return 0; |
| 905 | 906 | } |
| 906 | 907 | |
| 907 | | UINT32 Processor::ZDecompress(UINT32 zcurpixel) |
| 908 | UINT32 n64_rdp::ZDecompress(UINT32 zcurpixel) |
| 908 | 909 | { |
| 909 | 910 | UINT32 zb = RREADIDX16(zcurpixel); |
| 910 | 911 | return z_complete_dec_table[(zb >> 2) & 0x3fff]; |
| 911 | 912 | } |
| 912 | 913 | |
| 913 | | UINT32 Processor::DZDecompress(UINT32 zcurpixel, UINT32 dzcurpixel) |
| 914 | UINT32 n64_rdp::DZDecompress(UINT32 zcurpixel, UINT32 dzcurpixel) |
| 914 | 915 | { |
| 915 | 916 | UINT16 zval = RREADIDX16(zcurpixel); |
| 916 | 917 | UINT8 dzval = (((dzcurpixel) <= 0x7fffff) ? (HiddenBits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0); |
| r14423 | r14424 | |
| 918 | 919 | return (1 << dz_compressed); |
| 919 | 920 | } |
| 920 | 921 | |
| 921 | | UINT32 Processor::DZCompress(UINT32 value) |
| 922 | UINT32 n64_rdp::DZCompress(UINT32 value) |
| 922 | 923 | { |
| 923 | 924 | INT32 j = 0; |
| 924 | 925 | for (; value > 1; j++, value >>= 1); |
| 925 | 926 | return j; |
| 926 | 927 | } |
| 927 | 928 | |
| 928 | | void Processor::GetDitherValues(int x, int y, int* cdith, int* adith) |
| 929 | void n64_rdp::GetDitherValues(int x, int y, int* cdith, int* adith, const rdp_poly_state& object) |
| 929 | 930 | { |
| 930 | 931 | int dithindex = ((y & 3) << 2) | (x & 3); |
| 931 | | switch((OtherModes.rgb_dither_sel << 2) | OtherModes.alpha_dither_sel) |
| 932 | switch((object.OtherModes.rgb_dither_sel << 2) | object.OtherModes.alpha_dither_sel) |
| 932 | 933 | { |
| 933 | 934 | case 0: |
| 934 | 935 | *adith = *cdith = s_magic_matrix[dithindex]; |
| r14423 | r14424 | |
| 1001 | 1002 | return in; |
| 1002 | 1003 | } |
| 1003 | 1004 | |
| 1004 | | bool Processor::ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix) |
| 1005 | bool n64_rdp::ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 1005 | 1006 | { |
| 1006 | 1007 | bool force_coplanar = false; |
| 1007 | 1008 | sz &= 0x3ffff; |
| r14423 | r14424 | |
| 1011 | 1012 | UINT32 zval; |
| 1012 | 1013 | INT32 rawdzmem; |
| 1013 | 1014 | |
| 1014 | | if (OtherModes.z_compare_en) |
| 1015 | if (object.OtherModes.z_compare_en) |
| 1015 | 1016 | { |
| 1016 | 1017 | oz = ZDecompress(zcurpixel); |
| 1017 | 1018 | dzmem = DZDecompress(zcurpixel, dzcurpixel); |
| r14423 | r14424 | |
| 1026 | 1027 | rawdzmem = 0xf; |
| 1027 | 1028 | } |
| 1028 | 1029 | |
| 1029 | | m_dzpix_enc = DZCompress(dzpix & 0xffff); |
| 1030 | | Blender.ShiftA = CLAMP(m_dzpix_enc - rawdzmem, 0, 4); |
| 1031 | | Blender.ShiftB = CLAMP(rawdzmem - m_dzpix_enc, 0, 4); |
| 1030 | userdata->m_dzpix_enc = DZCompress(dzpix & 0xffff); |
| 1031 | userdata->ShiftA = CLAMP(userdata->m_dzpix_enc - rawdzmem, 0, 4); |
| 1032 | userdata->ShiftB = CLAMP(rawdzmem - userdata->m_dzpix_enc, 0, 4); |
| 1032 | 1033 | |
| 1033 | 1034 | int precision_factor = (zval >> 13) & 0xf; |
| 1034 | 1035 | if (precision_factor < 3) |
| r14423 | r14424 | |
| 1065 | 1066 | farther = true; |
| 1066 | 1067 | } |
| 1067 | 1068 | |
| 1068 | | bool overflow = ((MiscState.CurrentMemCvg + MiscState.CurrentPixCvg) & 8) > 0; |
| 1069 | | Blender.BlendEnable = OtherModes.force_blend || (!overflow && OtherModes.antialias_en && farther); |
| 1070 | | Framebuffer.SetPreWrap(overflow); |
| 1069 | bool overflow = ((userdata->CurrentMemCvg + userdata->CurrentPixCvg) & 8) > 0; |
| 1070 | userdata->BlendEnable = (object.OtherModes.force_blend || (!overflow && object.OtherModes.antialias_en && farther)) ? 1 : 0; |
| 1071 | userdata->PreWrap = overflow; |
| 1071 | 1072 | |
| 1072 | 1073 | int cvgcoeff = 0; |
| 1073 | 1074 | UINT32 dzenc = 0; |
| 1074 | 1075 | |
| 1075 | | if (OtherModes.z_mode == 1 && infront && farther && overflow) |
| 1076 | if (object.OtherModes.z_mode == 1 && infront && farther && overflow) |
| 1076 | 1077 | { |
| 1077 | 1078 | dzenc = DZCompress(dznotshift & 0xffff); |
| 1078 | 1079 | cvgcoeff = ((oz >> dzenc) - (sz >> dzenc)) & 0xf; |
| 1079 | | MiscState.CurrentPixCvg = ((cvgcoeff * MiscState.CurrentPixCvg) >> 3) & 0xf; |
| 1080 | userdata->CurrentPixCvg = ((cvgcoeff * userdata->CurrentPixCvg) >> 3) & 0xf; |
| 1080 | 1081 | } |
| 1081 | 1082 | |
| 1082 | | if (!OtherModes.z_compare_en) |
| 1083 | if (!object.OtherModes.z_compare_en) |
| 1083 | 1084 | { |
| 1084 | 1085 | return true; |
| 1085 | 1086 | } |
| r14423 | r14424 | |
| 1092 | 1093 | nearer = true; |
| 1093 | 1094 | } |
| 1094 | 1095 | |
| 1095 | | switch(OtherModes.z_mode) |
| 1096 | switch(object.OtherModes.z_mode) |
| 1096 | 1097 | { |
| 1097 | 1098 | case 0: |
| 1098 | 1099 | return (max || (overflow ? infront : nearer)); |
| r14423 | r14424 | |
| 1111 | 1112 | return false; |
| 1112 | 1113 | } |
| 1113 | 1114 | |
| 1114 | | UINT32 Processor::GetLog2(UINT32 lod_clamp) |
| 1115 | UINT32 n64_rdp::GetLog2(UINT32 lod_clamp) |
| 1115 | 1116 | { |
| 1116 | 1117 | if (lod_clamp < 2) |
| 1117 | 1118 | { |
| r14423 | r14424 | |
| 1133 | 1134 | |
| 1134 | 1135 | /*****************************************************************************/ |
| 1135 | 1136 | |
| 1136 | | UINT32 N64::RDP::Processor::ReadData(UINT32 address) |
| 1137 | UINT32 n64_rdp::ReadData(UINT32 address) |
| 1137 | 1138 | { |
| 1138 | 1139 | if (m_status & 0x1) // XBUS_DMEM_DMA enabled |
| 1139 | 1140 | { |
| r14423 | r14424 | |
| 1216 | 1217 | 8 // 0x3f, Set_Color_Image |
| 1217 | 1218 | }; |
| 1218 | 1219 | |
| 1219 | | void N64::RDP::Processor::Dasm(char *buffer) |
| 1220 | void n64_rdp::Dasm(char *buffer) |
| 1220 | 1221 | { |
| 1221 | 1222 | int i; |
| 1222 | 1223 | int tile; |
| r14423 | r14424 | |
| 1730 | 1731 | |
| 1731 | 1732 | /*****************************************************************************/ |
| 1732 | 1733 | |
| 1733 | | N64::RDP::Triangle::Triangle(running_machine &machine, bool shade, bool texture, bool zbuffer, bool rect, bool flip) |
| 1734 | | { |
| 1735 | | InitFromData(machine, shade, texture, zbuffer, rect, flip); |
| 1736 | | } |
| 1737 | | |
| 1738 | | void N64::RDP::Triangle::InitFromData(running_machine &machine, bool shade, bool texture, bool zbuffer, bool rect, bool flip) |
| 1739 | | { |
| 1740 | | m_machine = &machine; |
| 1741 | | m_rdp = &(machine.driver_data<_n64_state>())->m_rdp; |
| 1742 | | m_cmd_data = rect ? m_rdp->GetTempRectData() : m_rdp->GetCommandData(); |
| 1743 | | m_shade = shade; |
| 1744 | | m_texture = texture; |
| 1745 | | m_zbuffer = zbuffer; |
| 1746 | | m_rect = rect; |
| 1747 | | } |
| 1748 | | |
| 1749 | 1734 | static UINT32 rightcvghex(UINT32 x, UINT32 fmask) |
| 1750 | 1735 | { |
| 1751 | 1736 | UINT32 stickybit = ((x >> 1) & 0x1fff) > 0; |
| r14423 | r14424 | |
| 1778 | 1763 | } |
| 1779 | 1764 | } |
| 1780 | 1765 | |
| 1781 | | void N64::RDP::Triangle::compute_cvg_noflip(INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl) |
| 1766 | void n64_rdp::compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base) |
| 1782 | 1767 | { |
| 1783 | 1768 | INT32 purgestart = 0xfff; |
| 1784 | 1769 | INT32 purgeend = 0; |
| r14423 | r14424 | |
| 1805 | 1790 | |
| 1806 | 1791 | if (length < 0) return; |
| 1807 | 1792 | |
| 1808 | | memset(&m_rdp->Spans[scanline].m_cvg[purgestart], 0, (length + 1) << 1); |
| 1793 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata; |
| 1794 | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); |
| 1809 | 1795 | |
| 1810 | 1796 | for(int i = 0; i < 4; i++) |
| 1811 | 1797 | { |
| r14423 | r14424 | |
| 1827 | 1813 | { |
| 1828 | 1814 | if (!(minorcurint & ~0x3ff)) |
| 1829 | 1815 | { |
| 1830 | | m_rdp->Spans[scanline].m_cvg[minorcurint] |= (leftcvghex(minorcur, fmask) << maskshift); |
| 1816 | userdata->m_cvg[minorcurint] |= (leftcvghex(minorcur, fmask) << maskshift); |
| 1831 | 1817 | } |
| 1832 | 1818 | if (!(majorcurint & ~0x3ff)) |
| 1833 | 1819 | { |
| 1834 | | m_rdp->Spans[scanline].m_cvg[majorcurint] |= (rightcvghex(majorcur, fmask) << maskshift); |
| 1820 | userdata->m_cvg[majorcurint] |= (rightcvghex(majorcur, fmask) << maskshift); |
| 1835 | 1821 | } |
| 1836 | 1822 | } |
| 1837 | 1823 | else |
| r14423 | r14424 | |
| 1839 | 1825 | if (!(majorcurint & ~0x3ff)) |
| 1840 | 1826 | { |
| 1841 | 1827 | INT32 samecvg = leftcvghex(minorcur, fmask) & rightcvghex(majorcur, fmask); |
| 1842 | | m_rdp->Spans[scanline].m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1828 | userdata->m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1843 | 1829 | } |
| 1844 | 1830 | } |
| 1845 | 1831 | for (; fleft <= fright; fleft++) |
| 1846 | 1832 | { |
| 1847 | | m_rdp->Spans[scanline].m_cvg[fleft] |= fmaskshifted; |
| 1833 | userdata->m_cvg[fleft] |= fmaskshifted; |
| 1848 | 1834 | } |
| 1849 | 1835 | } |
| 1850 | 1836 | } |
| 1851 | 1837 | } |
| 1852 | 1838 | |
| 1853 | | void N64::RDP::Triangle::compute_cvg_flip(INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl) |
| 1839 | void n64_rdp::compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base) |
| 1854 | 1840 | { |
| 1855 | 1841 | INT32 purgestart = 0xfff; |
| 1856 | 1842 | INT32 purgeend = 0; |
| r14423 | r14424 | |
| 1878 | 1864 | |
| 1879 | 1865 | if (length < 0) return; |
| 1880 | 1866 | |
| 1881 | | memset(&m_rdp->Spans[scanline].m_cvg[purgestart], 0, (length + 1) << 1); |
| 1867 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata; |
| 1868 | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); |
| 1882 | 1869 | |
| 1883 | 1870 | for(int i = 0; i < 4; i++) |
| 1884 | 1871 | { |
| r14423 | r14424 | |
| 1900 | 1887 | { |
| 1901 | 1888 | if (!(minorcurint & ~0x3ff)) |
| 1902 | 1889 | { |
| 1903 | | m_rdp->Spans[scanline].m_cvg[minorcurint] |= (rightcvghex(minorcur, fmask) << maskshift); |
| 1890 | userdata->m_cvg[minorcurint] |= (rightcvghex(minorcur, fmask) << maskshift); |
| 1904 | 1891 | } |
| 1905 | 1892 | if (!(majorcurint & ~0x3ff)) |
| 1906 | 1893 | { |
| 1907 | | m_rdp->Spans[scanline].m_cvg[majorcurint] |= (leftcvghex(majorcur, fmask) << maskshift); |
| 1894 | userdata->m_cvg[majorcurint] |= (leftcvghex(majorcur, fmask) << maskshift); |
| 1908 | 1895 | } |
| 1909 | 1896 | } |
| 1910 | 1897 | else |
| r14423 | r14424 | |
| 1912 | 1899 | if (!(majorcurint & ~0x3ff)) |
| 1913 | 1900 | { |
| 1914 | 1901 | INT32 samecvg = rightcvghex(minorcur, fmask) & leftcvghex(majorcur, fmask); |
| 1915 | | m_rdp->Spans[scanline].m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1902 | userdata->m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1916 | 1903 | } |
| 1917 | 1904 | } |
| 1918 | 1905 | for (; fleft <= fright; fleft++) |
| 1919 | 1906 | { |
| 1920 | | m_rdp->Spans[scanline].m_cvg[fleft] |= fmaskshifted; |
| 1907 | userdata->m_cvg[fleft] |= fmaskshifted; |
| 1921 | 1908 | } |
| 1922 | 1909 | } |
| 1923 | 1910 | } |
| 1924 | 1911 | } |
| 1925 | 1912 | |
| 1926 | | void N64::RDP::Triangle::Draw() |
| 1913 | void n64_rdp::DrawTriangle(bool shade, bool texture, bool zbuffer, bool rect) |
| 1927 | 1914 | { |
| 1928 | | UINT32 fifo_index = m_rect ? 0 : m_rdp->GetCurrFIFOIndex(); |
| 1929 | | UINT32 w1 = m_cmd_data[fifo_index + 0]; |
| 1930 | | UINT32 w2 = m_cmd_data[fifo_index + 1]; |
| 1915 | UINT32 *cmd_data = rect ? m_temp_rect_data : m_cmd_data; |
| 1916 | UINT32 fifo_index = rect ? 0 : m_cmd_cur; |
| 1917 | UINT32 w1 = cmd_data[fifo_index + 0]; |
| 1918 | UINT32 w2 = cmd_data[fifo_index + 1]; |
| 1931 | 1919 | |
| 1932 | | int flip = (w1 & 0x800000) ? 1 : 0; |
| 1933 | | m_rdp->MiscState.MaxLevel = ((w1 >> 19) & 7); |
| 1920 | int flip = (w1 & 0x00800000) ? 1 : 0; |
| 1921 | MiscState.MaxLevel = ((w1 >> 19) & 7); |
| 1934 | 1922 | int tilenum = (w1 >> 16) & 0x7; |
| 1935 | 1923 | |
| 1936 | 1924 | int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0; |
| r14423 | r14424 | |
| 1938 | 1926 | int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0; |
| 1939 | 1927 | int dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0; |
| 1940 | 1928 | |
| 1941 | | INT32 maxxmx = 0; |
| 1929 | INT32 maxxmx = 0; // maxxmx / minxhx very opaque names, consider re-naming |
| 1942 | 1930 | INT32 minxmx = 0; |
| 1943 | 1931 | INT32 maxxhx = 0; |
| 1944 | 1932 | INT32 minxhx = 0; |
| r14423 | r14424 | |
| 1946 | 1934 | int shade_base = fifo_index + 8; |
| 1947 | 1935 | int texture_base = fifo_index + 8; |
| 1948 | 1936 | int zbuffer_base = fifo_index + 8; |
| 1949 | | if(m_shade) |
| 1937 | if(shade) |
| 1950 | 1938 | { |
| 1951 | 1939 | texture_base += 16; |
| 1952 | 1940 | zbuffer_base += 16; |
| 1953 | 1941 | } |
| 1954 | | if(m_texture) |
| 1942 | if(texture) |
| 1955 | 1943 | { |
| 1956 | 1944 | zbuffer_base += 16; |
| 1957 | 1945 | } |
| 1958 | 1946 | |
| 1959 | | UINT32 w3 = m_cmd_data[fifo_index + 2]; |
| 1960 | | UINT32 w4 = m_cmd_data[fifo_index + 3]; |
| 1961 | | UINT32 w5 = m_cmd_data[fifo_index + 4]; |
| 1962 | | UINT32 w6 = m_cmd_data[fifo_index + 5]; |
| 1963 | | UINT32 w7 = m_cmd_data[fifo_index + 6]; |
| 1964 | | UINT32 w8 = m_cmd_data[fifo_index + 7]; |
| 1947 | UINT32 w3 = cmd_data[fifo_index + 2]; |
| 1948 | UINT32 w4 = cmd_data[fifo_index + 3]; |
| 1949 | UINT32 w5 = cmd_data[fifo_index + 4]; |
| 1950 | UINT32 w6 = cmd_data[fifo_index + 5]; |
| 1951 | UINT32 w7 = cmd_data[fifo_index + 6]; |
| 1952 | UINT32 w8 = cmd_data[fifo_index + 7]; |
| 1965 | 1953 | |
| 1966 | 1954 | INT32 yl = (w1 & 0x3fff); |
| 1967 | 1955 | INT32 ym = ((w2 >> 16) & 0x3fff); |
| r14423 | r14424 | |
| 1982 | 1970 | if (xm & 0x20000000) xm |= 0xc0000000; |
| 1983 | 1971 | if (xh & 0x20000000) xh |= 0xc0000000; |
| 1984 | 1972 | |
| 1985 | | int r = (m_cmd_data[shade_base+0 ] & 0xffff0000) | ((m_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff); |
| 1986 | | int g = ((m_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+4 ] & 0x0000ffff); |
| 1987 | | int b = (m_cmd_data[shade_base+1 ] & 0xffff0000) | ((m_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff); |
| 1988 | | int a = ((m_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+5 ] & 0x0000ffff); |
| 1989 | | int drdx = (m_cmd_data[shade_base+2 ] & 0xffff0000) | ((m_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff); |
| 1990 | | int dgdx = ((m_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+6 ] & 0x0000ffff); |
| 1991 | | int dbdx = (m_cmd_data[shade_base+3 ] & 0xffff0000) | ((m_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff); |
| 1992 | | int dadx = ((m_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+7 ] & 0x0000ffff); |
| 1993 | | int drde = (m_cmd_data[shade_base+8 ] & 0xffff0000) | ((m_cmd_data[shade_base+12] >> 16) & 0x0000ffff); |
| 1994 | | int dgde = ((m_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+12] & 0x0000ffff); |
| 1995 | | int dbde = (m_cmd_data[shade_base+9 ] & 0xffff0000) | ((m_cmd_data[shade_base+13] >> 16) & 0x0000ffff); |
| 1996 | | int dade = ((m_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+13] & 0x0000ffff); |
| 1997 | | int drdy = (m_cmd_data[shade_base+10] & 0xffff0000) | ((m_cmd_data[shade_base+14] >> 16) & 0x0000ffff); |
| 1998 | | int dgdy = ((m_cmd_data[shade_base+10] << 16) & 0xffff0000) | (m_cmd_data[shade_base+14] & 0x0000ffff); |
| 1999 | | int dbdy = (m_cmd_data[shade_base+11] & 0xffff0000) | ((m_cmd_data[shade_base+15] >> 16) & 0x0000ffff); |
| 2000 | | int dady = ((m_cmd_data[shade_base+11] << 16) & 0xffff0000) | (m_cmd_data[shade_base+15] & 0x0000ffff); |
| 2001 | | int s = (m_cmd_data[texture_base+0 ] & 0xffff0000) | ((m_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff); |
| 2002 | | int t = ((m_cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (m_cmd_data[texture_base+4 ] & 0x0000ffff); |
| 2003 | | int w = (m_cmd_data[texture_base+1 ] & 0xffff0000) | ((m_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff); |
| 2004 | | int dsdx = (m_cmd_data[texture_base+2 ] & 0xffff0000) | ((m_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff); |
| 2005 | | int dtdx = ((m_cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (m_cmd_data[texture_base+6 ] & 0x0000ffff); |
| 2006 | | int dwdx = (m_cmd_data[texture_base+3 ] & 0xffff0000) | ((m_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff); |
| 2007 | | int dsde = (m_cmd_data[texture_base+8 ] & 0xffff0000) | ((m_cmd_data[texture_base+12] >> 16) & 0x0000ffff); |
| 2008 | | int dtde = ((m_cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (m_cmd_data[texture_base+12] & 0x0000ffff); |
| 2009 | | int dwde = (m_cmd_data[texture_base+9 ] & 0xffff0000) | ((m_cmd_data[texture_base+13] >> 16) & 0x0000ffff); |
| 2010 | | int dsdy = (m_cmd_data[texture_base+10] & 0xffff0000) | ((m_cmd_data[texture_base+14] >> 16) & 0x0000ffff); |
| 2011 | | int dtdy = ((m_cmd_data[texture_base+10] << 16) & 0xffff0000) | (m_cmd_data[texture_base+14] & 0x0000ffff); |
| 2012 | | int dwdy = (m_cmd_data[texture_base+11] & 0xffff0000) | ((m_cmd_data[texture_base+15] >> 16) & 0x0000ffff); |
| 2013 | | int z = m_cmd_data[zbuffer_base+0]; |
| 2014 | | int dzdx = m_cmd_data[zbuffer_base+1]; |
| 2015 | | int dzde = m_cmd_data[zbuffer_base+2]; |
| 2016 | | int dzdy = m_cmd_data[zbuffer_base+3]; |
| 1973 | int r = (cmd_data[shade_base+0 ] & 0xffff0000) | ((cmd_data[shade_base+4 ] >> 16) & 0x0000ffff); |
| 1974 | int g = ((cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (cmd_data[shade_base+4 ] & 0x0000ffff); |
| 1975 | int b = (cmd_data[shade_base+1 ] & 0xffff0000) | ((cmd_data[shade_base+5 ] >> 16) & 0x0000ffff); |
| 1976 | int a = ((cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (cmd_data[shade_base+5 ] & 0x0000ffff); |
| 1977 | int drdx = (cmd_data[shade_base+2 ] & 0xffff0000) | ((cmd_data[shade_base+6 ] >> 16) & 0x0000ffff); |
| 1978 | int dgdx = ((cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (cmd_data[shade_base+6 ] & 0x0000ffff); |
| 1979 | int dbdx = (cmd_data[shade_base+3 ] & 0xffff0000) | ((cmd_data[shade_base+7 ] >> 16) & 0x0000ffff); |
| 1980 | int dadx = ((cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (cmd_data[shade_base+7 ] & 0x0000ffff); |
| 1981 | int drde = (cmd_data[shade_base+8 ] & 0xffff0000) | ((cmd_data[shade_base+12] >> 16) & 0x0000ffff); |
| 1982 | int dgde = ((cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (cmd_data[shade_base+12] & 0x0000ffff); |
| 1983 | int dbde = (cmd_data[shade_base+9 ] & 0xffff0000) | ((cmd_data[shade_base+13] >> 16) & 0x0000ffff); |
| 1984 | int dade = ((cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (cmd_data[shade_base+13] & 0x0000ffff); |
| 1985 | int drdy = (cmd_data[shade_base+10] & 0xffff0000) | ((cmd_data[shade_base+14] >> 16) & 0x0000ffff); |
| 1986 | int dgdy = ((cmd_data[shade_base+10] << 16) & 0xffff0000) | (cmd_data[shade_base+14] & 0x0000ffff); |
| 1987 | int dbdy = (cmd_data[shade_base+11] & 0xffff0000) | ((cmd_data[shade_base+15] >> 16) & 0x0000ffff); |
| 1988 | int dady = ((cmd_data[shade_base+11] << 16) & 0xffff0000) | (cmd_data[shade_base+15] & 0x0000ffff); |
| 1989 | int s = (cmd_data[texture_base+0 ] & 0xffff0000) | ((cmd_data[texture_base+4 ] >> 16) & 0x0000ffff); |
| 1990 | int t = ((cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (cmd_data[texture_base+4 ] & 0x0000ffff); |
| 1991 | int w = (cmd_data[texture_base+1 ] & 0xffff0000) | ((cmd_data[texture_base+5 ] >> 16) & 0x0000ffff); |
| 1992 | int dsdx = (cmd_data[texture_base+2 ] & 0xffff0000) | ((cmd_data[texture_base+6 ] >> 16) & 0x0000ffff); |
| 1993 | int dtdx = ((cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (cmd_data[texture_base+6 ] & 0x0000ffff); |
| 1994 | int dwdx = (cmd_data[texture_base+3 ] & 0xffff0000) | ((cmd_data[texture_base+7 ] >> 16) & 0x0000ffff); |
| 1995 | int dsde = (cmd_data[texture_base+8 ] & 0xffff0000) | ((cmd_data[texture_base+12] >> 16) & 0x0000ffff); |
| 1996 | int dtde = ((cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (cmd_data[texture_base+12] & 0x0000ffff); |
| 1997 | int dwde = (cmd_data[texture_base+9 ] & 0xffff0000) | ((cmd_data[texture_base+13] >> 16) & 0x0000ffff); |
| 1998 | int dsdy = (cmd_data[texture_base+10] & 0xffff0000) | ((cmd_data[texture_base+14] >> 16) & 0x0000ffff); |
| 1999 | int dtdy = ((cmd_data[texture_base+10] << 16) & 0xffff0000) | (cmd_data[texture_base+14] & 0x0000ffff); |
| 2000 | int dwdy = (cmd_data[texture_base+11] & 0xffff0000) | ((cmd_data[texture_base+15] >> 16) & 0x0000ffff); |
| 2001 | int z = cmd_data[zbuffer_base+0]; |
| 2002 | int dzdx = cmd_data[zbuffer_base+1]; |
| 2003 | int dzde = cmd_data[zbuffer_base+2]; |
| 2004 | int dzdy = cmd_data[zbuffer_base+3]; |
| 2017 | 2005 | |
| 2018 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[0], m_cmd_data[1], m_cmd_data[2], m_cmd_data[3]); |
| 2019 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[4], m_cmd_data[5], m_cmd_data[6], m_cmd_data[7]); |
| 2020 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[8], m_cmd_data[9], m_cmd_data[10], m_cmd_data[11]); |
| 2021 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[12], m_cmd_data[13], m_cmd_data[14], m_cmd_data[15]); |
| 2022 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[16], m_cmd_data[17], m_cmd_data[18], m_cmd_data[19]); |
| 2023 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[20], m_cmd_data[21], m_cmd_data[22], m_cmd_data[23]); |
| 2024 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[24], m_cmd_data[25], m_cmd_data[26], m_cmd_data[27]); |
| 2025 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[28], m_cmd_data[29], m_cmd_data[30], m_cmd_data[31]); |
| 2026 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[32], m_cmd_data[33], m_cmd_data[34], m_cmd_data[35]); |
| 2027 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[36], m_cmd_data[37], m_cmd_data[38], m_cmd_data[39]); |
| 2028 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[40], m_cmd_data[41], m_cmd_data[42], m_cmd_data[43]); |
| 2029 | | //printf("%08x %08x %08x %08x\n", m_cmd_data[44], m_cmd_data[45], m_cmd_data[46], m_cmd_data[47]); |
| 2030 | | |
| 2031 | 2006 | int dzdy_dz = (dzdy >> 16) & 0xffff; |
| 2032 | 2007 | int dzdx_dz = (dzdx >> 16) & 0xffff; |
| 2033 | 2008 | |
| 2034 | | m_rdp->set_span_base_y(drdy, dgdy, dbdy, dady, dzdy); |
| 2009 | extent_t Spans[512]; |
| 2010 | |
| 2011 | SpanBase.m_span_drdy = drdy; |
| 2012 | SpanBase.m_span_dgdy = dgdy; |
| 2013 | SpanBase.m_span_dbdy = dbdy; |
| 2014 | SpanBase.m_span_dady = dady; |
| 2015 | SpanBase.m_span_dzdy = OtherModes.z_source_sel ? 0 : dzdy; |
| 2016 | |
| 2035 | 2017 | UINT32 temp_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz); |
| 2036 | | m_rdp->set_span_base(drdx & ~0x1f, |
| 2037 | | dgdx & ~0x1f, |
| 2038 | | dbdx & ~0x1f, |
| 2039 | | dadx & ~0x1f, |
| 2040 | | dsdx, |
| 2041 | | dtdx, |
| 2042 | | dwdx, |
| 2043 | | dzdx, |
| 2044 | | 0, |
| 2045 | | m_rdp->NormalizeDZPix(temp_dzpix & 0xffff) & 0xffff |
| 2046 | | ); |
| 2018 | SpanBase.m_span_dr = drdx & ~0x1f; |
| 2019 | SpanBase.m_span_dg = dgdx & ~0x1f; |
| 2020 | SpanBase.m_span_db = dbdx & ~0x1f; |
| 2021 | SpanBase.m_span_da = dadx & ~0x1f; |
| 2022 | SpanBase.m_span_ds = dsdx; |
| 2023 | SpanBase.m_span_dt = dtdx; |
| 2024 | SpanBase.m_span_dw = dwdx; |
| 2025 | SpanBase.m_span_dz = OtherModes.z_source_sel ? 0 : dzdx; |
| 2026 | SpanBase.m_span_dymax = 0; |
| 2027 | SpanBase.m_span_dzpix = NormalizeDZPix(temp_dzpix & 0xffff) & 0xffff; |
| 2047 | 2028 | |
| 2048 | 2029 | int xleft_inc = (dxmdy >> 2) & ~1; |
| 2049 | 2030 | int xright_inc = (dxhdy >> 2) & ~1; |
| r14423 | r14424 | |
| 2099 | 2080 | |
| 2100 | 2081 | int xfrac = ((xright >> 8) & 0xff); |
| 2101 | 2082 | |
| 2083 | rdp_poly_state &object = object_data_alloc(); |
| 2084 | memcpy(&object.m_tmem, m_tmem, 0x1000); |
| 2085 | |
| 2102 | 2086 | if(flip) |
| 2103 | 2087 | { |
| 2104 | 2088 | for (int k = ycur; k <= ylfar; k++) |
| r14423 | r14424 | |
| 2109 | 2093 | xleft_inc = (dxldy >> 2) & ~1; |
| 2110 | 2094 | } |
| 2111 | 2095 | |
| 2112 | | int xstart = xleft >> 16; |
| 2113 | | int xend = xright >> 16; |
| 2096 | int xstart = xleft >> 16; // 319 |
| 2097 | int xend = xright >> 16; // 0 |
| 2114 | 2098 | int j = k >> 2; |
| 2115 | 2099 | int spix = k & 3; |
| 2116 | 2100 | valid_y = !(k < yh || k >= yl); |
| 2117 | 2101 | |
| 2118 | 2102 | if (k >= 0 && k < 0x1000) |
| 2119 | 2103 | { |
| 2120 | | majorxint[spix] = xend; |
| 2121 | | minorxint[spix] = xstart; |
| 2122 | | majorx[spix] = xright; |
| 2123 | | minorx[spix] = xleft; |
| 2104 | majorxint[spix] = xend; // 0 |
| 2105 | minorxint[spix] = xstart; // 319 |
| 2106 | majorx[spix] = xright; // 0x00000000 |
| 2107 | minorx[spix] = xleft; // 0x013f0000 |
| 2124 | 2108 | |
| 2125 | 2109 | if (spix == 0) |
| 2126 | 2110 | { |
| r14423 | r14424 | |
| 2134 | 2118 | minxhx = (xend < minxhx) ? xend : minxhx; |
| 2135 | 2119 | } |
| 2136 | 2120 | |
| 2121 | if (spix == 0) |
| 2122 | { |
| 2123 | Spans[j - (ycur >> 2)].userdata = (void*)((UINT8*)AuxBuf[AuxBufIndex] + AuxBufPtr[AuxBufIndex]); |
| 2124 | AuxBufPtr[AuxBufIndex] += sizeof(rdp_span_aux); |
| 2125 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[j - (ycur >> 2)].userdata; |
| 2126 | userdata->m_tmem = object.m_tmem; |
| 2127 | |
| 2128 | userdata->BlendColor = BlendColor; |
| 2129 | userdata->PrimColor = PrimColor; |
| 2130 | userdata->EnvColor = EnvColor; |
| 2131 | userdata->FogColor = FogColor; |
| 2132 | userdata->KeyScale = KeyScale; |
| 2133 | userdata->LODFraction = LODFraction; |
| 2134 | userdata->PrimLODFraction = PrimLODFraction; |
| 2135 | |
| 2136 | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r; |
| 2137 | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g; |
| 2138 | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b; |
| 2139 | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r; |
| 2140 | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g; |
| 2141 | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b; |
| 2142 | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r; |
| 2143 | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g; |
| 2144 | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b; |
| 2145 | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r; |
| 2146 | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g; |
| 2147 | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b; |
| 2148 | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a; |
| 2149 | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a; |
| 2150 | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a; |
| 2151 | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a; |
| 2152 | |
| 2153 | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r; |
| 2154 | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g; |
| 2155 | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b; |
| 2156 | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a; |
| 2157 | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r; |
| 2158 | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g; |
| 2159 | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b; |
| 2160 | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a; |
| 2161 | |
| 2162 | // Setup blender data for this scanline |
| 2163 | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0], |
| 2164 | &userdata->ColorInputs.blender1a_g[0], |
| 2165 | &userdata->ColorInputs.blender1a_b[0], |
| 2166 | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata); |
| 2167 | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0], |
| 2168 | &userdata->ColorInputs.blender2a_g[0], |
| 2169 | &userdata->ColorInputs.blender2a_b[0], |
| 2170 | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata); |
| 2171 | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1], |
| 2172 | &userdata->ColorInputs.blender1a_g[1], |
| 2173 | &userdata->ColorInputs.blender1a_b[1], |
| 2174 | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata); |
| 2175 | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1], |
| 2176 | &userdata->ColorInputs.blender2a_g[1], |
| 2177 | &userdata->ColorInputs.blender2a_b[1], |
| 2178 | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata); |
| 2179 | |
| 2180 | // Setup color combiner data for this scanline |
| 2181 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata); |
| 2182 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata); |
| 2183 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata); |
| 2184 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata); |
| 2185 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata); |
| 2186 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata); |
| 2187 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata); |
| 2188 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata); |
| 2189 | |
| 2190 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata); |
| 2191 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata); |
| 2192 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata); |
| 2193 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata); |
| 2194 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata); |
| 2195 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata); |
| 2196 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata); |
| 2197 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata); |
| 2198 | } |
| 2199 | |
| 2137 | 2200 | if (spix == 3) |
| 2138 | 2201 | { |
| 2139 | | m_rdp->Spans[j].m_lx = maxxmx; |
| 2140 | | m_rdp->Spans[j].m_rx = minxhx; |
| 2141 | | compute_cvg_flip(majorx, minorx, majorxint, minorxint, j, yh, yl); |
| 2202 | Spans[j - (ycur >> 2)].startx = maxxmx; |
| 2203 | Spans[j - (ycur >> 2)].stopx = minxhx; |
| 2204 | compute_cvg_flip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2); |
| 2142 | 2205 | } |
| 2143 | 2206 | |
| 2144 | 2207 | if (spix == ldflag) |
| 2145 | 2208 | { |
| 2146 | | m_rdp->Spans[j].m_unscissored_rx = xend; |
| 2209 | ((rdp_span_aux*)Spans[j - (ycur >> 2)].userdata)->m_unscissored_rx = xend; |
| 2147 | 2210 | xfrac = ((xright >> 8) & 0xff); |
| 2148 | | m_rdp->Spans[j].m_r.w = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2149 | | m_rdp->Spans[j].m_g.w = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2150 | | m_rdp->Spans[j].m_b.w = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2151 | | m_rdp->Spans[j].m_a.w = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2152 | | m_rdp->Spans[j].m_s.w = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2153 | | m_rdp->Spans[j].m_t.w = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2154 | | m_rdp->Spans[j].m_w.w = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2155 | | m_rdp->Spans[j].m_z.w = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2156 | | //printf("%d - %08x\n", j, m_rdp->Spans[j].m_z.w); |
| 2211 | Spans[j - (ycur >> 2)].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2212 | Spans[j - (ycur >> 2)].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2213 | Spans[j - (ycur >> 2)].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2214 | Spans[j - (ycur >> 2)].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2215 | Spans[j - (ycur >> 2)].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2216 | Spans[j - (ycur >> 2)].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2217 | Spans[j - (ycur >> 2)].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2218 | Spans[j - (ycur >> 2)].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2157 | 2219 | } |
| 2158 | 2220 | } |
| 2159 | 2221 | |
| r14423 | r14424 | |
| 2208 | 2270 | maxxhx = (xend > maxxhx) ? xend : maxxhx; |
| 2209 | 2271 | } |
| 2210 | 2272 | |
| 2273 | if (spix == 0) |
| 2274 | { |
| 2275 | Spans[j - (ycur >> 2)].userdata = (void*)((UINT8*)AuxBuf[AuxBufIndex] + AuxBufPtr[AuxBufIndex]); |
| 2276 | AuxBufPtr[AuxBufIndex] += sizeof(rdp_span_aux); |
| 2277 | |
| 2278 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[j - (ycur >> 2)].userdata; |
| 2279 | userdata->m_tmem = object.m_tmem; |
| 2280 | |
| 2281 | userdata->BlendColor = BlendColor; |
| 2282 | userdata->PrimColor = PrimColor; |
| 2283 | userdata->EnvColor = EnvColor; |
| 2284 | userdata->FogColor = FogColor; |
| 2285 | userdata->KeyScale = KeyScale; |
| 2286 | userdata->LODFraction = LODFraction; |
| 2287 | userdata->PrimLODFraction = PrimLODFraction; |
| 2288 | |
| 2289 | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r; |
| 2290 | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g; |
| 2291 | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b; |
| 2292 | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r; |
| 2293 | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g; |
| 2294 | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b; |
| 2295 | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r; |
| 2296 | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g; |
| 2297 | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b; |
| 2298 | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r; |
| 2299 | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g; |
| 2300 | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b; |
| 2301 | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a; |
| 2302 | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a; |
| 2303 | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a; |
| 2304 | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a; |
| 2305 | |
| 2306 | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r; |
| 2307 | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g; |
| 2308 | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b; |
| 2309 | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a; |
| 2310 | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r; |
| 2311 | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g; |
| 2312 | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b; |
| 2313 | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a; |
| 2314 | |
| 2315 | // Setup blender data for this scanline |
| 2316 | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0], |
| 2317 | &userdata->ColorInputs.blender1a_g[0], |
| 2318 | &userdata->ColorInputs.blender1a_b[0], |
| 2319 | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata); |
| 2320 | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0], |
| 2321 | &userdata->ColorInputs.blender2a_g[0], |
| 2322 | &userdata->ColorInputs.blender2a_b[0], |
| 2323 | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata); |
| 2324 | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1], |
| 2325 | &userdata->ColorInputs.blender1a_g[1], |
| 2326 | &userdata->ColorInputs.blender1a_b[1], |
| 2327 | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata); |
| 2328 | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1], |
| 2329 | &userdata->ColorInputs.blender2a_g[1], |
| 2330 | &userdata->ColorInputs.blender2a_b[1], |
| 2331 | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata); |
| 2332 | |
| 2333 | // Setup color combiner data for this scanline |
| 2334 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata); |
| 2335 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata); |
| 2336 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata); |
| 2337 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata); |
| 2338 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata); |
| 2339 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata); |
| 2340 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata); |
| 2341 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata); |
| 2342 | |
| 2343 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata); |
| 2344 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata); |
| 2345 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata); |
| 2346 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata); |
| 2347 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata); |
| 2348 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata); |
| 2349 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata); |
| 2350 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata); |
| 2351 | } |
| 2352 | |
| 2211 | 2353 | if (spix == 3) |
| 2212 | 2354 | { |
| 2213 | | m_rdp->Spans[j].m_lx = minxmx; |
| 2214 | | m_rdp->Spans[j].m_rx = maxxhx; |
| 2215 | | compute_cvg_noflip(majorx, minorx, majorxint, minorxint, j, yh, yl); |
| 2355 | Spans[j - (ycur >> 2)].startx = minxmx; |
| 2356 | Spans[j - (ycur >> 2)].stopx = maxxhx; |
| 2357 | compute_cvg_noflip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2); |
| 2216 | 2358 | } |
| 2217 | 2359 | |
| 2218 | 2360 | if (spix == ldflag) |
| 2219 | 2361 | { |
| 2220 | | m_rdp->Spans[j].m_unscissored_rx = xend; |
| 2362 | ((rdp_span_aux*)Spans[j - (ycur >> 2)].userdata)->m_unscissored_rx = xend; |
| 2221 | 2363 | xfrac = ((xright >> 8) & 0xff); |
| 2222 | | m_rdp->Spans[j].m_r.w = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2223 | | m_rdp->Spans[j].m_g.w = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2224 | | m_rdp->Spans[j].m_b.w = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2225 | | m_rdp->Spans[j].m_a.w = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2226 | | m_rdp->Spans[j].m_s.w = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2227 | | m_rdp->Spans[j].m_t.w = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2228 | | m_rdp->Spans[j].m_w.w = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2229 | | m_rdp->Spans[j].m_z.w = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2364 | Spans[j - (ycur >> 2)].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2365 | Spans[j - (ycur >> 2)].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2366 | Spans[j - (ycur >> 2)].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2367 | Spans[j - (ycur >> 2)].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2368 | Spans[j - (ycur >> 2)].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2369 | Spans[j - (ycur >> 2)].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2370 | Spans[j - (ycur >> 2)].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2371 | Spans[j - (ycur >> 2)].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2230 | 2372 | } |
| 2231 | 2373 | } |
| 2232 | 2374 | |
| r14423 | r14424 | |
| 2246 | 2388 | } |
| 2247 | 2389 | } |
| 2248 | 2390 | |
| 2249 | | m_rdp->RenderSpans(yh >> 2, yl >> 2, tilenum, flip); |
| 2391 | RenderSpans(yh >> 2, yl >> 2, tilenum, flip ? true : false, Spans, rect, object); |
| 2392 | //wait("DrawTriangle"); |
| 2250 | 2393 | } |
| 2251 | 2394 | |
| 2252 | 2395 | /*****************************************************************************/ |
| 2253 | 2396 | |
| 2254 | 2397 | //////////////////////// |
| 2255 | | // RDP COMMANDS |
| 2398 | // FB ACCESSORS |
| 2256 | 2399 | //////////////////////// |
| 2400 | void n64_rdp::_Write16Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2401 | { |
| 2402 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2403 | UINT32 hb = fb; |
| 2257 | 2404 | |
| 2258 | | void N64::RDP::Processor::Triangle(bool shade, bool texture, bool zbuffer) |
| 2405 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2406 | UINT32 finalcvg = 0; |
| 2407 | |
| 2408 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2409 | { |
| 2410 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2411 | } |
| 2412 | |
| 2413 | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg; |
| 2414 | if (finalcvg & 8) |
| 2415 | { |
| 2416 | finalcvg = 7; |
| 2417 | } |
| 2418 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2419 | HWRITEADDR8(hb, finalcvg & 3); |
| 2420 | } |
| 2421 | |
| 2422 | void n64_rdp::_Write16Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2259 | 2423 | { |
| 2260 | | N64::RDP::Triangle tri(*m_machine, shade, texture, zbuffer, false, false); |
| 2261 | | tri.Draw(); |
| 2424 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2425 | UINT32 hb = fb; |
| 2426 | |
| 2427 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2428 | UINT32 finalcvg = 0; |
| 2429 | |
| 2430 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2431 | { |
| 2432 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2433 | } |
| 2434 | |
| 2435 | finalcvg = (userdata->CurrentPixCvg - 1) & 7; |
| 2436 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2437 | HWRITEADDR8(hb, finalcvg & 3); |
| 2262 | 2438 | } |
| 2263 | 2439 | |
| 2264 | | void N64::RDP::Processor::CmdTriangle(UINT32 w1, UINT32 w2) |
| 2440 | void n64_rdp::_Write16Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2265 | 2441 | { |
| 2442 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2443 | UINT32 hb = fb; |
| 2444 | |
| 2445 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2446 | UINT32 finalcvg = 0; |
| 2447 | |
| 2448 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2449 | { |
| 2450 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2451 | } |
| 2452 | |
| 2453 | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7; |
| 2454 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2455 | HWRITEADDR8(hb, finalcvg & 3); |
| 2456 | } |
| 2457 | |
| 2458 | void n64_rdp::_Write16Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2459 | { |
| 2460 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2461 | UINT32 hb = fb; |
| 2462 | |
| 2463 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2464 | |
| 2465 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2466 | { |
| 2467 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2468 | } |
| 2469 | |
| 2470 | RWRITEIDX16(fb, finalcolor | 1); |
| 2471 | HWRITEADDR8(hb, 3); |
| 2472 | } |
| 2473 | |
| 2474 | void n64_rdp::_Write16Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2475 | { |
| 2476 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2477 | UINT32 hb = fb; |
| 2478 | |
| 2479 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2480 | |
| 2481 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2482 | { |
| 2483 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2484 | } |
| 2485 | |
| 2486 | RWRITEIDX16(fb, finalcolor | ((userdata->CurrentMemCvg >> 2) & 1)); |
| 2487 | HWRITEADDR8(hb, userdata->CurrentMemCvg & 3); |
| 2488 | } |
| 2489 | |
| 2490 | void n64_rdp::_Write32Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2491 | { |
| 2492 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2493 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2494 | UINT32 finalcvg = 0; |
| 2495 | |
| 2496 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2497 | { |
| 2498 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2499 | } |
| 2500 | |
| 2501 | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg; |
| 2502 | if (finalcvg & 8) |
| 2503 | { |
| 2504 | finalcvg = 7; |
| 2505 | } |
| 2506 | RWRITEIDX32(fb, finalcolor | (finalcvg << 5)); |
| 2507 | } |
| 2508 | |
| 2509 | void n64_rdp::_Write32Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2510 | { |
| 2511 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2512 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2513 | UINT32 finalcvg = 0; |
| 2514 | |
| 2515 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2516 | { |
| 2517 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2518 | } |
| 2519 | |
| 2520 | finalcvg = (userdata->CurrentPixCvg - 1) & 7; |
| 2521 | RWRITEIDX32(fb, finalcolor | (finalcvg << 5)); |
| 2522 | } |
| 2523 | |
| 2524 | void n64_rdp::_Write32Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2525 | { |
| 2526 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2527 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2528 | UINT32 finalcvg = 0; |
| 2529 | |
| 2530 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2531 | { |
| 2532 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2533 | } |
| 2534 | |
| 2535 | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7; |
| 2536 | finalcolor |= (finalcvg << 5); |
| 2537 | RWRITEIDX32(fb, finalcolor); |
| 2538 | } |
| 2539 | |
| 2540 | void n64_rdp::_Write32Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2541 | { |
| 2542 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2543 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2544 | |
| 2545 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2546 | { |
| 2547 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2548 | } |
| 2549 | |
| 2550 | RWRITEIDX32(fb, finalcolor | 0xE0); |
| 2551 | } |
| 2552 | |
| 2553 | void n64_rdp::_Write32Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2554 | { |
| 2555 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2556 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2557 | |
| 2558 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2559 | { |
| 2560 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2561 | } |
| 2562 | |
| 2563 | RWRITEIDX32(fb, finalcolor | (userdata->CurrentMemCvg << 5)); |
| 2564 | } |
| 2565 | |
| 2566 | |
| 2567 | void n64_rdp::_Read16Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2568 | { |
| 2569 | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2570 | userdata->MemoryColor.i.r = GETHICOL(fword); |
| 2571 | userdata->MemoryColor.i.g = GETMEDCOL(fword); |
| 2572 | userdata->MemoryColor.i.b = GETLOWCOL(fword); |
| 2573 | userdata->MemoryColor.i.a = 0xff; |
| 2574 | userdata->CurrentMemCvg = 7; |
| 2575 | } |
| 2576 | |
| 2577 | void n64_rdp::_Read16Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2578 | { |
| 2579 | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2580 | UINT8 hbyte = HREADADDR8((object.MiscState.FBAddress >> 1) + curpixel); |
| 2581 | userdata->MemoryColor.i.r = GETHICOL(fword); |
| 2582 | userdata->MemoryColor.i.g = GETMEDCOL(fword); |
| 2583 | userdata->MemoryColor.i.b = GETLOWCOL(fword); |
| 2584 | userdata->MemoryColor.i.a = userdata->CurrentMemCvg << 5; |
| 2585 | userdata->CurrentMemCvg = ((fword & 1) << 2) | (hbyte & 3); |
| 2586 | } |
| 2587 | |
| 2588 | void n64_rdp::_Read32Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2589 | { |
| 2590 | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2591 | userdata->MemoryColor.i.r = (mem >> 24) & 0xff; |
| 2592 | userdata->MemoryColor.i.g = (mem >> 16) & 0xff; |
| 2593 | userdata->MemoryColor.i.b = (mem >> 8) & 0xff; |
| 2594 | userdata->MemoryColor.i.a = 0xff; |
| 2595 | userdata->CurrentMemCvg = 7; |
| 2596 | } |
| 2597 | |
| 2598 | void n64_rdp::_Read32Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2599 | { |
| 2600 | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2601 | userdata->MemoryColor.i.r = (mem >> 24) & 0xff; |
| 2602 | userdata->MemoryColor.i.g = (mem >> 16) & 0xff; |
| 2603 | userdata->MemoryColor.i.b = (mem >> 8) & 0xff; |
| 2604 | userdata->MemoryColor.i.a = (mem) & 0xff; |
| 2605 | userdata->CurrentMemCvg = (mem >> 5) & 7; |
| 2606 | } |
| 2607 | |
| 2608 | void n64_rdp::_Copy16Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object) |
| 2609 | { |
| 2610 | UINT16 val = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | ((CurrentPixCvg >> 2) & 1); |
| 2611 | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val); |
| 2612 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, CurrentPixCvg & 3); |
| 2613 | } |
| 2614 | |
| 2615 | void n64_rdp::_Copy32Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object) |
| 2616 | { |
| 2617 | UINT32 val = (r << 24) | (g << 16) | (b << 8) | (CurrentPixCvg << 5); |
| 2618 | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, val); |
| 2619 | } |
| 2620 | |
| 2621 | |
| 2622 | void n64_rdp::_Fill16Bit(UINT32 curpixel, const rdp_poly_state &object) |
| 2623 | { |
| 2624 | UINT16 val; |
| 2625 | if (curpixel & 1) |
| 2626 | { |
| 2627 | val = object.FillColor & 0xffff; |
| 2628 | } |
| 2629 | else |
| 2630 | { |
| 2631 | val = (object.FillColor >> 16) & 0xffff; |
| 2632 | } |
| 2633 | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val); |
| 2634 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, ((val & 1) << 1) | (val & 1)); |
| 2635 | } |
| 2636 | |
| 2637 | void n64_rdp::_Fill32Bit(UINT32 curpixel, const rdp_poly_state &object) |
| 2638 | { |
| 2639 | UINT32 FillColor = object.FillColor; |
| 2640 | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, FillColor); |
| 2641 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1), (FillColor & 0x10000) ? 3 : 0); |
| 2642 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1) + 1, (FillColor & 0x1) ? 3 : 0); |
| 2643 | } |
| 2644 | |
| 2645 | //////////////////////// |
| 2646 | // RDP COMMANDS |
| 2647 | //////////////////////// |
| 2648 | void n64_rdp::Triangle(bool shade, bool texture, bool zbuffer) |
| 2649 | { |
| 2650 | DrawTriangle(shade, texture, zbuffer, false); |
| 2651 | m_pipe_clean = false; |
| 2652 | } |
| 2653 | |
| 2654 | void n64_rdp::CmdTriangle(UINT32 w1, UINT32 w2) |
| 2655 | { |
| 2266 | 2656 | Triangle(false, false, false); |
| 2267 | 2657 | } |
| 2268 | 2658 | |
| 2269 | | void N64::RDP::Processor::CmdTriangleZ(UINT32 w1, UINT32 w2) |
| 2659 | void n64_rdp::CmdTriangleZ(UINT32 w1, UINT32 w2) |
| 2270 | 2660 | { |
| 2271 | 2661 | Triangle(false, false, true); |
| 2272 | 2662 | } |
| 2273 | 2663 | |
| 2274 | | void N64::RDP::Processor::CmdTriangleT(UINT32 w1, UINT32 w2) |
| 2664 | void n64_rdp::CmdTriangleT(UINT32 w1, UINT32 w2) |
| 2275 | 2665 | { |
| 2276 | 2666 | Triangle(false, true, false); |
| 2277 | 2667 | } |
| 2278 | 2668 | |
| 2279 | | void N64::RDP::Processor::CmdTriangleTZ(UINT32 w1, UINT32 w2) |
| 2669 | void n64_rdp::CmdTriangleTZ(UINT32 w1, UINT32 w2) |
| 2280 | 2670 | { |
| 2281 | 2671 | Triangle(false, true, true); |
| 2282 | 2672 | } |
| 2283 | 2673 | |
| 2284 | | void N64::RDP::Processor::CmdTriangleS(UINT32 w1, UINT32 w2) |
| 2674 | void n64_rdp::CmdTriangleS(UINT32 w1, UINT32 w2) |
| 2285 | 2675 | { |
| 2286 | 2676 | Triangle(true, false, false); |
| 2287 | 2677 | } |
| 2288 | 2678 | |
| 2289 | | void N64::RDP::Processor::CmdTriangleSZ(UINT32 w1, UINT32 w2) |
| 2679 | void n64_rdp::CmdTriangleSZ(UINT32 w1, UINT32 w2) |
| 2290 | 2680 | { |
| 2291 | 2681 | Triangle(true, false, true); |
| 2292 | 2682 | } |
| 2293 | 2683 | |
| 2294 | | void N64::RDP::Processor::CmdTriangleST(UINT32 w1, UINT32 w2) |
| 2684 | void n64_rdp::CmdTriangleST(UINT32 w1, UINT32 w2) |
| 2295 | 2685 | { |
| 2296 | 2686 | Triangle(true, true, false); |
| 2297 | 2687 | } |
| 2298 | 2688 | |
| 2299 | | void N64::RDP::Processor::CmdTriangleSTZ(UINT32 w1, UINT32 w2) |
| 2689 | void n64_rdp::CmdTriangleSTZ(UINT32 w1, UINT32 w2) |
| 2300 | 2690 | { |
| 2301 | 2691 | Triangle(true, true, true); |
| 2302 | 2692 | } |
| 2303 | 2693 | |
| 2304 | | void N64::RDP::Processor::CmdTexRect(UINT32 w1, UINT32 w2) |
| 2694 | void n64_rdp::CmdTexRect(UINT32 w1, UINT32 w2) |
| 2305 | 2695 | { |
| 2696 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 2697 | |
| 2306 | 2698 | UINT32 *data = m_cmd_data + m_cmd_cur; |
| 2307 | 2699 | |
| 2308 | 2700 | UINT32 w3 = data[2]; |
| r14423 | r14424 | |
| 2329 | 2721 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 2330 | 2722 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 2331 | 2723 | |
| 2332 | | UINT32* ewdata = GetTempRectData(); |
| 2724 | UINT32* ewdata = m_temp_rect_data; |
| 2333 | 2725 | ewdata[0] = (0x24 << 24) | ((0x80 | tilenum) << 16) | yl; // command, flipped, tile, yl |
| 2334 | 2726 | ewdata[1] = (yl << 16) | yh; // ym, yh |
| 2335 | 2727 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14); // xl, xl frac |
| r14423 | r14424 | |
| 2357 | 2749 | ewdata[39] = 0;//dwdy frac |
| 2358 | 2750 | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth |
| 2359 | 2751 | |
| 2360 | | N64::RDP::Triangle tri(*m_machine, true, true, false, true, false); |
| 2361 | | tri.Draw(); |
| 2752 | DrawTriangle(true, true, false, true); |
| 2362 | 2753 | } |
| 2363 | 2754 | |
| 2364 | | void N64::RDP::Processor::CmdTexRectFlip(UINT32 w1, UINT32 w2) |
| 2755 | void n64_rdp::CmdTexRectFlip(UINT32 w1, UINT32 w2) |
| 2365 | 2756 | { |
| 2757 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 2758 | |
| 2366 | 2759 | UINT32 *data = m_cmd_data + m_cmd_cur; |
| 2367 | 2760 | |
| 2368 | 2761 | UINT32 w3 = data[2]; |
| r14423 | r14424 | |
| 2389 | 2782 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 2390 | 2783 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 2391 | 2784 | |
| 2392 | | UINT32* ewdata = GetTempRectData(); |
| 2785 | UINT32* ewdata = m_temp_rect_data; |
| 2393 | 2786 | ewdata[0] = (0x25 << 24) | ((0x80 | tilenum) << 16) | yl;//command, flipped, tile, yl |
| 2394 | 2787 | ewdata[1] = (yl << 16) | yh;//ym, yh |
| 2395 | 2788 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac |
| r14423 | r14424 | |
| 2417 | 2810 | ewdata[39] = 0;//dwdy frac |
| 2418 | 2811 | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth |
| 2419 | 2812 | |
| 2420 | | N64::RDP::Triangle tri(*m_machine, true, true, false, true, false); |
| 2421 | | tri.Draw(); |
| 2813 | DrawTriangle(true, true, false, true); |
| 2422 | 2814 | } |
| 2423 | 2815 | |
| 2424 | | void N64::RDP::Processor::CmdSyncLoad(UINT32 w1, UINT32 w2) |
| 2816 | void n64_rdp::CmdSyncLoad(UINT32 w1, UINT32 w2) |
| 2425 | 2817 | { |
| 2426 | | // Nothing to do? |
| 2818 | //wait("SyncLoad"); |
| 2427 | 2819 | } |
| 2428 | 2820 | |
| 2429 | | void N64::RDP::Processor::CmdSyncPipe(UINT32 w1, UINT32 w2) |
| 2821 | void n64_rdp::CmdSyncPipe(UINT32 w1, UINT32 w2) |
| 2430 | 2822 | { |
| 2431 | | // Nothing to do? |
| 2823 | //wait("SyncPipe"); |
| 2432 | 2824 | } |
| 2433 | 2825 | |
| 2434 | | void N64::RDP::Processor::CmdSyncTile(UINT32 w1, UINT32 w2) |
| 2826 | void n64_rdp::CmdSyncTile(UINT32 w1, UINT32 w2) |
| 2435 | 2827 | { |
| 2436 | | // Nothing to do? |
| 2828 | //wait("SyncTile"); |
| 2437 | 2829 | } |
| 2438 | 2830 | |
| 2439 | | void N64::RDP::Processor::CmdSyncFull(UINT32 w1, UINT32 w2) |
| 2831 | void n64_rdp::CmdSyncFull(UINT32 w1, UINT32 w2) |
| 2440 | 2832 | { |
| 2833 | //wait("SyncFull"); |
| 2441 | 2834 | dp_full_sync(*m_machine); |
| 2442 | 2835 | } |
| 2443 | 2836 | |
| 2444 | | void N64::RDP::Processor::CmdSetKeyGB(UINT32 w1, UINT32 w2) |
| 2837 | void n64_rdp::CmdSetKeyGB(UINT32 w1, UINT32 w2) |
| 2445 | 2838 | { |
| 2446 | 2839 | KeyScale.i.b = w2 & 0xff; |
| 2447 | 2840 | KeyScale.i.g = (w2 >> 16) & 0xff; |
| 2448 | 2841 | } |
| 2449 | 2842 | |
| 2450 | | void N64::RDP::Processor::CmdSetKeyR(UINT32 w1, UINT32 w2) |
| 2843 | void n64_rdp::CmdSetKeyR(UINT32 w1, UINT32 w2) |
| 2451 | 2844 | { |
| 2452 | 2845 | KeyScale.i.r = w2 & 0xff; |
| 2453 | 2846 | } |
| 2454 | 2847 | |
| 2455 | | void N64::RDP::Processor::CmdSetFillColor32(UINT32 w1, UINT32 w2) |
| 2848 | void n64_rdp::CmdSetFillColor32(UINT32 w1, UINT32 w2) |
| 2456 | 2849 | { |
| 2850 | //wait("SetFillColor"); |
| 2457 | 2851 | FillColor = w2; |
| 2458 | 2852 | } |
| 2459 | 2853 | |
| 2460 | | void N64::RDP::Processor::CmdSetConvert(UINT32 w1, UINT32 w2) |
| 2854 | void n64_rdp::CmdSetConvert(UINT32 w1, UINT32 w2) |
| 2461 | 2855 | { |
| 2856 | if(!m_pipe_clean) { m_pipe_clean = true; wait("SetConvert"); } |
| 2462 | 2857 | INT32 k0 = (w1 >> 13) & 0xff; |
| 2463 | 2858 | INT32 k1 = (w1 >> 4) & 0xff; |
| 2464 | 2859 | INT32 k2 = ((w1 & 7) << 5) | ((w2 >> 27) & 0x1f); |
| r14423 | r14424 | |
| 2474 | 2869 | SetYUVFactors(k0, k1, k2, k3, k4, k5); |
| 2475 | 2870 | } |
| 2476 | 2871 | |
| 2477 | | void N64::RDP::Processor::CmdSetScissor(UINT32 w1, UINT32 w2) |
| 2872 | void n64_rdp::CmdSetScissor(UINT32 w1, UINT32 w2) |
| 2478 | 2873 | { |
| 2479 | | m_scissor.m_xh = ((w1 >> 12) & 0xfff) >> 2; |
| 2480 | | m_scissor.m_yh = ((w1 >> 0) & 0xfff) >> 2; |
| 2481 | | m_scissor.m_xl = ((w2 >> 12) & 0xfff) >> 2; |
| 2482 | | m_scissor.m_yl = ((w2 >> 0) & 0xfff) >> 2; |
| 2874 | Scissor.m_xh = ((w1 >> 12) & 0xfff) >> 2; |
| 2875 | Scissor.m_yh = ((w1 >> 0) & 0xfff) >> 2; |
| 2876 | Scissor.m_xl = ((w2 >> 12) & 0xfff) >> 2; |
| 2877 | Scissor.m_yl = ((w2 >> 0) & 0xfff) >> 2; |
| 2483 | 2878 | |
| 2484 | 2879 | // TODO: handle f & o? |
| 2485 | 2880 | } |
| 2486 | 2881 | |
| 2487 | | void N64::RDP::Processor::CmdSetPrimDepth(UINT32 w1, UINT32 w2) |
| 2882 | void n64_rdp::CmdSetPrimDepth(UINT32 w1, UINT32 w2) |
| 2488 | 2883 | { |
| 2489 | 2884 | MiscState.PrimitiveZ = (UINT16)(w2 >> 16) & 0x7fff; |
| 2490 | 2885 | MiscState.PrimitiveDZ = (UINT16)(w1); |
| 2491 | | |
| 2492 | 2886 | } |
| 2493 | 2887 | |
| 2494 | | void N64::RDP::Processor::CmdSetOtherModes(UINT32 w1, UINT32 w2) |
| 2888 | void n64_rdp::CmdSetOtherModes(UINT32 w1, UINT32 w2) |
| 2495 | 2889 | { |
| 2890 | //wait("SetOtherModes"); |
| 2496 | 2891 | OtherModes.cycle_type = (w1 >> 20) & 0x3; // 01 |
| 2497 | 2892 | OtherModes.persp_tex_en = (w1 & 0x80000) ? 1 : 0; // 1 |
| 2498 | 2893 | OtherModes.detail_tex_en = (w1 & 0x40000) ? 1 : 0; // 0 |
| r14423 | r14424 | |
| 2522 | 2917 | OtherModes.z_mode = (w2 >> 10) & 0x3; // 00 |
| 2523 | 2918 | OtherModes.cvg_dest = (w2 >> 8) & 0x3; // 00 |
| 2524 | 2919 | OtherModes.color_on_cvg = (w2 >> 7) & 1; // 0 |
| 2525 | | OtherModes.image_read_en = (w2 >> 6) & 1; // 1 |
| 2920 | OtherModes.image_read_en = (w2 >> 6) & 1; // 1 |
| 2526 | 2921 | OtherModes.z_update_en = (w2 >> 5) & 1; // 1 |
| 2527 | 2922 | OtherModes.z_compare_en = (w2 >> 4) & 1; // 1 |
| 2528 | 2923 | OtherModes.antialias_en = (w2 >> 3) & 1; // 1 |
| 2529 | 2924 | OtherModes.z_source_sel = (w2 >> 2) & 1; // 0 |
| 2530 | 2925 | OtherModes.dither_alpha_en = (w2 >> 1) & 1; // 0 |
| 2531 | 2926 | OtherModes.alpha_compare_en = (w2) & 1; // 0 |
| 2532 | | |
| 2533 | | // These should belong to the Blender class |
| 2534 | | SetBlenderInput(0, 0, &ColorInputs.blender1a_r[0], &ColorInputs.blender1a_g[0], &ColorInputs.blender1a_b[0], &ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0); |
| 2535 | | SetBlenderInput(0, 1, &ColorInputs.blender2a_r[0], &ColorInputs.blender2a_g[0], &ColorInputs.blender2a_b[0], &ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0); |
| 2536 | | SetBlenderInput(1, 0, &ColorInputs.blender1a_r[1], &ColorInputs.blender1a_g[1], &ColorInputs.blender1a_b[1], &ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1); |
| 2537 | | SetBlenderInput(1, 1, &ColorInputs.blender2a_r[1], &ColorInputs.blender2a_g[1], &ColorInputs.blender2a_b[1], &ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1); |
| 2538 | 2927 | } |
| 2539 | 2928 | |
| 2540 | | void N64::RDP::Processor::CmdLoadTLUT(UINT32 w1, UINT32 w2) |
| 2929 | void n64_rdp::CmdLoadTLUT(UINT32 w1, UINT32 w2) |
| 2541 | 2930 | { |
| 2542 | | Tile* tile = GetTiles(); |
| 2931 | //wait("LoadTLUT"); |
| 2932 | N64Tile* tile = m_tiles; |
| 2543 | 2933 | |
| 2544 | 2934 | int tilenum = (w2 >> 24) & 0x7; |
| 2545 | 2935 | int sl = tile[tilenum].sl = ((w1 >> 12) & 0xfff); |
| r14423 | r14424 | |
| 2585 | 2975 | } |
| 2586 | 2976 | } |
| 2587 | 2977 | |
| 2588 | | void N64::RDP::Processor::CmdSetTileSize(UINT32 w1, UINT32 w2) |
| 2978 | void n64_rdp::CmdSetTileSize(UINT32 w1, UINT32 w2) |
| 2589 | 2979 | { |
| 2980 | //wait("SetTileSize"); |
| 2981 | |
| 2590 | 2982 | const int tilenum = (w2 >> 24) & 0x7; |
| 2591 | 2983 | |
| 2592 | 2984 | m_tiles[tilenum].sl = (w1 >> 12) & 0xfff; |
| r14423 | r14424 | |
| 2595 | 2987 | m_tiles[tilenum].th = (w2 >> 0) & 0xfff; |
| 2596 | 2988 | } |
| 2597 | 2989 | |
| 2598 | | void N64::RDP::Processor::CmdLoadBlock(UINT32 w1, UINT32 w2) |
| 2990 | void n64_rdp::CmdLoadBlock(UINT32 w1, UINT32 w2) |
| 2599 | 2991 | { |
| 2600 | | Tile* tile = GetTiles(); |
| 2992 | //wait("LoadBlock"); |
| 2993 | N64Tile* tile = m_tiles; |
| 2601 | 2994 | |
| 2602 | 2995 | int tilenum = (w2 >> 24) & 0x7; |
| 2603 | 2996 | UINT16* tc = GetTMEM16(); |
| r14423 | r14424 | |
| 2762 | 3155 | } |
| 2763 | 3156 | } |
| 2764 | 3157 | |
| 2765 | | void N64::RDP::Processor::CmdLoadTile(UINT32 w1, UINT32 w2) |
| 3158 | void n64_rdp::CmdLoadTile(UINT32 w1, UINT32 w2) |
| 2766 | 3159 | { |
| 2767 | | Tile* tile = GetTiles(); |
| 3160 | //wait("LoadTile"); |
| 3161 | N64Tile* tile = m_tiles; |
| 2768 | 3162 | int tilenum = (w2 >> 24) & 0x7; |
| 2769 | 3163 | |
| 2770 | 3164 | tile[tilenum].sl = ((w1 >> 12) & 0xfff); |
| r14423 | r14424 | |
| 2881 | 3275 | } |
| 2882 | 3276 | } |
| 2883 | 3277 | |
| 2884 | | void N64::RDP::Processor::CmdSetTile(UINT32 w1, UINT32 w2) |
| 3278 | void n64_rdp::CmdSetTile(UINT32 w1, UINT32 w2) |
| 2885 | 3279 | { |
| 3280 | //wait("SetTile"); |
| 3281 | |
| 2886 | 3282 | int tilenum = (w2 >> 24) & 0x7; |
| 2887 | | N64::RDP::Tile* tex_tile = &m_tiles[tilenum]; |
| 3283 | N64Tile* tex_tile = &m_tiles[tilenum]; |
| 2888 | 3284 | |
| 2889 | 3285 | tex_tile->format = (w1 >> 21) & 0x7; |
| 2890 | 3286 | tex_tile->size = (w1 >> 19) & 0x3; |
| r14423 | r14424 | |
| 2913 | 3309 | { |
| 2914 | 3310 | tex_tile->format = FORMAT_CI; // Used by Exterem-G2, Madden Football 64, and Rat Attack |
| 2915 | 3311 | } |
| 3312 | |
| 3313 | //m_pending_mode_block = true; |
| 2916 | 3314 | } |
| 2917 | 3315 | |
| 2918 | | void N64::RDP::Processor::CmdFillRect(UINT32 w1, UINT32 w2) |
| 3316 | void n64_rdp::CmdFillRect(UINT32 w1, UINT32 w2) |
| 2919 | 3317 | { |
| 3318 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 3319 | |
| 2920 | 3320 | UINT32 xl = (w1 >> 12) & 0xfff; |
| 2921 | 3321 | UINT32 yl = (w1 >> 0) & 0xfff; |
| 2922 | 3322 | UINT32 xh = (w2 >> 12) & 0xfff; |
| r14423 | r14424 | |
| 2930 | 3330 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 2931 | 3331 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 2932 | 3332 | |
| 2933 | | UINT32* ewdata = GetTempRectData(); |
| 3333 | UINT32* ewdata = m_temp_rect_data; |
| 2934 | 3334 | ewdata[0] = (0x3680 << 16) | yl;//command, flipped, tile, yl |
| 2935 | 3335 | ewdata[1] = (yl << 16) | yh;//ym, yh |
| 2936 | 3336 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac |
| r14423 | r14424 | |
| 2941 | 3341 | ewdata[7] = 0;//dxmdy, dxmdy frac |
| 2942 | 3342 | memset(&ewdata[8], 0, 36 * sizeof(UINT32));//shade, texture, depth |
| 2943 | 3343 | |
| 2944 | | N64::RDP::Triangle tri(*m_machine, false, false, false, true, false); |
| 2945 | | tri.Draw(); |
| 3344 | DrawTriangle(false, false, false, true); |
| 2946 | 3345 | } |
| 2947 | 3346 | |
| 2948 | | void N64::RDP::Processor::CmdSetFogColor(UINT32 w1, UINT32 w2) |
| 3347 | void n64_rdp::CmdSetFogColor(UINT32 w1, UINT32 w2) |
| 2949 | 3348 | { |
| 2950 | 3349 | FogColor.c = w2; |
| 2951 | 3350 | } |
| 2952 | 3351 | |
| 2953 | | void N64::RDP::Processor::CmdSetBlendColor(UINT32 w1, UINT32 w2) |
| 3352 | void n64_rdp::CmdSetBlendColor(UINT32 w1, UINT32 w2) |
| 2954 | 3353 | { |
| 2955 | 3354 | BlendColor.c = w2; |
| 2956 | 3355 | } |
| 2957 | 3356 | |
| 2958 | | void N64::RDP::Processor::CmdSetPrimColor(UINT32 w1, UINT32 w2) |
| 3357 | void n64_rdp::CmdSetPrimColor(UINT32 w1, UINT32 w2) |
| 2959 | 3358 | { |
| 2960 | 3359 | MiscState.MinLevel = (w1 >> 8) & 0x1f; |
| 2961 | 3360 | PrimLODFraction = w1 & 0xff; |
| 2962 | 3361 | PrimColor.c = w2; |
| 2963 | 3362 | } |
| 2964 | 3363 | |
| 2965 | | void N64::RDP::Processor::CmdSetEnvColor(UINT32 w1, UINT32 w2) |
| 3364 | void n64_rdp::CmdSetEnvColor(UINT32 w1, UINT32 w2) |
| 2966 | 3365 | { |
| 2967 | 3366 | EnvColor.c = w2; |
| 2968 | 3367 | } |
| 2969 | 3368 | |
| 2970 | | void N64::RDP::Processor::CmdSetCombine(UINT32 w1, UINT32 w2) |
| 3369 | void n64_rdp::CmdSetCombine(UINT32 w1, UINT32 w2) |
| 2971 | 3370 | { |
| 2972 | 3371 | m_combine.sub_a_rgb0 = (w1 >> 20) & 0xf; |
| 2973 | 3372 | m_combine.mul_rgb0 = (w1 >> 15) & 0x1f; |
| r14423 | r14424 | |
| 2986 | 3385 | m_combine.add_rgb1 = (w2 >> 6) & 0x7; |
| 2987 | 3386 | m_combine.sub_b_a1 = (w2 >> 3) & 0x7; |
| 2988 | 3387 | m_combine.add_a1 = (w2 >> 0) & 0x7; |
| 2989 | | |
| 2990 | | SetSubAInputRGB(&ColorInputs.combiner_rgbsub_a_r[0], &ColorInputs.combiner_rgbsub_a_g[0], &ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0); |
| 2991 | | SetSubBInputRGB(&ColorInputs.combiner_rgbsub_b_r[0], &ColorInputs.combiner_rgbsub_b_g[0], &ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0); |
| 2992 | | SetMulInputRGB(&ColorInputs.combiner_rgbmul_r[0], &ColorInputs.combiner_rgbmul_g[0], &ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0); |
| 2993 | | SetAddInputRGB(&ColorInputs.combiner_rgbadd_r[0], &ColorInputs.combiner_rgbadd_g[0], &ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0); |
| 2994 | | SetSubInputAlpha(&ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0); |
| 2995 | | SetSubInputAlpha(&ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0); |
| 2996 | | SetMulInputAlpha(&ColorInputs.combiner_alphamul[0], m_combine.mul_a0); |
| 2997 | | SetSubInputAlpha(&ColorInputs.combiner_alphaadd[0], m_combine.add_a0); |
| 2998 | | |
| 2999 | | SetSubAInputRGB(&ColorInputs.combiner_rgbsub_a_r[1], &ColorInputs.combiner_rgbsub_a_g[1], &ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1); |
| 3000 | | SetSubBInputRGB(&ColorInputs.combiner_rgbsub_b_r[1], &ColorInputs.combiner_rgbsub_b_g[1], &ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1); |
| 3001 | | SetMulInputRGB(&ColorInputs.combiner_rgbmul_r[1], &ColorInputs.combiner_rgbmul_g[1], &ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1); |
| 3002 | | SetAddInputRGB(&ColorInputs.combiner_rgbadd_r[1], &ColorInputs.combiner_rgbadd_g[1], &ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1); |
| 3003 | | SetSubInputAlpha(&ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1); |
| 3004 | | SetSubInputAlpha(&ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1); |
| 3005 | | SetMulInputAlpha(&ColorInputs.combiner_alphamul[1], m_combine.mul_a1); |
| 3006 | | SetSubInputAlpha(&ColorInputs.combiner_alphaadd[1], m_combine.add_a1); |
| 3007 | 3388 | } |
| 3008 | 3389 | |
| 3009 | | void N64::RDP::Processor::CmdSetTextureImage(UINT32 w1, UINT32 w2) |
| 3390 | void n64_rdp::CmdSetTextureImage(UINT32 w1, UINT32 w2) |
| 3010 | 3391 | { |
| 3011 | 3392 | MiscState.TIFormat = (w1 >> 21) & 0x7; |
| 3012 | 3393 | MiscState.TISize = (w1 >> 19) & 0x3; |
| r14423 | r14424 | |
| 3014 | 3395 | MiscState.TIAddress = w2 & 0x01ffffff; |
| 3015 | 3396 | } |
| 3016 | 3397 | |
| 3017 | | void N64::RDP::Processor::CmdSetMaskImage(UINT32 w1, UINT32 w2) |
| 3398 | void n64_rdp::CmdSetMaskImage(UINT32 w1, UINT32 w2) |
| 3018 | 3399 | { |
| 3019 | 3400 | MiscState.ZBAddress = w2 & 0x01ffffff; |
| 3020 | 3401 | } |
| 3021 | 3402 | |
| 3022 | | void N64::RDP::Processor::CmdSetColorImage(UINT32 w1, UINT32 w2) |
| 3403 | void n64_rdp::CmdSetColorImage(UINT32 w1, UINT32 w2) |
| 3023 | 3404 | { |
| 3024 | 3405 | MiscState.FBFormat = (w1 >> 21) & 0x7; |
| 3025 | 3406 | MiscState.FBSize = (w1 >> 19) & 0x3; |
| r14423 | r14424 | |
| 3044 | 3425 | } |
| 3045 | 3426 | } |
| 3046 | 3427 | |
| 3047 | | UINT32 N64::RDP::Processor::AddRightCvg(UINT32 x, UINT32 k) |
| 3428 | UINT32 n64_rdp::AddRightCvg(UINT32 x, UINT32 k) |
| 3048 | 3429 | { |
| 3049 | 3430 | //#undef FULL_SUBPIXELS |
| 3050 | 3431 | #define FULL_SUBPIXELS |
| r14423 | r14424 | |
| 3088 | 3469 | } |
| 3089 | 3470 | } |
| 3090 | 3471 | |
| 3091 | | UINT32 N64::RDP::Processor::AddLeftCvg(UINT32 x, UINT32 k) |
| 3472 | UINT32 n64_rdp::AddLeftCvg(UINT32 x, UINT32 k) |
| 3092 | 3473 | { |
| 3093 | 3474 | UINT32 coveredsubpixels = 3 - ((x >> 14) & 3); |
| 3094 | 3475 | if (!(x & 0xffff)) |
| r14423 | r14424 | |
| 3132 | 3513 | |
| 3133 | 3514 | /*****************************************************************************/ |
| 3134 | 3515 | |
| 3135 | | void N64::RDP::Processor::CmdInvalid(UINT32 w1, UINT32 w2) |
| 3516 | void n64_rdp::CmdInvalid(UINT32 w1, UINT32 w2) |
| 3136 | 3517 | { |
| 3137 | | fatalerror("N64::RDP::Processor::Invalid: %d, %08x %08x\n", (w1 >> 24) & 0x3f, w1, w2); |
| 3518 | fatalerror("n64_rdp::Invalid: %d, %08x %08x\n", (w1 >> 24) & 0x3f, w1, w2); |
| 3138 | 3519 | } |
| 3139 | 3520 | |
| 3140 | | void N64::RDP::Processor::CmdNoOp(UINT32 w1, UINT32 w2) |
| 3521 | void n64_rdp::CmdNoOp(UINT32 w1, UINT32 w2) |
| 3141 | 3522 | { |
| 3142 | 3523 | // Do nothing |
| 3143 | 3524 | } |
| 3144 | 3525 | |
| 3145 | 3526 | |
| 3146 | | void N64::RDP::Processor::ProcessList() |
| 3527 | void n64_rdp::ProcessList() |
| 3147 | 3528 | { |
| 3148 | 3529 | UINT32 length = m_end - m_current; |
| 3149 | 3530 | |
| 3150 | | //printf("length %08x\n", length); |
| 3151 | | //printf("end %08x\n", m_end); |
| 3152 | | //printf("current %08x\n", m_current); |
| 3153 | | |
| 3154 | 3531 | // load command data |
| 3155 | 3532 | for(int i = 0; i < length; i += 4) |
| 3156 | 3533 | { |
| 3157 | | //printf("%08x\n", m_current); |
| 3158 | 3534 | m_cmd_data[m_cmd_ptr++] = ReadData((m_current & 0x1fffffff) + i); |
| 3159 | 3535 | } |
| 3160 | 3536 | |
| 3161 | | //printf("Queued\n"); |
| 3162 | 3537 | m_current = m_end; |
| 3163 | 3538 | |
| 3164 | 3539 | UINT32 cmd = (m_cmd_data[0] >> 24) & 0x3f; |
| r14423 | r14424 | |
| 3169 | 3544 | // check if more data is needed |
| 3170 | 3545 | if (cmd_length < rdp_command_length[cmd]) |
| 3171 | 3546 | { |
| 3172 | | //printf("Early-out\n"); |
| 3173 | 3547 | return; |
| 3174 | 3548 | } |
| 3175 | 3549 | |
| 3176 | 3550 | while (m_cmd_cur < m_cmd_ptr) |
| 3177 | 3551 | { |
| 3178 | | //printf("Command\n"); |
| 3179 | 3552 | cmd = (m_cmd_data[m_cmd_cur] >> 24) & 0x3f; |
| 3180 | 3553 | |
| 3181 | 3554 | if (((m_cmd_ptr - m_cmd_cur) * 4) < rdp_command_length[cmd]) |
| r14423 | r14424 | |
| 3253 | 3626 | m_cmd_cur = 0; |
| 3254 | 3627 | |
| 3255 | 3628 | m_start = m_current = m_end; |
| 3256 | | //printf("Done RDP\n"); |
| 3257 | 3629 | } |
| 3258 | 3630 | |
| 3259 | | } // namespace RDP |
| 3631 | /*****************************************************************************/ |
| 3260 | 3632 | |
| 3261 | | } // namespace N64 |
| 3633 | n64_rdp::n64_rdp(n64_state &state) : poly_manager<UINT32, rdp_poly_state, 8, 32000>(state.machine()) |
| 3634 | { |
| 3635 | AuxBufIndex = 0; |
| 3636 | AuxBufPtr[0] = AuxBufPtr[1] = 0; |
| 3637 | AuxBuf[0] = AuxBuf[1] = NULL; |
| 3638 | m_pipe_clean = true; |
| 3262 | 3639 | |
| 3263 | | /*****************************************************************************/ |
| 3640 | m_pending_mode_block = false; |
| 3264 | 3641 | |
| 3642 | m_cmd_ptr = 0; |
| 3643 | m_cmd_cur = 0; |
| 3644 | |
| 3645 | m_start = 0; |
| 3646 | m_end = 0; |
| 3647 | m_current = 0; |
| 3648 | m_status = 0x88; |
| 3649 | |
| 3650 | for (int i = 0; i < 8; i++) |
| 3651 | { |
| 3652 | m_tiles[i].num = i; |
| 3653 | } |
| 3654 | |
| 3655 | OneColor.c = 0xffffffff; |
| 3656 | ZeroColor.c = 0x00000000; |
| 3657 | |
| 3658 | m_tmem = NULL; |
| 3659 | |
| 3660 | m_machine = NULL; |
| 3661 | |
| 3662 | //memset(m_hidden_bits, 3, 8388608); |
| 3663 | |
| 3664 | PrimLODFraction = 0; |
| 3665 | |
| 3666 | for (int i = 0; i < 256; i++) |
| 3667 | { |
| 3668 | m_gamma_table[i] = sqrt((float)(i << 6)); |
| 3669 | m_gamma_table[i] <<= 1; |
| 3670 | } |
| 3671 | |
| 3672 | for (int i = 0; i < 0x4000; i++) |
| 3673 | { |
| 3674 | m_gamma_dither_table[i] = sqrt((float)i); |
| 3675 | m_gamma_dither_table[i] <<= 1; |
| 3676 | } |
| 3677 | |
| 3678 | z_build_com_table(); |
| 3679 | |
| 3680 | for (int i = 0; i < 0x4000; i++) |
| 3681 | { |
| 3682 | UINT32 exponent = (i >> 11) & 7; |
| 3683 | UINT32 mantissa = i & 0x7ff; |
| 3684 | z_complete_dec_table[i] = ((mantissa << z_dec_table[exponent].shift) + z_dec_table[exponent].add) & 0x3fffff; |
| 3685 | } |
| 3686 | |
| 3687 | precalc_cvmask_derivatives(); |
| 3688 | |
| 3689 | for(int i = 0; i < 0x200; i++) |
| 3690 | { |
| 3691 | switch((i >> 7) & 3) |
| 3692 | { |
| 3693 | case 0: |
| 3694 | case 1: |
| 3695 | m_special_9bit_clamptable[i] = i & 0xff; |
| 3696 | break; |
| 3697 | case 2: |
| 3698 | m_special_9bit_clamptable[i] = 0xff; |
| 3699 | break; |
| 3700 | case 3: |
| 3701 | m_special_9bit_clamptable[i] = 0; |
| 3702 | break; |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | for(int i = 0; i < 32; i++) |
| 3707 | { |
| 3708 | ReplicatedRGBA[i] = (i << 3) | ((i >> 2) & 7); |
| 3709 | } |
| 3710 | |
| 3711 | _Write[0] = &n64_rdp::_Write16Bit_Cvg0_NoBlend; |
| 3712 | _Write[1] = &n64_rdp::_Write16Bit_Cvg0_Blend; |
| 3713 | _Write[2] = &n64_rdp::_Write16Bit_Cvg1; |
| 3714 | _Write[3] = &n64_rdp::_Write16Bit_Cvg1; |
| 3715 | _Write[4] = &n64_rdp::_Write16Bit_Cvg2; |
| 3716 | _Write[5] = &n64_rdp::_Write16Bit_Cvg2; |
| 3717 | _Write[6] = &n64_rdp::_Write16Bit_Cvg3; |
| 3718 | _Write[7] = &n64_rdp::_Write16Bit_Cvg3; |
| 3719 | _Write[8] = &n64_rdp::_Write32Bit_Cvg0_NoBlend; |
| 3720 | _Write[9] = &n64_rdp::_Write32Bit_Cvg0_Blend; |
| 3721 | _Write[10] = &n64_rdp::_Write32Bit_Cvg1; |
| 3722 | _Write[11] = &n64_rdp::_Write32Bit_Cvg1; |
| 3723 | _Write[12] = &n64_rdp::_Write32Bit_Cvg2; |
| 3724 | _Write[13] = &n64_rdp::_Write32Bit_Cvg2; |
| 3725 | _Write[14] = &n64_rdp::_Write32Bit_Cvg3; |
| 3726 | _Write[15] = &n64_rdp::_Write32Bit_Cvg3; |
| 3727 | |
| 3728 | _Read[0] = &n64_rdp::_Read16Bit_ImgRead0; |
| 3729 | _Read[1] = &n64_rdp::_Read16Bit_ImgRead1; |
| 3730 | _Read[2] = &n64_rdp::_Read32Bit_ImgRead0; |
| 3731 | _Read[3] = &n64_rdp::_Read32Bit_ImgRead1; |
| 3732 | |
| 3733 | _Copy[0] = &n64_rdp::_Copy16Bit; |
| 3734 | _Copy[1] = &n64_rdp::_Copy32Bit; |
| 3735 | |
| 3736 | _Fill[0] = &n64_rdp::_Fill16Bit; |
| 3737 | _Fill[1] = &n64_rdp::_Fill32Bit; |
| 3738 | } |
| 3739 | |
| 3265 | 3740 | VIDEO_START(n64) |
| 3266 | 3741 | { |
| 3267 | | _n64_state *state = machine.driver_data<_n64_state>(); |
| 3742 | n64_state *state = machine.driver_data<n64_state>(); |
| 3268 | 3743 | |
| 3269 | | state->m_rdp.SetMachine(machine); |
| 3270 | | state->m_rdp.InitInternalState(); |
| 3744 | state->m_rdp = auto_alloc(machine, n64_rdp(*state)); |
| 3271 | 3745 | |
| 3272 | | state->m_rdp.Blender.SetMachine(machine); |
| 3273 | | state->m_rdp.Blender.SetProcessor(&state->m_rdp); |
| 3746 | state->m_rdp->SetMachine(machine); |
| 3747 | state->m_rdp->InitInternalState(); |
| 3274 | 3748 | |
| 3275 | | state->m_rdp.Framebuffer.SetProcessor(&state->m_rdp); |
| 3749 | state->m_rdp->Blender.SetMachine(machine); |
| 3750 | state->m_rdp->Blender.SetProcessor(state->m_rdp); |
| 3276 | 3751 | |
| 3277 | | state->m_rdp.TexPipe.SetMachine(machine); |
| 3752 | state->m_rdp->TexPipe.SetMachine(machine); |
| 3278 | 3753 | |
| 3754 | state->m_rdp->AuxBuf[0] = auto_alloc_array_clear(machine, UINT8, EXTENT_AUX_COUNT); |
| 3755 | state->m_rdp->AuxBuf[1] = auto_alloc_array_clear(machine, UINT8, EXTENT_AUX_COUNT); |
| 3756 | |
| 3279 | 3757 | if (LOG_RDP_EXECUTION) |
| 3280 | 3758 | { |
| 3281 | 3759 | rdp_exec = fopen("rdp_execute.txt", "wt"); |
| 3282 | 3760 | } |
| 3283 | | |
| 3284 | | printf("A"); |
| 3285 | | for (int i = 0; i < 4096; i++) |
| 3286 | | { |
| 3287 | | state->m_rdp.Spans[i].SetMachine(machine); |
| 3288 | | } |
| 3289 | | printf("B"); |
| 3290 | 3761 | } |
| 3291 | 3762 | |
| 3292 | 3763 | SCREEN_UPDATE_RGB32(n64) |
| 3293 | 3764 | { |
| 3294 | | _n64_state *state = screen.machine().driver_data<_n64_state>(); |
| 3765 | n64_state *state = screen.machine().driver_data<n64_state>(); |
| 3295 | 3766 | n64_periphs *n64 = screen.machine().device<n64_periphs>("rcp"); |
| 3767 | state->m_rdp->visarea = screen.visible_area(); |
| 3296 | 3768 | |
| 3297 | | int height = state->m_rdp.MiscState.FBHeight; |
| 3769 | int height = state->m_rdp->MiscState.FBHeight; |
| 3298 | 3770 | //UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; |
| 3299 | 3771 | //UINT8 *cvg_buffer = &state->m_rdp.HiddenBits[((n64->vi_origin & 0xffffff) >> 2) >> 1]; |
| 3300 | 3772 | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot); |
| r14423 | r14424 | |
| 3333 | 3805 | } |
| 3334 | 3806 | */ |
| 3335 | 3807 | |
| 3808 | state->m_rdp->AuxBufPtr[state->m_rdp->AuxBufIndex] = 0; |
| 3809 | state->m_rdp->AuxBufIndex ^= 1; |
| 3810 | |
| 3336 | 3811 | if (n64->vi_blank) |
| 3337 | 3812 | { |
| 3338 | 3813 | for (int j = 0; j <height; j++) |
| 3339 | 3814 | { |
| 3340 | 3815 | UINT32 *d = &bitmap.pix32(j); |
| 3341 | | for (int i = 0; i < state->m_rdp.MiscState.FBWidth; i++) |
| 3816 | for (int i = 0; i < state->m_rdp->MiscState.FBWidth; i++) |
| 3342 | 3817 | { |
| 3343 | 3818 | d[BYTE_XOR_BE(i)] = 0; |
| 3344 | 3819 | } |
| r14423 | r14424 | |
| 3346 | 3821 | return 0; |
| 3347 | 3822 | } |
| 3348 | 3823 | |
| 3349 | | state->m_rdp.VideoUpdate(n64, bitmap); |
| 3824 | state->m_rdp->wait(); |
| 3825 | state->m_rdp->VideoUpdate(n64, bitmap); |
| 3350 | 3826 | |
| 3351 | 3827 | return 0; |
| 3352 | 3828 | } |
src/mame/video/n64.h
| r14423 | r14424 | |
| 2 | 2 | #define _VIDEO_N64_H_ |
| 3 | 3 | |
| 4 | 4 | #include "emu.h" |
| 5 | #include "includes/n64.h" |
| 6 | #include "video/polynew.h" |
| 5 | 7 | #include "video/rdpblend.h" |
| 6 | | #include "video/rdptri.h" |
| 7 | | #include "video/rdpfb.h" |
| 8 | 8 | #include "video/rdptpipe.h" |
| 9 | | #include "video/rdpspn16.h" |
| 10 | 9 | |
| 11 | 10 | /*****************************************************************************/ |
| 12 | 11 | |
| r14423 | r14424 | |
| 57 | 56 | #define MEM16_LIMIT 0x3fffff |
| 58 | 57 | #define MEM32_LIMIT 0x1fffff |
| 59 | 58 | |
| 60 | | #define RREADADDR8(in) (((in) <= MEM8_LIMIT) ? (((UINT8*)rdram)[(in) ^ BYTE_ADDR_XOR]) : 0) |
| 61 | | #define RREADIDX16(in) (((in) <= MEM16_LIMIT) ? (((UINT16*)rdram)[(in) ^ WORD_ADDR_XOR]) : 0) |
| 62 | | #define RREADIDX32(in) (((in) <= MEM32_LIMIT) ? (rdram[(in)]) : 0) |
| 59 | #define RREADADDR8(in) /*(((in) <= MEM8_LIMIT) ? */(((UINT8*)rdram)[(in) ^ BYTE_ADDR_XOR]) /*: 0)*/ |
| 60 | #define RREADIDX16(in) /*(((in) <= MEM16_LIMIT) ? */(((UINT16*)rdram)[(in) ^ WORD_ADDR_XOR]) /*: 0)*/ |
| 61 | #define RREADIDX32(in) /*(((in) <= MEM32_LIMIT) ? */(rdram[(in)]) /*: 0)*/ |
| 63 | 62 | |
| 64 | | #define RWRITEADDR8(in, val) {if ((in) <= MEM8_LIMIT) ((UINT8*)rdram)[(in) ^ BYTE_ADDR_XOR] = val;} |
| 65 | | #define RWRITEIDX16(in, val) {if ((in) <= MEM16_LIMIT) ((UINT16*)rdram)[(in) ^ WORD_ADDR_XOR] = val;} |
| 66 | | #define RWRITEIDX32(in, val) {if ((in) <= MEM32_LIMIT) rdram[(in)] = val;} |
| 63 | #define RWRITEADDR8(in, val) {/*if ((in) <= MEM8_LIMIT) */((UINT8*)rdram)[(in) ^ BYTE_ADDR_XOR] = val;} |
| 64 | #define RWRITEIDX16(in, val) {/*if ((in) <= MEM16_LIMIT)*/ ((UINT16*)rdram)[(in) ^ WORD_ADDR_XOR] = val;} |
| 65 | #define RWRITEIDX32(in, val) {/*if ((in) <= MEM32_LIMIT)*/ rdram[(in)] = val;} |
| 67 | 66 | |
| 68 | 67 | #define GETLOWCOL(x) (((x) & 0x3e) << 2) |
| 69 | 68 | #define GETMEDCOL(x) (((x) & 0x7c0) >> 3) |
| 70 | 69 | #define GETHICOL(x) (((x) & 0xf800) >> 8) |
| 71 | 70 | |
| 72 | | #define HREADADDR8(in) (((in) <= MEM8_LIMIT) ? (m_rdp->HiddenBits[(in) ^ BYTE_ADDR_XOR]) : 0) |
| 73 | | #define HWRITEADDR8(in, val) {if ((in) <= MEM8_LIMIT) m_rdp->HiddenBits[(in) ^ BYTE_ADDR_XOR] = val;} |
| 71 | #define HREADADDR8(in) /*(((in) <= MEM8_LIMIT) ? */(HiddenBits[(in) ^ BYTE_ADDR_XOR])/* : 0)*/ |
| 72 | #define HWRITEADDR8(in, val) /*{if ((in) <= MEM8_LIMIT) */HiddenBits[(in) ^ BYTE_ADDR_XOR] = val;/*}*/ |
| 74 | 73 | |
| 75 | 74 | //sign-extension macros |
| 76 | 75 | #define SIGN22(x) (((x) & 0x200000) ? ((x) | ~0x3fffff) : ((x) & 0x3fffff)) |
| r14423 | r14424 | |
| 83 | 82 | |
| 84 | 83 | #define KURT_AKELEY_SIGN9(x) ((((x) & 0x180) == 0x180) ? ((x) | ~0x1ff) : ((x) & 0x1ff)) |
| 85 | 84 | |
| 86 | | /*****************************************************************************/ |
| 85 | #define SPAN_R (0) |
| 86 | #define SPAN_G (1) |
| 87 | #define SPAN_B (2) |
| 88 | #define SPAN_A (3) |
| 89 | #define SPAN_S (4) |
| 90 | #define SPAN_T (5) |
| 91 | #define SPAN_W (6) |
| 92 | #define SPAN_Z (7) |
| 87 | 93 | |
| 88 | | class n64_periphs; |
| 94 | #define RDP_CVG_SPAN_MAX (1024) |
| 89 | 95 | |
| 90 | | namespace N64 |
| 91 | | { |
| 96 | #define EXTENT_AUX_COUNT (sizeof(rdp_span_aux)*(480*128)) // Screen coverage *128, more or less |
| 92 | 97 | |
| 93 | | namespace RDP |
| 94 | | { |
| 98 | /*****************************************************************************/ |
| 95 | 99 | |
| 96 | | class Processor; |
| 97 | | class MiscStateT; |
| 98 | | class OtherModesT; |
| 100 | class n64_periphs; |
| 101 | class n64_rdp; |
| 99 | 102 | |
| 103 | struct MiscStateT; |
| 104 | struct OtherModesT; |
| 105 | struct CombineModesT; |
| 106 | struct ColorInputsT; |
| 107 | struct SpanBaseT; |
| 108 | struct Rectangle; |
| 109 | |
| 100 | 110 | class Color |
| 101 | 111 | { |
| 102 | 112 | public: |
| r14423 | r14424 | |
| 124 | 134 | BIT_DEPTH_COUNT |
| 125 | 135 | }; |
| 126 | 136 | |
| 127 | | class Tile |
| 137 | class SpanParam |
| 128 | 138 | { |
| 129 | 139 | public: |
| 130 | | int format; // Image data format: RGBA, YUV, CI, IA, I |
| 131 | | int size; // Size of texel element: 4b, 8b, 16b, 32b |
| 132 | | int line; // Size of tile line in bytes |
| 133 | | int tmem; // Starting tmem address for this tile in bytes |
| 134 | | int palette; // Palette number for 4b CI texels |
| 135 | | int ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction |
| 136 | | int mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts |
| 137 | | UINT16 sl, tl, sh, th; // 10.2 fixed-point, starting and ending texel row / column |
| 138 | | int num; |
| 140 | union |
| 141 | { |
| 142 | UINT32 w; |
| 143 | #ifdef LSB_FIRST |
| 144 | struct { UINT16 l; INT16 h; } h; |
| 145 | #else |
| 146 | struct { INT16 h; UINT16 l; } h; |
| 147 | #endif |
| 148 | }; |
| 139 | 149 | }; |
| 140 | 150 | |
| 141 | | class MiscStateT |
| 151 | struct N64Tile |
| 142 | 152 | { |
| 143 | | public: |
| 144 | | MiscStateT() |
| 145 | | { |
| 146 | | CurrentPixCvg = 0; |
| 147 | | CurrentMemCvg = 0; |
| 148 | | CurrentCvgBit = 0; |
| 149 | | CurrentPixOverlap = 0; |
| 153 | int format; // Image data format: RGBA, YUV, CI, IA, I |
| 154 | int size; // Size of texel element: 4b, 8b, 16b, 32b |
| 155 | int line; // Size of tile line in bytes |
| 156 | int tmem; // Starting tmem address for this tile in bytes |
| 157 | int palette; // Palette number for 4b CI texels |
| 158 | int ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction |
| 159 | int mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts |
| 160 | UINT16 sl, tl, sh, th; // 10.2 fixed-point, starting and ending texel row / column |
| 161 | int num; |
| 162 | }; |
| 150 | 163 | |
| 151 | | MaxLevel = 0; |
| 152 | | MinLevel = 0; |
| 153 | | } |
| 164 | struct SpanBaseT |
| 165 | { |
| 166 | int m_span_dr; |
| 167 | int m_span_dg; |
| 168 | int m_span_db; |
| 169 | int m_span_da; |
| 170 | int m_span_ds; |
| 171 | int m_span_dt; |
| 172 | int m_span_dw; |
| 173 | int m_span_dz; |
| 174 | int m_span_dymax; |
| 175 | int m_span_dzpix; |
| 176 | int m_span_drdy; |
| 177 | int m_span_dgdy; |
| 178 | int m_span_dbdy; |
| 179 | int m_span_dady; |
| 180 | int m_span_dzdy; |
| 181 | }; |
| 154 | 182 | |
| 155 | | int FBFormat; // Framebuffer pixel format index (0 - I, 1 - IA, 2 - CI, 3 - RGBA) |
| 156 | | int FBSize; // Framebuffer pixel size index (0 - 4bpp, 1 - 8bpp, 2 - 16bpp, 3 - 32bpp) |
| 157 | | int FBWidth; // Framebuffer width, in pixels |
| 158 | | int FBHeight; // Framebuffer height, in scanlines |
| 159 | | UINT32 FBAddress; // Framebuffer source address offset (in bytes) from start of RDRAM |
| 183 | struct MiscStateT |
| 184 | { |
| 185 | MiscStateT() |
| 186 | { |
| 187 | MaxLevel = 0; |
| 188 | MinLevel = 0; |
| 189 | } |
| 160 | 190 | |
| 161 | | UINT32 ZBAddress; // Z-buffer source address offset (in bytes) from start of RDRAM |
| 191 | int FBFormat; // Framebuffer pixel format index (0 - I, 1 - IA, 2 - CI, 3 - RGBA) |
| 192 | int FBSize; // Framebuffer pixel size index (0 - 4bpp, 1 - 8bpp, 2 - 16bpp, 3 - 32bpp) |
| 193 | int FBWidth; // Framebuffer width, in pixels |
| 194 | int FBHeight; // Framebuffer height, in scanlines |
| 195 | UINT32 FBAddress; // Framebuffer source address offset (in bytes) from start of RDRAM |
| 162 | 196 | |
| 163 | | int TIFormat; // Format for Texture Interface (TI) transfers |
| 164 | | int TISize; // Size (in bytes) of TI transfers |
| 165 | | int TIWidth; // Width (in pixels) of TI transfers |
| 166 | | UINT32 TIAddress; // Destination address for TI transfers |
| 197 | UINT32 ZBAddress; // Z-buffer source address offset (in bytes) from start of RDRAM |
| 167 | 198 | |
| 168 | | UINT32 CurrentPixCvg; // Coverage for the current pixel |
| 169 | | UINT32 CurrentMemCvg; // Incoming coverage, in memory, for the current pixel |
| 170 | | UINT32 CurrentCvgBit; // Bitfield representation of current coverage value |
| 171 | | UINT32 CurrentPixOverlap; // Current overlap value, in coverage indices, for the current pixel |
| 199 | int TIFormat; // Format for Texture Interface (TI) transfers |
| 200 | int TISize; // Size (in bytes) of TI transfers |
| 201 | int TIWidth; // Width (in pixels) of TI transfers |
| 202 | UINT32 TIAddress; // Destination address for TI transfers |
| 172 | 203 | |
| 173 | | UINT8 RandomSeed; // %HACK%, adds 19 each time it's read and is more or less random |
| 204 | UINT8 RandomSeed; // %HACK%, adds 19 each time it's read and is more or less random |
| 174 | 205 | |
| 175 | | int SpecialBlendSelect0; // Special blend-mode select for cycle 0 |
| 176 | | int SpecialBlendSelect1; // Special blend-mode select for cycle 1 |
| 206 | int SpecialBlendSelect0; // Special blend-mode select for cycle 0 |
| 207 | int SpecialBlendSelect1; // Special blend-mode select for cycle 1 |
| 177 | 208 | |
| 178 | | UINT32 MaxLevel; // Maximum LOD level for texture filtering |
| 179 | | UINT32 MinLevel; // Minimum LOD level for texture filtering |
| 209 | UINT32 MaxLevel; // Maximum LOD level for texture filtering |
| 210 | UINT32 MinLevel; // Minimum LOD level for texture filtering |
| 180 | 211 | |
| 181 | | UINT16 PrimitiveZ; // Forced Z value for current primitive, if applicable |
| 182 | | UINT16 PrimitiveDZ; // Forced Delta-Z value for current primitive, if applicable |
| 212 | UINT16 PrimitiveZ; // Forced Z value for current primitive, if applicable |
| 213 | UINT16 PrimitiveDZ; // Forced Delta-Z value for current primitive, if applicable |
| 183 | 214 | }; |
| 184 | 215 | |
| 185 | | class CombineModes |
| 216 | struct CombineModesT |
| 186 | 217 | { |
| 187 | | public: |
| 188 | | int sub_a_rgb0; |
| 189 | | int sub_b_rgb0; |
| 190 | | int mul_rgb0; |
| 191 | | int add_rgb0; |
| 192 | | int sub_a_a0; |
| 193 | | int sub_b_a0; |
| 194 | | int mul_a0; |
| 195 | | int add_a0; |
| 218 | int sub_a_rgb0; |
| 219 | int sub_b_rgb0; |
| 220 | int mul_rgb0; |
| 221 | int add_rgb0; |
| 222 | int sub_a_a0; |
| 223 | int sub_b_a0; |
| 224 | int mul_a0; |
| 225 | int add_a0; |
| 196 | 226 | |
| 197 | | int sub_a_rgb1; |
| 198 | | int sub_b_rgb1; |
| 199 | | int mul_rgb1; |
| 200 | | int add_rgb1; |
| 201 | | int sub_a_a1; |
| 202 | | int sub_b_a1; |
| 203 | | int mul_a1; |
| 204 | | int add_a1; |
| 227 | int sub_a_rgb1; |
| 228 | int sub_b_rgb1; |
| 229 | int mul_rgb1; |
| 230 | int add_rgb1; |
| 231 | int sub_a_a1; |
| 232 | int sub_b_a1; |
| 233 | int mul_a1; |
| 234 | int add_a1; |
| 205 | 235 | }; |
| 206 | 236 | |
| 207 | | class OtherModesT |
| 237 | struct OtherModesT |
| 208 | 238 | { |
| 209 | | public: |
| 210 | | int cycle_type; |
| 211 | | bool persp_tex_en; |
| 212 | | bool detail_tex_en; |
| 213 | | bool sharpen_tex_en; |
| 214 | | bool tex_lod_en; |
| 215 | | bool en_tlut; |
| 216 | | bool tlut_type; |
| 217 | | bool sample_type; |
| 218 | | bool mid_texel; |
| 219 | | bool bi_lerp0; |
| 220 | | bool bi_lerp1; |
| 221 | | bool convert_one; |
| 222 | | bool key_en; |
| 223 | | int rgb_dither_sel; |
| 224 | | int alpha_dither_sel; |
| 225 | | int blend_m1a_0; |
| 226 | | int blend_m1a_1; |
| 227 | | int blend_m1b_0; |
| 228 | | int blend_m1b_1; |
| 229 | | int blend_m2a_0; |
| 230 | | int blend_m2a_1; |
| 231 | | int blend_m2b_0; |
| 232 | | int blend_m2b_1; |
| 233 | | int tex_edge; |
| 234 | | bool force_blend; |
| 235 | | bool alpha_cvg_select; |
| 236 | | bool cvg_times_alpha; |
| 237 | | int z_mode; |
| 238 | | int cvg_dest; |
| 239 | | bool color_on_cvg; |
| 240 | | bool image_read_en; |
| 241 | | bool z_update_en; |
| 242 | | bool z_compare_en; |
| 243 | | bool antialias_en; |
| 244 | | bool z_source_sel; |
| 245 | | bool dither_alpha_en; |
| 246 | | bool alpha_compare_en; |
| 239 | int cycle_type; |
| 240 | bool persp_tex_en; |
| 241 | bool detail_tex_en; |
| 242 | bool sharpen_tex_en; |
| 243 | bool tex_lod_en; |
| 244 | bool en_tlut; |
| 245 | bool tlut_type; |
| 246 | bool sample_type; |
| 247 | bool mid_texel; |
| 248 | bool bi_lerp0; |
| 249 | bool bi_lerp1; |
| 250 | bool convert_one; |
| 251 | bool key_en; |
| 252 | int rgb_dither_sel; |
| 253 | int alpha_dither_sel; |
| 254 | int blend_m1a_0; |
| 255 | int blend_m1a_1; |
| 256 | int blend_m1b_0; |
| 257 | int blend_m1b_1; |
| 258 | int blend_m2a_0; |
| 259 | int blend_m2a_1; |
| 260 | int blend_m2b_0; |
| 261 | int blend_m2b_1; |
| 262 | int tex_edge; |
| 263 | bool force_blend; |
| 264 | bool alpha_cvg_select; |
| 265 | bool cvg_times_alpha; |
| 266 | int z_mode; |
| 267 | int cvg_dest; |
| 268 | bool color_on_cvg; |
| 269 | UINT8 image_read_en; |
| 270 | bool z_update_en; |
| 271 | bool z_compare_en; |
| 272 | bool antialias_en; |
| 273 | bool z_source_sel; |
| 274 | bool dither_alpha_en; |
| 275 | bool alpha_compare_en; |
| 247 | 276 | }; |
| 248 | 277 | |
| 249 | | class ColorInputsT |
| 278 | struct ColorInputsT |
| 250 | 279 | { |
| 251 | | public: |
| 252 | | // combiner inputs |
| 253 | | UINT8 *combiner_rgbsub_a_r[2]; |
| 254 | | UINT8 *combiner_rgbsub_a_g[2]; |
| 255 | | UINT8 *combiner_rgbsub_a_b[2]; |
| 256 | | UINT8 *combiner_rgbsub_b_r[2]; |
| 257 | | UINT8 *combiner_rgbsub_b_g[2]; |
| 258 | | UINT8 *combiner_rgbsub_b_b[2]; |
| 259 | | UINT8 *combiner_rgbmul_r[2]; |
| 260 | | UINT8 *combiner_rgbmul_g[2]; |
| 261 | | UINT8 *combiner_rgbmul_b[2]; |
| 262 | | UINT8 *combiner_rgbadd_r[2]; |
| 263 | | UINT8 *combiner_rgbadd_g[2]; |
| 264 | | UINT8 *combiner_rgbadd_b[2]; |
| 280 | // combiner inputs |
| 281 | UINT8 *combiner_rgbsub_a_r[2]; |
| 282 | UINT8 *combiner_rgbsub_a_g[2]; |
| 283 | UINT8 *combiner_rgbsub_a_b[2]; |
| 284 | UINT8 *combiner_rgbsub_b_r[2]; |
| 285 | UINT8 *combiner_rgbsub_b_g[2]; |
| 286 | UINT8 *combiner_rgbsub_b_b[2]; |
| 287 | UINT8 *combiner_rgbmul_r[2]; |
| 288 | UINT8 *combiner_rgbmul_g[2]; |
| 289 | UINT8 *combiner_rgbmul_b[2]; |
| 290 | UINT8 *combiner_rgbadd_r[2]; |
| 291 | UINT8 *combiner_rgbadd_g[2]; |
| 292 | UINT8 *combiner_rgbadd_b[2]; |
| 265 | 293 | |
| 266 | | UINT8 *combiner_alphasub_a[2]; |
| 267 | | UINT8 *combiner_alphasub_b[2]; |
| 268 | | UINT8 *combiner_alphamul[2]; |
| 269 | | UINT8 *combiner_alphaadd[2]; |
| 294 | UINT8 *combiner_alphasub_a[2]; |
| 295 | UINT8 *combiner_alphasub_b[2]; |
| 296 | UINT8 *combiner_alphamul[2]; |
| 297 | UINT8 *combiner_alphaadd[2]; |
| 270 | 298 | |
| 271 | | // blender input |
| 272 | | UINT8 *blender1a_r[2]; |
| 273 | | UINT8 *blender1a_g[2]; |
| 274 | | UINT8 *blender1a_b[2]; |
| 275 | | UINT8 *blender1b_a[2]; |
| 276 | | UINT8 *blender2a_r[2]; |
| 277 | | UINT8 *blender2a_g[2]; |
| 278 | | UINT8 *blender2a_b[2]; |
| 279 | | UINT8 *blender2b_a[2]; |
| 299 | // blender input |
| 300 | UINT8 *blender1a_r[2]; |
| 301 | UINT8 *blender1a_g[2]; |
| 302 | UINT8 *blender1a_b[2]; |
| 303 | UINT8 *blender1b_a[2]; |
| 304 | UINT8 *blender2a_r[2]; |
| 305 | UINT8 *blender2a_g[2]; |
| 306 | UINT8 *blender2a_b[2]; |
| 307 | UINT8 *blender2b_a[2]; |
| 280 | 308 | }; |
| 281 | 309 | |
| 310 | struct rdp_span_aux |
| 311 | { |
| 312 | UINT32 m_unscissored_rx; |
| 313 | UINT16 m_cvg[RDP_CVG_SPAN_MAX]; |
| 314 | Color MemoryColor; |
| 315 | Color PixelColor; |
| 316 | Color InvPixelColor; |
| 317 | Color BlendedPixelColor; |
| 318 | Color CombinedColor; |
| 319 | Color Texel0Color; |
| 320 | Color Texel1Color; |
| 321 | Color NextTexelColor; |
| 322 | Color BlendColor; /* constant blend color */ |
| 323 | Color PrimColor; /* flat primitive color */ |
| 324 | Color EnvColor; /* generic color constant ('environment') */ |
| 325 | Color FogColor; /* generic color constant ('fog') */ |
| 326 | Color ShadeColor; /* gouraud-shaded color */ |
| 327 | Color KeyScale; /* color-keying constant */ |
| 328 | Color NoiseColor; /* noise */ |
| 329 | UINT8 LODFraction; /* Z-based LOD fraction for this poly */ |
| 330 | UINT8 PrimLODFraction; /* fixed LOD fraction for this poly */ |
| 331 | ColorInputsT ColorInputs; |
| 332 | UINT32 CurrentPixCvg; |
| 333 | UINT32 CurrentMemCvg; |
| 334 | UINT32 CurrentCvgBit; |
| 335 | UINT32 CurrentPixOverlap; |
| 336 | INT32 ShiftA; |
| 337 | INT32 ShiftB; |
| 338 | INT32 m_precomp_s; |
| 339 | INT32 m_precomp_t; |
| 340 | INT32 m_clamp_s_diff[8]; |
| 341 | INT32 m_clamp_t_diff[8]; |
| 342 | UINT8 BlendEnable; |
| 343 | bool PreWrap; |
| 344 | INT32 m_dzpix_enc; |
| 345 | UINT8 *m_tmem; /* pointer to texture cache for this polygon */ |
| 346 | bool m_start_span; |
| 347 | }; |
| 348 | |
| 282 | 349 | struct Rectangle |
| 283 | 350 | { |
| 284 | 351 | UINT16 m_xl; // 10.2 fixed-point |
| r14423 | r14424 | |
| 287 | 354 | UINT16 m_yh; // 10.2 fixed-point |
| 288 | 355 | }; |
| 289 | 356 | |
| 290 | | class Processor |
| 357 | struct rdp_poly_state |
| 291 | 358 | { |
| 292 | | public: |
| 293 | | Processor() |
| 294 | | { |
| 295 | | m_cmd_ptr = 0; |
| 296 | | m_cmd_cur = 0; |
| 359 | n64_rdp * m_rdp; /* pointer back to the RDP state */ |
| 297 | 360 | |
| 298 | | m_start = 0; |
| 299 | | m_end = 0; |
| 300 | | m_current = 0; |
| 301 | | m_status = 0x88; |
| 361 | MiscStateT MiscState; /* miscellaneous rasterizer bits */ |
| 362 | OtherModesT OtherModes; /* miscellaneous rasterizer bits (2) */ |
| 363 | SpanBaseT SpanBase; /* span initial values for triangle rasterization */ |
| 364 | Rectangle Scissor; /* screen-space scissor bounds */ |
| 365 | UINT32 FillColor; /* poly fill color */ |
| 366 | N64Tile m_tiles[8]; /* texture tile state */ |
| 367 | UINT8 m_tmem[0x1000]; /* texture cache */ |
| 368 | int tilenum; /* texture tile index */ |
| 369 | bool flip; /* left-major / right-major flip */ |
| 370 | bool rect; /* primitive is rectangle (vs. triangle) */ |
| 371 | }; |
| 302 | 372 | |
| 303 | | for (int i = 0; i < 8; i++) |
| 304 | | { |
| 305 | | m_tiles[i].num = i; |
| 306 | | } |
| 373 | //class n64_state; |
| 307 | 374 | |
| 308 | | OneColor.c = 0xffffffff; |
| 309 | | ZeroColor.c = 0x00000000; |
| 375 | class n64_rdp : public poly_manager<UINT32, rdp_poly_state, 8, 32000> |
| 376 | { |
| 377 | public: |
| 378 | typedef void (n64_rdp::*Writer) (UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 379 | typedef void (n64_rdp::*Reader) (UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 380 | typedef void (n64_rdp::*Copier) (UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object); |
| 381 | typedef void (n64_rdp::*Filler) (UINT32 curpixel, const rdp_poly_state &object); |
| 310 | 382 | |
| 311 | | ColorInputs.combiner_rgbsub_a_r[0] = ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r; |
| 312 | | ColorInputs.combiner_rgbsub_a_g[0] = ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g; |
| 313 | | ColorInputs.combiner_rgbsub_a_b[0] = ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b; |
| 314 | | ColorInputs.combiner_rgbsub_b_r[0] = ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r; |
| 315 | | ColorInputs.combiner_rgbsub_b_g[0] = ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g; |
| 316 | | ColorInputs.combiner_rgbsub_b_b[0] = ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b; |
| 317 | | ColorInputs.combiner_rgbmul_r[0] = ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r; |
| 318 | | ColorInputs.combiner_rgbmul_g[0] = ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g; |
| 319 | | ColorInputs.combiner_rgbmul_b[0] = ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b; |
| 320 | | ColorInputs.combiner_rgbadd_r[0] = ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r; |
| 321 | | ColorInputs.combiner_rgbadd_g[0] = ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g; |
| 322 | | ColorInputs.combiner_rgbadd_b[0] = ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b; |
| 383 | n64_rdp(n64_state &state); |
| 323 | 384 | |
| 324 | | ColorInputs.combiner_alphasub_a[0] = ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a; |
| 325 | | ColorInputs.combiner_alphasub_b[0] = ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a; |
| 326 | | ColorInputs.combiner_alphamul[0] = ColorInputs.combiner_alphamul[1] = &OneColor.i.a; |
| 327 | | ColorInputs.combiner_alphaadd[0] = ColorInputs.combiner_alphaadd[1] = &OneColor.i.a; |
| 328 | | |
| 329 | | ColorInputs.blender1a_r[0] = ColorInputs.blender1a_r[1] = &PixelColor.i.r; |
| 330 | | ColorInputs.blender1a_g[0] = ColorInputs.blender1a_g[1] = &PixelColor.i.r; |
| 331 | | ColorInputs.blender1a_b[0] = ColorInputs.blender1a_b[1] = &PixelColor.i.r; |
| 332 | | ColorInputs.blender1b_a[0] = ColorInputs.blender1b_a[1] = &PixelColor.i.r; |
| 333 | | ColorInputs.blender2a_r[0] = ColorInputs.blender2a_r[1] = &PixelColor.i.r; |
| 334 | | ColorInputs.blender2a_g[0] = ColorInputs.blender2a_g[1] = &PixelColor.i.r; |
| 335 | | ColorInputs.blender2a_b[0] = ColorInputs.blender2a_b[1] = &PixelColor.i.r; |
| 336 | | ColorInputs.blender2b_a[0] = ColorInputs.blender2b_a[1] = &PixelColor.i.r; |
| 337 | | |
| 338 | | m_tmem = NULL; |
| 339 | | |
| 340 | | m_machine = NULL; |
| 341 | | |
| 342 | | //memset(m_hidden_bits, 3, 8388608); |
| 343 | | |
| 344 | | PrimLODFraction = 0; |
| 345 | | LODFraction = 0; |
| 346 | | |
| 347 | | for (int i = 0; i < 256; i++) |
| 348 | | { |
| 349 | | m_gamma_table[i] = sqrt((float)(i << 6)); |
| 350 | | m_gamma_table[i] <<= 1; |
| 351 | | } |
| 352 | | |
| 353 | | for (int i = 0; i < 0x4000; i++) |
| 354 | | { |
| 355 | | m_gamma_dither_table[i] = sqrt((float)i); |
| 356 | | m_gamma_dither_table[i] <<= 1; |
| 357 | | } |
| 358 | | |
| 359 | | z_build_com_table(); |
| 360 | | |
| 361 | | for (int i = 0; i < 0x4000; i++) |
| 362 | | { |
| 363 | | UINT32 exponent = (i >> 11) & 7; |
| 364 | | UINT32 mantissa = i & 0x7ff; |
| 365 | | z_complete_dec_table[i] = ((mantissa << z_dec_table[exponent].shift) + z_dec_table[exponent].add) & 0x3fffff; |
| 366 | | } |
| 367 | | |
| 368 | | precalc_cvmask_derivatives(); |
| 369 | | |
| 370 | | for(int i = 0; i < 0x200; i++) |
| 371 | | { |
| 372 | | switch((i >> 7) & 3) |
| 373 | | { |
| 374 | | case 0: |
| 375 | | case 1: |
| 376 | | m_special_9bit_clamptable[i] = i & 0xff; |
| 377 | | break; |
| 378 | | case 2: |
| 379 | | m_special_9bit_clamptable[i] = 0xff; |
| 380 | | break; |
| 381 | | case 3: |
| 382 | | m_special_9bit_clamptable[i] = 0; |
| 383 | | break; |
| 384 | | } |
| 385 | | } |
| 386 | | |
| 387 | | for(int i = 0; i < 32; i++) |
| 388 | | { |
| 389 | | ReplicatedRGBA[i] = (i << 3) | ((i >> 2) & 7); |
| 390 | | } |
| 391 | | } |
| 392 | | |
| 393 | | ~Processor() { } |
| 394 | | |
| 395 | | void Dasm(char *buffer); |
| 396 | | |
| 397 | | void ProcessList(); |
| 398 | | UINT32 ReadData(UINT32 address); |
| 399 | | |
| 400 | | void set_span_base(int dr, int dg, int db, int da, int ds, int dt, int dw, int dz, int dymax, int dzpix) |
| 401 | | { |
| 402 | | m_span_dr = dr; |
| 403 | | m_span_dg = dg; |
| 404 | | m_span_db = db; |
| 405 | | m_span_da = da; |
| 406 | | m_span_ds = ds; |
| 407 | | m_span_dt = dt; |
| 408 | | m_span_dw = dw; |
| 409 | | m_span_dz = dz; |
| 410 | | m_span_dymax = dymax; |
| 411 | | m_span_dzpix = dzpix; |
| 412 | | } |
| 413 | | |
| 414 | | void set_span_base_y(int dr, int dg, int db, int da, int dz) |
| 415 | | { |
| 416 | | m_span_drdy = dr; |
| 417 | | m_span_dgdy = dg; |
| 418 | | m_span_dbdy = db; |
| 419 | | m_span_dady = da; |
| 420 | | m_span_dzdy = dz; |
| 421 | | } |
| 422 | | |
| 423 | 385 | running_machine &machine() const { assert(m_machine != NULL); return *m_machine; } |
| 424 | 386 | |
| 425 | 387 | void InitInternalState() |
| r14423 | r14424 | |
| 437 | 399 | } |
| 438 | 400 | } |
| 439 | 401 | |
| 402 | void ProcessList(); |
| 403 | UINT32 ReadData(UINT32 address); |
| 404 | void Dasm(char *buffer); |
| 405 | |
| 440 | 406 | void SetMachine(running_machine& machine) { m_machine = &machine; } |
| 441 | 407 | |
| 442 | 408 | // CPU-visible registers |
| r14423 | r14424 | |
| 453 | 419 | UINT32 GetStatusReg() const { return m_status; } |
| 454 | 420 | |
| 455 | 421 | // Internal state |
| 456 | | CombineModes* GetCombine() { return &m_combine; } |
| 422 | CombineModesT* GetCombine() { return &m_combine; } |
| 457 | 423 | |
| 458 | 424 | // Color Combiner |
| 459 | 425 | INT32 ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d); |
| 460 | 426 | INT32 AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d); |
| 461 | | void ColorCombiner2Cycle(bool noisecompute); |
| 462 | | void ColorCombiner1Cycle(bool noisecompute); |
| 463 | | void SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code); |
| 464 | | void SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code); |
| 465 | | void SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code); |
| 466 | | void SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code); |
| 467 | | void SetSubInputAlpha(UINT8 **input, int code); |
| 468 | | void SetMulInputAlpha(UINT8 **input, int code); |
| 427 | void ColorCombiner2Cycle(rdp_span_aux *userdata); |
| 428 | void ColorCombiner1Cycle(rdp_span_aux *userdata); |
| 429 | void SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata); |
| 430 | void SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata); |
| 431 | void SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata); |
| 432 | void SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata); |
| 433 | void SetSubInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata); |
| 434 | void SetMulInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata); |
| 469 | 435 | |
| 470 | 436 | // Texture memory |
| 471 | 437 | UINT8* GetTMEM() { return m_tmem; } |
| 472 | 438 | UINT16* GetTMEM16() { return (UINT16*)m_tmem; } |
| 473 | 439 | UINT32* GetTMEM32() { return (UINT32*)m_tmem; } |
| 474 | 440 | UINT16* GetTLUT() { return (UINT16*)(m_tmem + 0x800); } |
| 475 | | Tile* GetTiles(){ return m_tiles; } |
| 476 | 441 | |
| 477 | 442 | // Emulation Accelerators |
| 478 | 443 | UINT8 GetRandom() { return MiscState.RandomSeed += 0x13; } |
| r14423 | r14424 | |
| 487 | 452 | INT32* GetK5() { return &m_k5; } |
| 488 | 453 | |
| 489 | 454 | // Blender-related (move into RDP::Blender) |
| 490 | | void SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b); |
| 455 | void SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b, rdp_span_aux *userdata); |
| 491 | 456 | |
| 457 | // Span rasterization |
| 458 | void SpanDraw1Cycle(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid); |
| 459 | void SpanDraw2Cycle(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid); |
| 460 | void SpanDrawCopy(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid); |
| 461 | void SpanDrawFill(INT32 scanline, const extent_t &extent, const rdp_poly_state &object, int threadid); |
| 462 | |
| 492 | 463 | // Render-related (move into eventual drawing-related classes?) |
| 493 | | Rectangle* GetScissor() { return &m_scissor; } |
| 494 | 464 | void TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst); |
| 495 | 465 | void TCDivNoPersp(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst); |
| 496 | 466 | UINT32 GetLog2(UINT32 lod_clamp); |
| 497 | | void RenderSpans(int start, int end, int tilenum, bool flip); |
| 498 | | void GetAlphaCvg(UINT8 *comb_alpha); |
| 467 | void RenderSpans(int start, int end, int tilenum, bool flip, extent_t *Spans, bool rect, rdp_poly_state &object); |
| 468 | void GetAlphaCvg(UINT8 *comb_alpha, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 499 | 469 | const UINT8* GetBayerMatrix() const { return s_bayer_matrix; } |
| 500 | 470 | const UINT8* GetMagicMatrix() const { return s_magic_matrix; } |
| 501 | 471 | int GetCurrFIFOIndex() const { return m_cmd_cur; } |
| 502 | 472 | |
| 503 | | void ZStore(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z); |
| 473 | void ZStore(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z, UINT32 enc); |
| 504 | 474 | UINT32 ZDecompress(UINT32 zcurpixel); |
| 505 | 475 | UINT32 DZDecompress(UINT32 zcurpixel, UINT32 dzcurpixel); |
| 506 | 476 | UINT32 DZCompress(UINT32 value); |
| 507 | 477 | INT32 NormalizeDZPix(INT32 sum); |
| 508 | | bool ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix); |
| 478 | bool ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 509 | 479 | |
| 510 | 480 | // Fullscreen update-related |
| 511 | 481 | void VideoUpdate(n64_periphs *n64, bitmap_rgb32 &bitmap); |
| r14423 | r14424 | |
| 549 | 519 | void CmdSetMaskImage(UINT32 w1, UINT32 w2); |
| 550 | 520 | void CmdSetColorImage(UINT32 w1, UINT32 w2); |
| 551 | 521 | |
| 522 | void RGBAZClip(int sr, int sg, int sb, int sa, int *sz, rdp_span_aux *userdata); |
| 523 | void RGBAZCorrectTriangle(INT32 offx, INT32 offy, INT32* r, INT32* g, INT32* b, INT32* a, INT32* z, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 524 | |
| 552 | 525 | void Triangle(bool shade, bool texture, bool zbuffer); |
| 553 | 526 | UINT32 AddRightCvg(UINT32 x, UINT32 k); |
| 554 | 527 | UINT32 AddLeftCvg(UINT32 x, UINT32 k); |
| 555 | 528 | |
| 556 | | UINT32* GetCommandData() { return m_cmd_data; } |
| 557 | | UINT32* GetTempRectData() { return m_temp_rect_data; } |
| 529 | void GetDitherValues(int x, int y, int* cdith, int* adith, const rdp_poly_state &object); |
| 558 | 530 | |
| 559 | | void GetDitherValues(int x, int y, int* cdith, int* adith); |
| 560 | | |
| 561 | | |
| 562 | | int m_span_dr; |
| 563 | | int m_span_drdy; |
| 564 | | int m_span_dg; |
| 565 | | int m_span_dgdy; |
| 566 | | int m_span_db; |
| 567 | | int m_span_dbdy; |
| 568 | | int m_span_da; |
| 569 | | int m_span_dady; |
| 570 | | int m_span_ds; |
| 571 | | int m_span_dt; |
| 572 | | int m_span_dw; |
| 573 | | int m_span_dz; |
| 574 | | int m_span_dzdy; |
| 575 | | int m_span_dymax; |
| 576 | | int m_span_dzpix; |
| 577 | | |
| 578 | 531 | UINT32* GetSpecial9BitClampTable() { return m_special_9bit_clamptable; } |
| 579 | 532 | |
| 580 | 533 | UINT16 decompress_cvmask_frombyte(UINT8 x); |
| 581 | | void lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy); |
| 534 | void lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy, rdp_span_aux *userdata); |
| 582 | 535 | |
| 583 | 536 | MiscStateT MiscState; |
| 584 | 537 | |
| 585 | 538 | // Color constants |
| 586 | | Color MemoryColor; |
| 587 | | Color PixelColor; |
| 588 | | Color InvPixelColor; |
| 589 | | Color BlendedPixelColor; |
| 590 | | Color BlendColor; |
| 539 | Color BlendColor; /* constant blend color */ |
| 540 | Color PrimColor; /* flat primitive color */ |
| 541 | Color EnvColor; /* generic color constant ('environment') */ |
| 542 | Color FogColor; /* generic color constant ('fog') */ |
| 543 | Color KeyScale; /* color-keying constant */ |
| 544 | UINT8 LODFraction; /* Z-based LOD fraction for this poly */ |
| 545 | UINT8 PrimLODFraction; /* fixed LOD fraction for this poly */ |
| 591 | 546 | |
| 592 | | Color PrimColor; |
| 593 | | Color EnvColor; |
| 594 | | Color FogColor; |
| 595 | | Color CombinedColor; |
| 596 | | Color Texel0Color; |
| 597 | | Color Texel1Color; |
| 598 | | Color NextTexelColor; |
| 599 | | Color ShadeColor; |
| 600 | | Color KeyScale; |
| 601 | | Color NoiseColor; |
| 602 | | |
| 603 | 547 | Color OneColor; |
| 604 | 548 | Color ZeroColor; |
| 605 | 549 | |
| 606 | | UINT8 LODFraction; |
| 607 | | UINT8 PrimLODFraction; |
| 608 | | |
| 609 | 550 | UINT32 FillColor; |
| 610 | 551 | |
| 611 | 552 | OtherModesT OtherModes; |
| 612 | | ColorInputsT ColorInputs; |
| 613 | 553 | |
| 614 | | BlenderT Blender; |
| 554 | N64BlenderT Blender; |
| 615 | 555 | |
| 616 | | Span Spans[4096]; |
| 556 | N64TexturePipeT TexPipe; |
| 617 | 557 | |
| 618 | | FramebufferT Framebuffer; |
| 619 | | TexturePipeT TexPipe; |
| 620 | | |
| 621 | 558 | UINT8 HiddenBits[0x800000]; |
| 622 | 559 | |
| 623 | 560 | UINT8 ReplicatedRGBA[32]; |
| 624 | 561 | |
| 562 | Rectangle Scissor; |
| 563 | SpanBaseT SpanBase; |
| 564 | |
| 565 | rectangle visarea; |
| 566 | |
| 567 | void DrawTriangle(bool shade, bool texture, bool zbuffer, bool rect); |
| 568 | void compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base); |
| 569 | void compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base); |
| 570 | |
| 571 | void* AuxBuf[2]; |
| 572 | UINT32 AuxBufPtr[2]; |
| 573 | UINT32 AuxBufIndex; |
| 574 | |
| 575 | void* ExtentBuf[2]; |
| 576 | UINT32 ExtentBufPtr[2]; |
| 577 | UINT32 ExtentBufIndex; |
| 578 | |
| 625 | 579 | protected: |
| 626 | | CombineModes m_combine; |
| 580 | CombineModesT m_combine; |
| 581 | bool m_pending_mode_block; |
| 582 | bool m_pipe_clean; |
| 627 | 583 | |
| 628 | 584 | typedef struct |
| 629 | 585 | { |
| r14423 | r14424 | |
| 651 | 607 | |
| 652 | 608 | UINT8* m_tmem; |
| 653 | 609 | |
| 654 | | Tile m_tiles[8]; |
| 610 | N64Tile m_tiles[8]; |
| 655 | 611 | |
| 656 | 612 | running_machine* m_machine; |
| 657 | 613 | |
| r14423 | r14424 | |
| 663 | 619 | INT32 m_k4; |
| 664 | 620 | INT32 m_k5; |
| 665 | 621 | |
| 666 | | // Render-related (move into eventual drawing-related classes?) |
| 667 | | Rectangle m_scissor; |
| 668 | | |
| 669 | 622 | // Texture perspective division |
| 670 | 623 | INT32 m_norm_point_rom[64]; |
| 671 | 624 | INT32 m_norm_slope_rom[64]; |
| r14423 | r14424 | |
| 678 | 631 | |
| 679 | 632 | UINT32 m_special_9bit_clamptable[512]; |
| 680 | 633 | |
| 681 | | INT32 m_dzpix_enc; |
| 682 | | INT32 m_dz_enc; |
| 634 | Writer _Write[16]; |
| 635 | Reader _Read[4]; |
| 636 | Copier _Copy[2]; |
| 637 | Filler _Fill[2]; |
| 683 | 638 | |
| 639 | void _Write16Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 640 | void _Write16Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 641 | void _Write16Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 642 | void _Write16Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 643 | void _Write16Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 644 | void _Write32Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 645 | void _Write32Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 646 | void _Write32Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 647 | void _Write32Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 648 | void _Write32Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 649 | void _Read16Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 650 | void _Read16Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 651 | void _Read32Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 652 | void _Read32Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object); |
| 653 | void _Copy16Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object); |
| 654 | void _Copy32Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object); |
| 655 | void _Fill16Bit(UINT32 curpixel, const rdp_poly_state &object); |
| 656 | void _Fill32Bit(UINT32 curpixel, const rdp_poly_state &object); |
| 657 | |
| 684 | 658 | class ZDecompressEntry |
| 685 | 659 | { |
| 686 | 660 | public: |
| r14423 | r14424 | |
| 701 | 675 | static const Command m_commands[0x40]; |
| 702 | 676 | }; |
| 703 | 677 | |
| 704 | | } // namespace RDP |
| 705 | | |
| 706 | | } // namespace N64 |
| 707 | | |
| 708 | 678 | #endif // _VIDEO_N64_H_ |