Previous 199869 Revisions Next

r25471 Tuesday 1st October, 2013 at 07:20:01 UTC by Ryan Holtz
-N64 optimizations: [MooglyGuy]
 * Converted PIF RAM from 8-bit array to 32-bit array
 * Inlined color and alpha combiner equations
 * Moved a number of calculations in span rendering to outer loops
 * Flattened branch structure of texel fetching somewhat
[src/mame/includes]n64.h
[src/mame/machine]n64.c
[src/mame/video]n64.c n64.h rdpspn16.c rdptpipe.c rdptpipe.h

trunk/src/mame/machine/n64.c
r25470r25471
4545   switch(cic_type)
4646   {
4747      case 1:
48         pif_ram[0x24] = 0x00;
49         pif_ram[0x25] = 0x06;
50         pif_ram[0x26] = 0x3f;
51         pif_ram[0x27] = 0x3f;
48         pif_ram[0x09] = 0x00063f3f;
5249         break;
5350      case 3:
54         pif_ram[0x24] = 0x00;
55         pif_ram[0x25] = 0x02;
56         pif_ram[0x26] = 0x78;
57         pif_ram[0x27] = 0x3f;
51         pif_ram[0x09] = 0x0002783f;
5852         break;
5953      case 5:
60         pif_ram[0x24] = 0x00;
61         pif_ram[0x25] = 0x02;
62         pif_ram[0x26] = 0x91;
63         pif_ram[0x27] = 0x3f;
54         pif_ram[0x09] = 0x0002913f;
6455         break;
6556      case 6:
66         pif_ram[0x24] = 0x00;
67         pif_ram[0x25] = 0x02;
68         pif_ram[0x26] = 0x85;
69         pif_ram[0x27] = 0x3f;
57         pif_ram[0x09] = 0x0002853f;
7058         break;
7159      case 0xd:
72         pif_ram[0x24] = 0x00;
73         pif_ram[0x25] = 0x0a;
74         pif_ram[0x26] = 0xdd;
75         pif_ram[0x27] = 0x3f;
60         pif_ram[0x09] = 0x000add3f;
7661         break;
7762      default:
78         pif_ram[0x24] = 0x00;
79         pif_ram[0x25] = 0x02;
80         pif_ram[0x26] = 0x3f;
81         pif_ram[0x27] = 0x3f;
63         pif_ram[0x09] = 0x00023f3f;
8264         break;
8365   }
8466}
r25470r25471
213195   }
214196
215197   // CIC-NUS-6102 (default)
216   pif_ram[0x24] = 0x00;
217   pif_ram[0x25] = 0x00;
218   pif_ram[0x26] = 0x3f;
219   pif_ram[0x27] = 0x3f;
198   pif_ram[0x09] = 0x00003f3f;
220199   dd_present = false;
221200   cic_type=2;
222201   mem_map->write_dword(0x00000318, 0x800000);
223202
224203   if (boot_checksum == U64(0x00000000001ff230))
225204   {
226      //printf("64DD detected\n");
227      pif_ram[0x24] = 0x00;
228      pif_ram[0x25] = 0x08;
229      pif_ram[0x26] = 0xdd; // How utterly predictable
230      pif_ram[0x27] = 0x3f;
205      pif_ram[0x09] = 0x3fdd0800;
231206      dd_present = true;
232207      cic_type=0xd;
233208   }
234209   else if (boot_checksum == U64(0x000000cffb830843) || boot_checksum == U64(0x000000d0027fdf31))
235210   {
236211      // CIC-NUS-6101
237      //printf("CIC-NUS-6101 detected\n");
238      pif_ram[0x24] = 0x00;
239      pif_ram[0x25] = 0x04;
240      pif_ram[0x26] = 0x3f;
241      pif_ram[0x27] = 0x3f;
212      pif_ram[0x09] = 0x00043f3f;
242213      cic_type=1;
243214   }
244215   else if (boot_checksum == U64(0x000000d6499e376b))
245216   {
246217      // CIC-NUS-6103
247      //printf("CIC-NUS-6103 detected\n");
248      pif_ram[0x24] = 0x00;
249      pif_ram[0x25] = 0x00;
250      pif_ram[0x26] = 0x78;
251      pif_ram[0x27] = 0x3f;
218      pif_ram[0x09] = 0x0000783f;
252219      cic_type=3;
253220   }
254221   else if (boot_checksum == U64(0x0000011a4a1604b6))
255222   {
256223      // CIC-NUS-6105
257      //printf("CIC-NUS-6105 detected\n");
258      pif_ram[0x24] = 0x00;
259      pif_ram[0x25] = 0x00;
260      pif_ram[0x26] = 0x91;
261      pif_ram[0x27] = 0x3f;
224      pif_ram[0x09] = 0x0000913f;
262225      cic_type=5;
263226      mem_map->write_dword(0x000003f0, 0x800000);
264227   }
265228   else if (boot_checksum == U64(0x000000d6d5de4ba0))
266229   {
267230      // CIC-NUS-6106
268      //printf("CIC-NUS-6106 detected\n");
269      pif_ram[0x24] = 0x00;
270      pif_ram[0x25] = 0x00;
271      pif_ram[0x26] = 0x85;
272      pif_ram[0x27] = 0x3f;
231      pif_ram[0x09] = 0x0000853f;
273232      cic_type=6;
274233   }
275234   else
r25470r25471
20021961
20031962void n64_periphs::handle_pif()
20041963{
2005   /*printf("Before:\n"); fflush(stdout);
2006   for(int i = 0; i < 0x40; i++)
2007   {
2008       printf("%02x ", pif_cmd[i]);
2009       if((i & 0xf) == 0xf)
2010       {
2011           printf("\n"); fflush(stdout);
2012       }
2013   }*/
1964   UINT8 *ram = (UINT8*)pif_ram;
20141965   if(pif_cmd[0x3f] == 0x1)        // only handle the command if the last byte is 1
20151966   {
20161967      int channel = 0;
r25470r25471
20642015                  }
20652016                  for(int j = 0; j < bytes_to_recv; j++)
20662017                  {
2067                     pif_ram[cmd_ptr++] = recv_buffer[j];
2018                     ram[cmd_ptr ^ BYTE4_XOR_BE(0)] = recv_buffer[j];
2019                     cmd_ptr++;
20682020                  }
20692021               }
20702022               else if (res == 1)
20712023               {
20722024                  int offset = 0;//bytes_to_send;
2073                  pif_ram[cmd_ptr-offset-2] |= 0x80;
2025                  ram[(cmd_ptr - offset - 2) ^ BYTE4_XOR_BE(0)] |= 0x80;
20742026               }
20752027            }
20762028
r25470r25471
20782030         }
20792031      }
20802032
2081      pif_ram[0x3f] = 0;
2033      ram[0x3f ^ BYTE4_XOR_BE(0)] = 0;
20822034   }
20832035
20842036   /*printf("After:\n"); fflush(stdout);
r25470r25471
20942046
20952047void n64_periphs::pif_dma(int direction)
20962048{
2097   UINT32 *src, *dst;
2049   UINT8 *ram = (UINT8*)pif_ram;
20982050
20992051   if (si_dram_addr & 0x3)
21002052   {
r25470r25471
21032055
21042056   if (direction)      // RDRAM -> PIF RAM
21052057   {
2106      src = (UINT32*)&rdram[(si_dram_addr & 0x1fffffff) / 4];
2058      UINT32 *src = (UINT32*)&rdram[(si_dram_addr & 0x1fffffff) / 4];
21072059
21082060      for(int i = 0; i < 64; i+=4)
21092061      {
2110         UINT32 d = *src++;
2111         pif_ram[i+0] = (d >> 24) & 0xff;
2112         pif_ram[i+1] = (d >> 16) & 0xff;
2113         pif_ram[i+2] = (d >>  8) & 0xff;
2114         pif_ram[i+3] = (d >>  0) & 0xff;
2062         ram[i >> 2] = *src;
2063         src++;
21152064      }
21162065
21172066      memcpy(pif_cmd, pif_ram, 0x40);
r25470r25471
21202069   {
21212070      handle_pif();
21222071
2123      dst = (UINT32*)&rdram[(si_dram_addr & 0x1fffffff) / 4];
2072      UINT32 *dst = (UINT32*)&rdram[(si_dram_addr & 0x1fffffff) / 4];
21242073
21252074      for(int i = 0; i < 64; i+=4)
21262075      {
2127         UINT32 d = 0;
2128         d |= pif_ram[i+0] << 24;
2129         d |= pif_ram[i+1] << 16;
2130         d |= pif_ram[i+2] <<  8;
2131         d |= pif_ram[i+3] <<  0;
2132
2133         *dst++ = d;
2076         *dst = ram[i >> 2];
2077         dst++;
21342078      }
21352079   }
21362080
r25470r25471
24032347         return cic_status;
24042348      }
24052349   }
2406   return ( ( pif_ram[offset*4+0] << 24 ) | ( pif_ram[offset*4+1] << 16 ) | ( pif_ram[offset*4+2] <<  8 ) | ( pif_ram[offset*4+3] <<  0 ) ) & mem_mask;
2350   return pif_ram[offset] & mem_mask;
24072351}
24082352
24092353WRITE32_MEMBER( n64_periphs::pif_ram_w )
24102354{
2411   if( mem_mask & 0xff000000 )
2412   {
2413      pif_ram[offset*4+0] = ( data >> 24 ) & 0x000000ff;
2414   }
2415   if( mem_mask & 0x00ff0000 )
2416   {
2417      pif_ram[offset*4+1] = ( data >> 16 ) & 0x000000ff;
2418   }
2419   if( mem_mask & 0x0000ff00 )
2420   {
2421      pif_ram[offset*4+2] = ( data >>  8 ) & 0x000000ff;
2422   }
2423   if( mem_mask & 0x000000ff )
2424   {
2425      pif_ram[offset*4+3] = ( data >>  0 ) & 0x000000ff;
2426   }
2427
2355   COMBINE_DATA(&pif_ram[offset]);
24282356   signal_rcp_interrupt(SI_INTERRUPT);
24292357}
24302358
trunk/src/mame/includes/n64.h
r25470r25471
221221   void handle_pif();
222222   int pif_channel_handle_command(int channel, int slength, UINT8 *sdata, int rlength, UINT8 *rdata);
223223   UINT8 calc_mempak_crc(UINT8 *buffer, int length);
224   UINT8 pif_ram[0x40];
224   UINT32 pif_ram[0x10];
225225   UINT8 pif_cmd[0x40];
226226   UINT32 si_dram_addr;
227227   UINT32 si_pif_addr;
trunk/src/mame/video/rdpspn16.c
r25470r25471
1515#include "includes/n64.h"
1616#include "video/n64.h"
1717
18#define LookUpCC(A, B, C, D) m_rdp->GetCCLUT2()[(m_rdp->GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
18#define LookUpCC(A, B, C, D) GetCCLUT2()[(GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
1919
2020void n64_rdp::RenderSpans(int start, int end, int tilenum, bool flip, extent_t *Spans, bool rect, rdp_poly_state *object)
2121{
r25470r25471
8181
8282void n64_rdp::RGBAZClip(int sr, int sg, int sb, int sa, int *sz, rdp_span_aux *userdata)
8383{
84   userdata->ShadeColor.i.r = m_special_9bit_clamptable[sr & 0x1ff];
85   userdata->ShadeColor.i.g = m_special_9bit_clamptable[sg & 0x1ff];
86   userdata->ShadeColor.i.b = m_special_9bit_clamptable[sb & 0x1ff];
87   userdata->ShadeColor.i.a = m_special_9bit_clamptable[sa & 0x1ff];
84   userdata->ShadeColor.i.r = s_special_9bit_clamptable[sr & 0x1ff];
85   userdata->ShadeColor.i.g = s_special_9bit_clamptable[sg & 0x1ff];
86   userdata->ShadeColor.i.b = s_special_9bit_clamptable[sb & 0x1ff];
87   userdata->ShadeColor.i.a = s_special_9bit_clamptable[sa & 0x1ff];
8888
8989   INT32 zanded = (*sz) & 0x60000;
9090
r25470r25471
134134{
135135   int clipx1 = object.Scissor.m_xh;
136136   int clipx2 = object.Scissor.m_xl;
137   n64_rdp *m_rdp = object.m_rdp;
138137   int tilenum = object.tilenum;
139138   bool flip = object.flip;
140139
r25470r25471
157156
158157   INT32 m_clamp_s_diff[8];
159158   INT32 m_clamp_t_diff[8];
160   m_rdp->TexPipe.CalculateClampDiffs(tile1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
159   TexPipe.CalculateClampDiffs(tile1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
161160
162161   bool partialreject = (userdata->ColorInputs.blender2b_a[0] == &userdata->InvPixelColor.i.a && userdata->ColorInputs.blender1b_a[0] == &userdata->PixelColor.i.a);
163162   int sel0 = (OtherModes.force_blend ? 2 : 0) | ((userdata->ColorInputs.blender2b_a[0] == &userdata->MemoryColor.i.a) ? 1 : 0);
r25470r25471
209208   int blend_index = (object.OtherModes.alpha_cvg_select ? 2 : 0) | ((object.OtherModes.rgb_dither_sel < 3) ? 1 : 0);
210209   int read_index = ((object.MiscState.FBSize - 2) << 1) | object.OtherModes.image_read_en;
211210   int write_index = ((object.MiscState.FBSize - 2) << 3) | (object.OtherModes.cvg_dest << 1);
211   int cycle0 = ((object.OtherModes.sample_type & 1) << 1) | (object.OtherModes.bi_lerp0 & 1);
212212   int acmode = (object.OtherModes.alpha_compare_en ? 2 : 0) | (object.OtherModes.dither_alpha_en ? 1 : 0);
213213
214   INT32 sss = 0;
215   INT32 sst = 0;
216
217   if (object.OtherModes.persp_tex_en)
218   {
219      TCDiv(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst);
220   }
221   else
222   {
223      TCDivNoPersp(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst);
224   }
225
214226   userdata->m_start_span = true;
215227   for (int j = 0; j <= length; j++)
216228   {
r25470r25471
218230      int sg = g.w >> 14;
219231      int sb = b.w >> 14;
220232      int sa = a.w >> 14;
221      int ss = s.w >> 16;
222      int st = t.w >> 16;
223      int sw = w.w >> 16;
224233      int sz = (z.w >> 10) & 0x3fffff;
225      INT32 sss = 0;
226      INT32 sst = 0;
227
228234      bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored);
229235
230236      if (x >= clipx1 && x < clipx2 && valid_x)
231237      {
232         m_rdp->lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata);
238         lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata);
233239
234         if (userdata->m_start_span)
235         {
236            if (object.OtherModes.persp_tex_en)
237            {
238               m_rdp->TCDiv(ss, st, sw, &sss, &sst);
239            }
240            else
241            {
242               m_rdp->TCDivNoPersp(ss, st, sw, &sss, &sst);
243            }
244         }
245         else
246         {
247            sss = userdata->m_precomp_s;
248            sst = userdata->m_precomp_t;
249         }
240         TexPipe.LOD1Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, userdata, object);
250241
251         m_rdp->TexPipe.LOD1Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, userdata, object);
252
253242         RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object);
254243         RGBAZClip(sr, sg, sb, sa, &sz, userdata);
255244
256         m_rdp->TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tilenum, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
245         ((TexPipe).*(TexPipe.cycle[cycle0]))(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tilenum, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
246         //TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tilenum, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
257247
258         m_rdp->ColorCombiner1Cycle(userdata);
248         userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = rand() << 3; // Not accurate
259249
250         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]);
251         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]);
252         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]);
253         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]);
254
260255         //Alpha coverage combiner
261256         GetAlphaCvg(&userdata->PixelColor.i.a, userdata, object);
262257
r25470r25471
266261
267262         ((this)->*(_Read[read_index]))(curpixel, userdata, object);
268263
269         if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object))
264         if(ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object))
270265         {
271            m_rdp->GetDitherValues(scanline, j, &cdith, &adith, object);
266            GetDitherValues(scanline, j, &cdith, &adith, object);
272267
273            bool rendered = ((&m_rdp->Blender)->*(m_rdp->Blender.blend1[(userdata->BlendEnable << 2) | blend_index]))(&fir, &fig, &fib, cdith, adith, partialreject, sel0, acmode, userdata, object);
268            bool rendered = ((&Blender)->*(Blender.blend1[(userdata->BlendEnable << 2) | blend_index]))(&fir, &fig, &fib, cdith, adith, partialreject, sel0, acmode, userdata, object);
274269
275270            if (rendered)
276271            {
r25470r25471
278273
279274               if (object.OtherModes.z_update_en)
280275               {
281                  m_rdp->ZStore(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc);
276                  ZStore(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc);
282277               }
283278            }
284279         }
280
281         sss = userdata->m_precomp_s;
282         sst = userdata->m_precomp_t;
285283      }
286284
287285      r.w += drinc;
r25470r25471
301299{
302300   int clipx1 = object.Scissor.m_xh;
303301   int clipx2 = object.Scissor.m_xl;
304   n64_rdp *m_rdp = object.m_rdp;
305302   int tilenum = object.tilenum;
306303   bool flip = object.flip;
307304
r25470r25471
316313
317314   UINT32 zb = object.MiscState.ZBAddress >> 1;
318315   UINT32 zhb = object.MiscState.ZBAddress;
319   UINT8 offx = 0, offy = 0;
320316
321317   INT32 tile2 = (tilenum + 1) & 7;
322318   INT32 tile1 = tilenum;
r25470r25471
330326
331327   INT32 m_clamp_s_diff[8];
332328   INT32 m_clamp_t_diff[8];
333   m_rdp->TexPipe.CalculateClampDiffs(tile1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
329   TexPipe.CalculateClampDiffs(tile1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
334330
335331   bool partialreject = (userdata->ColorInputs.blender2b_a[1] == &userdata->InvPixelColor.i.a && userdata->ColorInputs.blender1b_a[1] == &userdata->PixelColor.i.a);
336332   int sel0 = (OtherModes.force_blend ? 2 : 0) | ((userdata->ColorInputs.blender2b_a[0] == &userdata->MemoryColor.i.a) ? 1 : 0);
r25470r25471
371367   int blend_index = (object.OtherModes.alpha_cvg_select ? 2 : 0) | ((object.OtherModes.rgb_dither_sel < 3) ? 1 : 0);
372368   int read_index = ((object.MiscState.FBSize - 2) << 1) | object.OtherModes.image_read_en;
373369   int write_index = ((object.MiscState.FBSize - 2) << 3) | (object.OtherModes.cvg_dest << 1);
370   int cycle0 = ((object.OtherModes.sample_type & 1) << 1) | (object.OtherModes.bi_lerp0 & 1);
371   int cycle1 = ((object.OtherModes.sample_type & 1) << 1) | (object.OtherModes.bi_lerp1 & 1);
374372   int acmode = (object.OtherModes.alpha_compare_en ? 2 : 0) | (object.OtherModes.dither_alpha_en ? 1 : 0);
375373
374   INT32 sss = 0;
375   INT32 sst = 0;
376
377   if (object.OtherModes.persp_tex_en)
378   {
379      TCDiv(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst);
380   }
381   else
382   {
383      TCDivNoPersp(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst);
384   }
385
376386   userdata->m_start_span = true;
377387   for (int j = 0; j <= length; j++)
378388   {
r25470r25471
380390      int sg = g.w >> 14;
381391      int sb = b.w >> 14;
382392      int sa = a.w >> 14;
383      int ss = s.h.h;
384      int st = t.h.h;
385      int sw = w.h.h;
386393      int sz = (z.w >> 10) & 0x3fffff;
387      INT32 sss = 0;
388      INT32 sst = 0;
389394      Color c1;
390395      Color c2;
391396
r25470r25471
393398
394399      if (x >= clipx1 && x < clipx2 && valid_x)
395400      {
396         m_rdp->lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata);
401         UINT32 compidx = compressed_cvmasks[userdata->m_cvg[x]];
402         userdata->CurrentPixCvg = cvarray[compidx].cvg;
403         userdata->CurrentCvgBit = cvarray[compidx].cvbit;
404         UINT8 offx = cvarray[compidx].xoff;
405         UINT8 offy = cvarray[compidx].yoff;
406         //lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata);
397407
398         if (userdata->m_start_span)
399         {
400            if (object.OtherModes.persp_tex_en)
401            {
402               m_rdp->TCDiv(ss, st, sw, &sss, &sst);
403            }
404            else
405            {
406               m_rdp->TCDivNoPersp(ss, st, sw, &sss, &sst);
407            }
408         }
409         else
410         {
411            sss = userdata->m_precomp_s;
412            sst = userdata->m_precomp_t;
413         }
408         TexPipe.LOD2Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, prim_tile, &tile1, &tile2, userdata, object);
414409
415         m_rdp->TexPipe.LOD2Cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, prim_tile, &tile1, &tile2, userdata, object);
416
417410         news = userdata->m_precomp_s;
418411         newt = userdata->m_precomp_t;
419         m_rdp->TexPipe.LOD2CycleLimited(&news, &newt, s.w + dsinc, t.w + dtinc, w.w + dwinc, dsinc, dtinc, dwinc, prim_tile, &newtile1, object);
412         TexPipe.LOD2CycleLimited(&news, &newt, s.w + dsinc, t.w + dtinc, w.w + dwinc, dsinc, dtinc, dwinc, prim_tile, &newtile1, object);
420413
421414         RGBAZCorrectTriangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object);
422415         RGBAZClip(sr, sg, sb, sa, &sz, userdata);
423416
424         m_rdp->TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tile1, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
425         m_rdp->TexPipe.Cycle(&userdata->Texel1Color, &userdata->Texel0Color, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
417         ((TexPipe).*(TexPipe.cycle[cycle0]))(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tile1, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
418         ((TexPipe).*(TexPipe.cycle[cycle1]))(&userdata->Texel1Color, &userdata->Texel0Color, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
419         ((TexPipe).*(TexPipe.cycle[cycle1]))(&userdata->NextTexelColor, &userdata->NextTexelColor, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
420         //TexPipe.Cycle(&userdata->Texel0Color, &userdata->Texel0Color, sss, sst, tile1, 0, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
421         //TexPipe.Cycle(&userdata->Texel1Color, &userdata->Texel0Color, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
422         //TexPipe.Cycle(&userdata->NextTexelColor, &userdata->NextTexelColor, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
426423
427         m_rdp->TexPipe.Cycle(&userdata->NextTexelColor, &userdata->NextTexelColor, sss, sst, tile2, 1, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
424         userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = rand() << 3; // Not accurate
425         userdata->CombinedColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[0],
426                                                *userdata->ColorInputs.combiner_rgbsub_b_r[0],
427                                                *userdata->ColorInputs.combiner_rgbmul_r[0],
428                                                *userdata->ColorInputs.combiner_rgbadd_r[0]);
429         userdata->CombinedColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[0],
430                                                *userdata->ColorInputs.combiner_rgbsub_b_g[0],
431                                                *userdata->ColorInputs.combiner_rgbmul_g[0],
432                                                *userdata->ColorInputs.combiner_rgbadd_g[0]);
433         userdata->CombinedColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[0],
434                                                *userdata->ColorInputs.combiner_rgbsub_b_b[0],
435                                                *userdata->ColorInputs.combiner_rgbmul_b[0],
436                                                *userdata->ColorInputs.combiner_rgbadd_b[0]);
437         userdata->CombinedColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[0],
438                                                *userdata->ColorInputs.combiner_alphasub_b[0],
439                                                *userdata->ColorInputs.combiner_alphamul[0],
440                                                *userdata->ColorInputs.combiner_alphaadd[0]);
428441
429         m_rdp->ColorCombiner2Cycle(userdata);
442         userdata->Texel0Color = userdata->Texel1Color;
443         userdata->Texel1Color = userdata->NextTexelColor;
430444
445         userdata->PixelColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[1],
446                                                *userdata->ColorInputs.combiner_rgbsub_b_r[1],
447                                                *userdata->ColorInputs.combiner_rgbmul_r[1],
448                                                *userdata->ColorInputs.combiner_rgbadd_r[1]);
449         userdata->PixelColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[1],
450                                                *userdata->ColorInputs.combiner_rgbsub_b_g[1],
451                                                *userdata->ColorInputs.combiner_rgbmul_g[1],
452                                                *userdata->ColorInputs.combiner_rgbadd_g[1]);
453         userdata->PixelColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[1],
454                                                *userdata->ColorInputs.combiner_rgbsub_b_b[1],
455                                                *userdata->ColorInputs.combiner_rgbmul_b[1],
456                                                *userdata->ColorInputs.combiner_rgbadd_b[1]);
457         userdata->PixelColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[1],
458                                                *userdata->ColorInputs.combiner_alphasub_b[1],
459                                                *userdata->ColorInputs.combiner_alphamul[1],
460                                                *userdata->ColorInputs.combiner_alphaadd[1]);
461
431462         //Alpha coverage combiner
432463         GetAlphaCvg(&userdata->PixelColor.i.a, userdata, object);
433464
r25470r25471
437468
438469         ((this)->*(_Read[read_index]))(curpixel, userdata, object);
439470
440         if(m_rdp->ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object))
471         if(ZCompare(zbcur, zhbcur, sz, dzpix, userdata, object))
441472         {
442            m_rdp->GetDitherValues(scanline, j, &cdith, &adith, object);
473            GetDitherValues(scanline, j, &cdith, &adith, object);
443474
444            bool rendered = ((&m_rdp->Blender)->*(m_rdp->Blender.blend2[(userdata->BlendEnable << 2) | blend_index]))(&fir, &fig, &fib, cdith, adith, partialreject, sel0, sel1, acmode, userdata, object);
475            bool rendered = ((&Blender)->*(Blender.blend2[(userdata->BlendEnable << 2) | blend_index]))(&fir, &fig, &fib, cdith, adith, partialreject, sel0, sel1, acmode, userdata, object);
445476
446477            if (rendered)
447478            {
448479               ((this)->*(_Write[write_index | userdata->BlendEnable]))(curpixel, fir, fig, fib, userdata, object);
449480               if (object.OtherModes.z_update_en)
450481               {
451                  m_rdp->ZStore(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc);
482                  ZStore(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc);
452483               }
453484            }
454485         }
486         sss = userdata->m_precomp_s;
487         sst = userdata->m_precomp_t;
455488      }
456489
457490      r.w += drinc;
r25470r25471
471504{
472505   int clipx1 = object.Scissor.m_xh;
473506   int clipx2 = object.Scissor.m_xl;
474   n64_rdp *m_rdp = object.m_rdp;
475507   int tilenum = object.tilenum;
476508   bool flip = object.flip;
477509
r25470r25471
503535      {
504536         INT32 sss = s.h.h;
505537         INT32 sst = t.h.h;
506         m_rdp->TexPipe.Copy(&userdata->Texel0Color, sss, sst, tilenum, object, userdata);
538         TexPipe.Copy(&userdata->Texel0Color, sss, sst, tilenum, object, userdata);
507539
508540         UINT32 curpixel = fb_index + x;
509541         if ((userdata->Texel0Color.i.a != 0) || (!object.OtherModes.alpha_compare_en))
trunk/src/mame/video/rdptpipe.c
r25470r25471
3636
3737void N64TexturePipeT::Mask(INT32* S, INT32* T, INT32 num, const rdp_poly_state& object)
3838{
39   const N64Tile* tile = object.m_tiles;
39   const N64Tile* tiles = object.m_tiles;
4040
41   if (tile[num].mask_s)
41   if (tiles[num].mask_s)
4242   {
43      INT32 wrap = *S >> (tile[num].mask_s > 10 ? 10 : tile[num].mask_s);
43      INT32 wrap = *S >> (tiles[num].mask_s > 10 ? 10 : tiles[num].mask_s);
4444      wrap &= 1;
45      if (tile[num].ms && wrap)
45      if (tiles[num].ms && wrap)
4646      {
4747         *S = (~(*S));
4848      }
49      *S &= m_maskbits_table[tile[num].mask_s];
49      *S &= m_maskbits_table[tiles[num].mask_s];
5050   }
5151
52   if (tile[num].mask_t)
52   if (tiles[num].mask_t)
5353   {
54      INT32 wrap = *T >> (tile[num].mask_t > 10 ? 10 : tile[num].mask_t);
54      INT32 wrap = *T >> (tiles[num].mask_t > 10 ? 10 : tiles[num].mask_t);
5555      wrap &= 1;
56      if (tile[num].mt && wrap)
56      if (tiles[num].mt && wrap)
5757      {
5858         *T = (~(*T));
5959      }
60      *T &= m_maskbits_table[tile[num].mask_t];
60      *T &= m_maskbits_table[tiles[num].mask_t];
6161   }
6262}
6363
64#define MASK_COUPLED(param, param1, num, coord) \
65   if (tiles[num].mask_##coord)               \
66   {                                 \
67      INT32 maskbits_##coord = m_maskbits_table[tiles[num].mask_##coord];   \
68      if (tiles[num].m##coord)               \
69      {                              \
70         INT32 wrapthreshold = tiles[num].mask_##coord > 10 ? 10 : tiles[num].mask_##coord;   \
71         if ((param >> wrapthreshold) & 1)   \
72         {                           \
73            param = ~param;               \
74         }                           \
75         if ((param1 >> wrapthreshold) & 1)   \
76         {                           \
77            param1 = ~param1;            \
78         }                           \
79      }                              \
80      param &= maskbits_##coord;            \
81      param1 &= maskbits_##coord;            \
82   }
83
6484void N64TexturePipeT::MaskCoupled(INT32* S, INT32* S1, INT32* T, INT32* T1, INT32 num, const rdp_poly_state& object)
6585{
66   const N64Tile* tile = object.m_tiles;
86   const N64Tile* tiles = object.m_tiles;
6787
68   if (tile[num].mask_s)
88   if (tiles[num].mask_s)
6989   {
70      INT32 maskbits_s = m_maskbits_table[tile[num].mask_s];
71      if (tile[num].ms)
90      INT32 maskbits_s = m_maskbits_table[tiles[num].mask_s];
91      if (tiles[num].ms)
7292      {
73         INT32 swrapthreshold = tile[num].mask_s > 10 ? 10 : tile[num].mask_s;
93         INT32 swrapthreshold = tiles[num].mask_s > 10 ? 10 : tiles[num].mask_s;
7494         INT32 wrap = (*S >> swrapthreshold) & 1;
7595         INT32 wrap1 = (*S1 >> swrapthreshold) & 1;
7696         if (wrap)
r25470r25471
86106      *S1 &= maskbits_s;
87107   }
88108
89   if (tile[num].mask_t)
109   if (tiles[num].mask_t)
90110   {
91      INT32 maskbits_t = m_maskbits_table[tile[num].mask_t];
92      if (tile[num].mt)
111      INT32 maskbits_t = m_maskbits_table[tiles[num].mask_t];
112      if (tiles[num].mt)
93113      {
94         INT32 twrapthreshold = tile[num].mask_t > 10 ? 10 : tile[num].mask_t;
114         INT32 twrapthreshold = tiles[num].mask_t > 10 ? 10 : tiles[num].mask_t;
95115         INT32 wrap = (*T >> twrapthreshold) & 1;
96116         INT32 wrap1 = (*T1 >> twrapthreshold) & 1;
97117         if (wrap)
r25470r25471
108128   }
109129}
110130
131#define SHIFT_CYCLE(param, max, num, coord)         \
132   param = SIGN16(param);                     \
133   if (tiles[num].shift_##coord < 11)            \
134   {                                    \
135      param >>= tiles[num].shift_##coord;         \
136   }                                    \
137   else                                 \
138   {                                    \
139      param <<= (16 - tiles[num].shift_##coord);   \
140   }                                    \
141   param = SIGN16(param);                     \
142   max = ((param >> 3) >= tiles[num].coord##h);
143
111144void N64TexturePipeT::ShiftCycle(INT32* S, INT32* T, INT32* maxs, INT32* maxt, UINT32 num, const rdp_poly_state& object)
112145{
113   const N64Tile* tile = object.m_tiles;
146   const N64Tile* tiles = object.m_tiles;
114147   *S = SIGN16(*S);
115   *T = SIGN16(*T);
116   if (tile[num].shift_s < 11)
148   if (tiles[num].shift_s < 11)
117149   {
118      *S >>= tile[num].shift_s;
150      *S >>= tiles[num].shift_s;
119151   }
120152   else
121153   {
122      *S <<= (16 - tile[num].shift_s);
154      *S <<= (16 - tiles[num].shift_s);
123155   }
124156   *S = SIGN16(*S);
125   if (tile[num].shift_t < 11)
157   *maxs = ((*S >> 3) >= tiles[num].sh);
158
159   *T = SIGN16(*T);
160   if (tiles[num].shift_t < 11)
126161   {
127      *T >>= tile[num].shift_t;
162      *T >>= tiles[num].shift_t;
128163   }
129164   else
130165   {
131      *T <<= (16 - tile[num].shift_t);
166      *T <<= (16 - tiles[num].shift_t);
132167   }
133168   *T = SIGN16(*T);
134
135   *maxs = ((*S >> 3) >= tile[num].sh);
136   *maxt = ((*T >> 3) >= tile[num].th);
169   *maxt = ((*T >> 3) >= tiles[num].th);
137170}
138171
139172void N64TexturePipeT::ShiftCopy(INT32* S, INT32* T, UINT32 num, const rdp_poly_state& object)
140173{
141   const N64Tile* tile = object.m_tiles;
174   const N64Tile* tiles = object.m_tiles;
142175   *S = SIGN16(*S);
143176   *T = SIGN16(*T);
144   if (tile[num].shift_s < 11)//?-? tcu_tile
177   if (tiles[num].shift_s < 11)//?-? tcu_tile
145178   {
146      *S >>= tile[num].shift_s;
179      *S >>= tiles[num].shift_s;
147180   }
148181   else
149182   {
150      *S <<= (16 - tile[num].shift_s);
183      *S <<= (16 - tiles[num].shift_s);
151184   }
152185   *S = SIGN16(*S);
153   if (tile[num].shift_t < 11)
186   if (tiles[num].shift_t < 11)
154187   {
155      *T >>= tile[num].shift_t;
188      *T >>= tiles[num].shift_t;
156189   }
157190   else
158191   {
159      *T <<= (16 - tile[num].shift_t);
192      *T <<= (16 - tiles[num].shift_t);
160193   }
161194   *T = SIGN16(*T);
162195}
163196
197#define CLAMP_CYCLE(param, frac, max, num, coord)      \
198   if (tiles[num].c##coord || !tiles[num].mask_##coord)   \
199   {                                       \
200      if (param & 0x10000)                     \
201      {                                    \
202         param = 0;                           \
203         frac = 0;                           \
204      }                                    \
205      else if (max)                           \
206      {                                    \
207         param = m_clamp_##coord##_diff[num];      \
208         frac = 0;                           \
209      }                                    \
210      else                                 \
211      {                                    \
212         param = (SIGN17(param) >> 5) & 0x1fff;      \
213      }                                    \
214   }                                       \
215   else                                    \
216   {                                       \
217      param = (SIGN17(param) >> 5) & 0x1fff;         \
218   }
219
164220void 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, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
165221{
166   const N64Tile* tile = object.m_tiles;
167   int dos = tile[num].cs || !tile[num].mask_s;
168   int dot = tile[num].ct || !tile[num].mask_t;
222   const N64Tile* tiles = object.m_tiles;
169223
170   if (dos)
224   if (tiles[num].cs || !tiles[num].mask_s)
171225   {
172226      if (*S & 0x10000)
173227      {
r25470r25471
189243      *S = (SIGN17(*S) >> 5) & 0x1fff;
190244   }
191245
192   if (dot)
246   if (tiles[num].ct || !tiles[num].mask_t)
193247   {
194248      if (*T & 0x10000)
195249      {
r25470r25471
214268
215269void N64TexturePipeT::ClampCycleLight(INT32* S, INT32* T, bool maxs, bool maxt, INT32 num, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
216270{
217   const N64Tile* tile = object.m_tiles;
218   int dos = tile[num].cs || !tile[num].mask_s;
219   int dot = tile[num].ct || !tile[num].mask_t;
271   const N64Tile* tiles = object.m_tiles;
272   int dos = tiles[num].cs || !tiles[num].mask_s;
273   int dot = tiles[num].ct || !tiles[num].mask_t;
220274
221275   if (dos)
222276   {
r25470r25471
259313   }
260314}
261315
262void N64TexturePipeT::Cycle(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
316void N64TexturePipeT::CycleNearest(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
263317{
264   const N64Tile* tile = object.m_tiles;
318   const N64Tile* tiles = object.m_tiles;
319   const N64Tile& tile = tiles[tilenum];
320   UINT32 tformat = tile.format;
321   UINT32 tsize =  tile.size;
322   UINT32 tpal = tile.palette;
323   UINT32 index = (tformat << 4) | (tsize << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
265324
266325#define TRELATIVE(x, y)     ((((x) >> 3) - (y)) << 3) | (x & 7);
267   INT32 bilerp = cycle ? object.OtherModes.bi_lerp1 : object.OtherModes.bi_lerp0;
268326   int convert = object.OtherModes.convert_one && cycle;
269327   Color t0;
270   Color t1;
271   Color t2;
272   Color t3;
273   if (object.OtherModes.sample_type)
328
329   INT32 sss1 = SSS;
330   INT32 maxs;
331   SHIFT_CYCLE(sss1, maxs, tilenum, s);
332   sss1 = TRELATIVE(sss1, tile.sl);
333
334   INT32 sst1 = SST;
335   INT32 maxt;
336   SHIFT_CYCLE(sst1, maxt, tilenum, t);
337   sst1 = TRELATIVE(sst1, tile.tl);
338
339   ClampCycleLight(&sss1, &sst1, maxs, maxt, tilenum, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
340   Mask(&sss1, &sst1, tilenum, object);
341
342   UINT32 tbase = tile.tmem + ((tile.line * sst1) & 0x1ff);
343
344   t0.c = ((this)->*(TexelFetch[index]))(sss1, sst1, tbase, tpal, userdata);
345
346   INT32 newk0 = SIGN9(m_rdp->GetK0());
347   INT32 newk1 = SIGN9(m_rdp->GetK1());
348   INT32 newk2 = SIGN9(m_rdp->GetK2());
349   INT32 newk3 = SIGN9(m_rdp->GetK3());
350   INT32 invk0 = ~newk0;
351   INT32 invk1 = ~newk1;
352   INT32 invk2 = ~newk2;
353   INT32 invk3 = ~newk3;
354   if (convert)
274355   {
275      int sss1, sst1, sss2, sst2;
356      t0 = *prev;
357   }
358   t0.i.r = SIGN9(t0.i.r);
359   t0.i.g = SIGN9(t0.i.g);
360   t0.i.b = SIGN9(t0.i.b);
361   TEX->i.r = t0.i.b + (((newk0 - invk0) * t0.i.g + 0x80) >> 8);
362   TEX->i.g = t0.i.b + (((newk1 - invk1) * t0.i.r + (newk2 - invk2) * t0.i.g + 0x80) >> 8);
363   TEX->i.b = t0.i.b + (((newk3 - invk3) * t0.i.r + 0x80) >> 8);
364   TEX->i.a = t0.i.b;
365   TEX->i.r &= 0x1ff;
366   TEX->i.g &= 0x1ff;
367   TEX->i.b &= 0x1ff;
368   TEX->i.a &= 0x1ff;
369}
276370
277      INT32 invsf = 0;
278      INT32 invtf = 0;
279      int center = 0;
371void N64TexturePipeT::CycleNearestLerp(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
372{
373   const N64Tile* tiles = object.m_tiles;
374   const N64Tile& tile = tiles[tilenum];
375   UINT32 tformat = tile.format;
376   UINT32 tsize =  tile.size;
377   UINT32 tpal = tile.palette;
378   UINT32 index = (tformat << 4) | (tsize << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
280379
281      sss1 = SSS;
282      sst1 = SST;
380#define TRELATIVE(x, y)     ((((x) >> 3) - (y)) << 3) | (x & 7);
381   Color t0;
283382
284      INT32 maxs;
285      INT32 maxt;
383   INT32 sss1 = SSS;
384   INT32 maxs;
385   SHIFT_CYCLE(sss1, maxs, tilenum, s);
386   sss1 = TRELATIVE(sss1, tile.sl);
286387
287      ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum, object);
388   INT32 sst1 = SST;
389   INT32 maxt;
390   SHIFT_CYCLE(sst1, maxt, tilenum, t);
391   sst1 = TRELATIVE(sst1, tile.tl);
288392
289      sss1 = TRELATIVE(sss1, tile[tilenum].sl);
290      sst1 = TRELATIVE(sst1, tile[tilenum].tl);
393   ClampCycleLight(&sss1, &sst1, maxs, maxt, tilenum, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
394   Mask(&sss1, &sst1, tilenum, object);
291395
292      INT32 sfrac = sss1 & 0x1f;
293      INT32 tfrac = sst1 & 0x1f;
396   UINT32 tbase = tile.tmem + ((tile.line * sst1) & 0x1ff);
294397
295      ClampCycle(&sss1, &sst1, &sfrac, &tfrac, maxs, maxt, tilenum, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
398   (*TEX).c = ((this)->*(TexelFetch[index]))(sss1, sst1, tbase, tpal, userdata);
399}
296400
297      sss2 = sss1 + 1;
298      sst2 = sst1 + 1;
401void N64TexturePipeT::CycleLinear(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
402{
403   const N64Tile* tiles = object.m_tiles;
404   const N64Tile& tile = tiles[tilenum];
299405
300      MaskCoupled(&sss1, &sss2, &sst1, &sst2, tilenum, object);
406#define TRELATIVE(x, y)     ((((x) >> 3) - (y)) << 3) | (x & 7);
407   int convert = object.OtherModes.convert_one && cycle;
408   UINT32 tpal = tile.palette;
409   UINT32 index = (tile.format << 4) | (tile.size << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
301410
302      bool upper = ((sfrac + tfrac) >= 0x20);
411   INT32 invsf = 0;
412   INT32 sss1 = SSS;
413   INT32 maxs;
414   SHIFT_CYCLE(sss1, maxs, tilenum, s);
415   sss1 = TRELATIVE(sss1, tile.sl);
416   INT32 sfrac = sss1 & 0x1f;
417   CLAMP_CYCLE(sss1, sfrac, maxs, tilenum, s);
418   INT32 sss2 = sss1 + 1;
419   MASK_COUPLED(sss1, sss2, tilenum, s);
303420
304      if (upper)
305      {
306         invsf = 0x20 - sfrac;
307         invtf = 0x20 - tfrac;
308      }
421   INT32 invtf = 0;
422   INT32 sst1 = SST;
423   INT32 maxt;
424   SHIFT_CYCLE(sst1, maxt, tilenum, t);
425   sst1 = TRELATIVE(sst1, tile.tl);
426   INT32 tfrac = sst1 & 0x1f;
427   CLAMP_CYCLE(sst1, tfrac, maxt, tilenum, t);
428   INT32 sst2 = sst1 + 1;
429   MASK_COUPLED(sst1, sst2, tilenum, t);
309430
310      center = (sfrac == 0x10) && (tfrac == 0x10) && object.OtherModes.mid_texel;
431   UINT32 tbase = tile.tmem + ((tile.line * sst1) & 0x1ff);
311432
433   bool upper = ((sfrac + tfrac) >= 0x20);
434
435   if (upper)
436   {
437      invsf = 0x20 - sfrac;
312438      invsf <<= 3;
439
440      invtf = 0x20 - tfrac;
313441      invtf <<= 3;
314      sfrac <<= 3;
315      tfrac <<= 3;
442   }
316443
317      t0.c = Fetch(sss1, sst1, tilenum, object, userdata);
444   sfrac <<= 3;
445   tfrac <<= 3;
318446
319      if (bilerp)
320      {
321         t1.c = Fetch(sss2, sst1, tilenum, object, userdata);
322         t2.c = Fetch(sss1, sst2, tilenum, object, userdata);
323         t3.c = Fetch(sss2, sst2, tilenum, object, userdata);
324         if (!center)
325         {
326            if (upper)
327            {
328               TEX->i.r = t3.i.r + (((invsf * (t2.i.r - t3.i.r)) + (invtf * (t1.i.r - t3.i.r)) + 0x80) >> 8);
329               TEX->i.g = t3.i.g + (((invsf * (t2.i.g - t3.i.g)) + (invtf * (t1.i.g - t3.i.g)) + 0x80) >> 8);
330               TEX->i.b = t3.i.b + (((invsf * (t2.i.b - t3.i.b)) + (invtf * (t1.i.b - t3.i.b)) + 0x80) >> 8);
331               TEX->i.a = t3.i.a + (((invsf * (t2.i.a - t3.i.a)) + (invtf * (t1.i.a - t3.i.a)) + 0x80) >> 8);
332            }
333            else
334            {
335               TEX->i.r = t0.i.r + (((sfrac * (t1.i.r - t0.i.r)) + (tfrac * (t2.i.r - t0.i.r)) + 0x80) >> 8);
336               TEX->i.g = t0.i.g + (((sfrac * (t1.i.g - t0.i.g)) + (tfrac * (t2.i.g - t0.i.g)) + 0x80) >> 8);
337               TEX->i.b = t0.i.b + (((sfrac * (t1.i.b - t0.i.b)) + (tfrac * (t2.i.b - t0.i.b)) + 0x80) >> 8);
338               TEX->i.a = t0.i.a + (((sfrac * (t1.i.a - t0.i.a)) + (tfrac * (t2.i.a - t0.i.a)) + 0x80) >> 8);
339            }
340            TEX->i.r &= 0x1ff;
341            TEX->i.g &= 0x1ff;
342            TEX->i.b &= 0x1ff;
343            TEX->i.a &= 0x1ff;
344         }
345         else
346         {
347            TEX->i.r = (t0.i.r + t1.i.r + t2.i.r + t3.i.r) >> 2;
348            TEX->i.g = (t0.i.g + t1.i.g + t2.i.g + t3.i.g) >> 2;
349            TEX->i.b = (t0.i.b + t1.i.b + t2.i.b + t3.i.b) >> 2;
350            TEX->i.a = (t0.i.a + t1.i.a + t2.i.a + t3.i.a) >> 2;
351         }
352      }
353      else
354      {
355         INT32 newk0 = SIGN9(m_rdp->GetK0());
356         INT32 newk1 = SIGN9(m_rdp->GetK1());
357         INT32 newk2 = SIGN9(m_rdp->GetK2());
358         INT32 newk3 = SIGN9(m_rdp->GetK3());
359         INT32 invk0 = ~newk0;
360         INT32 invk1 = ~newk1;
361         INT32 invk2 = ~newk2;
362         INT32 invk3 = ~newk3;
363         if (convert)
364         {
365            t0 = *prev;
366         }
367         t0.i.r = SIGN9(t0.i.r); t0.i.g = SIGN9(t0.i.g); t0.i.b = SIGN9(t0.i.b);
368         TEX->i.r = t0.i.b + (((newk0 - invk0) * t0.i.g + 0x80) >> 8);
369         TEX->i.g = t0.i.b + (((newk1 - invk1) * t0.i.r + (newk2 - invk2) * t0.i.g + 0x80) >> 8);
370         TEX->i.b = t0.i.b + (((newk3 - invk3) * t0.i.r + 0x80) >> 8);
371         TEX->i.a = t0.i.b;
372         TEX->i.r &= 0x1ff;
373         TEX->i.g &= 0x1ff;
374         TEX->i.b &= 0x1ff;
375         TEX->i.a &= 0x1ff;
376      }
447   Color t0;
448   t0.c = ((this)->*(TexelFetch[index]))(sss1, sst1, tbase, tpal, userdata);
449   INT32 newk0 = SIGN9(m_rdp->GetK0());
450   INT32 newk1 = SIGN9(m_rdp->GetK1());
451   INT32 newk2 = SIGN9(m_rdp->GetK2());
452   INT32 newk3 = SIGN9(m_rdp->GetK3());
453   INT32 invk0 = ~newk0;
454   INT32 invk1 = ~newk1;
455   INT32 invk2 = ~newk2;
456   INT32 invk3 = ~newk3;
457   if (convert)
458   {
459      t0 = *prev;
377460   }
378   else
461   t0.i.r = SIGN9(t0.i.r); t0.i.g = SIGN9(t0.i.g); t0.i.b = SIGN9(t0.i.b);
462   TEX->i.r = t0.i.b + (((newk0 - invk0) * t0.i.g + 0x80) >> 8);
463   TEX->i.g = t0.i.b + (((newk1 - invk1) * t0.i.r + (newk2 - invk2) * t0.i.g + 0x80) >> 8);
464   TEX->i.b = t0.i.b + (((newk3 - invk3) * t0.i.r + 0x80) >> 8);
465   TEX->i.a = t0.i.b;
466   TEX->i.r &= 0x1ff;
467   TEX->i.g &= 0x1ff;
468   TEX->i.b &= 0x1ff;
469   TEX->i.a &= 0x1ff;
470}
471
472void N64TexturePipeT::CycleLinearLerp(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
473{
474   const N64Tile* tiles = object.m_tiles;
475   const N64Tile& tile = tiles[tilenum];
476
477#define TRELATIVE(x, y)     ((((x) >> 3) - (y)) << 3) | (x & 7);
478   UINT32 tpal = tile.palette;
479   UINT32 index = (tile.format << 4) | (tile.size << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
480
481   int center = 0;
482
483   INT32 invsf = 0;
484   INT32 sss1 = SSS;
485   INT32 maxs;
486   SHIFT_CYCLE(sss1, maxs, tilenum, s);
487   sss1 = TRELATIVE(sss1, tile.sl);
488   INT32 sfrac = sss1 & 0x1f;
489   CLAMP_CYCLE(sss1, sfrac, maxs, tilenum, s);
490   INT32 sss2 = sss1 + 1;
491   MASK_COUPLED(sss1, sss2, tilenum, s);
492
493   INT32 invtf = 0;
494   INT32 sst1 = SST;
495   INT32 maxt;
496   SHIFT_CYCLE(sst1, maxt, tilenum, t);
497   sst1 = TRELATIVE(sst1, tile.tl);
498   INT32 tfrac = sst1 & 0x1f;
499   CLAMP_CYCLE(sst1, tfrac, maxt, tilenum, t);
500   INT32 sst2 = sst1 + 1;
501   MASK_COUPLED(sst1, sst2, tilenum, t);
502
503   UINT32 tbase1 = tile.tmem + ((tile.line * sst1) & 0x1ff);
504   UINT32 tbase2 = tile.tmem + ((tile.line * sst2) & 0x1ff);
505
506   bool upper = ((sfrac + tfrac) >= 0x20);
507
508   if (upper)
379509   {
380      INT32 sss1 = SSS;
381      INT32 sst1 = SST;
510      invsf = 0x20 - sfrac;
511      invsf <<= 3;
382512
383      INT32 maxs;
384      INT32 maxt;
513      invtf = 0x20 - tfrac;
514      invtf <<= 3;
515   }
385516
386      ShiftCycle(&sss1, &sst1, &maxs, &maxt, tilenum, object);
387      sss1 = TRELATIVE(sss1, tile[tilenum].sl);
388      sst1 = TRELATIVE(sst1, tile[tilenum].tl);
517   center = (sfrac == 0x10) && (tfrac == 0x10) && object.OtherModes.mid_texel;
389518
390      ClampCycleLight(&sss1, &sst1, maxs, maxt, tilenum, userdata, object, m_clamp_s_diff, m_clamp_t_diff);
519   sfrac <<= 3;
520   tfrac <<= 3;
391521
392      Mask(&sss1, &sst1, tilenum, object);
393
394      t0.c = Fetch(sss1, sst1, tilenum, object, userdata);
395      if (bilerp)
522   Color t1;
523   Color t2;
524   t1.c = ((this)->*(TexelFetch[index]))(sss2, sst1, tbase1, tpal, userdata);
525   t2.c = ((this)->*(TexelFetch[index]))(sss1, sst2, tbase2, tpal, userdata);
526   if (!center)
527   {
528      if (upper)
396529      {
397         *TEX = t0;
530         Color t3;
531         t3.c = ((this)->*(TexelFetch[index]))(sss2, sst2, tbase2, tpal, userdata);
532         TEX->i.r = t3.i.r + (((invsf * (t2.i.r - t3.i.r)) + (invtf * (t1.i.r - t3.i.r)) + 0x80) >> 8);
533         TEX->i.g = t3.i.g + (((invsf * (t2.i.g - t3.i.g)) + (invtf * (t1.i.g - t3.i.g)) + 0x80) >> 8);
534         TEX->i.b = t3.i.b + (((invsf * (t2.i.b - t3.i.b)) + (invtf * (t1.i.b - t3.i.b)) + 0x80) >> 8);
535         TEX->i.a = t3.i.a + (((invsf * (t2.i.a - t3.i.a)) + (invtf * (t1.i.a - t3.i.a)) + 0x80) >> 8);
398536      }
399537      else
400538      {
401         INT32 newk0 = SIGN9(m_rdp->GetK0());
402         INT32 newk1 = SIGN9(m_rdp->GetK1());
403         INT32 newk2 = SIGN9(m_rdp->GetK2());
404         INT32 newk3 = SIGN9(m_rdp->GetK3());
405         INT32 invk0 = ~newk0;
406         INT32 invk1 = ~newk1;
407         INT32 invk2 = ~newk2;
408         INT32 invk3 = ~newk3;
409         if (convert)
410         {
411            t0 = *prev;
412         }
413         t0.i.r = SIGN9(t0.i.r);
414         t0.i.g = SIGN9(t0.i.g);
415         t0.i.b = SIGN9(t0.i.b);
416         TEX->i.r = t0.i.b + (((newk0 - invk0) * t0.i.g + 0x80) >> 8);
417         TEX->i.g = t0.i.b + (((newk1 - invk1) * t0.i.r + (newk2 - invk2) * t0.i.g + 0x80) >> 8);
418         TEX->i.b = t0.i.b + (((newk3 - invk3) * t0.i.r + 0x80) >> 8);
419         TEX->i.a = t0.i.b;
420         TEX->i.r &= 0x1ff;
421         TEX->i.g &= 0x1ff;
422         TEX->i.b &= 0x1ff;
423         TEX->i.a &= 0x1ff;
539         Color t0;
540         t0.c = ((this)->*(TexelFetch[index]))(sss1, sst1, tbase1, tpal, userdata);
541         TEX->i.r = t0.i.r + (((sfrac * (t1.i.r - t0.i.r)) + (tfrac * (t2.i.r - t0.i.r)) + 0x80) >> 8);
542         TEX->i.g = t0.i.g + (((sfrac * (t1.i.g - t0.i.g)) + (tfrac * (t2.i.g - t0.i.g)) + 0x80) >> 8);
543         TEX->i.b = t0.i.b + (((sfrac * (t1.i.b - t0.i.b)) + (tfrac * (t2.i.b - t0.i.b)) + 0x80) >> 8);
544         TEX->i.a = t0.i.a + (((sfrac * (t1.i.a - t0.i.a)) + (tfrac * (t2.i.a - t0.i.a)) + 0x80) >> 8);
424545      }
546      TEX->i.r &= 0x1ff;
547      TEX->i.g &= 0x1ff;
548      TEX->i.b &= 0x1ff;
549      TEX->i.a &= 0x1ff;
425550   }
551   else
552   {
553      Color t0;
554      Color t3;
555      t0.c = ((this)->*(TexelFetch[index]))(sss1, sst1, 1, tpal, userdata);
556      t3.c = ((this)->*(TexelFetch[index]))(sss2, sst2, tbase2, tpal, userdata);
557      TEX->i.r = (t0.i.r + t1.i.r + t2.i.r + t3.i.r) >> 2;
558      TEX->i.g = (t0.i.g + t1.i.g + t2.i.g + t3.i.g) >> 2;
559      TEX->i.b = (t0.i.b + t1.i.b + t2.i.b + t3.i.b) >> 2;
560      TEX->i.a = (t0.i.a + t1.i.a + t2.i.a + t3.i.a) >> 2;
561   }
426562}
427563
428564void N64TexturePipeT::Copy(Color* TEX, INT32 SSS, INT32 SST, UINT32 tilenum, const rdp_poly_state& object, rdp_span_aux *userdata)
429565{
430   const N64Tile* tile = object.m_tiles;
566   const N64Tile* tiles = object.m_tiles;
567   const N64Tile& tile = tiles[tilenum];
431568   INT32 sss1 = SSS;
432569   INT32 sst1 = SST;
433570   ShiftCopy(&sss1, &sst1, tilenum, object);
434   sss1 = TRELATIVE(sss1, tile[tilenum].sl);
435   sst1 = TRELATIVE(sst1, tile[tilenum].tl);
571   sss1 = TRELATIVE(sss1, tile.sl);
572   sst1 = TRELATIVE(sst1, tile.tl);
436573   sss1 = (SIGN17(sss1) >> 5) & 0x1fff;
437574   sst1 = (SIGN17(sst1) >> 5) & 0x1fff;
438575   Mask(&sss1, &sst1, tilenum, object);
r25470r25471
789926
790927void N64TexturePipeT::CalculateClampDiffs(UINT32 prim_tile, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff)
791928{
792   const N64Tile* tile = object.m_tiles;
929   const N64Tile* tiles = object.m_tiles;
793930   if (object.OtherModes.cycle_type == CYCLE_TYPE_2)
794931   {
795932      if (object.OtherModes.tex_lod_en)
r25470r25471
798935         int end = 7;
799936         for (; start <= end; start++)
800937         {
801            m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2);
802            m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2);
938            m_clamp_s_diff[start] = (tiles[start].sh >> 2) - (tiles[start].sl >> 2);
939            m_clamp_t_diff[start] = (tiles[start].th >> 2) - (tiles[start].tl >> 2);
803940         }
804941      }
805942      else
806943      {
807944         int start = prim_tile;
808945         int end = (prim_tile + 1) & 7;
809         m_clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2);
810         m_clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2);
811         m_clamp_s_diff[end] = (tile[end].sh >> 2) - (tile[end].sl >> 2);
812         m_clamp_t_diff[end] = (tile[end].th >> 2) - (tile[end].tl >> 2);
946         m_clamp_s_diff[start] = (tiles[start].sh >> 2) - (tiles[start].sl >> 2);
947         m_clamp_t_diff[start] = (tiles[start].th >> 2) - (tiles[start].tl >> 2);
948         m_clamp_s_diff[end] = (tiles[end].sh >> 2) - (tiles[end].sl >> 2);
949         m_clamp_t_diff[end] = (tiles[end].th >> 2) - (tiles[end].tl >> 2);
813950      }
814951   }
815952   else//1-cycle or copy
816953   {
817      m_clamp_s_diff[prim_tile] = (tile[prim_tile].sh >> 2) - (tile[prim_tile].sl >> 2);
818      m_clamp_t_diff[prim_tile] = (tile[prim_tile].th >> 2) - (tile[prim_tile].tl >> 2);
954      m_clamp_s_diff[prim_tile] = (tiles[prim_tile].sh >> 2) - (tiles[prim_tile].sl >> 2);
955      m_clamp_t_diff[prim_tile] = (tiles[prim_tile].th >> 2) - (tiles[prim_tile].tl >> 2);
819956   }
820957}
821958
r25470r25471
13771514
13781515UINT32 N64TexturePipeT::Fetch(INT32 s, INT32 t, INT32 tilenum, const rdp_poly_state& object, rdp_span_aux *userdata)
13791516{
1380   const N64Tile* tile = object.m_tiles;
1381   UINT32 tformat = tile[tilenum].format;
1382   UINT32 tsize =  tile[tilenum].size;
1517   const N64Tile* tiles = object.m_tiles;
1518   const N64Tile& tile = tiles[tilenum];
1519   UINT32 tformat = tile.format;
1520   UINT32 tsize =  tile.size;
1521   UINT32 tpal = tile.palette;
1522   UINT32 index = (tformat << 4) | (tsize << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
13831523
1384   UINT32 tbase = (tile[tilenum].line * t) & 0x1ff;
1385   tbase += tile[tilenum].tmem;
1386   UINT32 tpal = tile[tilenum].palette;
1524   UINT32 tbase = tile.tmem + ((tile.line * t) & 0x1ff);
13871525
1388   UINT32 index = (tformat << 4) | (tsize << 2) | ((UINT32) object.OtherModes.en_tlut << 1) | (UINT32) object.OtherModes.tlut_type;
1389
13901526   return ((this)->*(TexelFetch[index]))(s, t, tbase, tpal, userdata);
13911527}
trunk/src/mame/video/rdptpipe.h
r25470r25471
2626{
2727   public:
2828      typedef UINT32 (N64TexturePipeT::*TexelFetcher) (INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux *userdata);
29      typedef void (N64TexturePipeT::*Cycler) (Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
2930
3031      N64TexturePipeT()
3132      {
r25470r25471
8586         TexelFetch[69] = &N64TexturePipeT::_FetchI_8_RAW;
8687         TexelFetch[70] = &N64TexturePipeT::_FetchI_8_TLUT0;
8788         TexelFetch[71] = &N64TexturePipeT::_FetchI_8_TLUT1;
89
90         cycle[0] = &N64TexturePipeT::CycleNearest;
91         cycle[1] = &N64TexturePipeT::CycleNearestLerp;
92         cycle[2] = &N64TexturePipeT::CycleLinear;
93         cycle[3] = &N64TexturePipeT::CycleLinearLerp;
8894      }
8995
90      void                Cycle(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
96      void                CycleNearest(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
97      void                CycleNearestLerp(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
98      void                CycleLinear(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
99      void                CycleLinearLerp(Color* TEX, Color* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
100
101      Cycler            cycle[4];
102
91103      void                Copy(Color* TEX, INT32 SSS, INT32 SST, UINT32 tilenum, const rdp_poly_state& object, rdp_span_aux *userdata);
92104      UINT32              Fetch(INT32 SSS, INT32 SST, INT32 tile, const rdp_poly_state& object, rdp_span_aux *userdata);
93105      void                CalculateClampDiffs(UINT32 prim_tile, rdp_span_aux *userdata, const rdp_poly_state& object, INT32 *m_clamp_s_diff, INT32 *m_clamp_t_diff);
trunk/src/mame/video/n64.c
r25470r25471
3030
3131static FILE *rdp_exec;
3232
33UINT32 n64_rdp::s_special_9bit_clamptable[512];
34
3335bool n64_rdp::rdp_range_check(UINT32 addr)
3436{
3537   if(MiscState.FBSize == 0) return false;
r25470r25471
413415   d = KURT_AKELEY_SIGN9(d);
414416   a = (((a - b) * c) + (d << 8) + 0x80);
415417   a = SIGN17(a) >> 8;
416   a = m_special_9bit_clamptable[a & 0x1ff];
418   a = s_special_9bit_clamptable[a & 0x1ff];
417419   return a;
418420}
419421
r25470r25471
425427   d = KURT_AKELEY_SIGN9(d);
426428   a = (((a - b) * c) + (d << 8) + 0x80) >> 8;
427429   a = SIGN9(a);
428   a = m_special_9bit_clamptable[a & 0x1ff];
430   a = s_special_9bit_clamptable[a & 0x1ff];
429431   return a;
430432}
431433
432void n64_rdp::ColorCombiner1Cycle(rdp_span_aux *userdata)
433{
434   userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = GetRandom() << 3; // Not accurate
435
436   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]);
437   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]);
438   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]);
439   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]);
440}
441
442void n64_rdp::ColorCombiner2Cycle(rdp_span_aux *userdata)
443{
444   userdata->NoiseColor.i.r = userdata->NoiseColor.i.g = userdata->NoiseColor.i.b = GetRandom() << 3; // Not accurate
445   userdata->CombinedColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[0],
446                                          *userdata->ColorInputs.combiner_rgbsub_b_r[0],
447                                          *userdata->ColorInputs.combiner_rgbmul_r[0],
448                                          *userdata->ColorInputs.combiner_rgbadd_r[0]);
449   userdata->CombinedColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[0],
450                                          *userdata->ColorInputs.combiner_rgbsub_b_g[0],
451                                          *userdata->ColorInputs.combiner_rgbmul_g[0],
452                                          *userdata->ColorInputs.combiner_rgbadd_g[0]);
453   userdata->CombinedColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[0],
454                                          *userdata->ColorInputs.combiner_rgbsub_b_b[0],
455                                          *userdata->ColorInputs.combiner_rgbmul_b[0],
456                                          *userdata->ColorInputs.combiner_rgbadd_b[0]);
457   userdata->CombinedColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[0],
458                                          *userdata->ColorInputs.combiner_alphasub_b[0],
459                                          *userdata->ColorInputs.combiner_alphamul[0],
460                                          *userdata->ColorInputs.combiner_alphaadd[0]);
461
462   userdata->Texel0Color = userdata->Texel1Color;
463   userdata->Texel1Color = userdata->NextTexelColor;
464
465   userdata->PixelColor.i.r = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_r[1],
466                                          *userdata->ColorInputs.combiner_rgbsub_b_r[1],
467                                          *userdata->ColorInputs.combiner_rgbmul_r[1],
468                                          *userdata->ColorInputs.combiner_rgbadd_r[1]);
469   userdata->PixelColor.i.g = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_g[1],
470                                          *userdata->ColorInputs.combiner_rgbsub_b_g[1],
471                                          *userdata->ColorInputs.combiner_rgbmul_g[1],
472                                          *userdata->ColorInputs.combiner_rgbadd_g[1]);
473   userdata->PixelColor.i.b = ColorCombinerEquation(*userdata->ColorInputs.combiner_rgbsub_a_b[1],
474                                          *userdata->ColorInputs.combiner_rgbsub_b_b[1],
475                                          *userdata->ColorInputs.combiner_rgbmul_b[1],
476                                          *userdata->ColorInputs.combiner_rgbadd_b[1]);
477   userdata->PixelColor.i.a = AlphaCombinerEquation(*userdata->ColorInputs.combiner_alphasub_a[1],
478                                          *userdata->ColorInputs.combiner_alphasub_b[1],
479                                          *userdata->ColorInputs.combiner_alphamul[1],
480                                          *userdata->ColorInputs.combiner_alphaadd[1]);
481}
482
483434void n64_rdp::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata)
484435{
485436   switch (code & 0xf)
r25470r25471
37823733      {
37833734      case 0:
37843735      case 1:
3785         m_special_9bit_clamptable[i] = i & 0xff;
3736         s_special_9bit_clamptable[i] = i & 0xff;
37863737         break;
37873738      case 2:
3788         m_special_9bit_clamptable[i] = 0xff;
3739         s_special_9bit_clamptable[i] = 0xff;
37893740         break;
37903741      case 3:
3791         m_special_9bit_clamptable[i] = 0;
3742         s_special_9bit_clamptable[i] = 0;
37923743         break;
37933744      }
37943745   }
trunk/src/mame/video/n64.h
r25470r25471
5656#define MEM16_LIMIT 0x3fffff
5757#define MEM32_LIMIT 0x1fffff
5858
59#define RDP_RANGE_CHECK (1)
59#define RDP_RANGE_CHECK (0)
6060
6161#if RDP_RANGE_CHECK
6262#define CHECK8(in) if(rdp_range_check((in))) { printf("Check8: Address %08x out of range!\n", (in)); fflush(stdout); fatalerror("Address %08x out of range!\n", (in)); }
r25470r25471
458458      // Color Combiner
459459      INT32       ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d);
460460      INT32       AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d);
461      void        ColorCombiner2Cycle(rdp_span_aux *userdata);
462      void        ColorCombiner1Cycle(rdp_span_aux *userdata);
463461      void        SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata);
464462      void        SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata);
465463      void        SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata);
r25470r25471
562560
563561      void        GetDitherValues(int x, int y, int* cdith, int* adith, const rdp_poly_state &object);
564562
565      UINT32*         GetSpecial9BitClampTable() { return m_special_9bit_clamptable; }
566
567563      UINT16 decompress_cvmask_frombyte(UINT8 x);
568564      void lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy, rdp_span_aux *userdata);
569565
r25470r25471
665661      INT32 m_gamma_table[256];
666662      INT32 m_gamma_dither_table[0x4000];
667663
668      UINT32 m_special_9bit_clamptable[512];
664      static UINT32 s_special_9bit_clamptable[512];
669665
670666      Writer              _Write[16];
671667      Reader              _Read[4];

Previous 199869 Revisions Next


© 1997-2024 The MAME Team