Previous 15994 Revisions Next

r7676 Friday 2nd April, 2010 at 05:40:45 UTC by MooglyGuy
Almost completely re-wrote the N64 RDP implementation to be class-
based. Import from MAME. [Harmony]
[src/mame/includes]n64.h
[src/mame/machine]n64.c
[src/mame/video]n64.c n64.h* rdpacomp.c rdpacomp.h rdpacvg.c rdpacvg.h rdpblend.c rdpblend.h rdpcc.c rdpcc.h rdpclamp.c rdpclamp.h rdpfb.c rdpfb.h rdpfetch.c rdpfetch.h rdpfiltr.c* rdpfrect.c rdpfrect.h rdpmask.c rdpmask.h rdpshift.c rdpshift.h rdpspn16.c rdpspn16.h rdptpipe.c rdptpipe.h rdptrect.c rdptrect.h rdptri.c rdptri.h rdpupd16.c rdpupd16.h rdpzcomp.c rdpzcomp.h
[src/mess]mess.mak
[src/mess/drivers]n64.c

src/mame/machine/n64.c
r7675r7676
719719}
720720
721721// RDP Interface
722UINT32 dp_start;
723UINT32 dp_end;
724UINT32 dp_current;
725UINT32 dp_status = 0x88;
726722
727
728723void dp_full_sync(running_machine *machine)
729724{
730725   signal_rcp_interrupt(machine, DP_INTERRUPT);
r7675r7676
732727
733728READ32_DEVICE_HANDLER( n64_dp_reg_r )
734729{
730   _n64_state *state = (_n64_state *)device->machine->driver_data;
731
735732   switch (offset)
736733   {
737734      case 0x00/4:      // DP_START_REG
738         return dp_start;
735         return state->m_rdp.GetStartReg();
739736
740737      case 0x04/4:      // DP_END_REG
741         return dp_end;
738         return state->m_rdp.GetEndReg();
742739
743740      case 0x08/4:      // DP_CURRENT_REG
744         return dp_current;
741         return state->m_rdp.GetCurrentReg();
745742
746743      case 0x0c/4:      // DP_STATUS_REG
747         return dp_status;
744         return state->m_rdp.GetStatusReg();
748745
749746      default:
750747         logerror("dp_reg_r: %08X, %08X at %08X\n", offset, mem_mask, cpu_get_pc(device));
r7675r7676
756753
757754WRITE32_DEVICE_HANDLER( n64_dp_reg_w )
758755{
756   _n64_state *state = (_n64_state *)device->machine->driver_data;
757
759758   switch (offset)
760759   {
761760      case 0x00/4:      // DP_START_REG
762         dp_start = data;
763         dp_current = dp_start;
761         state->m_rdp.SetStartReg(data);
762         state->m_rdp.SetCurrentReg(state->m_rdp.GetStartReg());
764763         break;
765764
766765      case 0x04/4:      // DP_END_REG
767         dp_end = data;
766         state->m_rdp.SetEndReg(data);
768767         profiler_mark_start(PROFILER_USER1);
769         rdp_process_list(device->machine);
768         state->m_rdp.ProcessList();
770769         profiler_mark_end();
771770         break;
772771
773772      case 0x0c/4:      // DP_STATUS_REG
774         if (data & 0x00000001)   dp_status &= ~DP_STATUS_XBUS_DMA;
775         if (data & 0x00000002)   dp_status |= DP_STATUS_XBUS_DMA;
776         if (data & 0x00000004)   dp_status &= ~DP_STATUS_FREEZE;
777         if (data & 0x00000008)   dp_status |= DP_STATUS_FREEZE;
778         if (data & 0x00000010)   dp_status &= ~DP_STATUS_FLUSH;
779         if (data & 0x00000020)   dp_status |= DP_STATUS_FLUSH;
773      {
774         UINT32 current_status = state->m_rdp.GetStatusReg();
775         if (data & 0x00000001)   current_status &= ~DP_STATUS_XBUS_DMA;
776         if (data & 0x00000002)   current_status |= DP_STATUS_XBUS_DMA;
777         if (data & 0x00000004)   current_status &= ~DP_STATUS_FREEZE;
778         if (data & 0x00000008)   current_status |= DP_STATUS_FREEZE;
779         if (data & 0x00000010)   current_status &= ~DP_STATUS_FLUSH;
780         if (data & 0x00000020)   current_status |= DP_STATUS_FLUSH;
781         state->m_rdp.SetStatusReg(current_status);
780782         break;
783      }
781784
782785      default:
783786         logerror("dp_reg_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(device));
r7675r7676
811814
812815static void n64_vi_recalculate_resolution(running_machine *machine)
813816{
817   _n64_state *state = (_n64_state *)machine->driver_data;
818
814819    int x_start = (n64_vi_hstart & 0x03ff0000) >> 16;
815820    int x_end = n64_vi_hstart & 0x000003ff;
816821    int y_start = ((n64_vi_vstart & 0x03ff0000) >> 16) / 2;
r7675r7676
846851    if (height > 480)
847852        height = 480;
848853
849   fb_height = height;
854   state->m_rdp.GetMiscState()->m_fb_height = height;
850855
851856    visarea.max_x = width - 1;
852857    visarea.max_y = height - 1;
r7675r7676
908913
909914WRITE32_HANDLER( n64_vi_reg_w )
910915{
916   _n64_state *state = (_n64_state *)space->machine->driver_data;
917
911918   switch (offset)
912919   {
913920      case 0x00/4:      // VI_CONTROL_REG
r7675r7676
925932                n64_vi_recalculate_resolution(space->machine);
926933         }
927934            n64_vi_width = data;
928          fb_width = data;
935          state->m_rdp.GetMiscState()->m_fb_width = data;
929936         break;
930937
931938      case 0x0c/4:      // VI_INTR_REG
r7675r7676
20302037   sp_dma_skip = 0;
20312038   sp_semaphore = 0;
20322039
2033   dp_start = 0;
2034   dp_end = 0;
2035   dp_current = 0;
2036   dp_status = 0x88;
2037
20382040   n64_vi_width = 0;
20392041   n64_vi_origin = 0;
20402042   n64_vi_control = 0;
src/mame/includes/n64.h
r7675r7676
22#define _INCLUDES_N64_H_
33
44#include "cpu/rsp/rsp.h"
5#include "video/n64.h"
56
7/*----------- driver state -----------*/
8
9class _n64_state
10{
11public:
12   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, _n64_state(machine)); }
13
14   _n64_state(running_machine &machine) { }
15
16   /* video-related */
17   N64::RDP::Processor m_rdp;
18};
19
620/*----------- defined in video/n64.c -----------*/
721
822extern int fb_width;
r7675r7676
5165extern UINT32 *rsp_imem;
5266extern UINT32 *rsp_dmem;
5367
54extern UINT32 dp_start;
55extern UINT32 dp_end;
56extern UINT32 dp_current;
57extern UINT32 dp_status;
58
5968extern UINT32 n64_vi_width;
6069extern UINT32 n64_vi_origin;
6170extern UINT32 n64_vi_control;
src/mame/video/rdptri.c
r7675r7676
1#define addleft(x) addleftcvg(x,k)
2#define addright(x) addrightcvg(x,k)
3
4#define setvalues()   \
5{               \
6   addvalues();   \
7   adjust_attr();   \
8}
9
10static void triangle_ns_nt_nz(UINT32 w1, UINT32 w2)
11{
12   int flip     = (w1 & 0x800000) ?  1 :  0;
13   int sign     = (w1 & 0x800000) ? -1 :  1;
14   int inv_sign = (w1 & 0x800000) ?  1 : -1;
15
16   int xfrac = 0;
17
18   INT32 maxxmx = 0;
19   INT32 minxmx = 0;
20   INT32 maxxhx = 0;
21   INT32 minxhx = 0;
22
23   UINT32 w3 = rdp_cmd_data[rdp_cmd_cur+2];
24   UINT32 w4 = rdp_cmd_data[rdp_cmd_cur+3];
25   UINT32 w5 = rdp_cmd_data[rdp_cmd_cur+4];
26   UINT32 w6 = rdp_cmd_data[rdp_cmd_cur+5];
27   UINT32 w7 = rdp_cmd_data[rdp_cmd_cur+6];
28   UINT32 w8 = rdp_cmd_data[rdp_cmd_cur+7];
29
30   INT32 yl = (w1 & 0x3fff);
31   INT32 ym = ((w2 >> 16) & 0x3fff);
32   INT32 yh = ((w2 >>  0) & 0x3fff);
33   INT32 xl = (INT32)(w3 & 0x3fffffff);
34   INT32 xh = (INT32)(w5 & 0x3fffffff);
35   INT32 xm = (INT32)(w7 & 0x3fffffff);
36   // Inverse slopes in 16.16 format
37   INT32 dxldy = (INT32)(w4);
38   INT32 dxhdy = (INT32)(w6);
39   INT32 dxmdy = (INT32)(w8);
40
41   max_level = ((w1 >> 19) & 7);
42
43   if (yl & 0x2000)  yl |= 0xffffc000;
44   if (ym & 0x2000)  ym |= 0xffffc000;
45   if (yh & 0x2000)  yh |= 0xffffc000;
46
47   if (xl & 0x20000000)  xl |= 0xc0000000;
48   if (xm & 0x20000000)  xm |= 0xc0000000;
49   if (xh & 0x20000000)  xh |= 0xc0000000;
50
51   span[0].dymax = 0;
52
53   int xleft_inc = dxmdy >> 2;
54   int xright_inc = dxhdy >> 2;
55
56   int xright = xh;
57   int xleft = xm;
58
59   INT32 limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
60   if (limcvg < 0)
61   {
62      limcvg = 0;
63   }
64
65   INT32 startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
66   for (int k = startcvg; k <= limcvg; k++)
67   {
68      memset((void*)&span[k].cvg[0],0,640);
69   }
70
71   int sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
72
73   int ycur =   yh & ~3;
74   int ylfar = yl | 3;
75   int ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
76   int yhpix = yh >> 2;
77   int ylpix = yl >> 2;
78
79   if(ylfar >= 0x1000)
80   {
81      ylfar = 0x0fff;
82   }
83
84   for (int k = ycur; k <= ylfar; k++)
85   {
86      if (k == ym)
87      {
88         xleft = xl;
89         xleft_inc = dxldy >> 2;
90      }
91
92      int xstart = xleft >> 16;
93      int xend = xright >> 16;
94      int j = k >> 2;
95      int spix = k & 3;
96
97      UINT32 min = 0;
98      UINT32 max = 3;
99      if (j == yhpix)
100      {
101         min = yh & 3;
102      }
103      if (j == ylpix)
104      {
105         max = yl & 3;
106      }
107      if (spix >= min && spix <= max)
108      {
109         if (spix == min)
110         {
111            minxmx = maxxmx = xstart;
112            minxhx = maxxhx = xend;
113         }
114         else
115         {
116            minxmx = (xstart < minxmx) ? xstart : minxmx;
117            maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
118            minxhx = (xend < minxhx) ? xend : minxhx;
119            maxxhx = (xend > maxxhx) ? xend : maxxhx;
120         }
121      }
122
123      if (spix == max)
124      {
125         if (flip)
126         {
127            span[j].lx = maxxmx;
128            span[j].rx = minxhx;
129         }
130         else
131         {
132            span[j].lx = minxmx;
133            span[j].rx = maxxhx;
134         }
135      }
136
137      int length = (xend - xstart) * sign;
138
139      if (spix == ldflag)
140      {
141         xfrac = ((xright >> 8) & 0xff);
142      }
143
144      int m = flip ? (xend+1) : (xend-1);
145
146      if (k >= yh && length >= 0 && k <= yl)
147      {
148         if (xstart>=0 && xstart <1024)
149         {
150            if (!flip)
151            {
152               span[j].cvg[xstart] += addleft(xleft);
153            }
154            else
155            {
156               span[j].cvg[xstart] += addright(xleft);
157            }
158         }
159         if (xend>=0 && xend<1024)
160         {
161            if (xstart != xend)
162            {
163               if (!flip)
164               {
165                  span[j].cvg[xend] += addright(xright);
166               }
167               else
168               {
169                  span[j].cvg[xend] += addleft(xright);
170               }
171            }
172            else
173            {
174               if (!flip)
175               {
176                  span[j].cvg[xend] -= (2 - addright(xright));
177               }
178               else
179               {
180                  span[j].cvg[xend] -= (2 - addleft(xright));
181               }
182               if (span[j].cvg[xend] > 200)
183               {
184                  span[j].cvg[xend] = 0;
185               }
186            }
187         }
188         for (int n = 0; n < (length - 1); n++)
189         {
190            if (m >= 0 && m < 640)
191            {
192               span[j].cvg[m] += 2;
193            }
194
195            m += inv_sign;
196         }
197      }
198
199      xleft += xleft_inc;
200      xright += xright_inc;
201   }
202
203   switch (fb_size) // 8bpp needs to be implemented
204   {
205      case PIXEL_SIZE_16BIT:
206         if(flip)
207         {
208            render_spans_16_ns_nt_nz_f(yh>>2, yl>>2, &tile[0]); break;
209         }
210         else
211         {
212            render_spans_16_ns_nt_nz_nf(yh>>2, yl>>2, &tile[0]); break;
213         }
214      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[0], 0, 0, 0, flip); break;
215      default: break; // V-Rally2 does this, fb_size=0
216   }
217}
218
219static void triangle_ns_nt_z(UINT32 w1, UINT32 w2)
220{
221   int flip     = (w1 & 0x800000) ? 1 : 0;
222   int sign     = (w1 & 0x800000) ? -1 : 1;
223   int inv_sign = (w1 & 0x800000) ? 1 : -1;
224
225   int xfrac = 0;
226
227   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
228
229   int zbuffer_base = rdp_cmd_cur + 8;
230
231   UINT32 w3 = rdp_cmd_data[rdp_cmd_cur+2];
232   UINT32 w4 = rdp_cmd_data[rdp_cmd_cur+3];
233   UINT32 w5 = rdp_cmd_data[rdp_cmd_cur+4];
234   UINT32 w6 = rdp_cmd_data[rdp_cmd_cur+5];
235   UINT32 w7 = rdp_cmd_data[rdp_cmd_cur+6];
236   UINT32 w8 = rdp_cmd_data[rdp_cmd_cur+7];
237
238   INT32 yl = (w1 & 0x3fff);
239   INT32 ym = ((w2 >> 16) & 0x3fff);
240   INT32 yh = ((w2 >>  0) & 0x3fff);
241   INT32 xl = (INT32)(w3 & 0x3fffffff);
242   INT32 xh = (INT32)(w5 & 0x3fffffff);
243   INT32 xm = (INT32)(w7 & 0x3fffffff);
244   // Inverse slopes in 16.16 format
245   INT32 dxldy = (INT32)(w4);
246   INT32 dxhdy = (INT32)(w6);
247   INT32 dxmdy = (INT32)(w8);
248
249   max_level = ((w1 >> 19) & 7);
250   int tilenum = (w1 >> 16) & 0x7;
251
252   if (yl & 0x2000)  yl |= 0xffffc000;
253   if (ym & 0x2000)  ym |= 0xffffc000;
254   if (yh & 0x2000)  yh |= 0xffffc000;
255
256   if (xl & 0x20000000)  xl |= 0xc0000000;
257   if (xm & 0x20000000)  xm |= 0xc0000000;
258   if (xh & 0x20000000)  xh |= 0xc0000000;
259
260   int z    = rdp_cmd_data[zbuffer_base+0];
261   int dzdx = rdp_cmd_data[zbuffer_base+1];
262   int dzde = rdp_cmd_data[zbuffer_base+2];
263   int dzdy = rdp_cmd_data[zbuffer_base+3];
264
265   int dzdiff = 0;
266   int dzeoff = 0;
267   int dzdeh = 0;
268   int dzdyh = 0;
269   int dzdxh = dzdx >> 8;
270
271   int dzdy_dz = (dzdy >> 16) & 0xffff;
272   int dzdx_dz = (dzdx >> 16) & 0xffff;
273   span[0].dz.w = dzdx;
274   span[0].dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
275   span[0].dzpix = normalize_dzpix(span[0].dzpix);
276
277   int xleft_inc = dxmdy >> 2;
278   int xright_inc = dxhdy >> 2;
279
280   int xright = xh;
281   int xleft = xm;
282
283   INT32 limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
284   if (limcvg < 0)
285   {
286      limcvg = 0;
287   }
288
289   INT32 startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
290   for (int k = startcvg; k <= limcvg; k++)
291   {
292      memset((void*)&span[k].cvg[0],0,640);
293   }
294
295   int sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
296
297   if (!(sign_dxhdy ^ (flip)))
298   {
299      dzdeh = dzde >> 9;
300      dzdyh = dzdy >> 9;
301      dzdiff = (dzdeh*3 - dzdyh*3) << 7;
302      dzeoff = (dzdeh*3) << 7;
303   }
304   else
305   {
306      dzdiff = 0;
307      dzeoff = 0;
308   }
309
310#define adjust_attr()      \
311{                     \
312         span[j].z.w = z + dzdiff - (xfrac * dzdxh);            \
313}
314
315#define addvalues() {   \
316         z += dzde; \
317}
318
319   int ycur =   yh & ~3;
320   int ylfar = yl | 3;
321   int ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
322   int yhpix = yh >> 2;
323   int ylpix = yl >> 2;
324
325   if(ylfar >= 0x1000)
326   {
327      ylfar = 0x0fff;
328   }
329
330   for (int k = ycur; k <= ylfar; k++)
331   {
332      if (k == ym)
333      {
334         xleft = xl;
335         xleft_inc = dxldy >> 2;
336      }
337
338      int xstart = xleft >> 16;
339      int xend = xright >> 16;
340      int j = k >> 2;
341      int spix = k & 3;
342
343      //if (k >= 0 && k < 0x1000)
344      {
345         int n = 0;
346         UINT32 min = 0;
347         UINT32 max = 3;
348         if (j == yhpix)
349         {
350            min = yh & 3;
351         }
352         if (j == ylpix)
353         {
354            max = yl & 3;
355         }
356         if (spix >= min && spix <= max)
357         {
358            if (spix == min)
359            {
360               minxmx = maxxmx = xstart;
361               minxhx = maxxhx = xend;
362            }
363            else
364            {
365               minxmx = (xstart < minxmx) ? xstart : minxmx;
366               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
367               minxhx = (xend < minxhx) ? xend : minxhx;
368               maxxhx = (xend > maxxhx) ? xend : maxxhx;
369            }
370         }
371
372         if (spix == max)
373         {
374            if (flip)
375            {
376               span[j].lx = maxxmx;
377               span[j].rx = minxhx;
378            }
379            else
380            {
381               span[j].lx = minxmx;
382               span[j].rx = maxxhx;
383            }
384         }
385
386         int length = (xend - xstart) * sign;
387
388         if (spix == ldflag)
389         {
390            xfrac = ((xright >> 8) & 0xff);
391            adjust_attr();
392         }
393
394         int m = flip ? (xend+1) : (xend-1);
395
396         if (k >= yh && length >= 0 && k <= yl)
397         {
398            if (xstart>=0 && xstart <1024)
399            {
400               if (!flip)
401               {
402                  span[j].cvg[xstart] += addleft(xleft);
403               }
404               else
405               {
406                  span[j].cvg[xstart] += addright(xleft);
407               }
408            }
409            if (xend>=0 && xend<1024)
410            {
411               if (xstart != xend)
412               {
413                  if (!flip)
414                  {
415                     span[j].cvg[xend] += addright(xright);
416                  }
417                  else
418                  {
419                     span[j].cvg[xend] += addleft(xright);
420                  }
421               }
422               else
423               {
424                  if (!flip)
425                  {
426                     span[j].cvg[xend] -= (2 - addright(xright));
427                  }
428                  else
429                  {
430                     span[j].cvg[xend] -= (2 - addleft(xright));
431                  }
432                  if (span[j].cvg[xend] > 200)
433                  {
434                     span[j].cvg[xend] = 0;
435                  }
436               }
437            }
438            for (n = 0; n < (length - 1); n++)
439            {
440               if (m>=0 && m < 640)
441               {
442                  span[j].cvg[m] += 2;
443               }
444
445               m += inv_sign;
446            }
447         }
448      }
449
450      if (spix == 3)
451      {
452         addvalues();
453      }
454      xleft += xleft_inc;
455      xright += xright_inc;
456   }
457
458   switch (fb_size) // 8bpp needs to be implemented
459   {
460      case PIXEL_SIZE_16BIT:
461         if(flip)
462         {
463            render_spans_16_ns_nt_z_f(yh>>2, yl>>2, &tile[0]); break;
464         }
465         else
466         {
467            render_spans_16_ns_nt_z_nf(yh>>2, yl>>2, &tile[0]); break;
468         }
469      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 0, 0, 1, flip); break;
470      default: break; // V-Rally2 does this, fb_size=0
471   }
472}
473#undef addvalues
474#undef adjust_attr
475
476static void triangle_ns_t_nz(UINT32 w1, UINT32 w2)
477{
478   int j;
479   int xleft, xright, xleft_inc, xright_inc;
480   int xstart, xend;
481   int s = 0, t = 0, w = 0;
482   int dsdx = 0, dtdx = 0, dwdx = 0;
483   int dsdy = 0, dtdy = 0, dwdy = 0;
484   int dsde = 0, dtde = 0, dwde = 0;
485   int tilenum;
486   int flip = (w1 & 0x800000) ? 1 : 0;
487   int sign = (w1 & 0x800000) ? -1 : 1;
488   int inv_sign = (w1 & 0x800000) ?  1 : -1;
489
490   INT32 yl, ym, yh;
491   INT32 xl, xm, xh;
492   INT32 dxldy, dxhdy, dxmdy;
493   UINT32 w3, w4, w5, w6, w7, w8;
494
495   int k = 0;
496
497   INT32 limcvg = 0;
498   INT32 startcvg = 0;
499
500   int sign_dxldy = 0;
501   int sign_dxmdy = 0;
502   int samesign = 0;
503
504   int dsdiff = 0, dtdiff = 0, dwdiff = 0;
505   int sign_dxhdy = 0;
506
507   int dsdeh = 0, dtdeh = 0, dwdeh = 0, dsdyh = 0, dtdyh = 0, dwdyh = 0;
508   int do_offset = 0;
509
510   int xfrac = 0;
511   int dseoff = 0, dteoff = 0, dweoff = 0;
512
513   int dsdxh = 0, dtdxh = 0, dwdxh = 0;
514
515   UINT32 min=0, max=3;
516   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
517
518   int spix = 0; // Current subpixel
519   int ycur;
520   int ylfar;
521   int ldflag;
522   int yhpix;
523   int ympix;
524   int ylpix;
525
526   int texture_base = rdp_cmd_cur + 8;
527
528   w3 = rdp_cmd_data[rdp_cmd_cur+2];
529   w4 = rdp_cmd_data[rdp_cmd_cur+3];
530   w5 = rdp_cmd_data[rdp_cmd_cur+4];
531   w6 = rdp_cmd_data[rdp_cmd_cur+5];
532   w7 = rdp_cmd_data[rdp_cmd_cur+6];
533   w8 = rdp_cmd_data[rdp_cmd_cur+7];
534
535   yl = (w1 & 0x3fff);
536   ym = ((w2 >> 16) & 0x3fff);
537   yh = ((w2 >>  0) & 0x3fff);
538   xl = (INT32)(w3 & 0x3fffffff);
539   xh = (INT32)(w5 & 0x3fffffff);
540   xm = (INT32)(w7 & 0x3fffffff);
541   // Inverse slopes in 16.16 format
542   dxldy = (INT32)(w4);
543   dxhdy = (INT32)(w6);
544   dxmdy = (INT32)(w8);
545
546   max_level = ((w1 >> 19) & 7);
547   tilenum = (w1 >> 16) & 0x7;
548
549   if (yl & 0x2000)  yl |= 0xffffc000;
550   if (ym & 0x2000)  ym |= 0xffffc000;
551   if (yh & 0x2000)  yh |= 0xffffc000;
552
553   if (xl & 0x20000000)  xl |= 0xc0000000;
554   if (xm & 0x20000000)  xm |= 0xc0000000;
555   if (xh & 0x20000000)  xh |= 0xc0000000;
556
557   s = 0;   t = 0;   w = 0;
558
559   s    = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
560   t    = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff);
561   w    = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
562   dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
563   dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff);
564   dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
565   dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
566   dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+12] & 0x0000ffff);
567   dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
568   dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
569   dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+14] & 0x0000ffff);
570   dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
571
572   span[0].ds.w = dsdx;
573   span[0].dt.w = dtdx;
574   span[0].dw.w = dwdx;
575
576   xleft_inc = dxmdy >> 2;
577   xright_inc = dxhdy >> 2;
578
579   xright = xh;
580   xleft = xm;
581
582   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
583   if (limcvg < 0)
584   {
585      limcvg = 0;
586   }
587
588   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
589   for (k = startcvg; k <= limcvg; k++)
590   {
591      memset((void*)&span[k].cvg[0],0,640);
592   }
593
594   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
595   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
596   samesign = !(sign_dxldy ^ sign_dxmdy);
597
598   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
599
600   do_offset = !(sign_dxhdy ^ (flip));
601
602   if (do_offset)
603   {
604      dsdeh = dsde >> 9;   dsdyh = dsdy >> 9;
605      dtdeh = dtde >> 9;   dtdyh = dtdy >> 9;
606      dwdeh = dwde >> 9;   dwdyh = dwdy >> 9;
607
608      dsdiff = (dsdeh*3 - dsdyh*3) << 7;
609      dtdiff = (dtdeh*3 - dtdyh*3) << 7;
610      dwdiff = (dwdeh*3 - dwdyh*3) << 7;
611   }
612   else
613   {
614      dsdiff = dtdiff = dwdiff = 0;
615   }
616
617   if (do_offset)
618   {
619      dseoff = (dsdeh*3) << 7;
620      dteoff = (dtdeh*3) << 7;
621      dweoff = (dwdeh*3) << 7;
622   }
623   else
624   {
625      dseoff = dteoff = dweoff;
626   }
627
628   dsdxh = dsdx >> 8;
629   dtdxh = dtdx >> 8;
630   dwdxh = dwdx >> 8;
631
632#define adjust_attr()      \
633{                     \
634         span[j].s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;            \
635         span[j].t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;            \
636         span[j].w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;            \
637}
638
639#define addvalues() {   \
640         s += dsde;   \
641         t += dtde;   \
642         w += dwde; \
643}
644
645   ycur =   yh & ~3;
646   ylfar = yl | 3;
647   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
648   yhpix = yh >> 2;
649   ympix = ym >> 2;
650   ylpix = yl >> 2;
651
652   if(ylfar >= 0x1000)
653   {
654      ylfar = 0x0fff;
655   }
656
657   for (k = ycur; k <= ylfar; k++)
658   {
659      if (k == ym)
660      {
661         xleft = xl;
662         xleft_inc = dxldy >> 2;
663      }
664
665      xstart = xleft >> 16;
666      xend = xright >> 16;
667      j = k >> 2;
668      spix = k & 3;
669
670      //if (k >= 0 && k < 0x1000)
671      {
672         int m = 0;
673         int n = 0;
674         min = 0; max = 3;
675         if (j == yhpix)
676         {
677            min = yh & 3;
678         }
679         if (j == ylpix)
680         {
681            max = yl & 3;
682         }
683         if (spix >= min && spix <= max)
684         {
685            if (spix == min)
686            {
687               minxmx = maxxmx = xstart;
688               minxhx = maxxhx = xend;
689            }
690            else
691            {
692               minxmx = (xstart < minxmx) ? xstart : minxmx;
693               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
694               minxhx = (xend < minxhx) ? xend : minxhx;
695               maxxhx = (xend > maxxhx) ? xend : maxxhx;
696            }
697         }
698
699         if (spix == max)
700         {
701            if (flip)
702            {
703               span[j].lx = maxxmx;
704               span[j].rx = minxhx;
705            }
706            else
707            {
708               span[j].lx = minxmx;
709               span[j].rx = maxxhx;
710            }
711         }
712
713         int length = (xend - xstart) * sign;
714
715         if (spix == ldflag)
716         {
717            xfrac = ((xright >> 8) & 0xff);
718            adjust_attr();
719         }
720
721         m = flip ? (xend+1) : (xend-1);
722
723         if (k >= yh && length >= 0 && k <= yl)
724         {
725            if (xstart>=0 && xstart <1024)
726            {
727               if (!flip)
728               {
729                  span[j].cvg[xstart] += addleft(xleft);
730               }
731               else
732               {
733                  span[j].cvg[xstart] += addright(xleft);
734               }
735            }
736            if (xend>=0 && xend<1024)
737            {
738               if (xstart != xend)
739               {
740                  if (!flip)
741                  {
742                     span[j].cvg[xend] += addright(xright);
743                  }
744                  else
745                  {
746                     span[j].cvg[xend] += addleft(xright);
747                  }
748               }
749               else
750               {
751                  if (!flip)
752                  {
753                     span[j].cvg[xend] -= (2 - addright(xright));
754                  }
755                  else
756                  {
757                     span[j].cvg[xend] -= (2 - addleft(xright));
758                  }
759                  if (span[j].cvg[xend] > 200)
760                  {
761                     span[j].cvg[xend] = 0;
762                  }
763               }
764            }
765            for (n = 0; n < (length - 1); n++)
766            {
767               if (m>=0 && m < 640)
768               {
769                  span[j].cvg[m] += 2;
770               }
771
772               m += inv_sign;
773            }
774         }
775      }
776
777      if (spix == 3)
778      {
779         addvalues();
780      }
781      xleft += xleft_inc;
782      xright += xright_inc;
783   }
784
785   switch (fb_size) // 8bpp needs to be implemented
786   {
787      case PIXEL_SIZE_16BIT:
788         if(flip)
789         {
790            render_spans_16_ns_t_nz_f(yh>>2, yl>>2, &tile[0]); break;
791         }
792         else
793         {
794            render_spans_16_ns_t_nz_nf(yh>>2, yl>>2, &tile[0]); break;
795         }
796      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 0, 1, 0, flip); break;
797      default: break; // V-Rally2 does this, fb_size=0
798   }
799}
800#undef addvalues
801#undef adjust_attr
802
803static void triangle_ns_t_z(UINT32 w1, UINT32 w2)
804{
805   int j;
806   int xleft, xright, xleft_inc, xright_inc;
807   int xstart, xend;
808   int z = 0, s = 0, t = 0, w = 0;
809   int dzdx = 0, dsdx = 0, dtdx = 0, dwdx = 0;
810   int dzdy = 0, dsdy = 0, dtdy = 0, dwdy = 0;
811   int dzde = 0, dsde = 0, dtde = 0, dwde = 0;
812   int tilenum;
813   int flip = (w1 & 0x800000) ? 1 : 0;
814   int sign = (w1 & 0x800000) ? -1 : 1;
815   int inv_sign = (w1 & 0x800000) ?  1 : -1;
816
817   INT32 yl, ym, yh;
818   INT32 xl, xm, xh;
819   INT32 dxldy, dxhdy, dxmdy;
820   int dzdy_dz, dzdx_dz;
821   int dsdylod, dtdylod;
822   UINT32 w3, w4, w5, w6, w7, w8;
823
824   int k = 0;
825
826   INT32 limcvg = 0;
827   INT32 startcvg = 0;
828
829   int sign_dxldy = 0;
830   int sign_dxmdy = 0;
831   int samesign = 0;
832
833   int dsdiff = 0, dtdiff = 0, dwdiff = 0, dzdiff = 0;
834   int sign_dxhdy = 0;
835
836   int dsdeh = 0, dtdeh = 0, dwdeh = 0, dzdeh = 0, dsdyh = 0, dtdyh = 0, dwdyh = 0, dzdyh = 0;
837   int do_offset = 0;
838
839   int xfrac = 0;
840   int dseoff = 0, dteoff = 0, dweoff = 0, dzeoff = 0;
841
842   int dsdxh = 0, dtdxh = 0, dwdxh = 0, dzdxh = 0;
843
844   UINT32 min=0, max=3;
845   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
846
847   int spix = 0; // Current subpixel
848   int ycur;
849   int ylfar;
850   int ldflag;
851   int yhpix;
852   int ympix;
853   int ylpix;
854
855   int texture_base = rdp_cmd_cur + 8;
856   int zbuffer_base = rdp_cmd_cur + 8;
857
858   zbuffer_base += 16;
859
860   w3 = rdp_cmd_data[rdp_cmd_cur+2];
861   w4 = rdp_cmd_data[rdp_cmd_cur+3];
862   w5 = rdp_cmd_data[rdp_cmd_cur+4];
863   w6 = rdp_cmd_data[rdp_cmd_cur+5];
864   w7 = rdp_cmd_data[rdp_cmd_cur+6];
865   w8 = rdp_cmd_data[rdp_cmd_cur+7];
866
867   yl = (w1 & 0x3fff);
868   ym = ((w2 >> 16) & 0x3fff);
869   yh = ((w2 >>  0) & 0x3fff);
870   xl = (INT32)(w3 & 0x3fffffff);
871   xh = (INT32)(w5 & 0x3fffffff);
872   xm = (INT32)(w7 & 0x3fffffff);
873   // Inverse slopes in 16.16 format
874   dxldy = (INT32)(w4);
875   dxhdy = (INT32)(w6);
876   dxmdy = (INT32)(w8);
877
878   max_level = ((w1 >> 19) & 7);
879   tilenum = (w1 >> 16) & 0x7;
880
881   if (yl & 0x2000)  yl |= 0xffffc000;
882   if (ym & 0x2000)  ym |= 0xffffc000;
883   if (yh & 0x2000)  yh |= 0xffffc000;
884
885   if (xl & 0x20000000)  xl |= 0xc0000000;
886   if (xm & 0x20000000)  xm |= 0xc0000000;
887   if (xh & 0x20000000)  xh |= 0xc0000000;
888
889   z = 0;
890   s = 0;   t = 0;   w = 0;
891
892   s    = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
893   t    = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff);
894   w    = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
895   dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
896   dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff);
897   dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
898   dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
899   dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+12] & 0x0000ffff);
900   dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
901   dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
902   dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+14] & 0x0000ffff);
903   dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
904   z    = rdp_cmd_data[zbuffer_base+0];
905   dzdx = rdp_cmd_data[zbuffer_base+1];
906   dzde = rdp_cmd_data[zbuffer_base+2];
907   dzdy = rdp_cmd_data[zbuffer_base+3];
908
909   span[0].ds.w = dsdx;
910   span[0].dt.w = dtdx;
911   span[0].dw.w = dwdx;
912   span[0].dz.w = dzdx;
913   dzdy_dz = (dzdy >> 16) & 0xffff;
914   dzdx_dz = (dzdx >> 16) & 0xffff;
915   span[0].dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
916   span[0].dzpix = normalize_dzpix(span[0].dzpix);
917   dsdylod = dsdy >> 16;
918   dtdylod = dtdy >> 16;
919   if (dsdylod & 0x20000)
920   {
921      dsdylod = ~dsdylod & 0x1ffff;
922   }
923   if (dtdylod & 0x20000)
924   {
925      dtdylod = ~dtdylod & 0x1ffff;
926   }
927   span[0].dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
928
929   xleft_inc = dxmdy >> 2;
930   xright_inc = dxhdy >> 2;
931
932   xright = xh;
933   xleft = xm;
934
935   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
936   if (limcvg < 0)
937   {
938      limcvg = 0;
939   }
940
941   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
942   for (k = startcvg; k <= limcvg; k++)
943   {
944      memset((void*)&span[k].cvg[0],0,640);
945   }
946
947   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
948   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
949   samesign = !(sign_dxldy ^ sign_dxmdy);
950
951   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
952
953   do_offset = !(sign_dxhdy ^ (flip));
954
955   if (do_offset)
956   {
957      dsdeh = dsde >> 9;   dsdyh = dsdy >> 9;
958      dtdeh = dtde >> 9;   dtdyh = dtdy >> 9;
959      dwdeh = dwde >> 9;   dwdyh = dwdy >> 9;
960      dzdeh = dzde >> 9;   dzdyh = dzdy >> 9;
961
962      dsdiff = (dsdeh*3 - dsdyh*3) << 7;
963      dtdiff = (dtdeh*3 - dtdyh*3) << 7;
964      dwdiff = (dwdeh*3 - dwdyh*3) << 7;
965      dzdiff = (dzdeh*3 - dzdyh*3) << 7;
966   }
967   else
968   {
969      dsdiff = dtdiff = dwdiff = dzdiff = 0;
970   }
971
972   if (do_offset)
973   {
974      dseoff = (dsdeh*3) << 7;
975      dteoff = (dtdeh*3) << 7;
976      dweoff = (dwdeh*3) << 7;
977      dzeoff = (dzdeh*3) << 7;
978   }
979   else
980   {
981      dseoff = dteoff = dweoff = dzeoff = 0;
982   }
983
984   dsdxh = dsdx >> 8;
985   dtdxh = dtdx >> 8;
986   dwdxh = dwdx >> 8;
987   dzdxh = dzdx >> 8;
988
989#define adjust_attr()      \
990{                     \
991         span[j].s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;            \
992         span[j].t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;            \
993         span[j].w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;            \
994         span[j].z.w = z + dzdiff - (xfrac * dzdxh);            \
995}
996
997#define addvalues() {   \
998         s += dsde;   \
999         t += dtde;   \
1000         w += dwde; \
1001         z += dzde; \
1002}
1003
1004   ycur =   yh & ~3;
1005   ylfar = yl | 3;
1006   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
1007   yhpix = yh >> 2;
1008   ympix = ym >> 2;
1009   ylpix = yl >> 2;
1010
1011   if(ylfar >= 0x1000)
1012   {
1013      ylfar = 0x0fff;
1014   }
1015
1016   for (k = ycur; k <= ylfar; k++)
1017   {
1018      if (k == ym)
1019      {
1020         xleft = xl;
1021         xleft_inc = dxldy >> 2;
1022      }
1023
1024      xstart = xleft >> 16;
1025      xend = xright >> 16;
1026      j = k >> 2;
1027      spix = k & 3;
1028
1029      //if (k >= 0 && k < 0x1000)
1030      {
1031         int m = 0;
1032         int n = 0;
1033         min = 0; max = 3;
1034         if (j == yhpix)
1035         {
1036            min = yh & 3;
1037         }
1038         if (j == ylpix)
1039         {
1040            max = yl & 3;
1041         }
1042         if (spix >= min && spix <= max)
1043         {
1044            if (spix == min)
1045            {
1046               minxmx = maxxmx = xstart;
1047               minxhx = maxxhx = xend;
1048            }
1049            else
1050            {
1051               minxmx = (xstart < minxmx) ? xstart : minxmx;
1052               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
1053               minxhx = (xend < minxhx) ? xend : minxhx;
1054               maxxhx = (xend > maxxhx) ? xend : maxxhx;
1055            }
1056         }
1057
1058         if (spix == max)
1059         {
1060            if (flip)
1061            {
1062               span[j].lx = maxxmx;
1063               span[j].rx = minxhx;
1064            }
1065            else
1066            {
1067               span[j].lx = minxmx;
1068               span[j].rx = maxxhx;
1069            }
1070         }
1071
1072         int length = (xend - xstart) * sign;
1073
1074         if (spix == ldflag)
1075         {
1076            xfrac = ((xright >> 8) & 0xff);
1077            adjust_attr();
1078         }
1079
1080         m = flip ? (xend+1) : (xend-1);
1081
1082         if (k >= yh && length >= 0 && k <= yl)
1083         {
1084            if (xstart>=0 && xstart <1024)
1085            {
1086               if (!flip)
1087               {
1088                  span[j].cvg[xstart] += addleft(xleft);
1089               }
1090               else
1091               {
1092                  span[j].cvg[xstart] += addright(xleft);
1093               }
1094            }
1095            if (xend>=0 && xend<1024)
1096            {
1097               if (xstart != xend)
1098               {
1099                  if (!flip)
1100                  {
1101                     span[j].cvg[xend] += addright(xright);
1102                  }
1103                  else
1104                  {
1105                     span[j].cvg[xend] += addleft(xright);
1106                  }
1107               }
1108               else
1109               {
1110                  if (!flip)
1111                  {
1112                     span[j].cvg[xend] -= (2 - addright(xright));
1113                  }
1114                  else
1115                  {
1116                     span[j].cvg[xend] -= (2 - addleft(xright));
1117                  }
1118                  if (span[j].cvg[xend] > 200)
1119                  {
1120                     span[j].cvg[xend] = 0;
1121                  }
1122               }
1123            }
1124            for (n = 0; n < (length - 1); n++)
1125            {
1126               if (m>=0 && m < 640)
1127               {
1128                  span[j].cvg[m] += 2;
1129               }
1130
1131               m += inv_sign;
1132            }
1133         }
1134      }
1135
1136      if (spix == 3)
1137      {
1138         addvalues();
1139      }
1140      xleft += xleft_inc;
1141      xright += xright_inc;
1142   }
1143
1144   switch (fb_size) // 8bpp needs to be implemented
1145   {
1146      case PIXEL_SIZE_16BIT:
1147         if(flip)
1148         {
1149            render_spans_16_ns_t_z_f(yh>>2, yl>>2, &tile[0]); break;
1150         }
1151         else
1152         {
1153            render_spans_16_ns_t_z_nf(yh>>2, yl>>2, &tile[0]); break;
1154         }
1155      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 0, 1, 1, flip); break;
1156      default: break; // V-Rally2 does this, fb_size=0
1157   }
1158}
1159#undef addvalues
1160#undef adjust_attr
1161
1162static void triangle_s_nt_nz(UINT32 w1, UINT32 w2)
1163{
1164   int j;
1165   int xleft, xright, xleft_inc, xright_inc;
1166   int xstart, xend;
1167   int r = 0, g = 0, b = 0, a = 0;
1168   int dr, dg, db, da;
1169   int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0;
1170   int drdy = 0, dgdy = 0, dbdy = 0, dady = 0;
1171   int drde = 0, dgde = 0, dbde = 0, dade = 0;
1172   int tilenum;
1173   int flip = (w1 & 0x800000) ? 1 : 0;
1174   int sign = (w1 & 0x800000) ? -1 : 1;
1175   int inv_sign = (w1 & 0x800000) ?  1 : -1;
1176
1177   INT32 yl, ym, yh;
1178   INT32 xl, xm, xh;
1179   INT32 dxldy, dxhdy, dxmdy;
1180   UINT32 w3, w4, w5, w6, w7, w8;
1181
1182   int k = 0;
1183
1184   INT32 limcvg = 0;
1185   INT32 startcvg = 0;
1186
1187   int sign_dxldy = 0;
1188   int sign_dxmdy = 0;
1189   int samesign = 0;
1190
1191   int drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0;
1192   int sign_dxhdy = 0;
1193
1194   int drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0;
1195   int do_offset = 0;
1196
1197   int xfrac = 0;
1198   int dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0;
1199
1200   int drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0;
1201
1202   UINT32 min=0, max=3;
1203   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
1204
1205   int spix = 0; // Current subpixel
1206   int ycur;
1207   int ylfar;
1208   int ldflag;
1209   int yhpix;
1210   int ympix;
1211   int ylpix;
1212
1213   int shade_base = rdp_cmd_cur + 8;
1214
1215   w3 = rdp_cmd_data[rdp_cmd_cur+2];
1216   w4 = rdp_cmd_data[rdp_cmd_cur+3];
1217   w5 = rdp_cmd_data[rdp_cmd_cur+4];
1218   w6 = rdp_cmd_data[rdp_cmd_cur+5];
1219   w7 = rdp_cmd_data[rdp_cmd_cur+6];
1220   w8 = rdp_cmd_data[rdp_cmd_cur+7];
1221
1222   yl = (w1 & 0x3fff);
1223   ym = ((w2 >> 16) & 0x3fff);
1224   yh = ((w2 >>  0) & 0x3fff);
1225   xl = (INT32)(w3 & 0x3fffffff);
1226   xh = (INT32)(w5 & 0x3fffffff);
1227   xm = (INT32)(w7 & 0x3fffffff);
1228   // Inverse slopes in 16.16 format
1229   dxldy = (INT32)(w4);
1230   dxhdy = (INT32)(w6);
1231   dxmdy = (INT32)(w8);
1232
1233   max_level = ((w1 >> 19) & 7);
1234   tilenum = (w1 >> 16) & 0x7;
1235
1236   if (yl & 0x2000)  yl |= 0xffffc000;
1237   if (ym & 0x2000)  ym |= 0xffffc000;
1238   if (yh & 0x2000)  yh |= 0xffffc000;
1239
1240   if (xl & 0x20000000)  xl |= 0xc0000000;
1241   if (xm & 0x20000000)  xm |= 0xc0000000;
1242   if (xh & 0x20000000)  xh |= 0xc0000000;
1243
1244   dr = 0;      dg = 0;      db = 0;      da = 0;
1245
1246   r    = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
1247   g    = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff);
1248   b    = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
1249   a    = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff);
1250   drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
1251   dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff);
1252   dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
1253   dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff);
1254   drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
1255   dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff);
1256   dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
1257   dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff);
1258   drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
1259   dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff);
1260   dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
1261   dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff);
1262
1263   span[0].dr.w = drdx & ~0x1f;
1264   span[0].dg.w = dgdx & ~0x1f;
1265   span[0].db.w = dbdx & ~0x1f;
1266   span[0].da.w = dadx & ~0x1f;
1267
1268   xleft_inc = dxmdy >> 2;
1269   xright_inc = dxhdy >> 2;
1270
1271   xright = xh;
1272   xleft = xm;
1273
1274   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
1275   if (limcvg < 0)
1276   {
1277      limcvg = 0;
1278   }
1279
1280   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
1281   for (k = startcvg; k <= limcvg; k++)
1282   {
1283      memset((void*)&span[k].cvg[0],0,640);
1284   }
1285
1286   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
1287   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
1288   samesign = !(sign_dxldy ^ sign_dxmdy);
1289
1290   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
1291
1292   do_offset = !(sign_dxhdy ^ (flip));
1293
1294   if (do_offset)
1295   {
1296      drdeh = drde >> 9;   drdyh = drdy >> 9;
1297      dgdeh = dgde >> 9;   dgdyh = dgdy >> 9;
1298      dbdeh = dbde >> 9;   dbdyh = dbdy >> 9;
1299      dadeh = dade >> 9;   dadyh = dady >> 9;
1300
1301      drdiff = (drdeh*3 - drdyh*3) << 7;
1302      dgdiff = (dgdeh*3 - dgdyh*3) << 7;
1303      dbdiff = (dbdeh*3 - dbdyh*3) << 7;
1304      dadiff = (dadeh*3 - dadyh*3) << 7;
1305   }
1306   else
1307   {
1308      drdiff = dgdiff = dbdiff = dadiff;
1309   }
1310
1311   if (do_offset)
1312   {
1313      dreoff = (drdeh*3) << 7;
1314      dgeoff = (dgdeh*3) << 7;
1315      dbeoff = (dbdeh*3) << 7;
1316      daeoff = (dadeh*3) << 7;
1317   }
1318   else
1319   {
1320      dreoff = dgeoff = dbeoff = daeoff;
1321   }
1322
1323   drdxh = drdx >> 8;
1324   dgdxh = dgdx >> 8;
1325   dbdxh = dbdx >> 8;
1326   dadxh = dadx >> 8;
1327
1328#define adjust_attr()      \
1329{                     \
1330         span[j].r.w = r + drdiff - (xfrac * drdxh);            \
1331         span[j].g.w = g + dgdiff - (xfrac * dgdxh);            \
1332         span[j].b.w = b + dbdiff - (xfrac * dbdxh);            \
1333         span[j].a.w = a + dadiff - (xfrac * dadxh);            \
1334}
1335
1336#define addvalues() {   \
1337         r += drde; \
1338         g += dgde; \
1339         b += dbde; \
1340         a += dade; \
1341}
1342
1343   ycur =   yh & ~3;
1344   ylfar = yl | 3;
1345   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
1346   yhpix = yh >> 2;
1347   ympix = ym >> 2;
1348   ylpix = yl >> 2;
1349
1350   if(ylfar >= 0x1000)
1351   {
1352      ylfar = 0x0fff;
1353   }
1354
1355   for (k = ycur; k <= ylfar; k++)
1356   {
1357      if (k == ym)
1358      {
1359         xleft = xl;
1360         xleft_inc = dxldy >> 2;
1361      }
1362
1363      xstart = xleft >> 16;
1364      xend = xright >> 16;
1365      j = k >> 2;
1366      spix = k & 3;
1367
1368      //if (k >= 0 && k < 0x1000)
1369      {
1370         int m = 0;
1371         int n = 0;
1372         min = 0; max = 3;
1373         if (j == yhpix)
1374         {
1375            min = yh & 3;
1376         }
1377         if (j == ylpix)
1378         {
1379            max = yl & 3;
1380         }
1381         if (spix >= min && spix <= max)
1382         {
1383            if (spix == min)
1384            {
1385               minxmx = maxxmx = xstart;
1386               minxhx = maxxhx = xend;
1387            }
1388            else
1389            {
1390               minxmx = (xstart < minxmx) ? xstart : minxmx;
1391               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
1392               minxhx = (xend < minxhx) ? xend : minxhx;
1393               maxxhx = (xend > maxxhx) ? xend : maxxhx;
1394            }
1395         }
1396
1397         if (spix == max)
1398         {
1399            if (flip)
1400            {
1401               span[j].lx = maxxmx;
1402               span[j].rx = minxhx;
1403            }
1404            else
1405            {
1406               span[j].lx = minxmx;
1407               span[j].rx = maxxhx;
1408            }
1409         }
1410
1411         int length = (xend - xstart) * sign;
1412
1413         if (spix == ldflag)
1414         {
1415            xfrac = ((xright >> 8) & 0xff);
1416            adjust_attr();
1417         }
1418
1419         m = flip ? (xend+1) : (xend-1);
1420
1421         if (k >= yh && length >= 0 && k <= yl)
1422         {
1423            if (xstart>=0 && xstart <1024)
1424            {
1425               if (!flip)
1426               {
1427                  span[j].cvg[xstart] += addleft(xleft);
1428               }
1429               else
1430               {
1431                  span[j].cvg[xstart] += addright(xleft);
1432               }
1433            }
1434            if (xend>=0 && xend<1024)
1435            {
1436               if (xstart != xend)
1437               {
1438                  if (!flip)
1439                  {
1440                     span[j].cvg[xend] += addright(xright);
1441                  }
1442                  else
1443                  {
1444                     span[j].cvg[xend] += addleft(xright);
1445                  }
1446               }
1447               else
1448               {
1449                  if (!flip)
1450                  {
1451                     span[j].cvg[xend] -= (2 - addright(xright));
1452                  }
1453                  else
1454                  {
1455                     span[j].cvg[xend] -= (2 - addleft(xright));
1456                  }
1457                  if (span[j].cvg[xend] > 200)
1458                  {
1459                     span[j].cvg[xend] = 0;
1460                  }
1461               }
1462            }
1463            for (n = 0; n < (length - 1); n++)
1464            {
1465               if (m>=0 && m < 640)
1466               {
1467                  span[j].cvg[m] += 2;
1468               }
1469
1470               m += inv_sign;
1471            }
1472         }
1473      }
1474
1475      if (spix == 3)
1476      {
1477         addvalues();
1478      }
1479      xleft += xleft_inc;
1480      xright += xright_inc;
1481   }
1482
1483   switch (fb_size) // 8bpp needs to be implemented
1484   {
1485      case PIXEL_SIZE_16BIT:
1486         if(flip)
1487         {
1488            render_spans_16_s_nt_nz_f(yh>>2, yl>>2, &tile[0]); break;
1489         }
1490         else
1491         {
1492            render_spans_16_s_nt_nz_nf(yh>>2, yl>>2, &tile[0]); break;
1493         }
1494      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 1, 0, 0, flip); break;
1495      default: break; // V-Rally2 does this, fb_size=0
1496   }
1497}
1498#undef addvalues
1499#undef adjust_attr
1500
1501static void triangle_s_nt_z(UINT32 w1, UINT32 w2)
1502{
1503   int j;
1504   int xleft, xright, xleft_inc, xright_inc;
1505   int xstart, xend;
1506   int r = 0, g = 0, b = 0, a = 0, z = 0;
1507   int dr, dg, db, da;
1508   int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0, dzdx = 0;
1509   int drdy = 0, dgdy = 0, dbdy = 0, dady = 0, dzdy = 0;
1510   int drde = 0, dgde = 0, dbde = 0, dade = 0, dzde = 0;
1511   int tilenum;
1512   int flip = (w1 & 0x800000) ? 1 : 0;
1513   int sign = (w1 & 0x800000) ? -1 : 1;
1514   int inv_sign = (w1 & 0x800000) ?  1 : -1;
1515
1516   INT32 yl, ym, yh;
1517   INT32 xl, xm, xh;
1518   INT32 dxldy, dxhdy, dxmdy;
1519   int dzdy_dz, dzdx_dz;
1520   UINT32 w3, w4, w5, w6, w7, w8;
1521
1522   int k = 0;
1523
1524   INT32 limcvg = 0;
1525   INT32 startcvg = 0;
1526
1527   int sign_dxldy = 0;
1528   int sign_dxmdy = 0;
1529   int samesign = 0;
1530
1531   int drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0;
1532   int sign_dxhdy = 0;
1533
1534   int drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0;
1535   int do_offset = 0;
1536
1537   int xfrac = 0;
1538   int dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0, dzeoff = 0;
1539
1540   int drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0;
1541
1542   UINT32 min=0, max=3;
1543   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
1544
1545   int spix = 0; // Current subpixel
1546   int ycur;
1547   int ylfar;
1548   int ldflag;
1549   int yhpix;
1550   int ympix;
1551   int ylpix;
1552
1553   int shade_base = rdp_cmd_cur + 8;
1554   int zbuffer_base = rdp_cmd_cur + 8;
1555
1556   zbuffer_base += 16;
1557
1558   w3 = rdp_cmd_data[rdp_cmd_cur+2];
1559   w4 = rdp_cmd_data[rdp_cmd_cur+3];
1560   w5 = rdp_cmd_data[rdp_cmd_cur+4];
1561   w6 = rdp_cmd_data[rdp_cmd_cur+5];
1562   w7 = rdp_cmd_data[rdp_cmd_cur+6];
1563   w8 = rdp_cmd_data[rdp_cmd_cur+7];
1564
1565   yl = (w1 & 0x3fff);
1566   ym = ((w2 >> 16) & 0x3fff);
1567   yh = ((w2 >>  0) & 0x3fff);
1568   xl = (INT32)(w3 & 0x3fffffff);
1569   xh = (INT32)(w5 & 0x3fffffff);
1570   xm = (INT32)(w7 & 0x3fffffff);
1571   // Inverse slopes in 16.16 format
1572   dxldy = (INT32)(w4);
1573   dxhdy = (INT32)(w6);
1574   dxmdy = (INT32)(w8);
1575
1576   max_level = ((w1 >> 19) & 7);
1577   tilenum = (w1 >> 16) & 0x7;
1578
1579   if (yl & 0x2000)  yl |= 0xffffc000;
1580   if (ym & 0x2000)  ym |= 0xffffc000;
1581   if (yh & 0x2000)  yh |= 0xffffc000;
1582
1583   if (xl & 0x20000000)  xl |= 0xc0000000;
1584   if (xm & 0x20000000)  xm |= 0xc0000000;
1585   if (xh & 0x20000000)  xh |= 0xc0000000;
1586
1587   z = 0;
1588   dr = 0;      dg = 0;      db = 0;      da = 0;
1589
1590   r    = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
1591   g    = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff);
1592   b    = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
1593   a    = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff);
1594   drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
1595   dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff);
1596   dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
1597   dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff);
1598   drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
1599   dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff);
1600   dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
1601   dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff);
1602   drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
1603   dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff);
1604   dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
1605   dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff);
1606   z    = rdp_cmd_data[zbuffer_base+0];
1607   dzdx = rdp_cmd_data[zbuffer_base+1];
1608   dzde = rdp_cmd_data[zbuffer_base+2];
1609   dzdy = rdp_cmd_data[zbuffer_base+3];
1610
1611   span[0].dr.w = drdx & ~0x1f;
1612   span[0].dg.w = dgdx & ~0x1f;
1613   span[0].db.w = dbdx & ~0x1f;
1614   span[0].da.w = dadx & ~0x1f;
1615   span[0].dz.w = dzdx;
1616   dzdy_dz = (dzdy >> 16) & 0xffff;
1617   dzdx_dz = (dzdx >> 16) & 0xffff;
1618   span[0].dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
1619   span[0].dzpix = normalize_dzpix(span[0].dzpix);
1620
1621   xleft_inc = dxmdy >> 2;
1622   xright_inc = dxhdy >> 2;
1623
1624   xright = xh;
1625   xleft = xm;
1626
1627   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
1628   if (limcvg < 0)
1629   {
1630      limcvg = 0;
1631   }
1632
1633   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
1634   for (k = startcvg; k <= limcvg; k++)
1635   {
1636      memset((void*)&span[k].cvg[0],0,640);
1637   }
1638
1639   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
1640   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
1641   samesign = !(sign_dxldy ^ sign_dxmdy);
1642
1643   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
1644
1645   do_offset = !(sign_dxhdy ^ (flip));
1646
1647   if (do_offset)
1648   {
1649      drdeh = drde >> 9;   drdyh = drdy >> 9;
1650      dgdeh = dgde >> 9;   dgdyh = dgdy >> 9;
1651      dbdeh = dbde >> 9;   dbdyh = dbdy >> 9;
1652      dadeh = dade >> 9;   dadyh = dady >> 9;
1653      dzdeh = dzde >> 9;   dzdyh = dzdy >> 9;
1654
1655      drdiff = (drdeh*3 - drdyh*3) << 7;
1656      dgdiff = (dgdeh*3 - dgdyh*3) << 7;
1657      dbdiff = (dbdeh*3 - dbdyh*3) << 7;
1658      dadiff = (dadeh*3 - dadyh*3) << 7;
1659      dzdiff = (dzdeh*3 - dzdyh*3) << 7;
1660   }
1661   else
1662   {
1663      drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0;
1664   }
1665
1666   if (do_offset)
1667   {
1668      dreoff = (drdeh*3) << 7;
1669      dgeoff = (dgdeh*3) << 7;
1670      dbeoff = (dbdeh*3) << 7;
1671      daeoff = (dadeh*3) << 7;
1672      dzeoff = (dzdeh*3) << 7;
1673   }
1674   else
1675   {
1676      dreoff = dgeoff = dbeoff = daeoff = dzeoff = 0;
1677   }
1678
1679   drdxh = drdx >> 8;
1680   dgdxh = dgdx >> 8;
1681   dbdxh = dbdx >> 8;
1682   dadxh = dadx >> 8;
1683   dzdxh = dzdx >> 8;
1684
1685#define adjust_attr()      \
1686{                     \
1687         span[j].r.w = r + drdiff - (xfrac * drdxh);            \
1688         span[j].g.w = g + dgdiff - (xfrac * dgdxh);            \
1689         span[j].b.w = b + dbdiff - (xfrac * dbdxh);            \
1690         span[j].a.w = a + dadiff - (xfrac * dadxh);            \
1691         span[j].z.w = z + dzdiff - (xfrac * dzdxh);            \
1692}
1693
1694#define addvalues() {   \
1695         r += drde; \
1696         g += dgde; \
1697         b += dbde; \
1698         a += dade; \
1699         z += dzde; \
1700}
1701
1702   ycur =   yh & ~3;
1703   ylfar = yl | 3;
1704   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
1705   yhpix = yh >> 2;
1706   ympix = ym >> 2;
1707   ylpix = yl >> 2;
1708
1709   if(ylfar >= 0x1000)
1710   {
1711      ylfar = 0x0fff;
1712   }
1713
1714   for (k = ycur; k <= ylfar; k++)
1715   {
1716      if (k == ym)
1717      {
1718         xleft = xl;
1719         xleft_inc = dxldy >> 2;
1720      }
1721
1722      xstart = xleft >> 16;
1723      xend = xright >> 16;
1724      j = k >> 2;
1725      spix = k & 3;
1726
1727      //if (k >= 0 && k < 0x1000)
1728      {
1729         int m = 0;
1730         int n = 0;
1731         min = 0; max = 3;
1732         if (j == yhpix)
1733         {
1734            min = yh & 3;
1735         }
1736         if (j == ylpix)
1737         {
1738            max = yl & 3;
1739         }
1740         if (spix >= min && spix <= max)
1741         {
1742            if (spix == min)
1743            {
1744               minxmx = maxxmx = xstart;
1745               minxhx = maxxhx = xend;
1746            }
1747            else
1748            {
1749               minxmx = (xstart < minxmx) ? xstart : minxmx;
1750               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
1751               minxhx = (xend < minxhx) ? xend : minxhx;
1752               maxxhx = (xend > maxxhx) ? xend : maxxhx;
1753            }
1754         }
1755
1756         if (spix == max)
1757         {
1758            if (flip)
1759            {
1760               span[j].lx = maxxmx;
1761               span[j].rx = minxhx;
1762            }
1763            else
1764            {
1765               span[j].lx = minxmx;
1766               span[j].rx = maxxhx;
1767            }
1768         }
1769
1770         int length = (xend - xstart) * sign;
1771
1772         if (spix == ldflag)
1773         {
1774            xfrac = ((xright >> 8) & 0xff);
1775            adjust_attr();
1776         }
1777
1778         m = flip ? (xend+1) : (xend-1);
1779
1780         if (k >= yh && length >= 0 && k <= yl)
1781         {
1782            if (xstart>=0 && xstart <1024)
1783            {
1784               if (!flip)
1785               {
1786                  span[j].cvg[xstart] += addleft(xleft);
1787               }
1788               else
1789               {
1790                  span[j].cvg[xstart] += addright(xleft);
1791               }
1792            }
1793            if (xend>=0 && xend<1024)
1794            {
1795               if (xstart != xend)
1796               {
1797                  if (!flip)
1798                  {
1799                     span[j].cvg[xend] += addright(xright);
1800                  }
1801                  else
1802                  {
1803                     span[j].cvg[xend] += addleft(xright);
1804                  }
1805               }
1806               else
1807               {
1808                  if (!flip)
1809                  {
1810                     span[j].cvg[xend] -= (2 - addright(xright));
1811                  }
1812                  else
1813                  {
1814                     span[j].cvg[xend] -= (2 - addleft(xright));
1815                  }
1816                  if (span[j].cvg[xend] > 200)
1817                  {
1818                     span[j].cvg[xend] = 0;
1819                  }
1820               }
1821            }
1822            for (n = 0; n < (length - 1); n++)
1823            {
1824               if (m>=0 && m < 640)
1825               {
1826                  span[j].cvg[m] += 2;
1827               }
1828
1829               m += inv_sign;
1830            }
1831         }
1832      }
1833
1834      if (spix == 3)
1835      {
1836         addvalues();
1837      }
1838      xleft += xleft_inc;
1839      xright += xright_inc;
1840   }
1841
1842   switch (fb_size) // 8bpp needs to be implemented
1843   {
1844      case PIXEL_SIZE_16BIT:
1845         if(flip)
1846         {
1847            render_spans_16_s_nt_z_f(yh>>2, yl>>2, &tile[0]); break;
1848         }
1849         else
1850         {
1851            render_spans_16_s_nt_z_nf(yh>>2, yl>>2, &tile[0]); break;
1852         }
1853      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 1, 0, 1, flip); break;
1854      default: break; // V-Rally2 does this, fb_size=0
1855   }
1856}
1857#undef addvalues
1858#undef adjust_attr
1859
1860static void triangle_s_t_nz(UINT32 w1, UINT32 w2)
1861{
1862   int j;
1863   int xleft, xright, xleft_inc, xright_inc;
1864   int xstart, xend;
1865   int r = 0, g = 0, b = 0, a = 0, s = 0, t = 0, w = 0;
1866   int dr, dg, db, da;
1867   int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0, dsdx = 0, dtdx = 0, dwdx = 0;
1868   int drdy = 0, dgdy = 0, dbdy = 0, dady = 0, dsdy = 0, dtdy = 0, dwdy = 0;
1869   int drde = 0, dgde = 0, dbde = 0, dade = 0, dsde = 0, dtde = 0, dwde = 0;
1870   int tilenum;
1871   int flip = (w1 & 0x800000) ? 1 : 0;
1872   int sign = (w1 & 0x800000) ? -1 : 1;
1873   int inv_sign = (w1 & 0x800000) ?  1 : -1;
1874
1875   INT32 yl, ym, yh;
1876   INT32 xl, xm, xh;
1877   INT32 dxldy, dxhdy, dxmdy;
1878   int dsdylod, dtdylod;
1879   UINT32 w3, w4, w5, w6, w7, w8;
1880
1881   int k = 0;
1882
1883   INT32 limcvg = 0;
1884   INT32 startcvg = 0;
1885
1886   int sign_dxldy = 0;
1887   int sign_dxmdy = 0;
1888   int samesign = 0;
1889
1890   int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0;
1891   int sign_dxhdy = 0;
1892
1893   int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0;
1894   int do_offset = 0;
1895
1896   int xfrac = 0;
1897   int dseoff = 0, dteoff = 0, dweoff = 0, dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0;
1898
1899   int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0;
1900
1901   UINT32 min=0, max=3;
1902   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
1903
1904   int spix = 0; // Current subpixel
1905   int ycur;
1906   int ylfar;
1907   int ldflag;
1908   int yhpix;
1909   int ympix;
1910   int ylpix;
1911
1912   int shade_base = rdp_cmd_cur + 8;
1913   int texture_base = rdp_cmd_cur + 8;
1914
1915   texture_base += 16;
1916
1917   w3 = rdp_cmd_data[rdp_cmd_cur+2];
1918   w4 = rdp_cmd_data[rdp_cmd_cur+3];
1919   w5 = rdp_cmd_data[rdp_cmd_cur+4];
1920   w6 = rdp_cmd_data[rdp_cmd_cur+5];
1921   w7 = rdp_cmd_data[rdp_cmd_cur+6];
1922   w8 = rdp_cmd_data[rdp_cmd_cur+7];
1923
1924   yl = (w1 & 0x3fff);
1925   ym = ((w2 >> 16) & 0x3fff);
1926   yh = ((w2 >>  0) & 0x3fff);
1927   xl = (INT32)(w3 & 0x3fffffff);
1928   xh = (INT32)(w5 & 0x3fffffff);
1929   xm = (INT32)(w7 & 0x3fffffff);
1930   // Inverse slopes in 16.16 format
1931   dxldy = (INT32)(w4);
1932   dxhdy = (INT32)(w6);
1933   dxmdy = (INT32)(w8);
1934
1935   max_level = ((w1 >> 19) & 7);
1936   tilenum = (w1 >> 16) & 0x7;
1937
1938   if (yl & 0x2000)  yl |= 0xffffc000;
1939   if (ym & 0x2000)  ym |= 0xffffc000;
1940   if (yh & 0x2000)  yh |= 0xffffc000;
1941
1942   if (xl & 0x20000000)  xl |= 0xc0000000;
1943   if (xm & 0x20000000)  xm |= 0xc0000000;
1944   if (xh & 0x20000000)  xh |= 0xc0000000;
1945
1946   s = 0;   t = 0;   w = 0;
1947   dr = 0;      dg = 0;      db = 0;      da = 0;
1948
1949   r    = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
1950   g    = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff);
1951   b    = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
1952   a    = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff);
1953   drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
1954   dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff);
1955   dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
1956   dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff);
1957   drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
1958   dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff);
1959   dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
1960   dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff);
1961   drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
1962   dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff);
1963   dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
1964   dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff);
1965   s    = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
1966   t    = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff);
1967   w    = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
1968   dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
1969   dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff);
1970   dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
1971   dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
1972   dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+12] & 0x0000ffff);
1973   dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
1974   dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
1975   dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+14] & 0x0000ffff);
1976   dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
1977
1978   span[0].ds.w = dsdx;
1979   span[0].dt.w = dtdx;
1980   span[0].dw.w = dwdx;
1981   span[0].dr.w = drdx & ~0x1f;
1982   span[0].dg.w = dgdx & ~0x1f;
1983   span[0].db.w = dbdx & ~0x1f;
1984   span[0].da.w = dadx & ~0x1f;
1985   dsdylod = dsdy >> 16;
1986   dtdylod = dtdy >> 16;
1987   if (dsdylod & 0x20000)
1988   {
1989      dsdylod = ~dsdylod & 0x1ffff;
1990   }
1991   if (dtdylod & 0x20000)
1992   {
1993      dtdylod = ~dtdylod & 0x1ffff;
1994   }
1995   span[0].dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
1996
1997   xleft_inc = dxmdy >> 2;
1998   xright_inc = dxhdy >> 2;
1999
2000   xright = xh;
2001   xleft = xm;
2002
2003   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
2004   if (limcvg < 0)
2005   {
2006      limcvg = 0;
2007   }
2008
2009   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
2010   for (k = startcvg; k <= limcvg; k++)
2011   {
2012      memset((void*)&span[k].cvg[0],0,640);
2013   }
2014
2015   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
2016   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
2017   samesign = !(sign_dxldy ^ sign_dxmdy);
2018
2019   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
2020
2021   do_offset = !(sign_dxhdy ^ (flip));
2022
2023   if (do_offset)
2024   {
2025      dsdeh = dsde >> 9;   dsdyh = dsdy >> 9;
2026      dtdeh = dtde >> 9;   dtdyh = dtdy >> 9;
2027      dwdeh = dwde >> 9;   dwdyh = dwdy >> 9;
2028      drdeh = drde >> 9;   drdyh = drdy >> 9;
2029      dgdeh = dgde >> 9;   dgdyh = dgdy >> 9;
2030      dbdeh = dbde >> 9;   dbdyh = dbdy >> 9;
2031      dadeh = dade >> 9;   dadyh = dady >> 9;
2032
2033      dsdiff = (dsdeh*3 - dsdyh*3) << 7;
2034      dtdiff = (dtdeh*3 - dtdyh*3) << 7;
2035      dwdiff = (dwdeh*3 - dwdyh*3) << 7;
2036      drdiff = (drdeh*3 - drdyh*3) << 7;
2037      dgdiff = (dgdeh*3 - dgdyh*3) << 7;
2038      dbdiff = (dbdeh*3 - dbdyh*3) << 7;
2039      dadiff = (dadeh*3 - dadyh*3) << 7;
2040   }
2041   else
2042   {
2043      dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = 0;
2044   }
2045
2046   if (do_offset)
2047   {
2048      dseoff = (dsdeh*3) << 7;
2049      dteoff = (dtdeh*3) << 7;
2050      dweoff = (dwdeh*3) << 7;
2051      dreoff = (drdeh*3) << 7;
2052      dgeoff = (dgdeh*3) << 7;
2053      dbeoff = (dbdeh*3) << 7;
2054      daeoff = (dadeh*3) << 7;
2055   }
2056   else
2057   {
2058      dseoff = dteoff = dweoff = dreoff = dgeoff = dbeoff = daeoff = 0;
2059   }
2060
2061   dsdxh = dsdx >> 8;
2062   dtdxh = dtdx >> 8;
2063   dwdxh = dwdx >> 8;
2064   drdxh = drdx >> 8;
2065   dgdxh = dgdx >> 8;
2066   dbdxh = dbdx >> 8;
2067   dadxh = dadx >> 8;
2068
2069#define adjust_attr()      \
2070{                     \
2071         span[j].s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;            \
2072         span[j].t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;            \
2073         span[j].w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;            \
2074         span[j].r.w = r + drdiff - (xfrac * drdxh);            \
2075         span[j].g.w = g + dgdiff - (xfrac * dgdxh);            \
2076         span[j].b.w = b + dbdiff - (xfrac * dbdxh);            \
2077         span[j].a.w = a + dadiff - (xfrac * dadxh);            \
2078}
2079
2080#define addvalues() {   \
2081         s += dsde;   \
2082         t += dtde;   \
2083         w += dwde; \
2084         r += drde; \
2085         g += dgde; \
2086         b += dbde; \
2087         a += dade; \
2088}
2089
2090   ycur =   yh & ~3;
2091   ylfar = yl | 3;
2092   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
2093   yhpix = yh >> 2;
2094   ympix = ym >> 2;
2095   ylpix = yl >> 2;
2096
2097   if(ylfar >= 0x1000)
2098   {
2099      ylfar = 0x0fff;
2100   }
2101
2102   for (k = ycur; k <= ylfar; k++)
2103   {
2104      if (k == ym)
2105      {
2106         xleft = xl;
2107         xleft_inc = dxldy >> 2;
2108      }
2109
2110      xstart = xleft >> 16;
2111      xend = xright >> 16;
2112      j = k >> 2;
2113      spix = k & 3;
2114
2115      //if (k >= 0 && k < 0x1000)
2116      {
2117         int m = 0;
2118         int n = 0;
2119         min = 0; max = 3;
2120         if (j == yhpix)
2121         {
2122            min = yh & 3;
2123         }
2124         if (j == ylpix)
2125         {
2126            max = yl & 3;
2127         }
2128         if (spix >= min && spix <= max)
2129         {
2130            if (spix == min)
2131            {
2132               minxmx = maxxmx = xstart;
2133               minxhx = maxxhx = xend;
2134            }
2135            else
2136            {
2137               minxmx = (xstart < minxmx) ? xstart : minxmx;
2138               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
2139               minxhx = (xend < minxhx) ? xend : minxhx;
2140               maxxhx = (xend > maxxhx) ? xend : maxxhx;
2141            }
2142         }
2143
2144         if (spix == max)
2145         {
2146            if (flip)
2147            {
2148               span[j].lx = maxxmx;
2149               span[j].rx = minxhx;
2150            }
2151            else
2152            {
2153               span[j].lx = minxmx;
2154               span[j].rx = maxxhx;
2155            }
2156         }
2157
2158         int length = (xend - xstart) * sign;
2159
2160         if (spix == ldflag)
2161         {
2162            xfrac = ((xright >> 8) & 0xff);
2163            adjust_attr();
2164         }
2165
2166         m = flip ? (xend+1) : (xend-1);
2167
2168         if (k >= yh && length >= 0 && k <= yl)
2169         {
2170            if (xstart>=0 && xstart <1024)
2171            {
2172               if (!flip)
2173               {
2174                  span[j].cvg[xstart] += addleft(xleft);
2175               }
2176               else
2177               {
2178                  span[j].cvg[xstart] += addright(xleft);
2179               }
2180            }
2181            if (xend>=0 && xend<1024)
2182            {
2183               if (xstart != xend)
2184               {
2185                  if (!flip)
2186                  {
2187                     span[j].cvg[xend] += addright(xright);
2188                  }
2189                  else
2190                  {
2191                     span[j].cvg[xend] += addleft(xright);
2192                  }
2193               }
2194               else
2195               {
2196                  if (!flip)
2197                  {
2198                     span[j].cvg[xend] -= (2 - addright(xright));
2199                  }
2200                  else
2201                  {
2202                     span[j].cvg[xend] -= (2 - addleft(xright));
2203                  }
2204                  if (span[j].cvg[xend] > 200)
2205                  {
2206                     span[j].cvg[xend] = 0;
2207                  }
2208               }
2209            }
2210            for (n = 0; n < (length - 1); n++)
2211            {
2212               if (m>=0 && m < 640)
2213               {
2214                  span[j].cvg[m] += 2;
2215               }
2216
2217               m += inv_sign;
2218            }
2219         }
2220      }
2221
2222      if (spix == 3)
2223      {
2224         addvalues();
2225      }
2226      xleft += xleft_inc;
2227      xright += xright_inc;
2228   }
2229
2230   switch (fb_size) // 8bpp needs to be implemented
2231   {
2232      case PIXEL_SIZE_16BIT:
2233         if(flip)
2234         {
2235            render_spans_16_s_t_nz_f(yh>>2, yl>>2, &tile[0]); break;
2236         }
2237         else
2238         {
2239            render_spans_16_s_t_nz_nf(yh>>2, yl>>2, &tile[0]); break;
2240         }
2241      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 1, 1, 0, flip); break;
2242      default: break; // V-Rally2 does this, fb_size=0
2243   }
2244}
2245#undef addvalues
2246#undef adjust_attr
2247
2248static void triangle_s_t_z(UINT32 w1, UINT32 w2)
2249{
2250   int j;
2251   int xleft, xright, xleft_inc, xright_inc;
2252   int xstart, xend;
2253   int r = 0, g = 0, b = 0, a = 0, z = 0, s = 0, t = 0, w = 0;
2254   int dr, dg, db, da;
2255   int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0, dzdx = 0, dsdx = 0, dtdx = 0, dwdx = 0;
2256   int drdy = 0, dgdy = 0, dbdy = 0, dady = 0, dzdy = 0, dsdy = 0, dtdy = 0, dwdy = 0;
2257   int drde = 0, dgde = 0, dbde = 0, dade = 0, dzde = 0, dsde = 0, dtde = 0, dwde = 0;
2258   int tilenum;
2259   int flip = (w1 & 0x800000) ? 1 : 0;
2260   int sign = (w1 & 0x800000) ? -1 : 1;
2261   int inv_sign = (w1 & 0x800000) ?  1 : -1;
2262
2263   INT32 yl, ym, yh;
2264   INT32 xl, xm, xh;
2265   INT32 dxldy, dxhdy, dxmdy;
2266   int dzdy_dz, dzdx_dz;
2267   int dsdylod, dtdylod;
2268   UINT32 w3, w4, w5, w6, w7, w8;
2269
2270   int k = 0;
2271
2272   INT32 limcvg = 0;
2273   INT32 startcvg = 0;
2274
2275   int sign_dxldy = 0;
2276   int sign_dxmdy = 0;
2277   int samesign = 0;
2278
2279   int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0;
2280   int sign_dxhdy = 0;
2281
2282   int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0, dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0;
2283   int do_offset = 0;
2284
2285   int xfrac = 0;
2286   int dseoff = 0, dteoff = 0, dweoff = 0, dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0, dzeoff = 0;
2287
2288   int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0;
2289
2290   UINT32 min=0, max=3;
2291   INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
2292
2293   int spix = 0; // Current subpixel
2294   int ycur;
2295   int ylfar;
2296   int ldflag;
2297   int yhpix;
2298   int ympix;
2299   int ylpix;
2300
2301   int shade_base = rdp_cmd_cur + 8;
2302   int texture_base = rdp_cmd_cur + 24;
2303   int zbuffer_base = rdp_cmd_cur + 40;
2304
2305   w3 = rdp_cmd_data[rdp_cmd_cur+2];
2306   w4 = rdp_cmd_data[rdp_cmd_cur+3];
2307   w5 = rdp_cmd_data[rdp_cmd_cur+4];
2308   w6 = rdp_cmd_data[rdp_cmd_cur+5];
2309   w7 = rdp_cmd_data[rdp_cmd_cur+6];
2310   w8 = rdp_cmd_data[rdp_cmd_cur+7];
2311
2312   yl = (w1 & 0x3fff);
2313   ym = ((w2 >> 16) & 0x3fff);
2314   yh = ((w2 >>  0) & 0x3fff);
2315   xl = (INT32)(w3 & 0x3fffffff);
2316   xh = (INT32)(w5 & 0x3fffffff);
2317   xm = (INT32)(w7 & 0x3fffffff);
2318   // Inverse slopes in 16.16 format
2319   dxldy = (INT32)(w4);
2320   dxhdy = (INT32)(w6);
2321   dxmdy = (INT32)(w8);
2322
2323   max_level = ((w1 >> 19) & 7);
2324   tilenum = (w1 >> 16) & 0x7;
2325
2326   if (yl & 0x2000)  yl |= 0xffffc000;
2327   if (ym & 0x2000)  ym |= 0xffffc000;
2328   if (yh & 0x2000)  yh |= 0xffffc000;
2329
2330   if (xl & 0x20000000)  xl |= 0xc0000000;
2331   if (xm & 0x20000000)  xm |= 0xc0000000;
2332   if (xh & 0x20000000)  xh |= 0xc0000000;
2333
2334   z = 0;
2335   s = 0;   t = 0;   w = 0;
2336   dr = 0;      dg = 0;      db = 0;      da = 0;
2337
2338   r    = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
2339   g    = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff);
2340   b    = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
2341   a    = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff);
2342   drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
2343   dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff);
2344   dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
2345   dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff);
2346   drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
2347   dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff);
2348   dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
2349   dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff);
2350   drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
2351   dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff);
2352   dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
2353   dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff);
2354   s    = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
2355   t    = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff);
2356   w    = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
2357   dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
2358   dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff);
2359   dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
2360   dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
2361   dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+12] & 0x0000ffff);
2362   dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
2363   dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
2364   dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000)   | (rdp_cmd_data[texture_base+14] & 0x0000ffff);
2365   dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
2366   z    = rdp_cmd_data[zbuffer_base+0];
2367   dzdx = rdp_cmd_data[zbuffer_base+1];
2368   dzde = rdp_cmd_data[zbuffer_base+2];
2369   dzdy = rdp_cmd_data[zbuffer_base+3];
2370
2371   span[0].ds.w = dsdx;
2372   span[0].dt.w = dtdx;
2373   span[0].dw.w = dwdx;
2374   span[0].dr.w = drdx & ~0x1f;
2375   span[0].dg.w = dgdx & ~0x1f;
2376   span[0].db.w = dbdx & ~0x1f;
2377   span[0].da.w = dadx & ~0x1f;
2378   span[0].dz.w = dzdx;
2379   dzdy_dz = (dzdy >> 16) & 0xffff;
2380   dzdx_dz = (dzdx >> 16) & 0xffff;
2381   span[0].dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
2382   span[0].dzpix = normalize_dzpix(span[0].dzpix);
2383   dsdylod = dsdy >> 16;
2384   dtdylod = dtdy >> 16;
2385   if (dsdylod & 0x20000)
2386   {
2387      dsdylod = ~dsdylod & 0x1ffff;
2388   }
2389   if (dtdylod & 0x20000)
2390   {
2391      dtdylod = ~dtdylod & 0x1ffff;
2392   }
2393   span[0].dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
2394
2395   xleft_inc = dxmdy >> 2;
2396   xright_inc = dxhdy >> 2;
2397
2398   xright = xh;
2399   xleft = xm;
2400
2401   limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
2402   if (limcvg < 0)
2403   {
2404      limcvg = 0;
2405   }
2406
2407   startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
2408   for (k = startcvg; k <= limcvg; k++)
2409   {
2410      memset((void*)&span[k].cvg[0],0,640);
2411   }
2412
2413   sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
2414   sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
2415   samesign = !(sign_dxldy ^ sign_dxmdy);
2416
2417   sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
2418
2419   do_offset = !(sign_dxhdy ^ (flip));
2420
2421   if (do_offset)
2422   {
2423      dsdeh = dsde >> 9;   dsdyh = dsdy >> 9;
2424      dtdeh = dtde >> 9;   dtdyh = dtdy >> 9;
2425      dwdeh = dwde >> 9;   dwdyh = dwdy >> 9;
2426      drdeh = drde >> 9;   drdyh = drdy >> 9;
2427      dgdeh = dgde >> 9;   dgdyh = dgdy >> 9;
2428      dbdeh = dbde >> 9;   dbdyh = dbdy >> 9;
2429      dadeh = dade >> 9;   dadyh = dady >> 9;
2430      dzdeh = dzde >> 9;   dzdyh = dzdy >> 9;
2431
2432      dsdiff = (dsdeh*3 - dsdyh*3) << 7;
2433      dtdiff = (dtdeh*3 - dtdyh*3) << 7;
2434      dwdiff = (dwdeh*3 - dwdyh*3) << 7;
2435      drdiff = (drdeh*3 - drdyh*3) << 7;
2436      dgdiff = (dgdeh*3 - dgdyh*3) << 7;
2437      dbdiff = (dbdeh*3 - dbdyh*3) << 7;
2438      dadiff = (dadeh*3 - dadyh*3) << 7;
2439      dzdiff = (dzdeh*3 - dzdyh*3) << 7;
2440   }
2441   else
2442   {
2443      dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0;
2444   }
2445
2446   if (do_offset)
2447   {
2448      dseoff = (dsdeh*3) << 7;
2449      dteoff = (dtdeh*3) << 7;
2450      dweoff = (dwdeh*3) << 7;
2451      dreoff = (drdeh*3) << 7;
2452      dgeoff = (dgdeh*3) << 7;
2453      dbeoff = (dbdeh*3) << 7;
2454      daeoff = (dadeh*3) << 7;
2455      dzeoff = (dzdeh*3) << 7;
2456   }
2457   else
2458   {
2459      dseoff = dteoff = dweoff = dreoff = dgeoff = dbeoff = daeoff = dzeoff = 0;
2460   }
2461
2462   dsdxh = dsdx >> 8;
2463   dtdxh = dtdx >> 8;
2464   dwdxh = dwdx >> 8;
2465   drdxh = drdx >> 8;
2466   dgdxh = dgdx >> 8;
2467   dbdxh = dbdx >> 8;
2468   dadxh = dadx >> 8;
2469   dzdxh = dzdx >> 8;
2470
2471#define adjust_attr()      \
2472{                     \
2473         span[j].s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;            \
2474         span[j].t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;            \
2475         span[j].w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;            \
2476         span[j].r.w = r + drdiff - (xfrac * drdxh);            \
2477         span[j].g.w = g + dgdiff - (xfrac * dgdxh);            \
2478         span[j].b.w = b + dbdiff - (xfrac * dbdxh);            \
2479         span[j].a.w = a + dadiff - (xfrac * dadxh);            \
2480         span[j].z.w = z + dzdiff - (xfrac * dzdxh);            \
2481}
2482
2483#define addvalues() {   \
2484         s += dsde;   \
2485         t += dtde;   \
2486         w += dwde; \
2487         r += drde; \
2488         g += dgde; \
2489         b += dbde; \
2490         a += dade; \
2491         z += dzde; \
2492}
2493
2494   ycur =   yh & ~3;
2495   ylfar = yl | 3;
2496   ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
2497   yhpix = yh >> 2;
2498   ympix = ym >> 2;
2499   ylpix = yl >> 2;
2500
2501   if(ylfar >= 0x1000)
2502   {
2503      ylfar = 0x0fff;
2504   }
2505
2506   if(flip)
2507   {
2508      for (k = ycur; k <= ylfar; k++)
2509      {
2510         if (k == ym)
2511         {
2512            xleft = xl;
2513            xleft_inc = dxldy >> 2;
2514         }
2515
2516         xstart = xleft >> 16;
2517         xend = xright >> 16;
2518         j = k >> 2;
2519         spix = k & 3;
2520
2521         //if (k >= 0 && k < 0x1000)
2522         {
2523            int m = 0;
2524            int n = 0;
2525            min = 0; max = 3;
2526            if (j == yhpix)
2527            {
2528               min = yh & 3;
2529            }
2530            if (j == ylpix)
2531            {
2532               max = yl & 3;
2533            }
2534            if (spix >= min && spix <= max)
2535            {
2536               if (spix == min)
2537               {
2538                  minxmx = maxxmx = xstart;
2539                  minxhx = maxxhx = xend;
2540               }
2541               else
2542               {
2543                  minxmx = (xstart < minxmx) ? xstart : minxmx;
2544                  maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
2545                  minxhx = (xend < minxhx) ? xend : minxhx;
2546                  maxxhx = (xend > maxxhx) ? xend : maxxhx;
2547               }
2548            }
2549
2550            if (spix == max)
2551            {
2552               span[j].lx = maxxmx;
2553               span[j].rx = minxhx;
2554            }
2555
2556            int length = (xend - xstart) * sign;
2557
2558            if (spix == ldflag)
2559            {
2560               xfrac = ((xright >> 8) & 0xff);
2561               adjust_attr();
2562            }
2563
2564            m = xend + 1;
2565
2566            if (k >= yh && length >= 0 && k <= yl)
2567            {
2568               if (xstart>=0 && xstart <1024)
2569               {
2570                  span[j].cvg[xstart] += addright(xleft);
2571               }
2572               if (xend>=0 && xend<1024)
2573               {
2574                  if (xstart != xend)
2575                  {
2576                     span[j].cvg[xend] += addleft(xright);
2577                  }
2578                  else
2579                  {
2580                     span[j].cvg[xend] -= (2 - addleft(xright));
2581                     if (span[j].cvg[xend] > 200)
2582                     {
2583                        span[j].cvg[xend] = 0;
2584                     }
2585                  }
2586               }
2587               for (n = 0; n < (length - 1); n++)
2588               {
2589                  if (m>=0 && m < 640)
2590                  {
2591                     span[j].cvg[m] += 2;
2592                  }
2593
2594                  m += inv_sign;
2595               }
2596            }
2597         }
2598
2599         if (spix == 3)
2600         {
2601            addvalues();
2602         }
2603         xleft += xleft_inc;
2604         xright += xright_inc;
2605      }
2606   }
2607   else
2608   {
2609      for (k = ycur; k <= ylfar; k++)
2610      {
2611         if (k == ym)
2612         {
2613            xleft = xl;
2614            xleft_inc = dxldy >> 2;
2615         }
2616
2617         xstart = xleft >> 16;
2618         xend = xright >> 16;
2619         j = k >> 2;
2620         spix = k & 3;
2621
2622         if (k >= 0 && k < 0x1000)
2623         {
2624            int m = 0;
2625            int n = 0;
2626            min = 0; max = 3;
2627            if (j == yhpix)
2628            {
2629               min = yh & 3;
2630            }
2631            if (j == ylpix)
2632            {
2633               max = yl & 3;
2634            }
2635            if (spix >= min && spix <= max)
2636            {
2637               if (spix == min)
2638               {
2639                  minxmx = maxxmx = xstart;
2640                  minxhx = maxxhx = xend;
2641               }
2642               else
2643               {
2644                  minxmx = (xstart < minxmx) ? xstart : minxmx;
2645                  maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
2646                  minxhx = (xend < minxhx) ? xend : minxhx;
2647                  maxxhx = (xend > maxxhx) ? xend : maxxhx;
2648               }
2649            }
2650
2651            if (spix == max)
2652            {
2653               span[j].lx = minxmx;
2654               span[j].rx = maxxhx;
2655            }
2656
2657            int length = (xend - xstart) * sign;
2658
2659            if (spix == ldflag)
2660            {
2661               xfrac = ((xright >> 8) & 0xff);
2662               adjust_attr();
2663            }
2664
2665            m = xend - 1;
2666
2667            if (k >= yh && length >= 0 && k <= yl)
2668            {
2669               if (xstart>=0 && xstart <1024)
2670               {
2671                  span[j].cvg[xstart] += addleft(xleft);
2672               }
2673               if (xend>=0 && xend<1024)
2674               {
2675                  if (xstart != xend)
2676                  {
2677                     span[j].cvg[xend] += addright(xright);
2678                  }
2679                  else
2680                  {
2681                     span[j].cvg[xend] -= (2 - addright(xright));
2682                     if (span[j].cvg[xend] > 200)
2683                     {
2684                        span[j].cvg[xend] = 0;
2685                     }
2686                  }
2687               }
2688               for (n = 0; n < (length - 1); n++)
2689               {
2690                  if (m>=0 && m < 640)
2691                  {
2692                     span[j].cvg[m] += 2;
2693                  }
2694
2695                  m += inv_sign;
2696               }
2697            }
2698         }
2699
2700         if (spix == 3)
2701         {
2702            addvalues();
2703         }
2704         xleft += xleft_inc;
2705         xright += xright_inc;
2706      }
2707   }
2708
2709   switch (fb_size) // 8bpp needs to be implemented
2710   {
2711      case PIXEL_SIZE_16BIT:
2712         if(flip)
2713         {
2714            render_spans_16_s_t_z_f(yh>>2, yl>>2, &tile[0]); break;
2715         }
2716         else
2717         {
2718            render_spans_16_s_t_z_nf(yh>>2, yl>>2, &tile[0]); break;
2719         }
2720      case PIXEL_SIZE_32BIT:   render_spans_32(yh>>2, yl>>2, &tile[tilenum], 1, 1, 1, flip); break;
2721      default: break; // V-Rally2 does this, fb_size=0
2722   }
2723}
2724
2725#undef addvalues
2726#undef adjust_attr
src/mame/video/rdpmask.c
r7675r7676
1#if defined(MASK_S)
2   #if defined(MASK_T)
3      INLINE void MASK_S_T(INT32* S, INT32* T, TILE* tex_tile)
4   #else
5      INLINE void MASK_S_NT(INT32* S, INT32* T, TILE* tex_tile)
6   #endif
7#else
8   #if defined(MASK_T)
9      INLINE void MASK_NS_T(INT32* S, INT32* T, TILE* tex_tile)
10   #else
11      INLINE void MASK_NS_NT(INT32* S, INT32* T, TILE* tex_tile)
12   #endif
13#endif
14{
15#if defined(MASK_S)
16   INT32 swrap = *S >> tex_tile->mask_s;
17   swrap &= 1;
18   if (tex_tile->ms && swrap)
19   {
20      *S = (~(*S)) & maskbits_table[tex_tile->mask_s]; // Mirroring and masking
21   }
22   else
23   {
24      *S &= maskbits_table[tex_tile->mask_s]; // Masking
25   }
26#endif
27
28#if defined(MASK_T)
29   INT32 twrap = *T >> tex_tile->mask_t;
30   twrap &= 1;
31   if (tex_tile->mt && twrap)
32   {
33      *T = (~(*T)) & maskbits_table[tex_tile->mask_t]; // Mirroring and masking
34   }
35   else
36   {
37      *T &= maskbits_table[tex_tile->mask_t];
38   }
39#endif
40}
41
src/mame/video/rdpmask.h
r7675r7676
1INLINE void MASK_NS_NT(INT32* S, INT32* T, TILE* tex_tile);
2INLINE void MASK_NS_T(INT32* S, INT32* T, TILE* tex_tile);
3INLINE void MASK_S_NT(INT32* S, INT32* T, TILE* tex_tile);
4INLINE void MASK_S_T(INT32* S, INT32* T, TILE* tex_tile);
5
6static void (*rdp_mask_func[8])(INT32*, INT32*, TILE*) =
7{
8   MASK_NS_NT,   MASK_NS_T,   MASK_S_NT,   MASK_S_T,
9};
src/mame/video/rdpzcomp.c
r7675r7676
1#if defined(ZMODE0)
2   #if defined(ANTIALIAS)
3      #if defined(IMGREAD)
4         INLINE UINT32 z_compare_IMR_AA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
5      #else
6         INLINE UINT32 z_compare_NIMR_AA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
7      #endif
8   #else
9      #if defined(IMGREAD)
10         INLINE UINT32 z_compare_IMR_NAA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
11      #else
12         INLINE UINT32 z_compare_NIMR_NAA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
13      #endif
14   #endif
15#elif defined(ZMODE1)
16   #if defined(ANTIALIAS)
17      #if defined(IMGREAD)
18         INLINE UINT32 z_compare_IMR_AA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
19      #else
20         INLINE UINT32 z_compare_NIMR_AA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
21      #endif
22   #else
23      #if defined(IMGREAD)
24         INLINE UINT32 z_compare_IMR_NAA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
25      #else
26         INLINE UINT32 z_compare_NIMR_NAA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
27      #endif
28   #endif
29#elif defined(ZMODE2)
30   #if defined(ANTIALIAS)
31      #if defined(IMGREAD)
32         INLINE UINT32 z_compare_IMR_AA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
33      #else
34         INLINE UINT32 z_compare_NIMR_AA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
35      #endif
36   #else
37      #if defined(IMGREAD)
38         INLINE UINT32 z_compare_IMR_NAA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
39      #else
40         INLINE UINT32 z_compare_NIMR_NAA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
41      #endif
42   #endif
43#elif defined(ZMODE3)
44   #if defined(ANTIALIAS)
45      #if defined(IMGREAD)
46         INLINE UINT32 z_compare_IMR_AA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
47      #else
48         INLINE UINT32 z_compare_NIMR_AA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
49      #endif
50   #else
51      #if defined(IMGREAD)
52         INLINE UINT32 z_compare_IMR_NAA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
53      #else
54         INLINE UINT32 z_compare_NIMR_NAA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
55      #endif
56   #endif
57#endif
58{
59   int force_coplanar = 0;
60   UINT32 oz = z_decompress(zb);
61   UINT32 dzmem = dz_decompress(zb, zhb);
62   UINT32 dznew = 0;
63   UINT32 farther = 0;
64   UINT32 diff = 0;
65   UINT32 nearer = 0;
66   UINT32 infront = 0;
67   UINT32 max = 0;
68   int precision_factor = (oz >> 15) & 0xf;
69   int overflow = 0;
70#if defined(ZMODE1)
71   int cvgcoeff = 0;
72#endif
73   UINT32 mempixel, memory_cvg;
74
75   sz &= 0x3ffff;
76   if (dzmem == 0x8000 && precision_factor < 3)
77   {
78      force_coplanar = 1;
79   }
80   if (!precision_factor)
81   {
82      dzmem = ((dzmem << 1) > 16) ? (dzmem << 1) : 16;
83   }
84   else if (precision_factor == 1)
85   {
86      dzmem = ((dzmem << 1) > 8) ? (dzmem << 1) : 8;
87   }
88   else if (precision_factor == 2)
89   {
90      dzmem = ((dzmem << 1) > 4) ? (dzmem << 1) : 4;
91   }
92   if (dzmem == 0 && precision_factor < 3)
93   {
94      dzmem = 0xffff;
95   }
96   if (dzmem > 0x8000)
97   {
98      dzmem = 0xffff;
99   }
100   dznew =((dzmem > dzpix) ? dzmem : (UINT32)dzpix) << 3;
101   dznew &= 0x3ffff;
102
103   farther = ((sz + dznew) >= oz) ? 1 : 0;
104   diff = (sz >= dznew) ? (sz - dznew) : 0;
105   nearer = (diff <= oz) ? 1: 0;
106   infront = (sz < oz) ? 1 : 0;
107   max = (dzmem == 0x3ffff);
108
109   if (force_coplanar)
110   {
111      farther = nearer = 1;
112   }
113
114   curpixel_overlap = 0;
115
116   switch(fb_size)
117   {
118      case 1: /* Banjo Tooie */
119         memory_cvg = 0; //??
120         break;
121      case 2:
122         mempixel = *(UINT16*)fb;
123         memory_cvg = ((mempixel & 1) << 2) + (*hb & 3);
124         break;
125      case 3:
126         mempixel = *(UINT32*)fb;
127         memory_cvg = (mempixel >> 5) & 7;
128         break;
129      default:
130         fatalerror("z_compare: fb_size = %d",fb_size);
131         break;
132   }
133
134#if !defined(IMGREAD)
135   memory_cvg = 7;
136#endif
137
138   overflow = ((memory_cvg + curpixel_cvg - 1) > 7) ? 1 : 0;
139
140#if defined(ANTIALIAS)
141   curpixel_overlap = (other_modes.force_blend || (!overflow && farther));
142#else
143   curpixel_overlap = other_modes.force_blend;
144#endif
145
146#if defined(ZMODE1)
147   if (infront && farther && overflow)
148   {
149      cvgcoeff = ((dzmem >> dznew) - (sz >> dznew)) & 0xf;
150      curpixel_cvg = ((cvgcoeff * (curpixel_cvg - 1)) >> 3) & 0xf;
151   }
152#endif
153   if (curpixel_cvg > 8)
154      curpixel_cvg = 8;
155
156#if defined(ZMODE0)
157   return (max || (overflow ? infront : nearer))? 1 : 0;
158#elif defined(ZMODE1)
159   return (max || (overflow ? infront : nearer))? 1 : 0;
160#elif defined(ZMODE2)
161   return infront | max;
162#elif defined(ZMODE3)
163   return farther & nearer & !max;
164#else
165   return 0;
166#endif
167}
168
src/mame/video/rdpzcomp.h
r7675r7676
1INLINE UINT32 z_compare_IMR_AA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
2INLINE UINT32 z_compare_NIMR_AA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
3INLINE UINT32 z_compare_IMR_NAA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
4INLINE UINT32 z_compare_NIMR_NAA_Z0(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
5INLINE UINT32 z_compare_IMR_AA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
6INLINE UINT32 z_compare_NIMR_AA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
7INLINE UINT32 z_compare_IMR_NAA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
8INLINE UINT32 z_compare_NIMR_NAA_Z1(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
9INLINE UINT32 z_compare_IMR_AA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
10INLINE UINT32 z_compare_NIMR_AA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
11INLINE UINT32 z_compare_IMR_NAA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
12INLINE UINT32 z_compare_NIMR_NAA_Z2(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
13INLINE UINT32 z_compare_IMR_AA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
14INLINE UINT32 z_compare_NIMR_AA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
15INLINE UINT32 z_compare_IMR_NAA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
16INLINE UINT32 z_compare_NIMR_NAA_Z3(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
17
18static UINT32 (*rdp_z_compare_func[16])(void*, UINT8*, UINT16*, UINT8*, UINT32, UINT16) =
19{
20   z_compare_IMR_AA_Z0,   z_compare_NIMR_AA_Z0,   z_compare_IMR_NAA_Z0,   z_compare_NIMR_NAA_Z0,
21   z_compare_IMR_AA_Z1,   z_compare_NIMR_AA_Z1,   z_compare_IMR_NAA_Z1,   z_compare_NIMR_NAA_Z1,
22   z_compare_IMR_AA_Z2,   z_compare_NIMR_AA_Z2,   z_compare_IMR_NAA_Z2,   z_compare_NIMR_NAA_Z2,
23   z_compare_IMR_AA_Z3,   z_compare_NIMR_AA_Z3,   z_compare_IMR_NAA_Z3,   z_compare_NIMR_NAA_Z3
24};
src/mame/video/rdpcc.c
r7675r7676
1/*
2#if defined(NOISE)
3    #define COLOR_COMBINER1_NOISE(color)
4        noise_color.i.r = rdp_rand();
5        noise_color.i.g = rdp_rand();
6        noise_color.i.b = rdp_rand();
7        color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[1],*combiner_rgbsub_b_r[1],*combiner_rgbmul_r[1],*combiner_rgbadd_r[1]);
8        color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[1],*combiner_rgbsub_b_g[1],*combiner_rgbmul_g[1],*combiner_rgbadd_g[1]);
9        color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[1],*combiner_rgbsub_b_b[1],*combiner_rgbmul_b[1],*combiner_rgbadd_b[1]);
10        color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[1],*combiner_alphasub_b[1],*combiner_alphamul[1],*combiner_alphaadd[1]);
11        alpha_cvg_get(&color.i.a);
12#else*/
13   #define COLOR_COMBINER1(color) \
14      color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[1],*combiner_rgbsub_b_r[1],*combiner_rgbmul_r[1],*combiner_rgbadd_r[1]); \
15      color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[1],*combiner_rgbsub_b_g[1],*combiner_rgbmul_g[1],*combiner_rgbadd_g[1]); \
16      color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[1],*combiner_rgbsub_b_b[1],*combiner_rgbmul_b[1],*combiner_rgbadd_b[1]); \
17      color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[1],*combiner_alphasub_b[1],*combiner_alphamul[1],*combiner_alphaadd[1]); \
18      alpha_cvg_get(&color.i.a);
19//#endif
20
21/*
22#if defined(NOISE)
23    #define COLOR_COMBINER2_C0_NOISE(color)
24        noise_color.i.r = rdp_rand();
25        noise_color.i.g = rdp_rand();
26        noise_color.i.b = rdp_rand();
27        color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[0],*combiner_rgbsub_b_r[0],*combiner_rgbmul_r[0],*combiner_rgbadd_r[0]);
28        color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[0],*combiner_rgbsub_b_g[0],*combiner_rgbmul_g[0],*combiner_rgbadd_g[0]);
29        color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[0],*combiner_rgbsub_b_b[0],*combiner_rgbmul_b[0],*combiner_rgbadd_b[0]);
30        color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[0],*combiner_alphasub_b[0],*combiner_alphamul[0],*combiner_alphaadd[0]);
31        combined_color.c = color.c;
32#else*/
33   #define COLOR_COMBINER2_C0(color) \
34      color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[0],*combiner_rgbsub_b_r[0],*combiner_rgbmul_r[0],*combiner_rgbadd_r[0]); \
35      color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[0],*combiner_rgbsub_b_g[0],*combiner_rgbmul_g[0],*combiner_rgbadd_g[0]); \
36      color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[0],*combiner_rgbsub_b_b[0],*combiner_rgbmul_b[0],*combiner_rgbadd_b[0]); \
37      color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[0],*combiner_alphasub_b[0],*combiner_alphamul[0],*combiner_alphaadd[0]); \
38      combined_color.c = color.c;
39//#endif
40
41
42/*#if defined(NOISE)
43    #define COLOR_COMBINER2_C1_NOISE(color)
44        color.c = texel0_color.c;
45        texel0_color.c = texel1_color.c;
46        texel1_color.c = color.c;
47        noise_color.i.r = rdp_rand();
48        noise_color.i.g = rdp_rand();
49        noise_color.i.b = rdp_rand();
50        color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[1],*combiner_rgbsub_b_r[1],*combiner_rgbmul_r[1],*combiner_rgbadd_r[1]);
51        color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[1],*combiner_rgbsub_b_g[1],*combiner_rgbmul_g[1],*combiner_rgbadd_g[1]);
52        color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[1],*combiner_rgbsub_b_b[1],*combiner_rgbmul_b[1],*combiner_rgbadd_b[1]);
53        color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[1],*combiner_alphasub_b[1],*combiner_alphamul[1],*combiner_alphaadd[1]);
54        alpha_cvg_get(&color.i.a);
55#else*/
56   #define COLOR_COMBINER2_C1(color) \
57      color.c = texel0_color.c; \
58      texel0_color.c = texel1_color.c; \
59      texel1_color.c = color.c; \
60      color.i.r = COMBINER_EQUATION(*combiner_rgbsub_a_r[1],*combiner_rgbsub_b_r[1],*combiner_rgbmul_r[1],*combiner_rgbadd_r[1]); \
61      color.i.g = COMBINER_EQUATION(*combiner_rgbsub_a_g[1],*combiner_rgbsub_b_g[1],*combiner_rgbmul_g[1],*combiner_rgbadd_g[1]); \
62      color.i.b = COMBINER_EQUATION(*combiner_rgbsub_a_b[1],*combiner_rgbsub_b_b[1],*combiner_rgbmul_b[1],*combiner_rgbadd_b[1]); \
63      color.i.a = COMBINER_EQUATION(*combiner_alphasub_a[1],*combiner_alphasub_b[1],*combiner_alphamul[1],*combiner_alphaadd[1]); \
64      alpha_cvg_get(&color.i.a);
65//#endif
src/mame/video/rdpcc.h
r7675r7676
1INLINE UINT32 COLOR_COMBINER1_NNOISE(void);
2INLINE UINT32 COLOR_COMBINER2_C0_NNOISE(void);
3INLINE UINT32 COLOR_COMBINER2_C1_NNOISE(void);
4INLINE UINT32 COLOR_COMBINER1_NOISE(void);
5INLINE UINT32 COLOR_COMBINER2_C0_NOISE(void);
6INLINE UINT32 COLOR_COMBINER2_C1_NOISE(void);
src/mame/video/rdpacvg.c
r7675r7676
1INLINE void alpha_cvg_get_cta_ca(UINT8 *comb_alpha)
2{
3   UINT32 temp = *comb_alpha;
4   UINT32 temp2 = curpixel_cvg;
5
6   UINT32 temp3 = (temp * temp2) + 4;
7   curpixel_cvg = temp3 >> 8;
8
9   temp = (temp3 >> 3);
10
11   if (temp > 0xff)
12   {
13      *comb_alpha = 0xff;
14   }
15   else
16   {
17      *comb_alpha = (UINT8)temp;
18   }
19}
20
21INLINE void alpha_cvg_get_ncta_ca(UINT8 *comb_alpha)
22{
23   UINT32 temp2 = curpixel_cvg;
24   UINT32 temp = temp2 << 5;
25
26   if (temp > 0xff)
27   {
28      *comb_alpha = 0xff;
29   }
30   else
31   {
32      *comb_alpha = (UINT8)temp;
33   }
34}
35
36INLINE void alpha_cvg_get_cta_nca(UINT8 *comb_alpha)
37{
38   UINT32 temp = *comb_alpha;
39   UINT32 temp2 = curpixel_cvg;
40   UINT32 temp3 = (temp * temp2) + 4;
41
42   curpixel_cvg = temp3 >> 8;
43
44   if (temp > 0xff)
45   {
46      *comb_alpha = 0xff;
47   }
48   else
49   {
50      *comb_alpha = (UINT8)temp;
51   }
52}
53
54INLINE void alpha_cvg_get_ncta_nca(UINT8 *comb_alpha)
55{
56   // DO nothing
57}
src/mame/video/rdpacvg.h
r7675r7676
1INLINE void alpha_cvg_get_cta_ca(UINT8 *comb_alpha);
2INLINE void alpha_cvg_get_ncta_ca(UINT8 *comb_alpha);
3INLINE void alpha_cvg_get_cta_nca(UINT8 *comb_alpha);
4INLINE void alpha_cvg_get_ncta_nca(UINT8 *comb_alpha);
5
6static void (*rdp_alpha_cvg_func[4])(UINT8*) =
7{
8   alpha_cvg_get_ncta_nca, alpha_cvg_get_ncta_ca, alpha_cvg_get_cta_nca, alpha_cvg_get_cta_ca,
9};
src/mame/video/rdpacomp.c
r7675r7676
1INLINE int alpha_compare_nac_nda(UINT8 comb_alpha)
2{
3   return 1;
4}
5
6INLINE int alpha_compare_nac_da(UINT8 comb_alpha)
7{
8   return 1;
9}
10
11INLINE int alpha_compare_ac_nda(UINT8 comb_alpha)
12{
13   if (comb_alpha < blend_color.i.a)
14   {
15      return 0;
16   }
17   return 1;
18}
19
20INLINE int alpha_compare_ac_da(UINT8 comb_alpha)
21{
22   return comb_alpha < rdp_rand();
23}
24
src/mame/video/rdpacomp.h
r7675r7676
1INLINE int alpha_compare_nac_nda(UINT8 comb_alpha);
2INLINE int alpha_compare_nac_da(UINT8 comb_alpha);
3INLINE int alpha_compare_ac_nda(UINT8 comb_alpha);
4INLINE int alpha_compare_ac_da(UINT8 comb_alpha);
5
6static int (*rdp_alpha_compare_func[4])(UINT8) =
7{
8   alpha_compare_nac_nda, alpha_compare_nac_da, alpha_compare_ac_nda, alpha_compare_ac_da
9};
src/mame/video/rdpshift.c
r7675r7676
1#if defined(SHIFT_S)
2   #if defined(SHIFT_T)
3      static void TEXSHIFT_S_T(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile)
4   #else
5      static void TEXSHIFT_S_NT(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile)
6   #endif
7#else
8   #if defined(SHIFT_T)
9      static void TEXSHIFT_NS_T(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile)
10   #else
11      static void TEXSHIFT_NS_NT(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile)
12   #endif
13#endif
14{
15#if defined(SHIFT_S)
16   *S = SIGN16(*S);
17   if (tex_tile->shift_s < 11)
18   {
19      *S >>= tex_tile->shift_s;
20   }
21   else
22   {
23      *S <<= (16 - tex_tile->shift_s);
24   }
25   *S = SIGN16(*S);
26#endif
27#if defined(SHIFT_T)
28   *T = SIGN16(*T);
29   if (tex_tile->shift_t < 11)
30   {
31      *T >>= tex_tile->shift_t;
32   }
33   else
34   {
35      *T <<= (16 - tex_tile->shift_t);
36   }
37   *T = SIGN16(*T);
38#endif
39   *maxs = ((*S >> 3) >= tex_tile->sh);
40   *maxt = ((*T >> 3) >= tex_tile->th);
41}
src/mame/video/rdpshift.h
r7675r7676
1static void TEXSHIFT_S_T(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile);
2static void TEXSHIFT_S_NT(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile);
3static void TEXSHIFT_NS_T(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile);
4static void TEXSHIFT_NS_NT(INT32* S, INT32* T, INT32* maxs, INT32* maxt, TILE* tex_tile);
5
6static void (*rdp_shift_func[4])(INT32*, INT32*, INT32*, INT32*, TILE*) =
7{
8   TEXSHIFT_NS_NT, TEXSHIFT_NS_T, TEXSHIFT_S_NT, TEXSHIFT_S_T
9};
src/mame/video/rdpclamp.c
r7675r7676
1#if defined(DOS)
2   #if defined(DOT)
3      INLINE void CLAMP_NC_DOS_DOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile)
4   #else
5      INLINE void CLAMP_NC_DOS_NDOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile)
6   #endif
7#else
8   #if defined(DOT)
9      INLINE void CLAMP_NC_NDOS_DOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile)
10   #else
11      INLINE void CLAMP_NC_NDOS_NDOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile)
12   #endif
13#endif
14{
15#if defined(DOS)
16   if (*S & 0x10000)
17   {
18      *S = 0;
19      *SFRAC = 0;
20   }
21   else if (maxs)
22   {
23      *S = clamp_s_diff[tex_tile->num];
24      *SFRAC = 0;
25   }
26   else
27#endif
28   {
29      *S = (SIGN17(*S) >> 5) & 0x1fff;
30   }
31
32#if defined(DOT)
33   if (*T & 0x10000)
34   {
35      *T = 0;
36      *TFRAC = 0;
37   }
38   else if (maxt)
39   {
40      *T = clamp_t_diff[tex_tile->num];
41      *TFRAC = 0;
42   }
43   else
44#endif
45   {
46      *T = (SIGN17(*T) >> 5) & 0x1fff;
47   }
48}
49
50#if defined(DOS)
51   #if defined(DOT)
52      INLINE void CLAMP_LIGHT_NC_DOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile)
53   #else
54      INLINE void CLAMP_LIGHT_NC_DOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile)
55   #endif
56#else
57   #if defined(DOT)
58      INLINE void CLAMP_LIGHT_NC_NDOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile)
59   #else
60      INLINE void CLAMP_LIGHT_NC_NDOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile)
61   #endif
62#endif
63{
64   //int dos = (tex_tile->cs || !tex_tile->mask_s);
65   //int dot = (tex_tile->ct || !tex_tile->mask_t);
66#if defined(DOS)
67   if (*S & 0x10000)
68   {
69      *S = 0;
70   }
71   else if (maxs)
72   {
73      *S = clamp_s_diff[tex_tile->num];
74   }
75   else
76#endif
77   {
78      *S = (SIGN17(*S) >> 5) & 0x1fff;
79   }
80
81#if defined(DOT)
82   if (*T & 0x10000)
83   {
84      *T = 0;
85   }
86   else if (maxt)
87   {
88      *T = clamp_t_diff[tex_tile->num];
89   }
90   else
91#endif
92   {
93      *T = (SIGN17(*T) >> 5) & 0x1fff;
94   }
95}
96
97#if defined(DOS)
98   #if defined(DOT)
99      INLINE void CLAMP_QUICK_NC_DOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num)
100   #else
101      INLINE void CLAMP_QUICK_NC_DOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num)
102   #endif
103#else
104   #if defined(DOT)
105      INLINE void CLAMP_QUICK_NC_NDOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num)
106   #else
107      INLINE void CLAMP_QUICK_NC_NDOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num)
108   #endif
109#endif
110{
111#if defined(DOS)
112   if (*S & 0x10000)
113   {
114      *S = 0;
115   }
116   else if (maxs)
117   {
118      *S = clamp_s_diff[num];
119   }
120   else
121#endif
122   {
123      *S = (SIGN17(*S) >> 5) & 0x1fff;
124   }
125
126#if defined(DOT)
127   if (*T & 0x10000)
128   {
129      *T = 0;
130   }
131   else if (maxt)
132   {
133      *T = clamp_t_diff[num];
134   }
135   else
136#endif
137   {
138      *T = (SIGN17(*T) >> 5) & 0x1fff;
139   }
140}
141
142#if defined(DOS) && defined(DOT)
143INLINE void CLAMP_C(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile)
144{
145   *S = (SIGN17(*S) >> 5) & 0x1fff;
146   *T = (SIGN17(*T) >> 5) & 0x1fff;
147}
148
149INLINE void CLAMP_LIGHT_C(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile)
150{
151   *S = (SIGN17(*S) >> 5) & 0x1fff;
152   *T = (SIGN17(*T) >> 5) & 0x1fff;
153}
154
155INLINE void CLAMP_QUICK_C(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num)
156{
157   *S = (SIGN17(*S) >> 5) & 0x1fff;
158   *T = (SIGN17(*T) >> 5) & 0x1fff;
159}
160#endif
src/mame/video/rdpclamp.h
r7675r7676
1INLINE void CLAMP_NC_NDOS_NDOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
2INLINE void CLAMP_NC_NDOS_DOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
3INLINE void CLAMP_NC_DOS_NDOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
4INLINE void CLAMP_NC_DOS_DOT(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
5
6INLINE void CLAMP_LIGHT_NC_NDOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
7INLINE void CLAMP_LIGHT_NC_NDOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
8INLINE void CLAMP_LIGHT_NC_DOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
9INLINE void CLAMP_LIGHT_NC_DOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
10
11INLINE void CLAMP_QUICK_NC_NDOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
12INLINE void CLAMP_QUICK_NC_NDOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
13INLINE void CLAMP_QUICK_NC_DOS_NDOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
14INLINE void CLAMP_QUICK_NC_DOS_DOT(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
15
16INLINE void CLAMP_C(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
17INLINE void CLAMP_LIGHT_C(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
18INLINE void CLAMP_QUICK_C(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
19
20static void (*rdp_clamp_func[8])(INT32*, INT32*, INT32*, INT32*, INT32, INT32, TILE*) =
21{
22   CLAMP_NC_NDOS_NDOT,      CLAMP_NC_NDOS_DOT,      CLAMP_NC_DOS_NDOT,      CLAMP_NC_DOS_DOT,
23   CLAMP_C,            CLAMP_C,            CLAMP_C,            CLAMP_C,
24};
25
26static void (*rdp_clamp_light_func[8])(INT32*, INT32*, INT32, INT32, TILE*) =
27{
28   CLAMP_LIGHT_NC_NDOS_NDOT,   CLAMP_LIGHT_NC_NDOS_DOT,   CLAMP_LIGHT_NC_DOS_NDOT,   CLAMP_LIGHT_NC_DOS_DOT,
29   CLAMP_LIGHT_C,            CLAMP_LIGHT_C,            CLAMP_LIGHT_C,            CLAMP_LIGHT_C,
30};
31
32static void (*rdp_clamp_quick_func[8])(INT32*, INT32*, INT32, INT32, int) =
33{
34   CLAMP_QUICK_NC_NDOS_NDOT,   CLAMP_QUICK_NC_NDOS_DOT,   CLAMP_QUICK_NC_DOS_NDOT,   CLAMP_QUICK_NC_DOS_DOT,
35   CLAMP_QUICK_C,            CLAMP_QUICK_C,            CLAMP_QUICK_C,            CLAMP_QUICK_C,
36};
src/mame/video/rdpupd16.c
r7675r7676
1#if defined(FSAA)
2   #if defined(DIVOT)
3      static void video_update_n64_16_fsaa_divot(bitmap_t *bitmap)
4   #else
5      static void video_update_n64_16_fsaa_nodivot(bitmap_t *bitmap)
6   #endif
7#else
8   #if defined(DIVOT)
9      static void video_update_n64_16_nofsaa_divot(bitmap_t *bitmap)
10   #else
11      static void video_update_n64_16_nofsaa_nodivot(bitmap_t *bitmap)
12   #endif
13#endif
14{
15   int i, j;
16#if defined(DIVOT)
17   UINT32 prev_cvg = 0, next_cvg = 0;
18#endif
19    //int dither_filter = (n64_vi_control >> 16) & 1;
20    //int vibuffering = ((n64_vi_control & 2) && fsaa && divot);
21
22   UINT16 *frame_buffer;
23   UINT32 hb;
24   UINT8* hidden_buffer;
25
26   UINT32 pixels = 0;
27   UINT16 pix = 0;
28
29   INT32 hdiff = (n64_vi_hstart & 0x3ff) - ((n64_vi_hstart >> 16) & 0x3ff);
30   float hcoeff = ((float)(n64_vi_xscale & 0xfff) / (1 << 10));
31   UINT32 hres = ((float)hdiff * hcoeff);
32   INT32 invisiblewidth = n64_vi_width - hres;
33
34   INT32 vdiff = ((n64_vi_vstart & 0x3ff) - ((n64_vi_vstart >> 16) & 0x3ff)) >> 1;
35   float vcoeff = ((float)(n64_vi_yscale & 0xfff) / (1 << 10));
36   UINT32 vres = ((float)vdiff * vcoeff);
37
38   if (vdiff <= 0 || hdiff <= 0)
39   {
40      return;
41   }
42
43   frame_buffer = (UINT16*)&rdram[(n64_vi_origin & 0xffffff) >> 2];
44   hb = ((n64_vi_origin & 0xffffff) >> 2) >> 1;
45   hidden_buffer = &hidden_bits[hb];
46
47   if (hres > 640) // Needed by Top Gear Overdrive (E)
48   {
49      invisiblewidth += (hres - 640);
50      hres = 640;
51   }
52
53   pixels = 0;
54
55   if (frame_buffer)
56   {
57      for (j=0; j < vres; j++)
58      {
59         UINT32 *d = BITMAP_ADDR32(bitmap, j, 0);
60
61         for (i=0; i < hres; i++)
62         {
63            COLOR c;
64            //int r, g, b;
65
66            pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
67            curpixel_cvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3);
68
69#if defined(DIVOT)
70            if (i > 0 && i < (hres - 1))
71            {
72               prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
73               next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
74            }
75#endif
76            c.c = rgb16_to_32_lut[pix];
77            //r = ((pix >> 8) & 0xf8) | (pix >> 13);
78            //g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
79            //b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
80
81#if defined(FSAA)
82            //if (/*!vibuffering &&*/ curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2))
83            //{
84               //video_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR],&hidden_buffer[pixels ^ BYTE_ADDR_XOR], n64_vi_width);
85            //}
86#endif
87            //else if (dither_filter && curpixel_cvg == 7 && i > 0 && j > 0 && i < (hres - 1) && j < (vres - 1))
88            //{
89               //if (vibuffering)
90               //{
91               //  restore_filter16_buffer(&r, &g, &b, &ViBuffer[i][j], n64_vi_width);
92               //}
93               //else
94               //{
95                  //restore_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR, n64_vi_width);
96               //}
97            //}
98#if defined(DIVOT)
99            if (i > 0 && i < (hres - 1) && (curpixel_cvg != 7 || prev_cvg != 7 || next_cvg != 7))
100            {
101               //if (vibuffering)
102               //{
103               //  divot_filter16_buffer(&r, &g, &b, &ViBuffer[i][j]);
104               //}
105               //else
106               //{
107                  //divot_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR);
108               //}
109            }
110#endif
111
112            /*
113                if (gamma_dither)
114                {
115                    dith = mame_rand(screen->machine) & 0x3f;
116                }
117                if (gamma)
118                {
119                    if (gamma_dither)
120                    {
121                        r = gamma_dither_table[(r << 6)|dith];
122                        g = gamma_dither_table[(g << 6)|dith];
123                        b = gamma_dither_table[(b << 6)|dith];
124                    }
125                    else
126                    {
127                        r = gamma_table[r];
128                        g = gamma_table[g];
129                        b = gamma_table[b];
130                    }
131                }
132                else if (gamma_dither)
133                {
134                    if (r < 255)
135                        r += (dith & 1);
136                    if (g < 255)
137                        g += (dith & 1);
138                    if (b < 255)
139                        b += (dith & 1);
140                }
141                */
142            pixels++;
143
144            d[i] = c.c >> 8;//(r << 16) | (g << 8) | b; // Fix me for endianness
145         }
146         pixels +=invisiblewidth;
147      }
148   }
149}
src/mame/video/rdpfiltr.c
r0r7676
1INLINE void video_filter16(int *out_r, int *out_g, int *out_b, UINT16* vbuff, UINT8* hbuff, const UINT32 hres);
2INLINE void divot_filter16(UINT8* r, UINT8* g, UINT8* b, UINT16* fbuff, UINT32 fbuff_index);
3INLINE void restore_filter16(INT32* r, INT32* g, INT32* b, UINT16* fbuff, UINT32 fbuff_index, UINT32 hres);
4INLINE void divot_filter16_buffer(INT32* r, INT32* g, INT32* b, N64::RDP::Color* vibuffer);
5INLINE void restore_filter16_buffer(INT32* r, INT32* g, INT32* b, N64::RDP::Color* vibuff, UINT32 hres);
6INLINE void restore_two(N64::RDP::Color* filtered, N64::RDP::Color* neighbour);
7INLINE void video_max(UINT32* Pixels, UINT8* max, UINT32* enb);
8INLINE UINT32 ge_two(UINT32 enb);
9
10INLINE void video_filter16(int *out_r, int *out_g, int *out_b, UINT16* vbuff, UINT8* hbuff, const UINT32 hres)
11{
12   N64::RDP::Color penumax, penumin, max, min;
13   UINT16 pix = *vbuff;
14   const UINT8 centercvg = (*hbuff & 3) + ((pix & 1) << 2) + 1;
15   UINT32 numoffull = 1;
16   UINT32 cvg;
17   UINT32 backr[7], backg[7], backb[7];
18   UINT32 invr[7], invg[7], invb[7];
19   INT32 coeff;
20   INT32 leftup = -hres - 2;
21   INT32 leftdown = hres - 2;
22   INT32 toleft = -2;
23   UINT32 colr, colg, colb;
24   UINT32 enb;
25   UINT32 r = ((pix >> 8) & 0xf8) | (pix >> 13);
26   UINT32 g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
27   UINT32 b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
28
29   *out_r = *out_g = *out_b = 0;
30
31   backr[0] = r;
32   backg[0] = g;
33   backb[0] = b;
34   invr[0] = ~r;
35   invg[0] = ~g;
36   invb[0] = ~b;
37
38   if (centercvg == 8)
39   {
40      *out_r = r;
41      *out_g = g;
42      *out_b = b;
43      return;
44   }
45
46   for(int i = 0; i < 5; i++)
47   {
48      pix = vbuff[leftup ^ WORD_ADDR_XOR];
49      cvg = hbuff[leftup ^ BYTE_ADDR_XOR] & 3;
50      if(i & 1)
51      {
52         if (cvg == 3 && (pix & 1))
53         {
54            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
55            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
56            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
57            invr[numoffull] = ~backr[numoffull];
58            invg[numoffull] = ~backg[numoffull];
59            invb[numoffull] = ~backb[numoffull];
60         }
61         else
62         {
63                backr[numoffull] = invr[numoffull] = 0;
64            backg[numoffull] = invg[numoffull] = 0;
65            backb[numoffull] = invb[numoffull] = 0;
66         }
67         numoffull++;
68      }
69      leftup++;
70   }
71
72   for(int i = 0; i < 5; i++)
73   {
74      pix = vbuff[leftdown ^ WORD_ADDR_XOR];
75      cvg = hbuff[leftdown ^ BYTE_ADDR_XOR] & 3;
76      if (i&1)
77      {
78         if (cvg == 3 && (pix & 1))
79         {
80            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
81            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
82            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
83            invr[numoffull] = ~backr[numoffull];
84            invg[numoffull] = ~backg[numoffull];
85            invb[numoffull] = ~backb[numoffull];
86         }
87         else
88         {
89                backr[numoffull] = invr[numoffull] = 0;
90            backg[numoffull] = invg[numoffull] = 0;
91            backb[numoffull] = invb[numoffull] = 0;
92         }
93         numoffull++;
94      }
95      leftdown++;
96   }
97
98   for(int i = 0; i < 5; i++)
99   {
100      pix = vbuff[toleft ^ WORD_ADDR_XOR];
101      cvg = hbuff[toleft ^ BYTE_ADDR_XOR] & 3;
102      if (!(i&3))
103      {
104         if (cvg == 3 && (pix & 1))
105         {
106            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
107            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
108            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
109            invr[numoffull] = ~backr[numoffull];
110            invg[numoffull] = ~backg[numoffull];
111            invb[numoffull] = ~backb[numoffull];
112         }
113         else
114         {
115                backr[numoffull] = invr[numoffull] = 0;
116            backg[numoffull] = invg[numoffull] = 0;
117            backb[numoffull] = invb[numoffull] = 0;
118         }
119         numoffull++;
120      }
121      toleft++;
122   }
123
124   video_max(&backr[0], &max.i.r, &enb);
125   for(int i = 1; i < 7; i++)
126   {
127      if (!((enb >> i) & 1))
128      {
129         backr[i] = 0;
130      }
131   }
132   video_max(&backg[0], &max.i.g, &enb);
133   for (int i = 1; i < 7; i++)
134   {
135      if (!((enb >> i) & 1))
136      {
137         backg[i] = 0;
138      }
139   }
140   video_max(&backb[0], &max.i.b, &enb);
141   for (int i = 1; i < 7; i++)
142   {
143      if (!((enb >> i) & 1))
144      {
145         backb[i] = 0;
146      }
147   }
148   video_max(&invr[0], &min.i.r, &enb);
149   for (int i = 1; i < 7; i++)
150   {
151      if (!((enb >> i) & 1))
152      {
153         backr[i] = 0;
154      }
155   }
156   video_max(&invg[0], &min.i.g, &enb);
157   for (int i = 1; i < 7; i++)
158   {
159      if (!((enb >> i) & 1))
160      {
161         backg[i] = 0;
162      }
163   }
164   video_max(&invb[0], &min.i.b, &enb);
165   for (int i = 1; i < 7; i++)
166   {
167      if (!((enb >> i) & 1))
168      {
169         backb[i] = 0;
170      }
171   }
172
173   video_max(&backr[0], &penumax.i.r, &enb);
174   penumax.i.r = ge_two(enb) ? max.i.r : penumax.i.r;
175
176   video_max(&backg[0], &penumax.i.g, &enb);
177   penumax.i.g = ge_two(enb) ? max.i.g : penumax.i.g;
178
179   video_max(&backb[0], &penumax.i.b, &enb);
180   penumax.i.b = ge_two(enb) ? max.i.b : penumax.i.b;
181
182   video_max(&invr[0], &penumin.i.r, &enb);
183   penumin.i.r = ge_two(enb) ? min.i.r : penumin.i.r;
184
185   video_max(&invg[0], &penumin.i.g, &enb);
186   penumin.i.g = ge_two(enb) ? min.i.g : penumin.i.g;
187
188   video_max(&invb[0], &penumin.i.b, &enb);
189   penumin.i.b = ge_two(enb) ? min.i.b : penumin.i.b;
190
191   penumin.i.r = ~penumin.i.r;
192   penumin.i.g = ~penumin.i.g;
193   penumin.i.b = ~penumin.i.b;
194
195   colr = (UINT32)penumin.i.r + (UINT32)penumax.i.r - (r << 1);
196   colg = (UINT32)penumin.i.g + (UINT32)penumax.i.g - (g << 1);
197   colb = (UINT32)penumin.i.b + (UINT32)penumax.i.b - (b << 1);
198   coeff = 8 - centercvg;
199   colr = (((colr * coeff) + 4) >> 3) + r;
200   colg = (((colg * coeff) + 4) >> 3) + g;
201   colb = (((colb * coeff) + 4) >> 3) + b;
202
203   *out_r = colr & 0xff;
204   *out_g = colg & 0xff;
205   *out_b = colb & 0xff;
206   return;
207}
208
209// This needs to be fixed for endianness.
210INLINE void divot_filter16(UINT8* r, UINT8* g, UINT8* b, UINT16* fbuff, UINT32 fbuff_index)
211{
212   UINT8 leftr, leftg, leftb, rightr, rightg, rightb;
213   UINT16 leftpix, rightpix;
214   UINT16* next, *prev;
215   UINT32 Lsw = fbuff_index & 1;
216   next = (Lsw) ? (UINT16*)(fbuff - 1) : (UINT16*)(fbuff + 3);
217   prev = (Lsw) ? (UINT16*)(fbuff - 3) : (UINT16*)(fbuff + 1);
218   leftpix = *prev;
219   rightpix = *next;
220
221   //leftpix = *(fbuff - 1); //for BE targets
222   //rightpix = *(fbuff + 1);
223
224   leftr = ((leftpix >> 8) & 0xf8) | (leftpix >> 13);
225   leftg = ((leftpix >> 3) & 0xf8) | ((leftpix >>  8) & 0x07);
226   leftb = ((leftpix << 2) & 0xf8) | ((leftpix >>  3) & 0x07);
227   rightr = ((rightpix >> 8) & 0xf8) | (rightpix >> 13);
228   rightg = ((rightpix >> 3) & 0xf8) | ((rightpix >>  8) & 0x07);
229   rightb = ((rightpix << 2) & 0xf8) | ((rightpix >>  3) & 0x07);
230   if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr))
231   {
232      *r = leftr; //left = median value
233   }
234   if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr))
235   {
236      *r = rightr; //right = median, else *r itself is median
237   }
238   if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg))
239   {
240      *g = leftg;
241   }
242   if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg))
243   {
244      *g = rightg;
245   }
246   if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb))
247   {
248      *b = leftb;
249   }
250   if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb))
251   {
252      *b = rightb;
253   }
254}
255
256INLINE void divot_filter16_buffer(int* r, int* g, int* b, N64::RDP::Color* vibuffer)
257{
258   N64::RDP::Color leftpix = vibuffer[-1];
259   N64::RDP::Color rightpix = vibuffer[1];
260   N64::RDP::Color filtered = *vibuffer;
261
262   *r = filtered.i.r;
263   *g = filtered.i.g;
264   *b = filtered.i.b;
265   UINT32 leftr = leftpix.i.r;
266   UINT32 leftg = leftpix.i.g;
267   UINT32 leftb = leftpix.i.b;
268   UINT32 rightr = rightpix.i.r;
269   UINT32 rightg = rightpix.i.g;
270   UINT32 rightb = rightpix.i.b;
271
272   if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr))
273   {
274      *r = leftr; //left = median value
275   }
276   if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr))
277   {
278      *r = rightr; //right = median, else *r itself is median
279   }
280   if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg))
281   {
282      *g = leftg;
283   }
284   if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg))
285   {
286      *g = rightg;
287   }
288   if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb))
289   {
290      *b = leftb;
291   }
292   if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb))
293   {
294      *b = rightb;
295   }
296
297   filtered.i.r = *r;
298   filtered.i.g = *g;
299   filtered.i.b = *b;
300}
301
302// Fix me.
303INLINE void restore_filter16(int* r, int* g, int* b, UINT16* fbuff, UINT32 fbuff_index, UINT32 hres)
304{
305   INT32 leftuppix = -hres - 1;
306   INT32 leftdownpix = hres - 1;
307   INT32 toleftpix = -1;
308   UINT8 tempr, tempg, tempb;
309   UINT16 pix;
310   int i;
311
312   UINT8 r5 = *r;
313   UINT8 g5 = *g;
314   UINT8 b5 = *b;
315   r5 &= ~7;
316   g5 &= ~7;
317   b5 &= ~7;
318
319   for (i = 0; i < 3; i++)
320   {
321      pix = fbuff[leftuppix ^ 1];
322      tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
323      tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
324      tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
325      tempr &= ~7;
326      tempg &= ~7;
327      tempb &= ~7;
328      if (tempr > r5)
329      {
330         *r += 1;
331      }
332      if (tempr < r5)
333      {
334         *r -= 1;
335      }
336      if (tempg > g5)
337      {
338         *g += 1;
339      }
340      if (tempg < g5)
341      {
342         *g -= 1;
343      }
344      if (tempb > b5)
345      {
346         *b += 1;
347      }
348      if (tempb < b5)
349      {
350         *b -= 1;
351      }
352      leftuppix++;
353   }
354
355   for (i = 0; i < 3; i++)
356   {
357      pix = fbuff[leftdownpix ^ 1];
358      tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
359      tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
360      tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
361      tempr &= ~7;
362      tempg &= ~7;
363      tempb &= ~7;
364      if (tempr > r5)
365      {
366         *r += 1;
367      }
368      if (tempr < r5)
369      {
370         *r -= 1;
371      }
372      if (tempg > g5)
373      {
374         *g += 1;
375      }
376      if (tempg < g5)
377      {
378         *g -= 1;
379      }
380      if (tempb > b5)
381      {
382         *b += 1;
383      }
384      if (tempb < b5)
385      {
386         *b -= 1;
387      }
388      leftdownpix++;
389   }
390   for(i = 0; i < 3; i++)
391   {
392      if (!(i & 1))
393      {
394         pix = fbuff[toleftpix ^ 1];
395         tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
396         tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
397         tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
398         tempr &= ~7;
399         tempg &= ~7;
400         tempb &= ~7;
401         if (tempr > r5)
402         {
403            *r += 1;
404         }
405         if (tempr < r5)
406         {
407            *r -= 1;
408         }
409         if (tempg > g5)
410         {
411            *g += 1;
412         }
413         if (tempg < g5)
414         {
415            *g -= 1;
416         }
417         if (tempb > b5)
418         {
419            *b += 1;
420         }
421         if (tempb < b5)
422         {
423            *b -= 1;
424         }
425      }
426      toleftpix++;
427   }
428}
429
430INLINE void restore_filter16_buffer(INT32* r, INT32* g, INT32* b, N64::RDP::Color* vibuff, UINT32 hres)
431{
432   N64::RDP::Color filtered;
433   N64::RDP::Color leftuppix, leftdownpix, leftpix;
434   N64::RDP::Color rightuppix, rightdownpix, rightpix;
435   N64::RDP::Color uppix, downpix;
436   INT32 ihres = (INT32)hres; //can't apply unary minus to unsigned
437
438   leftuppix = vibuff[-ihres - 1];
439   leftdownpix = vibuff[ihres - 1];
440   leftpix = vibuff[-1];
441
442   rightuppix = vibuff[-ihres + 1];
443   rightdownpix = vibuff[ihres + 1];
444   rightpix = vibuff[1];
445
446   uppix = vibuff[-ihres];
447   downpix = vibuff[ihres];
448   filtered = *vibuff;
449
450   restore_two(&filtered, &leftuppix);
451   restore_two(&filtered, &uppix);
452   restore_two(&filtered, &rightuppix);
453
454   restore_two(&filtered, &leftpix);
455   restore_two(&filtered, &rightpix);
456
457   restore_two(&filtered, &leftdownpix);
458   restore_two(&filtered, &downpix);
459   restore_two(&filtered, &rightdownpix);
460
461   *r = filtered.i.r;
462   *g = filtered.i.g;
463   *b = filtered.i.b;
464
465   if(*r < 0) *r = 0;
466   else if(*r > 255) *r = 255;
467   if(*g < 0) *g = 0;
468   else if(*g > 255) *g = 255;
469   if(*b < 0) *b = 0;
470   else if(*b > 255) *b = 255;
471}
472
473// This is wrong, only the 5 upper bits are compared.
474INLINE void restore_two(N64::RDP::Color* filtered, N64::RDP::Color* neighbour)
475{
476   if (neighbour->i.r > filtered->i.r)
477   {
478      filtered->i.r += 1;
479   }
480   if (neighbour->i.r < filtered->i.r)
481   {
482      filtered->i.r -= 1;
483   }
484   if (neighbour->i.g > filtered->i.g)
485   {
486      filtered->i.g += 1;
487   }
488   if (neighbour->i.g < filtered->i.g)
489   {
490      filtered->i.g -= 1;
491   }
492   if (neighbour->i.b > filtered->i.b)
493   {
494      filtered->i.b += 1;
495   }
496   if (neighbour->i.b < filtered->i.b)
497   {
498      filtered->i.b -= 1;
499   }
500}
501
502INLINE void video_max(UINT32* Pixels, UINT8* max, UINT32* enb)
503{
504    int i;
505    int pos = 0;
506    *enb = 0;
507    for(i = 0; i < 7; i++)
508    {
509        if (Pixels[i] > Pixels[pos])
510        {
511            *enb += (1 << i);
512            pos = i;
513        }
514        else if (Pixels[i] < Pixels[pos])
515        {
516            *enb += (1 << i);
517        }
518        else
519        {
520            pos = i;
521        }
522    }
523    *max = Pixels[pos];
524}
525
526INLINE UINT32 ge_two(UINT32 enb)
527{
528   if(enb & 1)
529   {
530      if(enb & 2)
531         return 1;
532      if(enb & 4)
533         return 1;
534      if(enb & 8)
535         return 1;
536      if(enb & 16)
537         return 1;
538      if(enb & 32)
539         return 1;
540      if(enb & 64)
541         return 1;
542      if(enb & 128)
543         return 1;
544      return 0;
545   }
546   else if(enb & 2)
547   {
548      if(enb & 4)
549         return 1;
550      if(enb & 8)
551         return 1;
552      if(enb & 16)
553         return 1;
554      if(enb & 32)
555         return 1;
556      if(enb & 64)
557         return 1;
558      if(enb & 128)
559         return 1;
560      return 0;
561   }
562   else if(enb & 4)
563   {
564      if(enb & 8)
565         return 1;
566      if(enb & 16)
567         return 1;
568      if(enb & 32)
569         return 1;
570      if(enb & 64)
571         return 1;
572      if(enb & 128)
573         return 1;
574      return 0;
575   }
576   else if(enb & 8)
577   {
578      if(enb & 16)
579         return 1;
580      if(enb & 32)
581         return 1;
582      if(enb & 64)
583         return 1;
584      if(enb & 128)
585         return 1;
586      return 0;
587   }
588   else if(enb & 16)
589   {
590      if(enb & 32)
591         return 1;
592      if(enb & 64)
593         return 1;
594      if(enb & 128)
595         return 1;
596      return 0;
597   }
598   else if(enb & 32)
599   {
600      if(enb & 64)
601         return 1;
602      if(enb & 128)
603         return 1;
604      return 0;
605   }
606   else if(enb & 64)
607   {
608      if(enb & 128)
609         return 1;
610      return 0;
611   }
612   return 0;
613}
src/mame/video/rdpfrect.c
r7675r7676
1#if defined(MAGICDITHER)
2   static void fill_rectangle_16bit_c1_dm(RECTANGLE *rect)
3#elif defined(BAYERDITHER)
4   static void fill_rectangle_16bit_c1_db(RECTANGLE *rect)
5#else
6   static void fill_rectangle_16bit_c1_dn(RECTANGLE *rect)
7#endif
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
4
5namespace N64
86{
9   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
10   UINT8* hb = &hidden_bits[fb_address >> 1];
117
8namespace RDP
9{
10
11#define LookUpCC(A, B, C, D) m_rdp->GetCCLUT2()[(m_rdp->GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
12
13void Rectangle::SetMachine(running_machine* machine)
14{
15   _n64_state *state = (_n64_state *)machine->driver_data;
16
17   m_machine = machine;
18   m_rdp = &state->m_rdp;
19   m_misc_state = m_rdp->GetMiscState();
20   m_other_modes = m_rdp->GetOtherModes();
21   m_blender = m_rdp->GetBlender();
22}
23
24void Rectangle::Draw()
25{
26   switch(m_other_modes->cycle_type)
27   {
28      case CYCLE_TYPE_1:
29         Draw1Cycle();
30         return;
31
32      case CYCLE_TYPE_2:
33         Draw2Cycle();
34         return;
35
36      case CYCLE_TYPE_FILL:
37         DrawFill();
38         return;
39
40      default:
41         fatalerror("Unsupported cycle type for Textured Rectangle: %d\n", m_other_modes->cycle_type);
42         return;
43   }
44}
45
46void Rectangle::Draw1Cycle()
47{
48   UINT16 *fb = (UINT16*)&rdram[(m_misc_state->m_fb_address / 4)];
49   UINT8* hb = &m_rdp->GetHiddenBits()[m_misc_state->m_fb_address >> 1];
50
1251   int index, i, j;
13   int x1 = rect->xh;
14   int x2 = rect->xl;
15   int y1 = rect->yh;
16   int y2 = rect->yl;
17   UINT16 fill_color1, fill_color2;
18   int fill_cvg1;
19   int fill_cvg2;
52   int x1 = m_xh;
53   int x2 = m_xl;
54   int y1 = m_yh;
55   int y2 = m_yl;
56   UINT16 fill_color1 = (m_rdp->GetFillColor32() >> 16) & 0xffff;
57   UINT16 fill_color2 = (m_rdp->GetFillColor32() >>  0) & 0xffff;
58   int fill_cvg1 = (fill_color1 & 1) ? 8 : 1;
59   int fill_cvg2 = (fill_color2 & 1) ? 8 : 1;
2060
2161   if (x2 <= x1)
2262   {
r7675r7676
2767      y2=y1+1; // Goldeneye
2868   }
2969
30
31   fill_color1 = (fill_color >> 16) & 0xffff;
32   fill_color2 = (fill_color >>  0) & 0xffff;
33   fill_cvg1 = (fill_color1 & 1) ? 8 : 1;
34   fill_cvg2 = (fill_color2 & 1) ? 8 : 1;
35
3670   // clip
37   if (x1 < clip.xh)
71   if (x1 < m_rdp->GetScissor()->m_xh)
3872   {
39      x1 = clip.xh;
73      x1 = m_rdp->GetScissor()->m_xh;
4074   }
41   if (y1 < clip.yh)
75   if (y1 < m_rdp->GetScissor()->m_yh)
4276   {
43      y1 = clip.yh;
77      y1 = m_rdp->GetScissor()->m_yh;
4478   }
45   if (x2 >= clip.xl)
79   if (x2 >= m_rdp->GetScissor()->m_xl)
4680   {
47      x2 = clip.xl - 1;
81      x2 = m_rdp->GetScissor()->m_xl - 1;
4882   }
49   if (y2 >= clip.yl)
83   if (y2 >= m_rdp->GetScissor()->m_yl)
5084   {
51      y2 = clip.yl - 1;
85      y2 = m_rdp->GetScissor()->m_yl - 1;
5286   }
5387
54   shade_color.c = 0;   // Needed by Command & Conquer menus
88   m_rdp->GetShadeColor()->c = 0;   // Needed by Command & Conquer menus
5589
56#if defined(MAGIC_DITHER)
57   for (j = y1; j <= y2; j++)
90   if(m_other_modes->rgb_dither_sel == 0)
5891   {
59      COLOR c;
60      int dith = 0;
61      index = j * fb_width;
62      for (i = x1; i <= x2; i++)
92      for (int j = y1; j <= y2; j++)
6393      {
64         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
65         COLOR_COMBINER1(c);
66         dith = magic_matrix[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
67         BLENDER1_16_DITH(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c, dith);
94         Color c1;
95         int dith = 0;
96         index = j * m_misc_state->m_fb_width;
97         for (i = x1; i <= x2; i++)
98         {
99            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
100
101            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
102                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
103                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
104                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
105            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
106                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
107                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
108                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
109            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
110                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
111                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
112                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
113            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
114                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
115                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
116                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
117            m_rdp->GetAlphaCvg(&c1.i.a);
118
119            dith = m_rdp->GetMagicMatrix()[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
120
121            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, *m_rdp->GetZero(), dith);
122         }
68123      }
69124   }
70#elif defined(BAYER_DITHER)
71   for (j = y1; j <= y2; j++)
125   else if(m_other_modes->rgb_dither_sel == 1)
72126   {
73      COLOR c;
74      int dith = 0;
75      index = j * fb_width;
76      for (i = x1; i <= x2; i++)
127      for (j = y1; j <= y2; j++)
77128      {
78         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
79         COLOR_COMBINER1(c);
80         dith = bayer_matrix[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
81         BLENDER1_16_DITH(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c, dith);
129         Color c1;
130         int dith = 0;
131         index = j * m_misc_state->m_fb_width;
132         for (i = x1; i <= x2; i++)
133         {
134            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
135
136            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
137                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
138                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
139                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
140            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
141                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
142                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
143                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
144            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
145                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
146                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
147                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
148            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
149                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
150                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
151                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
152            m_rdp->GetAlphaCvg(&c1.i.a);
153
154            dith = m_rdp->GetBayerMatrix()[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
155            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, *m_rdp->GetZero(), dith);
156         }
82157      }
83158   }
84#else
85   for (j = y1; j <= y2; j++)
159   else
86160   {
87      COLOR c;
88      index = j * fb_width;
89      for (i = x1; i <= x2; i++)
161      for (j = y1; j <= y2; j++)
90162      {
91         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
92         COLOR_COMBINER1(c);
93         BLENDER1_16_NDITH(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c);
163         Color c1;
164         index = j * m_misc_state->m_fb_width;
165         for (i = x1; i <= x2; i++)
166         {
167            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
168
169            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
170                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
171                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
172                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
173            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
174                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
175                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
176                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
177            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
178                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
179                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
180                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
181            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
182                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
183                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
184                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
185            m_rdp->GetAlphaCvg(&c1.i.a);
186
187            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, *m_rdp->GetZero(), 0);
188         }
94189      }
95190   }
96#endif
97191}
98192
99#if defined(MAGICDITHER)
100   static void fill_rectangle_16bit_c2_dm(RECTANGLE *rect)
101#elif defined(BAYERDITHER)
102   static void fill_rectangle_16bit_c2_db(RECTANGLE *rect)
103#else
104   static void fill_rectangle_16bit_c2_dn(RECTANGLE *rect)
105#endif
193void Rectangle::Draw2Cycle()
106194{
107   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
108   UINT8* hb = &hidden_bits[fb_address >> 1];
195   UINT16 *fb = (UINT16*)&rdram[(m_misc_state->m_fb_address / 4)];
196   UINT8* hb = &m_rdp->GetHiddenBits()[m_misc_state->m_fb_address >> 1];
109197
110198   int index, i, j;
111   int x1 = rect->xh;
112   int x2 = rect->xl;
113   int y1 = rect->yh;
114   int y2 = rect->yl;
115   UINT16 fill_color1, fill_color2;
199   int x1 = m_xh;
200   int x2 = m_xl;
201   int y1 = m_yh;
202   int y2 = m_yl;
203   UINT16 fill_color1;
204   UINT16 fill_color2;
116205   int fill_cvg1;
117206   int fill_cvg2;
118207
r7675r7676
126215   }
127216
128217
129   fill_color1 = (fill_color >> 16) & 0xffff;
130   fill_color2 = (fill_color >>  0) & 0xffff;
218   fill_color1 = (m_rdp->GetFillColor32() >> 16) & 0xffff;
219   fill_color2 = (m_rdp->GetFillColor32() >>  0) & 0xffff;
131220   fill_cvg1 = (fill_color1 & 1) ? 8 : 1;
132221   fill_cvg2 = (fill_color2 & 1) ? 8 : 1;
133222
134223   // clip
135   if (x1 < clip.xh)
224   if (x1 < m_rdp->GetScissor()->m_xh)
136225   {
137      x1 = clip.xh;
226      x1 = m_rdp->GetScissor()->m_xh;
138227   }
139   if (y1 < clip.yh)
228   if (y1 < m_rdp->GetScissor()->m_yh)
140229   {
141      y1 = clip.yh;
230      y1 = m_rdp->GetScissor()->m_yh;
142231   }
143   if (x2 >= clip.xl)
232   if (x2 >= m_rdp->GetScissor()->m_xl)
144233   {
145      x2 = clip.xl - 1;
234      x2 = m_rdp->GetScissor()->m_xl - 1;
146235   }
147   if (y2 >= clip.yl)
236   if (y2 >= m_rdp->GetScissor()->m_yl)
148237   {
149      y2 = clip.yl - 1;
238      y2 = m_rdp->GetScissor()->m_yl - 1;
150239   }
151240
152   shade_color.c = 0;   // Needed by Command & Conquer menus
241   m_rdp->GetShadeColor()->c = 0;   // Needed by Command & Conquer menus
153242
154#if defined(MAGIC_DITHER)
155   for (j=y1; j <= y2; j++)
243   if(m_other_modes->rgb_dither_sel == 0)
156244   {
157      COLOR c1, c2;
158      int dith = 0;
159      index = j * fb_width;
160      for (i=x1; i <= x2; i++)
245      for (j=y1; j <= y2; j++)
161246      {
162         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
163         COLOR_COMBINER2_C0(c1);
164         COLOR_COMBINER2_C1(c2);
165         dith = magic_matrix[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
166         BLENDER2_16_DITH(&fb[(index + i) ^ WORD_ADDR_XOR],  &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2, dith);
247         Color c1;
248         Color c2;
249         int dith = 0;
250         index = j * m_misc_state->m_fb_width;
251         for (i=x1; i <= x2; i++)
252         {
253            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
254
255            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
256                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
257                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
258                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
259            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
260                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
261                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
262                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
263            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
264                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
265                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
266                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
267            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
268                          *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
269                          *m_rdp->GetColorInputs()->combiner_alphamul[0],
270                          *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
271            m_rdp->GetCombinedColor()->c = c1.c;
272            c2.c = m_rdp->GetTexel0Color()->c;
273            m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
274            m_rdp->GetTexel1Color()->c = c2.c;
275            c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
276                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
277                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
278                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
279            c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
280                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
281                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
282                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
283            c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
284                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
285                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
286                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
287            c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
288                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
289                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
290                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
291            m_rdp->GetAlphaCvg(&c2.i.a);
292
293            dith = m_rdp->GetMagicMatrix()[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
294            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2, dith);
295         }
167296      }
168297   }
169#elif defined(BAYER_DITHER)
170   for (j=y1; j <= y2; j++)
298   else if(m_other_modes->rgb_dither_sel == 1)
171299   {
172      COLOR c1, c2;
173      int dith = 0;
174      index = j * fb_width;
175      for (i=x1; i <= x2; i++)
300      for (j=y1; j <= y2; j++)
176301      {
177         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
178         COLOR_COMBINER2_C0(c1);
179         COLOR_COMBINER2_C1(c2);
180         dith = bayer_matrix[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
181         BLENDER2_16_DITH(&fb[(index + i) ^ WORD_ADDR_XOR],  &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2, dith);
302         Color c1;
303         Color c2;
304         int dith = 0;
305         index = j * m_misc_state->m_fb_width;
306         for (i=x1; i <= x2; i++)
307         {
308            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
309
310            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
311                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
312                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
313                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
314            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
315                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
316                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
317                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
318            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
319                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
320                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
321                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
322            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
323                          *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
324                          *m_rdp->GetColorInputs()->combiner_alphamul[0],
325                          *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
326            m_rdp->GetCombinedColor()->c = c1.c;
327            c2.c = m_rdp->GetTexel0Color()->c;
328            m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
329            m_rdp->GetTexel1Color()->c = c2.c;
330            c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
331                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
332                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
333                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
334            c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
335                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
336                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
337                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
338            c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
339                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
340                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
341                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
342            c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
343                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
344                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
345                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
346            m_rdp->GetAlphaCvg(&c2.i.a);
347
348            dith = m_rdp->GetBayerMatrix()[(((j) & 3) << 2) + ((i ^ WORD_ADDR_XOR) & 3)];
349            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2, dith);
350         }
182351      }
183352   }
184#else
185   for (j=y1; j <= y2; j++)
353   else
186354   {
187      COLOR c1, c2;
188      index = j * fb_width;
189      for (i=x1; i <= x2; i++)
355      for (j=y1; j <= y2; j++)
190356      {
191         curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
192         COLOR_COMBINER2_C0(c1);
193         COLOR_COMBINER2_C1(c2);
194         BLENDER2_16_NDITH(&fb[(index + i) ^ WORD_ADDR_XOR],  &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2);
357         Color c1, c2;
358         index = j * m_misc_state->m_fb_width;
359         for (i=x1; i <= x2; i++)
360         {
361            m_misc_state->m_curpixel_cvg = (i & 1) ? fill_cvg1 : fill_cvg2;
362
363            c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
364                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
365                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
366                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
367            c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
368                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
369                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
370                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
371            c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
372                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
373                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
374                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
375            c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
376                          *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
377                          *m_rdp->GetColorInputs()->combiner_alphamul[0],
378                          *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
379            m_rdp->GetCombinedColor()->c = c1.c;
380            c2.c = m_rdp->GetTexel0Color()->c;
381            m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
382            m_rdp->GetTexel1Color()->c = c2.c;
383            c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
384                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
385                          *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
386                          *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
387            c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
388                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
389                          *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
390                          *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
391            c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
392                          *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
393                          *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
394                          *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
395            c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
396                          *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
397                          *m_rdp->GetColorInputs()->combiner_alphamul[1],
398                          *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
399            m_rdp->GetAlphaCvg(&c2.i.a);
400
401            m_blender->Blend(&fb[(index + i) ^ WORD_ADDR_XOR], &hb[(index + i) ^ BYTE_ADDR_XOR], c1, c2, 0);
402         }
195403      }
196404   }
197#endif
198405}
199406
200#if defined(MAGICDITHER)
201static void fill_rectangle_16bit_cc(RECTANGLE *rect)
407void Rectangle::DrawFill()
202408{
203   fatalerror("fill_rectangle_16bit: cycle type copy");
204}
205#endif
409   UINT16 *fb = (UINT16*)&rdram[(m_misc_state->m_fb_address / 4)];
410   UINT8* hb = &m_rdp->GetHiddenBits()[m_misc_state->m_fb_address >> 1];
206411
207#if defined(MAGICDITHER)
208static void fill_rectangle_16bit_cf(RECTANGLE *rect)
209{
210   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
211   UINT8* hb = &hidden_bits[fb_address >> 1];
212
213412   int index, i, j;
214   int x1 = rect->xh;
215   int x2 = rect->xl;
216   int y1 = rect->yh;
217   int y2 = rect->yl;
218   UINT16 fill_color1, fill_color2;
413   int x1 = m_xh;
414   int x2 = m_xl;
415   int y1 = m_yh;
416   int y2 = m_yl;
417   UINT16 fill_color1;
418   UINT16 fill_color2;
219419   int fill_cvg1;
220420   int fill_cvg2;
221421
r7675r7676
229429   }
230430
231431
232   fill_color1 = (fill_color >> 16) & 0xffff;
233   fill_color2 = (fill_color >>  0) & 0xffff;
432   fill_color1 = (m_rdp->GetFillColor32() >> 16) & 0xffff;
433   fill_color2 = (m_rdp->GetFillColor32() >>  0) & 0xffff;
234434   fill_cvg1 = (fill_color1 & 1) ? 8 : 1;
235435   fill_cvg2 = (fill_color2 & 1) ? 8 : 1;
236436
237437   // clip
238   if (x1 < clip.xh)
438   if (x1 < m_rdp->GetScissor()->m_xh)
239439   {
240      x1 = clip.xh;
440      x1 = m_rdp->GetScissor()->m_xh;
241441   }
242   if (y1 < clip.yh)
442   if (y1 < m_rdp->GetScissor()->m_yh)
243443   {
244      y1 = clip.yh;
444      y1 = m_rdp->GetScissor()->m_yh;
245445   }
246   if (x2 >= clip.xl)
446   if (x2 >= m_rdp->GetScissor()->m_xl)
247447   {
248      x2 = clip.xl - 1;
448      x2 = m_rdp->GetScissor()->m_xl - 1;
249449   }
250   if (y2 >= clip.yl)
450   if (y2 >= m_rdp->GetScissor()->m_yl)
251451   {
252      y2 = clip.yl - 1;
452      y2 = m_rdp->GetScissor()->m_yl - 1;
253453   }
254454
255   shade_color.c = 0;   // Needed by Command & Conquer menus
455   m_rdp->GetShadeColor()->c = 0;   // Needed by Command & Conquer menus
256456
257457   fill_cvg1 = (fill_color1 & 1) ? 3 : 0;
258458   fill_cvg2 = (fill_color2 & 1) ? 3 : 0;
r7675r7676
261461   {
262462      for (j=y1; j <= y2; j++)
263463      {
264         index = j * fb_width;
464         index = j * m_misc_state->m_fb_width;
265465         for (i=x1; i <= x2; i += 2)
266466         {
267467            int curpixel = index + i;
r7675r7676
271471      }
272472      for (j=y1; j <= y2; j++)
273473      {
274         index = j * fb_width;
474         index = j * m_misc_state->m_fb_width;
275475         for (i=x1+1; i <= x2; i += 2)
276476         {
277477            int curpixel = index + i;
r7675r7676
284484   {
285485      for (j=y1; j <= y2; j++)
286486      {
287         index = j * fb_width;
487         index = j * m_misc_state->m_fb_width;
288488         for (i=x1; i <= x2; i += 2)
289489         {
290490            int curpixel = index + i;
r7675r7676
294494      }
295495      for (j=y1; j <= y2; j++)
296496      {
297         index = j * fb_width;
497         index = j * m_misc_state->m_fb_width;
298498         for (i=x1+1; i <= x2; i += 2)
299499         {
300500            int curpixel = index + i;
r7675r7676
304504      }
305505   }
306506}
307#endif
507
508} // namespace RDP
509
510} // namespace N64
src/mame/video/rdpfrect.h
r7675r7676
1static void fill_rectangle_16bit_c1_dm(RECTANGLE *rect);
2static void fill_rectangle_16bit_c1_db(RECTANGLE *rect);
3static void fill_rectangle_16bit_c1_dn(RECTANGLE *rect);
4static void fill_rectangle_16bit_c2_dm(RECTANGLE *rect);
5static void fill_rectangle_16bit_c2_db(RECTANGLE *rect);
6static void fill_rectangle_16bit_c2_dn(RECTANGLE *rect);
7static void fill_rectangle_16bit_cc(RECTANGLE *rect);
8static void fill_rectangle_16bit_cf(RECTANGLE *rect);
1#ifndef _VIDEO_RDPFILLRECT_H_
2#define _VIDEO_RDPFILLRECT_H_
93
10static void (*rdp_fill_rectangle_16bit_func[16])(RECTANGLE *) =
4#include "emu.h"
5#include "video/rdpblend.h"
6
7namespace N64
118{
12   fill_rectangle_16bit_c1_dm, fill_rectangle_16bit_c1_db, fill_rectangle_16bit_c1_dn, fill_rectangle_16bit_c1_dn,
13   fill_rectangle_16bit_c2_dm, fill_rectangle_16bit_c2_db, fill_rectangle_16bit_c2_dn, fill_rectangle_16bit_c2_dn,
14   fill_rectangle_16bit_cc,   fill_rectangle_16bit_cc,   fill_rectangle_16bit_cc,   fill_rectangle_16bit_cc,
15   fill_rectangle_16bit_cf,   fill_rectangle_16bit_cf,   fill_rectangle_16bit_cf,   fill_rectangle_16bit_cf,
9
10namespace RDP
11{
12
13class OtherModes;
14class MiscState;
15class Processor;
16class Blender;
17class Color;
18
19class Rectangle
20{
21   public:
22      Rectangle() {}
23      Rectangle(running_machine *machine, UINT32 *data)
24      {
25         SetMachine(machine);
26         InitFromBuffer(data);
27      }
28
29      void Draw();
30      void SetMachine(running_machine *machine);
31      void InitFromBuffer(UINT32 *data);
32
33      UINT16 m_xl;   // 10.2 fixed-point
34      UINT16 m_yl;   // 10.2 fixed-point
35      UINT16 m_xh;   // 10.2 fixed-point
36      UINT16 m_yh;   // 10.2 fixed-point
37
38   private:
39      void             Draw1Cycle();
40      void             Draw2Cycle();
41      void             DrawFill();
42
43      running_machine*   m_machine;
44      Processor*         m_rdp;
45      MiscState*         m_misc_state;
46      OtherModes*         m_other_modes;
47      Blender*         m_blender;
1648};
49
50} // namespace RDP
51
52} // namespace N64
53
54#endif // _VIDEO_RDPFILLRECT_H_
No newline at end of file
src/mame/video/rdpfetch.c
r7675r7676
1INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_EN0(UINT32 s, UINT32 t)
2{
3   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
4   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
5   return rgb16_to_32_lut[tlut[((cached_tpal | p) ^ WORD_ADDR_XOR) << 2]];
6}
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
74
8INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_EN1(UINT32 s, UINT32 t)
5namespace N64
96{
10   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
11   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
12   return ia8_to_32_lut[tlut[((cached_tpal | p) ^ WORD_ADDR_XOR) << 2]];
13}
147
15INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_NEN(UINT32 s, UINT32 t)
8namespace RDP
169{
17   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
18   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
1910
20   return (cached_tpal | p) * 0x01010101;
21}
22
23INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_EN0(UINT32 s, UINT32 t)
11void TexFetch::SetMachine(running_machine *machine)
2412{
25   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
26   return rgb16_to_32_lut[tlut[(TMEM[taddr ^ BYTE_ADDR_XOR] ^ WORD_ADDR_XOR) << 2]];
27}
13   _n64_state *state = (_n64_state *)machine->driver_data;
2814
29INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_EN1(UINT32 s, UINT32 t)
30{
31   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
32   return ia8_to_32_lut[tlut[(TMEM[taddr ^ BYTE_ADDR_XOR] ^ WORD_ADDR_XOR) << 2]];
15   m_machine = machine;
16   m_rdp = &state->m_rdp;
17   m_other_modes = m_rdp->GetOtherModes();
18   m_misc_state = m_rdp->GetMiscState();
19   m_tiles = m_rdp->GetTiles();
3320}
3421
35INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_NEN(UINT32 s, UINT32 t)
22UINT32 TexFetch::Fetch(UINT32 s, UINT32 t, Tile* tile)
3623{
37   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
38   return TMEM[taddr ^ BYTE_ADDR_XOR] * 0x01010101;
39}
24   UINT32 tformat = tile->format;
4025
41INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_EN0(UINT32 s, UINT32 t)
42{
43   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
44   return rgb16_to_32_lut[tlut[(TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR] >> 8) << 2]];
45}
26   if (t < 0) t = 0;
27   if (s < 0) s = 0;
4628
47INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_EN1(UINT32 s, UINT32 t)
48{
49   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
50   return ia8_to_32_lut[tlut[(TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR] >> 8) << 2]];
51}
29   switch (tformat)
30   {
31      case 0:      // RGBA
32         return FetchRGBA(s, t, tile);
5233
53INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_NEN(UINT32 s, UINT32 t)
54{
55   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
56   return rgb16_to_32_lut[TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR]];
57}
34      case 1:      // YUV: Bottom of the 9th, Pokemon Stadium, Ogre Battle 64
35         return FetchYUV(s, t, tile);
5836
59INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_EN0(UINT32 s, UINT32 t)
60{
61   int xorval = (fb_size == PIXEL_SIZE_16BIT) ? XOR_SWAP_WORD : XOR_SWAP_DWORD; // Conker's Bad Fur Day, Jet Force Gemini, Super Smash Bros., Mickey's Speedway USA, Ogre Battle, Wave Race, Gex 3, South Park Rally
62   UINT32 taddr = (((cached_tbase >> 2) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) ? xorval : 0)) & 0x3ff;
37      case 2:      // Color Index
38         return FetchCI(s, t, tile);
6339
64   return rgb16_to_32_lut[tlut[(TMEM32[taddr] >> 24) << 2]];
65}
40      case 3:      // Intensity + Alpha
41         return FetchIA(s, t, tile);
6642
67INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_EN1(UINT32 s, UINT32 t)
68{
69   int xorval = (fb_size == PIXEL_SIZE_16BIT) ? XOR_SWAP_WORD : XOR_SWAP_DWORD; // Conker's Bad Fur Day, Jet Force Gemini, Super Smash Bros., Mickey's Speedway USA, Ogre Battle, Wave Race, Gex 3, South Park Rally
70   UINT32 taddr = (((cached_tbase >> 2) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) ? xorval : 0)) & 0x3ff;
43      case 4:      // Intensity
44         return FetchI(s, t, tile);
7145
72   return ia8_to_32_lut[tlut[(TMEM32[taddr] >> 24) << 2]];
73}
74
75INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_NEN(UINT32 s, UINT32 t)
76{
77   int xorval = (fb_size == PIXEL_SIZE_16BIT) ? XOR_SWAP_WORD : XOR_SWAP_DWORD; // Conker's Bad Fur Day, Jet Force Gemini, Super Smash Bros., Mickey's Speedway USA, Ogre Battle, Wave Race, Gex 3, South Park Rally
78   UINT32 taddr = (((cached_tbase >> 2) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) ? xorval : 0)) & 0x3ff;
79
80   return TMEM32[taddr];
81}
82
83INLINE UINT32 FETCH_TEXEL_YUV16(UINT32 s, UINT32 t)
84{   // YUV: Bottom of the 9th, Pokemon Stadium, Ogre Battle 64
85   INT32 newr = 0;
86   INT32 newg = 0;
87   INT32 newb = 0;
88   UINT32 taddr = ((cached_tbase >> 1) + ((t) * (cached_twidth)) + s) ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
89   UINT32 c1, c2;
90   INT32 y;
91   INT32 u, v;
92   c1 = TMEM16[taddr ^ WORD_ADDR_XOR];
93   c2 = TMEM16[taddr]; // other word
94
95   if (!(taddr & 1))
96   {
97      v = c2 >> 8;
98      u = c1 >> 8;
99      y = c1 & 0xff;
46      default:
47         fatalerror("FETCH_TEXEL: unknown texture format %d\n", tformat);
48         return 0xffffffff;
10049   }
101   else
102   {
103      v = c1 >> 8;
104      u = c2 >> 8;
105      y = c1 & 0xff;
106   }
107   v -= 128;
108   u -= 128;
10950
110   if (!other_modes.bi_lerp0)
111   {
112      newr = y + ((k0 * v) >> 8);
113      newg = y + ((k1 * u) >> 8) + ((k2 * v) >> 8);
114      newb = y + ((k3 * u) >> 8);
115   }
116
117   return (((newr < 0) ? 0 : ((newr > 0xff) ? 0xff : newr)) << 24) |
118          (((newg < 0) ? 0 : ((newg > 0xff) ? 0xff : newg)) << 16) |
119          (((newb < 0) ? 0 : ((newb > 0xff) ? 0xff : newb)) <<  8) |
120          0xff;
51   return 0;
12152}
12253
123INLINE UINT32 FETCH_TEXEL_CI4_TLUT_EN0(UINT32 s, UINT32 t)
54UINT32 TexFetch::FetchRGBA(UINT32 s, UINT32 t, Tile* tile)
12455{
125   UINT32 b = TMEM[(((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff) ^ BYTE_ADDR_XOR];
126   return rgb16_to_32_lut[tlut[(cached_tpal | ((b >> ((s & 1) << 2)) & 0xf)) << 2]];
127}
56   UINT32 twidth   = tile->line;
57   UINT32 tbase =   tile->tmem;
58   UINT32 tpal   = tile->palette & 0xf;
12859
129INLINE UINT32 FETCH_TEXEL_CI4_TLUT_EN1(UINT32 s, UINT32 t)
130{
131   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
132   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
133   return ia8_to_32_lut[tlut[(cached_tpal | p) << 2]];
134}
60   switch (tile->size)
61   {
62      case PIXEL_SIZE_4BIT:
63      {
64         UINT8 *tc = (UINT8*)m_rdp->GetTMEM();
65         int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff;
66         UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4);
67         UINT16 c = m_rdp->GetTLUT()[(((tpal << 4) | p) ^ WORD_ADDR_XOR) << 2];
13568
136INLINE UINT32 FETCH_TEXEL_CI4_TLUT_NEN(UINT32 s, UINT32 t)
137{
138   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
139   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
69         if (m_other_modes->en_tlut)
70         {
71            if (m_other_modes->tlut_type == 0)
72            {
73               return m_rdp->LookUp16To32(c);
74            }
75            else
76            {
77               return m_rdp->LookUpIA8To32(c);
78            }
79         }
80         else
81         {
82            return ((tpal << 4) | p) * 0x01010101;
83         }
84         break;
85      }
86      case PIXEL_SIZE_8BIT:
87      {
88         UINT8 *tc = m_rdp->GetTMEM();
89         int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff;
90         UINT8 p = tc[taddr ^ BYTE_ADDR_XOR];
91         UINT16 c = m_rdp->GetTLUT()[(p ^ WORD_ADDR_XOR) << 2];
14092
141   return (cached_tpal | p) * 0x01010101;
142}
93         if (m_other_modes->en_tlut)
94         {
95            if (m_other_modes->tlut_type == 0)
96            {
97               return m_rdp->LookUp16To32(c);
98            }
99            else
100            {
101               return m_rdp->LookUpIA8To32(c);
102            }
103         }
104         else
105         {
106            return p * 0x01010101;
107         }
108         break;
109      }
110      case PIXEL_SIZE_16BIT:
111      {
112         UINT16 *tc = m_rdp->GetTMEM16();
113         int taddr = ((tbase>>1) + ((t) * (twidth>>1)) + (s))  ^ ((t & 1) ? XOR_SWAP_WORD : 0);
114         UINT16 c = tc[(taddr & 0x7ff) ^ WORD_ADDR_XOR]; // PGA European Tour (U)
143115
144INLINE UINT32 FETCH_TEXEL_CI8_TLUT_EN0(UINT32 s, UINT32 t)
145{
146   return rgb16_to_32_lut[tlut[TMEM[(((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff) ^ BYTE_ADDR_XOR] << 2]];
147}
116         if (!m_other_modes->en_tlut)
117         {
118            return m_rdp->LookUp16To32(c);
119         }
120         else
121         {
122            if (m_other_modes->tlut_type == 0) //Golden Eye 007, sea, "frigate" level
123            {
124               return m_rdp->LookUp16To32(m_rdp->GetTLUT()[(c >> 8) << 2]);
125            }
126            else // Beetle Adventure Racing, Mount Mayhem
127            {
128               return m_rdp->LookUpIA8To32(m_rdp->GetTLUT()[(c >> 8) << 2]);
129            }
130         }
131         break;
132      }
133      case PIXEL_SIZE_32BIT:
134      {
135         UINT32 *tc = m_rdp->GetTMEM32();
136         int xorval = (m_misc_state->m_fb_size == PIXEL_SIZE_16BIT) ? XOR_SWAP_WORD : XOR_SWAP_DWORD; // Conker's Bad Fur Day, Jet Force Gemini, Super Smash Bros., Mickey's Speedway USA, Ogre Battle, Wave Race, Gex 3, South Park Rally
137         int taddr = (((tbase >> 2) + ((t) * (twidth >> 1)) + (s)) ^ ((t & 1) ? xorval : 0)) & 0x3ff;
148138
149INLINE UINT32 FETCH_TEXEL_CI8_TLUT_EN1(UINT32 s, UINT32 t)
150{
151   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
152   return ia8_to_32_lut[tlut[TMEM[taddr ^ BYTE_ADDR_XOR] << 2]];
139         if (!m_other_modes->en_tlut)
140         {
141            return tc[taddr];
142         }
143         else
144         {
145            if (!m_other_modes->tlut_type)
146            {
147               return m_rdp->LookUp16To32(m_rdp->GetTLUT()[(tc[taddr] >> 24) << 2]);
148            }
149            else
150            {
151               return m_rdp->LookUpIA8To32(m_rdp->GetTLUT()[(tc[taddr] >> 24) << 2]);
152            }
153         }
154         break;
155      }
156      default:
157         fatalerror("FETCH_TEXEL: unknown RGBA texture size %d\n", tile->size);
158         return 0xffffffff;
159   }
153160}
154161
155INLINE UINT32 FETCH_TEXEL_CI8_TLUT_NEN(UINT32 s, UINT32 t)
162UINT32 TexFetch::FetchYUV(UINT32 s, UINT32 t, Tile* tile)
156163{
157   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0x7ff;
158   return TMEM[taddr ^ BYTE_ADDR_XOR] * 0x01010101;
159}
164   UINT32 twidth   = tile->line;
165   UINT32 tsize =   tile->size;
166   UINT32 tbase =   tile->tmem;
167   Color out;
160168
161INLINE UINT32 FETCH_TEXEL_CI16_TLUT_EN0(UINT32 s, UINT32 t)
162{   // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA
163   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
164   return rgb16_to_32_lut[tlut[(TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR] >> 8) << 2]];
165}
169   out.c = 0;
166170
167INLINE UINT32 FETCH_TEXEL_CI16_TLUT_EN1(UINT32 s, UINT32 t)
168{   // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA
169   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
170   return ia8_to_32_lut[tlut[(TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR] >> 8) << 2]]; // Beetle Adventure Racing, Mount Mayhem
171}
171   if(tsize == PIXEL_SIZE_16BIT)
172   {
173      INT32 newr = 0;
174      INT32 newg = 0;
175      INT32 newb = 0;
176      UINT16 *tc = m_rdp->GetTMEM16();
177      int taddr = ((tbase >> 1) + ((t) * (twidth)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0);
178      UINT16 c1, c2;
179      INT32 y;
180      INT32 u, v;
181      c1 = tc[taddr ^ WORD_ADDR_XOR];
182      c2 = tc[taddr]; // other word
172183
173INLINE UINT32 FETCH_TEXEL_CI16_TLUT_NEN(UINT32 s, UINT32 t)
174{   // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA
175   UINT32 taddr = ((cached_tbase_s1) + ((t) * (cached_twidth_s1)) + s)  ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
176   return rgb16_to_32_lut[TMEM16[(taddr & 0x7ff) ^ WORD_ADDR_XOR]]; // PGA European Tour (U)
177}
184      if (!(taddr & 1))
185      {
186         v = c2 >> 8;
187         u = c1 >> 8;
188         y = c1 & 0xff;
189      }
190      else
191      {
192         v = c1 >> 8;
193         u = c2 >> 8;
194         y = c1 & 0xff;
195      }
196      v -= 128;
197      u -= 128;
178198
179INLINE UINT32 FETCH_TEXEL_IA4_TLUT_EN0(UINT32 s, UINT32 t)
180{
181   UINT32 taddr = (cached_tbase + ((t) * cached_twidth) + (s >> 1)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT);
182   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
183   return rgb16_to_32_lut[tlut[(cached_tpal | p) << 2]];
184}
199      if (!m_other_modes->bi_lerp0)
200      {
201         newr = y + ((m_rdp->GetK0() * v) >> 8);
202         newg = y + ((m_rdp->GetK1() * u) >> 8) + ((m_rdp->GetK2() * v) >> 8);
203         newb = y + ((m_rdp->GetK2() * u) >> 8);
204      }
205      out.i.r = (newr < 0) ? 0 : ((newr > 0xff) ? 0xff : newr);
206      out.i.g = (newg < 0) ? 0 : ((newg > 0xff) ? 0xff : newg);
207      out.i.b = (newb < 0) ? 0 : ((newb > 0xff) ? 0xff : newb);
208      out.i.a = 0xff;
209   }
185210
186INLINE UINT32 FETCH_TEXEL_IA4_TLUT_EN1(UINT32 s, UINT32 t)
187{
188   UINT32 taddr = (cached_tbase + ((t) * cached_twidth) + (s >> 1)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT);
189   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
190   return ia8_to_32_lut[tlut[(cached_tpal | p) << 2]];
211   return out.c;
191212}
192213
193INLINE UINT32 FETCH_TEXEL_IA4_TLUT_NEN(UINT32 s, UINT32 t)
214UINT32 TexFetch::FetchCI(UINT32 s, UINT32 t, Tile* tile)
194215{
195   UINT32 taddr = (cached_tbase + ((t) * cached_twidth) + (s >> 1)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT);
196   UINT32 p = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
197   UINT32 i = ((p & 0xe) << 4) | ((p & 0xe) << 1) | (p & 0xe >> 2);
216   UINT32 twidth = tile->line;
217   UINT32 tsize =   tile->size;
218   UINT32 tbase =   tile->tmem;
219   UINT32 tpal   = tile->palette & 0xf;
198220
199   return (i * 0x01010100) | ((p & 0x1) & 0xff);
200}
221   switch (tsize)
222   {
223      case PIXEL_SIZE_4BIT:
224      {
225         UINT8 *tc = m_rdp->GetTMEM();
226         int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff;
227         UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4);
228         UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2];
201229
202INLINE UINT32 FETCH_TEXEL_IA8_TLUT_EN0(UINT32 s, UINT32 t)
203{
204   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
205   return rgb16_to_32_lut[tlut[TMEM[taddr ^ BYTE_ADDR_XOR] << 2]];
206}
230         if (m_other_modes->en_tlut)
231         {
232            if (m_other_modes->tlut_type == 0)
233            {
234               return m_rdp->LookUp16To32(c);
235            }
236            else
237            {
238               return m_rdp->LookUpIA8To32(c);
239            }
240         }
241         else
242         {
243            return ((tpal << 4) | p) * 0x01010101;
244         }
245         break;
246      }
247      case PIXEL_SIZE_8BIT:
248      {
249         UINT8 *tc = m_rdp->GetTMEM();
250         int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0x7ff;
251         UINT8 p = tc[taddr ^ BYTE_ADDR_XOR];
252         UINT16 c = m_rdp->GetTLUT()[p << 2];
207253
208INLINE UINT32 FETCH_TEXEL_IA8_TLUT_EN1(UINT32 s, UINT32 t)
209{
210   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
211   return ia8_to_32_lut[tlut[TMEM[taddr ^ BYTE_ADDR_XOR] << 2]];
212}
254         if (m_other_modes->en_tlut)
255         {
256            if (m_other_modes->tlut_type == 0)
257            {
258               return m_rdp->LookUp16To32(c);
259            }
260            else
261            {
262               return m_rdp->LookUpIA8To32(c);
263            }
264         }
265         else
266         {
267            return p * 0x01010101;
268         }
269         break;
270      }
271      case PIXEL_SIZE_16BIT:
272      {
273         // 16-bit CI is a "valid" mode; some games use it, it behaves the same as 16-bit RGBA
274         UINT16 *tc = m_rdp->GetTMEM16();
275         int taddr = ((tbase>>1) + ((t) * (twidth>>1)) + (s))  ^ ((t & 1) ? XOR_SWAP_WORD : 0);
276         UINT16 c = tc[(taddr & 0x7ff) ^ WORD_ADDR_XOR]; // PGA European Tour (U)
213277
214INLINE UINT32 FETCH_TEXEL_IA8_TLUT_NEN(UINT32 s, UINT32 t)
215{
216   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
217   UINT32 p = TMEM[taddr ^ BYTE_ADDR_XOR];
218   UINT32 i = (p >> 4) | (p & 0xf0);
278         if (!m_other_modes->en_tlut)
279         {
280            return m_rdp->LookUp16To32(c);
281         }
282         else
283         {
284            if (!m_other_modes->tlut_type) // GoldenEye 007, sea, "frigate" level
285            {
286               return m_rdp->LookUp16To32(m_rdp->GetTLUT()[(c >> 8) << 2]);
287            }
288            else // Beetle Adventure Racing, Mount Mayhem
289            {
290               return m_rdp->LookUpIA8To32(m_rdp->GetTLUT()[(c >> 8) << 2]);
291            }
292         }
293         break;
294      }
219295
220   return (i * 0x01010100) | ((p & 0xf) | ((p << 4) & 0xf0));
221}
296      default:
297         fatalerror("FETCH_TEXEL: unknown CI texture size %d\n", tsize);
298         return 0xffffffff;
299   }
222300
223INLINE UINT32 FETCH_TEXEL_IA16_TLUT_EN0(UINT32 s, UINT32 t)
224{
225   UINT32 taddr = ((cached_tbase >> 1) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
226   return rgb16_to_32_lut[tlut[(TMEM16[taddr ^ WORD_ADDR_XOR] >> 8) << 2]];
301   return 0;
227302}
228303
229INLINE UINT32 FETCH_TEXEL_IA16_TLUT_EN1(UINT32 s, UINT32 t)
304UINT32 TexFetch::FetchIA(UINT32 s, UINT32 t, Tile* tile)
230305{
231   UINT32 taddr = ((cached_tbase >> 1) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
232   return ia8_to_32_lut[tlut[(TMEM16[taddr ^ WORD_ADDR_XOR] >> 8) << 2]];
233}
306   UINT32 twidth = tile->line;
307   UINT32 tsize =   tile->size;
308   UINT32 tbase =   tile->tmem;
309   UINT32 tpal   = tile->palette & 0xf;
234310
235INLINE UINT32 FETCH_TEXEL_IA16_TLUT_NEN(UINT32 s, UINT32 t)
236{
237   UINT32 taddr = ((cached_tbase >> 1) + ((t) * (cached_twidth >> 1)) + s) ^ ((t & 1) << XOR_SWAP_WORD_SHIFT);
238   UINT32 c = TMEM16[taddr ^ WORD_ADDR_XOR];
311   switch (tsize)
312   {
313      case PIXEL_SIZE_4BIT:
314      {
315         UINT8 *tc = m_rdp->GetTMEM();
316         int taddr = (tbase + ((t) * twidth) + (s >> 1)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0);
317         UINT8 p = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4);
318         UINT8 i = ((p & 0xe) << 4) | ((p & 0xe) << 1) | (p & 0xe >> 2);
239319
240   return ((c >> 8) * 0x01010100) | (c & 0xff);
241}
320         if (!m_other_modes->en_tlut)
321         {
322            return (i * 0x01010100) | ((p & 0x1) ? 0xff : 0);
323         }
324         else
325         {
326            UINT16 c = m_rdp->GetTLUT()[((tpal << 4) | p) << 2];
327            if (!m_other_modes->tlut_type)
328            {
329               return m_rdp->LookUp16To32(c);
330            }
331            else
332            {
333               return m_rdp->LookUpIA8To32(c);
334            }
335         }
336         break;
337      }
338      case PIXEL_SIZE_8BIT:
339      {
340         UINT8 *tc = m_rdp->GetTMEM();
341         int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff;
342         UINT8 p = tc[taddr ^ BYTE_ADDR_XOR];
242343
243INLINE UINT32 FETCH_TEXEL_I4_TLUT_EN0(UINT32 s, UINT32 t)
244{
245   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
246   UINT32 c = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
247   c |= (c << 4);
344         if (!m_other_modes->en_tlut)
345         {
346            UINT8 i = (p >> 4) | (p & 0xf0);
347            return (i * 0x01010100) | ((p & 0xf) | ((p << 4) & 0xf0));
348         }
349         else
350         {
351            UINT16 c = m_rdp->GetTLUT()[p << 2];
352            if (!m_other_modes->tlut_type)
353            {
354               return m_rdp->LookUp16To32(c);
355            }
356            else
357            {
358               return m_rdp->LookUpIA8To32(c);
359            }
360         }
361         break;
362      }
363      case PIXEL_SIZE_16BIT:
364      {
365         UINT16 *tc = m_rdp->GetTMEM16();
366         int taddr = ((tbase >> 1) + ((t) * (twidth >> 1)) + (s)) ^ ((t & 1) ? XOR_SWAP_WORD : 0);
367         UINT16 c = tc[taddr ^ WORD_ADDR_XOR];
248368
249   return rgb16_to_32_lut[tlut[(cached_tpal | c) << 2]];
250}
369         if (m_other_modes->en_tlut)
370         {
371            c = m_rdp->GetTLUT()[(c >> 8) << 2];
372            if (m_other_modes->tlut_type == 0)
373            {
374               return m_rdp->LookUp16To32(c);
375            }
376            else
377            {
378               return m_rdp->LookUpIA8To32(c);
379            }
380         }
381         else
382         {
383            return m_rdp->LookUpIA8To32(c);
384         }
251385
252INLINE UINT32 FETCH_TEXEL_I4_TLUT_EN1(UINT32 s, UINT32 t)
253{
254   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
255   UINT32 c = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
256   c |= (c << 4);
386         break;
387      }
388      default:
389         return 0xffffffff;
390         fatalerror("FETCH_TEXEL: unknown IA texture size %d\n", tsize);
391         break;
392   }
257393
258   return ia8_to_32_lut[tlut[(cached_tpal | c) << 2]];
394   return 0;
259395}
260396
261INLINE UINT32 FETCH_TEXEL_I4_TLUT_NEN(UINT32 s, UINT32 t)
397UINT32 TexFetch::FetchI(UINT32 s, UINT32 t, Tile* tile)
262398{
263   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + (s / 2)) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
264   UINT32 c = (TMEM[taddr ^ BYTE_ADDR_XOR] >> ((s & 1) << 2)) & 0xf;
265   c |= (c << 4);
399   UINT32 twidth = tile->line;
400   UINT32 tsize =   tile->size;
401   UINT32 tbase =   tile->tmem;
402   UINT32 tpal   = tile->palette & 0xf;
266403
267   return (c * 0x01010101);
268}
404   switch (tsize)
405   {
406      case PIXEL_SIZE_4BIT:
407      {
408         UINT8 *tc = m_rdp->GetTMEM();
409         int taddr = ((tbase + ((t) * twidth) + ((s) / 2)) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff;
410         UINT8 c = ((s) & 1) ? (tc[taddr ^ BYTE_ADDR_XOR] & 0xf) : (tc[taddr ^ BYTE_ADDR_XOR] >> 4);
411         c |= (c << 4);
269412
270INLINE UINT32 FETCH_TEXEL_I8_TLUT_EN0(UINT32 s, UINT32 t)
271{
272   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
273   return rgb16_to_32_lut[tlut[TMEM[taddr ^ BYTE_ADDR_XOR] << 2]];
274}
413         if (!m_other_modes->en_tlut)
414         {
415            return c * 0x01010101;
416         }
417         else
418         {
419            UINT16 k = m_rdp->GetTLUT()[((tpal << 4) | c) << 2];
420            if (!m_other_modes->tlut_type)
421            {
422               return m_rdp->LookUp16To32(k);
423            }
424            else
425            {
426               return m_rdp->LookUpIA8To32(k);
427            }
428         }
429         break;
430      }
431      case PIXEL_SIZE_8BIT:
432      {
433         UINT8 *tc = m_rdp->GetTMEM();
434         int taddr = ((tbase + ((t) * twidth) + ((s))) ^ ((t & 1) ? XOR_SWAP_BYTE : 0)) & 0xfff;
435         UINT8 c = tc[taddr ^ BYTE_ADDR_XOR];
275436
276INLINE UINT32 FETCH_TEXEL_I8_TLUT_EN1(UINT32 s, UINT32 t)
277{
278   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
279   return ia8_to_32_lut[tlut[TMEM[taddr ^ BYTE_ADDR_XOR] << 2]];
280}
437         if (!m_other_modes->en_tlut)
438         {
439            return c * 0x01010101;
440         }
441         else
442         {
443            UINT16 k = m_rdp->GetTLUT()[ c << 2];
444            if (!m_other_modes->tlut_type)
445            {
446               return m_rdp->LookUp16To32(k);
447            }
448            else
449            {
450               return m_rdp->LookUpIA8To32(k);
451            }
452         }
453         break;
454      }
455      default:
456         //fatalerror("FETCH_TEXEL: unknown I texture size %d\n", tsize);
457         return 0xffffffff;
458   }
281459
282INLINE UINT32 FETCH_TEXEL_I8_TLUT_NEN(UINT32 s, UINT32 t)
283{
284   UINT32 taddr = ((cached_tbase + ((t) * cached_twidth) + s) ^ ((t & 1) << XOR_SWAP_BYTE_SHIFT)) & 0xfff;
285   return TMEM[taddr ^ BYTE_ADDR_XOR] * 0x01010101;
286}
287
288INLINE UINT32 FETCH_TEXEL_INVALID(UINT32 s, UINT32 t)
289{
290   printf("Invalid texel mode\n");
291460   return 0;
292461}
293462
294//typedef void (*rdp_fetch_texel_func)(UINT32 s, UINT32 t);
463} // namespace RDP
464
465} // namespace N64
src/mame/video/rdpfetch.h
r7675r7676
1INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_EN0(UINT32 s, UINT32 t);
2INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_EN1(UINT32 s, UINT32 t);
3INLINE UINT32 FETCH_TEXEL_RGBA4_TLUT_NEN(UINT32 s, UINT32 t);
4INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_EN0(UINT32 s, UINT32 t);
5INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_EN1(UINT32 s, UINT32 t);
6INLINE UINT32 FETCH_TEXEL_RGBA8_TLUT_NEN(UINT32 s, UINT32 t);
7INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_EN0(UINT32 s, UINT32 t);
8INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_EN1(UINT32 s, UINT32 t);
9INLINE UINT32 FETCH_TEXEL_RGBA16_TLUT_NEN(UINT32 s, UINT32 t);
10INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_EN0(UINT32 s, UINT32 t);
11INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_EN1(UINT32 s, UINT32 t);
12INLINE UINT32 FETCH_TEXEL_RGBA32_TLUT_NEN(UINT32 s, UINT32 t);
13INLINE UINT32 FETCH_TEXEL_YUV16(UINT32 s, UINT32 t);
14INLINE UINT32 FETCH_TEXEL_CI4_TLUT_EN0(UINT32 s, UINT32 t);
15INLINE UINT32 FETCH_TEXEL_CI4_TLUT_EN1(UINT32 s, UINT32 t);
16INLINE UINT32 FETCH_TEXEL_CI4_TLUT_NEN(UINT32 s, UINT32 t);
17INLINE UINT32 FETCH_TEXEL_CI8_TLUT_EN0(UINT32 s, UINT32 t);
18INLINE UINT32 FETCH_TEXEL_CI8_TLUT_EN1(UINT32 s, UINT32 t);
19INLINE UINT32 FETCH_TEXEL_CI8_TLUT_NEN(UINT32 s, UINT32 t);
20INLINE UINT32 FETCH_TEXEL_CI16_TLUT_EN0(UINT32 s, UINT32 t);
21INLINE UINT32 FETCH_TEXEL_CI16_TLUT_EN1(UINT32 s, UINT32 t);
22INLINE UINT32 FETCH_TEXEL_CI16_TLUT_NEN(UINT32 s, UINT32 t);
23INLINE UINT32 FETCH_TEXEL_IA4_TLUT_EN0(UINT32 s, UINT32 t);
24INLINE UINT32 FETCH_TEXEL_IA4_TLUT_EN1(UINT32 s, UINT32 t);
25INLINE UINT32 FETCH_TEXEL_IA4_TLUT_NEN(UINT32 s, UINT32 t);
26INLINE UINT32 FETCH_TEXEL_IA8_TLUT_EN0(UINT32 s, UINT32 t);
27INLINE UINT32 FETCH_TEXEL_IA8_TLUT_EN1(UINT32 s, UINT32 t);
28INLINE UINT32 FETCH_TEXEL_IA8_TLUT_NEN(UINT32 s, UINT32 t);
29INLINE UINT32 FETCH_TEXEL_IA16_TLUT_EN0(UINT32 s, UINT32 t);
30INLINE UINT32 FETCH_TEXEL_IA16_TLUT_EN1(UINT32 s, UINT32 t);
31INLINE UINT32 FETCH_TEXEL_IA16_TLUT_NEN(UINT32 s, UINT32 t);
32INLINE UINT32 FETCH_TEXEL_I4_TLUT_EN0(UINT32 s, UINT32 t);
33INLINE UINT32 FETCH_TEXEL_I4_TLUT_EN1(UINT32 s, UINT32 t);
34INLINE UINT32 FETCH_TEXEL_I4_TLUT_NEN(UINT32 s, UINT32 t);
35INLINE UINT32 FETCH_TEXEL_I8_TLUT_EN0(UINT32 s, UINT32 t);
36INLINE UINT32 FETCH_TEXEL_I8_TLUT_EN1(UINT32 s, UINT32 t);
37INLINE UINT32 FETCH_TEXEL_I8_TLUT_NEN(UINT32 s, UINT32 t);
38INLINE UINT32 FETCH_TEXEL_INVALID(UINT32 s, UINT32 t);
1#ifndef _VIDEO_RDPFETCH_H_
2#define _VIDEO_RDPFETCH_H_
393
40static UINT32 (*rdp_fetch_texel_func[128])(UINT32, UINT32) =
4#include "emu.h"
5
6namespace N64
417{
42   // 4-bit accessors
43   FETCH_TEXEL_RGBA4_TLUT_NEN, FETCH_TEXEL_RGBA4_TLUT_NEN, FETCH_TEXEL_RGBA4_TLUT_EN0, FETCH_TEXEL_RGBA4_TLUT_EN1,
44   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
45   FETCH_TEXEL_CI4_TLUT_NEN,   FETCH_TEXEL_CI4_TLUT_NEN,   FETCH_TEXEL_CI4_TLUT_EN0,   FETCH_TEXEL_CI4_TLUT_EN1,
46   FETCH_TEXEL_IA4_TLUT_NEN,   FETCH_TEXEL_IA4_TLUT_NEN,   FETCH_TEXEL_IA4_TLUT_EN0,   FETCH_TEXEL_IA4_TLUT_EN1,
47   FETCH_TEXEL_I4_TLUT_NEN,   FETCH_TEXEL_I4_TLUT_NEN,   FETCH_TEXEL_I4_TLUT_EN0,   FETCH_TEXEL_I4_TLUT_EN1,
48   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
49   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
50   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
518
52   // 8-bit accessors
53   FETCH_TEXEL_RGBA8_TLUT_NEN, FETCH_TEXEL_RGBA8_TLUT_NEN, FETCH_TEXEL_RGBA8_TLUT_EN0, FETCH_TEXEL_RGBA8_TLUT_EN1,
54   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
55   FETCH_TEXEL_CI8_TLUT_NEN,   FETCH_TEXEL_CI8_TLUT_NEN,   FETCH_TEXEL_CI8_TLUT_EN0,   FETCH_TEXEL_CI8_TLUT_EN1,
56   FETCH_TEXEL_IA8_TLUT_NEN,   FETCH_TEXEL_IA8_TLUT_NEN,   FETCH_TEXEL_IA8_TLUT_EN0,   FETCH_TEXEL_IA8_TLUT_EN1,
57   FETCH_TEXEL_I8_TLUT_NEN,   FETCH_TEXEL_I8_TLUT_NEN,   FETCH_TEXEL_I8_TLUT_EN0,   FETCH_TEXEL_I8_TLUT_EN1,
58   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
59   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
60   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
9namespace RDP
10{
6111
62   // 16-bit accessors
63   FETCH_TEXEL_RGBA16_TLUT_NEN,FETCH_TEXEL_RGBA16_TLUT_NEN,FETCH_TEXEL_RGBA16_TLUT_EN0,FETCH_TEXEL_RGBA16_TLUT_EN1,
64   FETCH_TEXEL_YUV16,         FETCH_TEXEL_YUV16,         FETCH_TEXEL_YUV16,         FETCH_TEXEL_YUV16,
65   FETCH_TEXEL_CI16_TLUT_NEN,   FETCH_TEXEL_CI16_TLUT_NEN,   FETCH_TEXEL_CI16_TLUT_EN0,   FETCH_TEXEL_CI16_TLUT_EN1,
66   FETCH_TEXEL_IA16_TLUT_NEN,   FETCH_TEXEL_IA16_TLUT_NEN,   FETCH_TEXEL_IA16_TLUT_EN0,   FETCH_TEXEL_IA16_TLUT_EN1,
67   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
68   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
69   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
70   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
12class Processor;
13class OtherModes;
14class MiscState;
15class Tile;
7116
72   // 32-bit accessors
73   FETCH_TEXEL_RGBA32_TLUT_NEN,FETCH_TEXEL_RGBA32_TLUT_NEN,FETCH_TEXEL_RGBA32_TLUT_EN0,FETCH_TEXEL_RGBA32_TLUT_EN1,
74   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
75   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
76   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
77   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
78   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
79   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
80   FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,      FETCH_TEXEL_INVALID,
17class TexFetch
18{
19   public:
20      TexFetch() { }
21
22      UINT32            Fetch(UINT32 s, UINT32 t, Tile* tile);
23
24      void            SetMachine(running_machine* machine);
25
26   private:
27      running_machine*   m_machine;
28      Processor*         m_rdp;
29      OtherModes*         m_other_modes;
30      MiscState*         m_misc_state;
31      Tile*            m_tiles;
32
33      UINT32            FetchRGBA(UINT32 s, UINT32 t, Tile* tile);
34      UINT32            FetchYUV(UINT32 s, UINT32 t, Tile* tile);
35      UINT32            FetchCI(UINT32 s, UINT32 t, Tile* tile);
36      UINT32            FetchIA(UINT32 s, UINT32 t, Tile* tile);
37      UINT32            FetchI(UINT32 s, UINT32 t, Tile* tile);
8138};
39
40} // namespace RDP
41
42} // namespace N64
43
44#endif // _VIDEO_RDPFETCH_H_
src/mame/video/rdptri.h
r7675r7676
1static void triangle_ns_nt_nz(UINT32 w1, UINT32 w2);
2static void triangle_ns_nt_z(UINT32 w1, UINT32 w2);
3static void triangle_ns_t_nz(UINT32 w1, UINT32 w2);
4static void triangle_ns_t_z(UINT32 w1, UINT32 w2);
5static void triangle_s_nt_nz(UINT32 w1, UINT32 w2);
6static void triangle_s_nt_z(UINT32 w1, UINT32 w2);
7static void triangle_s_t_nz(UINT32 w1, UINT32 w2);
8static void triangle_s_t_z(UINT32 w1, UINT32 w2);
1#ifndef _VIDEO_RDPTRI_H_
2#define _VIDEO_RDPTRI_H_
3
4#include "emu.h"
5
6namespace N64
7{
8
9namespace RDP
10{
11
12class MiscState;
13class Processor;
14
15class Triangle
16{
17   public:
18      Triangle() { fatalerror("Please don't use the default constructor for N64::RDP::Triangle\n"); }
19      Triangle(running_machine* machine, bool shade, bool texture, bool zbuffer);
20
21      void InitFromData(running_machine* machine, bool shade, bool texture, bool zbuffer);
22      void Draw();
23
24   private:
25      running_machine*   m_machine;
26      UINT32*            m_cmd_data;
27      MiscState*         m_misc_state;
28      Processor*         m_rdp;
29      bool            m_shade;
30      bool            m_texture;
31      bool            m_zbuffer;
32};
33
34} // namespace RDP
35
36} // namespace N64
37
38#endif // _VIDEO_RDPTRI_H_
No newline at end of file
src/mame/video/rdptpipe.c
r7675r7676
1#define RELATIVE(x, y)   (((((x) >> 3) - (y)) << 3) | (x & 7))
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
24
3   #if defined(COPY)
4      #define CLAMP(SSS, SST, maxs, maxt) \
5         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
6         SST = (SIGN17(SST) >> 5) & 0x1fff;
7   #else
5namespace N64
6{
87
9   #if defined(DOS) && defined(DOT)
10      #define CLAMP(SSS, SST, maxs, maxt) \
11         if (SSS & 0x10000) \
12         { \
13            SSS = 0; \
14            SFRAC = 0; \
15         } \
16         else if (maxs) \
17         { \
18            SSS = clamp_s_diff[tex_tile->num]; \
19            SFRAC = 0; \
20         } \
21         else \
22         { \
23            SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
24         } \
25 \
26         if (SST & 0x10000) \
27         { \
28            SST = 0; \
29            TFRAC = 0; \
30         } \
31         else if (maxt) \
32         { \
33            SST = clamp_t_diff[tex_tile->num]; \
34            TFRAC = 0; \
35         } \
36         else \
37         { \
38            SST = (SIGN17(SST) >> 5) & 0x1fff; \
39         }
40   #elif defined(DOS) && !defined(DOT)
41      #define CLAMP(SSS, SST, maxs, maxt) \
42         if (SSS & 0x10000) \
43         { \
44            SSS = 0; \
45            SFRAC = 0; \
46         } \
47         else if (maxs) \
48         { \
49            SSS = clamp_s_diff[tex_tile->num]; \
50            SFRAC = 0; \
51         } \
52         else \
53         { \
54            SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
55         } \
56 \
57         SST = (SIGN17(SST) >> 5) & 0x1fff;
58   #elif !defined(DOS) && defined(DOT)
59      #define CLAMP(SSS, SST, maxs, maxt) \
60         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
61 \
62         if (SST & 0x10000) \
63         { \
64            SST = 0; \
65            TFRAC = 0; \
66         } \
67         else if (maxt) \
68         { \
69            SST = clamp_t_diff[tex_tile->num]; \
70            TFRAC = 0; \
71         } \
72         else \
73         { \
74            SST = (SIGN17(SST) >> 5) & 0x1fff; \
75         }
76   #else
77      #define CLAMP(SSS, SST, maxs, maxt) \
78         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
79         SST = (SIGN17(SST) >> 5) & 0x1fff;
80   #endif
81   #endif
8namespace RDP
9{
8210
83   #if defined(COPY)
84      #define CLAMP_LIGHT(SSS, SST) \
85         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
86         SST = (SIGN17(SST) >> 5) & 0x1fff;
87   #else
88   #if defined(DOS) && defined(DOT)
89      #define CLAMP_LIGHT(SSS, SST) \
90         if (SSS & 0x10000) \
91         { \
92            SSS = 0; \
93         } \
94         else if (maxs) \
95         { \
96            SSS = clamp_s_diff[tex_tile->num]; \
97         } \
98         else \
99         { \
100            SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
101         } \
102 \
103         if (SST & 0x10000) \
104         { \
105            SST = 0; \
106         } \
107         else if (maxt) \
108         { \
109            SST = clamp_t_diff[tex_tile->num]; \
110         } \
111         else \
112         { \
113            SST = (SIGN17(SST) >> 5) & 0x1fff; \
114         }
115   #elif defined(DOS) && !defined(DOT)
116      #define CLAMP_LIGHT(SSS, SST) \
117         if (SSS & 0x10000) \
118         { \
119            SSS = 0; \
120         } \
121         else if (maxs) \
122         { \
123            SSS = clamp_s_diff[tex_tile->num]; \
124         } \
125         else \
126         { \
127            SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
128         } \
129 \
130         SST = (SIGN17(SST) >> 5) & 0x1fff;
131   #elif !defined(DOS) && defined(DOT)
132      #define CLAMP_LIGHT(SSS, SST) \
133         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
134 \
135         if (SST & 0x10000) \
136         { \
137            SST = 0; \
138         } \
139         else if (maxt) \
140         { \
141            SST = clamp_t_diff[tex_tile->num]; \
142         } \
143         else \
144         { \
145            SST = (SIGN17(SST) >> 5) & 0x1fff; \
146         }
147   #else
148      #define CLAMP_LIGHT(SSS, SST) \
149         SSS = (SIGN17(SSS) >> 5) & 0x1fff; \
150         SST = (SIGN17(SST) >> 5) & 0x1fff;
151   #endif
152   #endif
11#define RELATIVE(x, y)    ((((x) >> 3) - (y)) << 3) | (x & 7);
15312
154   #if defined(SHIFT_S) && defined(SHIFT_T)
155      #define TEXSHIFT(SSS, SST, maxs, maxt) \
156         SSS = SIGN16(SSS); \
157         if (tex_tile->shift_s < 11) \
158         { \
159            SSS >>= tex_tile->shift_s; \
160         } \
161         else \
162         { \
163            SSS <<= (16 - tex_tile->shift_s); \
164         } \
165         SSS = SIGN16(SSS); \
166         SST = SIGN16(SST); \
167         if (tex_tile->shift_t < 11) \
168         { \
169            SST >>= tex_tile->shift_t; \
170         } \
171         else \
172         { \
173            SST <<= (16 - tex_tile->shift_t); \
174         } \
175         SST = SIGN16(SST); \
176         maxs = ((SSS >> 3) >= tex_tile->sh); \
177         maxt = ((SST >> 3) >= tex_tile->th);
178   #elif defined(SHIFT_S) && !defined(SHIFT_T)
179      #define TEXSHIFT(SSS, SST, maxs, maxt) \
180         SSS = SIGN16(SSS); \
181         if (tex_tile->shift_s < 11) \
182         { \
183            SSS >>= tex_tile->shift_s; \
184         } \
185         else \
186         { \
187            SSS <<= (16 - tex_tile->shift_s); \
188         } \
189         SSS = SIGN16(SSS); \
190         maxs = ((SSS >> 3) >= tex_tile->sh); \
191         maxt = ((SST >> 3) >= tex_tile->th);
192   #elif !defined(SHIFT_S) && defined(SHIFT_T)
193      #define TEXSHIFT(SSS, SST, maxs, maxt) \
194         SST = SIGN16(SST); \
195         if (tex_tile->shift_t < 11) \
196         { \
197            SST >>= tex_tile->shift_t; \
198         } \
199         else \
200         { \
201            SST <<= (16 - tex_tile->shift_t); \
202         } \
203         SST = SIGN16(SST); \
204         maxs = ((SSS >> 3) >= tex_tile->sh); \
205         maxt = ((SST >> 3) >= tex_tile->th);
206   #else
207      #define TEXSHIFT(SSS, SST, maxs, maxt) \
208         maxs = ((SSS >> 3) >= tex_tile->sh); \
209         maxt = ((SST >> 3) >= tex_tile->th);
210   #endif
13void TexturePipe::SetMachine(running_machine *machine)
14{
15   _n64_state *state = (_n64_state *)machine->driver_data;
21116
212#if defined(SHIFT_T)
213   #if defined(SHIFT_S)
214      #if defined(DOT)
215         #if defined(DOS)
216            #if defined(COPY)
217               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
218            #else
219               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
220            #endif
221         #else
222            #if defined(COPY)
223               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
224            #else
225               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
226            #endif
227         #endif
228      #else
229         #if defined(DOS)
230            #if defined(COPY)
231               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
232            #else
233               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
234            #endif
235         #else
236            #if defined(COPY)
237               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
238            #else
239               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
240            #endif
241         #endif
242      #endif
243   #else
244      #if defined(DOT)
245         #if defined(DOS)
246            #if defined(COPY)
247               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
248            #else
249               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
250            #endif
251         #else
252            #if defined(COPY)
253               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
254            #else
255               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
256            #endif
257         #endif
258      #else
259         #if defined(DOS)
260            #if defined(COPY)
261               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
262            #else
263               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
264            #endif
265         #else
266            #if defined(COPY)
267               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
268            #else
269               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
270            #endif
271         #endif
272      #endif
273   #endif
274#else
275   #if defined(SHIFT_S)
276      #if defined(DOT)
277         #if defined(DOS)
278            #if defined(COPY)
279               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
280            #else
281               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
282            #endif
283         #else
284            #if defined(COPY)
285               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
286            #else
287               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
288            #endif
289         #endif
290      #else
291         #if defined(DOS)
292            #if defined(COPY)
293               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
294            #else
295               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
296            #endif
297         #else
298            #if defined(COPY)
299               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
300            #else
301               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
302            #endif
303         #endif
304      #endif
305   #else
306      #if defined(DOT)
307         #if defined(DOS)
308            #if defined(COPY)
309               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
310            #else
311               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
312            #endif
313         #else
314            #if defined(COPY)
315               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
316            #else
317               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
318            #endif
319         #endif
320      #else
321         #if defined(DOS)
322            #if defined(COPY)
323               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
324            #else
325               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
326            #endif
327         #else
328            #if defined(COPY)
329               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
330            #else
331               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
332            #endif
333         #endif
334      #endif
335   #endif
336#endif
17   m_machine = machine;
18   m_rdp = &state->m_rdp;
19   m_other_modes = m_rdp->GetOtherModes();
20
21   m_tex_fetch.SetMachine(m_machine);
22}
23
24void TexturePipe::CalculateClampDiffs(UINT32 prim_tile)
33725{
338   INT32 maxs, maxt;
339   int sss2 = SSS + 32;
340   int sst2 = SST + 32;
26   int start;
27   int end;
28   if (m_other_modes->tex_lod_en || prim_tile == 7)
29   {
30      start = 0;
31      end = 7;
32   }
33   else
34   {
35      start = prim_tile;
36      end = prim_tile + 1;
37   }
38   for (; start <= end; start++)
39   {
40      m_clamp_s_diff[start] = (m_rdp->GetTiles()[start].sh >> 2) - (m_rdp->GetTiles()[start].sl >> 2);
41      m_clamp_t_diff[start] = (m_rdp->GetTiles()[start].th >> 2) - (m_rdp->GetTiles()[start].tl >> 2);
42   }
43}
34144
342   TEXSHIFT(SSS, SST, maxs, maxt)
45void TexturePipe::Mask(INT32* S, INT32* T, Tile* tile)
46{
47   INT32 swrap, twrap;
34348
344   SSS = RELATIVE(SSS, tex_tile->sl);
345   SST = RELATIVE(SST, tex_tile->tl);
346   sss2 = RELATIVE(sss2, tex_tile->sl);
347   sst2 = RELATIVE(sst2, tex_tile->tl);
49   if (tile->mask_s) // Select clamp if mask == 0
50   {
51      swrap = *S >> (tile->mask_s > 10 ? 10 : tile->mask_s);
52      swrap &= 1;
53      if (tile->ms && swrap)
54      {
55         *S = (~(*S)) & m_maskbits_table[tile->mask_s]; // Mirroring and masking
56      }
57      else if (tile->mask_s)
58      {
59         *S &= m_maskbits_table[tile->mask_s]; // Masking
60      }
61   }
34862
349   INT32 SFRAC = SSS & 0x1f;
350   INT32 TFRAC = SST & 0x1f;
63   if (tile->mask_t)
64   {
65      twrap = *T >> (tile->mask_t > 10 ? 10 : tile->mask_t);
66      twrap &= 1;
67      if (tile->mt && twrap)
68      {
69         *T = (~(*T)) & m_maskbits_table[tile->mask_t]; // Mirroring and masking
70      }
71      else if (tile->mask_t)
72      {
73         *T &= m_maskbits_table[tile->mask_t];
74      }
75   }
76}
35177
352   CLAMP(SSS, SST, maxs, maxt)
353   CLAMP_LIGHT(sss2, sst2)
78void TexturePipe::TexShift(INT32* S, INT32* T, bool* maxs, bool* maxt, Tile *tile)
79{
80   *S = SIGN16(*S);
81   *T = SIGN16(*T);
35482
355   MASK(&SSS, &SST, tex_tile);
356   MASK(&sss2, &sst2, tex_tile);
83   if (tile->shift_s)
84   {
85      if (tile->shift_s < 11)
86      {
87         *S >>= tile->shift_s;
88      }
89      else
90      {
91         *S <<= (16 - tile->shift_s);
92      }
93      *S = SIGN16(*S);
94   }
35795
358   COLOR t1 = { { FETCH_TEXEL(sss2, SST) } };
359   COLOR t2 = { { FETCH_TEXEL(SSS, sst2) } };
96   if (tile->shift_s)
97   {
98      if (tile->shift_t < 11)
99      {
100         *T >>= tile->shift_t;
101      }
102       else
103       {
104         *T <<= (16 - tile->shift_t);
105      }
106      *T = SIGN16(*T);
107   }
360108
361   COLOR TEX;
362   if ((SFRAC + TFRAC) < 0x20)
109   *maxs = ((*S >> 3) >= tile->sh);
110   *maxt = ((*T >> 3) >= tile->th);
111}
112
113void TexturePipe::Clamp(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, bool maxs, bool maxt, Tile* tile)
114{
115   bool notcopy = (m_other_modes->cycle_type != CYCLE_TYPE_COPY);
116   bool dosfrac = (tile->cs || !tile->mask_s);
117   bool dos = dosfrac && notcopy;
118   bool dotfrac = (tile->ct || !tile->mask_t);
119   bool dot = dotfrac && notcopy;
120   bool overunders = false;
121   bool overundert = false;
122   if (*S & 0x10000 && dos)
363123   {
364      COLOR t0 = { { FETCH_TEXEL(SSS, SST) } };
365      INT32 R32 = t0.i.r + ((SFRAC*(t1.i.r - t0.i.r))>>5) + ((TFRAC*(t2.i.r - t0.i.r))>>5);
366      INT32 G32 = t0.i.g + ((SFRAC*(t1.i.g - t0.i.g))>>5) + ((TFRAC*(t2.i.g - t0.i.g))>>5);
367      INT32 B32 = t0.i.b + ((SFRAC*(t1.i.b - t0.i.b))>>5) + ((TFRAC*(t2.i.b - t0.i.b))>>5);
368      INT32 A32 = t0.i.a + ((SFRAC*(t1.i.a - t0.i.a))>>5) + ((TFRAC*(t2.i.a - t0.i.a))>>5);
369      TEX.i.r = (R32 < 0) ? 0 : R32;
370      TEX.i.g = (G32 < 0) ? 0 : G32;
371      TEX.i.b = (B32 < 0) ? 0 : B32;
372      TEX.i.a = (A32 < 0) ? 0 : A32;
124      *S = 0;
125      overunders = true;
373126   }
127   else if (maxs && dos)
128   {
129      *S = m_clamp_s_diff[tile->num];
130      overunders = true;
131   }
374132   else
375133   {
376      INT32 INVSF = 0x20 - SFRAC;
377      INT32 INVTF = 0x20 - TFRAC;
378      COLOR t3 = { { FETCH_TEXEL(sss2, sst2) } };
379      INT32 R32 = t3.i.r + ((INVSF*(t2.i.r - t3.i.r))>>5) + ((INVTF*(t1.i.r - t3.i.r))>>5);
380      INT32 G32 = t3.i.g + ((INVSF*(t2.i.g - t3.i.g))>>5) + ((INVTF*(t1.i.g - t3.i.g))>>5);
381      INT32 B32 = t3.i.b + ((INVSF*(t2.i.b - t3.i.b))>>5) + ((INVTF*(t1.i.b - t3.i.b))>>5);
382      INT32 A32 = t3.i.a + ((INVSF*(t2.i.a - t3.i.a))>>5) + ((INVTF*(t1.i.a - t3.i.a))>>5);
383      TEX.i.r = (R32 < 0) ? 0 : R32;
384      TEX.i.g = (G32 < 0) ? 0 : G32;
385      TEX.i.b = (B32 < 0) ? 0 : B32;
386      TEX.i.a = (A32 < 0) ? 0 : A32;
134      *S = (SIGN17(*S) >> 5) & 0x1fff;
387135   }
136   if (overunders && dosfrac)
137   {
138      *SFRAC = 0;
139   }
388140
389   return TEX.c;
141   if (*T & 0x10000 && dot)
142   {
143      *T = 0;
144      overundert = true;
145   }
146   else if (maxt && dot)
147   {
148      *T = m_clamp_t_diff[tile->num];
149      overundert = true;
150   }
151   else
152   {
153      *T = (SIGN17(*T) >> 5) & 0x1fff;
154   }
155   if (overundert && dotfrac)
156   {
157      *TFRAC = 0;
158   }
390159}
391160
392#if defined(SHIFT_T)
393   #if defined(SHIFT_S)
394      #if defined(DOT)
395         #if defined(DOS)
396            #if defined(COPY)
397               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
398            #else
399               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
400            #endif
401         #else
402            #if defined(COPY)
403               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
404            #else
405               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
406            #endif
407         #endif
408      #else
409         #if defined(DOS)
410            #if defined(COPY)
411               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
412            #else
413               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
414            #endif
415         #else
416            #if defined(COPY)
417               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
418            #else
419               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
420            #endif
421         #endif
422      #endif
423   #else
424      #if defined(DOT)
425         #if defined(DOS)
426            #if defined(COPY)
427               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
428            #else
429               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
430            #endif
431         #else
432            #if defined(COPY)
433               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
434            #else
435               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
436            #endif
437         #endif
438      #else
439         #if defined(DOS)
440            #if defined(COPY)
441               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
442            #else
443               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
444            #endif
445         #else
446            #if defined(COPY)
447               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
448            #else
449               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
450            #endif
451         #endif
452      #endif
453   #endif
454#else
455   #if defined(SHIFT_S)
456      #if defined(DOT)
457         #if defined(DOS)
458            #if defined(COPY)
459               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
460            #else
461               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
462            #endif
463         #else
464            #if defined(COPY)
465               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
466            #else
467               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
468            #endif
469         #endif
470      #else
471         #if defined(DOS)
472            #if defined(COPY)
473               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
474            #else
475               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
476            #endif
477         #else
478            #if defined(COPY)
479               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
480            #else
481               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
482            #endif
483         #endif
484      #endif
485   #else
486      #if defined(DOT)
487         #if defined(DOS)
488            #if defined(COPY)
489               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
490            #else
491               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
492            #endif
493         #else
494            #if defined(COPY)
495               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
496            #else
497               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
498            #endif
499         #endif
500      #else
501         #if defined(DOS)
502            #if defined(COPY)
503               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
504            #else
505               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
506            #endif
507         #else
508            #if defined(COPY)
509               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
510            #else
511               INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
512            #endif
513         #endif
514      #endif
515   #endif
516#endif
161void TexturePipe::ClampLight(INT32* S, INT32* T, bool maxs, bool maxt, Tile* tile)
517162{
518   INT32 maxs, maxt;
519   int sss2, sst2;
163   bool notcopy = (m_other_modes->cycle_type != CYCLE_TYPE_COPY);
164   bool dos = (tile->cs || !tile->mask_s) && notcopy;
165   bool dot = (tile->ct || !tile->mask_t) && notcopy;
520166
521   TEXSHIFT(SSS, SST, maxs, maxt)
167   if (*S & 0x10000 && dos)
168   {
169      *S = 0;
170   }
171   else if (maxs && dos)
172   {
173      *S = m_clamp_s_diff[tile->num];
174   }
175   else
176   {
177      *S = (SIGN17(*S) >> 5) & 0x1fff;
178   }
522179
523   sss2 = SSS + 32; sst2 = SST + 32;
180   if (*T & 0x10000 && dot)
181   {
182      *T = 0;
183   }
184   else if (maxt && dot)
185   {
186      *T = m_clamp_t_diff[tile->num];
187   }
188   else
189   {
190      *T = (SIGN17(*T) >> 5) & 0x1fff;
191   }
192}
524193
525   SSS = RELATIVE(SSS, tex_tile->sl);
526   SST = RELATIVE(SST, tex_tile->tl);
527   sss2 = RELATIVE(sss2, tex_tile->sl);
528   sst2 = RELATIVE(sst2, tex_tile->tl);
194UINT32 TexturePipe::Fetch(INT32 SSS, INT32 SST, Tile* tile)
195{
196   Color TEX;
197   if (m_other_modes->sample_type)
198   {
199      INT32 rt[4] = { 0 };
200      INT32 gt[4] = { 0 };
201      INT32 bt[4] = { 0 };
202      INT32 at[4] = { 0 };
203      Color t0;
204      Color t1;
205      Color t2;
206      Color t3;
529207
530   INT32 SFRAC = SSS & 0x1f;
531   INT32 TFRAC = SST & 0x1f;
208      int sss1 = SSS;
209      int sst1 = SST;
210      bool maxs = false;
211      bool maxt = false;
212      TexShift(&sss1, &sst1, &maxs, &maxt, tile);
532213
533   CLAMP(SSS, SST, maxs, maxt)
534   CLAMP_LIGHT(sss2, sst2)
214      int sss2 = sss1 + 32;
215      int sst2 = sst1 + 32;
216      bool maxs2 = ((sss2 >> 3) >= tile->sh);
217      bool maxt2 = ((sst2 >> 3) >= tile->th);
535218
536   MASK(&SSS, &SST, tex_tile);
537   MASK(&sss2, &sst2, tex_tile);
219      sss1 = RELATIVE(sss1, tile->sl);
220      sst1 = RELATIVE(sst1, tile->tl);
221      sss2 = RELATIVE(sss2, tile->sl);
222      sst2 = RELATIVE(sst2, tile->tl);
538223
539   COLOR t0 = { { FETCH_TEXEL(SSS, SST)   } };
540   COLOR t1 = { { FETCH_TEXEL(sss2, SST)  } };
541   COLOR t2 = { { FETCH_TEXEL(SSS, sst2)  } };
542   COLOR t3 = { { FETCH_TEXEL(sss2, sst2) } };
224      INT32 SFRAC = sss1 & 0x1f;
225      INT32 TFRAC = sst1 & 0x1f;
543226
544   COLOR TEX;
545   if (SFRAC!= 0x10 || TFRAC != 0x10)
546   {
547      if ((SFRAC + TFRAC) >= 0x20)
227      Clamp(&sss1, &sst1, &SFRAC, &TFRAC, maxs, maxt, tile);
228      ClampLight(&sss2, &sst2, maxs2, maxt2, tile);
229
230      Mask(&sss1, &sst1, tile);
231        Mask(&sss2, &sst2, tile);
232
233      bool upper = ((SFRAC + TFRAC) >= 0x20);
234      INT32 INVSF = 0;
235      INT32 INVTF = 0;
236      if (upper)
548237      {
549         INT32 INVSF = 0x20 - SFRAC;
550         INT32 INVTF = 0x20 - TFRAC;
551         INT32 R32 = t3.i.r + ((INVSF*(t2.i.r - t3.i.r))>>5) + ((INVTF*(t1.i.r - t3.i.r))>>5);
552         INT32 G32 = t3.i.g + ((INVSF*(t2.i.g - t3.i.g))>>5) + ((INVTF*(t1.i.g - t3.i.g))>>5);
553         INT32 B32 = t3.i.b + ((INVSF*(t2.i.b - t3.i.b))>>5) + ((INVTF*(t1.i.b - t3.i.b))>>5);
554         INT32 A32 = t3.i.a + ((INVSF*(t2.i.a - t3.i.a))>>5) + ((INVTF*(t1.i.a - t3.i.a))>>5);
555         TEX.i.r = (R32 < 0) ? 0 : R32;
556         TEX.i.g = (G32 < 0) ? 0 : G32;
557         TEX.i.b = (B32 < 0) ? 0 : B32;
558         TEX.i.a = (A32 < 0) ? 0 : A32;
238         INVSF = 0x20 - SFRAC;
239         INVTF = 0x20 - TFRAC;
559240      }
560      else
241
242      t1.c = m_tex_fetch.Fetch(sss2, sst1, tile);
243      t2.c = m_tex_fetch.Fetch(sss1, sst2, tile);
244      if(m_other_modes->mid_texel || !upper)
561245      {
562         INT32 R32 = t0.i.r + ((SFRAC*(t1.i.r - t0.i.r))>>5) + ((TFRAC*(t2.i.r - t0.i.r))>>5);
563         INT32 G32 = t0.i.g + ((SFRAC*(t1.i.g - t0.i.g))>>5) + ((TFRAC*(t2.i.g - t0.i.g))>>5);
564         INT32 B32 = t0.i.b + ((SFRAC*(t1.i.b - t0.i.b))>>5) + ((TFRAC*(t2.i.b - t0.i.b))>>5);
565         INT32 A32 = t0.i.a + ((SFRAC*(t1.i.a - t0.i.a))>>5) + ((TFRAC*(t2.i.a - t0.i.a))>>5);
566         TEX.i.r = (R32 < 0) ? 0 : R32;
567         TEX.i.g = (G32 < 0) ? 0 : G32;
568         TEX.i.b = (B32 < 0) ? 0 : B32;
569         TEX.i.a = (A32 < 0) ? 0 : A32;
246         t0.c = m_tex_fetch.Fetch(sss1, sst1, tile);
247         rt[0] = t0.i.r; gt[0] = t0.i.g; bt[0] = t0.i.b; at[0] = t0.i.a;
570248      }
249      rt[1] = t1.i.r; gt[1] = t1.i.g; bt[1] = t1.i.b; at[1] = t1.i.a;
250      rt[2] = t2.i.r; gt[2] = t2.i.g; bt[2] = t2.i.b; at[2] = t2.i.a;
251      if (m_other_modes->mid_texel || upper)
252      {
253         t3.c = m_tex_fetch.Fetch(sss2, sst2, tile);
254         rt[3] = t3.i.r; gt[3] = t3.i.g; bt[3] = t3.i.b; at[3] = t3.i.a;
255      }
256
257      if (!m_other_modes->mid_texel || SFRAC!= 0x10 || TFRAC != 0x10)
258      {
259         if (upper)
260         {
261            INT32 R32 = rt[3] + ((INVSF*(rt[2] - rt[3]))>>5) + ((INVTF*(rt[1] - rt[3]))>>5);
262            INT32 G32 = gt[3] + ((INVSF*(gt[2] - gt[3]))>>5) + ((INVTF*(gt[1] - gt[3]))>>5);
263            INT32 B32 = bt[3] + ((INVSF*(bt[2] - bt[3]))>>5) + ((INVTF*(bt[1] - bt[3]))>>5);
264            INT32 A32 = at[3] + ((INVSF*(at[2] - at[3]))>>5) + ((INVTF*(at[1] - at[3]))>>5);
265            TEX.i.r = (R32 < 0) ? 0 : R32;
266            TEX.i.g = (G32 < 0) ? 0 : G32;
267            TEX.i.b = (B32 < 0) ? 0 : B32;
268            TEX.i.a = (A32 < 0) ? 0 : A32;
269         }
270         else
271         {
272            INT32 R32 = rt[0] + ((SFRAC*(rt[1] - rt[0]))>>5) + ((TFRAC*(rt[2] - rt[0]))>>5);
273            INT32 G32 = gt[0] + ((SFRAC*(gt[1] - gt[0]))>>5) + ((TFRAC*(gt[2] - gt[0]))>>5);
274            INT32 B32 = bt[0] + ((SFRAC*(bt[1] - bt[0]))>>5) + ((TFRAC*(bt[2] - bt[0]))>>5);
275            INT32 A32 = at[0] + ((SFRAC*(at[1] - at[0]))>>5) + ((TFRAC*(at[2] - at[0]))>>5);
276            TEX.i.r = (R32 < 0) ? 0 : R32;
277            TEX.i.g = (G32 < 0) ? 0 : G32;
278            TEX.i.b = (B32 < 0) ? 0 : B32;
279            TEX.i.a = (A32 < 0) ? 0 : A32;
280         }
281      }
282      else // Is this accurate?
283      {
284         TEX.i.r = (rt[0] + rt[1] + rt[2] + rt[3]) >> 2;
285         TEX.i.g = (gt[0] + gt[1] + gt[2] + gt[3]) >> 2;
286         TEX.i.b = (bt[0] + bt[1] + bt[2] + bt[3]) >> 2;
287         TEX.i.a = (at[0] + at[1] + at[2] + at[3]) >> 2;
288      }
571289   }
572   else // Is this accurate?
290   else
573291   {
574      TEX.i.r = (t0.i.r + t1.i.r + t2.i.r + t3.i.r) >> 2;
575      TEX.i.g = (t0.i.g + t1.i.g + t2.i.g + t3.i.g) >> 2;
576      TEX.i.b = (t0.i.b + t1.i.b + t2.i.b + t3.i.b) >> 2;
577      TEX.i.a = (t0.i.a + t1.i.a + t2.i.a + t3.i.a) >> 2;
578   }
292      int sss1 = SSS;
293      int sst1 = SST;
579294
580   return TEX.c;
581}
295      bool maxs = false;
296      bool maxt = false;
297      TexShift(&sss1, &sst1, &maxs, &maxt, tile);
582298
583#if defined(SHIFT_T)
584   #if defined(SHIFT_S)
585      #if defined(DOT)
586         #if defined(DOS)
587            #if defined(COPY)
588               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
589            #else
590               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
591            #endif
592         #else
593            #if defined(COPY)
594               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
595            #else
596               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
597            #endif
598         #endif
599      #else
600         #if defined(DOS)
601            #if defined(COPY)
602               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
603            #else
604               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
605            #endif
606         #else
607            #if defined(COPY)
608               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
609            #else
610               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
611            #endif
612         #endif
613      #endif
614   #else
615      #if defined(DOT)
616         #if defined(DOS)
617            #if defined(COPY)
618               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
619            #else
620               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
621            #endif
622         #else
623            #if defined(COPY)
624               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
625            #else
626               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
627            #endif
628         #endif
629      #else
630         #if defined(DOS)
631            #if defined(COPY)
632               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
633            #else
634               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
635            #endif
636         #else
637            #if defined(COPY)
638               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
639            #else
640               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile)
641            #endif
642         #endif
643      #endif
644   #endif
645#else
646   #if defined(SHIFT_S)
647      #if defined(DOT)
648         #if defined(DOS)
649            #if defined(COPY)
650               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
651            #else
652               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
653            #endif
654         #else
655            #if defined(COPY)
656               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
657            #else
658               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
659            #endif
660         #endif
661      #else
662         #if defined(DOS)
663            #if defined(COPY)
664               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
665            #else
666               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
667            #endif
668         #else
669            #if defined(COPY)
670               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
671            #else
672               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
673            #endif
674         #endif
675      #endif
676   #else
677      #if defined(DOT)
678         #if defined(DOS)
679            #if defined(COPY)
680               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
681            #else
682               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
683            #endif
684         #else
685            #if defined(COPY)
686               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
687            #else
688               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
689            #endif
690         #endif
691      #else
692         #if defined(DOS)
693            #if defined(COPY)
694               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
695            #else
696               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
697            #endif
698         #else
699            #if defined(COPY)
700               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
701            #else
702               INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile)
703            #endif
704         #endif
705      #endif
706   #endif
707#endif
708{
709   INT32 maxs, maxt;
710   INT32 SFRAC, TFRAC;
299      sss1 = RELATIVE(sss1, tile->sl);
300      sst1 = RELATIVE(sst1, tile->tl);
711301
712   TEXSHIFT(SSS, SST, maxs, maxt)
713   SSS = RELATIVE(SSS, tex_tile->sl);
714   SST = RELATIVE(SST, tex_tile->tl);
302      sss1 += 0x10;
303      sst1 += 0x10;
715304
716   SSS += 0x10;
717   SST += 0x10;
305      INT32 SFRAC = sss1 & 0x1f;
306      INT32 TFRAC = sst1 & 0x1f;
718307
719   SFRAC = SSS & 0x1f;
720   TFRAC = SST & 0x1f;
308      Clamp(&sss1, &sst1, &SFRAC, &TFRAC, maxs, maxt, tile);
721309
722   CLAMP(SSS, SST, maxs, maxt)
310        Mask(&sss1, &sst1, tile);
723311
724   MASK(&SSS, &SST, tex_tile);
312      /* point sample */
313      TEX.c = m_tex_fetch.Fetch(sss1, sst1, tile);
314   }
725315
726   /* point sample */
727   return FETCH_TEXEL(SSS, SST);
316   return TEX.c;
728317}
729318
730#undef CLAMP
731#undef CLAMP_LIGHT
732#undef TEXSHIFT
319} // namespace RDP
320
321} // namespace N64
src/mame/video/rdptpipe.h
r7675r7676
1INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
2INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
3INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
4INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
5INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
6INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
7INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
8INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
9INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
10INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
11INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
12INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
1#ifndef _VIDEO_RDPTEXPIPE_H_
2#define _VIDEO_RDPTEXPIPE_H_
133
14INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
15INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
16INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
17INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
18INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
19INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
20INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
21INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
22INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
23INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
24INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
25INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
4#include "emu.h"
5#include "video/rdpfetch.h"
266
27INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
28INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
29INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
30INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
31INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
32INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
33INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
34INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
35INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
36INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
37INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
38INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
7namespace N64
8{
399
40INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
41INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
42INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
43INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
44INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
45INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
46INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
47INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
48INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
49INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
50INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
51INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
10namespace RDP
11{
5212
53INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
54INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
55INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
56INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
57INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
58INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
59INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
60INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
61INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
62INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
63INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
64INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
13class OtherModes;
14class MiscState;
15class Processor;
16class Color;
6517
66INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
67INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
68INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
69INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
70INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
71INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
72INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
73INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
74INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
75INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
76INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
77INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_ST(INT32 SSS, INT32 SST, TILE* tex_tile);
18class TexturePipe
19{
20   public:
21      TexturePipe()
22      {
23         m_maskbits_table[0] = 0x3ff;
24         for(int i = 1; i < 16; i++)
25         {
26            m_maskbits_table[i] = ((UINT16)(0xffff) >> (16 - i)) & 0x3ff;
27         }
28      }
7829
79INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
80INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
81INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
82INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
83INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
84INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
85INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
86INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
87INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
88INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
89INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
90INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
30      UINT32            Fetch(INT32 SSS, INT32 SST, Tile* tile);
31      void             CalculateClampDiffs(UINT32 prim_tile);
9132
92INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
93INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
94INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
95INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
96INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
97INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
98INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
99INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
100INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
101INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
102INLINE UINT32 TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
103INLINE UINT32 TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_NST(INT32 SSS, INT32 SST, TILE* tex_tile);
33      void            SetMachine(running_machine* machine);
10434
105static UINT32 (*rdp_texture_pipeline_func[128])(INT32, INT32, TILE*) =
106{
107   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_NST, TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_NST,
108   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_NST, TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_NST,
109   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_NST,
110   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_NST,
111   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_NST,
112   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_NST,
113   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_NST,
114   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_NST,
115   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_NST,
116   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_NST,  TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_NST,
117   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_NST,
118   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_NST,
119   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_NST,
120   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_NST,
121   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_NST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_NST,
122   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_NST,    TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_NST,
35   private:
36      void             Mask(INT32* S, INT32* T, Tile* tile);
37      void             TexShift(INT32* S, INT32* T, bool* maxs, bool* maxt, Tile *tile);
38      void             Clamp(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, bool maxs, bool maxt, Tile* tile);
39      void             ClampLight(INT32* S, INT32* T, bool maxs, bool maxt, Tile* tile);
12340
124   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_NST,  TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_NST,
125   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_NST,  TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_NST,
126   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_NST,
127   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_NST,
128   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_NST,
129   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_NST,
130   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_NST,
131   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_NST,
132   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_NST,
133   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_NST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_NST,
134   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_NST,
135   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_NST,
136   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_NST,
137   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_NST,    TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_NST,
138   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_NST,     TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_NST,
139   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_NST,     TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_NST,
41      running_machine*   m_machine;
42      OtherModes*         m_other_modes;
43      Processor*         m_rdp;
44      TexFetch         m_tex_fetch;
14045
141   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_ST,  TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_NSS_ST,
142   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_NSS_ST,  TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_NSS_ST,
143   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_NSS_ST,
144   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_NSS_ST,
145   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_NSS_ST,
146   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_NSS_ST,
147   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_NSS_ST,
148   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_NSS_ST,
149   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_NSS_ST,
150   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_NSS_ST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_NSS_ST,
151   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_NSS_ST,
152   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_NSS_ST,
153   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_NSS_ST,
154   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_NSS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_NSS_ST,
155   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_ST,     TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_NSS_ST,
156   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_NSS_ST,     TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_NSS_ST,
157
158   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_ST,   TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_NDOT_SS_ST,
159   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_NDOT_SS_ST,   TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_NDOT_SS_ST,
160   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_NDOT_SS_ST,
161   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_NDOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_NDOT_SS_ST,
162   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_NDOT_SS_ST,
163   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_NDOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_NDOT_SS_ST,
164   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_NDOT_SS_ST,
165   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_NDOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_NDOT_SS_ST,
166   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_NMID_NC_NDOS_DOT_SS_ST,
167   TEXTURE_PIPELINE_NEAREST_NMID_NC_NDOS_DOT_SS_ST,    TEXTURE_PIPELINE_BILINEAR_MID_NC_NDOS_DOT_SS_ST,
168   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_NMID_C_NDOS_DOT_SS_ST,
169   TEXTURE_PIPELINE_NEAREST_NMID_C_NDOS_DOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_MID_C_NDOS_DOT_SS_ST,
170   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_NMID_NC_DOS_DOT_SS_ST,
171   TEXTURE_PIPELINE_NEAREST_NMID_NC_DOS_DOT_SS_ST,     TEXTURE_PIPELINE_BILINEAR_MID_NC_DOS_DOT_SS_ST,
172   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_ST,      TEXTURE_PIPELINE_BILINEAR_NMID_C_DOS_DOT_SS_ST,
173   TEXTURE_PIPELINE_NEAREST_NMID_C_DOS_DOT_SS_ST,      TEXTURE_PIPELINE_BILINEAR_MID_C_DOS_DOT_SS_ST,
46      INT32             m_maskbits_table[16];
47      INT32             m_clamp_t_diff[8];
48      INT32             m_clamp_s_diff[8];
17449};
50
51} // namespace RDP
52
53} // namespace N64
54
55#endif // _VIDEO_RDPTEXPIPE_H_
No newline at end of file
src/mame/video/rdpblend.c
r7675r7676
1#if defined(FORCEBLEND)
2   #if defined(ALPHACOMPARE)
3      #if defined(RGBDITHER1)
4         #if defined(ZCOMPARE)
5            #if defined(IMGREAD)
6               INLINE int BLENDER1_16_IMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
7            #else
8               INLINE int BLENDER1_16_NIMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
9            #endif
10         #else
11            #if defined(IMGREAD)
12               INLINE int BLENDER1_16_IMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
13            #else
14               INLINE int BLENDER1_16_NIMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
15            #endif
16         #endif
17      #else
18         #if defined(ZCOMPARE)
19            #if defined(IMGREAD)
20               INLINE int BLENDER1_16_IMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
21            #else
22               INLINE int BLENDER1_16_NIMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
23            #endif
24         #else
25            #if defined(IMGREAD)
26               INLINE int BLENDER1_16_IMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
27            #else
28               INLINE int BLENDER1_16_NIMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
29            #endif
30         #endif
31      #endif
32   #else
33      #if defined(RGBDITHER1)
34         #if defined(ZCOMPARE)
35            #if defined(IMGREAD)
36               INLINE int BLENDER1_16_IMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
37            #else
38               INLINE int BLENDER1_16_NIMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
39            #endif
40         #else
41            #if defined(IMGREAD)
42               INLINE int BLENDER1_16_IMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
43            #else
44               INLINE int BLENDER1_16_NIMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
45            #endif
46         #endif
47      #else
48         #if defined(ZCOMPARE)
49            #if defined(IMGREAD)
50               INLINE int BLENDER1_16_IMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
51            #else
52               INLINE int BLENDER1_16_NIMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
53            #endif
54         #else
55            #if defined(IMGREAD)
56               INLINE int BLENDER1_16_IMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
57            #else
58               INLINE int BLENDER1_16_NIMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
59            #endif
60         #endif
61      #endif
62   #endif
63#else
64   #if defined(ALPHACOMPARE)
65      #if defined(RGBDITHER1)
66         #if defined(ZCOMPARE)
67            #if defined(IMGREAD)
68               INLINE int BLENDER1_16_IMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
69            #else
70               INLINE int BLENDER1_16_NIMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
71            #endif
72         #else
73            #if defined(IMGREAD)
74               INLINE int BLENDER1_16_IMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
75            #else
76               INLINE int BLENDER1_16_NIMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
77            #endif
78         #endif
79      #else
80         #if defined(ZCOMPARE)
81            #if defined(IMGREAD)
82               INLINE int BLENDER1_16_IMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
83            #else
84               INLINE int BLENDER1_16_NIMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
85            #endif
86         #else
87            #if defined(IMGREAD)
88               INLINE int BLENDER1_16_IMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
89            #else
90               INLINE int BLENDER1_16_NIMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
91            #endif
92         #endif
93      #endif
94   #else
95      #if defined(RGBDITHER1)
96         #if defined(ZCOMPARE)
97            #if defined(IMGREAD)
98               INLINE int BLENDER1_16_IMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
99            #else
100               INLINE int BLENDER1_16_NIMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
101            #endif
102         #else
103            #if defined(IMGREAD)
104               INLINE int BLENDER1_16_IMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
105            #else
106               INLINE int BLENDER1_16_NIMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
107            #endif
108         #endif
109      #else
110         #if defined(ZCOMPARE)
111            #if defined(IMGREAD)
112               INLINE int BLENDER1_16_IMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
113            #else
114               INLINE int BLENDER1_16_NIMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
115            #endif
116         #else
117            #if defined(IMGREAD)
118               INLINE int BLENDER1_16_IMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
119            #else
120               INLINE int BLENDER1_16_NIMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith)
121            #endif
122         #endif
123      #endif
124   #endif
125#endif
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
4
5namespace N64
1266{
7
8bool RDP::Blender::Blend(void* in_fb, UINT8* hb, RDP::Color c1, RDP::Color c2, int dith)
9{
10   switch(m_misc_state->m_fb_size)
11   {
12      case PIXEL_SIZE_16BIT:
13         return Blend16Bit((UINT16*)in_fb, hb, c1, c2, dith);
14
15      case PIXEL_SIZE_32BIT:
16         return Blend32Bit((UINT32*)in_fb, c1, c2);
17
18      default:
19         fatalerror("Unsupported bit depth: %d\n", m_misc_state->m_fb_size);
20         break;
21   }
22
23   return false;
24}
25
26bool RDP::Blender::Blend16Bit(UINT16* fb, UINT8* hb, RDP::Color c1, RDP::Color c2, int dith)
27{
28   switch(m_other_modes->cycle_type)
29   {
30      case CYCLE_TYPE_1:
31         return Blend16Bit1Cycle(fb, hb, c1, dith);
32
33      case CYCLE_TYPE_2:
34         return Blend16Bit2Cycle(fb, hb, c1, c2, dith);
35
36      default:
37         fatalerror("Unsupported cycle type for Blend16Bit: %d\n", m_other_modes->cycle_type);
38         break;
39   }
40
41   return false;
42}
43
44bool RDP::Blender::Blend16Bit1Cycle(UINT16* fb, UINT8* hb, RDP::Color c, int dith)
45{
12746   UINT16 mem = *fb;
128#if defined(IMGREAD)
129   UINT32 memory_cvg = ((mem & 1) << 2) + (*hb & 3);
130#endif
47   UINT32 memory_cvg = 7;
48   if(m_other_modes->image_read_en)
49   {
50      memory_cvg = ((mem & 1) << 2) + (*hb & 3);
51   }
13152
132#if defined(ALPHACOMPARE)
13353   // Alpha compare
134   if (!alpha_compare(c.i.a))
54   if (!AlphaCompare(c.i.a))
13555   {
136      return 0;
56      return false;
13757   }
138#endif
13958
140   if (!curpixel_cvg) // New coverage is zero, so abort
59   if (!m_misc_state->m_curpixel_cvg) // New coverage is zero, so abort
14160   {
142      return 0;
61      return false;
14362   }
14463
14564   int special_bsel = 0;
146   if (blender2b_a[0] == &memory_color.i.a)
65   if (m_rdp->GetColorInputs()->blender2b_a[0] == &m_rdp->GetMemoryColor()->i.a)
14766   {
14867      special_bsel = 1;
14968   }
15069
151   pixel_color.c = c.c;
70   m_rdp->GetPixelColor()->c = c.c;
15271
153#if !defined(ZCOMPARE)
154   curpixel_overlap = 0;
155#endif
72   if(!m_other_modes->z_compare_en)
73   {
74      m_misc_state->m_curpixel_overlap = 0;
75   }
15676
157   memory_color.c = rgb16_to_32_lut[mem];
77   m_rdp->GetMemoryColor()->c = m_rdp->LookUp16To32(mem);
78   m_rdp->GetMemoryColor()->i.a = (memory_cvg << 5) & 0xe0;
15879
159#if defined(IMGREAD)
160   memory_color.i.a = (memory_cvg << 5) & 0xe0;
161#else
162   memory_color.i.a = 0xe0;
163#endif
80   int r;
81   int g;
82   int b;
16483
165   int r, g, b;
166#if defined(ZCOMPARE)
167#if defined(FORCEBLEND)
168   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
169
170   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
171#else
172   if (!curpixel_overlap)
84   if(m_other_modes->z_compare_en)
17385   {
174      r = *blender1a_r[0];
175      g = *blender1a_g[0];
176      b = *blender1a_b[0];
86      if(m_other_modes->force_blend)
87      {
88         m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
89         BlendEquation0Force(&r, &g, &b, special_bsel);
90      }
91      else
92      {
93         if (!m_misc_state->m_curpixel_overlap)
94         {
95            r = *m_rdp->GetColorInputs()->blender1a_r[0];
96            g = *m_rdp->GetColorInputs()->blender1a_g[0];
97            b = *m_rdp->GetColorInputs()->blender1a_b[0];
98         }
99         else
100         {
101            m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
102
103            BlendEquation0NoForce(&r, &g, &b, special_bsel);
104         }
105      }
177106   }
178107   else
179108   {
180      inv_pixel_color.i.a = 0xff - *blender1b_a[0];
109      if(m_other_modes->force_blend)
110      {
111         m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
181112
182      BLENDER_EQUATION0_NFORCE(&r, &g, &b, special_bsel);
113         BlendEquation0Force(&r, &g, &b, special_bsel);
114      }
115      else
116      {
117         r = *m_rdp->GetColorInputs()->blender1a_r[0];
118         g = *m_rdp->GetColorInputs()->blender1a_g[0];
119         b = *m_rdp->GetColorInputs()->blender1a_b[0];
120      }
183121   }
184#endif
185#else
186#if defined(FORCEBLEND)
187   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
188122
189   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
190#else
191   r = *blender1a_r[0];
192   g = *blender1a_g[0];
193   b = *blender1a_b[0];
194#endif
195#endif
196
197#if !defined(RGBDITHER1)
198   // Hack to prevent "double-dithering" artifacts
199   if (!(((r & 0xf8)==(memory_color.i.r&0xf8) && (g & 0xf8) == (memory_color.i.g & 0xf8) &&(b&0xf8)==(memory_color.i.b&0xf8))))
123   if(!(m_other_modes->rgb_dither_sel & 2))
200124   {
201      rgb_dither(&r, &g, &b, dith);
125      // Hack to prevent "double-dithering" artifacts
126      if (!(((r & 0xf8)==(m_rdp->GetMemoryColor()->i.r&0xf8) && (g & 0xf8) == (m_rdp->GetMemoryColor()->i.g & 0xf8) &&(b&0xf8)==(m_rdp->GetMemoryColor()->i.b&0xf8))))
127      {
128         DitherRGB(&r, &g, &b, dith);
129      }
202130   }
203#endif
204131
205    return (FBWRITE_16(fb, hb, r, g, b));
132    return m_rdp->GetFramebuffer()->Write(fb, hb, r, g, b);
206133}
207134
208#if defined(FORCEBLEND)
209   #if defined(ALPHACOMPARE)
210      #if defined(RGBDITHER1)
211         #if defined(ZCOMPARE)
212            #if defined(IMGREAD)
213               INLINE int BLENDER2_16_IMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
214            #else
215               INLINE int BLENDER2_16_NIMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
216            #endif
217         #else
218            #if defined(IMGREAD)
219               INLINE int BLENDER2_16_IMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
220            #else
221               INLINE int BLENDER2_16_NIMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
222            #endif
223         #endif
224      #else
225         #if defined(ZCOMPARE)
226            #if defined(IMGREAD)
227               INLINE int BLENDER2_16_IMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
228            #else
229               INLINE int BLENDER2_16_NIMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
230            #endif
231         #else
232            #if defined(IMGREAD)
233               INLINE int BLENDER2_16_IMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
234            #else
235               INLINE int BLENDER2_16_NIMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
236            #endif
237         #endif
238      #endif
239   #else
240      #if defined(RGBDITHER1)
241         #if defined(ZCOMPARE)
242            #if defined(IMGREAD)
243               INLINE int BLENDER2_16_IMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
244            #else
245               INLINE int BLENDER2_16_NIMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
246            #endif
247         #else
248            #if defined(IMGREAD)
249               INLINE int BLENDER2_16_IMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
250            #else
251               INLINE int BLENDER2_16_NIMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
252            #endif
253         #endif
254      #else
255         #if defined(ZCOMPARE)
256            #if defined(IMGREAD)
257               INLINE int BLENDER2_16_IMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
258            #else
259               INLINE int BLENDER2_16_NIMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
260            #endif
261         #else
262            #if defined(IMGREAD)
263               INLINE int BLENDER2_16_IMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
264            #else
265               INLINE int BLENDER2_16_NIMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
266            #endif
267         #endif
268      #endif
269   #endif
270#else
271   #if defined(ALPHACOMPARE)
272      #if defined(RGBDITHER1)
273         #if defined(ZCOMPARE)
274            #if defined(IMGREAD)
275               INLINE int BLENDER2_16_IMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
276            #else
277               INLINE int BLENDER2_16_NIMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
278            #endif
279         #else
280            #if defined(IMGREAD)
281               INLINE int BLENDER2_16_IMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
282            #else
283               INLINE int BLENDER2_16_NIMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
284            #endif
285         #endif
286      #else
287         #if defined(ZCOMPARE)
288            #if defined(IMGREAD)
289               INLINE int BLENDER2_16_IMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
290            #else
291               INLINE int BLENDER2_16_NIMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
292            #endif
293         #else
294            #if defined(IMGREAD)
295               INLINE int BLENDER2_16_IMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
296            #else
297               INLINE int BLENDER2_16_NIMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
298            #endif
299         #endif
300      #endif
301   #else
302      #if defined(RGBDITHER1)
303         #if defined(ZCOMPARE)
304            #if defined(IMGREAD)
305               INLINE int BLENDER2_16_IMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
306            #else
307               INLINE int BLENDER2_16_NIMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
308            #endif
309         #else
310            #if defined(IMGREAD)
311               INLINE int BLENDER2_16_IMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
312            #else
313               INLINE int BLENDER2_16_NIMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
314            #endif
315         #endif
316      #else
317         #if defined(ZCOMPARE)
318            #if defined(IMGREAD)
319               INLINE int BLENDER2_16_IMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
320            #else
321               INLINE int BLENDER2_16_NIMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
322            #endif
323         #else
324            #if defined(IMGREAD)
325               INLINE int BLENDER2_16_IMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
326            #else
327               INLINE int BLENDER2_16_NIMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith)
328            #endif
329         #endif
330      #endif
331   #endif
332#endif
135bool RDP::Blender::Blend16Bit2Cycle(UINT16* fb, UINT8* hb, RDP::Color c1, RDP::Color c2, int dith)
333136{
334137   UINT16 mem = *fb;
335#if defined(IMGREAD)
336   UINT32 memory_cvg = ((mem & 1) << 2) + (*hb & 3);
337#endif
138   UINT32 memory_cvg = 7;
139   if(m_other_modes->image_read_en)
140   {
141      memory_cvg = ((mem & 1) << 2) + (*hb & 3);
142   }
338143
339#if defined(ALPHACOMPARE)
340144   // Alpha compare
341   if (!alpha_compare(c2.i.a))
145   if (!AlphaCompare(c2.i.a))
342146   {
343      return 0;
147      return false;
344148   }
345#endif
346149
347   if (!curpixel_cvg)
150   if (!m_misc_state->m_curpixel_cvg)
348151   {
349      return 0;
152      return false;
350153   }
351154
352155   int special_bsel = 0;
353   if (blender2b_a[0] == &memory_color.i.a)
156   if (m_rdp->GetColorInputs()->blender2b_a[0] == &m_rdp->GetMemoryColor()->i.a)
354157   {
355158      special_bsel = 1;
356159   }
357160
358   pixel_color.c = c2.c;
161   m_rdp->GetPixelColor()->c = c2.c;
359162
360#if !defined(ZCOMPARE)
361   curpixel_overlap = 0;
362#endif
163   if(m_other_modes->z_compare_en)
164   {
165      m_misc_state->m_curpixel_overlap = 0;
166   }
363167
364   memory_color.c = rgb16_to_32_lut[mem];
168   m_rdp->GetMemoryColor()->c = m_rdp->LookUp16To32(mem);
169   m_rdp->GetMemoryColor()->i.a = (memory_cvg << 5) & 0xe0;
365170
366#if defined(IMGREAD)
367   memory_color.i.a = (memory_cvg << 5) & 0xe0;
368#else
369   memory_color.i.a = 0xe0;
370#endif
171   m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
371172
372   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
373
374173   int r, g, b;
375#if defined(FORCEBLEND)
376   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
377#else
378   BLENDER_EQUATION1_FORCE(&r, &g, &b, special_bsel);
379#endif
380
381   blended_pixel_color.i.r = r;
382   blended_pixel_color.i.g = g;
383   blended_pixel_color.i.b = b;
384   blended_pixel_color.i.a = pixel_color.i.a;
385
386   pixel_color.i.r = r;
387   pixel_color.i.g = g;
388   pixel_color.i.b = b;
389
390   inv_pixel_color.i.a = 0xff - *blender1b_a[1];
391
392#if defined(FORCEBLEND)
393   if (blender2b_a[1] == &memory_color.i.a)
174   if(m_other_modes->force_blend)
394175   {
395      special_bsel = 1;
176      BlendEquation0Force(&r, &g, &b, special_bsel);
396177   }
397178   else
398179   {
399      special_bsel = 0;
180      BlendEquation1Force(&r, &g, &b, special_bsel);
400181   }
401182
402   BLENDER_EQUATION1_FORCE(&r, &g, &b, special_bsel);
403#else
404   if (!curpixel_overlap)
183   m_rdp->GetBlendedColor()->i.r = r;
184   m_rdp->GetBlendedColor()->i.g = g;
185   m_rdp->GetBlendedColor()->i.b = b;
186   m_rdp->GetBlendedColor()->i.a = m_rdp->GetPixelColor()->i.a;
187
188   m_rdp->GetPixelColor()->i.r = r;
189   m_rdp->GetPixelColor()->i.g = g;
190   m_rdp->GetPixelColor()->i.b = b;
191
192   m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[1];
193
194   if(m_other_modes->force_blend)
405195   {
406      r = *blender1a_r[1];
407      g = *blender1a_g[1];
408      b = *blender1a_b[1];
196      if (m_rdp->GetColorInputs()->blender2b_a[1] == &m_rdp->GetMemoryColor()->i.a)
197      {
198         special_bsel = 1;
199      }
200      else
201      {
202         special_bsel = 0;
203      }
204
205      BlendEquation1Force(&r, &g, &b, special_bsel);
409206   }
410207   else
411208   {
412      if (blender2b_a[1] == &memory_color.i.a)
209      if (!m_misc_state->m_curpixel_overlap)
413210      {
414         special_bsel = 1;
211         r = *m_rdp->GetColorInputs()->blender1a_r[1];
212         g = *m_rdp->GetColorInputs()->blender1a_g[1];
213         b = *m_rdp->GetColorInputs()->blender1a_b[1];
415214      }
416215      else
417216      {
418         special_bsel = 0;
217         if (m_rdp->GetColorInputs()->blender2b_a[1] == &m_rdp->GetMemoryColor()->i.a)
218         {
219            special_bsel = 1;
220         }
221         else
222         {
223            special_bsel = 0;
224         }
225
226         BlendEquation1NoForce(&r, &g, &b, special_bsel);
419227      }
228   }
420229
421      BLENDER_EQUATION1_NFORCE(&r, &g, &b, special_bsel);
230   if(!(m_other_modes->rgb_dither_sel & 2))
231   {
232      // Hack to prevent "double-dithering" artifacts
233      if (!(((r & 0xf8)==(m_rdp->GetMemoryColor()->i.r&0xf8) && (g & 0xf8) == (m_rdp->GetMemoryColor()->i.g & 0xf8) &&(b&0xf8)==(m_rdp->GetMemoryColor()->i.b&0xf8))))
234      {
235         DitherRGB(&r, &g, &b, dith);
236      }
422237   }
423#endif
424238
425#if !defined(RGBDITH1)
426   // Hack to prevent "double-dithering" artifacts
427   if (!(((r & 0xf8)==(memory_color.i.r&0xf8) && (g & 0xf8) == (memory_color.i.g & 0xf8) &&(b&0xf8)==(memory_color.i.b&0xf8))))
239    return m_rdp->GetFramebuffer()->Write(fb, hb, r, g, b);
240}
241
242bool RDP::Blender::Blend32Bit(UINT32* fb, RDP::Color c1, RDP::Color c2)
243{
244   switch(m_other_modes->cycle_type)
428245   {
429      rgb_dither(&r, &g, &b, dith);
246      case CYCLE_TYPE_1:
247         return Blend32Bit1Cycle(fb, c1);
248
249      case CYCLE_TYPE_2:
250         return Blend32Bit2Cycle(fb, c1, c2);
251
252      default:
253         fatalerror("Unsupported cycle type for Blend16Bit: %d\n", m_other_modes->cycle_type);
254         break;
430255   }
431#endif
432256
433   return (FBWRITE_16(fb, hb, r, g, b));
257   return false;
434258}
435259
436#if !defined(RGBDITHER1)
437#if defined(FORCEBLEND)
438   #if defined(ALPHACOMPARE)
439      #if defined(ZCOMPARE)
440         #if defined(IMGREAD)
441            INLINE int BLENDER1_16_IMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
442         #else
443            INLINE int BLENDER1_16_NIMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
444         #endif
445      #else
446         #if defined(IMGREAD)
447            INLINE int BLENDER1_16_IMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
448         #else
449            INLINE int BLENDER1_16_NIMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
450         #endif
451      #endif
452   #else
453      #if defined(ZCOMPARE)
454         #if defined(IMGREAD)
455            INLINE int BLENDER1_16_IMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
456         #else
457            INLINE int BLENDER1_16_NIMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
458         #endif
459      #else
460         #if defined(IMGREAD)
461            INLINE int BLENDER1_16_IMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
462         #else
463            INLINE int BLENDER1_16_NIMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c)
464         #endif
465      #endif
466   #endif
467#else
468   #if defined(ALPHACOMPARE)
469      #if defined(ZCOMPARE)
470         #if defined(IMGREAD)
471            INLINE int BLENDER1_16_IMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
472         #else
473            INLINE int BLENDER1_16_NIMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
474         #endif
475      #else
476         #if defined(IMGREAD)
477            INLINE int BLENDER1_16_IMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
478         #else
479            INLINE int BLENDER1_16_NIMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
480         #endif
481      #endif
482   #else
483      #if defined(ZCOMPARE)
484         #if defined(IMGREAD)
485            INLINE int BLENDER1_16_IMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
486         #else
487            INLINE int BLENDER1_16_NIMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
488         #endif
489      #else
490         #if defined(IMGREAD)
491            INLINE int BLENDER1_16_IMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
492         #else
493            INLINE int BLENDER1_16_NIMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c)
494         #endif
495      #endif
496   #endif
497#endif
260bool RDP::Blender::Blend32Bit1Cycle(UINT32* fb, RDP::Color c)
498261{
499   UINT16 mem = *fb;
500#if defined(IMGREAD)
501   UINT32 memory_cvg = ((mem & 1) << 2) + (*hb & 3);
502#endif
262   UINT32 mem = *fb;
263   int r, g, b;
503264
504#if defined(ALPHACOMPARE)
505265   // Alpha compare
506   if (!alpha_compare(c.i.a))
266   if (!AlphaCompare(c.i.a))
507267   {
508268      return 0;
509269   }
510#endif
511270
512   if (!curpixel_cvg) // New coverage is zero, so abort
271   if (!m_misc_state->m_curpixel_cvg)
513272   {
514273      return 0;
515274   }
516275
517   int special_bsel = 0;
518   if (blender2b_a[0] == &memory_color.i.a)
276   m_rdp->GetPixelColor()->c = c.c;
277   if (!m_other_modes->z_compare_en)
519278   {
520      special_bsel = 1;
279      m_misc_state->m_curpixel_overlap = 0;
521280   }
522281
523   pixel_color.c = c.c;
282   m_rdp->GetMemoryColor()->i.r = (mem >> 24) & 0xff;
283   m_rdp->GetMemoryColor()->i.g = (mem >> 16) & 0xff;
284   m_rdp->GetMemoryColor()->i.b = (mem >> 8) & 0xff;
524285
525#if !defined(ZCOMPARE)
526   curpixel_overlap = 0;
527#endif
286   if (m_other_modes->image_read_en)
287   {
288      m_rdp->GetMemoryColor()->i.a = mem & 0xe0;
289   }
290   else
291   {
292      m_rdp->GetMemoryColor()->i.a = 0xe0;
293   }
528294
529   memory_color.c = rgb16_to_32_lut[mem];
530
531#if defined(IMGREAD)
532   memory_color.i.a = (memory_cvg << 5) & 0xe0;
533#else
534   memory_color.i.a = 0xe0;
535#endif
536
537   int r, g, b;
538#if defined(ZCOMPARE)
539#if defined(FORCEBLEND)
540   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
541
542   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
543#else
544   if (!curpixel_overlap)
295   if (!m_misc_state->m_curpixel_overlap && !m_other_modes->force_blend)
545296   {
546      r = *blender1a_r[0];
547      g = *blender1a_g[0];
548      b = *blender1a_b[0];
297      r = *m_rdp->GetColorInputs()->blender1a_r[0];
298      g = *m_rdp->GetColorInputs()->blender1a_g[0];
299      b = *m_rdp->GetColorInputs()->blender1a_b[0];
549300   }
550301   else
551302   {
552      inv_pixel_color.i.a = 0xff - *blender1b_a[0];
303      m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
553304
554      BLENDER_EQUATION0_NFORCE(&r, &g, &b, special_bsel);
305      if(m_other_modes->force_blend)
306      {
307         BlendEquation0Force(&r, &g, &b, m_misc_state->m_special_bsel0);
308      }
309      else
310      {
311         BlendEquation0NoForce(&r, &g, &b, m_misc_state->m_special_bsel0);
312      }
555313   }
556#endif
557#else
558#if defined(FORCEBLEND)
559   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
560314
561   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
562#else
563   r = *blender1a_r[0];
564   g = *blender1a_g[0];
565   b = *blender1a_b[0];
566#endif
567#endif
568
569    return (FBWRITE_16(fb, hb, r, g, b));
315    return m_rdp->GetFramebuffer()->Write(fb, NULL, r, g, b);
570316}
571317
572#if defined(FORCEBLEND)
573   #if defined(ALPHACOMPARE)
574      #if defined(ZCOMPARE)
575         #if defined(IMGREAD)
576            INLINE int BLENDER2_16_IMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
577         #else
578            INLINE int BLENDER2_16_NIMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
579         #endif
580      #else
581         #if defined(IMGREAD)
582            INLINE int BLENDER2_16_IMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
583         #else
584            INLINE int BLENDER2_16_NIMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
585         #endif
586      #endif
587   #else
588      #if defined(ZCOMPARE)
589         #if defined(IMGREAD)
590            INLINE int BLENDER2_16_IMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
591         #else
592            INLINE int BLENDER2_16_NIMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
593         #endif
594      #else
595         #if defined(IMGREAD)
596            INLINE int BLENDER2_16_IMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
597         #else
598            INLINE int BLENDER2_16_NIMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
599         #endif
600      #endif
601   #endif
602#else
603   #if defined(ALPHACOMPARE)
604      #if defined(ZCOMPARE)
605         #if defined(IMGREAD)
606            INLINE int BLENDER2_16_IMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
607         #else
608            INLINE int BLENDER2_16_NIMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
609         #endif
610      #else
611         #if defined(IMGREAD)
612            INLINE int BLENDER2_16_IMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
613         #else
614            INLINE int BLENDER2_16_NIMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
615         #endif
616      #endif
617   #else
618      #if defined(ZCOMPARE)
619         #if defined(IMGREAD)
620            INLINE int BLENDER2_16_IMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
621         #else
622            INLINE int BLENDER2_16_NIMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
623         #endif
624      #else
625         #if defined(IMGREAD)
626            INLINE int BLENDER2_16_IMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
627         #else
628            INLINE int BLENDER2_16_NIMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2)
629         #endif
630      #endif
631   #endif
632#endif
318bool RDP::Blender::Blend32Bit2Cycle(UINT32* fb, RDP::Color c1, RDP::Color c2)
633319{
634   UINT16 mem = *fb;
635#if defined(IMGREAD)
636   UINT32 memory_cvg = ((mem & 1) << 2) + (*hb & 3);
637#endif
320   UINT32 mem = *fb;
321   int r, g, b;
638322
639#if defined(ALPHACOMPARE)
640323   // Alpha compare
641   if (!alpha_compare(c2.i.a))
324   if (!AlphaCompare(c2.i.a))
642325   {
643326      return 0;
644327   }
645#endif
646328
647   if (!curpixel_cvg)
329   if (!m_misc_state->m_curpixel_cvg)
648330   {
649331      return 0;
650332   }
651333
652   int special_bsel = 0;
653   if (blender2b_a[0] == &memory_color.i.a)
334   m_rdp->GetPixelColor()->c = c2.c;
335   if (!m_other_modes->z_compare_en)
654336   {
655      special_bsel = 1;
337      m_misc_state->m_curpixel_overlap = 0;
656338   }
657339
658   pixel_color.c = c2.c;
340   m_rdp->GetMemoryColor()->i.r = (mem >>24) & 0xff;
341   m_rdp->GetMemoryColor()->i.g = (mem >> 16) & 0xff;
342   m_rdp->GetMemoryColor()->i.b = (mem >> 8) & 0xff;
659343
660#if !defined(ZCOMPARE)
661   curpixel_overlap = 0;
662#endif
344   if (m_other_modes->image_read_en)
345   {
346      m_rdp->GetMemoryColor()->i.a = (mem & 0xe0);
347   }
348   else
349   {
350      m_rdp->GetMemoryColor()->i.a = 0xe0;
351   }
663352
664   memory_color.c = rgb16_to_32_lut[mem];
353   m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[0];
665354
666#if defined(IMGREAD)
667   memory_color.i.a = (memory_cvg << 5) & 0xe0;
668#else
669   memory_color.i.a = 0xe0;
670#endif
355   if(m_other_modes->force_blend)
356   {
357      BlendEquation0Force(&r, &g, &b, m_misc_state->m_special_bsel0);
358   }
359   else
360   {
361      BlendEquation0NoForce(&r, &g, &b, m_misc_state->m_special_bsel0);
362   }
671363
672   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
364   m_rdp->GetBlendedColor()->i.r = r;
365   m_rdp->GetBlendedColor()->i.g = g;
366   m_rdp->GetBlendedColor()->i.b = b;
673367
674   int r, g, b;
675#if defined(FORCEBLEND)
676   BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel);
677#else
678   BLENDER_EQUATION0_NFORCE(&r, &g, &b, special_bsel);
679#endif
368   m_rdp->GetPixelColor()->i.r = r;
369   m_rdp->GetPixelColor()->i.g = g;
370   m_rdp->GetPixelColor()->i.b = b;
680371
681   blended_pixel_color.i.r = r;
682   blended_pixel_color.i.g = g;
683   blended_pixel_color.i.b = b;
684   blended_pixel_color.i.a = pixel_color.i.a;
372   if (!m_misc_state->m_curpixel_overlap && !m_other_modes->force_blend)
373   {
374      r = *m_rdp->GetColorInputs()->blender1a_r[1];
375      g = *m_rdp->GetColorInputs()->blender1a_g[1];
376      b = *m_rdp->GetColorInputs()->blender1a_b[1];
377   }
378   else
379   {
380      m_rdp->GetInvPixelColor()->i.a = 0xff - *m_rdp->GetColorInputs()->blender1b_a[1];
685381
686   pixel_color.i.r = r;
687   pixel_color.i.g = g;
688   pixel_color.i.b = b;
382      if(m_other_modes->force_blend)
383      {
384         BlendEquation1Force(&r, &g, &b, m_misc_state->m_special_bsel1);
385      }
386      else
387      {
388         BlendEquation1NoForce(&r, &g, &b, m_misc_state->m_special_bsel1);
389      }
390   }
689391
690   inv_pixel_color.i.a = 0xff - *blender1b_a[1];
392    return m_rdp->GetFramebuffer()->Write(fb, NULL, r, g, b);
393}
691394
692#if defined(FORCEBLEND)
693   if (blender2b_a[1] == &memory_color.i.a)
395void RDP::Blender::BlendEquation0Force(INT32* r, INT32* g, INT32* b, int bsel_special)
396{
397   int blend1a = *m_rdp->GetColorInputs()->blender1b_a[0];
398   if (bsel_special)
694399   {
695      special_bsel = 1;
400      blend1a &= 0xe0;
696401   }
402
403   INT32 tr = ((int)(*m_rdp->GetColorInputs()->blender1a_r[0]) * blend1a + (int)(*m_rdp->GetColorInputs()->blender2a_r[0]) * *m_rdp->GetColorInputs()->blender2b_a[0] + ((int)(*m_rdp->GetColorInputs()->blender2a_r[0]) << (3 + bsel_special))) >> 8;
404   INT32 tg = ((int)(*m_rdp->GetColorInputs()->blender1a_g[0]) * blend1a + (int)(*m_rdp->GetColorInputs()->blender2a_g[0]) * *m_rdp->GetColorInputs()->blender2b_a[0] + ((int)(*m_rdp->GetColorInputs()->blender2a_g[0]) << (3 + bsel_special))) >> 8;
405   INT32 tb = ((int)(*m_rdp->GetColorInputs()->blender1a_b[0]) * blend1a + (int)(*m_rdp->GetColorInputs()->blender2a_b[0]) * *m_rdp->GetColorInputs()->blender2b_a[0] + ((int)(*m_rdp->GetColorInputs()->blender2a_b[0]) << (3 + bsel_special))) >> 8;
406
407   if (tr > 255) *r = 255; else *r = tr;
408   if (tg > 255) *g = 255; else *g = tg;
409   if (tb > 255) *b = 255; else *b = tb;
410}
411
412void RDP::Blender::BlendEquation0NoForce(INT32* r, INT32* g, INT32* b, int bsel_special)
413{
414   UINT8 blend1a = *m_rdp->GetColorInputs()->blender1b_a[0];
415   UINT8 blend2a = *m_rdp->GetColorInputs()->blender2b_a[0];
416   if (bsel_special)
417   {
418      blend1a &= 0xe0;
419   }
420
421   UINT32 sum = (((blend1a >> 5) + (blend2a >> 5) + 1) & 0xf) << 5;
422
423   INT32 tr = (((int)(*m_rdp->GetColorInputs()->blender1a_r[0]) * (int)(blend1a))) +
424      (((int)(*m_rdp->GetColorInputs()->blender2a_r[0]) * (int)(blend2a)));
425   tr += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_r[0])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_r[0])) << 3);
426
427   INT32 tg = (((int)(*m_rdp->GetColorInputs()->blender1a_g[0]) * (int)(blend1a))) +
428      (((int)(*m_rdp->GetColorInputs()->blender2a_g[0]) * (int)(blend2a)));
429   tg += (bsel_special) ? ((int)((*m_rdp->GetColorInputs()->blender2a_g[0])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_g[0])) << 3);
430
431   INT32 tb = (((int)(*m_rdp->GetColorInputs()->blender1a_b[0]) * (int)(blend1a))) +
432      (((int)(*m_rdp->GetColorInputs()->blender2a_b[0]) * (int)(blend2a)));
433   tb += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_b[0])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_b[0])) << 3);
434
435   if (sum)
436   {
437      tr /= sum;
438      tg /= sum;
439      tb /= sum;
440   }
697441   else
698442   {
699      special_bsel = 0;
443      *r = *g = *b = 0xff;
444      return;
700445   }
701446
702   BLENDER_EQUATION1_FORCE(&r, &g, &b, special_bsel);
703#else
704   if (!curpixel_overlap)
447   if (tr > 255) *r = 255; else *r = tr;
448   if (tg > 255) *g = 255; else *g = tg;
449   if (tb > 255) *b = 255; else *b = tb;
450}
451
452void RDP::Blender::BlendEquation1Force(INT32* r, INT32* g, INT32* b, int bsel_special)
453{
454   UINT8 blend1a = *m_rdp->GetColorInputs()->blender1b_a[1];
455   UINT8 blend2a = *m_rdp->GetColorInputs()->blender2b_a[1];
456   if (bsel_special)
705457   {
706      r = *blender1a_r[1];
707      g = *blender1a_g[1];
708      b = *blender1a_b[1];
458      blend1a &= 0xe0;
709459   }
460
461   INT32 tr = (((int)(*m_rdp->GetColorInputs()->blender1a_r[1]) * (int)(blend1a))) +
462      (((int)(*m_rdp->GetColorInputs()->blender2a_r[1]) * (int)(blend2a)));
463   tr += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_r[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_r[1])) << 3);
464
465   INT32 tg = (((int)(*m_rdp->GetColorInputs()->blender1a_g[1]) * (int)(blend1a))) +
466      (((int)(*m_rdp->GetColorInputs()->blender2a_g[1]) * (int)(blend2a)));
467   tg += (bsel_special) ? ((int)((*m_rdp->GetColorInputs()->blender2a_g[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_g[1])) << 3);
468
469   INT32 tb = (((int)(*m_rdp->GetColorInputs()->blender1a_b[1]) * (int)(blend1a))) +
470      (((int)(*m_rdp->GetColorInputs()->blender2a_b[1]) * (int)(blend2a)));
471   tb += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_b[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_b[1])) << 3);
472
473   tr >>= 8;
474   tg >>= 8;
475   tb >>= 8;
476
477   if (tr > 255) *r = 255; else *r = tr;
478   if (tg > 255) *g = 255; else *g = tg;
479   if (tb > 255) *b = 255; else *b = tb;
480}
481
482void RDP::Blender::BlendEquation1NoForce(INT32* r, INT32* g, INT32* b, int bsel_special)
483{
484   UINT8 blend1a = *m_rdp->GetColorInputs()->blender1b_a[1];
485   UINT8 blend2a = *m_rdp->GetColorInputs()->blender2b_a[1];
486   if (bsel_special)
487   {
488      blend1a &= 0xe0;
489   }
490
491   UINT32 sum = (((blend1a >> 5) + (blend2a >> 5) + 1) & 0xf) << 5;
492
493   INT32 tr = (((int)(*m_rdp->GetColorInputs()->blender1a_r[1]) * (int)(blend1a))) +
494      (((int)(*m_rdp->GetColorInputs()->blender2a_r[1]) * (int)(blend2a)));
495   tr += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_r[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_r[1])) << 3);
496
497   INT32 tg = (((int)(*m_rdp->GetColorInputs()->blender1a_g[1]) * (int)(blend1a))) +
498      (((int)(*m_rdp->GetColorInputs()->blender2a_g[1]) * (int)(blend2a)));
499   tg += (bsel_special) ? ((int)((*m_rdp->GetColorInputs()->blender2a_g[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_g[1])) << 3);
500
501   INT32 tb = (((int)(*m_rdp->GetColorInputs()->blender1a_b[1]) * (int)(blend1a))) +
502      (((int)(*m_rdp->GetColorInputs()->blender2a_b[1]) * (int)(blend2a)));
503   tb += (bsel_special) ? (((int)(*m_rdp->GetColorInputs()->blender2a_b[1])) << 5) : (((int)(*m_rdp->GetColorInputs()->blender2a_b[1])) << 3);
504
505   if (sum)
506   {
507      tr /= sum;
508      tg /= sum;
509      tb /= sum;
510   }
710511   else
711512   {
712      if (blender2b_a[1] == &memory_color.i.a)
513      *r = *g = *b = 0xff;
514      return;
515   }
516
517   if (tr > 255) *r = 255; else *r = tr;
518   if (tg > 255) *g = 255; else *g = tg;
519   if (tb > 255) *b = 255; else *b = tb;
520}
521
522bool RDP::Blender::AlphaCompare(UINT8 alpha)
523{
524   if(m_other_modes->alpha_compare_en)
525   {
526      if(m_other_modes->dither_alpha_en)
713527      {
714         special_bsel = 1;
528         return (alpha > m_rdp->GetRandom());
715529      }
716530      else
717531      {
718         special_bsel = 0;
532         return (alpha > m_rdp->GetBlendColor()->i.a);
719533      }
720
721      BLENDER_EQUATION1_NFORCE(&r, &g, &b, special_bsel);
722534   }
723#endif
535   return true;
536}
724537
725   return (FBWRITE_16(fb, hb, r, g, b));
538void RDP::Blender::DitherRGB(INT32 *r, INT32 *g, INT32 *b, int dith)
539{
540   if ((*r & 7) > dith)
541   {
542      *r = (*r & 0xf8) + 8;
543      if (*r > 247)
544      {
545         *r = 255;
546      }
547   }
548   if ((*g & 7) > dith)
549   {
550      *g = (*g & 0xf8) + 8;
551      if (*g > 247)
552      {
553         *g = 255;
554      }
555   }
556   if ((*b & 7) > dith)
557   {
558      *b = (*b & 0xf8) + 8;
559      if (*b > 247)
560      {
561         *b = 255;
562      }
563   }
726564}
727#endif
565
566} // namespace N64
No newline at end of file
src/mame/video/rdpblend.h
r7675r7676
1INLINE int BLENDER1_16_IMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
2INLINE int BLENDER1_16_IMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
3INLINE int BLENDER1_16_IMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
4INLINE int BLENDER1_16_IMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
5INLINE int BLENDER1_16_NIMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
6INLINE int BLENDER1_16_NIMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
7INLINE int BLENDER1_16_NIMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
8INLINE int BLENDER1_16_NIMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
1#ifndef _VIDEO_RDPBLEND_H_
2#define _VIDEO_RDPBLEND_H_
93
10INLINE int BLENDER2_16_IMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
11INLINE int BLENDER2_16_IMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
12INLINE int BLENDER2_16_IMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
13INLINE int BLENDER2_16_IMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
14INLINE int BLENDER2_16_NIMR_ZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
15INLINE int BLENDER2_16_NIMR_ZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
16INLINE int BLENDER2_16_NIMR_NZC_DITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
17INLINE int BLENDER2_16_NIMR_NZC_NDITH_NAC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
4#include "emu.h"
185
19INLINE int BLENDER1_16_IMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
20INLINE int BLENDER1_16_IMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
21INLINE int BLENDER1_16_IMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
22INLINE int BLENDER1_16_IMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
23INLINE int BLENDER1_16_NIMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
24INLINE int BLENDER1_16_NIMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
25INLINE int BLENDER1_16_NIMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
26INLINE int BLENDER1_16_NIMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
6namespace N64
7{
278
28INLINE int BLENDER2_16_IMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
29INLINE int BLENDER2_16_IMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
30INLINE int BLENDER2_16_IMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
31INLINE int BLENDER2_16_IMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
32INLINE int BLENDER2_16_NIMR_ZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
33INLINE int BLENDER2_16_NIMR_ZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
34INLINE int BLENDER2_16_NIMR_NZC_DITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
35INLINE int BLENDER2_16_NIMR_NZC_NDITH_AC_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
9namespace RDP
10{
3611
37INLINE int BLENDER1_16_IMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
38INLINE int BLENDER1_16_IMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
39INLINE int BLENDER1_16_NIMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
40INLINE int BLENDER1_16_NIMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
12class OtherModes;
13class MiscState;
14class Processor;
15class Color;
4116
42INLINE int BLENDER2_16_IMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
43INLINE int BLENDER2_16_IMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
44INLINE int BLENDER2_16_NIMR_ZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
45INLINE int BLENDER2_16_NIMR_NZC_NAC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
17class Blender
18{
19   public:
20      Blender() { }
4621
47INLINE int BLENDER1_16_IMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
48INLINE int BLENDER1_16_IMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
49INLINE int BLENDER1_16_NIMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
50INLINE int BLENDER1_16_NIMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c);
22      bool            Blend(void* in_fb, UINT8* hb, Color c1, Color c2, int dith);
5123
52INLINE int BLENDER2_16_IMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
53INLINE int BLENDER2_16_IMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
54INLINE int BLENDER2_16_NIMR_ZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
55INLINE int BLENDER2_16_NIMR_NZC_AC_ND_FORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
24      void            SetOtherModes(OtherModes* other_modes) { m_other_modes = other_modes; }
25      void            SetMiscState(MiscState* misc_state) { m_misc_state = misc_state; }
26      void            SetMachine(running_machine* machine) { m_machine = machine; }
27      void            SetProcessor(Processor* rdp) { m_rdp = rdp; }
5628
57INLINE int BLENDER1_16_IMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
58INLINE int BLENDER1_16_IMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
59INLINE int BLENDER1_16_IMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
60INLINE int BLENDER1_16_IMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
61INLINE int BLENDER1_16_NIMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
62INLINE int BLENDER1_16_NIMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
63INLINE int BLENDER1_16_NIMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
64INLINE int BLENDER1_16_NIMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
29   private:
30      running_machine*   m_machine;
31      OtherModes*         m_other_modes;
32      MiscState*         m_misc_state;
33      Processor*         m_rdp;
6534
66INLINE int BLENDER2_16_IMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
67INLINE int BLENDER2_16_IMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
68INLINE int BLENDER2_16_IMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
69INLINE int BLENDER2_16_IMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
70INLINE int BLENDER2_16_NIMR_ZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
71INLINE int BLENDER2_16_NIMR_ZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
72INLINE int BLENDER2_16_NIMR_NZC_DITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
73INLINE int BLENDER2_16_NIMR_NZC_NDITH_NAC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
35      bool             Blend16Bit(UINT16* fb, UINT8* hb, RDP::Color c1, RDP::Color c2, int dith);
36      bool             Blend16Bit1Cycle(UINT16* fb, UINT8* hb, RDP::Color c, int dith);
37      bool             Blend16Bit2Cycle(UINT16* fb, UINT8* hb, RDP::Color c1, RDP::Color c2, int dith);
38      bool             Blend32Bit(UINT32* fb, RDP::Color c1, RDP::Color c2);
39      bool             Blend32Bit1Cycle(UINT32* fb, RDP::Color c);
40      bool             Blend32Bit2Cycle(UINT32* fb, RDP::Color c1, RDP::Color c2);
41      bool            AlphaCompare(UINT8 alpha);
7442
75INLINE int BLENDER1_16_IMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
76INLINE int BLENDER1_16_IMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
77INLINE int BLENDER1_16_IMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
78INLINE int BLENDER1_16_IMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
79INLINE int BLENDER1_16_NIMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
80INLINE int BLENDER1_16_NIMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
81INLINE int BLENDER1_16_NIMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
82INLINE int BLENDER1_16_NIMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c, int dith);
43      void             BlendEquation0Force(INT32* r, INT32* g, INT32* b, int bsel_special);
44      void             BlendEquation0NoForce(INT32* r, INT32* g, INT32* b, int bsel_special);
45      void             BlendEquation1Force(INT32* r, INT32* g, INT32* b, int bsel_special);
46      void             BlendEquation1NoForce(INT32* r, INT32* g, INT32* b, int bsel_special);
8347
84INLINE int BLENDER2_16_IMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
85INLINE int BLENDER2_16_IMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
86INLINE int BLENDER2_16_IMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
87INLINE int BLENDER2_16_IMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
88INLINE int BLENDER2_16_NIMR_ZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
89INLINE int BLENDER2_16_NIMR_ZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
90INLINE int BLENDER2_16_NIMR_NZC_DITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
91INLINE int BLENDER2_16_NIMR_NZC_NDITH_AC_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
92
93INLINE int BLENDER1_16_IMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
94INLINE int BLENDER1_16_IMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
95INLINE int BLENDER1_16_NIMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
96INLINE int BLENDER1_16_NIMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
97
98INLINE int BLENDER2_16_IMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
99INLINE int BLENDER2_16_IMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
100INLINE int BLENDER2_16_NIMR_ZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
101INLINE int BLENDER2_16_NIMR_NZC_NAC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
102
103INLINE int BLENDER1_16_IMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
104INLINE int BLENDER1_16_IMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
105INLINE int BLENDER1_16_NIMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
106INLINE int BLENDER1_16_NIMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c);
107
108INLINE int BLENDER2_16_IMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
109INLINE int BLENDER2_16_IMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
110INLINE int BLENDER2_16_NIMR_ZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
111INLINE int BLENDER2_16_NIMR_NZC_AC_ND_NFORCE(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
112
113static int (*rdp_blender1_16_dith_func[32])(UINT16 *, UINT8 *, COLOR, int) =
114{
115   BLENDER1_16_NIMR_NZC_NDITH_NAC_NFORCE,   BLENDER1_16_NIMR_NZC_NDITH_AC_NFORCE,   BLENDER1_16_NIMR_NZC_DITH_NAC_NFORCE,   BLENDER1_16_NIMR_NZC_DITH_AC_NFORCE,
116   BLENDER1_16_NIMR_ZC_NDITH_NAC_NFORCE,   BLENDER1_16_NIMR_ZC_NDITH_AC_NFORCE,   BLENDER1_16_NIMR_ZC_DITH_NAC_NFORCE,   BLENDER1_16_NIMR_ZC_DITH_AC_NFORCE,
117   BLENDER1_16_IMR_NZC_NDITH_NAC_NFORCE,   BLENDER1_16_IMR_NZC_NDITH_AC_NFORCE,   BLENDER1_16_IMR_NZC_DITH_NAC_NFORCE,   BLENDER1_16_IMR_NZC_DITH_AC_NFORCE,
118   BLENDER1_16_IMR_ZC_NDITH_NAC_NFORCE,   BLENDER1_16_IMR_ZC_NDITH_AC_NFORCE,    BLENDER1_16_IMR_ZC_DITH_NAC_NFORCE,      BLENDER1_16_IMR_ZC_DITH_AC_NFORCE,
119   BLENDER1_16_NIMR_NZC_NDITH_NAC_FORCE,   BLENDER1_16_NIMR_NZC_NDITH_AC_FORCE,   BLENDER1_16_NIMR_NZC_DITH_NAC_FORCE,   BLENDER1_16_NIMR_NZC_DITH_AC_FORCE,
120   BLENDER1_16_NIMR_ZC_NDITH_NAC_FORCE,   BLENDER1_16_NIMR_ZC_NDITH_AC_FORCE,    BLENDER1_16_NIMR_ZC_DITH_NAC_FORCE,      BLENDER1_16_NIMR_ZC_DITH_AC_FORCE,
121   BLENDER1_16_IMR_NZC_NDITH_NAC_FORCE,   BLENDER1_16_IMR_NZC_NDITH_AC_FORCE,    BLENDER1_16_IMR_NZC_DITH_NAC_FORCE,      BLENDER1_16_IMR_NZC_DITH_AC_FORCE,
122   BLENDER1_16_IMR_ZC_NDITH_NAC_FORCE,    BLENDER1_16_IMR_ZC_NDITH_AC_FORCE,      BLENDER1_16_IMR_ZC_DITH_NAC_FORCE,      BLENDER1_16_IMR_ZC_DITH_AC_FORCE,
48      void             DitherRGB(INT32* r, INT32* g, INT32* b, int dith);
12349};
12450
125static int (*rdp_blender2_16_dith_func[32])(UINT16 *, UINT8 *, COLOR, COLOR, int) =
126{
127   BLENDER2_16_NIMR_NZC_NDITH_NAC_NFORCE,   BLENDER2_16_NIMR_NZC_NDITH_AC_NFORCE,   BLENDER2_16_NIMR_NZC_DITH_NAC_NFORCE,   BLENDER2_16_NIMR_NZC_DITH_AC_NFORCE,
128   BLENDER2_16_NIMR_ZC_NDITH_NAC_NFORCE,   BLENDER2_16_NIMR_ZC_NDITH_AC_NFORCE,   BLENDER2_16_NIMR_ZC_DITH_NAC_NFORCE,   BLENDER2_16_NIMR_ZC_DITH_AC_NFORCE,
129   BLENDER2_16_IMR_NZC_NDITH_NAC_NFORCE,   BLENDER2_16_IMR_NZC_NDITH_AC_NFORCE,   BLENDER2_16_IMR_NZC_DITH_NAC_NFORCE,   BLENDER2_16_IMR_NZC_DITH_AC_NFORCE,
130   BLENDER2_16_IMR_ZC_NDITH_NAC_NFORCE,   BLENDER2_16_IMR_ZC_NDITH_AC_NFORCE,    BLENDER2_16_IMR_ZC_DITH_NAC_NFORCE,      BLENDER2_16_IMR_ZC_DITH_AC_NFORCE,
131   BLENDER2_16_NIMR_NZC_NDITH_NAC_FORCE,   BLENDER2_16_NIMR_NZC_NDITH_AC_FORCE,   BLENDER2_16_NIMR_NZC_DITH_NAC_FORCE,   BLENDER2_16_NIMR_NZC_DITH_AC_FORCE,
132   BLENDER2_16_NIMR_ZC_NDITH_NAC_FORCE,   BLENDER2_16_NIMR_ZC_NDITH_AC_FORCE,    BLENDER2_16_NIMR_ZC_DITH_NAC_FORCE,      BLENDER2_16_NIMR_ZC_DITH_AC_FORCE,
133   BLENDER2_16_IMR_NZC_NDITH_NAC_FORCE,   BLENDER2_16_IMR_NZC_NDITH_AC_FORCE,    BLENDER2_16_IMR_NZC_DITH_NAC_FORCE,      BLENDER2_16_IMR_NZC_DITH_AC_FORCE,
134   BLENDER2_16_IMR_ZC_NDITH_NAC_FORCE,    BLENDER2_16_IMR_ZC_NDITH_AC_FORCE,      BLENDER2_16_IMR_ZC_DITH_NAC_FORCE,      BLENDER2_16_IMR_ZC_DITH_AC_FORCE,
135};
51} // namespace RDP
13652
137static int (*rdp_blender1_16_ndith_func[16])(UINT16 *, UINT8 *, COLOR) =
138{
139   BLENDER1_16_NIMR_NZC_NAC_ND_NFORCE,   BLENDER1_16_NIMR_NZC_AC_ND_NFORCE,
140   BLENDER1_16_NIMR_ZC_NAC_ND_NFORCE,   BLENDER1_16_NIMR_ZC_AC_ND_NFORCE,
141   BLENDER1_16_IMR_NZC_NAC_ND_NFORCE,   BLENDER1_16_IMR_NZC_AC_ND_NFORCE,
142   BLENDER1_16_IMR_ZC_NAC_ND_NFORCE,   BLENDER1_16_IMR_ZC_AC_ND_NFORCE,
143   BLENDER1_16_NIMR_NZC_NAC_ND_FORCE,   BLENDER1_16_NIMR_NZC_AC_ND_FORCE,
144   BLENDER1_16_NIMR_ZC_NAC_ND_FORCE,   BLENDER1_16_NIMR_ZC_AC_ND_FORCE,
145   BLENDER1_16_IMR_NZC_NAC_ND_FORCE,   BLENDER1_16_IMR_NZC_AC_ND_FORCE,
146   BLENDER1_16_IMR_ZC_NAC_ND_FORCE,   BLENDER1_16_IMR_ZC_AC_ND_FORCE,
147};
53} // namespace N64
14854
149static int (*rdp_blender2_16_ndith_func[16])(UINT16 *, UINT8 *, COLOR, COLOR) =
150{
151   BLENDER2_16_NIMR_NZC_NAC_ND_NFORCE,   BLENDER2_16_NIMR_NZC_AC_ND_NFORCE,
152   BLENDER2_16_NIMR_ZC_NAC_ND_NFORCE,   BLENDER2_16_NIMR_ZC_AC_ND_NFORCE,
153   BLENDER2_16_IMR_NZC_NAC_ND_NFORCE,   BLENDER2_16_IMR_NZC_AC_ND_NFORCE,
154   BLENDER2_16_IMR_ZC_NAC_ND_NFORCE,   BLENDER2_16_IMR_ZC_AC_ND_NFORCE,
155   BLENDER2_16_NIMR_NZC_NAC_ND_FORCE,   BLENDER2_16_NIMR_NZC_AC_ND_FORCE,
156   BLENDER2_16_NIMR_ZC_NAC_ND_FORCE,   BLENDER2_16_NIMR_ZC_AC_ND_FORCE,
157   BLENDER2_16_IMR_NZC_NAC_ND_FORCE,   BLENDER2_16_IMR_NZC_AC_ND_FORCE,
158   BLENDER2_16_IMR_ZC_NAC_ND_FORCE,   BLENDER2_16_IMR_ZC_AC_ND_FORCE,
159};
55#endif // _VIDEO_RDPBLEND_H_
No newline at end of file
src/mame/video/rdpspn16.c
r7675r7676
1#if defined(MAGICDITHER)
2   #if defined(SHADE)
3      #if defined(TEXTURE)
4         #if defined(ZBUF)
5            #if defined(FLIP)
6               #if defined(ZUPDATE)
7                  #if defined(ZCOMPARE)
8                     static void render_spans_16_c1_s_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
9                  #else
10                     static void render_spans_16_c1_s_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
11                  #endif
12               #else
13                  #if defined(ZCOMPARE)
14                     static void render_spans_16_c1_s_t_z_f_zc_dm(int start, int end, TILE* tex_tile)
15                  #else
16                     static void render_spans_16_c1_s_t_z_f_nzc_dm(int start, int end, TILE* tex_tile)
17                  #endif
18               #endif
19            #else
20               #if defined(ZUPDATE)
21                  #if defined(ZCOMPARE)
22                     static void render_spans_16_c1_s_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
23                  #else
24                     static void render_spans_16_c1_s_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
25                  #endif
26               #else
27                  #if defined(ZCOMPARE)
28                     static void render_spans_16_c1_s_t_z_nf_zc_dm(int start, int end, TILE* tex_tile)
29                  #else
30                     static void render_spans_16_c1_s_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
31                  #endif
32               #endif
33            #endif
34         #else
35            #if defined(FLIP)
36               #if defined(ZUPDATE)
37                  #if defined(ZCOMPARE)
38                     static void render_spans_16_c1_s_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
39                  #else
40                     static void render_spans_16_c1_s_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
41                  #endif
42               #else
43                  #if defined(ZCOMPARE)
44                     static void render_spans_16_c1_s_t_nz_f_zc_dm(int start, int end, TILE* tex_tile)
45                  #else
46                     static void render_spans_16_c1_s_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
47                  #endif
48               #endif
49            #else
50               #if defined(ZUPDATE)
51                  #if defined(ZCOMPARE)
52                     static void render_spans_16_c1_s_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
53                  #else
54                     static void render_spans_16_c1_s_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
55                  #endif
56               #else
57                  #if defined(ZCOMPARE)
58                     static void render_spans_16_c1_s_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
59                  #else
60                     static void render_spans_16_c1_s_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
61                  #endif
62               #endif
63            #endif
64         #endif
65      #else
66         #if defined(ZBUF)
67            #if defined(FLIP)
68               #if defined(ZUPDATE)
69                  #if defined(ZCOMPARE)
70                     static void render_spans_16_c1_s_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
71                  #else
72                     static void render_spans_16_c1_s_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
73                  #endif
74               #else
75                  #if defined(ZCOMPARE)
76                     static void render_spans_16_c1_s_nt_z_f_zc_dm(int start, int end, TILE* tex_tile)
77                  #else
78                     static void render_spans_16_c1_s_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile)
79                  #endif
80               #endif
81            #else
82               #if defined(ZUPDATE)
83                  #if defined(ZCOMPARE)
84                     static void render_spans_16_c1_s_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
85                  #else
86                     static void render_spans_16_c1_s_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
87                  #endif
88               #else
89                  #if defined(ZCOMPARE)
90                     static void render_spans_16_c1_s_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile)
91                  #else
92                     static void render_spans_16_c1_s_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
93                  #endif
94               #endif
95            #endif
96         #else
97            #if defined(FLIP)
98               #if defined(ZUPDATE)
99                  #if defined(ZCOMPARE)
100                     static void render_spans_16_c1_s_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
101                  #else
102                     static void render_spans_16_c1_s_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
103                  #endif
104               #else
105                  #if defined(ZCOMPARE)
106                     static void render_spans_16_c1_s_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile)
107                  #else
108                     static void render_spans_16_c1_s_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
109                  #endif
110               #endif
111            #else
112               #if defined(ZUPDATE)
113                  #if defined(ZCOMPARE)
114                     static void render_spans_16_c1_s_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
115                  #else
116                     static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
117                  #endif
118               #else
119                  #if defined(ZCOMPARE)
120                     static void render_spans_16_c1_s_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
121                  #else
122                     static void render_spans_16_c1_s_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
123                  #endif
124               #endif
125            #endif
126         #endif
127      #endif
128   #else
129      #if defined(TEXTURE)
130         #if defined(ZBUF)
131            #if defined(FLIP)
132               #if defined(ZUPDATE)
133                  #if defined(ZCOMPARE)
134                     static void render_spans_16_c1_ns_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
135                  #else
136                     static void render_spans_16_c1_ns_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
137                  #endif
138               #else
139                  #if defined(ZCOMPARE)
140                     static void render_spans_16_c1_ns_t_z_f_zc_dm(int start, int end, TILE* tex_tile)
141                  #else
142                     static void render_spans_16_c1_ns_t_z_f_nzc_dm(int start, int end, TILE* tex_tile)
143                  #endif
144               #endif
145            #else
146               #if defined(ZUPDATE)
147                  #if defined(ZCOMPARE)
148                     static void render_spans_16_c1_ns_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
149                  #else
150                     static void render_spans_16_c1_ns_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
151                  #endif
152               #else
153                  #if defined(ZCOMPARE)
154                     static void render_spans_16_c1_ns_t_z_nf_zc_dm(int start, int end, TILE* tex_tile)
155                  #else
156                     static void render_spans_16_c1_ns_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
157                  #endif
158               #endif
159            #endif
160         #else
161            #if defined(FLIP)
162               #if defined(ZUPDATE)
163                  #if defined(ZCOMPARE)
164                     static void render_spans_16_c1_ns_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
165                  #else
166                     static void render_spans_16_c1_ns_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
167                  #endif
168               #else
169                  #if defined(ZCOMPARE)
170                     static void render_spans_16_c1_ns_t_nz_f_zc_dm(int start, int end, TILE* tex_tile)
171                  #else
172                     static void render_spans_16_c1_ns_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
173                  #endif
174               #endif
175            #else
176               #if defined(ZUPDATE)
177                  #if defined(ZCOMPARE)
178                     static void render_spans_16_c1_ns_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
179                  #else
180                     static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
181                  #endif
182               #else
183                  #if defined(ZCOMPARE)
184                     static void render_spans_16_c1_ns_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
185                  #else
186                     static void render_spans_16_c1_ns_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
187                  #endif
188               #endif
189            #endif
190         #endif
191      #else
192         #if defined(ZBUF)
193            #if defined(FLIP)
194               #if defined(ZUPDATE)
195                  #if defined(ZCOMPARE)
196                     static void render_spans_16_c1_ns_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
197                  #else
198                     static void render_spans_16_c1_ns_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
199                  #endif
200               #else
201                  #if defined(ZCOMPARE)
202                     static void render_spans_16_c1_ns_nt_z_f_zc_dm(int start, int end, TILE* tex_tile)
203                  #else
204                     static void render_spans_16_c1_ns_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile)
205                  #endif
206               #endif
207            #else
208               #if defined(ZUPDATE)
209                  #if defined(ZCOMPARE)
210                     static void render_spans_16_c1_ns_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
211                  #else
212                     static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
213                  #endif
214               #else
215                  #if defined(ZCOMPARE)
216                     static void render_spans_16_c1_ns_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile)
217                  #else
218                     static void render_spans_16_c1_ns_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
219                  #endif
220               #endif
221            #endif
222         #else
223            #if defined(FLIP)
224               #if defined(ZUPDATE)
225                  #if defined(ZCOMPARE)
226                     static void render_spans_16_c1_ns_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
227                  #else
228                     static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
229                  #endif
230               #else
231                  #if defined(ZCOMPARE)
232                     static void render_spans_16_c1_ns_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile)
233                  #else
234                     static void render_spans_16_c1_ns_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
235                  #endif
236               #endif
237            #else
238               #if defined(ZUPDATE)
239                  #if defined(ZCOMPARE)
240                     static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
241                  #else
242                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
243                  #endif
244               #else
245                  #if defined(ZCOMPARE)
246                     static void render_spans_16_c1_ns_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
247                  #else
248                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
249                  #endif
250               #endif
251            #endif
252         #endif
253      #endif
254   #endif
255#elif defined(BAYERDITHER)
256   #if defined(SHADE)
257      #if defined(TEXTURE)
258         #if defined(ZBUF)
259            #if defined(FLIP)
260               #if defined(ZUPDATE)
261                  #if defined(ZCOMPARE)
262                     static void render_spans_16_c1_s_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
263                  #else
264                     static void render_spans_16_c1_s_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
265                  #endif
266               #else
267                  #if defined(ZCOMPARE)
268                     static void render_spans_16_c1_s_t_z_f_zc_db(int start, int end, TILE* tex_tile)
269                  #else
270                     static void render_spans_16_c1_s_t_z_f_nzc_db(int start, int end, TILE* tex_tile)
271                  #endif
272               #endif
273            #else
274               #if defined(ZUPDATE)
275                  #if defined(ZCOMPARE)
276                     static void render_spans_16_c1_s_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
277                  #else
278                     static void render_spans_16_c1_s_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
279                  #endif
280               #else
281                  #if defined(ZCOMPARE)
282                     static void render_spans_16_c1_s_t_z_nf_zc_db(int start, int end, TILE* tex_tile)
283                  #else
284                     static void render_spans_16_c1_s_t_z_nf_nzc_db(int start, int end, TILE* tex_tile)
285                  #endif
286               #endif
287            #endif
288         #else
289            #if defined(FLIP)
290               #if defined(ZUPDATE)
291                  #if defined(ZCOMPARE)
292                     static void render_spans_16_c1_s_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
293                  #else
294                     static void render_spans_16_c1_s_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
295                  #endif
296               #else
297                  #if defined(ZCOMPARE)
298                     static void render_spans_16_c1_s_t_nz_f_zc_db(int start, int end, TILE* tex_tile)
299                  #else
300                     static void render_spans_16_c1_s_t_nz_f_nzc_db(int start, int end, TILE* tex_tile)
301                  #endif
302               #endif
303            #else
304               #if defined(ZUPDATE)
305                  #if defined(ZCOMPARE)
306                     static void render_spans_16_c1_s_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
307                  #else
308                     static void render_spans_16_c1_s_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
309                  #endif
310               #else
311                  #if defined(ZCOMPARE)
312                     static void render_spans_16_c1_s_t_nz_nf_zc_db(int start, int end, TILE* tex_tile)
313                  #else
314                     static void render_spans_16_c1_s_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
315                  #endif
316               #endif
317            #endif
318         #endif
319      #else
320         #if defined(ZBUF)
321            #if defined(FLIP)
322               #if defined(ZUPDATE)
323                  #if defined(ZCOMPARE)
324                     static void render_spans_16_c1_s_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
325                  #else
326                     static void render_spans_16_c1_s_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
327                  #endif
328               #else
329                  #if defined(ZCOMPARE)
330                     static void render_spans_16_c1_s_nt_z_f_zc_db(int start, int end, TILE* tex_tile)
331                  #else
332                     static void render_spans_16_c1_s_nt_z_f_nzc_db(int start, int end, TILE* tex_tile)
333                  #endif
334               #endif
335            #else
336               #if defined(ZUPDATE)
337                  #if defined(ZCOMPARE)
338                     static void render_spans_16_c1_s_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
339                  #else
340                     static void render_spans_16_c1_s_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
341                  #endif
342               #else
343                  #if defined(ZCOMPARE)
344                     static void render_spans_16_c1_s_nt_z_nf_zc_db(int start, int end, TILE* tex_tile)
345                  #else
346                     static void render_spans_16_c1_s_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile)
347                  #endif
348               #endif
349            #endif
350         #else
351            #if defined(FLIP)
352               #if defined(ZUPDATE)
353                  #if defined(ZCOMPARE)
354                     static void render_spans_16_c1_s_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
355                  #else
356                     static void render_spans_16_c1_s_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
357                  #endif
358               #else
359                  #if defined(ZCOMPARE)
360                     static void render_spans_16_c1_s_nt_nz_f_zc_db(int start, int end, TILE* tex_tile)
361                  #else
362                     static void render_spans_16_c1_s_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile)
363                  #endif
364               #endif
365            #else
366               #if defined(ZUPDATE)
367                  #if defined(ZCOMPARE)
368                     static void render_spans_16_c1_s_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
369                  #else
370                     static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
371                  #endif
372               #else
373                  #if defined(ZCOMPARE)
374                     static void render_spans_16_c1_s_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile)
375                  #else
376                     static void render_spans_16_c1_s_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
377                  #endif
378               #endif
379            #endif
380         #endif
381      #endif
382   #else
383      #if defined(TEXTURE)
384         #if defined(ZBUF)
385            #if defined(FLIP)
386               #if defined(ZUPDATE)
387                  #if defined(ZCOMPARE)
388                     static void render_spans_16_c1_ns_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
389                  #else
390                     static void render_spans_16_c1_ns_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
391                  #endif
392               #else
393                  #if defined(ZCOMPARE)
394                     static void render_spans_16_c1_ns_t_z_f_zc_db(int start, int end, TILE* tex_tile)
395                  #else
396                     static void render_spans_16_c1_ns_t_z_f_nzc_db(int start, int end, TILE* tex_tile)
397                  #endif
398               #endif
399            #else
400               #if defined(ZUPDATE)
401                  #if defined(ZCOMPARE)
402                     static void render_spans_16_c1_ns_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
403                  #else
404                     static void render_spans_16_c1_ns_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
405                  #endif
406               #else
407                  #if defined(ZCOMPARE)
408                     static void render_spans_16_c1_ns_t_z_nf_zc_db(int start, int end, TILE* tex_tile)
409                  #else
410                     static void render_spans_16_c1_ns_t_z_nf_nzc_db(int start, int end, TILE* tex_tile)
411                  #endif
412               #endif
413            #endif
414         #else
415            #if defined(FLIP)
416               #if defined(ZUPDATE)
417                  #if defined(ZCOMPARE)
418                     static void render_spans_16_c1_ns_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
419                  #else
420                     static void render_spans_16_c1_ns_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
421                  #endif
422               #else
423                  #if defined(ZCOMPARE)
424                     static void render_spans_16_c1_ns_t_nz_f_zc_db(int start, int end, TILE* tex_tile)
425                  #else
426                     static void render_spans_16_c1_ns_t_nz_f_nzc_db(int start, int end, TILE* tex_tile)
427                  #endif
428               #endif
429            #else
430               #if defined(ZUPDATE)
431                  #if defined(ZCOMPARE)
432                     static void render_spans_16_c1_ns_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
433                  #else
434                     static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
435                  #endif
436               #else
437                  #if defined(ZCOMPARE)
438                     static void render_spans_16_c1_ns_t_nz_nf_zc_db(int start, int end, TILE* tex_tile)
439                  #else
440                     static void render_spans_16_c1_ns_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
441                  #endif
442               #endif
443            #endif
444         #endif
445      #else
446         #if defined(ZBUF)
447            #if defined(FLIP)
448               #if defined(ZUPDATE)
449                  #if defined(ZCOMPARE)
450                     static void render_spans_16_c1_ns_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
451                  #else
452                     static void render_spans_16_c1_ns_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
453                  #endif
454               #else
455                  #if defined(ZCOMPARE)
456                     static void render_spans_16_c1_ns_nt_z_f_zc_db(int start, int end, TILE* tex_tile)
457                  #else
458                     static void render_spans_16_c1_ns_nt_z_f_nzc_db(int start, int end, TILE* tex_tile)
459                  #endif
460               #endif
461            #else
462               #if defined(ZUPDATE)
463                  #if defined(ZCOMPARE)
464                     static void render_spans_16_c1_ns_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
465                  #else
466                     static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
467                  #endif
468               #else
469                  #if defined(ZCOMPARE)
470                     static void render_spans_16_c1_ns_nt_z_nf_zc_db(int start, int end, TILE* tex_tile)
471                  #else
472                     static void render_spans_16_c1_ns_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile)
473                  #endif
474               #endif
475            #endif
476         #else
477            #if defined(FLIP)
478               #if defined(ZUPDATE)
479                  #if defined(ZCOMPARE)
480                     static void render_spans_16_c1_ns_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
481                  #else
482                     static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
483                  #endif
484               #else
485                  #if defined(ZCOMPARE)
486                     static void render_spans_16_c1_ns_nt_nz_f_zc_db(int start, int end, TILE* tex_tile)
487                  #else
488                     static void render_spans_16_c1_ns_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile)
489                  #endif
490               #endif
491            #else
492               #if defined(ZUPDATE)
493                  #if defined(ZCOMPARE)
494                     static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
495                  #else
496                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
497                  #endif
498               #else
499                  #if defined(ZCOMPARE)
500                     static void render_spans_16_c1_ns_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile)
501                  #else
502                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
503                  #endif
504               #endif
505            #endif
506         #endif
507      #endif
508   #endif
509#else
510   #if defined(SHADE)
511      #if defined(TEXTURE)
512         #if defined(ZBUF)
513            #if defined(FLIP)
514               #if defined(ZUPDATE)
515                  #if defined(ZCOMPARE)
516                     static void render_spans_16_c1_s_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
517                  #else
518                     static void render_spans_16_c1_s_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
519                  #endif
520               #else
521                  #if defined(ZCOMPARE)
522                     static void render_spans_16_c1_s_t_z_f_zc_dn(int start, int end, TILE* tex_tile)
523                  #else
524                     static void render_spans_16_c1_s_t_z_f_nzc_dn(int start, int end, TILE* tex_tile)
525                  #endif
526               #endif
527            #else
528               #if defined(ZUPDATE)
529                  #if defined(ZCOMPARE)
530                     static void render_spans_16_c1_s_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
531                  #else
532                     static void render_spans_16_c1_s_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
533                  #endif
534               #else
535                  #if defined(ZCOMPARE)
536                     static void render_spans_16_c1_s_t_z_nf_zc_dn(int start, int end, TILE* tex_tile)
537                  #else
538                     static void render_spans_16_c1_s_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
539                  #endif
540               #endif
541            #endif
542         #else
543            #if defined(FLIP)
544               #if defined(ZUPDATE)
545                  #if defined(ZCOMPARE)
546                     static void render_spans_16_c1_s_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
547                  #else
548                     static void render_spans_16_c1_s_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
549                  #endif
550               #else
551                  #if defined(ZCOMPARE)
552                     static void render_spans_16_c1_s_t_nz_f_zc_dn(int start, int end, TILE* tex_tile)
553                  #else
554                     static void render_spans_16_c1_s_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
555                  #endif
556               #endif
557            #else
558               #if defined(ZUPDATE)
559                  #if defined(ZCOMPARE)
560                     static void render_spans_16_c1_s_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
561                  #else
562                     static void render_spans_16_c1_s_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
563                  #endif
564               #else
565                  #if defined(ZCOMPARE)
566                     static void render_spans_16_c1_s_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
567                  #else
568                     static void render_spans_16_c1_s_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
569                  #endif
570               #endif
571            #endif
572         #endif
573      #else
574         #if defined(ZBUF)
575            #if defined(FLIP)
576               #if defined(ZUPDATE)
577                  #if defined(ZCOMPARE)
578                     static void render_spans_16_c1_s_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
579                  #else
580                     static void render_spans_16_c1_s_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
581                  #endif
582               #else
583                  #if defined(ZCOMPARE)
584                     static void render_spans_16_c1_s_nt_z_f_zc_dn(int start, int end, TILE* tex_tile)
585                  #else
586                     static void render_spans_16_c1_s_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile)
587                  #endif
588               #endif
589            #else
590               #if defined(ZUPDATE)
591                  #if defined(ZCOMPARE)
592                     static void render_spans_16_c1_s_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
593                  #else
594                     static void render_spans_16_c1_s_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
595                  #endif
596               #else
597                  #if defined(ZCOMPARE)
598                     static void render_spans_16_c1_s_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile)
599                  #else
600                     static void render_spans_16_c1_s_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
601                  #endif
602               #endif
603            #endif
604         #else
605            #if defined(FLIP)
606               #if defined(ZUPDATE)
607                  #if defined(ZCOMPARE)
608                     static void render_spans_16_c1_s_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
609                  #else
610                     static void render_spans_16_c1_s_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
611                  #endif
612               #else
613                  #if defined(ZCOMPARE)
614                     static void render_spans_16_c1_s_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile)
615                  #else
616                     static void render_spans_16_c1_s_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
617                  #endif
618               #endif
619            #else
620               #if defined(ZUPDATE)
621                  #if defined(ZCOMPARE)
622                     static void render_spans_16_c1_s_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
623                  #else
624                     static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
625                  #endif
626               #else
627                  #if defined(ZCOMPARE)
628                     static void render_spans_16_c1_s_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
629                  #else
630                     static void render_spans_16_c1_s_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
631                  #endif
632               #endif
633            #endif
634         #endif
635      #endif
636   #else
637      #if defined(TEXTURE)
638         #if defined(ZBUF)
639            #if defined(FLIP)
640               #if defined(ZUPDATE)
641                  #if defined(ZCOMPARE)
642                     static void render_spans_16_c1_ns_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
643                  #else
644                     static void render_spans_16_c1_ns_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
645                  #endif
646               #else
647                  #if defined(ZCOMPARE)
648                     static void render_spans_16_c1_ns_t_z_f_zc_dn(int start, int end, TILE* tex_tile)
649                  #else
650                     static void render_spans_16_c1_ns_t_z_f_nzc_dn(int start, int end, TILE* tex_tile)
651                  #endif
652               #endif
653            #else
654               #if defined(ZUPDATE)
655                  #if defined(ZCOMPARE)
656                     static void render_spans_16_c1_ns_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
657                  #else
658                     static void render_spans_16_c1_ns_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
659                  #endif
660               #else
661                  #if defined(ZCOMPARE)
662                     static void render_spans_16_c1_ns_t_z_nf_zc_dn(int start, int end, TILE* tex_tile)
663                  #else
664                     static void render_spans_16_c1_ns_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
665                  #endif
666               #endif
667            #endif
668         #else
669            #if defined(FLIP)
670               #if defined(ZUPDATE)
671                  #if defined(ZCOMPARE)
672                     static void render_spans_16_c1_ns_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
673                  #else
674                     static void render_spans_16_c1_ns_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
675                  #endif
676               #else
677                  #if defined(ZCOMPARE)
678                     static void render_spans_16_c1_ns_t_nz_f_zc_dn(int start, int end, TILE* tex_tile)
679                  #else
680                     static void render_spans_16_c1_ns_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
681                  #endif
682               #endif
683            #else
684               #if defined(ZUPDATE)
685                  #if defined(ZCOMPARE)
686                     static void render_spans_16_c1_ns_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
687                  #else
688                     static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
689                  #endif
690               #else
691                  #if defined(ZCOMPARE)
692                     static void render_spans_16_c1_ns_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
693                  #else
694                     static void render_spans_16_c1_ns_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
695                  #endif
696               #endif
697            #endif
698         #endif
699      #else
700         #if defined(ZBUF)
701            #if defined(FLIP)
702               #if defined(ZUPDATE)
703                  #if defined(ZCOMPARE)
704                     static void render_spans_16_c1_ns_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
705                  #else
706                     static void render_spans_16_c1_ns_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
707                  #endif
708               #else
709                  #if defined(ZCOMPARE)
710                     static void render_spans_16_c1_ns_nt_z_f_zc_dn(int start, int end, TILE* tex_tile)
711                  #else
712                     static void render_spans_16_c1_ns_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile)
713                  #endif
714               #endif
715            #else
716               #if defined(ZUPDATE)
717                  #if defined(ZCOMPARE)
718                     static void render_spans_16_c1_ns_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
719                  #else
720                     static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
721                  #endif
722               #else
723                  #if defined(ZCOMPARE)
724                     static void render_spans_16_c1_ns_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile)
725                  #else
726                     static void render_spans_16_c1_ns_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
727                  #endif
728               #endif
729            #endif
730         #else
731            #if defined(FLIP)
732               #if defined(ZUPDATE)
733                  #if defined(ZCOMPARE)
734                     static void render_spans_16_c1_ns_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
735                  #else
736                     static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
737                  #endif
738               #else
739                  #if defined(ZCOMPARE)
740                     static void render_spans_16_c1_ns_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile)
741                  #else
742                     static void render_spans_16_c1_ns_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
743                  #endif
744               #endif
745            #else
746               #if defined(ZUPDATE)
747                  #if defined(ZCOMPARE)
748                     static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
749                  #else
750                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
751                  #endif
752               #else
753                  #if defined(ZCOMPARE)
754                     static void render_spans_16_c1_ns_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
755                  #else
756                     static void render_spans_16_c1_ns_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
757                  #endif
758               #endif
759            #endif
760         #endif
761      #endif
762   #endif
763#endif
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
4
5namespace N64
7646{
765   UINT16 *fb = (UINT16*)&rdram[fb_address / 4];
766   UINT8 *hb = &hidden_bits[fb_address >> 1];
767#if defined(ZUPDATE) || defined(ZCOMPARE)
768   UINT16 *zb = (UINT16*)&rdram[zb_address / 4];
769   UINT8 *zhb = &hidden_bits[zb_address >> 1];
770#endif
7717
772#if defined(SHADE)
773   SPAN_PARAM dr = span[0].dr;
774   SPAN_PARAM dg = span[0].dg;
775   SPAN_PARAM db = span[0].db;
776   SPAN_PARAM da = span[0].da;
777#if defined(FLIP)
778   int drinc = dr.w;
779   int dginc = dg.w;
780   int dbinc = db.w;
781   int dainc = da.w;
782#else
783   int drinc = -dr.w;
784   int dginc = -dg.w;
785   int dbinc = -db.w;
786   int dainc = -da.w;
787#endif
788#endif
8namespace RDP
9{
78910
790#if defined(TEXTURE)
791   UINT32 prim_tile = tex_tile->num;
792   UINT32 disable_lod = 0;
793   int tilenum;
11#define LookUpCC(A, B, C, D) m_rdp->GetCCLUT2()[(m_rdp->GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
79412
795   SPAN_PARAM ds = span[0].ds;
796   SPAN_PARAM dt = span[0].dt;
797   SPAN_PARAM dw = span[0].dw;
798#if defined(FLIP)
799   int dsinc = ds.w;
800   int dtinc = dt.w;
801   int dwinc = dw.w;
802#else
803   int dsinc = -ds.w;
804   int dtinc = -dt.w;
805   int dwinc = -dw.w;
806#endif
807#endif
13void Processor::RenderSpans(int start, int end, int tilenum, bool shade, bool texture, bool zbuffer, bool flip)
14{
15   m_tex_pipe.CalculateClampDiffs(tilenum);
80816
809#if defined(ZBUF)
810   SPAN_PARAM dz = span[0].dz;
811   int dzpix = span[0].dzpix;
812#if defined(FLIP)
813   int dzinc = dz.w;
814#else
815   int dzinc = -dz.w;
816#endif
817#else
818   int sz = 0, dzpix = 0;
17   int clipy1 = GetScissor()->m_yh;
18   int clipy2 = GetScissor()->m_yl;
81919
820   if (other_modes.z_source_sel)
20   if (start < clipy1)
82121   {
822      sz = (((UINT32)primitive_z) << 3) & 0x3ffff;
823      dzpix = primitive_delta_z;
22      start = clipy1;
82423   }
825#endif
826
827#if defined(TEXTURE)
828   calculate_clamp_diffs(tex_tile->num);
829
830   if (!other_modes.tex_lod_en)
24   if (start >= clipy2)
83125   {
832      tilenum = prim_tile;
833      tex_tile = &tile[tilenum];
26      start = clipy2 - 1;
83427   }
835   else
28   if (end < clipy1)
83629   {
837      disable_lod = 1; // Used by World Driver Championship
30      end = clipy1;
83831   }
839#endif
840
841   if (start < clip.yh)
32   if (end >= clipy2) // Needed by 40 Winks
84233   {
843      start = clip.yh;
34      end = clipy2 - 1;
84435   }
845   if (start >= clip.yl)
36
37   for(int i = start; i <= end; i++)
84638   {
847      start = clip.yl - 1;
39      m_span[i].SetMachine(m_machine);
40      m_span[i].Draw(i, tilenum, shade, texture, zbuffer, flip);
84841   }
849   if (end < clip.yh)
850   {
851      end = clip.yh;
852   }
853   if (end >= clip.yl) // Needed by 40 Winks
854   {
855      end = clip.yl - 1;
856   }
42}
85743
858#if !defined(SHADE)
859   shade_color.c = prim_color.c;
860#endif
44void Span::Dump()
45{
46   printf("    m_lx = %d\n", m_lx);
47   printf("    m_rx = %d\n",  m_rx);
48   printf("    m_s.w = %08x\n", m_s.w);
49   printf("    m_t.w = %08x\n", m_t.w);
50   printf("    m_w.w = %08x\n", m_w.w);
51   printf("    m_r.w = %08x\n", m_r.w);
52   printf("    m_g.w = %08x\n", m_g.w);
53   printf("    m_b.w = %08x\n", m_b.w);
54   printf("    m_a.w = %08x\n", m_a.w);
55   printf("    m_z.w = %08x\n", m_z.w);
86156
862   CACHE_TEXTURE_PARAMS(tex_tile);
863
864   for (int i = start; i <= end; i++)
57   printf("    CVG: ");
58   for(int index = 0; index < RDP_CVG_SPAN_MAX; index++)
86559   {
866      int x = span[i].rx;
60      printf("%d", m_cvg[index]);
61   }
62   printf("\n");
86763
868      int fb_index = fb_width * i;
64   printf("    m_dymax = %08x\n", m_dymax);
65   printf("    m_ds.w = %08x\n", m_ds.w);
66   printf("    m_dt.w = %08x\n", m_dt.w);
67   printf("    m_dw.w = %08x\n", m_dw.w);
68   printf("    m_dr.w = %08x\n", m_dr.w);
69   printf("    m_dg.w = %08x\n", m_dg.w);
70   printf("    m_db.w = %08x\n", m_db.w);
71   printf("    m_da.w = %08x\n", m_da.w);
72   printf("    m_dz.w = %08x\n", m_dz.w);
73   printf("    m_dzpix = %08x\n", m_dzpix);
74}
86975
870#if defined(SHADE)
871      SPAN_PARAM r = span[i].r;
872      SPAN_PARAM g = span[i].g;
873      SPAN_PARAM b = span[i].b;
874      SPAN_PARAM a = span[i].a;
875#endif
876#if defined(TEXTURE)
877      SPAN_PARAM s = span[i].s;
878      SPAN_PARAM t = span[i].t;
879      SPAN_PARAM w = span[i].w;
880#endif
881#if defined(ZBUF)
882      SPAN_PARAM z = span[i].z;
883#endif
76void Span::SetMachine(running_machine *machine)
77{
78   _n64_state *state = (_n64_state *)machine->driver_data;
88479
885#if defined(FLIP)
886      int length = (span[i].lx - span[i].rx);
887#else
888      int length = (span[i].rx - span[i].lx);
889#endif
80   m_machine = machine;
81   m_rdp = &state->m_rdp;
82   m_other_modes = m_rdp->GetOtherModes();
83   m_misc_state = m_rdp->GetMiscState();
84}
89085
891      for (int j = 0; j <= length; j++)
892      {
893#if defined(SHADE)
894         int sr = r.h.h;
895         int sg = g.h.h;
896         int sb = b.h.h;
897         int sa = a.h.h;
898#endif
899#if defined(TEXTURE)
900         int ss = s.h.h;
901         int st = t.h.h;
902         int sw = w.h.h;
903         int sss = 0, sst = 0;
904#endif
905#if defined(ZBUF)
906         int sz = z.w >> 13;
907#endif
908         COLOR c1;
909         //c1.c = 0;
86void Span::Draw(int index, int tilenum, bool shade, bool texture, bool zbuffer, bool flip)
87{
88   int clipx1 = m_rdp->GetScissor()->m_xh;
89   int clipx2 = m_rdp->GetScissor()->m_xl;
91090
911#if defined(ZBUF)
912         if (other_modes.z_source_sel)
913         {
914            sz = (((UINT32)primitive_z) << 3) & 0x3ffff;
915            dzpix = primitive_delta_z;
916         }
917#endif
91   SpanParam r = m_r;
92   SpanParam g = m_g;
93   SpanParam b = m_b;
94   SpanParam a = m_a;
95   SpanParam z = m_z;
96   SpanParam s = m_s;
97   SpanParam t = m_t;
98   SpanParam w = m_w;
91899
919         if (x >= clip.xh && x < clip.xl)
920         {
921#if defined(ZCOMPARE)
922            int z_compare_result = 1;
923#endif
100   UINT16 *fb = (UINT16*)&rdram[m_misc_state->m_fb_address / 4];
101   UINT16 *zb = (UINT16*)&rdram[m_misc_state->m_zb_address / 4];
102   UINT8 *hb = &m_rdp->GetHiddenBits()[m_misc_state->m_fb_address >> 1];
103   UINT8 *zhb = &m_rdp->GetHiddenBits()[m_misc_state->m_zb_address >> 1];
924104
925            curpixel_cvg=span[i].cvg[x];
105   UINT32 prim_tile = tilenum;
106   UINT32 tilenum2 = 0;
926107
927            if (curpixel_cvg)
928            {
929               int curpixel = fb_index + x;
930               UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
931               UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
932#if defined(ZUPDATE) || defined(ZCOMPARE)
933               UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
934               UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
935#endif
108   int dzpix = m_dzpix;
109   int drinc = flip ? (m_dr.w) : -m_dr.w;
110   int dginc = flip ? (m_dg.w) : -m_dg.w;
111   int dbinc = flip ? (m_db.w) : -m_db.w;
112   int dainc = flip ? (m_da.w) : -m_da.w;
113   int dzinc = flip ? (m_dz.w) : -m_dz.w;
114   int dsinc = flip ? (m_ds.w) : -m_ds.w;
115   int dtinc = flip ? (m_dt.w) : -m_dt.w;
116   int dwinc = flip ? (m_dw.w) : -m_dw.w;
117   int xinc = flip ? 1 : -1;
936118
937#if defined(TEXTURE)
938               if (other_modes.persp_tex_en)
939               {
940                  tcdiv(ss, st, sw, &sss, &sst);
941               }
942               else // Hack for Bust-a-Move 2
943               {
944                  sss = ss;
945                  sst = st;
946               }
947#endif
119   int nexts;
120   int nextt;
121   int nextsw;
948122
949#if defined(SHADE)
950               if (sr > 0xff) shade_color.i.r = 0xff;
951               else if (sr < 0) shade_color.i.r = 0;
952               else shade_color.i.r = sr;
953               if (sg > 0xff) shade_color.i.g = 0xff;
954               else if (sg < 0) shade_color.i.g = 0;
955               else shade_color.i.g = sg;
956               if (sb > 0xff) shade_color.i.b = 0xff;
957               else if (sb < 0) shade_color.i.b = 0;
958               else shade_color.i.b = sb;
959               if (sa > 0xff) shade_color.i.a = 0xff;
960               else if (sa < 0) shade_color.i.a = 0;
961               else shade_color.i.a = sa;
962#endif
123   int fb_index = m_misc_state->m_fb_width * index;
963124
964#if defined(TEXTURE)
965               texel0_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile);
966#endif
125   int x = m_rx;
967126
968               COLOR_COMBINER1(c1);
127   int length = flip ? (m_lx - m_rx) : (m_rx - m_lx);
969128
970#if defined(ZCOMPARE)
971#if !defined(ZBUF)
972               if (other_modes.z_source_sel)
973#endif
974               {
975                  z_compare_result = z_compare(fbcur, hbcur, zbcur, zhbcur, sz, dzpix);
976               }
977
978               if(z_compare_result)
979#endif
980               {
981#if defined(ZUPDATE)
982#endif
983#if defined(MAGICDITHER)
984                  int dith = magic_matrix[(((i) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
985#elif defined(BAYERDITHER)
986                  int dith = bayer_matrix[(((i) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
987#endif
988
989#if defined(ZUPDATE)
990#if defined(MAGICDITHER) || defined(BAYERDITHER)
991                  int rendered = BLENDER1_16_DITH(fbcur, hbcur, c1, dith);
992#else
993                  int rendered = BLENDER1_16_NDITH(fbcur, hbcur, c1);
994#endif
995
996                  if (rendered)
997                  {
998                     z_store(zbcur, zhbcur, sz, dzpix);
999                  }
1000#else
1001#if defined(MAGICDITHER) || defined(BAYERDITHER)
1002                  BLENDER1_16_DITH(fbcur, hbcur, c1, dith);
1003#else
1004                  BLENDER1_16_NDITH(fbcur, hbcur, c1);
1005#endif
1006#endif
1007               }
1008            }
1009         }
1010
1011#if defined(SHADE)
1012         r.w += drinc;
1013         g.w += dginc;
1014         b.w += dbinc;
1015         a.w += dainc;
1016#endif
1017#if defined(TEXTURE)
1018         s.w += dsinc;
1019         t.w += dtinc;
1020         w.w += dwinc;
1021#endif
1022#if defined(ZBUF)
1023         z.w += dzinc;
1024#endif
1025
1026#if defined(FLIP)
1027         x++;
1028#else
1029         x--;
1030#endif
1031      }
129   bool disable_lod = false;
130   if (m_other_modes->tex_lod_en && m_other_modes->cycle_type != CYCLE_TYPE_2) // Used by World Driver Championship
131   {
132      disable_lod = true;
1032133   }
1033}
1034134
1035#if defined(MAGICDITHER)
1036   #if defined(SHADE)
1037      #if defined(TEXTURE)
1038         #if defined(ZBUF)
1039            #if defined(FLIP)
1040               #if defined(ZUPDATE)
1041                  #if defined(ZCOMPARE)
1042                  static void render_spans_16_c2_s_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1043                  #else
1044                  static void render_spans_16_c2_s_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1045                  #endif
1046               #else
1047                  #if defined(ZCOMPARE)
1048                  static void render_spans_16_c2_s_t_z_f_zc_dm(int start, int end, TILE* tex_tile)
1049                  #else
1050                  static void render_spans_16_c2_s_t_z_f_nzc_dm(int start, int end, TILE* tex_tile)
1051                  #endif
1052               #endif
1053            #else
1054               #if defined(ZUPDATE)
1055                  #if defined(ZCOMPARE)
1056                  static void render_spans_16_c2_s_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1057                  #else
1058                  static void render_spans_16_c2_s_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1059                  #endif
1060               #else
1061                  #if defined(ZCOMPARE)
1062                  static void render_spans_16_c2_s_t_z_nf_zc_dm(int start, int end, TILE* tex_tile)
1063                  #else
1064                  static void render_spans_16_c2_s_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
1065                  #endif
1066               #endif
1067            #endif
1068         #else
1069            #if defined(FLIP)
1070               #if defined(ZUPDATE)
1071                  #if defined(ZCOMPARE)
1072                  static void render_spans_16_c2_s_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1073                  #else
1074                  static void render_spans_16_c2_s_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1075                  #endif
1076               #else
1077                  #if defined(ZCOMPARE)
1078                  static void render_spans_16_c2_s_t_nz_f_zc_dm(int start, int end, TILE* tex_tile)
1079                  #else
1080                  static void render_spans_16_c2_s_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
1081                  #endif
1082               #endif
1083            #else
1084               #if defined(ZUPDATE)
1085                  #if defined(ZCOMPARE)
1086                  static void render_spans_16_c2_s_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1087                  #else
1088                  static void render_spans_16_c2_s_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1089                  #endif
1090               #else
1091                  #if defined(ZCOMPARE)
1092                  static void render_spans_16_c2_s_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
1093                  #else
1094                  static void render_spans_16_c2_s_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
1095                  #endif
1096               #endif
1097            #endif
1098         #endif
1099      #else
1100         #if defined(ZBUF)
1101            #if defined(FLIP)
1102               #if defined(ZUPDATE)
1103                  #if defined(ZCOMPARE)
1104                  static void render_spans_16_c2_s_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1105                  #else
1106                  static void render_spans_16_c2_s_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1107                  #endif
1108               #else
1109                  #if defined(ZCOMPARE)
1110                  static void render_spans_16_c2_s_nt_z_f_zc_dm(int start, int end, TILE* tex_tile)
1111                  #else
1112                  static void render_spans_16_c2_s_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile)
1113                  #endif
1114               #endif
1115            #else
1116               #if defined(ZUPDATE)
1117                  #if defined(ZCOMPARE)
1118                  static void render_spans_16_c2_s_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1119                  #else
1120                  static void render_spans_16_c2_s_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1121                  #endif
1122               #else
1123                  #if defined(ZCOMPARE)
1124                  static void render_spans_16_c2_s_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile)
1125                  #else
1126                  static void render_spans_16_c2_s_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
1127                  #endif
1128               #endif
1129            #endif
1130         #else
1131            #if defined(FLIP)
1132               #if defined(ZUPDATE)
1133                  #if defined(ZCOMPARE)
1134                  static void render_spans_16_c2_s_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1135                  #else
1136                  static void render_spans_16_c2_s_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1137                  #endif
1138               #else
1139                  #if defined(ZCOMPARE)
1140                  static void render_spans_16_c2_s_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile)
1141                  #else
1142                  static void render_spans_16_c2_s_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
1143                  #endif
1144               #endif
1145            #else
1146               #if defined(ZUPDATE)
1147                  #if defined(ZCOMPARE)
1148                  static void render_spans_16_c2_s_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1149                  #else
1150                  static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1151                  #endif
1152               #else
1153                  #if defined(ZCOMPARE)
1154                  static void render_spans_16_c2_s_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
1155                  #else
1156                  static void render_spans_16_c2_s_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
1157                  #endif
1158               #endif
1159            #endif
1160         #endif
1161      #endif
1162   #else
1163      #if defined(TEXTURE)
1164         #if defined(ZBUF)
1165            #if defined(FLIP)
1166               #if defined(ZUPDATE)
1167                  #if defined(ZCOMPARE)
1168                  static void render_spans_16_c2_ns_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1169                  #else
1170                  static void render_spans_16_c2_ns_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1171                  #endif
1172               #else
1173                  #if defined(ZCOMPARE)
1174                  static void render_spans_16_c2_ns_t_z_f_zc_dm(int start, int end, TILE* tex_tile)
1175                  #else
1176                  static void render_spans_16_c2_ns_t_z_f_nzc_dm(int start, int end, TILE* tex_tile)
1177                  #endif
1178               #endif
1179            #else
1180               #if defined(ZUPDATE)
1181                  #if defined(ZCOMPARE)
1182                  static void render_spans_16_c2_ns_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1183                  #else
1184                  static void render_spans_16_c2_ns_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1185                  #endif
1186               #else
1187                  #if defined(ZCOMPARE)
1188                  static void render_spans_16_c2_ns_t_z_nf_zc_dm(int start, int end, TILE* tex_tile)
1189                  #else
1190                  static void render_spans_16_c2_ns_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
1191                  #endif
1192               #endif
1193            #endif
1194         #else
1195            #if defined(FLIP)
1196               #if defined(ZUPDATE)
1197                  #if defined(ZCOMPARE)
1198                  static void render_spans_16_c2_ns_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1199                  #else
1200                  static void render_spans_16_c2_ns_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1201                  #endif
1202               #else
1203                  #if defined(ZCOMPARE)
1204                  static void render_spans_16_c2_ns_t_nz_f_zc_dm(int start, int end, TILE* tex_tile)
1205                  #else
1206                  static void render_spans_16_c2_ns_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
1207                  #endif
1208               #endif
1209            #else
1210               #if defined(ZUPDATE)
1211                  #if defined(ZCOMPARE)
1212                  static void render_spans_16_c2_ns_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1213                  #else
1214                  static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1215                  #endif
1216               #else
1217                  #if defined(ZCOMPARE)
1218                  static void render_spans_16_c2_ns_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
1219                  #else
1220                  static void render_spans_16_c2_ns_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
1221                  #endif
1222               #endif
1223            #endif
1224         #endif
1225      #else
1226         #if defined(ZBUF)
1227            #if defined(FLIP)
1228               #if defined(ZUPDATE)
1229                  #if defined(ZCOMPARE)
1230                  static void render_spans_16_c2_ns_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1231                  #else
1232                  static void render_spans_16_c2_ns_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1233                  #endif
1234               #else
1235                  #if defined(ZCOMPARE)
1236                  static void render_spans_16_c2_ns_nt_z_f_zc_dm(int start, int end, TILE* tex_tile)
1237                  #else
1238                  static void render_spans_16_c2_ns_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile)
1239                  #endif
1240               #endif
1241            #else
1242               #if defined(ZUPDATE)
1243                  #if defined(ZCOMPARE)
1244                  static void render_spans_16_c2_ns_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1245                  #else
1246                  static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1247                  #endif
1248               #else
1249                  #if defined(ZCOMPARE)
1250                  static void render_spans_16_c2_ns_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile)
1251                  #else
1252                  static void render_spans_16_c2_ns_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile)
1253                  #endif
1254               #endif
1255            #endif
1256         #else
1257            #if defined(FLIP)
1258               #if defined(ZUPDATE)
1259                  #if defined(ZCOMPARE)
1260                  static void render_spans_16_c2_ns_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile)
1261                  #else
1262                  static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile)
1263                  #endif
1264               #else
1265                  #if defined(ZCOMPARE)
1266                  static void render_spans_16_c2_ns_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile)
1267                  #else
1268                  static void render_spans_16_c2_ns_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile)
1269                  #endif
1270               #endif
1271            #else
1272               #if defined(ZUPDATE)
1273                  #if defined(ZCOMPARE)
1274                  static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile)
1275                  #else
1276                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile)
1277                  #endif
1278               #else
1279                  #if defined(ZCOMPARE)
1280                  static void render_spans_16_c2_ns_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile)
1281                  #else
1282                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile)
1283                  #endif
1284               #endif
1285            #endif
1286         #endif
1287      #endif
1288   #endif
1289#elif defined(BAYERDITHER)
1290   #if defined(SHADE)
1291      #if defined(TEXTURE)
1292         #if defined(ZBUF)
1293            #if defined(FLIP)
1294               #if defined(ZUPDATE)
1295                  #if defined(ZCOMPARE)
1296                  static void render_spans_16_c2_s_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
1297                  #else
1298                  static void render_spans_16_c2_s_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1299                  #endif
1300               #else
1301                  #if defined(ZCOMPARE)
1302                  static void render_spans_16_c2_s_t_z_f_zc_db(int start, int end, TILE* tex_tile)
1303                  #else
1304                  static void render_spans_16_c2_s_t_z_f_nzc_db(int start, int end, TILE* tex_tile)
1305                  #endif
1306               #endif
1307            #else
1308               #if defined(ZUPDATE)
1309                  #if defined(ZCOMPARE)
1310                  static void render_spans_16_c2_s_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1311                  #else
1312                  static void render_spans_16_c2_s_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1313                  #endif
1314               #else
1315                  #if defined(ZCOMPARE)
1316                  static void render_spans_16_c2_s_t_z_nf_zc_db(int start, int end, TILE* tex_tile)
1317                  #else
1318                  static void render_spans_16_c2_s_t_z_nf_nzc_db(int start, int end, TILE* tex_tile)
1319                  #endif
1320               #endif
1321            #endif
1322         #else
1323            #if defined(FLIP)
1324               #if defined(ZUPDATE)
1325                  #if defined(ZCOMPARE)
1326                  static void render_spans_16_c2_s_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
1327                  #else
1328                  static void render_spans_16_c2_s_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1329                  #endif
1330               #else
1331                  #if defined(ZCOMPARE)
1332                  static void render_spans_16_c2_s_t_nz_f_zc_db(int start, int end, TILE* tex_tile)
1333                  #else
1334                  static void render_spans_16_c2_s_t_nz_f_nzc_db(int start, int end, TILE* tex_tile)
1335                  #endif
1336               #endif
1337            #else
1338               #if defined(ZUPDATE)
1339                  #if defined(ZCOMPARE)
1340                  static void render_spans_16_c2_s_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1341                  #else
1342                  static void render_spans_16_c2_s_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1343                  #endif
1344               #else
1345                  #if defined(ZCOMPARE)
1346                  static void render_spans_16_c2_s_t_nz_nf_zc_db(int start, int end, TILE* tex_tile)
1347                  #else
1348                  static void render_spans_16_c2_s_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
1349                  #endif
1350               #endif
1351            #endif
1352         #endif
1353      #else
1354         #if defined(ZBUF)
1355            #if defined(FLIP)
1356               #if defined(ZUPDATE)
1357                  #if defined(ZCOMPARE)
1358                  static void render_spans_16_c2_s_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
1359                  #else
1360                  static void render_spans_16_c2_s_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1361                  #endif
1362               #else
1363                  #if defined(ZCOMPARE)
1364                  static void render_spans_16_c2_s_nt_z_f_zc_db(int start, int end, TILE* tex_tile)
1365                  #else
1366                  static void render_spans_16_c2_s_nt_z_f_nzc_db(int start, int end, TILE* tex_tile)
1367                  #endif
1368               #endif
1369            #else
1370               #if defined(ZUPDATE)
1371                  #if defined(ZCOMPARE)
1372                  static void render_spans_16_c2_s_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1373                  #else
1374                  static void render_spans_16_c2_s_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1375                  #endif
1376               #else
1377                  #if defined(ZCOMPARE)
1378                  static void render_spans_16_c2_s_nt_z_nf_zc_db(int start, int end, TILE* tex_tile)
1379                  #else
1380                  static void render_spans_16_c2_s_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile)
1381                  #endif
1382               #endif
1383            #endif
1384         #else
1385            #if defined(FLIP)
1386               #if defined(ZUPDATE)
1387                  #if defined(ZCOMPARE)
1388                  static void render_spans_16_c2_s_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
1389                  #else
1390                  static void render_spans_16_c2_s_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1391                  #endif
1392               #else
1393                  #if defined(ZCOMPARE)
1394                  static void render_spans_16_c2_s_nt_nz_f_zc_db(int start, int end, TILE* tex_tile)
1395                  #else
1396                  static void render_spans_16_c2_s_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile)
1397                  #endif
1398               #endif
1399            #else
1400               #if defined(ZUPDATE)
1401                  #if defined(ZCOMPARE)
1402                  static void render_spans_16_c2_s_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1403                  #else
1404                  static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1405                  #endif
1406               #else
1407                  #if defined(ZCOMPARE)
1408                  static void render_spans_16_c2_s_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile)
1409                  #else
1410                  static void render_spans_16_c2_s_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
1411                  #endif
1412               #endif
1413            #endif
1414         #endif
1415      #endif
1416   #else
1417      #if defined(TEXTURE)
1418         #if defined(ZBUF)
1419            #if defined(FLIP)
1420               #if defined(ZUPDATE)
1421                  #if defined(ZCOMPARE)
1422                  static void render_spans_16_c2_ns_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
1423                  #else
1424                  static void render_spans_16_c2_ns_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1425                  #endif
1426               #else
1427                  #if defined(ZCOMPARE)
1428                  static void render_spans_16_c2_ns_t_z_f_zc_db(int start, int end, TILE* tex_tile)
1429                  #else
1430                  static void render_spans_16_c2_ns_t_z_f_nzc_db(int start, int end, TILE* tex_tile)
1431                  #endif
1432               #endif
1433            #else
1434               #if defined(ZUPDATE)
1435                  #if defined(ZCOMPARE)
1436                  static void render_spans_16_c2_ns_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1437                  #else
1438                  static void render_spans_16_c2_ns_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1439                  #endif
1440               #else
1441                  #if defined(ZCOMPARE)
1442                  static void render_spans_16_c2_ns_t_z_nf_zc_db(int start, int end, TILE* tex_tile)
1443                  #else
1444                  static void render_spans_16_c2_ns_t_z_nf_nzc_db(int start, int end, TILE* tex_tile)
1445                  #endif
1446               #endif
1447            #endif
1448         #else
1449            #if defined(FLIP)
1450               #if defined(ZUPDATE)
1451                  #if defined(ZCOMPARE)
1452                  static void render_spans_16_c2_ns_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
1453                  #else
1454                  static void render_spans_16_c2_ns_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1455                  #endif
1456               #else
1457                  #if defined(ZCOMPARE)
1458                  static void render_spans_16_c2_ns_t_nz_f_zc_db(int start, int end, TILE* tex_tile)
1459                  #else
1460                  static void render_spans_16_c2_ns_t_nz_f_nzc_db(int start, int end, TILE* tex_tile)
1461                  #endif
1462               #endif
1463            #else
1464               #if defined(ZUPDATE)
1465                  #if defined(ZCOMPARE)
1466                  static void render_spans_16_c2_ns_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1467                  #else
1468                  static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1469                  #endif
1470               #else
1471                  #if defined(ZCOMPARE)
1472                  static void render_spans_16_c2_ns_t_nz_nf_zc_db(int start, int end, TILE* tex_tile)
1473                  #else
1474                  static void render_spans_16_c2_ns_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
1475                  #endif
1476               #endif
1477            #endif
1478         #endif
1479      #else
1480         #if defined(ZBUF)
1481            #if defined(FLIP)
1482               #if defined(ZUPDATE)
1483                  #if defined(ZCOMPARE)
1484                  static void render_spans_16_c2_ns_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile)
1485                  #else
1486                  static void render_spans_16_c2_ns_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1487                  #endif
1488               #else
1489                  #if defined(ZCOMPARE)
1490                  static void render_spans_16_c2_ns_nt_z_f_zc_db(int start, int end, TILE* tex_tile)
1491                  #else
1492                  static void render_spans_16_c2_ns_nt_z_f_nzc_db(int start, int end, TILE* tex_tile)
1493                  #endif
1494               #endif
1495            #else
1496               #if defined(ZUPDATE)
1497                  #if defined(ZCOMPARE)
1498                  static void render_spans_16_c2_ns_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1499                  #else
1500                  static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1501                  #endif
1502               #else
1503                  #if defined(ZCOMPARE)
1504                  static void render_spans_16_c2_ns_nt_z_nf_zc_db(int start, int end, TILE* tex_tile)
1505                  #else
1506                  static void render_spans_16_c2_ns_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile)
1507                  #endif
1508               #endif
1509            #endif
1510         #else
1511            #if defined(FLIP)
1512               #if defined(ZUPDATE)
1513                  #if defined(ZCOMPARE)
1514                  static void render_spans_16_c2_ns_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile)
1515                  #else
1516                  static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile)
1517                  #endif
1518               #else
1519                  #if defined(ZCOMPARE)
1520                  static void render_spans_16_c2_ns_nt_nz_f_zc_db(int start, int end, TILE* tex_tile)
1521                  #else
1522                  static void render_spans_16_c2_ns_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile)
1523                  #endif
1524               #endif
1525            #else
1526               #if defined(ZUPDATE)
1527                  #if defined(ZCOMPARE)
1528                  static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile)
1529                  #else
1530                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile)
1531                  #endif
1532               #else
1533                  #if defined(ZCOMPARE)
1534                  static void render_spans_16_c2_ns_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile)
1535                  #else
1536                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile)
1537                  #endif
1538               #endif
1539            #endif
1540         #endif
1541      #endif
1542   #endif
1543#else
1544   #if defined(SHADE)
1545      #if defined(TEXTURE)
1546         #if defined(ZBUF)
1547            #if defined(FLIP)
1548               #if defined(ZUPDATE)
1549                  #if defined(ZCOMPARE)
1550                  static void render_spans_16_c2_s_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1551                  #else
1552                  static void render_spans_16_c2_s_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1553                  #endif
1554               #else
1555                  #if defined(ZCOMPARE)
1556                  static void render_spans_16_c2_s_t_z_f_zc_dn(int start, int end, TILE* tex_tile)
1557                  #else
1558                  static void render_spans_16_c2_s_t_z_f_nzc_dn(int start, int end, TILE* tex_tile)
1559                  #endif
1560               #endif
1561            #else
1562               #if defined(ZUPDATE)
1563                  #if defined(ZCOMPARE)
1564                  static void render_spans_16_c2_s_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1565                  #else
1566                  static void render_spans_16_c2_s_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1567                  #endif
1568               #else
1569                  #if defined(ZCOMPARE)
1570                  static void render_spans_16_c2_s_t_z_nf_zc_dn(int start, int end, TILE* tex_tile)
1571                  #else
1572                  static void render_spans_16_c2_s_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
1573                  #endif
1574               #endif
1575            #endif
1576         #else
1577            #if defined(FLIP)
1578               #if defined(ZUPDATE)
1579                  #if defined(ZCOMPARE)
1580                  static void render_spans_16_c2_s_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1581                  #else
1582                  static void render_spans_16_c2_s_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1583                  #endif
1584               #else
1585                  #if defined(ZCOMPARE)
1586                  static void render_spans_16_c2_s_t_nz_f_zc_dn(int start, int end, TILE* tex_tile)
1587                  #else
1588                  static void render_spans_16_c2_s_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
1589                  #endif
1590               #endif
1591            #else
1592               #if defined(ZUPDATE)
1593                  #if defined(ZCOMPARE)
1594                  static void render_spans_16_c2_s_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1595                  #else
1596                  static void render_spans_16_c2_s_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1597                  #endif
1598               #else
1599                  #if defined(ZCOMPARE)
1600                  static void render_spans_16_c2_s_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
1601                  #else
1602                  static void render_spans_16_c2_s_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
1603                  #endif
1604               #endif
1605            #endif
1606         #endif
1607      #else
1608         #if defined(ZBUF)
1609            #if defined(FLIP)
1610               #if defined(ZUPDATE)
1611                  #if defined(ZCOMPARE)
1612                  static void render_spans_16_c2_s_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1613                  #else
1614                  static void render_spans_16_c2_s_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1615                  #endif
1616               #else
1617                  #if defined(ZCOMPARE)
1618                  static void render_spans_16_c2_s_nt_z_f_zc_dn(int start, int end, TILE* tex_tile)
1619                  #else
1620                  static void render_spans_16_c2_s_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile)
1621                  #endif
1622               #endif
1623            #else
1624               #if defined(ZUPDATE)
1625                  #if defined(ZCOMPARE)
1626                  static void render_spans_16_c2_s_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1627                  #else
1628                  static void render_spans_16_c2_s_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1629                  #endif
1630               #else
1631                  #if defined(ZCOMPARE)
1632                  static void render_spans_16_c2_s_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile)
1633                  #else
1634                  static void render_spans_16_c2_s_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
1635                  #endif
1636               #endif
1637            #endif
1638         #else
1639            #if defined(FLIP)
1640               #if defined(ZUPDATE)
1641                  #if defined(ZCOMPARE)
1642                  static void render_spans_16_c2_s_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1643                  #else
1644                  static void render_spans_16_c2_s_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1645                  #endif
1646               #else
1647                  #if defined(ZCOMPARE)
1648                  static void render_spans_16_c2_s_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile)
1649                  #else
1650                  static void render_spans_16_c2_s_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
1651                  #endif
1652               #endif
1653            #else
1654               #if defined(ZUPDATE)
1655                  #if defined(ZCOMPARE)
1656                  static void render_spans_16_c2_s_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1657                  #else
1658                  static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1659                  #endif
1660               #else
1661                  #if defined(ZCOMPARE)
1662                  static void render_spans_16_c2_s_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
1663                  #else
1664                  static void render_spans_16_c2_s_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
1665                  #endif
1666               #endif
1667            #endif
1668         #endif
1669      #endif
1670   #else
1671      #if defined(TEXTURE)
1672         #if defined(ZBUF)
1673            #if defined(FLIP)
1674               #if defined(ZUPDATE)
1675                  #if defined(ZCOMPARE)
1676                  static void render_spans_16_c2_ns_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1677                  #else
1678                  static void render_spans_16_c2_ns_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1679                  #endif
1680               #else
1681                  #if defined(ZCOMPARE)
1682                  static void render_spans_16_c2_ns_t_z_f_zc_dn(int start, int end, TILE* tex_tile)
1683                  #else
1684                  static void render_spans_16_c2_ns_t_z_f_nzc_dn(int start, int end, TILE* tex_tile)
1685                  #endif
1686               #endif
1687            #else
1688               #if defined(ZUPDATE)
1689                  #if defined(ZCOMPARE)
1690                  static void render_spans_16_c2_ns_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1691                  #else
1692                  static void render_spans_16_c2_ns_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1693                  #endif
1694               #else
1695                  #if defined(ZCOMPARE)
1696                  static void render_spans_16_c2_ns_t_z_nf_zc_dn(int start, int end, TILE* tex_tile)
1697                  #else
1698                  static void render_spans_16_c2_ns_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
1699                  #endif
1700               #endif
1701            #endif
1702         #else
1703            #if defined(FLIP)
1704               #if defined(ZUPDATE)
1705                  #if defined(ZCOMPARE)
1706                  static void render_spans_16_c2_ns_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1707                  #else
1708                  static void render_spans_16_c2_ns_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1709                  #endif
1710               #else
1711                  #if defined(ZCOMPARE)
1712                  static void render_spans_16_c2_ns_t_nz_f_zc_dn(int start, int end, TILE* tex_tile)
1713                  #else
1714                  static void render_spans_16_c2_ns_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
1715                  #endif
1716               #endif
1717            #else
1718               #if defined(ZUPDATE)
1719                  #if defined(ZCOMPARE)
1720                  static void render_spans_16_c2_ns_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1721                  #else
1722                  static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1723                  #endif
1724               #else
1725                  #if defined(ZCOMPARE)
1726                  static void render_spans_16_c2_ns_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
1727                  #else
1728                  static void render_spans_16_c2_ns_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
1729                  #endif
1730               #endif
1731            #endif
1732         #endif
1733      #else
1734         #if defined(ZBUF)
1735            #if defined(FLIP)
1736               #if defined(ZUPDATE)
1737                  #if defined(ZCOMPARE)
1738                  static void render_spans_16_c2_ns_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1739                  #else
1740                  static void render_spans_16_c2_ns_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1741                  #endif
1742               #else
1743                  #if defined(ZCOMPARE)
1744                  static void render_spans_16_c2_ns_nt_z_f_zc_dn(int start, int end, TILE* tex_tile)
1745                  #else
1746                  static void render_spans_16_c2_ns_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile)
1747                  #endif
1748               #endif
1749            #else
1750               #if defined(ZUPDATE)
1751                  #if defined(ZCOMPARE)
1752                  static void render_spans_16_c2_ns_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1753                  #else
1754                  static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1755                  #endif
1756               #else
1757                  #if defined(ZCOMPARE)
1758                  static void render_spans_16_c2_ns_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile)
1759                  #else
1760                  static void render_spans_16_c2_ns_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile)
1761                  #endif
1762               #endif
1763            #endif
1764         #else
1765            #if defined(FLIP)
1766               #if defined(ZUPDATE)
1767                  #if defined(ZCOMPARE)
1768                  static void render_spans_16_c2_ns_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile)
1769                  #else
1770                  static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile)
1771                  #endif
1772               #else
1773                  #if defined(ZCOMPARE)
1774                  static void render_spans_16_c2_ns_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile)
1775                  #else
1776                  static void render_spans_16_c2_ns_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile)
1777                  #endif
1778               #endif
1779            #else
1780               #if defined(ZUPDATE)
1781                  #if defined(ZCOMPARE)
1782                  static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile)
1783                  #else
1784                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile)
1785                  #endif
1786               #else
1787                  #if defined(ZCOMPARE)
1788                  static void render_spans_16_c2_ns_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile)
1789                  #else
1790                  static void render_spans_16_c2_ns_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile)
1791                  #endif
1792               #endif
1793            #endif
1794         #endif
1795      #endif
1796   #endif
1797#endif
1798{
1799   UINT16 *fb = (UINT16*)&rdram[fb_address / 4];
1800   UINT8 *hb = &hidden_bits[fb_address >> 1];
1801#if defined(ZUPDATE) || defined(ZCOMPARE)
1802   UINT16 *zb = (UINT16*)&rdram[zb_address / 4];
1803   UINT8 *zhb = &hidden_bits[zb_address >> 1];
1804#endif
1805
1806#if defined(SHADE)
1807   SPAN_PARAM dr = span[0].dr;
1808   SPAN_PARAM dg = span[0].dg;
1809   SPAN_PARAM db = span[0].db;
1810   SPAN_PARAM da = span[0].da;
1811#if defined(FLIP)
1812   int drinc = dr.w;
1813   int dginc = dg.w;
1814   int dbinc = db.w;
1815   int dainc = da.w;
1816#else
1817   int drinc = -dr.w;
1818   int dginc = -dg.w;
1819   int dbinc = -db.w;
1820   int dainc = -da.w;
1821#endif
1822#endif
1823
1824#if defined(TEXTURE)
1825   UINT32 prim_tile = tex_tile->num;
1826   UINT32 tilenum2 = 0;
1827   TILE *tex_tile2 = NULL;
1828   int tilenum;
1829
1830   int nexts;// = 0;
1831   int nextt;// = 0;
1832   int nextsw;// = 0;
1833
1834   SPAN_PARAM ds = span[0].ds;
1835   SPAN_PARAM dt = span[0].dt;
1836   SPAN_PARAM dw = span[0].dw;
1837#if defined(FLIP)
1838   int dsinc = ds.w;
1839   int dtinc = dt.w;
1840   int dwinc = dw.w;
1841#else
1842   int dsinc = -ds.w;
1843   int dtinc = -dt.w;
1844   int dwinc = -dw.w;
1845#endif
1846#endif
1847
1848#if defined(ZBUF)
1849   SPAN_PARAM dz = span[0].dz;
1850   int dzpix = span[0].dzpix;
1851#if defined(FLIP)
1852   int dzinc = dz.w;
1853#else
1854   int dzinc = -dz.w;
1855#endif
1856#else
1857   int sz = 0, dzpix = 0;
1858
1859   if (other_modes.z_source_sel)
135   if (m_other_modes->cycle_type == CYCLE_TYPE_2 && texture && !m_other_modes->tex_lod_en)
1860136   {
1861      sz = (((UINT32)primitive_z) << 3) & 0x3ffff;
1862      dzpix = primitive_delta_z;
137      tilenum2 = (prim_tile + 1) & 7;
1863138   }
1864#endif
1865139
1866#if defined(TEXTURE)
1867   calculate_clamp_diffs(tex_tile->num);
1868
1869   if (!other_modes.tex_lod_en)
140   if (texture && !m_other_modes->tex_lod_en)
1870141   {
1871142      tilenum = prim_tile;
1872      tex_tile = &tile[tilenum];
1873      tilenum2 = (prim_tile + 1) & 7;
1874      tex_tile2 = &tile[tilenum2];
1875143   }
1876#endif
1877144
1878   if (start < clip.yh)
145   if(!shade)
1879146   {
1880      start = clip.yh;
147      m_rdp->GetShadeColor()->c = m_rdp->GetPrimColor()->c;
1881148   }
1882   if (start >= clip.yl)
1883   {
1884      start = clip.yl - 1;
1885   }
1886   if (end < clip.yh)
1887   {
1888      end = clip.yh;
1889   }
1890   if (end >= clip.yl) // Needed by 40 Winks
1891   {
1892      end = clip.yl - 1;
1893   }
1894149
1895#if !defined(SHADE)
1896   shade_color.c = prim_color.c;
1897#endif
1898
1899   for (int i = start; i <= end; i++)
150   for (int j = 0; j <= length; j++)
1900151   {
1901#if defined(SHADE)
1902      SPAN_PARAM r = span[i].r;
1903      SPAN_PARAM g = span[i].g;
1904      SPAN_PARAM b = span[i].b;
1905      SPAN_PARAM a = span[i].a;
1906#endif
1907#if defined(TEXTURE)
1908      SPAN_PARAM s = span[i].s;
1909      SPAN_PARAM t = span[i].t;
1910      SPAN_PARAM w = span[i].w;
1911#endif
1912#if defined(ZBUF)
1913      SPAN_PARAM z = span[i].z;
1914#endif
152      int sr = 0;
153      int sg = 0;
154      int sb = 0;
155      int sa = 0;
156      int ss = s.h.h;
157      int st = t.h.h;
158      int sw = w.h.h;
159      int sz = z.w >> 13;
160      int sss = 0;
161      int sst = 0;
162      Color c1;
163      Color c2;
1915164
1916      int fb_index = fb_width * i;
1917      int x = span[i].rx;
165      if(shade)
166      {
167         sr = r.h.h;
168         sg = g.h.h;
169         sb = b.h.h;
170         sa = a.h.h;
171      }
1918172
1919#if defined(FLIP)
1920      int length = (span[i].lx - span[i].rx);
1921#else
1922      int length = (span[i].rx - span[i].lx);
1923#endif
173      if (m_other_modes->z_source_sel)
174      {
175         sz = (((UINT32)m_misc_state->m_primitive_z) << 3) & 0x3ffff;
176         dzpix = m_misc_state->m_primitive_delta_z;
177      }
1924178
1925      for (int j = 0; j <= length; j++)
179      if (x >= clipx1 && x < clipx2)
1926180      {
1927#if defined(SHADE)
1928         int sr = r.h.h;
1929         int sg = g.h.h;
1930         int sb = b.h.h;
1931         int sa = a.h.h;
1932#endif
1933#if defined(TEXTURE)
1934         int ss = s.h.h;
1935         int st = t.h.h;
1936         int sw = w.h.h;
1937         int sss = 0, sst = 0;
1938#endif
1939#if defined(ZBUF)
1940         int sz = z.w >> 13;
1941#endif
1942         COLOR c1, c2;
1943         //c1.c = 0;
1944         //c2.c = 0;
181         bool z_compare_result = true;
1945182
1946#if defined(ZBUF)
1947         if (other_modes.z_source_sel)
1948         {
1949            sz = (((UINT32)primitive_z) << 3) & 0x3ffff;
1950            dzpix = primitive_delta_z;
1951         }
1952#endif
183         m_misc_state->m_curpixel_cvg = m_cvg[x];
1953184
1954         if (x >= clip.xh && x < clip.xl)
185         if (m_misc_state->m_curpixel_cvg)
1955186         {
1956#if defined(ZCOMPARE)
1957            int z_compare_result = 1;
1958#endif
187            int curpixel = fb_index + x;
188            UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
189            UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
190            UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
191            UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
1959192
1960            curpixel_cvg=span[i].cvg[x];
1961
1962            if (curpixel_cvg)
193            if (m_other_modes->persp_tex_en)
1963194            {
1964               int curpixel = fb_index + x;
1965               UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
1966               UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
1967#if defined(ZUPDATE) || defined(ZCOMPARE)
1968               UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
1969               UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
1970#endif
195               m_rdp->TCDiv(ss, st, sw, &sss, &sst);
196            }
197            else // Hack for Bust-a-Move 2
198            {
199               sss = ss;
200               sst = st;
201            }
1971202
1972#if defined(SHADE)
1973               if (sr > 0xff) sr = 0xff;
1974               if (sg > 0xff) sg = 0xff;
1975               if (sb > 0xff) sb = 0xff;
1976               if (sa > 0xff) sa = 0xff;
1977               if (sr < 0) sr = 0;
1978               if (sg < 0) sg = 0;
1979               if (sb < 0) sb = 0;
1980               if (sa < 0) sa = 0;
1981               shade_color.i.r = sr;
1982               shade_color.i.g = sg;
1983               shade_color.i.b = sb;
1984               shade_color.i.a = sa;
1985#endif
1986
1987#if defined(TEXTURE)
1988               if (other_modes.persp_tex_en)
203            if (m_other_modes->tex_lod_en && !disable_lod)
204            {
205               if (m_other_modes->persp_tex_en)
1989206               {
1990                  tcdiv(ss, st, sw, &sss, &sst);
207                  nextsw = (w.w + dwinc) >> 16;
208                  nexts = (s.w + dsinc) >> 16;
209                  nextt = (t.w + dtinc) >> 16;
210                  m_rdp->TCDiv(nexts, nextt, nextsw, &nexts, &nextt);
1991211               }
1992               else // Hack for Bust-a-Move 2
212               else
1993213               {
1994                  sss = ss;
1995                  sst = st;
214                  nexts = (s.w + dsinc)>>16;
215                  nextt = (t.w + dtinc)>>16;
1996216               }
1997217
1998               if (other_modes.tex_lod_en)
218               INT32 horstep = SIGN17(nexts & 0x1ffff) - SIGN17(sss & 0x1ffff);
219               INT32 vertstep = SIGN17(nextt & 0x1ffff) - SIGN17(sst & 0x1ffff);
220               if (horstep & 0x20000)
1999221               {
2000                  if (other_modes.persp_tex_en)
2001                  {
2002                     nextsw = (w.w + dwinc) >> 16;
2003                     nexts = (s.w + dsinc) >> 16;
2004                     nextt = (t.w + dtinc) >> 16;
2005                     tcdiv(nexts, nextt, nextsw, &nexts, &nextt);
2006                  }
2007                  else
2008                  {
2009                     nexts = (s.w + dsinc)>>16;
2010                     nextt = (t.w + dtinc)>>16;
2011                  }
222                  horstep = ~horstep & 0x1ffff;
223               }
224               if (vertstep & 0x20000)
225               {
226                  vertstep = ~vertstep & 0x1ffff;
227               }
2012228
2013                  int lodclamp = 0;
229               int LOD = (horstep >= vertstep) ? horstep : vertstep;
230               LOD = (LOD >= m_dymax) ? LOD : m_dymax;
2014231
2015                  INT32 horstep = SIGN17(nexts & 0x1ffff) - SIGN17(sss & 0x1ffff);
2016                  INT32 vertstep = SIGN17(nextt & 0x1ffff) - SIGN17(sst & 0x1ffff);
2017                  if (horstep & 0x20000)
2018                  {
2019                     horstep = ~horstep & 0x1ffff;
2020                  }
2021                  if (vertstep & 0x20000)
2022                  {
2023                     vertstep = ~vertstep & 0x1ffff;
2024                  }
2025                  int LOD = ((horstep >= vertstep) ? horstep : vertstep);
2026                  LOD = (LOD >= span[0].dymax) ? LOD : span[0].dymax;
232               if (LOD & 0x1c000)
233               {
234                  LOD = 0x7fff;
235               }
236               if (LOD < m_misc_state->m_min_level)
237               {
238                  LOD = m_misc_state->m_min_level;
239               }
2027240
2028                  if ((LOD & 0x1c000) || lodclamp)
2029                  {
2030                     LOD = 0x7fff;
2031                  }
2032                  if (LOD < min_level)
2033                  {
2034                     LOD = min_level;
2035                  }
241               bool magnify = (LOD < 32);
242               INT32 l_tile = m_rdp->GetLog2((LOD >> 5) & 0xff);
243               bool distant = ((LOD & 0x6000) || (l_tile >= m_misc_state->m_max_level));
2036244
2037                  bool magnify = (LOD < 32);
2038                  INT32 l_tile = getlog2((LOD >> 5) & 0xff);
2039                  bool distant = ((LOD & 0x6000) || (l_tile >= max_level));
245               m_rdp->SetLODFrac(((LOD << 3) >> l_tile) & 0xff);
2040246
2041                  lod_frac = ((LOD << 3) >> l_tile) & 0xff;
247               if (distant)
248               {
249                  l_tile = m_misc_state->m_max_level;
250               }
251               if(!m_other_modes->sharpen_tex_en && !m_other_modes->detail_tex_en && magnify)
252               {
253                  m_rdp->SetLODFrac(0);
254               }
255               if(!m_other_modes->sharpen_tex_en && !m_other_modes->detail_tex_en && distant)
256               {
257                  m_rdp->SetLODFrac(0xff);
258               }
259               if(m_other_modes->sharpen_tex_en && magnify)
260               {
261                  m_rdp->SetLODFrac(*(m_rdp->GetLODFrac()) | 0x100);
262               }
2042263
2043                  if (distant)
264               if (!m_other_modes->detail_tex_en)
265               {
266                  tilenum = (prim_tile + l_tile);
267                  tilenum &= 7;
268                  if (m_other_modes->sharpen_tex_en)
2044269                  {
2045                     l_tile = max_level;
270                     tilenum2 = (tilenum + 1) & 7;
2046271                  }
2047                  if(!other_modes.sharpen_tex_en && !other_modes.detail_tex_en && magnify)
272                  else if (!distant)
2048273                  {
2049                     lod_frac = 0;
274                     tilenum2 = (tilenum + 1) & 7;
2050275                  }
2051                  if(!other_modes.sharpen_tex_en && !other_modes.detail_tex_en && distant)
276                  else
2052277                  {
2053                     lod_frac = 0xff;
278                     tilenum2 = tilenum;
2054279                  }
2055                  if(other_modes.sharpen_tex_en && magnify)
280               }
281               else
282               {
283                  if (!magnify)
2056284                  {
2057                     lod_frac |= 0x100;
285                     tilenum = (prim_tile + l_tile + 1);
2058286                  }
2059
2060                  if (!other_modes.detail_tex_en)
287                  else
2061288                  {
2062289                     tilenum = (prim_tile + l_tile);
2063                     tilenum &= 7;
2064                     if (other_modes.sharpen_tex_en)
2065                     {
2066                        tilenum2 = (tilenum + 1) & 7;
2067                     }
2068                     else if (!distant)
2069                     {
2070                        tilenum2 = (tilenum + 1) & 7;
2071                     }
2072                     else
2073                     {
2074                        tilenum2 = tilenum;
2075                     }
2076                     tex_tile = &tile[tilenum];
2077                     tex_tile2 = &tile[tilenum2];
2078290                  }
291                  tilenum &= 7;
292
293                  if (!distant && !magnify)
294                  {
295                     tilenum2 = (prim_tile + l_tile + 2) & 7;
296                  }
2079297                  else
2080298                  {
2081                     if (!magnify)
2082                     {
2083                        tilenum = (prim_tile + l_tile + 1);
2084                     }
2085                     else
2086                     {
2087                        tilenum = (prim_tile + l_tile);
2088                     }
2089                     tilenum &= 7;
2090
2091                     if (!distant && !magnify)
2092                     {
2093                        tilenum2 = (prim_tile + l_tile + 2) & 7;
2094                     }
2095                     else
2096                     {
2097                        tilenum2 = (prim_tile + l_tile + 1) & 7;
2098                     }
2099                     tex_tile = &tile[tilenum];
2100                     tex_tile2 = &tile[tilenum2];
299                     tilenum2 = (prim_tile + l_tile + 1) & 7;
2101300                  }
2102301               }
302            }
2103303
2104               CACHE_TEXTURE_PARAMS(tex_tile);
2105               texel0_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile);
304            if (shade)
305            {
306               if (sr > 0xff) sr = 0xff;
307               if (sg > 0xff) sg = 0xff;
308               if (sb > 0xff) sb = 0xff;
309               if (sa > 0xff) sa = 0xff;
310               if (sr < 0) sr = 0;
311               if (sg < 0) sg = 0;
312               if (sb < 0) sb = 0;
313               if (sa < 0) sa = 0;
314               m_rdp->GetShadeColor()->i.r = sr;
315               m_rdp->GetShadeColor()->i.g = sg;
316               m_rdp->GetShadeColor()->i.b = sb;
317               m_rdp->GetShadeColor()->i.a = sa;
318            }
2106319
2107               CACHE_TEXTURE_PARAMS(tex_tile2);
2108               texel1_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile2);
2109#endif
320            if (texture)
321            {
322               if (m_other_modes->cycle_type == CYCLE_TYPE_1)
323               {
324                  m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(sss, sst, &m_rdp->GetTiles()[tilenum]);
325               }
326               else
327               {
328                  m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(sss, sst, &m_rdp->GetTiles()[tilenum]);
329                  m_rdp->GetTexel1Color()->c = m_rdp->GetTexPipe()->Fetch(sss, sst, &m_rdp->GetTiles()[tilenum2]);
330               }
331            }
2110332
2111               COLOR_COMBINER2_C0(c1);
2112               COLOR_COMBINER2_C1(c2);
333            if (m_other_modes->cycle_type == CYCLE_TYPE_1)
334            {
335               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
336                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
337                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
338                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
339               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
340                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
341                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
342                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
343               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
344                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
345                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
346                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
347               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
348                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
349                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
350                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
351               m_rdp->GetAlphaCvg(&c1.i.a);
352            }
353            else if (m_other_modes->cycle_type == CYCLE_TYPE_2)
354            {
355               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
356                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
357                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
358                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
359               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
360                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
361                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
362                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
363               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
364                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
365                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
366                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
367               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
368                             *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
369                             *m_rdp->GetColorInputs()->combiner_alphamul[0],
370                             *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
371               m_rdp->GetCombinedColor()->c = c1.c;
372               c2.c = m_rdp->GetTexel0Color()->c;
373               m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
374               m_rdp->GetTexel1Color()->c = c2.c;
375               c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
376                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
377                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
378                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
379               c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
380                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
381                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
382                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
383               c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
384                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
385                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
386                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
387               c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
388                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
389                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
390                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
391               m_rdp->GetAlphaCvg(&c2.i.a);
392            }
2113393
2114#if defined(ZCOMPARE)
2115#if !defined(ZBUF)
2116               if (other_modes.z_source_sel)
2117#endif
394            if ((zbuffer || m_other_modes->z_source_sel) && m_other_modes->z_compare_en)
395            {
396               z_compare_result = m_rdp->ZCompare(fbcur, hbcur, zbcur, zhbcur, sz, dzpix);
397            }
398
399            if(z_compare_result)
400            {
401               bool rendered = true;
402               int dith = 0;
403               if (!m_other_modes->rgb_dither_sel)
2118404               {
2119                  z_compare_result = z_compare(fbcur, hbcur, zbcur, zhbcur, sz, dzpix);
405                  dith = m_rdp->GetMagicMatrix()[(((index) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
2120406               }
2121
2122               if(z_compare_result)
2123#endif
407               else if (m_other_modes->rgb_dither_sel == 1)
2124408               {
2125#if defined(ZUPDATE)
2126                  int rendered = 0;
2127#endif
2128#if defined(MAGICDITHER)
2129                  int dith = magic_matrix[(((i) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
2130#elif defined(BAYERDITHER)
2131                  int dith = bayer_matrix[(((i) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
2132#endif
409                  dith = m_rdp->GetBayerMatrix()[(((index) & 3) << 2) + ((x ^ WORD_ADDR_XOR) & 3)];
410               }
2133411
2134#if defined(ZUPDATE)
2135#if defined(MAGICDITHER) || defined(BAYERDITHER)
2136                  rendered = BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
2137#else
2138                  rendered = BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
2139#endif
412               rendered = m_rdp->GetBlender()->Blend(fbcur, hbcur, c1, c2, dith);
2140413
2141                  if (rendered)
2142                  {
2143                     z_store(zbcur, zhbcur, sz, dzpix);
2144                  }
2145#else
2146#if defined(MAGICDITHER) || defined(BAYERDITHER)
2147                  BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
2148#else
2149                  BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
2150#endif
2151
2152#endif
414               if (m_other_modes->z_update_en && rendered)
415               {
416                  m_rdp->ZStore(zbcur, zhbcur, sz, dzpix);
2153417               }
2154418            }
2155419         }
420      }
2156421
2157#if defined(SHADE)
422      if (shade)
423      {
2158424         r.w += drinc;
2159425         g.w += dginc;
2160426         b.w += dbinc;
2161427         a.w += dainc;
2162#endif
2163#if defined(TEXTURE)
2164         s.w += dsinc;
2165         t.w += dtinc;
2166         w.w += dwinc;
2167#endif
2168#if defined(ZBUF)
2169         z.w += dzinc;
2170#endif
2171
2172#if defined(FLIP)
2173         x++;
2174#else
2175         x--;
2176#endif
2177428      }
429      z.w += dzinc;
430      s.w += dsinc;
431      t.w += dtinc;
432      w.w += dwinc;
433
434      x += xinc;
2178435   }
2179436}
437
438}
439
440}
No newline at end of file
src/mame/video/rdpspn16.h
r7675r7676
1static void render_spans_16_c1_ns_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
2static void render_spans_16_c2_ns_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
3static void render_spans_16_c1_ns_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
4static void render_spans_16_c2_ns_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
5static void render_spans_16_c1_ns_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
6static void render_spans_16_c2_ns_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
7static void render_spans_16_c1_ns_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
8static void render_spans_16_c2_ns_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
9static void render_spans_16_c1_s_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
10static void render_spans_16_c2_s_nt_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
11static void render_spans_16_c1_s_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
12static void render_spans_16_c2_s_nt_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
13static void render_spans_16_c1_s_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
14static void render_spans_16_c2_s_t_nz_nf_nzc_dm(int start, int end, TILE* tex_tile);
15static void render_spans_16_c1_s_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
16static void render_spans_16_c2_s_t_z_nf_nzc_dm(int start, int end, TILE* tex_tile);
17static void render_spans_16_c1_ns_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
18static void render_spans_16_c2_ns_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
19static void render_spans_16_c1_ns_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile);
20static void render_spans_16_c2_ns_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile);
21static void render_spans_16_c1_ns_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
22static void render_spans_16_c2_ns_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
23static void render_spans_16_c1_ns_t_z_f_nzc_dm(int start, int end, TILE* tex_tile);
24static void render_spans_16_c2_ns_t_z_f_nzc_dm(int start, int end, TILE* tex_tile);
25static void render_spans_16_c1_s_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
26static void render_spans_16_c2_s_nt_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
27static void render_spans_16_c1_s_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile);
28static void render_spans_16_c2_s_nt_z_f_nzc_dm(int start, int end, TILE* tex_tile);
29static void render_spans_16_c1_s_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
30static void render_spans_16_c2_s_t_nz_f_nzc_dm(int start, int end, TILE* tex_tile);
31static void render_spans_16_c1_s_t_z_f_nzc_dm(int start, int end, TILE* tex_tile);
32static void render_spans_16_c2_s_t_z_f_nzc_dm(int start, int end, TILE* tex_tile);
1#ifndef _VIDEO_RDPSPAN_H_
2#define _VIDEO_RDPSPAN_H_
333
34static void render_spans_16_c1_ns_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
35static void render_spans_16_c2_ns_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
36static void render_spans_16_c1_ns_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile);
37static void render_spans_16_c2_ns_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile);
38static void render_spans_16_c1_ns_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
39static void render_spans_16_c2_ns_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
40static void render_spans_16_c1_ns_t_z_nf_zc_dm(int start, int end, TILE* tex_tile);
41static void render_spans_16_c2_ns_t_z_nf_zc_dm(int start, int end, TILE* tex_tile);
42static void render_spans_16_c1_s_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
43static void render_spans_16_c2_s_nt_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
44static void render_spans_16_c1_s_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile);
45static void render_spans_16_c2_s_nt_z_nf_zc_dm(int start, int end, TILE* tex_tile);
46static void render_spans_16_c1_s_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
47static void render_spans_16_c2_s_t_nz_nf_zc_dm(int start, int end, TILE* tex_tile);
48static void render_spans_16_c1_s_t_z_nf_zc_dm(int start, int end, TILE* tex_tile);
49static void render_spans_16_c2_s_t_z_nf_zc_dm(int start, int end, TILE* tex_tile);
50static void render_spans_16_c1_ns_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile);
51static void render_spans_16_c2_ns_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile);
52static void render_spans_16_c1_ns_nt_z_f_zc_dm(int start, int end, TILE* tex_tile);
53static void render_spans_16_c2_ns_nt_z_f_zc_dm(int start, int end, TILE* tex_tile);
54static void render_spans_16_c1_ns_t_nz_f_zc_dm(int start, int end, TILE* tex_tile);
55static void render_spans_16_c2_ns_t_nz_f_zc_dm(int start, int end, TILE* tex_tile);
56static void render_spans_16_c1_ns_t_z_f_zc_dm(int start, int end, TILE* tex_tile);
57static void render_spans_16_c2_ns_t_z_f_zc_dm(int start, int end, TILE* tex_tile);
58static void render_spans_16_c1_s_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile);
59static void render_spans_16_c2_s_nt_nz_f_zc_dm(int start, int end, TILE* tex_tile);
60static void render_spans_16_c1_s_nt_z_f_zc_dm(int start, int end, TILE* tex_tile);
61static void render_spans_16_c2_s_nt_z_f_zc_dm(int start, int end, TILE* tex_tile);
62static void render_spans_16_c1_s_t_nz_f_zc_dm(int start, int end, TILE* tex_tile);
63static void render_spans_16_c2_s_t_nz_f_zc_dm(int start, int end, TILE* tex_tile);
64static void render_spans_16_c1_s_t_z_f_zc_dm(int start, int end, TILE* tex_tile);
65static void render_spans_16_c2_s_t_z_f_zc_dm(int start, int end, TILE* tex_tile);
4#include "emu.h"
665
67static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
68static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
69static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
70static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
71static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
72static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
73static void render_spans_16_c1_ns_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
74static void render_spans_16_c2_ns_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
75static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
76static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
77static void render_spans_16_c1_s_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
78static void render_spans_16_c2_s_nt_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
79static void render_spans_16_c1_s_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
80static void render_spans_16_c2_s_t_nz_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
81static void render_spans_16_c1_s_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
82static void render_spans_16_c2_s_t_z_nf_nzc_zu_dm(int start, int end, TILE* tex_tile);
83static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
84static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
85static void render_spans_16_c1_ns_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
86static void render_spans_16_c2_ns_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
87static void render_spans_16_c1_ns_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
88static void render_spans_16_c2_ns_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
89static void render_spans_16_c1_ns_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
90static void render_spans_16_c2_ns_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
91static void render_spans_16_c1_s_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
92static void render_spans_16_c2_s_nt_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
93static void render_spans_16_c1_s_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
94static void render_spans_16_c2_s_nt_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
95static void render_spans_16_c1_s_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
96static void render_spans_16_c2_s_t_nz_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
97static void render_spans_16_c1_s_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
98static void render_spans_16_c2_s_t_z_f_nzc_zu_dm(int start, int end, TILE* tex_tile);
6namespace N64
7{
998
100static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
101static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
102static void render_spans_16_c1_ns_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
103static void render_spans_16_c2_ns_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
104static void render_spans_16_c1_ns_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
105static void render_spans_16_c2_ns_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
106static void render_spans_16_c1_ns_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
107static void render_spans_16_c2_ns_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
108static void render_spans_16_c1_s_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
109static void render_spans_16_c2_s_nt_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
110static void render_spans_16_c1_s_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
111static void render_spans_16_c2_s_nt_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
112static void render_spans_16_c1_s_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
113static void render_spans_16_c2_s_t_nz_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
114static void render_spans_16_c1_s_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
115static void render_spans_16_c2_s_t_z_nf_zc_zu_dm(int start, int end, TILE* tex_tile);
116static void render_spans_16_c1_ns_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
117static void render_spans_16_c2_ns_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
118static void render_spans_16_c1_ns_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
119static void render_spans_16_c2_ns_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
120static void render_spans_16_c1_ns_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
121static void render_spans_16_c2_ns_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
122static void render_spans_16_c1_ns_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
123static void render_spans_16_c2_ns_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
124static void render_spans_16_c1_s_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
125static void render_spans_16_c2_s_nt_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
126static void render_spans_16_c1_s_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
127static void render_spans_16_c2_s_nt_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
128static void render_spans_16_c1_s_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
129static void render_spans_16_c2_s_t_nz_f_zc_zu_dm(int start, int end, TILE* tex_tile);
130static void render_spans_16_c1_s_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
131static void render_spans_16_c2_s_t_z_f_zc_zu_dm(int start, int end, TILE* tex_tile);
9namespace RDP
10{
13211
133static void render_spans_16_c1_ns_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
134static void render_spans_16_c2_ns_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
135static void render_spans_16_c1_ns_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile);
136static void render_spans_16_c2_ns_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile);
137static void render_spans_16_c1_ns_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
138static void render_spans_16_c2_ns_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
139static void render_spans_16_c1_ns_t_z_nf_nzc_db(int start, int end, TILE* tex_tile);
140static void render_spans_16_c2_ns_t_z_nf_nzc_db(int start, int end, TILE* tex_tile);
141static void render_spans_16_c1_s_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
142static void render_spans_16_c2_s_nt_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
143static void render_spans_16_c1_s_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile);
144static void render_spans_16_c2_s_nt_z_nf_nzc_db(int start, int end, TILE* tex_tile);
145static void render_spans_16_c1_s_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
146static void render_spans_16_c2_s_t_nz_nf_nzc_db(int start, int end, TILE* tex_tile);
147static void render_spans_16_c1_s_t_z_nf_nzc_db(int start, int end, TILE* tex_tile);
148static void render_spans_16_c2_s_t_z_nf_nzc_db(int start, int end, TILE* tex_tile);
149static void render_spans_16_c1_ns_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile);
150static void render_spans_16_c2_ns_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile);
151static void render_spans_16_c1_ns_nt_z_f_nzc_db(int start, int end, TILE* tex_tile);
152static void render_spans_16_c2_ns_nt_z_f_nzc_db(int start, int end, TILE* tex_tile);
153static void render_spans_16_c1_ns_t_nz_f_nzc_db(int start, int end, TILE* tex_tile);
154static void render_spans_16_c2_ns_t_nz_f_nzc_db(int start, int end, TILE* tex_tile);
155static void render_spans_16_c1_ns_t_z_f_nzc_db(int start, int end, TILE* tex_tile);
156static void render_spans_16_c2_ns_t_z_f_nzc_db(int start, int end, TILE* tex_tile);
157static void render_spans_16_c1_s_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile);
158static void render_spans_16_c2_s_nt_nz_f_nzc_db(int start, int end, TILE* tex_tile);
159static void render_spans_16_c1_s_nt_z_f_nzc_db(int start, int end, TILE* tex_tile);
160static void render_spans_16_c2_s_nt_z_f_nzc_db(int start, int end, TILE* tex_tile);
161static void render_spans_16_c1_s_t_nz_f_nzc_db(int start, int end, TILE* tex_tile);
162static void render_spans_16_c2_s_t_nz_f_nzc_db(int start, int end, TILE* tex_tile);
163static void render_spans_16_c1_s_t_z_f_nzc_db(int start, int end, TILE* tex_tile);
164static void render_spans_16_c2_s_t_z_f_nzc_db(int start, int end, TILE* tex_tile);
12#define RDP_CVG_SPAN_MAX    1024
16513
166static void render_spans_16_c1_ns_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile);
167static void render_spans_16_c2_ns_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile);
168static void render_spans_16_c1_ns_nt_z_nf_zc_db(int start, int end, TILE* tex_tile);
169static void render_spans_16_c2_ns_nt_z_nf_zc_db(int start, int end, TILE* tex_tile);
170static void render_spans_16_c1_ns_t_nz_nf_zc_db(int start, int end, TILE* tex_tile);
171static void render_spans_16_c2_ns_t_nz_nf_zc_db(int start, int end, TILE* tex_tile);
172static void render_spans_16_c1_ns_t_z_nf_zc_db(int start, int end, TILE* tex_tile);
173static void render_spans_16_c2_ns_t_z_nf_zc_db(int start, int end, TILE* tex_tile);
174static void render_spans_16_c1_s_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile);
175static void render_spans_16_c2_s_nt_nz_nf_zc_db(int start, int end, TILE* tex_tile);
176static void render_spans_16_c1_s_nt_z_nf_zc_db(int start, int end, TILE* tex_tile);
177static void render_spans_16_c2_s_nt_z_nf_zc_db(int start, int end, TILE* tex_tile);
178static void render_spans_16_c1_s_t_nz_nf_zc_db(int start, int end, TILE* tex_tile);
179static void render_spans_16_c2_s_t_nz_nf_zc_db(int start, int end, TILE* tex_tile);
180static void render_spans_16_c1_s_t_z_nf_zc_db(int start, int end, TILE* tex_tile);
181static void render_spans_16_c2_s_t_z_nf_zc_db(int start, int end, TILE* tex_tile);
182static void render_spans_16_c1_ns_nt_nz_f_zc_db(int start, int end, TILE* tex_tile);
183static void render_spans_16_c2_ns_nt_nz_f_zc_db(int start, int end, TILE* tex_tile);
184static void render_spans_16_c1_ns_nt_z_f_zc_db(int start, int end, TILE* tex_tile);
185static void render_spans_16_c2_ns_nt_z_f_zc_db(int start, int end, TILE* tex_tile);
186static void render_spans_16_c1_ns_t_nz_f_zc_db(int start, int end, TILE* tex_tile);
187static void render_spans_16_c2_ns_t_nz_f_zc_db(int start, int end, TILE* tex_tile);
188static void render_spans_16_c1_ns_t_z_f_zc_db(int start, int end, TILE* tex_tile);
189static void render_spans_16_c2_ns_t_z_f_zc_db(int start, int end, TILE* tex_tile);
190static void render_spans_16_c1_s_nt_nz_f_zc_db(int start, int end, TILE* tex_tile);
191static void render_spans_16_c2_s_nt_nz_f_zc_db(int start, int end, TILE* tex_tile);
192static void render_spans_16_c1_s_nt_z_f_zc_db(int start, int end, TILE* tex_tile);
193static void render_spans_16_c2_s_nt_z_f_zc_db(int start, int end, TILE* tex_tile);
194static void render_spans_16_c1_s_t_nz_f_zc_db(int start, int end, TILE* tex_tile);
195static void render_spans_16_c2_s_t_nz_f_zc_db(int start, int end, TILE* tex_tile);
196static void render_spans_16_c1_s_t_z_f_zc_db(int start, int end, TILE* tex_tile);
197static void render_spans_16_c2_s_t_z_f_zc_db(int start, int end, TILE* tex_tile);
14class OtherModes;
15class MiscState;
16class Processor;
19817
199static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
200static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
201static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
202static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
203static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
204static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
205static void render_spans_16_c1_ns_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
206static void render_spans_16_c2_ns_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
207static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
208static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
209static void render_spans_16_c1_s_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
210static void render_spans_16_c2_s_nt_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
211static void render_spans_16_c1_s_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
212static void render_spans_16_c2_s_t_nz_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
213static void render_spans_16_c1_s_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
214static void render_spans_16_c2_s_t_z_nf_nzc_zu_db(int start, int end, TILE* tex_tile);
215static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
216static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
217static void render_spans_16_c1_ns_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
218static void render_spans_16_c2_ns_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
219static void render_spans_16_c1_ns_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
220static void render_spans_16_c2_ns_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
221static void render_spans_16_c1_ns_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
222static void render_spans_16_c2_ns_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
223static void render_spans_16_c1_s_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
224static void render_spans_16_c2_s_nt_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
225static void render_spans_16_c1_s_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
226static void render_spans_16_c2_s_nt_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
227static void render_spans_16_c1_s_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
228static void render_spans_16_c2_s_t_nz_f_nzc_zu_db(int start, int end, TILE* tex_tile);
229static void render_spans_16_c1_s_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
230static void render_spans_16_c2_s_t_z_f_nzc_zu_db(int start, int end, TILE* tex_tile);
18class SpanParam
19{
20   public:
21      union
22      {
23         UINT32 w;
24#ifdef LSB_FIRST
25         struct { UINT16 l; INT16 h; } h;
26#else
27         struct { INT16 h; UINT16 l; } h;
28#endif
29      };
30};
23131
232static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
233static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
234static void render_spans_16_c1_ns_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
235static void render_spans_16_c2_ns_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
236static void render_spans_16_c1_ns_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
237static void render_spans_16_c2_ns_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
238static void render_spans_16_c1_ns_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
239static void render_spans_16_c2_ns_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
240static void render_spans_16_c1_s_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
241static void render_spans_16_c2_s_nt_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
242static void render_spans_16_c1_s_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
243static void render_spans_16_c2_s_nt_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
244static void render_spans_16_c1_s_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
245static void render_spans_16_c2_s_t_nz_nf_zc_zu_db(int start, int end, TILE* tex_tile);
246static void render_spans_16_c1_s_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
247static void render_spans_16_c2_s_t_z_nf_zc_zu_db(int start, int end, TILE* tex_tile);
248static void render_spans_16_c1_ns_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
249static void render_spans_16_c2_ns_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
250static void render_spans_16_c1_ns_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
251static void render_spans_16_c2_ns_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
252static void render_spans_16_c1_ns_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
253static void render_spans_16_c2_ns_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
254static void render_spans_16_c1_ns_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
255static void render_spans_16_c2_ns_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
256static void render_spans_16_c1_s_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
257static void render_spans_16_c2_s_nt_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
258static void render_spans_16_c1_s_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
259static void render_spans_16_c2_s_nt_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
260static void render_spans_16_c1_s_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
261static void render_spans_16_c2_s_t_nz_f_zc_zu_db(int start, int end, TILE* tex_tile);
262static void render_spans_16_c1_s_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
263static void render_spans_16_c2_s_t_z_f_zc_zu_db(int start, int end, TILE* tex_tile);
264
265static void render_spans_16_c1_ns_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
266static void render_spans_16_c2_ns_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
267static void render_spans_16_c1_ns_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
268static void render_spans_16_c2_ns_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
269static void render_spans_16_c1_ns_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
270static void render_spans_16_c2_ns_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
271static void render_spans_16_c1_ns_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
272static void render_spans_16_c2_ns_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
273static void render_spans_16_c1_s_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
274static void render_spans_16_c2_s_nt_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
275static void render_spans_16_c1_s_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
276static void render_spans_16_c2_s_nt_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
277static void render_spans_16_c1_s_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
278static void render_spans_16_c2_s_t_nz_nf_nzc_dn(int start, int end, TILE* tex_tile);
279static void render_spans_16_c1_s_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
280static void render_spans_16_c2_s_t_z_nf_nzc_dn(int start, int end, TILE* tex_tile);
281static void render_spans_16_c1_ns_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
282static void render_spans_16_c2_ns_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
283static void render_spans_16_c1_ns_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile);
284static void render_spans_16_c2_ns_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile);
285static void render_spans_16_c1_ns_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
286static void render_spans_16_c2_ns_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
287static void render_spans_16_c1_ns_t_z_f_nzc_dn(int start, int end, TILE* tex_tile);
288static void render_spans_16_c2_ns_t_z_f_nzc_dn(int start, int end, TILE* tex_tile);
289static void render_spans_16_c1_s_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
290static void render_spans_16_c2_s_nt_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
291static void render_spans_16_c1_s_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile);
292static void render_spans_16_c2_s_nt_z_f_nzc_dn(int start, int end, TILE* tex_tile);
293static void render_spans_16_c1_s_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
294static void render_spans_16_c2_s_t_nz_f_nzc_dn(int start, int end, TILE* tex_tile);
295static void render_spans_16_c1_s_t_z_f_nzc_dn(int start, int end, TILE* tex_tile);
296static void render_spans_16_c2_s_t_z_f_nzc_dn(int start, int end, TILE* tex_tile);
297
298static void render_spans_16_c1_ns_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
299static void render_spans_16_c2_ns_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
300static void render_spans_16_c1_ns_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile);
301static void render_spans_16_c2_ns_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile);
302static void render_spans_16_c1_ns_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
303static void render_spans_16_c2_ns_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
304static void render_spans_16_c1_ns_t_z_nf_zc_dn(int start, int end, TILE* tex_tile);
305static void render_spans_16_c2_ns_t_z_nf_zc_dn(int start, int end, TILE* tex_tile);
306static void render_spans_16_c1_s_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
307static void render_spans_16_c2_s_nt_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
308static void render_spans_16_c1_s_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile);
309static void render_spans_16_c2_s_nt_z_nf_zc_dn(int start, int end, TILE* tex_tile);
310static void render_spans_16_c1_s_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
311static void render_spans_16_c2_s_t_nz_nf_zc_dn(int start, int end, TILE* tex_tile);
312static void render_spans_16_c1_s_t_z_nf_zc_dn(int start, int end, TILE* tex_tile);
313static void render_spans_16_c2_s_t_z_nf_zc_dn(int start, int end, TILE* tex_tile);
314static void render_spans_16_c1_ns_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile);
315static void render_spans_16_c2_ns_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile);
316static void render_spans_16_c1_ns_nt_z_f_zc_dn(int start, int end, TILE* tex_tile);
317static void render_spans_16_c2_ns_nt_z_f_zc_dn(int start, int end, TILE* tex_tile);
318static void render_spans_16_c1_ns_t_nz_f_zc_dn(int start, int end, TILE* tex_tile);
319static void render_spans_16_c2_ns_t_nz_f_zc_dn(int start, int end, TILE* tex_tile);
320static void render_spans_16_c1_ns_t_z_f_zc_dn(int start, int end, TILE* tex_tile);
321static void render_spans_16_c2_ns_t_z_f_zc_dn(int start, int end, TILE* tex_tile);
322static void render_spans_16_c1_s_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile);
323static void render_spans_16_c2_s_nt_nz_f_zc_dn(int start, int end, TILE* tex_tile);
324static void render_spans_16_c1_s_nt_z_f_zc_dn(int start, int end, TILE* tex_tile);
325static void render_spans_16_c2_s_nt_z_f_zc_dn(int start, int end, TILE* tex_tile);
326static void render_spans_16_c1_s_t_nz_f_zc_dn(int start, int end, TILE* tex_tile);
327static void render_spans_16_c2_s_t_nz_f_zc_dn(int start, int end, TILE* tex_tile);
328static void render_spans_16_c1_s_t_z_f_zc_dn(int start, int end, TILE* tex_tile);
329static void render_spans_16_c2_s_t_z_f_zc_dn(int start, int end, TILE* tex_tile);
330
331static void render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
332static void render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
333static void render_spans_16_c1_ns_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
334static void render_spans_16_c2_ns_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
335static void render_spans_16_c1_ns_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
336static void render_spans_16_c2_ns_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
337static void render_spans_16_c1_ns_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
338static void render_spans_16_c2_ns_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
339static void render_spans_16_c1_s_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
340static void render_spans_16_c2_s_nt_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
341static void render_spans_16_c1_s_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
342static void render_spans_16_c2_s_nt_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
343static void render_spans_16_c1_s_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
344static void render_spans_16_c2_s_t_nz_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
345static void render_spans_16_c1_s_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
346static void render_spans_16_c2_s_t_z_nf_nzc_zu_dn(int start, int end, TILE* tex_tile);
347static void render_spans_16_c1_ns_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
348static void render_spans_16_c2_ns_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
349static void render_spans_16_c1_ns_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
350static void render_spans_16_c2_ns_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
351static void render_spans_16_c1_ns_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
352static void render_spans_16_c2_ns_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
353static void render_spans_16_c1_ns_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
354static void render_spans_16_c2_ns_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
355static void render_spans_16_c1_s_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
356static void render_spans_16_c2_s_nt_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
357static void render_spans_16_c1_s_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
358static void render_spans_16_c2_s_nt_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
359static void render_spans_16_c1_s_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
360static void render_spans_16_c2_s_t_nz_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
361static void render_spans_16_c1_s_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
362static void render_spans_16_c2_s_t_z_f_nzc_zu_dn(int start, int end, TILE* tex_tile);
363
364static void render_spans_16_c1_ns_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
365static void render_spans_16_c2_ns_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
366static void render_spans_16_c1_ns_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
367static void render_spans_16_c2_ns_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
368static void render_spans_16_c1_ns_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
369static void render_spans_16_c2_ns_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
370static void render_spans_16_c1_ns_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
371static void render_spans_16_c2_ns_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
372static void render_spans_16_c1_s_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
373static void render_spans_16_c2_s_nt_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
374static void render_spans_16_c1_s_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
375static void render_spans_16_c2_s_nt_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
376static void render_spans_16_c1_s_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
377static void render_spans_16_c2_s_t_nz_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
378static void render_spans_16_c1_s_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
379static void render_spans_16_c2_s_t_z_nf_zc_zu_dn(int start, int end, TILE* tex_tile);
380static void render_spans_16_c1_ns_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
381static void render_spans_16_c2_ns_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
382static void render_spans_16_c1_ns_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
383static void render_spans_16_c2_ns_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
384static void render_spans_16_c1_ns_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
385static void render_spans_16_c2_ns_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
386static void render_spans_16_c1_ns_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
387static void render_spans_16_c2_ns_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
388static void render_spans_16_c1_s_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
389static void render_spans_16_c2_s_nt_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
390static void render_spans_16_c1_s_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
391static void render_spans_16_c2_s_nt_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
392static void render_spans_16_c1_s_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
393static void render_spans_16_c2_s_t_nz_f_zc_zu_dn(int start, int end, TILE* tex_tile);
394static void render_spans_16_c1_s_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
395static void render_spans_16_c2_s_t_z_f_zc_zu_dn(int start, int end, TILE* tex_tile);
396
397static void (*rdp_render_spans_16_func[512])(int, int, TILE*) =
32class Span
39833{
399   render_spans_16_c1_ns_nt_nz_nf_nzc_dm,   render_spans_16_c2_ns_nt_nz_nf_nzc_dm,
400   render_spans_16_c1_ns_nt_z_nf_nzc_dm,   render_spans_16_c2_ns_nt_z_nf_nzc_dm,
401   render_spans_16_c1_ns_t_nz_nf_nzc_dm,   render_spans_16_c2_ns_t_nz_nf_nzc_dm,
402   render_spans_16_c1_ns_t_z_nf_nzc_dm,   render_spans_16_c2_ns_t_z_nf_nzc_dm,
403   render_spans_16_c1_s_nt_nz_nf_nzc_dm,   render_spans_16_c2_s_nt_nz_nf_nzc_dm,
404   render_spans_16_c1_s_nt_z_nf_nzc_dm,   render_spans_16_c2_s_nt_z_nf_nzc_dm,
405   render_spans_16_c1_s_t_nz_nf_nzc_dm,   render_spans_16_c2_s_t_nz_nf_nzc_dm,
406   render_spans_16_c1_s_t_z_nf_nzc_dm,    render_spans_16_c2_s_t_z_nf_nzc_dm,
407   render_spans_16_c1_ns_nt_nz_f_nzc_dm,   render_spans_16_c2_ns_nt_nz_f_nzc_dm,
408   render_spans_16_c1_ns_nt_z_f_nzc_dm,   render_spans_16_c2_ns_nt_z_f_nzc_dm,
409   render_spans_16_c1_ns_t_nz_f_nzc_dm,   render_spans_16_c2_ns_t_nz_f_nzc_dm,
410   render_spans_16_c1_ns_t_z_f_nzc_dm,    render_spans_16_c2_ns_t_z_f_nzc_dm,
411   render_spans_16_c1_s_nt_nz_f_nzc_dm,   render_spans_16_c2_s_nt_nz_f_nzc_dm,
412   render_spans_16_c1_s_nt_z_f_nzc_dm,    render_spans_16_c2_s_nt_z_f_nzc_dm,
413   render_spans_16_c1_s_t_nz_f_nzc_dm,    render_spans_16_c2_s_t_nz_f_nzc_dm,
414   render_spans_16_c1_s_t_z_f_nzc_dm,      render_spans_16_c2_s_t_z_f_nzc_dm,
34   public:
35      Span() { }
41536
416   render_spans_16_c1_ns_nt_nz_nf_zc_dm,   render_spans_16_c2_ns_nt_nz_nf_zc_dm,
417   render_spans_16_c1_ns_nt_z_nf_zc_dm,   render_spans_16_c2_ns_nt_z_nf_zc_dm,
418   render_spans_16_c1_ns_t_nz_nf_zc_dm,   render_spans_16_c2_ns_t_nz_nf_zc_dm,
419   render_spans_16_c1_ns_t_z_nf_zc_dm,    render_spans_16_c2_ns_t_z_nf_zc_dm,
420   render_spans_16_c1_s_nt_nz_nf_zc_dm,   render_spans_16_c2_s_nt_nz_nf_zc_dm,
421   render_spans_16_c1_s_nt_z_nf_zc_dm,    render_spans_16_c2_s_nt_z_nf_zc_dm,
422   render_spans_16_c1_s_t_nz_nf_zc_dm,    render_spans_16_c2_s_t_nz_nf_zc_dm,
423   render_spans_16_c1_s_t_z_nf_zc_dm,      render_spans_16_c2_s_t_z_nf_zc_dm,
424   render_spans_16_c1_ns_nt_nz_f_zc_dm,   render_spans_16_c2_ns_nt_nz_f_zc_dm,
425   render_spans_16_c1_ns_nt_z_f_zc_dm,    render_spans_16_c2_ns_nt_z_f_zc_dm,
426   render_spans_16_c1_ns_t_nz_f_zc_dm,    render_spans_16_c2_ns_t_nz_f_zc_dm,
427   render_spans_16_c1_ns_t_z_f_zc_dm,      render_spans_16_c2_ns_t_z_f_zc_dm,
428   render_spans_16_c1_s_nt_nz_f_zc_dm,    render_spans_16_c2_s_nt_nz_f_zc_dm,
429   render_spans_16_c1_s_nt_z_f_zc_dm,      render_spans_16_c2_s_nt_z_f_zc_dm,
430   render_spans_16_c1_s_t_nz_f_zc_dm,      render_spans_16_c2_s_t_nz_f_zc_dm,
431   render_spans_16_c1_s_t_z_f_zc_dm,      render_spans_16_c2_s_t_z_f_zc_dm,
37      void   Draw(int index, int tilenum, bool shade, bool texture, bool zbuffer, bool flip);
38      void   Dump();
39      void   SetMachine(running_machine* machine);
43240
433   render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dm,   render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dm,
434   render_spans_16_c1_ns_nt_z_nf_nzc_zu_dm,   render_spans_16_c2_ns_nt_z_nf_nzc_zu_dm,
435   render_spans_16_c1_ns_t_nz_nf_nzc_zu_dm,   render_spans_16_c2_ns_t_nz_nf_nzc_zu_dm,
436   render_spans_16_c1_ns_t_z_nf_nzc_zu_dm,    render_spans_16_c2_ns_t_z_nf_nzc_zu_dm,
437   render_spans_16_c1_s_nt_nz_nf_nzc_zu_dm,   render_spans_16_c2_s_nt_nz_nf_nzc_zu_dm,
438   render_spans_16_c1_s_nt_z_nf_nzc_zu_dm,    render_spans_16_c2_s_nt_z_nf_nzc_zu_dm,
439   render_spans_16_c1_s_t_nz_nf_nzc_zu_dm,    render_spans_16_c2_s_t_nz_nf_nzc_zu_dm,
440   render_spans_16_c1_s_t_z_nf_nzc_zu_dm,      render_spans_16_c2_s_t_z_nf_nzc_zu_dm,
441   render_spans_16_c1_ns_nt_nz_f_nzc_zu_dm,   render_spans_16_c2_ns_nt_nz_f_nzc_zu_dm,
442   render_spans_16_c1_ns_nt_z_f_nzc_zu_dm,    render_spans_16_c2_ns_nt_z_f_nzc_zu_dm,
443   render_spans_16_c1_ns_t_nz_f_nzc_zu_dm,    render_spans_16_c2_ns_t_nz_f_nzc_zu_dm,
444   render_spans_16_c1_ns_t_z_f_nzc_zu_dm,      render_spans_16_c2_ns_t_z_f_nzc_zu_dm,
445   render_spans_16_c1_s_nt_nz_f_nzc_zu_dm,    render_spans_16_c2_s_nt_nz_f_nzc_zu_dm,
446   render_spans_16_c1_s_nt_z_f_nzc_zu_dm,      render_spans_16_c2_s_nt_z_f_nzc_zu_dm,
447   render_spans_16_c1_s_t_nz_f_nzc_zu_dm,      render_spans_16_c2_s_t_nz_f_nzc_zu_dm,
448   render_spans_16_c1_s_t_z_f_nzc_zu_dm,      render_spans_16_c2_s_t_z_f_nzc_zu_dm,
41   public:
42      int m_lx;
43      int m_rx;
44944
450   render_spans_16_c1_ns_nt_nz_nf_zc_zu_dm,   render_spans_16_c2_ns_nt_nz_nf_zc_zu_dm,
451   render_spans_16_c1_ns_nt_z_nf_zc_zu_dm,    render_spans_16_c2_ns_nt_z_nf_zc_zu_dm,
452   render_spans_16_c1_ns_t_nz_nf_zc_zu_dm,    render_spans_16_c2_ns_t_nz_nf_zc_zu_dm,
453   render_spans_16_c1_ns_t_z_nf_zc_zu_dm,      render_spans_16_c2_ns_t_z_nf_zc_zu_dm,
454   render_spans_16_c1_s_nt_nz_nf_zc_zu_dm,    render_spans_16_c2_s_nt_nz_nf_zc_zu_dm,
455   render_spans_16_c1_s_nt_z_nf_zc_zu_dm,      render_spans_16_c2_s_nt_z_nf_zc_zu_dm,
456   render_spans_16_c1_s_t_nz_nf_zc_zu_dm,      render_spans_16_c2_s_t_nz_nf_zc_zu_dm,
457   render_spans_16_c1_s_t_z_nf_zc_zu_dm,      render_spans_16_c2_s_t_z_nf_zc_zu_dm,
458   render_spans_16_c1_ns_nt_nz_f_zc_zu_dm,    render_spans_16_c2_ns_nt_nz_f_zc_zu_dm,
459   render_spans_16_c1_ns_nt_z_f_zc_zu_dm,      render_spans_16_c2_ns_nt_z_f_zc_zu_dm,
460   render_spans_16_c1_ns_t_nz_f_zc_zu_dm,      render_spans_16_c2_ns_t_nz_f_zc_zu_dm,
461   render_spans_16_c1_ns_t_z_f_zc_zu_dm,      render_spans_16_c2_ns_t_z_f_zc_zu_dm,
462   render_spans_16_c1_s_nt_nz_f_zc_zu_dm,      render_spans_16_c2_s_nt_nz_f_zc_zu_dm,
463   render_spans_16_c1_s_nt_z_f_zc_zu_dm,      render_spans_16_c2_s_nt_z_f_zc_zu_dm,
464   render_spans_16_c1_s_t_nz_f_zc_zu_dm,      render_spans_16_c2_s_t_nz_f_zc_zu_dm,
465   render_spans_16_c1_s_t_z_f_zc_zu_dm,      render_spans_16_c2_s_t_z_f_zc_zu_dm,
45      SpanParam m_s;
46      SpanParam m_t;
47      SpanParam m_w;
48      SpanParam m_r;
49      SpanParam m_g;
50      SpanParam m_b;
51      SpanParam m_a;
52      SpanParam m_z;
46653
467   render_spans_16_c1_ns_nt_nz_nf_nzc_db, render_spans_16_c2_ns_nt_nz_nf_nzc_db,
468   render_spans_16_c1_ns_nt_z_nf_nzc_db,   render_spans_16_c2_ns_nt_z_nf_nzc_db,
469   render_spans_16_c1_ns_t_nz_nf_nzc_db,   render_spans_16_c2_ns_t_nz_nf_nzc_db,
470   render_spans_16_c1_ns_t_z_nf_nzc_db,   render_spans_16_c2_ns_t_z_nf_nzc_db,
471   render_spans_16_c1_s_nt_nz_nf_nzc_db,   render_spans_16_c2_s_nt_nz_nf_nzc_db,
472   render_spans_16_c1_s_nt_z_nf_nzc_db,   render_spans_16_c2_s_nt_z_nf_nzc_db,
473   render_spans_16_c1_s_t_nz_nf_nzc_db,   render_spans_16_c2_s_t_nz_nf_nzc_db,
474   render_spans_16_c1_s_t_z_nf_nzc_db,    render_spans_16_c2_s_t_z_nf_nzc_db,
475   render_spans_16_c1_ns_nt_nz_f_nzc_db,   render_spans_16_c2_ns_nt_nz_f_nzc_db,
476   render_spans_16_c1_ns_nt_z_f_nzc_db,   render_spans_16_c2_ns_nt_z_f_nzc_db,
477   render_spans_16_c1_ns_t_nz_f_nzc_db,   render_spans_16_c2_ns_t_nz_f_nzc_db,
478   render_spans_16_c1_ns_t_z_f_nzc_db,    render_spans_16_c2_ns_t_z_f_nzc_db,
479   render_spans_16_c1_s_nt_nz_f_nzc_db,   render_spans_16_c2_s_nt_nz_f_nzc_db,
480   render_spans_16_c1_s_nt_z_f_nzc_db,    render_spans_16_c2_s_nt_z_f_nzc_db,
481   render_spans_16_c1_s_t_nz_f_nzc_db,    render_spans_16_c2_s_t_nz_f_nzc_db,
482   render_spans_16_c1_s_t_z_f_nzc_db,   render_spans_16_c2_s_t_z_f_nzc_db,
54      UINT8 m_cvg[RDP_CVG_SPAN_MAX];
48355
484   render_spans_16_c1_ns_nt_nz_nf_zc_db,   render_spans_16_c2_ns_nt_nz_nf_zc_db,
485   render_spans_16_c1_ns_nt_z_nf_zc_db,   render_spans_16_c2_ns_nt_z_nf_zc_db,
486   render_spans_16_c1_ns_t_nz_nf_zc_db,   render_spans_16_c2_ns_t_nz_nf_zc_db,
487   render_spans_16_c1_ns_t_z_nf_zc_db,    render_spans_16_c2_ns_t_z_nf_zc_db,
488   render_spans_16_c1_s_nt_nz_nf_zc_db,   render_spans_16_c2_s_nt_nz_nf_zc_db,
489   render_spans_16_c1_s_nt_z_nf_zc_db,    render_spans_16_c2_s_nt_z_nf_zc_db,
490   render_spans_16_c1_s_t_nz_nf_zc_db,    render_spans_16_c2_s_t_nz_nf_zc_db,
491   render_spans_16_c1_s_t_z_nf_zc_db,   render_spans_16_c2_s_t_z_nf_zc_db,
492   render_spans_16_c1_ns_nt_nz_f_zc_db,   render_spans_16_c2_ns_nt_nz_f_zc_db,
493   render_spans_16_c1_ns_nt_z_f_zc_db,    render_spans_16_c2_ns_nt_z_f_zc_db,
494   render_spans_16_c1_ns_t_nz_f_zc_db,    render_spans_16_c2_ns_t_nz_f_zc_db,
495   render_spans_16_c1_ns_t_z_f_zc_db,   render_spans_16_c2_ns_t_z_f_zc_db,
496   render_spans_16_c1_s_nt_nz_f_zc_db,    render_spans_16_c2_s_nt_nz_f_zc_db,
497   render_spans_16_c1_s_nt_z_f_zc_db,   render_spans_16_c2_s_nt_z_f_zc_db,
498   render_spans_16_c1_s_t_nz_f_zc_db,   render_spans_16_c2_s_t_nz_f_zc_db,
499   render_spans_16_c1_s_t_z_f_zc_db,      render_spans_16_c2_s_t_z_f_zc_db,
56      int m_dymax;
50057
501   render_spans_16_c1_ns_nt_nz_nf_nzc_zu_db,   render_spans_16_c2_ns_nt_nz_nf_nzc_zu_db,
502   render_spans_16_c1_ns_nt_z_nf_nzc_zu_db,   render_spans_16_c2_ns_nt_z_nf_nzc_zu_db,
503   render_spans_16_c1_ns_t_nz_nf_nzc_zu_db,   render_spans_16_c2_ns_t_nz_nf_nzc_zu_db,
504   render_spans_16_c1_ns_t_z_nf_nzc_zu_db,    render_spans_16_c2_ns_t_z_nf_nzc_zu_db,
505   render_spans_16_c1_s_nt_nz_nf_nzc_zu_db,   render_spans_16_c2_s_nt_nz_nf_nzc_zu_db,
506   render_spans_16_c1_s_nt_z_nf_nzc_zu_db,    render_spans_16_c2_s_nt_z_nf_nzc_zu_db,
507   render_spans_16_c1_s_t_nz_nf_nzc_zu_db,    render_spans_16_c2_s_t_nz_nf_nzc_zu_db,
508   render_spans_16_c1_s_t_z_nf_nzc_zu_db,   render_spans_16_c2_s_t_z_nf_nzc_zu_db,
509   render_spans_16_c1_ns_nt_nz_f_nzc_zu_db,   render_spans_16_c2_ns_nt_nz_f_nzc_zu_db,
510   render_spans_16_c1_ns_nt_z_f_nzc_zu_db,    render_spans_16_c2_ns_nt_z_f_nzc_zu_db,
511   render_spans_16_c1_ns_t_nz_f_nzc_zu_db,    render_spans_16_c2_ns_t_nz_f_nzc_zu_db,
512   render_spans_16_c1_ns_t_z_f_nzc_zu_db,   render_spans_16_c2_ns_t_z_f_nzc_zu_db,
513   render_spans_16_c1_s_nt_nz_f_nzc_zu_db,    render_spans_16_c2_s_nt_nz_f_nzc_zu_db,
514   render_spans_16_c1_s_nt_z_f_nzc_zu_db,   render_spans_16_c2_s_nt_z_f_nzc_zu_db,
515   render_spans_16_c1_s_t_nz_f_nzc_zu_db,   render_spans_16_c2_s_t_nz_f_nzc_zu_db,
516   render_spans_16_c1_s_t_z_f_nzc_zu_db,      render_spans_16_c2_s_t_z_f_nzc_zu_db,
58      SpanParam m_ds;
59      SpanParam m_dt;
60      SpanParam m_dw;
61      SpanParam m_dr;
62      SpanParam m_dg;
63      SpanParam m_db;
64      SpanParam m_da;
65      SpanParam m_dz;
51766
518   render_spans_16_c1_ns_nt_nz_nf_zc_zu_db,   render_spans_16_c2_ns_nt_nz_nf_zc_zu_db,
519   render_spans_16_c1_ns_nt_z_nf_zc_zu_db,    render_spans_16_c2_ns_nt_z_nf_zc_zu_db,
520   render_spans_16_c1_ns_t_nz_nf_zc_zu_db,    render_spans_16_c2_ns_t_nz_nf_zc_zu_db,
521   render_spans_16_c1_ns_t_z_nf_zc_zu_db,   render_spans_16_c2_ns_t_z_nf_zc_zu_db,
522   render_spans_16_c1_s_nt_nz_nf_zc_zu_db,    render_spans_16_c2_s_nt_nz_nf_zc_zu_db,
523   render_spans_16_c1_s_nt_z_nf_zc_zu_db,   render_spans_16_c2_s_nt_z_nf_zc_zu_db,
524   render_spans_16_c1_s_t_nz_nf_zc_zu_db,   render_spans_16_c2_s_t_nz_nf_zc_zu_db,
525   render_spans_16_c1_s_t_z_nf_zc_zu_db,      render_spans_16_c2_s_t_z_nf_zc_zu_db,
526   render_spans_16_c1_ns_nt_nz_f_zc_zu_db,    render_spans_16_c2_ns_nt_nz_f_zc_zu_db,
527   render_spans_16_c1_ns_nt_z_f_zc_zu_db,   render_spans_16_c2_ns_nt_z_f_zc_zu_db,
528   render_spans_16_c1_ns_t_nz_f_zc_zu_db,   render_spans_16_c2_ns_t_nz_f_zc_zu_db,
529   render_spans_16_c1_ns_t_z_f_zc_zu_db,      render_spans_16_c2_ns_t_z_f_zc_zu_db,
530   render_spans_16_c1_s_nt_nz_f_zc_zu_db,   render_spans_16_c2_s_nt_nz_f_zc_zu_db,
531   render_spans_16_c1_s_nt_z_f_zc_zu_db,      render_spans_16_c2_s_nt_z_f_zc_zu_db,
532   render_spans_16_c1_s_t_nz_f_zc_zu_db,      render_spans_16_c2_s_t_nz_f_zc_zu_db,
533   render_spans_16_c1_s_t_z_f_zc_zu_db,      render_spans_16_c2_s_t_z_f_zc_zu_db,
67      int m_dzpix;
53468
535   render_spans_16_c1_ns_nt_nz_nf_nzc_dn, render_spans_16_c2_ns_nt_nz_nf_nzc_dn,
536   render_spans_16_c1_ns_nt_z_nf_nzc_dn,   render_spans_16_c2_ns_nt_z_nf_nzc_dn,
537   render_spans_16_c1_ns_t_nz_nf_nzc_dn,   render_spans_16_c2_ns_t_nz_nf_nzc_dn,
538   render_spans_16_c1_ns_t_z_nf_nzc_dn,   render_spans_16_c2_ns_t_z_nf_nzc_dn,
539   render_spans_16_c1_s_nt_nz_nf_nzc_dn,   render_spans_16_c2_s_nt_nz_nf_nzc_dn,
540   render_spans_16_c1_s_nt_z_nf_nzc_dn,   render_spans_16_c2_s_nt_z_nf_nzc_dn,
541   render_spans_16_c1_s_t_nz_nf_nzc_dn,   render_spans_16_c2_s_t_nz_nf_nzc_dn,
542   render_spans_16_c1_s_t_z_nf_nzc_dn,    render_spans_16_c2_s_t_z_nf_nzc_dn,
543   render_spans_16_c1_ns_nt_nz_f_nzc_dn,   render_spans_16_c2_ns_nt_nz_f_nzc_dn,
544   render_spans_16_c1_ns_nt_z_f_nzc_dn,   render_spans_16_c2_ns_nt_z_f_nzc_dn,
545   render_spans_16_c1_ns_t_nz_f_nzc_dn,   render_spans_16_c2_ns_t_nz_f_nzc_dn,
546   render_spans_16_c1_ns_t_z_f_nzc_dn,    render_spans_16_c2_ns_t_z_f_nzc_dn,
547   render_spans_16_c1_s_nt_nz_f_nzc_dn,   render_spans_16_c2_s_nt_nz_f_nzc_dn,
548   render_spans_16_c1_s_nt_z_f_nzc_dn,    render_spans_16_c2_s_nt_z_f_nzc_dn,
549   render_spans_16_c1_s_t_nz_f_nzc_dn,    render_spans_16_c2_s_t_nz_f_nzc_dn,
550   render_spans_16_c1_s_t_z_f_nzc_dn,   render_spans_16_c2_s_t_z_f_nzc_dn,
69   private:
70      running_machine* m_machine;
71      Processor* m_rdp;
72      MiscState* m_misc_state;
73      OtherModes* m_other_modes;
74};
55175
552   render_spans_16_c1_ns_nt_nz_nf_zc_dn,   render_spans_16_c2_ns_nt_nz_nf_zc_dn,
553   render_spans_16_c1_ns_nt_z_nf_zc_dn,   render_spans_16_c2_ns_nt_z_nf_zc_dn,
554   render_spans_16_c1_ns_t_nz_nf_zc_dn,   render_spans_16_c2_ns_t_nz_nf_zc_dn,
555   render_spans_16_c1_ns_t_z_nf_zc_dn,    render_spans_16_c2_ns_t_z_nf_zc_dn,
556   render_spans_16_c1_s_nt_nz_nf_zc_dn,   render_spans_16_c2_s_nt_nz_nf_zc_dn,
557   render_spans_16_c1_s_nt_z_nf_zc_dn,    render_spans_16_c2_s_nt_z_nf_zc_dn,
558   render_spans_16_c1_s_t_nz_nf_zc_dn,    render_spans_16_c2_s_t_nz_nf_zc_dn,
559   render_spans_16_c1_s_t_z_nf_zc_dn,   render_spans_16_c2_s_t_z_nf_zc_dn,
560   render_spans_16_c1_ns_nt_nz_f_zc_dn,   render_spans_16_c2_ns_nt_nz_f_zc_dn,
561   render_spans_16_c1_ns_nt_z_f_zc_dn,    render_spans_16_c2_ns_nt_z_f_zc_dn,
562   render_spans_16_c1_ns_t_nz_f_zc_dn,    render_spans_16_c2_ns_t_nz_f_zc_dn,
563   render_spans_16_c1_ns_t_z_f_zc_dn,   render_spans_16_c2_ns_t_z_f_zc_dn,
564   render_spans_16_c1_s_nt_nz_f_zc_dn,    render_spans_16_c2_s_nt_nz_f_zc_dn,
565   render_spans_16_c1_s_nt_z_f_zc_dn,   render_spans_16_c2_s_nt_z_f_zc_dn,
566   render_spans_16_c1_s_t_nz_f_zc_dn,   render_spans_16_c2_s_t_nz_f_zc_dn,
567   render_spans_16_c1_s_t_z_f_zc_dn,      render_spans_16_c2_s_t_z_f_zc_dn,
76} // namespace RDP
56877
569   render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dn,   render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dn,
570   render_spans_16_c1_ns_nt_z_nf_nzc_zu_dn,   render_spans_16_c2_ns_nt_z_nf_nzc_zu_dn,
571   render_spans_16_c1_ns_t_nz_nf_nzc_zu_dn,   render_spans_16_c2_ns_t_nz_nf_nzc_zu_dn,
572   render_spans_16_c1_ns_t_z_nf_nzc_zu_dn,    render_spans_16_c2_ns_t_z_nf_nzc_zu_dn,
573   render_spans_16_c1_s_nt_nz_nf_nzc_zu_dn,   render_spans_16_c2_s_nt_nz_nf_nzc_zu_dn,
574   render_spans_16_c1_s_nt_z_nf_nzc_zu_dn,    render_spans_16_c2_s_nt_z_nf_nzc_zu_dn,
575   render_spans_16_c1_s_t_nz_nf_nzc_zu_dn,    render_spans_16_c2_s_t_nz_nf_nzc_zu_dn,
576   render_spans_16_c1_s_t_z_nf_nzc_zu_dn,   render_spans_16_c2_s_t_z_nf_nzc_zu_dn,
577   render_spans_16_c1_ns_nt_nz_f_nzc_zu_dn,   render_spans_16_c2_ns_nt_nz_f_nzc_zu_dn,
578   render_spans_16_c1_ns_nt_z_f_nzc_zu_dn,    render_spans_16_c2_ns_nt_z_f_nzc_zu_dn,
579   render_spans_16_c1_ns_t_nz_f_nzc_zu_dn,    render_spans_16_c2_ns_t_nz_f_nzc_zu_dn,
580   render_spans_16_c1_ns_t_z_f_nzc_zu_dn,   render_spans_16_c2_ns_t_z_f_nzc_zu_dn,
581   render_spans_16_c1_s_nt_nz_f_nzc_zu_dn,    render_spans_16_c2_s_nt_nz_f_nzc_zu_dn,
582   render_spans_16_c1_s_nt_z_f_nzc_zu_dn,   render_spans_16_c2_s_nt_z_f_nzc_zu_dn,
583   render_spans_16_c1_s_t_nz_f_nzc_zu_dn,   render_spans_16_c2_s_t_nz_f_nzc_zu_dn,
584   render_spans_16_c1_s_t_z_f_nzc_zu_dn,      render_spans_16_c2_s_t_z_f_nzc_zu_dn,
78} // namespace N64
58579
586   render_spans_16_c1_ns_nt_nz_nf_zc_zu_dn,   render_spans_16_c2_ns_nt_nz_nf_zc_zu_dn,
587   render_spans_16_c1_ns_nt_z_nf_zc_zu_dn,    render_spans_16_c2_ns_nt_z_nf_zc_zu_dn,
588   render_spans_16_c1_ns_t_nz_nf_zc_zu_dn,    render_spans_16_c2_ns_t_nz_nf_zc_zu_dn,
589   render_spans_16_c1_ns_t_z_nf_zc_zu_dn,   render_spans_16_c2_ns_t_z_nf_zc_zu_dn,
590   render_spans_16_c1_s_nt_nz_nf_zc_zu_dn,    render_spans_16_c2_s_nt_nz_nf_zc_zu_dn,
591   render_spans_16_c1_s_nt_z_nf_zc_zu_dn,   render_spans_16_c2_s_nt_z_nf_zc_zu_dn,
592   render_spans_16_c1_s_t_nz_nf_zc_zu_dn,   render_spans_16_c2_s_t_nz_nf_zc_zu_dn,
593   render_spans_16_c1_s_t_z_nf_zc_zu_dn,      render_spans_16_c2_s_t_z_nf_zc_zu_dn,
594   render_spans_16_c1_ns_nt_nz_f_zc_zu_dn,    render_spans_16_c2_ns_nt_nz_f_zc_zu_dn,
595   render_spans_16_c1_ns_nt_z_f_zc_zu_dn,   render_spans_16_c2_ns_nt_z_f_zc_zu_dn,
596   render_spans_16_c1_ns_t_nz_f_zc_zu_dn,   render_spans_16_c2_ns_t_nz_f_zc_zu_dn,
597   render_spans_16_c1_ns_t_z_f_zc_zu_dn,      render_spans_16_c2_ns_t_z_f_zc_zu_dn,
598   render_spans_16_c1_s_nt_nz_f_zc_zu_dn,   render_spans_16_c2_s_nt_nz_f_zc_zu_dn,
599   render_spans_16_c1_s_nt_z_f_zc_zu_dn,      render_spans_16_c2_s_nt_z_f_zc_zu_dn,
600   render_spans_16_c1_s_t_nz_f_zc_zu_dn,      render_spans_16_c2_s_t_nz_f_zc_zu_dn,
601   render_spans_16_c1_s_t_z_f_zc_zu_dn,      render_spans_16_c2_s_t_z_f_zc_zu_dn,
602
603   render_spans_16_c1_ns_nt_nz_nf_nzc_dn, render_spans_16_c2_ns_nt_nz_nf_nzc_dn,
604   render_spans_16_c1_ns_nt_z_nf_nzc_dn,   render_spans_16_c2_ns_nt_z_nf_nzc_dn,
605   render_spans_16_c1_ns_t_nz_nf_nzc_dn,   render_spans_16_c2_ns_t_nz_nf_nzc_dn,
606   render_spans_16_c1_ns_t_z_nf_nzc_dn,   render_spans_16_c2_ns_t_z_nf_nzc_dn,
607   render_spans_16_c1_s_nt_nz_nf_nzc_dn,   render_spans_16_c2_s_nt_nz_nf_nzc_dn,
608   render_spans_16_c1_s_nt_z_nf_nzc_dn,   render_spans_16_c2_s_nt_z_nf_nzc_dn,
609   render_spans_16_c1_s_t_nz_nf_nzc_dn,   render_spans_16_c2_s_t_nz_nf_nzc_dn,
610   render_spans_16_c1_s_t_z_nf_nzc_dn,    render_spans_16_c2_s_t_z_nf_nzc_dn,
611   render_spans_16_c1_ns_nt_nz_f_nzc_dn,   render_spans_16_c2_ns_nt_nz_f_nzc_dn,
612   render_spans_16_c1_ns_nt_z_f_nzc_dn,   render_spans_16_c2_ns_nt_z_f_nzc_dn,
613   render_spans_16_c1_ns_t_nz_f_nzc_dn,   render_spans_16_c2_ns_t_nz_f_nzc_dn,
614   render_spans_16_c1_ns_t_z_f_nzc_dn,    render_spans_16_c2_ns_t_z_f_nzc_dn,
615   render_spans_16_c1_s_nt_nz_f_nzc_dn,   render_spans_16_c2_s_nt_nz_f_nzc_dn,
616   render_spans_16_c1_s_nt_z_f_nzc_dn,    render_spans_16_c2_s_nt_z_f_nzc_dn,
617   render_spans_16_c1_s_t_nz_f_nzc_dn,    render_spans_16_c2_s_t_nz_f_nzc_dn,
618   render_spans_16_c1_s_t_z_f_nzc_dn,   render_spans_16_c2_s_t_z_f_nzc_dn,
619
620   render_spans_16_c1_ns_nt_nz_nf_zc_dn,   render_spans_16_c2_ns_nt_nz_nf_zc_dn,
621   render_spans_16_c1_ns_nt_z_nf_zc_dn,   render_spans_16_c2_ns_nt_z_nf_zc_dn,
622   render_spans_16_c1_ns_t_nz_nf_zc_dn,   render_spans_16_c2_ns_t_nz_nf_zc_dn,
623   render_spans_16_c1_ns_t_z_nf_zc_dn,    render_spans_16_c2_ns_t_z_nf_zc_dn,
624   render_spans_16_c1_s_nt_nz_nf_zc_dn,   render_spans_16_c2_s_nt_nz_nf_zc_dn,
625   render_spans_16_c1_s_nt_z_nf_zc_dn,    render_spans_16_c2_s_nt_z_nf_zc_dn,
626   render_spans_16_c1_s_t_nz_nf_zc_dn,    render_spans_16_c2_s_t_nz_nf_zc_dn,
627   render_spans_16_c1_s_t_z_nf_zc_dn,   render_spans_16_c2_s_t_z_nf_zc_dn,
628   render_spans_16_c1_ns_nt_nz_f_zc_dn,   render_spans_16_c2_ns_nt_nz_f_zc_dn,
629   render_spans_16_c1_ns_nt_z_f_zc_dn,    render_spans_16_c2_ns_nt_z_f_zc_dn,
630   render_spans_16_c1_ns_t_nz_f_zc_dn,    render_spans_16_c2_ns_t_nz_f_zc_dn,
631   render_spans_16_c1_ns_t_z_f_zc_dn,   render_spans_16_c2_ns_t_z_f_zc_dn,
632   render_spans_16_c1_s_nt_nz_f_zc_dn,    render_spans_16_c2_s_nt_nz_f_zc_dn,
633   render_spans_16_c1_s_nt_z_f_zc_dn,   render_spans_16_c2_s_nt_z_f_zc_dn,
634   render_spans_16_c1_s_t_nz_f_zc_dn,   render_spans_16_c2_s_t_nz_f_zc_dn,
635   render_spans_16_c1_s_t_z_f_zc_dn,      render_spans_16_c2_s_t_z_f_zc_dn,
636
637   render_spans_16_c1_ns_nt_nz_nf_nzc_zu_dn,   render_spans_16_c2_ns_nt_nz_nf_nzc_zu_dn,
638   render_spans_16_c1_ns_nt_z_nf_nzc_zu_dn,   render_spans_16_c2_ns_nt_z_nf_nzc_zu_dn,
639   render_spans_16_c1_ns_t_nz_nf_nzc_zu_dn,   render_spans_16_c2_ns_t_nz_nf_nzc_zu_dn,
640   render_spans_16_c1_ns_t_z_nf_nzc_zu_dn,    render_spans_16_c2_ns_t_z_nf_nzc_zu_dn,
641   render_spans_16_c1_s_nt_nz_nf_nzc_zu_dn,   render_spans_16_c2_s_nt_nz_nf_nzc_zu_dn,
642   render_spans_16_c1_s_nt_z_nf_nzc_zu_dn,    render_spans_16_c2_s_nt_z_nf_nzc_zu_dn,
643   render_spans_16_c1_s_t_nz_nf_nzc_zu_dn,    render_spans_16_c2_s_t_nz_nf_nzc_zu_dn,
644   render_spans_16_c1_s_t_z_nf_nzc_zu_dn,   render_spans_16_c2_s_t_z_nf_nzc_zu_dn,
645   render_spans_16_c1_ns_nt_nz_f_nzc_zu_dn,   render_spans_16_c2_ns_nt_nz_f_nzc_zu_dn,
646   render_spans_16_c1_ns_nt_z_f_nzc_zu_dn,    render_spans_16_c2_ns_nt_z_f_nzc_zu_dn,
647   render_spans_16_c1_ns_t_nz_f_nzc_zu_dn,    render_spans_16_c2_ns_t_nz_f_nzc_zu_dn,
648   render_spans_16_c1_ns_t_z_f_nzc_zu_dn,   render_spans_16_c2_ns_t_z_f_nzc_zu_dn,
649   render_spans_16_c1_s_nt_nz_f_nzc_zu_dn,    render_spans_16_c2_s_nt_nz_f_nzc_zu_dn,
650   render_spans_16_c1_s_nt_z_f_nzc_zu_dn,   render_spans_16_c2_s_nt_z_f_nzc_zu_dn,
651   render_spans_16_c1_s_t_nz_f_nzc_zu_dn,   render_spans_16_c2_s_t_nz_f_nzc_zu_dn,
652   render_spans_16_c1_s_t_z_f_nzc_zu_dn,      render_spans_16_c2_s_t_z_f_nzc_zu_dn,
653
654   render_spans_16_c1_ns_nt_nz_nf_zc_zu_dn,   render_spans_16_c2_ns_nt_nz_nf_zc_zu_dn,
655   render_spans_16_c1_ns_nt_z_nf_zc_zu_dn,    render_spans_16_c2_ns_nt_z_nf_zc_zu_dn,
656   render_spans_16_c1_ns_t_nz_nf_zc_zu_dn,    render_spans_16_c2_ns_t_nz_nf_zc_zu_dn,
657   render_spans_16_c1_ns_t_z_nf_zc_zu_dn,   render_spans_16_c2_ns_t_z_nf_zc_zu_dn,
658   render_spans_16_c1_s_nt_nz_nf_zc_zu_dn,    render_spans_16_c2_s_nt_nz_nf_zc_zu_dn,
659   render_spans_16_c1_s_nt_z_nf_zc_zu_dn,   render_spans_16_c2_s_nt_z_nf_zc_zu_dn,
660   render_spans_16_c1_s_t_nz_nf_zc_zu_dn,   render_spans_16_c2_s_t_nz_nf_zc_zu_dn,
661   render_spans_16_c1_s_t_z_nf_zc_zu_dn,      render_spans_16_c2_s_t_z_nf_zc_zu_dn,
662   render_spans_16_c1_ns_nt_nz_f_zc_zu_dn,    render_spans_16_c2_ns_nt_nz_f_zc_zu_dn,
663   render_spans_16_c1_ns_nt_z_f_zc_zu_dn,   render_spans_16_c2_ns_nt_z_f_zc_zu_dn,
664   render_spans_16_c1_ns_t_nz_f_zc_zu_dn,   render_spans_16_c2_ns_t_nz_f_zc_zu_dn,
665   render_spans_16_c1_ns_t_z_f_zc_zu_dn,      render_spans_16_c2_ns_t_z_f_zc_zu_dn,
666   render_spans_16_c1_s_nt_nz_f_zc_zu_dn,   render_spans_16_c2_s_nt_nz_f_zc_zu_dn,
667   render_spans_16_c1_s_nt_z_f_zc_zu_dn,      render_spans_16_c2_s_nt_z_f_zc_zu_dn,
668   render_spans_16_c1_s_t_nz_f_zc_zu_dn,      render_spans_16_c2_s_t_nz_f_zc_zu_dn,
669   render_spans_16_c1_s_t_z_f_zc_zu_dn,      render_spans_16_c2_s_t_z_f_zc_zu_dn,
670};
80#endif // _VIDEO_RDPSPAN_H_
src/mame/video/rdptrect.c
r7675r7676
1#if defined(ZCOMPARE)
2   #if defined(ZUPDATE)
3      #if defined(MAGICDITHER)
4         static void texture_rectangle_16bit_c1_zc_zu_dm(TEX_RECTANGLE *rect)
5      #elif defined(BAYERDITHER)
6         static void texture_rectangle_16bit_c1_zc_zu_db(TEX_RECTANGLE *rect)
7      #else
8         static void texture_rectangle_16bit_c1_zc_zu_dn(TEX_RECTANGLE *rect)
9      #endif
10   #else
11      #if defined(MAGICDITHER)
12         static void texture_rectangle_16bit_c1_zc_nzu_dm(TEX_RECTANGLE *rect)
13      #elif defined(BAYERDITHER)
14         static void texture_rectangle_16bit_c1_zc_nzu_db(TEX_RECTANGLE *rect)
15      #else
16         static void texture_rectangle_16bit_c1_zc_nzu_dn(TEX_RECTANGLE *rect)
17      #endif
18   #endif
19#else
20   #if defined(ZUPDATE)
21      #if defined(MAGICDITHER)
22         static void texture_rectangle_16bit_c1_nzc_zu_dm(TEX_RECTANGLE *rect)
23      #elif defined(BAYERDITHER)
24         static void texture_rectangle_16bit_c1_nzc_zu_db(TEX_RECTANGLE *rect)
25      #else
26         static void texture_rectangle_16bit_c1_nzc_zu_dn(TEX_RECTANGLE *rect)
27      #endif
28   #else
29      #if defined(MAGICDITHER)
30         static void texture_rectangle_16bit_c1_nzc_nzu_dm(TEX_RECTANGLE *rect)
31      #elif defined(BAYERDITHER)
32         static void texture_rectangle_16bit_c1_nzc_nzu_db(TEX_RECTANGLE *rect)
33      #else
34         static void texture_rectangle_16bit_c1_nzc_nzu_dn(TEX_RECTANGLE *rect)
35      #endif
36   #endif
37#endif
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
4
5namespace N64
386{
39   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
40   UINT8 *hb = &hidden_bits[fb_address >> 1];
41#if (defined(ZCOMPARE) || defined(ZUPDATE))
42   UINT16 *zb = (UINT16*)&rdram[zb_address / 4];
43   UINT8 *zhb = &hidden_bits[zb_address >> 1];
44#endif
457
46   UINT32 tilenum = rect->tilenum;
47   TILE *tex_tile = &tile[rect->tilenum];
8namespace RDP
9{
4810
49   int x1 = rect->xh;
50   int x2 = rect->xl;
51   int y1 = rect->yh;
52   int y2 = rect->yl;
11#define LookUpCC(A, B, C, D) m_rdp->GetCCLUT2()[(m_rdp->GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
5312
13void TexRectangle::SetMachine(running_machine* machine)
14{
15   _n64_state *state = (_n64_state *)machine->driver_data;
16
17   m_machine = machine;
18   m_rdp = &state->m_rdp;
19   m_other_modes = m_rdp->GetOtherModes();
20   m_misc_state = m_rdp->GetMiscState();
21}
22
23void TexRectangle::Draw()
24{
25   switch(m_other_modes->cycle_type)
26   {
27      case CYCLE_TYPE_1:
28      case CYCLE_TYPE_2:
29         DrawDefault();
30         return;
31
32      case CYCLE_TYPE_COPY:
33         DrawCopy();
34         return;
35
36      default:
37         fatalerror("Unsupported cycle type for Textured Rectangle: %d\n", m_other_modes->cycle_type);
38         return;
39   }
40}
41
42void TexRectangle::DrawDefault()
43{
44   UINT16 *fb = (UINT16*)&rdram[(m_misc_state->m_fb_address / 4)];
45   UINT8 *hb = &m_rdp->GetHiddenBits()[m_misc_state->m_fb_address >> 1];
46   UINT16 *zb = (UINT16*)&rdram[m_misc_state->m_zb_address / 4];
47   UINT8 *zhb = &m_rdp->GetHiddenBits()[m_misc_state->m_zb_address >> 1];
48
49   UINT32 tilenum = m_tilenum;
50   N64::RDP::Tile *tex_tile = &m_rdp->GetTiles()[m_tilenum];
51   UINT32 tilenum2 = 0;
52   N64::RDP::Tile *tex_tile2 = NULL;
53
54   int x1 = m_xh;
55   int x2 = m_xl;
56   int y1 = m_yh;
57   int y2 = m_yl;
58
5459   if (x2 <= x1)
5560   {
5661      x2 = x1 + 1;
r7675r7676
6065      y2 = y1 + 1; // Needed by Goldeneye
6166   }
6267
63   if ((rect->xl & 3) == 3) // Needed by Mega Man 64
68   if ((m_xl & 3) == 3) // Needed by Mega Man 64
6469   {
6570      x2++;
6671   }
67   if ((rect->yl & 3) == 3)
72   if ((m_yl & 3) == 3)
6873   {
6974      y2++;
7075   }
7176
72   calculate_clamp_diffs(tilenum);
77   m_rdp->GetTexPipe()->CalculateClampDiffs(tilenum);
7378
74   shade_color.c = 0;   // Needed by Pilotwings 64
79   if(m_other_modes->cycle_type == CYCLE_TYPE_2)
80   {
81      if (!m_other_modes->tex_lod_en)
82      {
83         tilenum2 = (tilenum + 1) & 7;
84         tex_tile2 = &m_rdp->GetTiles()[tilenum2];
85      }
86      else
87      {
88         tilenum2 = (tilenum + 1) & 7;
89         tex_tile2 = &m_rdp->GetTiles()[tilenum2];
90      }
91   }
7592
76   CACHE_TEXTURE_PARAMS(tex_tile);
93   m_rdp->GetShadeColor()->c = 0;   // Needed by Pilotwings 64
7794
78   if(y1 < clip.yh)
95   if(y1 < m_rdp->GetScissor()->m_yh)
7996   {
80      rect->t += rect->dtdy * (clip.yh - y1);
81      y1 = clip.yh;
97      m_t += m_dtdy * (m_rdp->GetScissor()->m_yh - y1);
98      y1 = m_rdp->GetScissor()->m_yh;
8299   }
83   if(y2 > clip.yl)
100   if(y2 > m_rdp->GetScissor()->m_yl)
84101   {
85      y2 = clip.yl;
102      y2 = m_rdp->GetScissor()->m_yl;
86103   }
87   if(x1 < clip.xh)
104   if(x1 < m_rdp->GetScissor()->m_xh)
88105   {
89      rect->s += rect->dsdx * (clip.xh - x1);
90      x1 = clip.xh;
106      m_s += m_dsdx * (m_rdp->GetScissor()->m_xh - x1);
107      x1 = m_rdp->GetScissor()->m_xh;
91108   }
92   if(x2 > clip.xl)
109   if(x2 > m_rdp->GetScissor()->m_xl)
93110   {
94      x2 = clip.xl;
111      x2 = m_rdp->GetScissor()->m_xl;
95112   }
96   rect->dsdx >>= 5;
97   rect->dtdy >>= 5;
113   m_dsdx >>= 5;
114   m_dtdy >>= 5;
98115
99   int t = ((int)(rect->t));
116   int t = ((int)(m_t));
100117
101   if(rect->flip)
118   if(m_flip)
102119   {
103120      for (int j = y1; j < y2; j++)
104121      {
105         int fb_index = j * fb_width;
106#if defined(MAGICDITHER) || defined(BAYERDITHER)
107         int mline = (j & 3) << 2;
108#endif
109         int s = ((int)(rect->s));
122         int fb_index = j * m_misc_state->m_fb_width;
123         int mline = 0;
124         if(!(m_other_modes->rgb_dither_sel & 2))
125         {
126            mline = (j & 3) << 2;
127         }
128         int s = ((int)(m_s));
110129
111130         for (int i = x1; i < x2; i++)
112131         {
113            COLOR c;
114#if defined(ZUPDATE)
115            int rendered = 0;
116#endif
117#if defined(MAGICDITHER) || defined(BAYERDITHER)
132            N64::RDP::Color c1;
133            N64::RDP::Color c2;
118134            int dith = 0;
119#endif
120
121135            int curpixel = fb_index + i;
122136            UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
123137            UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
124#if (defined(ZCOMPARE) || defined(ZUPDATE))
125138            UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
126139            UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
127#endif
128            curpixel_cvg = 8;
129140
130            texel0_color.c = TEXTURE_PIPELINE(t, s, tex_tile);
141            m_misc_state->m_curpixel_cvg = 8;
131142
132            COLOR_COMBINER1(c);
143            if(m_other_modes->cycle_type == CYCLE_TYPE_1)
144            {
145               m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(t, s, tex_tile);
133146
134#if defined(MAGICDITHER)
135            dith = magic_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
136#elif defined(BAYERDITHER)
137            dith = bayer_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
138#endif
147               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
148                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
149                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
150                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
151               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
152                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
153                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
154                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
155               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
156                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
157                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
158                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
159               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
160                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
161                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
162                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
163               m_rdp->GetAlphaCvg(&c1.i.a);
164            }
165            else
166            {
167               m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(t, s, tex_tile);
168               m_rdp->GetTexel1Color()->c = m_rdp->GetTexPipe()->Fetch(t, s, tex_tile2);
139169
140#if defined(ZCOMPARE)
141            if (z_compare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)primitive_z)<<3,primitive_delta_z))
170               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
171                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
172                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
173                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
174               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
175                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
176                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
177                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
178               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
179                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
180                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
181                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
182               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
183                             *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
184                             *m_rdp->GetColorInputs()->combiner_alphamul[0],
185                             *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
186               m_rdp->GetCombinedColor()->c = c1.c;
187               c2.c = m_rdp->GetTexel0Color()->c;
188               m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
189               m_rdp->GetTexel1Color()->c = c2.c;
190               c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
191                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
192                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
193                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
194               c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
195                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
196                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
197                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
198               c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
199                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
200                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
201                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
202               c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
203                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
204                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
205                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
206               m_rdp->GetAlphaCvg(&c2.i.a);
207            }
208
209            if(m_other_modes->rgb_dither_sel == 0)
142210            {
143#endif
144#if defined(MAGICDITHER) || defined(BAYERDITHER)
145#if defined(ZUPDATE)
146               rendered = BLENDER1_16_DITH(fbcur, hbcur, c, dith);
147#else
148               BLENDER1_16_DITH(fbcur, hbcur, c, dith);
149#endif
150#else
151#if defined(ZUPDATE)
152               rendered = BLENDER1_16_NDITH(fbcur, hbcur, c);
153#else
154               BLENDER1_16_NDITH(fbcur, hbcur, c);
155#endif
156#endif
157#if defined(ZCOMPARE)
211               dith = m_rdp->GetMagicMatrix()[mline + ((i ^ WORD_ADDR_XOR) & 3)];
158212            }
159#endif
213            else if(m_other_modes->rgb_dither_sel == 1)
214            {
215               dith = m_rdp->GetBayerMatrix()[mline + ((i ^ WORD_ADDR_XOR) & 3)];
216            }
160217
161#if defined(ZUPDATE)
162            if(rendered)
218            bool z_compare_result = true;
219            if(m_other_modes->z_compare_en)
163220            {
164               z_store(zbcur, zhbcur, ((UINT32)primitive_z) << 3,primitive_delta_z);
221               z_compare_result = m_rdp->ZCompare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)m_misc_state->m_primitive_z)<<3, m_misc_state->m_primitive_delta_z);
165222            }
166#endif
167223
224            if(z_compare_result)
225            {
226               bool rendered = m_rdp->GetBlender()->Blend(fbcur, hbcur, c1, c2, dith);
168227
169            s += (int)(rect->dsdx);
228               if(m_other_modes->z_update_en && rendered)
229               {
230                  m_rdp->ZStore(zbcur, zhbcur, ((UINT32)m_misc_state->m_primitive_z) << 3, m_misc_state->m_primitive_delta_z);
231               }
232            }
233
234            s += (int)(m_dsdx);
170235         }
171         t += (int)(rect->dtdy);
236         t += (int)(m_dtdy);
172237      }
173238   }
174239   else
175240   {
176241      for (int j = y1; j < y2; j++)
177242      {
178         int fb_index = j * fb_width;
179#if defined(MAGICDITHER) || defined(BAYERDITHER)
180         int mline = (j & 3) << 2;
181#endif
243         int fb_index = j * m_misc_state->m_fb_width;
244         int mline = 0;
245         if(!(m_other_modes->rgb_dither_sel & 2))
246         {
247            mline = (j & 3) << 2;
248         }
182249
183         int s = ((int)(rect->s));
250         int s = ((int)(m_s));
184251
185252         for (int i = x1; i < x2; i++)
186253         {
187            COLOR c;
188#if defined(ZUPDATE)
189            int rendered = 0;
190#endif
191#if defined(MAGICDITHER) || defined(BAYERDITHER)
254            N64::RDP::Color c1;
255            N64::RDP::Color c2;
192256            int dith = 0;
193#endif
194257            int curpixel = fb_index + i;
195258            UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
196259            UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
197#if (defined(ZCOMPARE) || defined(ZUPDATE))
198260            UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
199261            UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
200#endif
201            curpixel_cvg = 8;
202262
203            texel0_color.c = TEXTURE_PIPELINE(s, t, tex_tile);
263            m_misc_state->m_curpixel_cvg = 8;
204264
205            COLOR_COMBINER1(c);
265            if(m_other_modes->cycle_type == CYCLE_TYPE_1)
266            {
267               m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(s, t, tex_tile);
206268
207#if defined(MAGICDITHER)
208            dith = magic_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
209#elif defined(BAYERDITHER)
210            dith = bayer_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
211#endif
212
213#if defined(ZCOMPARE)
214            if (z_compare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)primitive_z)<<3,primitive_delta_z))
269               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
270                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
271                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
272                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
273               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
274                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
275                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
276                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
277               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
278                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
279                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
280                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
281               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
282                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
283                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
284                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
285               m_rdp->GetAlphaCvg(&c1.i.a);
286            }
287            else
215288            {
216#endif
217#if defined(MAGICDITHER) || defined(BAYERDITHER)
218#if defined(ZUPDATE)
219               rendered = BLENDER1_16_DITH(fbcur, hbcur, c, dith);
220#else
221               BLENDER1_16_DITH(fbcur, hbcur, c, dith);
222#endif
223#else
224#if defined(ZUPDATE)
225               rendered = BLENDER1_16_NDITH(fbcur, hbcur, c);
226#else
227               BLENDER1_16_NDITH(fbcur, hbcur, c);
228#endif
229#endif
230#if defined(ZCOMPARE)
289               m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(s, t, tex_tile);
290               m_rdp->GetTexel1Color()->c = m_rdp->GetTexPipe()->Fetch(s, t, tex_tile2);
291
292               c1.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[0],
293                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[0],
294                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[0],
295                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[0]);
296               c1.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[0],
297                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[0],
298                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[0],
299                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[0]);
300               c1.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[0],
301                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[0],
302                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[0],
303                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[0]);
304               c1.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[0],
305                             *m_rdp->GetColorInputs()->combiner_alphasub_b[0],
306                             *m_rdp->GetColorInputs()->combiner_alphamul[0],
307                             *m_rdp->GetColorInputs()->combiner_alphaadd[0]);
308               m_rdp->GetCombinedColor()->c = c1.c;
309               c2.c = m_rdp->GetTexel0Color()->c;
310               m_rdp->GetTexel0Color()->c = m_rdp->GetTexel1Color()->c;
311               m_rdp->GetTexel1Color()->c = c2.c;
312               c2.i.r = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_r[1],
313                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_r[1],
314                             *m_rdp->GetColorInputs()->combiner_rgbmul_r[1],
315                             *m_rdp->GetColorInputs()->combiner_rgbadd_r[1]);
316               c2.i.g = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_g[1],
317                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_g[1],
318                             *m_rdp->GetColorInputs()->combiner_rgbmul_g[1],
319                             *m_rdp->GetColorInputs()->combiner_rgbadd_g[1]);
320               c2.i.b = LookUpCC(*m_rdp->GetColorInputs()->combiner_rgbsub_a_b[1],
321                             *m_rdp->GetColorInputs()->combiner_rgbsub_b_b[1],
322                             *m_rdp->GetColorInputs()->combiner_rgbmul_b[1],
323                             *m_rdp->GetColorInputs()->combiner_rgbadd_b[1]);
324               c2.i.a = LookUpCC(*m_rdp->GetColorInputs()->combiner_alphasub_a[1],
325                             *m_rdp->GetColorInputs()->combiner_alphasub_b[1],
326                             *m_rdp->GetColorInputs()->combiner_alphamul[1],
327                             *m_rdp->GetColorInputs()->combiner_alphaadd[1]);
328               m_rdp->GetAlphaCvg(&c2.i.a);
231329            }
232#endif
233330
234#if defined(ZUPDATE)
235            if(rendered)
331            if(m_other_modes->rgb_dither_sel == 0)
236332            {
237               z_store(zbcur, zhbcur, ((UINT32)primitive_z) << 3,primitive_delta_z);
333               dith = m_rdp->GetMagicMatrix()[mline + ((i ^ WORD_ADDR_XOR) & 3)];
238334            }
239#endif
240
241
242            fbcur++;
243            hbcur++;
244#if (defined(ZCOMPARE) || defined(ZUPDATE))
245            zbcur++;
246            zhbcur++;
247#endif
248            s += (int)(rect->dsdx);
249         }
250         t += (int)(rect->dtdy);
251      }
252   }
253}
254
255#if defined(ZCOMPARE)
256   #if defined(ZUPDATE)
257      #if defined(MAGICDITHER)
258         static void texture_rectangle_16bit_c2_zc_zu_dm(TEX_RECTANGLE *rect)
259      #elif defined(BAYERDITHER)
260         static void texture_rectangle_16bit_c2_zc_zu_db(TEX_RECTANGLE *rect)
261      #else
262         static void texture_rectangle_16bit_c2_zc_zu_dn(TEX_RECTANGLE *rect)
263      #endif
264   #else
265      #if defined(MAGICDITHER)
266         static void texture_rectangle_16bit_c2_zc_nzu_dm(TEX_RECTANGLE *rect)
267      #elif defined(BAYERDITHER)
268         static void texture_rectangle_16bit_c2_zc_nzu_db(TEX_RECTANGLE *rect)
269      #else
270         static void texture_rectangle_16bit_c2_zc_nzu_dn(TEX_RECTANGLE *rect)
271      #endif
272   #endif
273#else
274   #if defined(ZUPDATE)
275      #if defined(MAGICDITHER)
276         static void texture_rectangle_16bit_c2_nzc_zu_dm(TEX_RECTANGLE *rect)
277      #elif defined(BAYERDITHER)
278         static void texture_rectangle_16bit_c2_nzc_zu_db(TEX_RECTANGLE *rect)
279      #else
280         static void texture_rectangle_16bit_c2_nzc_zu_dn(TEX_RECTANGLE *rect)
281      #endif
282   #else
283      #if defined(MAGICDITHER)
284         static void texture_rectangle_16bit_c2_nzc_nzu_dm(TEX_RECTANGLE *rect)
285      #elif defined(BAYERDITHER)
286         static void texture_rectangle_16bit_c2_nzc_nzu_db(TEX_RECTANGLE *rect)
287      #else
288         static void texture_rectangle_16bit_c2_nzc_nzu_dn(TEX_RECTANGLE *rect)
289      #endif
290   #endif
291#endif
292{
293   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
294   UINT8 *hb = &hidden_bits[fb_address >> 1];
295#if (defined(ZCOMPARE) || defined(ZUPDATE))
296   UINT16 *zb = (UINT16*)&rdram[zb_address / 4];
297   UINT8 *zhb = &hidden_bits[zb_address >> 1];
298#endif
299
300   UINT32 tilenum = rect->tilenum;
301   UINT32 tilenum2 = 0;
302   TILE *tex_tile = &tile[rect->tilenum];
303   TILE *tex_tile2 = NULL;
304
305   int x1 = rect->xh;
306   int x2 = rect->xl;
307   int y1 = rect->yh;
308   int y2 = rect->yl;
309
310   if (x2 <= x1)
311   {
312      x2 = x1 + 1;
313   }
314   if (y1 == y2)
315   {
316      y2 = y1 + 1; // Needed by Goldeneye
317   }
318
319   if ((rect->xl & 3) == 3) // Needed by Mega Man 64
320   {
321      x2++;
322   }
323   if ((rect->yl & 3) == 3)
324   {
325      y2++;
326   }
327
328   calculate_clamp_diffs(tilenum);
329
330   if (!other_modes.tex_lod_en)
331   {
332      tilenum2 = (tilenum + 1) & 7;
333      tex_tile2 = &tile[tilenum2];
334   }
335   else
336   {
337      tilenum2 = (tilenum + 1) & 7;
338      tex_tile2 = &tile[tilenum2];
339   }
340
341   shade_color.c = 0;   // Needed by Pilotwings 64
342
343   if(y1 < clip.yh)
344   {
345      rect->t += rect->dtdy * (clip.yh - y1);
346      y1 = clip.yh;
347   }
348   if(y2 > clip.yl)
349   {
350      y2 = clip.yl;
351   }
352   if(x1 < clip.xh)
353   {
354      rect->s += rect->dsdx * (clip.xh - x1);
355      x1 = clip.xh;
356   }
357   if(x2 > clip.xl)
358   {
359      x2 = clip.xl;
360   }
361   rect->dsdx >>= 5;
362   rect->dtdy >>= 5;
363
364   int t = ((int)(rect->t));
365
366   if(rect->flip)
367   {
368      for (int j = y1; j < y2; j++)
369      {
370         {
371            int fb_index = j * fb_width;
372#if defined(MAGICDITHER) || defined(BAYERDITHER)
373            int mline = (j & 3) << 2;
374#endif
375            int s = (int)(rect->s);
376
377            for (int i = x1; i < x2; i++)
335            else if(m_other_modes->rgb_dither_sel == 1)
378336            {
379               {
380                  COLOR c1, c2;
381#if defined(ZUPDATE)
382                  int rendered=0;
383#endif
384                  int curpixel = fb_index + i;
385                  UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
386                  UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
387#if (defined(ZCOMPARE) || defined(ZUPDATE))
388                  UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
389                  UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
390#endif
391#if defined(MAGICDITHER) || defined(BAYERDITHER)
392                  int dith = 0;
393#endif
337               dith = m_rdp->GetBayerMatrix()[mline + ((i ^ WORD_ADDR_XOR) & 3)];
338            }
394339
395                  curpixel_cvg = 8;
396
397                  CACHE_TEXTURE_PARAMS(tex_tile);
398                  texel0_color.c = TEXTURE_PIPELINE(t, s, tex_tile);
399
400                  CACHE_TEXTURE_PARAMS(tex_tile2);
401                  texel1_color.c = TEXTURE_PIPELINE(t, s, tex_tile2);
402
403                  COLOR_COMBINER2_C0(c1);
404                  COLOR_COMBINER2_C1(c2);
405
406#if defined(MAGICDITHER)
407                  dith = magic_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
408#elif defined(BAYERDITHER)
409                  dith = bayer_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
410#endif
411
412#if defined(ZCOMPARE)
413                  if (z_compare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)primitive_z)<<3,primitive_delta_z))
414                  {
415#endif
416#if defined(MAGICDITHER) || defined(BAYERDITHER)
417#if defined(ZUPDATE)
418                     rendered = BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
419#else
420                     BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
421#endif
422#else
423#if defined(ZUPDATE)
424                     rendered = BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
425#else
426                     BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
427#endif
428#endif
429#if defined(ZCOMPARE)
430                  }
431#endif
432
433#if defined(ZUPDATE)
434                  if(rendered)
435                  {
436                     z_store(zbcur, zhbcur, ((UINT32)primitive_z) << 3,primitive_delta_z);
437                  }
438#endif
439               }
440
441               s += (rect->dsdx);
340            bool z_compare_result = true;
341            if(m_other_modes->z_compare_en)
342            {
343               z_compare_result = m_rdp->ZCompare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)m_misc_state->m_primitive_z)<<3, m_misc_state->m_primitive_delta_z);
442344            }
443         }
444         t += (rect->dtdy);
445      }
446   }
447   else
448   {
449      for (int j = y1; j < y2; j++)
450      {
451         {
452            int fb_index = j * fb_width;
453#if defined(MAGICDITHER) || defined(BAYERDITHER)
454            int mline = (j & 3) << 2;
455#endif
456            int s = (int)(rect->s);
457345
458            for (int i = x1; i < x2; i++)
346            if(z_compare_result)
459347            {
460               {
461                  COLOR c1, c2;
462#if defined(ZUPDATE)
463                  int rendered=0;
464#endif
465                  int curpixel = fb_index + i;
466                  UINT16* fbcur = &fb[curpixel ^ WORD_ADDR_XOR];
467                  UINT8* hbcur = &hb[curpixel ^ BYTE_ADDR_XOR];
468#if (defined(ZCOMPARE) || defined(ZUPDATE))
469                  UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
470                  UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
471#endif
472#if defined(MAGICDITHER) || defined(BAYERDITHER)
473                  int dith = 0;
474#endif
348               bool rendered = m_rdp->GetBlender()->Blend(fbcur, hbcur, c1, c2, dith);
475349
476                  curpixel_cvg = 8;
477
478                  CACHE_TEXTURE_PARAMS(tex_tile);
479                  texel0_color.c = TEXTURE_PIPELINE(s, t, tex_tile);
480
481                  CACHE_TEXTURE_PARAMS(tex_tile2);
482                  texel1_color.c = TEXTURE_PIPELINE(s, t, tex_tile2);
483
484                  COLOR_COMBINER2_C0(c1);
485                  COLOR_COMBINER2_C1(c2);
486
487#if defined(MAGICDITHER)
488                  dith = magic_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
489#elif defined(BAYERDITHER)
490                  dith = bayer_matrix[mline + ((i ^ WORD_ADDR_XOR) & 3)];
491#endif
492
493#if defined(ZCOMPARE)
494                  if (z_compare(fbcur, hbcur, zbcur, zhbcur, ((UINT32)primitive_z)<<3,primitive_delta_z))
495                  {
496#endif
497#if defined(MAGICDITHER) || defined(BAYERDITHER)
498#if defined(ZUPDATE)
499                     rendered = BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
500#else
501                     BLENDER2_16_DITH(fbcur, hbcur, c1, c2, dith);
502#endif
503#else
504#if defined(ZUPDATE)
505                     rendered = BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
506#else
507                     BLENDER2_16_NDITH(fbcur, hbcur, c1, c2);
508#endif
509#endif
510#if defined(ZCOMPARE)
511                  }
512#endif
513
514#if defined(ZUPDATE)
515                  if(rendered)
516                  {
517                     z_store(zbcur, zhbcur, ((UINT32)primitive_z) << 3,primitive_delta_z);
518                  }
519#endif
350               if(m_other_modes->z_update_en && rendered)
351               {
352                  m_rdp->ZStore(zbcur, zhbcur, ((UINT32)m_misc_state->m_primitive_z) << 3, m_misc_state->m_primitive_delta_z);
520353               }
521
522               s += (rect->dsdx);
523354            }
355
356            s += (int)(m_dsdx);
524357         }
525         t += (rect->dtdy);
358         t += (int)(m_dtdy);
526359      }
527360   }
528361}
529362
530#if defined(ZCOMPARE)
531   #if defined(ZUPDATE)
532      #if defined(MAGICDITHER)
533         static void texture_rectangle_16bit_cc_zc_zu_dm(TEX_RECTANGLE *rect)
534      #elif defined(BAYERDITHER)
535         static void texture_rectangle_16bit_cc_zc_zu_db(TEX_RECTANGLE *rect)
536      #else
537         static void texture_rectangle_16bit_cc_zc_zu_dn(TEX_RECTANGLE *rect)
538      #endif
539   #else
540      #if defined(MAGICDITHER)
541         static void texture_rectangle_16bit_cc_zc_nzu_dm(TEX_RECTANGLE *rect)
542      #elif defined(BAYERDITHER)
543         static void texture_rectangle_16bit_cc_zc_nzu_db(TEX_RECTANGLE *rect)
544      #else
545         static void texture_rectangle_16bit_cc_zc_nzu_dn(TEX_RECTANGLE *rect)
546      #endif
547   #endif
548#else
549   #if defined(ZUPDATE)
550      #if defined(MAGICDITHER)
551         static void texture_rectangle_16bit_cc_nzc_zu_dm(TEX_RECTANGLE *rect)
552      #elif defined(BAYERDITHER)
553         static void texture_rectangle_16bit_cc_nzc_zu_db(TEX_RECTANGLE *rect)
554      #else
555         static void texture_rectangle_16bit_cc_nzc_zu_dn(TEX_RECTANGLE *rect)
556      #endif
557   #else
558      #if defined(MAGICDITHER)
559         static void texture_rectangle_16bit_cc_nzc_nzu_dm(TEX_RECTANGLE *rect)
560      #elif defined(BAYERDITHER)
561         static void texture_rectangle_16bit_cc_nzc_nzu_db(TEX_RECTANGLE *rect)
562      #else
563         static void texture_rectangle_16bit_cc_nzc_nzu_dn(TEX_RECTANGLE *rect)
564      #endif
565   #endif
566#endif
363void TexRectangle::DrawCopy()
567364{
568   UINT16 *fb = (UINT16*)&rdram[(fb_address / 4)];
365   UINT16 *fb = (UINT16*)&rdram[(m_misc_state->m_fb_address / 4)];
569366
570   UINT32 tilenum = rect->tilenum;
571   TILE *tex_tile = &tile[rect->tilenum];
367   N64::RDP::Tile *tex_tile = &m_rdp->GetTiles()[m_tilenum];
572368
573   int x1 = rect->xh;
574   int x2 = rect->xl;
575   int y1 = rect->yh;
576   int y2 = rect->yl;
369   int x1 = m_xh;
370   int x2 = m_xl;
371   int y1 = m_yh;
372   int y2 = m_yl;
577373
578374   if (x2 <= x1)
579375   {
r7675r7676
584380      y2 = y1 + 1; // Needed by Goldeneye
585381   }
586382
587   rect->dsdx /= 4;
383   m_dsdx /= 4;
588384   x2 += 1;
589385   y2 += 1;
590386
591   calculate_clamp_diffs(tilenum);
387   m_rdp->GetShadeColor()->c = 0;   // Needed by Pilotwings 64
592388
593   shade_color.c = 0;   // Needed by Pilotwings 64
594
595   CACHE_TEXTURE_PARAMS(tex_tile);
596
597   if(y1 < clip.yh)
389   if(y1 < m_rdp->GetScissor()->m_yh)
598390   {
599      rect->t += rect->dtdy * (clip.yh - y1);
600      y1 = clip.yh;
391      m_t += m_dtdy * (m_rdp->GetScissor()->m_yh - y1);
392      y1 = m_rdp->GetScissor()->m_yh;
601393   }
602   if(y2 > clip.yl)
394   if(y2 > m_rdp->GetScissor()->m_yl)
603395   {
604      y2 = clip.yl;
396      y2 = m_rdp->GetScissor()->m_yl;
605397   }
606   if(x1 < clip.xh)
398   if(x1 < m_rdp->GetScissor()->m_xh)
607399   {
608      rect->s += rect->dsdx * (clip.xh - x1);
609      x1 = clip.xh;
400      m_s += m_dsdx * (m_rdp->GetScissor()->m_xh - x1);
401      x1 = m_rdp->GetScissor()->m_xh;
610402   }
611   if(x2 > clip.xl)
403   if(x2 > m_rdp->GetScissor()->m_xl)
612404   {
613      x2 = clip.xl;
405      x2 = m_rdp->GetScissor()->m_xl;
614406   }
615   rect->dsdx >>= 5;
616   rect->dtdy >>= 5;
407   m_dsdx >>= 5;
408   m_dtdy >>= 5;
617409
618   int t = ((int)(rect->t));
410   int t = (int)m_t;
619411
620   if(rect->flip)
412   if(m_flip)
621413   {
622414      for (int j = y1; j < y2; j++)
623415      {
624         int fb_index = j * fb_width;
416         int fb_index = j * m_misc_state->m_fb_width;
417         int s = (int)(m_s);
418
419         for (int i = x1; i < x2; i++)
625420         {
626            int s = (int)(rect->s);
421            m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(t, s, tex_tile);
627422
628            for (int i = x1; i < x2; i++)
629            {
630               {
631                  texel0_color.c = TEXTURE_PIPELINE(t, s, tex_tile);
423            m_misc_state->m_curpixel_cvg = 8;
632424
633                  curpixel_cvg = 8;
634
635                  if ((texel0_color.i.a != 0)||(!other_modes.alpha_compare_en))
636                  {
637                     fb[(fb_index + i) ^ WORD_ADDR_XOR] = ((texel0_color.i.r >> 3) << 11) | ((texel0_color.i.g >> 3) << 6) | ((texel0_color.i.b >> 3) << 1)|1;
638                  }
639               }
640               s += rect->dsdx;
425            if ((m_rdp->GetTexel0Color()->i.a != 0)||(!m_other_modes->alpha_compare_en))
426            {
427               fb[(fb_index + i) ^ WORD_ADDR_XOR] = ((m_rdp->GetTexel0Color()->i.r >> 3) << 11) | ((m_rdp->GetTexel0Color()->i.g >> 3) << 6) | ((m_rdp->GetTexel0Color()->i.b >> 3) << 1)|1;
641428            }
429            s += m_dsdx;
642430         }
643         t += rect->dtdy;
431         t += m_dtdy;
644432      }
645433   }
646434   else
647435   {
648436      for (int j = y1; j < y2; j++)
649437      {
650         int fb_index = j * fb_width;
438         int fb_index = j * m_misc_state->m_fb_width;
439         int s = (int)(m_s);
440
441         for (int i = x1; i < x2; i++)
651442         {
652            int s = (int)(rect->s);
443            m_rdp->GetTexel0Color()->c = m_rdp->GetTexPipe()->Fetch(s, t, tex_tile);
653444
654            for (int i = x1; i < x2; i++)
655            {
656               texel0_color.c = TEXTURE_PIPELINE(s, t, tex_tile);
445            m_misc_state->m_curpixel_cvg = 8;
657446
658               curpixel_cvg = 8;
659
660               if ((texel0_color.i.a != 0)||(!other_modes.alpha_compare_en))
661               {
662                  fb[(fb_index + i) ^ WORD_ADDR_XOR] = ((texel0_color.i.r >> 3) << 11) | ((texel0_color.i.g >> 3) << 6) | ((texel0_color.i.b >> 3) << 1)|1;
663               }
664               s += rect->dsdx;
447            if ((m_rdp->GetTexel0Color()->i.a != 0)||(!m_other_modes->alpha_compare_en))
448            {
449               fb[(fb_index + i) ^ WORD_ADDR_XOR] = ((m_rdp->GetTexel0Color()->i.r >> 3) << 11) | ((m_rdp->GetTexel0Color()->i.g >> 3) << 6) | ((m_rdp->GetTexel0Color()->i.b >> 3) << 1)|1;
665450            }
451            s += m_dsdx;
666452         }
667         t += rect->dtdy;
453         t += m_dtdy;
668454      }
669455   }
670456}
671457
672#if defined(ZCOMPARE)
673   #if defined(ZUPDATE)
674      #if defined(MAGICDITHER)
675         static void texture_rectangle_16bit_cf_zc_zu_dm(TEX_RECTANGLE *rect)
676      #elif defined(BAYERDITHER)
677         static void texture_rectangle_16bit_cf_zc_zu_db(TEX_RECTANGLE *rect)
678      #else
679         static void texture_rectangle_16bit_cf_zc_zu_dn(TEX_RECTANGLE *rect)
680      #endif
681   #else
682      #if defined(MAGICDITHER)
683         static void texture_rectangle_16bit_cf_zc_nzu_dm(TEX_RECTANGLE *rect)
684      #elif defined(BAYERDITHER)
685         static void texture_rectangle_16bit_cf_zc_nzu_db(TEX_RECTANGLE *rect)
686      #else
687         static void texture_rectangle_16bit_cf_zc_nzu_dn(TEX_RECTANGLE *rect)
688      #endif
689   #endif
690#else
691   #if defined(ZUPDATE)
692      #if defined(MAGICDITHER)
693         static void texture_rectangle_16bit_cf_nzc_zu_dm(TEX_RECTANGLE *rect)
694      #elif defined(BAYERDITHER)
695         static void texture_rectangle_16bit_cf_nzc_zu_db(TEX_RECTANGLE *rect)
696      #else
697         static void texture_rectangle_16bit_cf_nzc_zu_dn(TEX_RECTANGLE *rect)
698      #endif
699   #else
700      #if defined(MAGICDITHER)
701         static void texture_rectangle_16bit_cf_nzc_nzu_dm(TEX_RECTANGLE *rect)
702      #elif defined(BAYERDITHER)
703         static void texture_rectangle_16bit_cf_nzc_nzu_db(TEX_RECTANGLE *rect)
704      #else
705         static void texture_rectangle_16bit_cf_nzc_nzu_dn(TEX_RECTANGLE *rect)
706      #endif
707   #endif
708#endif
709{
710   fatalerror("texture_rectangle with FILL cycle type is not supported\n");
711}
458} // namespace RDP
459
460} // namespace N64
No newline at end of file
src/mame/video/rdptrect.h
r7675r7676
1static void texture_rectangle_16bit_c1_nzc_nzu_dm(TEX_RECTANGLE *rect);
2static void texture_rectangle_16bit_c1_nzc_nzu_db(TEX_RECTANGLE *rect);
3static void texture_rectangle_16bit_c1_nzc_nzu_dn(TEX_RECTANGLE *rect);
4static void texture_rectangle_16bit_c2_nzc_nzu_dm(TEX_RECTANGLE *rect);
5static void texture_rectangle_16bit_c2_nzc_nzu_db(TEX_RECTANGLE *rect);
6static void texture_rectangle_16bit_c2_nzc_nzu_dn(TEX_RECTANGLE *rect);
7static void texture_rectangle_16bit_cc_nzc_nzu_dm(TEX_RECTANGLE *rect);
8static void texture_rectangle_16bit_cc_nzc_nzu_db(TEX_RECTANGLE *rect);
9static void texture_rectangle_16bit_cc_nzc_nzu_dn(TEX_RECTANGLE *rect);
10static void texture_rectangle_16bit_cf_nzc_nzu_dm(TEX_RECTANGLE *rect);
11static void texture_rectangle_16bit_cf_nzc_nzu_db(TEX_RECTANGLE *rect);
12static void texture_rectangle_16bit_cf_nzc_nzu_dn(TEX_RECTANGLE *rect);
13static void texture_rectangle_16bit_c1_zc_nzu_dm(TEX_RECTANGLE *rect);
14static void texture_rectangle_16bit_c1_zc_nzu_db(TEX_RECTANGLE *rect);
15static void texture_rectangle_16bit_c1_zc_nzu_dn(TEX_RECTANGLE *rect);
16static void texture_rectangle_16bit_c2_zc_nzu_dm(TEX_RECTANGLE *rect);
17static void texture_rectangle_16bit_c2_zc_nzu_db(TEX_RECTANGLE *rect);
18static void texture_rectangle_16bit_c2_zc_nzu_dn(TEX_RECTANGLE *rect);
19static void texture_rectangle_16bit_cc_zc_nzu_dm(TEX_RECTANGLE *rect);
20static void texture_rectangle_16bit_cc_zc_nzu_db(TEX_RECTANGLE *rect);
21static void texture_rectangle_16bit_cc_zc_nzu_dn(TEX_RECTANGLE *rect);
22static void texture_rectangle_16bit_cf_zc_nzu_dm(TEX_RECTANGLE *rect);
23static void texture_rectangle_16bit_cf_zc_nzu_db(TEX_RECTANGLE *rect);
24static void texture_rectangle_16bit_cf_zc_nzu_dn(TEX_RECTANGLE *rect);
25static void texture_rectangle_16bit_c1_nzc_zu_dm(TEX_RECTANGLE *rect);
26static void texture_rectangle_16bit_c1_nzc_zu_db(TEX_RECTANGLE *rect);
27static void texture_rectangle_16bit_c1_nzc_zu_dn(TEX_RECTANGLE *rect);
28static void texture_rectangle_16bit_c2_nzc_zu_dm(TEX_RECTANGLE *rect);
29static void texture_rectangle_16bit_c2_nzc_zu_db(TEX_RECTANGLE *rect);
30static void texture_rectangle_16bit_c2_nzc_zu_dn(TEX_RECTANGLE *rect);
31static void texture_rectangle_16bit_cc_nzc_zu_dm(TEX_RECTANGLE *rect);
32static void texture_rectangle_16bit_cc_nzc_zu_db(TEX_RECTANGLE *rect);
33static void texture_rectangle_16bit_cc_nzc_zu_dn(TEX_RECTANGLE *rect);
34static void texture_rectangle_16bit_cf_nzc_zu_dm(TEX_RECTANGLE *rect);
35static void texture_rectangle_16bit_cf_nzc_zu_db(TEX_RECTANGLE *rect);
36static void texture_rectangle_16bit_cf_nzc_zu_dn(TEX_RECTANGLE *rect);
37static void texture_rectangle_16bit_c1_zc_zu_dm(TEX_RECTANGLE *rect);
38static void texture_rectangle_16bit_c1_zc_zu_db(TEX_RECTANGLE *rect);
39static void texture_rectangle_16bit_c1_zc_zu_dn(TEX_RECTANGLE *rect);
40static void texture_rectangle_16bit_c2_zc_zu_dm(TEX_RECTANGLE *rect);
41static void texture_rectangle_16bit_c2_zc_zu_db(TEX_RECTANGLE *rect);
42static void texture_rectangle_16bit_c2_zc_zu_dn(TEX_RECTANGLE *rect);
43static void texture_rectangle_16bit_cc_zc_zu_dm(TEX_RECTANGLE *rect);
44static void texture_rectangle_16bit_cc_zc_zu_db(TEX_RECTANGLE *rect);
45static void texture_rectangle_16bit_cc_zc_zu_dn(TEX_RECTANGLE *rect);
46static void texture_rectangle_16bit_cf_zc_zu_dm(TEX_RECTANGLE *rect);
47static void texture_rectangle_16bit_cf_zc_zu_db(TEX_RECTANGLE *rect);
48static void texture_rectangle_16bit_cf_zc_zu_dn(TEX_RECTANGLE *rect);
1#ifndef _VIDEO_RDPTEXRECT_H_
2#define _VIDEO_RDPTEXRECT_H_
493
50static void (*rdp_texture_rectangle_16bit_func[64])(TEX_RECTANGLE *) =
4#include "emu.h"
5
6namespace N64
517{
52   texture_rectangle_16bit_c1_nzc_nzu_dm, texture_rectangle_16bit_c1_nzc_nzu_db, texture_rectangle_16bit_c1_nzc_nzu_dn, texture_rectangle_16bit_c1_nzc_nzu_dn,
53   texture_rectangle_16bit_c2_nzc_nzu_dm, texture_rectangle_16bit_c2_nzc_nzu_db, texture_rectangle_16bit_c2_nzc_nzu_dn, texture_rectangle_16bit_c2_nzc_nzu_dn,
54   texture_rectangle_16bit_cc_nzc_nzu_dm, texture_rectangle_16bit_cc_nzc_nzu_db, texture_rectangle_16bit_cc_nzc_nzu_dn, texture_rectangle_16bit_cc_nzc_nzu_dn,
55   texture_rectangle_16bit_cf_nzc_nzu_dm, texture_rectangle_16bit_cf_nzc_nzu_db, texture_rectangle_16bit_cf_nzc_nzu_dn, texture_rectangle_16bit_cf_nzc_nzu_dn,
56   texture_rectangle_16bit_c1_zc_nzu_dm, texture_rectangle_16bit_c1_zc_nzu_db, texture_rectangle_16bit_c1_zc_nzu_dn, texture_rectangle_16bit_c1_zc_nzu_dn,
57   texture_rectangle_16bit_c2_zc_nzu_dm, texture_rectangle_16bit_c2_zc_nzu_db, texture_rectangle_16bit_c2_zc_nzu_dn, texture_rectangle_16bit_c2_zc_nzu_dn,
58   texture_rectangle_16bit_cc_zc_nzu_dm, texture_rectangle_16bit_cc_zc_nzu_db, texture_rectangle_16bit_cc_zc_nzu_dn, texture_rectangle_16bit_cc_zc_nzu_dn,
59   texture_rectangle_16bit_cf_zc_nzu_dm, texture_rectangle_16bit_cf_zc_nzu_db, texture_rectangle_16bit_cf_zc_nzu_dn, texture_rectangle_16bit_cf_zc_nzu_dn,
60   texture_rectangle_16bit_c1_nzc_zu_dm, texture_rectangle_16bit_c1_nzc_zu_db, texture_rectangle_16bit_c1_nzc_zu_dn, texture_rectangle_16bit_c1_nzc_zu_dn,
61   texture_rectangle_16bit_c2_nzc_zu_dm, texture_rectangle_16bit_c2_nzc_zu_db, texture_rectangle_16bit_c2_nzc_zu_dn, texture_rectangle_16bit_c2_nzc_zu_dn,
62   texture_rectangle_16bit_cc_nzc_zu_dm, texture_rectangle_16bit_cc_nzc_zu_db, texture_rectangle_16bit_cc_nzc_zu_dn, texture_rectangle_16bit_cc_nzc_zu_dn,
63   texture_rectangle_16bit_cf_nzc_zu_dm, texture_rectangle_16bit_cf_nzc_zu_db, texture_rectangle_16bit_cf_nzc_zu_dn, texture_rectangle_16bit_cf_nzc_zu_dn,
64   texture_rectangle_16bit_c1_zc_zu_dm, texture_rectangle_16bit_c1_zc_zu_db, texture_rectangle_16bit_c1_zc_zu_dn, texture_rectangle_16bit_c1_zc_zu_dn,
65   texture_rectangle_16bit_c2_zc_zu_dm, texture_rectangle_16bit_c2_zc_zu_db, texture_rectangle_16bit_c2_zc_zu_dn, texture_rectangle_16bit_c2_zc_zu_dn,
66   texture_rectangle_16bit_cc_zc_zu_dm, texture_rectangle_16bit_cc_zc_zu_db, texture_rectangle_16bit_cc_zc_zu_dn, texture_rectangle_16bit_cc_zc_zu_dn,
67   texture_rectangle_16bit_cf_zc_zu_dm, texture_rectangle_16bit_cf_zc_zu_db, texture_rectangle_16bit_cf_zc_zu_dn, texture_rectangle_16bit_cf_zc_zu_dn,
8
9namespace RDP
10{
11
12class OtherModes;
13class MiscState;
14class Processor;
15class Color;
16
17class TexRectangle
18{
19   public:
20      TexRectangle() {}
21      TexRectangle(running_machine *machine, UINT32 *data, int flip)
22      {
23         SetMachine(machine);
24         InitFromBuffer(data);
25         m_flip = flip;
26      }
27
28      void Draw();
29      void SetMachine(running_machine *machine);
30      void InitFromBuffer(UINT32 *data);
31
32      int m_tilenum;
33      UINT16 m_xl;   // 10.2 fixed-point
34      UINT16 m_yl;   // 10.2 fixed-point
35      UINT16 m_xh;   // 10.2 fixed-point
36      UINT16 m_yh;   // 10.2 fixed-point
37      INT16 m_s;      // 10.5 fixed-point
38      INT16 m_t;      // 10.5 fixed-point
39      INT16 m_dsdx;   // 5.10 fixed-point
40      INT16 m_dtdy;   // 5.10 fixed-point
41      int m_flip;
42
43   private:
44      void             DrawDefault();
45      void             DrawCopy();
46
47      running_machine*   m_machine;
48      Processor*         m_rdp;
49      MiscState*         m_misc_state;
50      OtherModes*         m_other_modes;
6851};
6952
53} // namespace RDP
54
55} // namespace N64
56
57#endif // _VIDEO_RDPTEXRECT_H_
src/mame/video/rdpfb.c
r7675r7676
1#if defined(COLOR_ON_CVG)
2   INLINE UINT32 FBWRITE_16_RDEN_CVGD0_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
3#else
4   INLINE UINT32 FBWRITE_16_RDEN_CVGD0_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
5#endif
1#include "emu.h"
2#include "includes/n64.h"
3#include "video/n64.h"
4
5namespace N64
66{
7#undef CVG_DRAW
8   UINT32 memory_cvg = ((*fb & 1) << 2) + (*hb & 3) + 1;
9#ifdef CVG_DRAW
10   int covdraw;
11   if (curpixel_cvg == 8)
12   {
13      covdraw=255;
14   }
15   else
16   {
17      covdraw = curpixel_cvg << 5;
18   }
19   r=covdraw; g=covdraw; b=covdraw;
20#endif
217
22   if (!other_modes.z_compare_en)
23   {
24      curpixel_overlap = 0;
25   }
26
27   UINT32 newcvg = curpixel_cvg + memory_cvg;
28   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
29
30   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
31
32   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
33   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
34
35   curpixel_cvg--;
36   newcvg--;
37   memory_cvg--;
38   clampcvg--;
39
40#if defined(COLOR_ON_CVG)
41   if (!wrapflag)
42   {
43      *fb &= 0xfffe;
44      *fb |= ((newcvg >> 2) & 1);
45      *hb = (newcvg & 3);
46      return 0;
47   }
48#endif
49
50   if (!other_modes.force_blend && !curpixel_overlap)
51   {
52      *fb = finalcolor|((curpixel_cvg >>2)&1);
53      *hb = (curpixel_cvg & 3);
54   }
55   else
56   {
57      *fb = finalcolor|((clampcvg>>2)&1);
58      *hb = (clampcvg&3);
59   }
60   return 1;
61}
62
63#if defined(COLOR_ON_CVG)
64   INLINE UINT32 FBWRITE_16_RDEN_CVGD1_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
65#else
66   INLINE UINT32 FBWRITE_16_RDEN_CVGD1_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
67#endif
8bool RDP::Framebuffer::Write(void *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
689{
69#undef CVG_DRAW
70   UINT32 memory_cvg = ((*fb & 1) << 2) + (*hb & 3) + 1;
71#ifdef CVG_DRAW
72   int covdraw;
73   if (curpixel_cvg == 8)
10   switch(m_misc_state->m_fb_size)
7411   {
75      covdraw=255;
76   }
77   else
78   {
79      covdraw = curpixel_cvg << 5;
80   }
81   r=covdraw; g=covdraw; b=covdraw;
82#endif
12      case PIXEL_SIZE_16BIT:
13         return Write16Bit((UINT16*)fb, hb, r, g, b);
8314
84   if (!other_modes.z_compare_en)
85   {
86      curpixel_overlap = 0;
87   }
15      case PIXEL_SIZE_32BIT:
16         return Write32Bit((UINT32*)fb, r, g, b);
8817
89   UINT32 newcvg = curpixel_cvg + memory_cvg;
90   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
91
92   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
93
94   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
95   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
96
97   curpixel_cvg--;
98   newcvg--;
99   memory_cvg--;
100   clampcvg--;
101
102#if defined(COLOR_ON_CVG)
103   if (!wrapflag)
104   {
105      *fb &= 0xfffe;
106      *fb |= ((newcvg >> 2) & 1);
107      *hb = (newcvg & 3);
108      return 0;
18      default:
19         fatalerror("Unsupported bit depth: %d\n", m_misc_state->m_fb_size);
20         break;
10921   }
110#endif
11122
112   *fb = finalcolor|((newcvg >> 2) & 1);
113   *hb = (newcvg & 3);
114   return 1;
23   return false;
11524}
11625
117#if defined(COLOR_ON_CVG)
118   INLINE UINT32 FBWRITE_16_RDEN_CVGD2_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
119#else
120   INLINE UINT32 FBWRITE_16_RDEN_CVGD2_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
121#endif
26bool RDP::Framebuffer::Write16Bit(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
12227{
12328#undef CVG_DRAW
124   UINT32 memory_cvg = ((*fb & 1) << 2) + (*hb & 3) + 1;
29//#define CVG_DRAW
12530#ifdef CVG_DRAW
12631   int covdraw;
127   if (curpixel_cvg == 8)
32   if (m_misc_state->m_curpixel_cvg == 8)
12833   {
129      covdraw=255;
34      covdraw = 255;
13035   }
13136   else
13237   {
133      covdraw = curpixel_cvg << 5;
38      covdraw = m_misc_state->m_curpixel_cvg << 5;
13439   }
135   r=covdraw; g=covdraw; b=covdraw;
40   r = covdraw;
41   g = covdraw;
42   b = covdraw;
13643#endif
13744
138   if (!other_modes.z_compare_en)
45   if (!m_other_modes->z_compare_en)
13946   {
140      curpixel_overlap = 0;
47      m_misc_state->m_curpixel_overlap = 0;
14148   }
14249
143   UINT32 newcvg = curpixel_cvg + memory_cvg;
144   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
145
146   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
147
148   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
149   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
150
151   curpixel_cvg--;
152   newcvg--;
153   memory_cvg--;
154   clampcvg--;
155
156#if defined(COLOR_ON_CVG)
157   if (!wrapflag)
50   UINT32 memory_cvg = 8;
51   if (m_other_modes->image_read_en)
15852   {
159      *fb &= 0xfffe;
160      *fb |= ((newcvg >> 2) & 1);
161      *hb = (newcvg & 3);
162      return 0;
53      memory_cvg = ((*fb & 1) << 2) + (*hb & 3) + 1;
16354   }
164#endif
16555
166   *fb = finalcolor|1;
167   *hb = 3;
168   return 1;
169}
56   UINT32 newcvg = m_misc_state->m_curpixel_cvg + memory_cvg;
57   bool wrapped = newcvg > 8;
17058
171#if defined(COLOR_ON_CVG)
172   INLINE UINT32 FBWRITE_16_RDEN_CVGD3_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
173#else
174   INLINE UINT32 FBWRITE_16_RDEN_CVGD3_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
175#endif
176{
177#undef CVG_DRAW
178   UINT32 memory_cvg = ((*fb & 1) << 2) + (*hb & 3) + 1;
179#ifdef CVG_DRAW
180   int covdraw;
181   if (curpixel_cvg == 8)
182   {
183      covdraw=255;
184   }
185   else
186   {
187      covdraw = curpixel_cvg << 5;
188   }
189   r=covdraw; g=covdraw; b=covdraw;
190#endif
191
192   if (!other_modes.z_compare_en)
193   {
194      curpixel_overlap = 0;
195   }
196
197   UINT32 newcvg = curpixel_cvg + memory_cvg;
198   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
199
20059   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
20160
202   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
203   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
61   UINT32 clamped_cvg = wrapped ? 8 : newcvg;
62   newcvg = wrapped ? (newcvg - 8) : newcvg;
20463
205   curpixel_cvg--;
64   m_misc_state->m_curpixel_cvg--;
20665   newcvg--;
20766   memory_cvg--;
208   clampcvg--;
67   clamped_cvg--;
20968
210#if defined(COLOR_ON_CVG)
211   if (!wrapflag)
69   if (m_other_modes->color_on_cvg && !wrapped)
21270   {
21371      *fb &= 0xfffe;
21472      *fb |= ((newcvg >> 2) & 1);
21573      *hb = (newcvg & 3);
216      return 0;
74      return false;
21775   }
218#endif
21976
220   *fb = finalcolor|((memory_cvg >> 2) & 1);
221   *hb = (memory_cvg & 3);
222   return 1;
223}
224
225#if defined(COLOR_ON_CVG)
226   INLINE UINT32 FBWRITE_16_RDNEN_CVGD0_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
227#else
228   INLINE UINT32 FBWRITE_16_RDNEN_CVGD0_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
229#endif
230{
231#undef CVG_DRAW
232#ifdef CVG_DRAW
233   int covdraw;
234   if (curpixel_cvg == 8)
77   switch(m_other_modes->cvg_dest)
23578   {
236      covdraw=255;
237   }
238   else
239   {
240      covdraw = curpixel_cvg << 5;
241   }
242   r=covdraw; g=covdraw; b=covdraw;
243#endif
79      case 0:
80         if (!m_other_modes->force_blend && !m_misc_state->m_curpixel_overlap)
81         {
82            *fb = finalcolor | ((m_misc_state->m_curpixel_cvg >> 2) & 1);
83            *hb = (m_misc_state->m_curpixel_cvg & 3);
84         }
85         else
86         {
87            *fb = finalcolor | ((clamped_cvg >> 2) & 1);
88            *hb = (clamped_cvg & 3);
89         }
90         break;
24491
245   if (!other_modes.z_compare_en)
246   {
247      curpixel_overlap = 0;
248   }
92      case 1:
93         *fb = finalcolor | ((newcvg >> 2) & 1);
94         *hb = (newcvg & 3);
95         break;
24996
250   UINT32 newcvg = curpixel_cvg + 8;
251   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
97      case 2:
98         *fb = finalcolor | 1;
99         *hb = 3;
100         break;
252101
253   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
254
255   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
256   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
257
258   curpixel_cvg--;
259   newcvg--;
260   clampcvg--;
261
262#if defined(COLOR_ON_CVG)
263   if (!wrapflag)
264   {
265      *fb &= 0xfffe;
266      *fb |= ((newcvg >> 2) & 1);
267      *hb = (newcvg & 3);
268      return 0;
102      case 3:
103         *fb = finalcolor | ((memory_cvg >> 2) & 1);
104         *hb = (memory_cvg & 3);
105         break;
269106   }
270#endif
271107
272   if (!other_modes.force_blend && !curpixel_overlap)
273   {
274      *fb = finalcolor|((curpixel_cvg >>2)&1);
275      *hb = (curpixel_cvg & 3);
276   }
277   else
278   {
279      *fb = finalcolor|((clampcvg>>2)&1);
280      *hb = (clampcvg&3);
281   }
282   return 1;
108   return true;
283109}
284110
285#if defined(COLOR_ON_CVG)
286   INLINE UINT32 FBWRITE_16_RDNEN_CVGD1_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
287#else
288   INLINE UINT32 FBWRITE_16_RDNEN_CVGD1_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
289#endif
111bool RDP::Framebuffer::Write32Bit(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
290112{
291#undef CVG_DRAW
292#ifdef CVG_DRAW
293   int covdraw;
294   if (curpixel_cvg == 8)
295   {
296      covdraw=255;
297   }
298   else
299   {
300      covdraw = curpixel_cvg << 5;
301   }
302   r=covdraw; g=covdraw; b=covdraw;
303#endif
113   UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);
114   UINT32 memory_alphachannel = *fb & 0xff;
304115
305   if (!other_modes.z_compare_en)
116   UINT32 memory_cvg = 8;
117   if (m_other_modes->image_read_en)
306118   {
307      curpixel_overlap = 0;
119      memory_cvg = ((*fb >>5) & 7) + 1;
308120   }
309121
310   UINT32 newcvg = curpixel_cvg + 8;
311   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
122   UINT32 newcvg = m_misc_state->m_curpixel_cvg + memory_cvg;
123   bool wrapped = (newcvg > 8);
124   UINT32 clamped_cvg = (wrapped > 8) ? 8 : newcvg;
125   newcvg = (wrapped) ? (newcvg - 8) : newcvg;
312126
313   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
314
315   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
316   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
317
318   curpixel_cvg--;
127   m_misc_state->m_curpixel_cvg--;
319128   newcvg--;
320   clampcvg--;
321
322#if defined(COLOR_ON_CVG)
323   if (!wrapflag)
324   {
325      *fb &= 0xfffe;
326      *fb |= ((newcvg >> 2) & 1);
327      *hb = (newcvg & 3);
328      return 0;
329   }
330#endif
331
332   *fb = finalcolor|1;
333   *hb = 3;
334   return 1;
335}
336
337#if defined(COLOR_ON_CVG)
338   INLINE UINT32 FBWRITE_16_RDNEN_CVGD2_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
339#else
340   INLINE UINT32 FBWRITE_16_RDNEN_CVGD2_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
341#endif
342{
343#undef CVG_DRAW
344#ifdef CVG_DRAW
345   int covdraw;
346   if (curpixel_cvg == 8)
347   {
348      covdraw=255;
349   }
350   else
351   {
352      covdraw = curpixel_cvg << 5;
353   }
354   r=covdraw; g=covdraw; b=covdraw;
355#endif
356
357   if (!other_modes.z_compare_en)
358   {
359      curpixel_overlap = 0;
360   }
361
362   UINT32 newcvg = curpixel_cvg + 8;
363   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
364
365   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
366
367   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
368   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
369
370   curpixel_cvg--;
371   newcvg--;
372   clampcvg--;
373
374#if defined(COLOR_ON_CVG)
375   if (!wrapflag)
376   {
377      *fb &= 0xfffe;
378      *fb |= ((newcvg >> 2) & 1);
379      *hb = (newcvg & 3);
380      return 0;
381   }
382#endif
383
384   *fb = finalcolor|1;
385   *hb = 3;
386   return 1;
387}
388
389#if defined(COLOR_ON_CVG)
390   INLINE UINT32 FBWRITE_16_RDNEN_CVGD3_COC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
391#else
392   INLINE UINT32 FBWRITE_16_RDNEN_CVGD3_NCOC(UINT16 *fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b)
393#endif
394{
395#undef CVG_DRAW
396#ifdef CVG_DRAW
397   int covdraw;
398   if (curpixel_cvg == 8)
399   {
400      covdraw=255;
401   }
402   else
403   {
404      covdraw = curpixel_cvg << 5;
405   }
406   r=covdraw; g=covdraw; b=covdraw;
407#endif
408
409   if (!other_modes.z_compare_en)
410   {
411      curpixel_overlap = 0;
412   }
413
414   UINT32 newcvg = curpixel_cvg + 8;
415   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
416
417   UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
418
419   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
420   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
421
422   curpixel_cvg--;
423   newcvg--;
424   clampcvg--;
425
426#if defined(COLOR_ON_CVG)
427   if (!wrapflag)
428   {
429      *fb &= 0xfffe;
430      *fb |= ((newcvg >> 2) & 1);
431      *hb = (newcvg & 3);
432      return 0;
433   }
434#endif
435
436   *fb = finalcolor|1;
437   *hb = 4;
438   return 1;
439}
440
441#if defined(COLOR_ON_CVG)
442   INLINE UINT32 FBWRITE_32_RDEN_CVGD0_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
443#else
444   INLINE UINT32 FBWRITE_32_RDEN_CVGD0_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
445#endif
446{
447   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
448   UINT32 memory_cvg = ((*fb >>5) & 7) + 1;
449
450   UINT32 newcvg = curpixel_cvg + memory_cvg;
451   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
452   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
453   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
454
455   curpixel_cvg--;
456   newcvg--;
457129   memory_cvg--;
458   clampcvg--;
130   clamped_cvg--;
459131
460#if defined(COLOR_ON_CVG)
461   if (!wrapflag)
132   if (m_other_modes->color_on_cvg && !wrapped)
462133   {
463134      *fb &= 0xffffff00;
464135      *fb |= ((newcvg << 5) & 0xff);
465136      return 0;
466137   }
467#endif
468138
469   if (!other_modes.force_blend && !curpixel_overlap)
139   switch(m_other_modes->cvg_dest)
470140   {
471      *fb = finalcolor|(curpixel_cvg << 5);
141      case 0:
142         if (!m_other_modes->force_blend && !m_misc_state->m_curpixel_overlap)
143         {
144            *fb = finalcolor|(m_misc_state->m_curpixel_cvg << 5);
145         }
146         else
147         {
148            *fb = finalcolor|(clamped_cvg << 5);
149         }
150         break;
151      case 1:
152         *fb = finalcolor | (newcvg << 5);
153         break;
154      case 2:
155         *fb = finalcolor | 0xE0;
156         break;
157      case 3:
158         *fb = finalcolor | memory_alphachannel;
159         break;
472160   }
473   else
474   {
475      *fb = finalcolor|(clampcvg << 5);
476   }
477   return 1;
478}
479161
480#if defined(COLOR_ON_CVG)
481   INLINE UINT32 FBWRITE_32_RDEN_CVGD1_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
482#else
483   INLINE UINT32 FBWRITE_32_RDEN_CVGD1_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
484#endif
485{
486   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
487   UINT32 memory_cvg = ((*fb >>5) & 7) + 1;
488
489   UINT32 newcvg = curpixel_cvg + memory_cvg;
490   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
491   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
492   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
493
494   curpixel_cvg--;
495   newcvg--;
496   memory_cvg--;
497   clampcvg--;
498
499#if defined(COLOR_ON_CVG)
500   if (!wrapflag)
501   {
502      *fb &= 0xffffff00;
503      *fb |= ((newcvg << 5) & 0xff);
504      return 0;
505   }
506#endif
507
508   *fb = finalcolor | (newcvg << 5);
509   return 1;
162   return true;
510163}
511164
512#if defined(COLOR_ON_CVG)
513   INLINE UINT32 FBWRITE_32_RDEN_CVGD2_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
514#else
515   INLINE UINT32 FBWRITE_32_RDEN_CVGD2_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
516#endif
517{
518   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
519   UINT32 memory_cvg = ((*fb >>5) & 7) + 1;
520
521   UINT32 newcvg = curpixel_cvg + memory_cvg;
522   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
523   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
524   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
525
526   curpixel_cvg--;
527   newcvg--;
528   memory_cvg--;
529   clampcvg--;
530
531#if defined(COLOR_ON_CVG)
532   if (!wrapflag)
533   {
534      *fb &= 0xffffff00;
535      *fb |= ((newcvg << 5) & 0xff);
536      return 0;
537   }
538#endif
539
540   *fb = finalcolor | 0xE0;
541   return 1;
542}
543
544#if defined(COLOR_ON_CVG)
545   INLINE UINT32 FBWRITE_32_RDEN_CVGD3_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
546#else
547   INLINE UINT32 FBWRITE_32_RDEN_CVGD3_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
548#endif
549{
550   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
551   UINT32 memory_alphachannel = *fb & 0xff;
552   UINT32 memory_cvg = ((*fb >>5) & 7) + 1;
553
554   UINT32 newcvg = curpixel_cvg + memory_cvg;
555   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
556   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
557   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
558
559   curpixel_cvg--;
560   newcvg--;
561   memory_cvg--;
562   clampcvg--;
563
564#if defined(COLOR_ON_CVG)
565   if (!wrapflag)
566   {
567      *fb &= 0xffffff00;
568      *fb |= ((newcvg << 5) & 0xff);
569      return 0;
570   }
571#endif
572
573   *fb = finalcolor | memory_alphachannel;
574   return 1;
575}
576
577#if defined(COLOR_ON_CVG)
578   INLINE UINT32 FBWRITE_32_RDNEN_CVGD0_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
579#else
580   INLINE UINT32 FBWRITE_32_RDNEN_CVGD0_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
581#endif
582{
583   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
584
585   UINT32 newcvg = curpixel_cvg + 8;
586   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
587   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
588   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
589
590   curpixel_cvg--;
591   newcvg--;
592   clampcvg--;
593
594#if defined(COLOR_ON_CVG)
595   if (!wrapflag)
596   {
597      *fb &= 0xffffff00;
598      *fb |= ((newcvg << 5) & 0xff);
599      return 0;
600   }
601#endif
602
603   if (!other_modes.force_blend && !curpixel_overlap)
604   {
605      *fb = finalcolor|(curpixel_cvg << 5);
606   }
607   else
608   {
609      *fb = finalcolor|(clampcvg << 5);
610   }
611   return 1;
612}
613
614#if defined(COLOR_ON_CVG)
615   INLINE UINT32 FBWRITE_32_RDNEN_CVGD1_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
616#else
617   INLINE UINT32 FBWRITE_32_RDNEN_CVGD1_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
618#endif
619{
620   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
621
622   UINT32 newcvg = curpixel_cvg + 8;
623   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
624   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
625   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
626
627   curpixel_cvg--;
628   newcvg--;
629   clampcvg--;
630
631#if defined(COLOR_ON_CVG)
632   if (!wrapflag)
633   {
634      *fb &= 0xffffff00;
635      *fb |= ((newcvg << 5) & 0xff);
636      return 0;
637   }
638#endif
639
640   *fb = finalcolor | (newcvg << 5);
641   return 1;
642}
643
644#if defined(COLOR_ON_CVG)
645   INLINE UINT32 FBWRITE_32_RDNEN_CVGD2_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
646#else
647   INLINE UINT32 FBWRITE_32_RDNEN_CVGD2_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
648#endif
649{
650   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
651
652   UINT32 newcvg = curpixel_cvg + 8;
653   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
654   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
655   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
656
657   curpixel_cvg--;
658   newcvg--;
659   clampcvg--;
660
661#if defined(COLOR_ON_CVG)
662   if (!wrapflag)
663   {
664      *fb &= 0xffffff00;
665      *fb |= ((newcvg << 5) & 0xff);
666      return 0;
667   }
668#endif
669
670   *fb = finalcolor | 0xE0;
671   return 1;
672}
673
674#if defined(COLOR_ON_CVG)
675   INLINE UINT32 FBWRITE_32_RDNEN_CVGD3_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
676#else
677   INLINE UINT32 FBWRITE_32_RDNEN_CVGD3_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b)
678#endif
679{
680   UINT32 finalcolor=(r << 24) | (g << 16) | (b << 8);
681   UINT32 memory_alphachannel = *fb & 0xff;
682
683   UINT32 newcvg = curpixel_cvg + 8;
684   UINT32 wrapflag = (newcvg > 8) ? 1 : 0;
685   UINT32 clampcvg = (newcvg > 8) ? 8 : newcvg;
686   newcvg = (wrapflag)? (newcvg - 8) : newcvg;
687
688   curpixel_cvg--;
689   newcvg--;
690   clampcvg--;
691
692#if defined(COLOR_ON_CVG)
693   if (!wrapflag)
694   {
695      *fb &= 0xffffff00;
696      *fb |= ((newcvg << 5) & 0xff);
697      return 0;
698   }
699#endif
700
701   *fb = finalcolor | memory_alphachannel;
702   return 1;
703}
165} // namespace N64
src/mame/video/rdpfb.h
r7675r7676
1INLINE UINT32 FBWRITE_16_RDEN_CVGD0_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
2INLINE UINT32 FBWRITE_16_RDEN_CVGD0_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
3INLINE UINT32 FBWRITE_16_RDEN_CVGD1_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
4INLINE UINT32 FBWRITE_16_RDEN_CVGD1_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
5INLINE UINT32 FBWRITE_16_RDEN_CVGD2_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
6INLINE UINT32 FBWRITE_16_RDEN_CVGD2_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
7INLINE UINT32 FBWRITE_16_RDEN_CVGD3_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
8INLINE UINT32 FBWRITE_16_RDEN_CVGD3_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
9INLINE UINT32 FBWRITE_16_RDNEN_CVGD0_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
10INLINE UINT32 FBWRITE_16_RDNEN_CVGD0_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
11INLINE UINT32 FBWRITE_16_RDNEN_CVGD1_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
12INLINE UINT32 FBWRITE_16_RDNEN_CVGD1_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
13INLINE UINT32 FBWRITE_16_RDNEN_CVGD2_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
14INLINE UINT32 FBWRITE_16_RDNEN_CVGD2_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
15INLINE UINT32 FBWRITE_16_RDNEN_CVGD3_NCOC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
16INLINE UINT32 FBWRITE_16_RDNEN_CVGD3_COC(UINT16 *fb, UINT8 *hb, UINT32 r, UINT32 g, UINT32 b);
1#ifndef _VIDEO_RDPFB_H_
2#define _VIDEO_RDPFB_H_
173
18INLINE UINT32 FBWRITE_32_RDEN_CVGD0_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
19INLINE UINT32 FBWRITE_32_RDEN_CVGD0_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
20INLINE UINT32 FBWRITE_32_RDEN_CVGD1_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
21INLINE UINT32 FBWRITE_32_RDEN_CVGD1_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
22INLINE UINT32 FBWRITE_32_RDEN_CVGD2_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
23INLINE UINT32 FBWRITE_32_RDEN_CVGD2_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
24INLINE UINT32 FBWRITE_32_RDEN_CVGD3_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
25INLINE UINT32 FBWRITE_32_RDEN_CVGD3_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
26INLINE UINT32 FBWRITE_32_RDNEN_CVGD0_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
27INLINE UINT32 FBWRITE_32_RDNEN_CVGD0_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
28INLINE UINT32 FBWRITE_32_RDNEN_CVGD1_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
29INLINE UINT32 FBWRITE_32_RDNEN_CVGD1_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
30INLINE UINT32 FBWRITE_32_RDNEN_CVGD2_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
31INLINE UINT32 FBWRITE_32_RDNEN_CVGD2_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
32INLINE UINT32 FBWRITE_32_RDNEN_CVGD3_NCOC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
33INLINE UINT32 FBWRITE_32_RDNEN_CVGD3_COC(UINT32 *fb, UINT32 r, UINT32 g, UINT32 b);
4#include "emu.h"
345
35static UINT32 (*rdp_fbwrite_16_func[16])(UINT16*, UINT8*, UINT32, UINT32, UINT32) =
6namespace N64
367{
37   FBWRITE_16_RDNEN_CVGD0_NCOC,   FBWRITE_16_RDNEN_CVGD1_NCOC,   FBWRITE_16_RDNEN_CVGD2_NCOC,   FBWRITE_16_RDNEN_CVGD3_NCOC,
38   FBWRITE_16_RDEN_CVGD0_NCOC,      FBWRITE_16_RDEN_CVGD1_NCOC,      FBWRITE_16_RDEN_CVGD2_NCOC,      FBWRITE_16_RDEN_CVGD3_NCOC,
39   FBWRITE_16_RDNEN_CVGD0_COC,      FBWRITE_16_RDNEN_CVGD1_COC,      FBWRITE_16_RDNEN_CVGD2_COC,      FBWRITE_16_RDNEN_CVGD3_COC,
40   FBWRITE_16_RDEN_CVGD0_COC,      FBWRITE_16_RDEN_CVGD1_COC,      FBWRITE_16_RDEN_CVGD2_COC,      FBWRITE_16_RDEN_CVGD3_COC,
41};
428
43static UINT32 (*rdp_fbwrite_32_func[16])(UINT32*, UINT32, UINT32, UINT32) =
9namespace RDP
4410{
45   FBWRITE_32_RDNEN_CVGD0_NCOC,   FBWRITE_32_RDNEN_CVGD1_NCOC,   FBWRITE_32_RDNEN_CVGD2_NCOC,   FBWRITE_32_RDNEN_CVGD3_NCOC,
46   FBWRITE_32_RDEN_CVGD0_NCOC,      FBWRITE_32_RDEN_CVGD1_NCOC,      FBWRITE_32_RDEN_CVGD2_NCOC,      FBWRITE_32_RDEN_CVGD3_NCOC,
47   FBWRITE_32_RDNEN_CVGD0_COC,      FBWRITE_32_RDNEN_CVGD1_COC,      FBWRITE_32_RDNEN_CVGD2_COC,      FBWRITE_32_RDNEN_CVGD3_COC,
48   FBWRITE_32_RDEN_CVGD0_COC,      FBWRITE_32_RDEN_CVGD1_COC,      FBWRITE_32_RDEN_CVGD2_COC,      FBWRITE_32_RDEN_CVGD3_COC,
11
12class OtherModes;
13class MiscState;
14
15class Framebuffer
16{
17   public:
18      Framebuffer() { }
19
20      bool            Write(void* fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b);
21
22      void            SetOtherModes(OtherModes* other_modes) { m_other_modes = other_modes; }
23      void            SetMiscState(MiscState* misc_state) { m_misc_state = misc_state; }
24
25   private:
26      OtherModes*         m_other_modes;
27      MiscState*         m_misc_state;
28
29      bool            Write16Bit(UINT16* fb, UINT8* hb, UINT32 r, UINT32 g, UINT32 b);
30      bool            Write32Bit(UINT32* fb, UINT32 r, UINT32 g, UINT32 b);
4931};
32
33} // namespace RDP
34
35} // namespace N64
36
37#endif // _VIDEO_RDPFB_H_
No newline at end of file
src/mame/video/n64.c
r7675r7676
88
99#include "emu.h"
1010#include "includes/n64.h"
11#include "video/n64.h"
1112
1213#define LOG_RDP_EXECUTION      0
1314
1415static FILE *rdp_exec;
1516
16static UINT32 rdp_cmd_data[0x1000];
17static int rdp_cmd_ptr = 0;
18static int rdp_cmd_cur = 0;
19
20static UINT32 curpixel_cvg=0;
21static UINT32 curpixel_overlap = 0;
22
23//sign-extension macros
24#define SIGN17(x)   (((x) & 0x10000) ? ((x) | ~0x1ffff) : ((x) & 0x1ffff))
25#define SIGN16(x)   (((x) & 0x8000) ? ((x) | ~0xffff) : ((x) & 0xffff))
26#define SIGN11(x)   (((x) & 0x400) ? ((x) | ~0x7ff) : ((x) & 0x7ff))
27
28#define RDP_CVG_SPAN_MAX    1024
29
30typedef union
31{
32   UINT32 w;
33#ifdef LSB_FIRST
34   struct { UINT16 l; INT16 h; } h;
35#else
36   struct { INT16 h; UINT16 l; } h;
37#endif
38} SPAN_PARAM;
39
40typedef struct
41{
42   int lx;
43   int rx;
44   int dymax;
45   SPAN_PARAM s;
46   SPAN_PARAM ds;
47   SPAN_PARAM t;
48   SPAN_PARAM dt;
49   SPAN_PARAM w;
50   SPAN_PARAM dw;
51   SPAN_PARAM r;
52   SPAN_PARAM dr;
53   SPAN_PARAM g;
54   SPAN_PARAM dg;
55   SPAN_PARAM b;
56   SPAN_PARAM db;
57   SPAN_PARAM a;
58   SPAN_PARAM da;
59   SPAN_PARAM z;
60   SPAN_PARAM dz;
61    UINT8 cvg[RDP_CVG_SPAN_MAX];
62    int dzpix;
63} SPAN;
64
65static SPAN span[4096];
66
6717/*****************************************************************************/
6818
69#define BYTE_ADDR_XOR      BYTE4_XOR_BE(0)
70#define WORD_ADDR_XOR      (WORD_XOR_BE(0) >> 1)
19#define LookUpCC(A, B, C, D) state->m_rdp.GetCCLUT2()[(state->m_rdp.GetCCLUT1()[(A << 16) | (B << 8) | C] << 8) | D]
7120
72typedef struct
73{
74   union
75   {
76      UINT32 c;
77#ifdef LSB_FIRST
78      struct { UINT8 a, b, g, r; } i;
79#else
80      struct { UINT8 r, g, b, a; } i;
81#endif
82   };
83} COLOR;
21// The functions in this file should be moved into the parent Processor class.
22#include "rdpfiltr.c"
8423
85typedef struct
24void N64::RDP::Processor::GetAlphaCvg(UINT8 *comb_alpha)
8625{
87   UINT16 xl, yl, xh, yh;      // 10.2 fixed-point
88} RECTANGLE;
89
90typedef struct
91{
92   int tilenum;
93   UINT16 xl, yl, xh, yh;      // 10.2 fixed-point
94   INT16 s, t;               // 10.5 fixed-point
95   INT16 dsdx, dtdy;         // 5.10 fixed-point
96   int flip;
97} TEX_RECTANGLE;
98
99typedef struct
100{
101   int format;   // Image data format: RGBA, YUV, CI, IA, I
102   int size; // Size of texel element: 4b, 8b, 16b, 32b
103   UINT32 line; // Size of tile line in bytes
104   UINT32 tmem; // Starting tmem address for this tile in bytes
105   int palette; // Palette number for 4b CI texels
106   int ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction
107   int mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts
108   UINT16 sl, tl, sh, th;      // 10.2 fixed-point, starting and ending texel row / column
109   int num;
110   int fetch_index; // FETCH_TEXEL function index
111} TILE;
112
113typedef struct
114{
115   int sub_a_rgb0;
116   int sub_b_rgb0;
117   int mul_rgb0;
118   int add_rgb0;
119   int sub_a_a0;
120   int sub_b_a0;
121   int mul_a0;
122   int add_a0;
123
124   int sub_a_rgb1;
125   int sub_b_rgb1;
126   int mul_rgb1;
127   int add_rgb1;
128   int sub_a_a1;
129   int sub_b_a1;
130   int mul_a1;
131   int add_a1;
132} COMBINE_MODES;
133
134typedef struct
135{
136   int cycle_type;
137   bool persp_tex_en;
138   bool detail_tex_en;
139   bool sharpen_tex_en;
140   bool tex_lod_en;
141   bool en_tlut;
142   bool tlut_type;
143   bool sample_type;
144   bool mid_texel;
145   bool bi_lerp0;
146   bool bi_lerp1;
147   bool convert_one;
148   bool key_en;
149   int rgb_dither_sel;
150   int alpha_dither_sel;
151   int blend_m1a_0;
152   int blend_m1a_1;
153   int blend_m1b_0;
154   int blend_m1b_1;
155   int blend_m2a_0;
156   int blend_m2a_1;
157   int blend_m2b_0;
158   int blend_m2b_1;
159    int tex_edge;
160   bool force_blend;
161   bool alpha_cvg_select;
162   bool cvg_times_alpha;
163   int z_mode;
164   int cvg_dest;
165   bool color_on_cvg;
166   bool image_read_en;
167   bool z_update_en;
168   bool z_compare_en;
169   bool antialias_en;
170   bool z_source_sel;
171   bool dither_alpha_en;
172   bool alpha_compare_en;
173} OTHER_MODES;
174
175/*****************************************************************************/
176
177#define PIXEL_SIZE_4BIT         0
178#define PIXEL_SIZE_8BIT         1
179#define PIXEL_SIZE_16BIT      2
180#define PIXEL_SIZE_32BIT      3
181
182#define CYCLE_TYPE_1         0
183#define CYCLE_TYPE_2         1
184#define CYCLE_TYPE_COPY         2
185#define CYCLE_TYPE_FILL         3
186
187#define SAMPLE_TYPE_1x1         0
188#define SAMPLE_TYPE_2x2         1
189
190static UINT16 cc_lut1[(1<<24)];
191static UINT8 cc_lut2[(1<<24)];
192static UINT32 rgb16_to_32_lut[(1<<16)];
193static UINT32 ia8_to_32_lut[(1<<16)];
194static UINT32 tex_lerp_lut[(1<<21)];
195
196static COMBINE_MODES combine;
197static OTHER_MODES other_modes;
198
199static COLOR blend_color;
200static COLOR prim_color;
201static COLOR env_color;
202static COLOR fog_color;
203static COLOR combined_color;
204static COLOR texel0_color;
205static COLOR texel1_color;
206static COLOR shade_color;
207static COLOR key_scale; // Used in NASCAR 2000
208static COLOR noise_color; // Used in Super Smash Bros.
209
210static COLOR one_color;
211static COLOR zero_color;
212
213// combiner inputs
214static UINT8 *combiner_rgbsub_a_r[2];
215static UINT8 *combiner_rgbsub_a_g[2];
216static UINT8 *combiner_rgbsub_a_b[2];
217static UINT8 *combiner_rgbsub_b_r[2];
218static UINT8 *combiner_rgbsub_b_g[2];
219static UINT8 *combiner_rgbsub_b_b[2];
220static UINT8 *combiner_rgbmul_r[2];
221static UINT8 *combiner_rgbmul_g[2];
222static UINT8 *combiner_rgbmul_b[2];
223static UINT8 *combiner_rgbadd_r[2];
224static UINT8 *combiner_rgbadd_g[2];
225static UINT8 *combiner_rgbadd_b[2];
226
227static UINT8 *combiner_alphasub_a[2];
228static UINT8 *combiner_alphasub_b[2];
229static UINT8 *combiner_alphamul[2];
230static UINT8 *combiner_alphaadd[2];
231
232// blender input
233static UINT8 *blender1a_r[2];
234static UINT8 *blender1a_g[2];
235static UINT8 *blender1a_b[2];
236static UINT8 *blender1b_a[2];
237static UINT8 *blender2a_r[2];
238static UINT8 *blender2a_g[2];
239static UINT8 *blender2a_b[2];
240static UINT8 *blender2b_a[2];
241
242static COLOR pixel_color;
243static COLOR inv_pixel_color;
244static COLOR blended_pixel_color;
245static COLOR memory_color;
246
247static UINT32 fill_color;      // packed 16-bit or 32-bit, depending on framebuffer format
248
249static UINT16 primitive_z;
250static UINT16 primitive_delta_z;
251
252static int fb_format;
253static int fb_size;
254int fb_width;
255int fb_height;
256static UINT32 fb_address;
257
258static UINT32 zb_address;
259
260static int ti_format;
261static int ti_size;
262static int ti_width;
263static UINT32 ti_address;
264
265static TILE tile[8];
266
267static RECTANGLE clip;
268
269static UINT8 *TMEM;
270static UINT16 *TMEM16;
271static UINT32 *TMEM32;
272#define tlut ((UINT16*)(TMEM + 0x800))
273
274static INT32 k0, k1, k2, k3, k4, k5;
275static UINT8 primitive_lod_frac = 0;
276static UINT8 lod_frac = 0;
277static UINT8 hidden_bits[0x800000];
278
279static INT32 NormPointRom[64];
280static INT32 NormSlopeRom[64];
281
282#define zmode other_modes.z_mode
283static struct
284{
285   UINT32 shift;
286   UINT32 add;
287} z_dec_table[8] =
288{
289   { 6, 0x00000 },
290   { 5, 0x20000 },
291   { 4, 0x30000 },
292   { 3, 0x38000 },
293   { 2, 0x3c000 },
294   { 1, 0x3e000 },
295   { 0, 0x3f000 },
296   { 0, 0x3f800 },
297};
298
299static INT32 gamma_table[256];
300static INT32 gamma_dither_table[0x4000];
301static UINT16 z_com_table[0x40000]; // Pre-calculated table of compressed z values
302static UINT32 max_level = 0;
303static UINT32 min_level = 0;
304//static COLOR ViBuffer[640][480]; // Used by divot filter
305static INT32 maskbits_table[16]; // Pre-calculated
306static INT32 clamp_t_diff[8];
307static INT32 clamp_s_diff[8];
308
309#define COMBINER_EQUATION(A, B, C, D) cc_lut2[(cc_lut1[(A << 16) | (B << 8) | C] << 8) | D]
310//#define COMBINER_EQUATION(A, B, C, D) cc_lut_base[((D) << 17) + ((C) << 9) + (A) - (B)]
311
312//INLINE void COMBINER_EQUATION(UINT8* out, UINT8 *A, UINT8 *B, UINT8 *C, UINT8 *D);
313INLINE UINT32 addrightcvg(UINT32 x, UINT32 k);
314INLINE UINT32 addleftcvg(UINT32 x, UINT32 k);
315INLINE UINT32 z_decompress(UINT16* zb);
316INLINE UINT16 dz_decompress(UINT16* zb, UINT8* zhb);
317INLINE void z_build_com_table(void);
318INLINE void z_store(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz);
319INLINE INT32 normalize_dzpix(INT32 sum);
320INLINE INT32 CLIP(INT32 value,INT32 min,INT32 max);
321INLINE void video_filter16(int *out_r, int *out_g, int *out_b, UINT16* vbuff, UINT8* hbuff, const UINT32 hres);
322INLINE void divot_filter16(UINT8* r, UINT8* g, UINT8* b, UINT16* fbuff, UINT32 fbuff_index);
323INLINE void restore_filter16(INT32* r, INT32* g, INT32* b, UINT16* fbuff, UINT32 fbuff_index, UINT32 hres);
324INLINE UINT32 getlog2(UINT32 lod_clamp);
325INLINE void copy_colors(COLOR* dst, COLOR* src);
326INLINE void BILERP_AND_WRITE(UINT32* src0, UINT32* src1, UINT32* dest);
327INLINE void tcdiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst);
328INLINE void divot_filter16_buffer(INT32* r, INT32* g, INT32* b, COLOR* vibuffer);
329INLINE void restore_filter16_buffer(INT32* r, INT32* g, INT32* b, COLOR* vibuff, UINT32 hres);
330INLINE void restore_two(COLOR* filtered, COLOR* neighbour);
331INLINE void video_max(UINT32* Pixels, UINT8* max, UINT32* enb);
332INLINE UINT32 ge_two(UINT32 enb);
333INLINE void calculate_clamp_diffs(UINT32 prim_tile);
334INLINE void rgb_dither(INT32* r, INT32* g, INT32* b, int dith);
335
336INLINE void BLENDER_EQUATION0_FORCE(INT32* r, INT32* g, INT32* b, int bsel_special);
337INLINE void BLENDER_EQUATION0_NFORCE(INT32* r, INT32* g, INT32* b, int bsel_special);
338INLINE void BLENDER_EQUATION1_FORCE(INT32* r, INT32* g, INT32* b, int bsel_special);
339INLINE void BLENDER_EQUATION1_NFORCE(INT32* r, INT32* g, INT32* b, int bsel_special);
340
341#include "video/rdpfb.h"
342
343static UINT32 (*FBWRITE_16)(UINT16*, UINT8*, UINT32, UINT32, UINT32);
344static UINT32 (*FBWRITE_32)(UINT32*, UINT32, UINT32, UINT32);
345
346#include "video/rdpacvg.h"
347
348static void (*alpha_cvg_get)(UINT8 *comb_alpha);
349
350#include "video/rdpacomp.h"
351
352static int (*alpha_compare)(UINT8 comb_alpha);
353
354#include "video/rdptrect.h"
355
356static void (*texture_rectangle_16bit)(TEX_RECTANGLE *rect);
357
358#include "video/rdpfrect.h"
359
360static void (*fill_rectangle_16bit)(RECTANGLE *rect);
361
362#include "video/rdpspn16.h"
363
364static void (*render_spans_16_ns_nt_nz_nf)( int start, int end, TILE* tex_tile);
365static void (*render_spans_16_ns_nt_z_nf)(int start, int end, TILE* tex_tile);
366static void (*render_spans_16_ns_t_nz_nf)(int start, int end, TILE* tex_tile);
367static void (*render_spans_16_ns_t_z_nf)(int start, int end, TILE* tex_tile);
368static void (*render_spans_16_s_nt_nz_nf)(int start, int end, TILE* tex_tile);
369static void (*render_spans_16_s_nt_z_nf)(int start, int end, TILE* tex_tile);
370static void (*render_spans_16_s_t_nz_nf)(int start, int end, TILE* tex_tile);
371static void (*render_spans_16_s_t_z_nf)(int start, int end, TILE* tex_tile);
372static void (*render_spans_16_ns_nt_nz_f)(int start, int end, TILE* tex_tile);
373static void (*render_spans_16_ns_nt_z_f)(int start, int end, TILE* tex_tile);
374static void (*render_spans_16_ns_t_nz_f)(int start, int end, TILE* tex_tile);
375static void (*render_spans_16_ns_t_z_f)(int start, int end, TILE* tex_tile);
376static void (*render_spans_16_s_nt_nz_f)(int start, int end, TILE* tex_tile);
377static void (*render_spans_16_s_nt_z_f)(int start, int end, TILE* tex_tile);
378static void (*render_spans_16_s_t_nz_f)(int start, int end, TILE* tex_tile);
379static void (*render_spans_16_s_t_z_f)(int start, int end, TILE* tex_tile);
380
381#include "video/rdptpipe.h"
382
383//static UINT32 (*TEXTURE_PIPELINE)(INT32 SSS, INT32 SST, TILE* tex_tile);
384static UINT32 (*TEXTURE_PIPELINE)(INT32 SSS, INT32 SST, TILE* tex_tile);
385
386#include "video/rdpblend.h"
387
388static int (*BLENDER1_16_NDITH)(UINT16 *fb, UINT8* hb, COLOR c);
389static int (*BLENDER2_16_NDITH)(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2);
390static int (*BLENDER1_16_DITH)(UINT16 *fb, UINT8* hb, COLOR c, int dith);
391static int (*BLENDER2_16_DITH)(UINT16 *fb, UINT8* hb, COLOR c1, COLOR c2, int dith);
392
393#include "video/rdptri.h"
394
395//#include "video/rdpclamp.h"
396
397//static void (*CLAMP)(INT32* S, INT32* T, INT32* SFRAC, INT32* TFRAC, INT32 maxs, INT32 maxt, TILE* tex_tile);
398//static void (*CLAMP_LIGHT)(INT32* S, INT32* T, INT32 maxs, INT32 maxt, TILE* tex_tile);
399//static void (*CLAMP_QUICK)(INT32* S, INT32* T, INT32 maxs, INT32 maxt, int num);
400
401static UINT8 rdp_rand_val = 0;
402
403#include "video/rdpfetch.h"
404
405#include "video/rdpmask.h"
406
407static void (*MASK)(INT32* S, INT32* T, TILE* tex_tile);
408
409#define NOISE
410   #include "video/rdpcc.c"
411#undef NOISE
412   #include "video/rdpcc.c"
413
414#define CACHE_TEXTURE_PARAMS(TEX) \
415   TEXTURE_PIPELINE = rdp_texture_pipeline_func[(TEX->shift_t ? 64 : 0) | (TEX->shift_s ? 32 : 0) | ((TEX->ct || !TEX->mask_t) ? 16 : 0) | ((TEX->cs || !TEX->mask_s) ? 8 : 0) | ((other_modes.cycle_type == CYCLE_TYPE_COPY) ? 4 : 0) | (other_modes.mid_texel << 1) | (other_modes.sample_type ? 1 : 0)]; \
416   MASK = rdp_mask_func[(TEX->mask_s ? 2 : 0) | (TEX->mask_t ? 1 : 0)]; \
417   cached_twidth  = TEX->line; \
418   cached_tbase   = TEX->tmem; \
419   cached_tpal    = (TEX->palette & 0xf) << 4; \
420   cached_tfetch  = TEX->fetch_index; \
421   cached_tbase_s1   = TEX->tmem >> 1; \
422   cached_twidth_s1 = TEX->line >> 1;
423
424// Hack, but more efficient than mame_rand
425#define rdp_rand()   (rdp_rand_val += 19)
426
427static int special_bsel0, special_bsel1;
428
429/*****************************************************************************/
430
431VIDEO_START(n64)
432{
433   UINT8 *normpoint = memory_region(machine, "normpoint");
434   UINT8 *normslope = memory_region(machine, "normslope");
435
436   if (LOG_RDP_EXECUTION)
26   if(m_other_modes.cvg_times_alpha)
43727   {
438      rdp_exec = fopen("rdp_execute.txt", "wt");
439   }
28      if(m_other_modes.alpha_cvg_select)
29      {
30         UINT32 temp = *comb_alpha;
31         UINT32 temp2 = m_misc_state.m_curpixel_cvg;
44032
441   TMEM = auto_alloc_array(machine, UINT8, 0x1004); // 4 guard bytes
442   memset(TMEM, 0, 0x1000);
443   TMEM[0x1000] = TMEM[0x1001] = 25;
444   TMEM16 = (UINT16*)TMEM;
445   TMEM32 = (UINT32*)TMEM;
33         UINT32 temp3 = (temp * temp2) + 4;
34         m_misc_state.m_curpixel_cvg = temp3 >> 8;
44635
447   one_color.c = 0xffffffff;
448   zero_color.c = 0;
36         temp = (temp3 >> 3);
44937
450   for(int i = 0; i < (1 << 21); i++)
451   {
452      INT32 frac = i >> 16;
453      INT32 left = (i >> 8) & 0x000000ff;
454      INT32 right = i & 0x000000ff;
455      tex_lerp_lut[i] = (frac*(left - right))>>5;
456   }
38         if (temp > 0xff)
39         {
40            *comb_alpha = 0xff;
41         }
42         else
43         {
44            *comb_alpha = (UINT8)temp;
45         }
46      }
47      else
48      {
49         UINT32 temp = *comb_alpha;
50         UINT32 temp2 = m_misc_state.m_curpixel_cvg;
51         UINT32 temp3 = (temp * temp2) + 4;
45752
458   for(int i = 0; i < (1 << 24); i++)
459   {
460      UINT8 A = (i >> 16) & 0x000000ff;
461      UINT8 B = (i >> 8) & 0x000000ff;
462      UINT8 C = i & 0x000000ff;
463      cc_lut1[i] = (INT16)((((((INT32)A - (INT32)B) * (INT32)C) + 0x80) >> 8) & 0x0000ffff);
464   }
53         m_misc_state.m_curpixel_cvg = temp3 >> 8;
46554
466   for(int i = 0; i < (1 << 16); i++)
467   {
468      for(int j = 0; j < (1 << 8); j++)
469      {
470         INT32 temp = (INT32)((INT16)i) + j;
471         if(temp > 255)
55         if (temp > 0xff)
47256         {
473            cc_lut2[(i << 8) | j] = 255;
57            *comb_alpha = 0xff;
47458         }
475         else if(temp < 0)
59         else
47660         {
477            cc_lut2[(i << 8) | j] = 0;
61            *comb_alpha = (UINT8)temp;
47862         }
63      }
64   }
65   else
66   {
67      if(m_other_modes.alpha_cvg_select)
68      {
69         UINT32 temp2 = m_misc_state.m_curpixel_cvg;
70         UINT32 temp = temp2 << 5;
71
72         if (temp > 0xff)
73         {
74            *comb_alpha = 0xff;
75         }
47976         else
48077         {
481            cc_lut2[(i << 8) | j] = (UINT8)temp;
78            *comb_alpha = (UINT8)temp;
48279         }
48380      }
48481   }
82}
48583
486   for(int i = 0; i < (1 << 16); i++)
84/*****************************************************************************/
85
86void N64::RDP::Processor::VideoUpdate(bitmap_t *bitmap)
87{
88   switch(n64_vi_control & 0x3)
48789   {
488      UINT8 r = ((i >> 8) & 0xf8) | (i >> 13);
489      UINT8 g = ((i >> 3) & 0xf8) | ((i >>  8) & 0x07);
490      UINT8 b = ((i << 2) & 0xf8) | ((i >>  3) & 0x07);
491      UINT8 a = (i & 1) ? 0xff : 0;
492      rgb16_to_32_lut[i] = (r << 24) | (g << 16) | (b << 8) | a;
90      case PIXEL_SIZE_16BIT:
91         VideoUpdate16(bitmap);
92         break;
49393
494      r = g = b = (i >> 8) & 0xff;
495      a = i & 0xff;
496      ia8_to_32_lut[i] = (r << 24) | (g << 16) | (b << 8) | a;
94      case PIXEL_SIZE_32BIT:
95         VideoUpdate32(bitmap);
96         break;
97
98      default:
99         fatalerror("Unsupported framebuffer depth: m_fb_size=%d\n", m_misc_state.m_fb_size);
100         break;
497101   }
102}
498103
499   combiner_rgbsub_a_r[0] = combiner_rgbsub_a_r[1] = &one_color.i.r;
500   combiner_rgbsub_a_g[0] = combiner_rgbsub_a_g[1] = &one_color.i.g;
501   combiner_rgbsub_a_b[0] = combiner_rgbsub_a_b[1] = &one_color.i.b;
502   combiner_rgbsub_b_r[0] = combiner_rgbsub_b_r[1] = &one_color.i.r;
503   combiner_rgbsub_b_g[0] = combiner_rgbsub_b_g[1] = &one_color.i.g;
504   combiner_rgbsub_b_b[0] = combiner_rgbsub_b_b[1] = &one_color.i.b;
505   combiner_rgbmul_r[0] = combiner_rgbmul_r[1] = &one_color.i.r;
506   combiner_rgbmul_g[0] = combiner_rgbmul_g[1] = &one_color.i.g;
507   combiner_rgbmul_b[0] = combiner_rgbmul_b[1] = &one_color.i.b;
508   combiner_rgbadd_r[0] = combiner_rgbadd_r[1] = &one_color.i.r;
509   combiner_rgbadd_g[0] = combiner_rgbadd_g[1] = &one_color.i.g;
510   combiner_rgbadd_b[0] = combiner_rgbadd_b[1] = &one_color.i.b;
104void N64::RDP::Processor::VideoUpdate16(bitmap_t *bitmap)
105{
106    int fsaa = (((n64_vi_control >> 8) & 3) < 2);
107    int divot = (n64_vi_control >> 4) & 1;
511108
512   combiner_alphasub_a[0] = combiner_alphasub_a[1] = &one_color.i.a;
513   combiner_alphasub_b[0] = combiner_alphasub_b[1] = &one_color.i.a;
514   combiner_alphamul[0] = combiner_alphamul[1] = &one_color.i.a;
515   combiner_alphaadd[0] = combiner_alphaadd[1] = &one_color.i.a;
109   UINT32 prev_cvg = 0;
110   UINT32 next_cvg = 0;
111    //int dither_filter = (n64_vi_control >> 16) & 1;
112    //int vibuffering = ((n64_vi_control & 2) && fsaa && divot);
516113
517   blender1a_r[0] = blender1a_r[1] = &pixel_color.i.r;
518   blender1a_g[0] = blender1a_g[1] = &pixel_color.i.r;
519   blender1a_b[0] = blender1a_b[1] = &pixel_color.i.r;
520   blender1b_a[0] = blender1b_a[1] = &pixel_color.i.r;
521   blender2a_r[0] = blender2a_r[1] = &pixel_color.i.r;
522   blender2a_g[0] = blender2a_g[1] = &pixel_color.i.r;
523   blender2a_b[0] = blender2a_b[1] = &pixel_color.i.r;
524   blender2b_a[0] = blender2b_a[1] = &pixel_color.i.r;
114   UINT16 *frame_buffer = (UINT16*)&rdram[(n64_vi_origin & 0xffffff) >> 2];
115   UINT32 hb = ((n64_vi_origin & 0xffffff) >> 2) >> 1;
116   UINT8* hidden_buffer = &m_hidden_bits[hb];
525117
526   memset(hidden_bits, 3, 4194304); // Hack / fix for letters in Rayman 2
118   INT32 hdiff = (n64_vi_hstart & 0x3ff) - ((n64_vi_hstart >> 16) & 0x3ff);
119   float hcoeff = ((float)(n64_vi_xscale & 0xfff) / (1 << 10));
120   UINT32 hres = ((float)hdiff * hcoeff);
121   INT32 invisiblewidth = n64_vi_width - hres;
527122
528   for (int i = 0; i < 8; i++)
529   {
530      tile[i].num = i;
531   }
123   INT32 vdiff = ((n64_vi_vstart & 0x3ff) - ((n64_vi_vstart >> 16) & 0x3ff)) >> 1;
124   float vcoeff = ((float)(n64_vi_yscale & 0xfff) / (1 << 10));
125   UINT32 vres = ((float)vdiff * vcoeff);
532126
533   for (int i = 0; i < 256; i++)
127   if (vdiff <= 0 || hdiff <= 0)
534128   {
535      gamma_table[i] = sqrt((float)(i << 6));
536      gamma_table[i] <<= 1;
129      return;
537130   }
538131
539   for (int i = 0; i < 0x4000; i++)
132   if (hres > 640) // Needed by Top Gear Overdrive (E)
540133   {
541      gamma_dither_table[i] = sqrt((float)i);
542      gamma_dither_table[i] <<= 1;
134      invisiblewidth += (hres - 640);
135      hres = 640;
543136   }
544137
545   z_build_com_table();
138   UINT32 pixels = 0;
546139
547   maskbits_table[0] = 0x3ff;
548   for(int i = 1; i < 16; i++)
140   if (frame_buffer)
549141   {
550      maskbits_table[i] = ((UINT16)(0xffff) >> (16 - i)) & 0x3ff;
551   }
142      for(int j = 0; j < vres; j++)
143      {
144         UINT32 *d = BITMAP_ADDR32(bitmap, j, 0);
552145
553   for(int i = 0; i < 64; i++)
554   {
555      NormPointRom[i] = (normpoint[(i << 1) + 1] << 8) | normpoint[i << 1];
556      NormSlopeRom[i] = (normslope[(i << 1) + 1] << 8) | normslope[i << 1];
146         for(int i = 0; i < hres; i++)
147         {
148            N64::RDP::Color c;
149            //int r, g, b;
150
151            UINT16 pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
152            m_misc_state.m_curpixel_cvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3);
153
154            if(divot)
155            {
156               if(i > 0 && i < (hres - 1))
157               {
158                  prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
159                  next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
160               }
161            }
162            c.c = LookUp16To32(pix);
163            //r = ((pix >> 8) & 0xf8) | (pix >> 13);
164            //g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
165            //b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
166
167            if(fsaa)
168            {
169               //if (/*!vibuffering &&*/ state->m_rdp.GetMiscState()->m_curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2))
170               //{
171                  //video_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR],&hidden_buffer[pixels ^ BYTE_ADDR_XOR], n64_vi_width);
172               //}
173            }
174            //else if (dither_filter && state->m_rdp.GetMiscState()->m_curpixel_cvg == 7 && i > 0 && j > 0 && i < (hres - 1) && j < (vres - 1))
175            //{
176               //if (vibuffering)
177               //{
178               //  restore_filter16_buffer(&r, &g, &b, &ViBuffer[i][j], n64_vi_width);
179               //}
180               //else
181               //{
182                  //restore_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR, n64_vi_width);
183               //}
184            //}
185            if(divot)
186            {
187               if (i > 0 && i < (hres - 1) && (m_misc_state.m_curpixel_cvg != 7 || prev_cvg != 7 || next_cvg != 7))
188               {
189                  //if (vibuffering)
190                  //{
191                  //  divot_filter16_buffer(&r, &g, &b, &ViBuffer[i][j]);
192                  //}
193                  //else
194                  //{
195                     //divot_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR);
196                  //}
197               }
198            }
199
200            /*
201                if (gamma_dither)
202                {
203                    dith = mame_rand(screen->machine) & 0x3f;
204                }
205                if (gamma)
206                {
207                    if (gamma_dither)
208                    {
209                        r = m_gamma_dither_table[(r << 6)|dith];
210                        g = m_gamma_dither_table[(g << 6)|dith];
211                        b = m_gamma_dither_table[(b << 6)|dith];
212                    }
213                    else
214                    {
215                        r = m_gamma_table[r];
216                        g = m_gamma_table[g];
217                        b = m_gamma_table[b];
218                    }
219                }
220                else if (gamma_dither)
221                {
222                    if (r < 255)
223                        r += (dith & 1);
224                    if (g < 255)
225                        g += (dith & 1);
226                    if (b < 255)
227                        b += (dith & 1);
228                }
229                */
230            pixels++;
231
232            d[i] = c.c >> 8;//(r << 16) | (g << 8) | b; // Fix me for endianness
233         }
234         pixels +=invisiblewidth;
235      }
557236   }
558237}
559238
560#define FSAA
561   #define DIVOT
562      #include "rdpupd16.c"
563   #undef DIVOT
564      #include "rdpupd16.c"
565#undef FSAA
566   #define DIVOT
567      #include "rdpupd16.c"
568   #undef DIVOT
569      #include "rdpupd16.c"
570
571static void video_update_n64_32(bitmap_t *bitmap)
239void N64::RDP::Processor::VideoUpdate32(bitmap_t *bitmap)
572240{
573241    int gamma = (n64_vi_control >> 3) & 1;
574242    int gamma_dither = (n64_vi_control >> 2) & 1;
r7675r7676
612280               int dith = 0;
613281               if (gamma_dither)
614282               {
615                  dith = rdp_rand() & 0x3f;
283                  dith = GetRandom() & 0x3f;
616284               }
617285               if (gamma)
618286               {
619287                  if (gamma_dither)
620288                  {
621                     r = gamma_dither_table[(r << 6)| dith];
622                     g = gamma_dither_table[(g << 6)| dith];
623                     b = gamma_dither_table[(b << 6)| dith];
289                     r = m_gamma_dither_table[(r << 6)| dith];
290                     g = m_gamma_dither_table[(g << 6)| dith];
291                     b = m_gamma_dither_table[(b << 6)| dith];
624292                  }
625293                  else
626294                  {
627                     r = gamma_table[r];
628                     g = gamma_table[g];
629                     b = gamma_table[b];
295                     r = m_gamma_table[r];
296                     g = m_gamma_table[g];
297                     b = m_gamma_table[b];
630298                  }
631299               }
632300               else if (gamma_dither)
r7675r7676
649317   }
650318}
651319
652VIDEO_UPDATE(n64)
320/*****************************************************************************/
321
322void N64::RDP::Processor::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst)
653323{
654    int fsaa = (((n64_vi_control >> 8) & 3) < 2);
655    int divot = (n64_vi_control >> 4) & 1;
656    int height = fb_height;
657   //UINT16 *frame_buffer = (UINT16*)&rdram[(n64_vi_origin & 0xffffff) >> 2];
658   //UINT8  *cvg_buffer = &hidden_bits[((n64_vi_origin & 0xffffff) >> 2) >> 1];
659    //int vibuffering = ((n64_vi_control & 2) && fsaa && divot);
324   int shift;
660325
661   //vibuffering = 0; // Disabled for now
326   sw &= 0x7fff;
327   for(shift = 1; shift <= 14 && !((sw << shift) & 0x8000); shift++);
328   shift -= 1;
662329
663   /*
664    if (vibuffering && ((n64_vi_control & 3) == 2))
665    {
666        if (frame_buffer)
667        {
668            for (j=0; j < vres; j++)
669            {
670                for (i=0; i < hres; i++)
671                {
672                    UINT16 pix;
673                    pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
674                    curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable
675                    if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa)
676                    {
677                        newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64_vi_width);
678                        ViBuffer[i][j] = newc;
679                    }
680                    else
681                    {
682                        newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13);
683                        newc.i.g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
684                        newc.i.b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
685                        ViBuffer[i][j] = newc;
686                    }
687                    pixels++;
688                }
689                pixels += invisiblewidth;
690            }
691        }
692    }
693    */
330   int normout = ((sw << shift) & 0x3fff) >> 8;
331   int wnorm = ((sw << shift) & 0xff) << 2;
694332
695    if (n64_vi_blank)
696    {
697        for (int j = 0; j <height; j++)
698        {
699            UINT32 *d = BITMAP_ADDR32(bitmap, j, 0);
700            for (int i = 0; i < fb_width; i++)
701            {
702                d[BYTE_XOR_BE(i)] = 0;
703            }
704        }
705        return 0;
706    }
333   int tlu_rcp = ((-(m_norm_slope_rom[normout] * wnorm)) >> 10) + m_norm_point_rom[normout];
707334
708    switch (n64_vi_control & 0x3)
335   if(shift == 14)
709336   {
710      case 0:      // blank/no signal
711      {
712         break;
713      }
714
715      case 2:      // RGBA5551
716      {
717         if(divot && fsaa)
718         {
719            video_update_n64_16_fsaa_divot(bitmap);
720         }
721         else if(divot)
722         {
723            video_update_n64_16_nofsaa_divot(bitmap);
724         }
725         else if(fsaa)
726         {
727            video_update_n64_16_fsaa_nodivot(bitmap);
728         }
729         else
730         {
731            video_update_n64_16_nofsaa_nodivot(bitmap);
732         }
733         break;
734      }
735
736      case 3:      // RGBA8888
737      {
738         video_update_n64_32(bitmap);
739         break;
740      }
741
742        default:    fatalerror("Unknown framebuffer format %d\n", n64_vi_control & 0x3);
337      *sss = (SIGN16(ss) * tlu_rcp) << 1;
338      *sst = (SIGN16(st) * tlu_rcp) << 1;
743339   }
744   return 0;
340   else
341   {
342      int shift_value = 13 - shift;
343      *sss = (SIGN16(ss) * tlu_rcp) >> shift_value;
344      *sst = (SIGN16(st) * tlu_rcp) >> shift_value;
345   }
745346}
746347
747/*****************************************************************************/
748
749static void SET_SUBA_RGB_INPUT(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
348void N64::RDP::Processor::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
750349{
751350   switch (code & 0xf)
752351   {
753      case 0:      *input_r = &combined_color.i.r;   *input_g = &combined_color.i.g;   *input_b = &combined_color.i.b;   break;
754      case 1:      *input_r = &texel0_color.i.r;      *input_g = &texel0_color.i.g;      *input_b = &texel0_color.i.b;      break;
755      case 2:      *input_r = &texel1_color.i.r;      *input_g = &texel1_color.i.g;      *input_b = &texel1_color.i.b;      break;
756      case 3:      *input_r = &prim_color.i.r;      *input_g = &prim_color.i.g;      *input_b = &prim_color.i.b;      break;
757      case 4:      *input_r = &shade_color.i.r;      *input_g = &shade_color.i.g;      *input_b = &shade_color.i.b;      break;
758      case 5:      *input_r = &env_color.i.r;      *input_g = &env_color.i.g;      *input_b = &env_color.i.b;      break;
759      case 6:      *input_r = &one_color.i.r;      *input_g = &one_color.i.g;      *input_b = &one_color.i.b;      break;
760      case 7:      *input_r = &noise_color.i.r;      *input_g = &noise_color.i.g;      *input_b = &noise_color.i.b;      break;
352      case 0:      *input_r = &m_combined_color.i.r;   *input_g = &m_combined_color.i.g;   *input_b = &m_combined_color.i.b;   break;
353      case 1:      *input_r = &m_texel0_color.i.r;      *input_g = &m_texel0_color.i.g;      *input_b = &m_texel0_color.i.b;      break;
354      case 2:      *input_r = &m_texel1_color.i.r;      *input_g = &m_texel1_color.i.g;      *input_b = &m_texel1_color.i.b;      break;
355      case 3:      *input_r = &m_prim_color.i.r;      *input_g = &m_prim_color.i.g;      *input_b = &m_prim_color.i.b;      break;
356      case 4:      *input_r = &m_shade_color.i.r;      *input_g = &m_shade_color.i.g;      *input_b = &m_shade_color.i.b;      break;
357      case 5:      *input_r = &m_env_color.i.r;      *input_g = &m_env_color.i.g;      *input_b = &m_env_color.i.b;      break;
358      case 6:      *input_r = &m_one_color.i.r;      *input_g = &m_one_color.i.g;      *input_b = &m_one_color.i.b;      break;
359      case 7:      *input_r = &m_noise_color.i.r;      *input_g = &m_noise_color.i.g;      *input_b = &m_noise_color.i.b;      break;
761360      case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
762361      {
763         *input_r = &zero_color.i.r;      *input_g = &zero_color.i.g;      *input_b = &zero_color.i.b;      break;
362               *input_r = &m_zero_color.i.r;      *input_g = &m_zero_color.i.g;      *input_b = &m_zero_color.i.b;      break;
764363      }
765364   }
766365}
767366
768static void SET_SUBB_RGB_INPUT(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
367void N64::RDP::Processor::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
769368{
770369   switch (code & 0xf)
771370   {
772      case 0:      *input_r = &combined_color.i.r;   *input_g = &combined_color.i.g;   *input_b = &combined_color.i.b;   break;
773      case 1:      *input_r = &texel0_color.i.r;      *input_g = &texel0_color.i.g;      *input_b = &texel0_color.i.b;      break;
774      case 2:      *input_r = &texel1_color.i.r;      *input_g = &texel1_color.i.g;      *input_b = &texel1_color.i.b;      break;
775      case 3:      *input_r = &prim_color.i.r;      *input_g = &prim_color.i.g;      *input_b = &prim_color.i.b;      break;
776      case 4:      *input_r = &shade_color.i.r;      *input_g = &shade_color.i.g;      *input_b = &shade_color.i.b;      break;
777      case 5:      *input_r = &env_color.i.r;      *input_g = &env_color.i.g;      *input_b = &env_color.i.b;      break;
778      case 6:      fatalerror("SET_SUBB_RGB_INPUT: key_center\n"); break;
779      case 7:      *input_r = (UINT8*)&k4;         *input_g = (UINT8*)&k4;         *input_b = (UINT8*)&k4;         break;
371      case 0:      *input_r = &m_combined_color.i.r;   *input_g = &m_combined_color.i.g;   *input_b = &m_combined_color.i.b;   break;
372      case 1:      *input_r = &m_texel0_color.i.r;      *input_g = &m_texel0_color.i.g;      *input_b = &m_texel0_color.i.b;      break;
373      case 2:      *input_r = &m_texel1_color.i.r;      *input_g = &m_texel1_color.i.g;      *input_b = &m_texel1_color.i.b;      break;
374      case 3:      *input_r = &m_prim_color.i.r;      *input_g = &m_prim_color.i.g;      *input_b = &m_prim_color.i.b;      break;
375      case 4:      *input_r = &m_shade_color.i.r;      *input_g = &m_shade_color.i.g;      *input_b = &m_shade_color.i.b;      break;
376      case 5:      *input_r = &m_env_color.i.r;      *input_g = &m_env_color.i.g;      *input_b = &m_env_color.i.b;      break;
377      case 6:      fatalerror("SET_SUBB_RGB_INPUT: key_center\n");   break;
378      case 7:      *input_r = (UINT8*)&m_k4;         *input_g = (UINT8*)&m_k4;         *input_b = (UINT8*)&m_k4;         break;
780379      case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
781380      {
782         *input_r = &zero_color.i.r;      *input_g = &zero_color.i.g;      *input_b = &zero_color.i.b;      break;
381               *input_r = &m_zero_color.i.r;      *input_g = &m_zero_color.i.g;      *input_b = &m_zero_color.i.b;      break;
783382      }
784383   }
785384}
786385
787static void SET_MUL_RGB_INPUT(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
386void N64::RDP::Processor::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
788387{
789388   switch (code & 0x1f)
790389   {
791      case 0:      *input_r = &combined_color.i.r;   *input_g = &combined_color.i.g;   *input_b = &combined_color.i.b;   break;
792      case 1:      *input_r = &texel0_color.i.r;      *input_g = &texel0_color.i.g;      *input_b = &texel0_color.i.b;      break;
793      case 2:      *input_r = &texel1_color.i.r;      *input_g = &texel1_color.i.g;      *input_b = &texel1_color.i.b;      break;
794      case 3:      *input_r = &prim_color.i.r;      *input_g = &prim_color.i.g;      *input_b = &prim_color.i.b;      break;
795      case 4:      *input_r = &shade_color.i.r;      *input_g = &shade_color.i.g;      *input_b = &shade_color.i.b;      break;
796      case 5:      *input_r = &env_color.i.r;      *input_g = &env_color.i.g;      *input_b = &env_color.i.b;      break;
797      case 6:      *input_r = &key_scale.i.r;      *input_g = &key_scale.i.g;      *input_b = &key_scale.i.b;      break;
798      case 7:      *input_r = &combined_color.i.a;   *input_g = &combined_color.i.a;   *input_b = &combined_color.i.a;   break;
799      case 8:      *input_r = &texel0_color.i.a;      *input_g = &texel0_color.i.a;      *input_b = &texel0_color.i.a;      break;
800      case 9:      *input_r = &texel1_color.i.a;      *input_g = &texel1_color.i.a;      *input_b = &texel1_color.i.a;      break;
801      case 10:   *input_r = &prim_color.i.a;      *input_g = &prim_color.i.a;      *input_b = &prim_color.i.a;      break;
802      case 11:   *input_r = &shade_color.i.a;      *input_g = &shade_color.i.a;      *input_b = &shade_color.i.a;      break;
803      case 12:   *input_r = &env_color.i.a;      *input_g = &env_color.i.a;      *input_b = &env_color.i.a;      break;
804      case 13:   *input_r = &lod_frac;         *input_g = &lod_frac;         *input_b = &lod_frac;         break;
805      case 14:   *input_r = &primitive_lod_frac;   *input_g = &primitive_lod_frac;   *input_b = &primitive_lod_frac; break;
806      case 15:   *input_r = (UINT8*)&k5;         *input_g = (UINT8*)&k5;         *input_b = (UINT8*)&k5;         break;
390      case 0:      *input_r = &m_combined_color.i.r;   *input_g = &m_combined_color.i.g;   *input_b = &m_combined_color.i.b;   break;
391      case 1:      *input_r = &m_texel0_color.i.r;      *input_g = &m_texel0_color.i.g;      *input_b = &m_texel0_color.i.b;      break;
392      case 2:      *input_r = &m_texel1_color.i.r;      *input_g = &m_texel1_color.i.g;      *input_b = &m_texel1_color.i.b;      break;
393      case 3:      *input_r = &m_prim_color.i.r;      *input_g = &m_prim_color.i.g;      *input_b = &m_prim_color.i.b;      break;
394      case 4:      *input_r = &m_shade_color.i.r;      *input_g = &m_shade_color.i.g;      *input_b = &m_shade_color.i.b;      break;
395      case 5:      *input_r = &m_env_color.i.r;      *input_g = &m_env_color.i.g;      *input_b = &m_env_color.i.b;      break;
396      case 6:      *input_r = &m_key_scale.i.r;      *input_g = &m_key_scale.i.g;      *input_b = &m_key_scale.i.b;      break;
397      case 7:      *input_r = &m_combined_color.i.a;   *input_g = &m_combined_color.i.a;   *input_b = &m_combined_color.i.a;   break;
398      case 8:      *input_r = &m_texel0_color.i.a;      *input_g = &m_texel0_color.i.a;      *input_b = &m_texel0_color.i.a;      break;
399      case 9:      *input_r = &m_texel1_color.i.a;      *input_g = &m_texel1_color.i.a;      *input_b = &m_texel1_color.i.a;      break;
400      case 10:   *input_r = &m_prim_color.i.a;      *input_g = &m_prim_color.i.a;      *input_b = &m_prim_color.i.a;      break;
401      case 11:   *input_r = &m_shade_color.i.a;      *input_g = &m_shade_color.i.a;      *input_b = &m_shade_color.i.a;      break;
402      case 12:   *input_r = &m_env_color.i.a;      *input_g = &m_env_color.i.a;      *input_b = &m_env_color.i.a;      break;
403      case 13:   *input_r = &m_lod_frac;            *input_g = &m_lod_frac;            *input_b = &m_lod_frac;            break;
404      case 14:   *input_r = &m_prim_lod_frac;      *input_g = &m_prim_lod_frac;      *input_b = &m_prim_lod_frac;       break;
405      case 15:   *input_r = (UINT8*)&m_k5;         *input_g = (UINT8*)&m_k5;         *input_b = (UINT8*)&m_k5;         break;
807406      case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
808407      case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
809408      {
810         *input_r = &zero_color.i.r;      *input_g = &zero_color.i.g;      *input_b = &zero_color.i.b;      break;
409               *input_r = &m_zero_color.i.r;      *input_g = &m_zero_color.i.g;      *input_b = &m_zero_color.i.b;      break;
811410      }
812411   }
813412}
814413
815static void SET_ADD_RGB_INPUT(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
414void N64::RDP::Processor::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code)
816415{
817416   switch (code & 0x7)
818417   {
819      case 0:      *input_r = &combined_color.i.r;   *input_g = &combined_color.i.g;   *input_b = &combined_color.i.b;   break;
820      case 1:      *input_r = &texel0_color.i.r;      *input_g = &texel0_color.i.g;      *input_b = &texel0_color.i.b;      break;
821      case 2:      *input_r = &texel1_color.i.r;      *input_g = &texel1_color.i.g;      *input_b = &texel1_color.i.b;      break;
822      case 3:      *input_r = &prim_color.i.r;      *input_g = &prim_color.i.g;      *input_b = &prim_color.i.b;      break;
823      case 4:      *input_r = &shade_color.i.r;      *input_g = &shade_color.i.g;      *input_b = &shade_color.i.b;      break;
824      case 5:      *input_r = &env_color.i.r;      *input_g = &env_color.i.g;      *input_b = &env_color.i.b;      break;
825      case 6:      *input_r = &one_color.i.r;      *input_g = &one_color.i.g;      *input_b = &one_color.i.b;      break;
826      case 7:      *input_r = &zero_color.i.r;      *input_g = &zero_color.i.g;      *input_b = &zero_color.i.b;      break;
418      case 0:      *input_r = &m_combined_color.i.r;   *input_g = &m_combined_color.i.g;   *input_b = &m_combined_color.i.b;   break;
419      case 1:      *input_r = &m_texel0_color.i.r;      *input_g = &m_texel0_color.i.g;      *input_b = &m_texel0_color.i.b;      break;
420      case 2:      *input_r = &m_texel1_color.i.r;      *input_g = &m_texel1_color.i.g;      *input_b = &m_texel1_color.i.b;      break;
421      case 3:      *input_r = &m_prim_color.i.r;      *input_g = &m_prim_color.i.g;      *input_b = &m_prim_color.i.b;      break;
422      case 4:      *input_r = &m_shade_color.i.r;      *input_g = &m_shade_color.i.g;      *input_b = &m_shade_color.i.b;      break;
423      case 5:      *input_r = &m_env_color.i.r;      *input_g = &m_env_color.i.g;      *input_b = &m_env_color.i.b;      break;
424      case 6:      *input_r = &m_one_color.i.r;      *input_g = &m_one_color.i.g;      *input_b = &m_one_color.i.b;      break;
425      case 7:      *input_r = &m_zero_color.i.r;      *input_g = &m_zero_color.i.g;      *input_b = &m_zero_color.i.b;      break;
827426   }
828427}
829428
830static void SET_SUB_ALPHA_INPUT(UINT8 **input, int code)
429void N64::RDP::Processor::SetSubInputAlpha(UINT8 **input, int code)
831430{
832431   switch (code & 0x7)
833432   {
834      case 0:      *input = &combined_color.i.a; break;
835      case 1:      *input = &texel0_color.i.a; break;
836      case 2:      *input = &texel1_color.i.a; break;
837      case 3:      *input = &prim_color.i.a; break;
838      case 4:      *input = &shade_color.i.a; break;
839      case 5:      *input = &env_color.i.a; break;
840      case 6:      *input = &one_color.i.a; break;
841      case 7:      *input = &zero_color.i.a; break;
433      case 0:      *input = &m_combined_color.i.a; break;
434      case 1:      *input = &m_texel0_color.i.a; break;
435      case 2:      *input = &m_texel1_color.i.a; break;
436      case 3:      *input = &m_prim_color.i.a; break;
437      case 4:      *input = &m_shade_color.i.a; break;
438      case 5:      *input = &m_env_color.i.a; break;
439      case 6:      *input = &m_one_color.i.a; break;
440      case 7:      *input = &m_zero_color.i.a; break;
842441   }
843442}
844443
845static void SET_MUL_ALPHA_INPUT(UINT8 **input, int code)
444void N64::RDP::Processor::SetMulInputAlpha(UINT8 **input, int code)
846445{
847446   switch (code & 0x7)
848447   {
849      case 0:      *input = &lod_frac; break;//HACK
850      case 1:      *input = &texel0_color.i.a; break;
851      case 2:      *input = &texel1_color.i.a; break;
852      case 3:      *input = &prim_color.i.a; break;
853      case 4:      *input = &shade_color.i.a; break;
854      case 5:      *input = &env_color.i.a; break;
855      case 6:      *input = &primitive_lod_frac; break;//HACK
856      case 7:      *input = &zero_color.i.a; break;
448      case 0:      *input = &m_lod_frac; break; //HACK
449      case 1:      *input = &m_texel0_color.i.a; break;
450      case 2:      *input = &m_texel1_color.i.a; break;
451      case 3:      *input = &m_prim_color.i.a; break;
452      case 4:      *input = &m_shade_color.i.a; break;
453      case 5:      *input = &m_env_color.i.a; break;
454      case 6:      *input = &m_prim_lod_frac; break; //HACK
455      case 7:      *input = &m_zero_color.i.a; break;
857456   }
858457}
859458
860static void SET_BLENDER_INPUT(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b)
459void N64::RDP::Processor::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b)
861460{
862461   switch (a & 0x3)
863462   {
r7675r7676
865464      {
866465         if (cycle == 0)
867466         {
868            *input_r = &pixel_color.i.r;
869            *input_g = &pixel_color.i.g;
870            *input_b = &pixel_color.i.b;
467            *input_r = &m_pixel_color.i.r;
468            *input_g = &m_pixel_color.i.g;
469            *input_b = &m_pixel_color.i.b;
871470         }
872471         else
873472         {
874            *input_r = &blended_pixel_color.i.r;
875            *input_g = &blended_pixel_color.i.g;
876            *input_b = &blended_pixel_color.i.b;
473            *input_r = &m_blended_pixel_color.i.r;
474            *input_g = &m_blended_pixel_color.i.g;
475            *input_b = &m_blended_pixel_color.i.b;
877476         }
878477         break;
879478      }
880479
881480      case 1:
882481      {
883         *input_r = &memory_color.i.r;
884         *input_g = &memory_color.i.g;
885         *input_b = &memory_color.i.b;
482         *input_r = &m_memory_color.i.r;
483         *input_g = &m_memory_color.i.g;
484         *input_b = &m_memory_color.i.b;
886485         break;
887486      }
888487
889488      case 2:
890489      {
891         *input_r = &blend_color.i.r;      *input_g = &blend_color.i.g;      *input_b = &blend_color.i.b;
490         *input_r = &m_blend_color.i.r;
491         *input_g = &m_blend_color.i.g;
492         *input_b = &m_blend_color.i.b;
892493         break;
893494      }
894495
895496      case 3:
896497      {
897         *input_r = &fog_color.i.r;      *input_g = &fog_color.i.g;      *input_b = &fog_color.i.b;
498         *input_r = &m_fog_color.i.r;
499         *input_g = &m_fog_color.i.g;
500         *input_b = &m_fog_color.i.b;
898501         break;
899502      }
900503   }
r7675r7676
903506   {
904507      switch (b & 0x3)
905508      {
906         case 0:      *input_a = &pixel_color.i.a; break;
907         case 1:      *input_a = &fog_color.i.a; break;
908         case 2:      *input_a = &shade_color.i.a; break;
909         case 3:      *input_a = &zero_color.i.a; break;
509         case 0:      *input_a = &m_pixel_color.i.a; break;
510         case 1:      *input_a = &m_fog_color.i.a; break;
511         case 2:      *input_a = &m_shade_color.i.a; break;
512         case 3:      *input_a = &m_zero_color.i.a; break;
910513      }
911514   }
912515   else
913516   {
914517      switch (b & 0x3)
915518      {
916         case 0:      *input_a = &inv_pixel_color.i.a; break;
917         case 1:      *input_a = &memory_color.i.a; break;
918         case 2:      *input_a = &one_color.i.a; break;
919         case 3:      *input_a = &zero_color.i.a; break;
519         case 0:      *input_a = &m_inv_pixel_color.i.a; break;
520         case 1:      *input_a = &m_memory_color.i.a; break;
521         case 2:      *input_a = &m_one_color.i.a; break;
522         case 3:      *input_a = &m_zero_color.i.a; break;
920523      }
921524   }
922525}
923526
924static const UINT8 bayer_matrix[16] =
527const UINT8 N64::RDP::Processor::s_bayer_matrix[16] =
925528{ /* Bayer matrix */
926529    0,  4,  1, 5,
927530    6,  2,  7, 3,
r7675r7676
929532    7,  3,  6, 2
930533};
931534
932static const UINT8 magic_matrix[16] =
535const UINT8 N64::RDP::Processor::s_magic_matrix[16] =
933536{ /* Magic square matrix */
934537    0,  6,  1, 7,
935538    4,  2,  5, 3,
r7675r7676
937540    7,  1,  6, 0
938541};
939542
543const N64::RDP::Processor::ZDecompressEntry N64::RDP::Processor::m_z_decompress_table[8] =
544{
545   { 6, 0x00000 },
546   { 5, 0x20000 },
547   { 4, 0x30000 },
548   { 3, 0x38000 },
549   { 2, 0x3c000 },
550   { 1, 0x3e000 },
551   { 0, 0x3f000 },
552   { 0, 0x3f800 },
553};
554
940555/*****************************************************************************/
941556
942#define XOR_SWAP_BYTE_SHIFT      2
943#define XOR_SWAP_WORD_SHIFT      1
944#define XOR_SWAP_DWORD_SHIFT   0
945
946#define XOR_SWAP_BYTE   4
947#define XOR_SWAP_WORD   2
948#define XOR_SWAP_DWORD   1
949
950/*
951    UINT32 twidth = tile[tilenum].line;
952    UINT32 tbase = tile[tilenum].tmem;
953    UINT32 tpal = tile[tilenum].palette & 0xf;
954
955    if (t < 0) t = 0;
956    if (s < 0) s = 0;
957*/
958
959static INT32 cached_tbase;
960static INT32 cached_twidth;
961static INT32 cached_tpal;
962static INT32 cached_tfetch;
963static INT32 cached_tbase_s1;
964static INT32 cached_twidth_s1;
965
966#define FETCH_TEXEL(s, t) rdp_fetch_texel_func[cached_tfetch](s < 0 ? 0 : s, t < 0 ? 0 : t)
967
968INLINE UINT32 z_decompress(UINT16 *zb)
557void N64::RDP::Processor::BuildCompressedZTable()
969558{
970   UINT32 exponent = (*zb >> 13) & 7;
971   UINT32 mantissa = (*zb >> 2) & 0x7ff;
972   return ((mantissa << z_dec_table[exponent].shift) + z_dec_table[exponent].add);
973}
974
975INLINE void z_build_com_table(void) // Thanks to angrylion, Gonetz and Orkin
976{
977559   for(int j = 0; j < 0x40000; j++)
978560   {
979561      UINT32 exponent = 0;
r7675r7676
986568      }
987569
988570      mantissa = (j >> (6 - (6 < exponent ? 6 : exponent))) & 0x7ff;
989      z_com_table[j] = (UINT16)(((exponent << 11) | mantissa) << 2);
571      m_z_compress_table[j] = (UINT16)(((exponent << 11) | mantissa) << 2);
990572   }
991573}
992574
993INLINE void z_store(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz)
575void N64::RDP::Processor::ZStore(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz)
994576{
995577   UINT8 deltazmem = 15;
996578   z &= 0x3ffff;
r7675r7676
1010592   {
1011593      deltazmem=0;
1012594   }
1013   *zb = z_com_table[z]|(deltazmem>>2);
595   *zb = m_z_compress_table[z] | (deltazmem>>2);
1014596   *zhb = (deltazmem & 3);
1015597}
1016598
1017INLINE UINT16 dz_decompress(UINT16* zb, UINT8* zhb)
599UINT32 N64::RDP::Processor::DecompressZ(UINT16 *zb)
1018600{
601   UINT32 exponent = (*zb >> 13) & 7;
602   UINT32 mantissa = (*zb >> 2) & 0x7ff;
603   return ((mantissa << m_z_decompress_table[exponent].shift) + m_z_decompress_table[exponent].add);
604}
605
606UINT16 N64::RDP::Processor::DecompressDZ(UINT16* zb, UINT8* zhb)
607{
1019608   UINT32 dz_compressed = (((*zb & 3) << 2)|(*zhb & 3));
1020609   return (1 << dz_compressed);
1021610}
1022611
1023#include "video/rdpzcomp.h"
1024
1025#define ZMODE0
1026   #define ANTIALIAS
1027      #define IMGREAD
1028         #include "video/rdpzcomp.c"
1029      #undef IMGREAD
1030         #include "video/rdpzcomp.c"
1031   #undef ANTIALIAS
1032      #define IMGREAD
1033         #include "video/rdpzcomp.c"
1034      #undef IMGREAD
1035         #include "video/rdpzcomp.c"
1036#undef ZMODE0
1037#define ZMODE1
1038   #define ANTIALIAS
1039      #define IMGREAD
1040         #include "video/rdpzcomp.c"
1041      #undef IMGREAD
1042         #include "video/rdpzcomp.c"
1043   #undef ANTIALIAS
1044      #define IMGREAD
1045         #include "video/rdpzcomp.c"
1046      #undef IMGREAD
1047         #include "video/rdpzcomp.c"
1048#undef ZMODE1
1049#define ZMODE2
1050   #define ANTIALIAS
1051      #define IMGREAD
1052         #include "video/rdpzcomp.c"
1053      #undef IMGREAD
1054         #include "video/rdpzcomp.c"
1055   #undef ANTIALIAS
1056      #define IMGREAD
1057         #include "video/rdpzcomp.c"
1058      #undef IMGREAD
1059         #include "video/rdpzcomp.c"
1060#undef ZMODE2
1061#define ZMODE3
1062   #define ANTIALIAS
1063      #define IMGREAD
1064         #include "video/rdpzcomp.c"
1065      #undef IMGREAD
1066         #include "video/rdpzcomp.c"
1067   #undef ANTIALIAS
1068      #define IMGREAD
1069         #include "video/rdpzcomp.c"
1070      #undef IMGREAD
1071         #include "video/rdpzcomp.c"
1072#undef ZMODE3
1073
1074static UINT32 (*z_compare)(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
1075
1076INLINE INT32 normalize_dzpix(INT32 sum)
612INT32 N64::RDP::Processor::NormalizeDZPix(INT32 sum)
1077613{
1078614   if (sum & 0xc000)
1079615   {
r7675r7676
1093629    return 0;
1094630}
1095631
1096INLINE INT32 CLIP(INT32 value,INT32 min,INT32 max)
632bool N64::RDP::Processor::ZCompare(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix)
1097633{
1098   if (value < min)
1099   {
1100      return min;
1101   }
1102   else if(value > max)
1103   {
1104      return max;
1105   }
1106   else
1107   {
1108      return value;
1109   }
1110}
634   int force_coplanar = 0;
635   UINT32 oz = DecompressZ(zb);
636   UINT32 dzmem = DecompressDZ(zb, zhb);
637   UINT32 dznew = 0;
638   UINT32 diff = 0;
639   int precision_factor = (oz >> 15) & 0xf;
640   int cvgcoeff = 0;
641   UINT32 mempixel;
642   UINT32 memory_cvg;
1111643
1112INLINE void video_filter16(int *out_r, int *out_g, int *out_b, UINT16* vbuff, UINT8* hbuff, const UINT32 hres)
1113{
1114
1115   COLOR penumax, penumin, max, min;
1116   UINT16 pix = *vbuff;
1117   const UINT8 centercvg = (*hbuff & 3) + ((pix & 1) << 2) + 1;
1118   UINT32 numoffull = 1;
1119   UINT32 cvg;
1120   UINT32 backr[7], backg[7], backb[7];
1121   UINT32 invr[7], invg[7], invb[7];
1122   INT32 coeff;
1123   INT32 leftup = -hres - 2;
1124   INT32 leftdown = hres - 2;
1125   INT32 toleft = -2;
1126   UINT32 colr, colg, colb;
1127   UINT32 enb;
1128   UINT32 r = ((pix >> 8) & 0xf8) | (pix >> 13);
1129   UINT32 g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1130   UINT32 b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1131
1132   *out_r = *out_g = *out_b = 0;
1133
1134   backr[0] = r;
1135   backg[0] = g;
1136   backb[0] = b;
1137   invr[0] = ~r;
1138   invg[0] = ~g;
1139   invb[0] = ~b;
1140
1141   if (centercvg == 8)
644   sz &= 0x3ffff;
645   if (dzmem == 0x8000 && precision_factor < 3)
1142646   {
1143      *out_r = r;
1144      *out_g = g;
1145      *out_b = b;
1146      return;
647      force_coplanar = 1;
1147648   }
1148
1149   for(int i = 0; i < 5; i++)
649   if (!precision_factor)
1150650   {
1151      pix = vbuff[leftup ^ WORD_ADDR_XOR];
1152      cvg = hbuff[leftup ^ BYTE_ADDR_XOR] & 3;
1153      if(i & 1)
1154      {
1155         if (cvg == 3 && (pix & 1))
1156         {
1157            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
1158            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1159            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1160            invr[numoffull] = ~backr[numoffull];
1161            invg[numoffull] = ~backg[numoffull];
1162            invb[numoffull] = ~backb[numoffull];
1163         }
1164         else
1165         {
1166                backr[numoffull] = invr[numoffull] = 0;
1167            backg[numoffull] = invg[numoffull] = 0;
1168            backb[numoffull] = invb[numoffull] = 0;
1169         }
1170         numoffull++;
1171      }
1172      leftup++;
651      dzmem = ((dzmem << 1) > 16) ? (dzmem << 1) : 16;
1173652   }
1174
1175   for(int i = 0; i < 5; i++)
653   else if (precision_factor == 1)
1176654   {
1177      pix = vbuff[leftdown ^ WORD_ADDR_XOR];
1178      cvg = hbuff[leftdown ^ BYTE_ADDR_XOR] & 3;
1179      if (i&1)
1180      {
1181         if (cvg == 3 && (pix & 1))
1182         {
1183            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
1184            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1185            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1186            invr[numoffull] = ~backr[numoffull];
1187            invg[numoffull] = ~backg[numoffull];
1188            invb[numoffull] = ~backb[numoffull];
1189         }
1190         else
1191         {
1192                backr[numoffull] = invr[numoffull] = 0;
1193            backg[numoffull] = invg[numoffull] = 0;
1194            backb[numoffull] = invb[numoffull] = 0;
1195         }
1196         numoffull++;
1197      }
1198      leftdown++;
655      dzmem = ((dzmem << 1) > 8) ? (dzmem << 1) : 8;
1199656   }
1200
1201   for(int i = 0; i < 5; i++)
657   else if (precision_factor == 2)
1202658   {
1203      pix = vbuff[toleft ^ WORD_ADDR_XOR];
1204      cvg = hbuff[toleft ^ BYTE_ADDR_XOR] & 3;
1205      if (!(i&3))
1206      {
1207         if (cvg == 3 && (pix & 1))
1208         {
1209            backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13);
1210            backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1211            backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1212            invr[numoffull] = ~backr[numoffull];
1213            invg[numoffull] = ~backg[numoffull];
1214            invb[numoffull] = ~backb[numoffull];
1215         }
1216         else
1217         {
1218                backr[numoffull] = invr[numoffull] = 0;
1219            backg[numoffull] = invg[numoffull] = 0;
1220            backb[numoffull] = invb[numoffull] = 0;
1221         }
1222         numoffull++;
1223      }
1224      toleft++;
659      dzmem = ((dzmem << 1) > 4) ? (dzmem << 1) : 4;
1225660   }
1226
1227   video_max(&backr[0], &max.i.r, &enb);
1228   for(int i = 1; i < 7; i++)
661   if (dzmem == 0 && precision_factor < 3)
1229662   {
1230      if (!((enb >> i) & 1))
1231      {
1232         backr[i] = 0;
1233      }
663      dzmem = 0xffff;
1234664   }
1235   video_max(&backg[0], &max.i.g, &enb);
1236   for (int i = 1; i < 7; i++)
665   if (dzmem > 0x8000)
1237666   {
1238      if (!((enb >> i) & 1))
1239      {
1240         backg[i] = 0;
1241      }
667      dzmem = 0xffff;
1242668   }
1243   video_max(&backb[0], &max.i.b, &enb);
1244   for (int i = 1; i < 7; i++)
1245   {
1246      if (!((enb >> i) & 1))
1247      {
1248         backb[i] = 0;
1249      }
1250   }
1251   video_max(&invr[0], &min.i.r, &enb);
1252   for (int i = 1; i < 7; i++)
1253   {
1254      if (!((enb >> i) & 1))
1255      {
1256         backr[i] = 0;
1257      }
1258   }
1259   video_max(&invg[0], &min.i.g, &enb);
1260   for (int i = 1; i < 7; i++)
1261   {
1262      if (!((enb >> i) & 1))
1263      {
1264         backg[i] = 0;
1265      }
1266   }
1267   video_max(&invb[0], &min.i.b, &enb);
1268   for (int i = 1; i < 7; i++)
1269   {
1270      if (!((enb >> i) & 1))
1271      {
1272         backb[i] = 0;
1273      }
1274   }
669   dznew =((dzmem > dzpix) ? dzmem : (UINT32)dzpix) << 3;
670   dznew &= 0x3ffff;
1275671
1276   video_max(&backr[0], &penumax.i.r, &enb);
1277   penumax.i.r = ge_two(enb) ? max.i.r : penumax.i.r;
672   bool farther = ((sz + dznew) >= oz);
673   diff = (sz >= dznew) ? (sz - dznew) : 0;
674   bool nearer = (diff <= oz);
675   bool infront = (sz < oz);
676   bool max = (dzmem == 0x3ffff);
1278677
1279   video_max(&backg[0], &penumax.i.g, &enb);
1280   penumax.i.g = ge_two(enb) ? max.i.g : penumax.i.g;
1281
1282   video_max(&backb[0], &penumax.i.b, &enb);
1283   penumax.i.b = ge_two(enb) ? max.i.b : penumax.i.b;
1284
1285   video_max(&invr[0], &penumin.i.r, &enb);
1286   penumin.i.r = ge_two(enb) ? min.i.r : penumin.i.r;
1287
1288   video_max(&invg[0], &penumin.i.g, &enb);
1289   penumin.i.g = ge_two(enb) ? min.i.g : penumin.i.g;
1290
1291   video_max(&invb[0], &penumin.i.b, &enb);
1292   penumin.i.b = ge_two(enb) ? min.i.b : penumin.i.b;
1293
1294   penumin.i.r = ~penumin.i.r;
1295   penumin.i.g = ~penumin.i.g;
1296   penumin.i.b = ~penumin.i.b;
1297
1298   colr = (UINT32)penumin.i.r + (UINT32)penumax.i.r - (r << 1);
1299   colg = (UINT32)penumin.i.g + (UINT32)penumax.i.g - (g << 1);
1300   colb = (UINT32)penumin.i.b + (UINT32)penumax.i.b - (b << 1);
1301   coeff = 8 - centercvg;
1302   colr = (((colr * coeff) + 4) >> 3) + r;
1303   colg = (((colg * coeff) + 4) >> 3) + g;
1304   colb = (((colb * coeff) + 4) >> 3) + b;
1305
1306   *out_r = colr & 0xff;
1307   *out_g = colg & 0xff;
1308   *out_b = colb & 0xff;
1309   return;
1310}
1311
1312// This needs to be fixed for endianness.
1313INLINE void divot_filter16(UINT8* r, UINT8* g, UINT8* b, UINT16* fbuff, UINT32 fbuff_index)
1314{
1315   UINT8 leftr, leftg, leftb, rightr, rightg, rightb;
1316   UINT16 leftpix, rightpix;
1317   UINT16* next, *prev;
1318   UINT32 Lsw = fbuff_index & 1;
1319   next = (Lsw) ? (UINT16*)(fbuff - 1) : (UINT16*)(fbuff + 3);
1320   prev = (Lsw) ? (UINT16*)(fbuff - 3) : (UINT16*)(fbuff + 1);
1321   leftpix = *prev;
1322   rightpix = *next;
1323
1324   //leftpix = *(fbuff - 1); //for BE targets
1325   //rightpix = *(fbuff + 1);
1326
1327   leftr = ((leftpix >> 8) & 0xf8) | (leftpix >> 13);
1328   leftg = ((leftpix >> 3) & 0xf8) | ((leftpix >>  8) & 0x07);
1329   leftb = ((leftpix << 2) & 0xf8) | ((leftpix >>  3) & 0x07);
1330   rightr = ((rightpix >> 8) & 0xf8) | (rightpix >> 13);
1331   rightg = ((rightpix >> 3) & 0xf8) | ((rightpix >>  8) & 0x07);
1332   rightb = ((rightpix << 2) & 0xf8) | ((rightpix >>  3) & 0x07);
1333   if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr))
678   if (force_coplanar)
1334679   {
1335      *r = leftr; //left = median value
680      farther = nearer = true;
1336681   }
1337   if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr))
1338   {
1339      *r = rightr; //right = median, else *r itself is median
1340   }
1341   if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg))
1342   {
1343      *g = leftg;
1344   }
1345   if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg))
1346   {
1347      *g = rightg;
1348   }
1349   if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb))
1350   {
1351      *b = leftb;
1352   }
1353   if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb))
1354   {
1355      *b = rightb;
1356   }
1357}
1358682
1359INLINE void divot_filter16_buffer(int* r, int* g, int* b, COLOR* vibuffer)
1360{
1361   COLOR leftpix = vibuffer[-1];
1362   COLOR rightpix = vibuffer[1];
1363   COLOR filtered = *vibuffer;
683   m_misc_state.m_curpixel_overlap = 0;
1364684
1365   *r = filtered.i.r;
1366   *g = filtered.i.g;
1367   *b = filtered.i.b;
1368   UINT32 leftr = leftpix.i.r;
1369   UINT32 leftg = leftpix.i.g;
1370   UINT32 leftb = leftpix.i.b;
1371   UINT32 rightr = rightpix.i.r;
1372   UINT32 rightg = rightpix.i.g;
1373   UINT32 rightb = rightpix.i.b;
1374
1375   if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr))
685   switch(m_misc_state.m_fb_size)
1376686   {
1377      *r = leftr; //left = median value
687      case 1: /* Banjo Tooie */
688         memory_cvg = 0; //??
689         break;
690      case 2:
691         mempixel = *(UINT16*)fb;
692         memory_cvg = ((mempixel & 1) << 2) + (*hb & 3);
693         break;
694      case 3:
695         mempixel = *(UINT32*)fb;
696         memory_cvg = (mempixel >> 5) & 7;
697         break;
698      default:
699         fatalerror("z_compare: fb_size = %d",m_misc_state.m_fb_size);
700         break;
1378701   }
1379   if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr))
1380   {
1381      *r = rightr; //right = median, else *r itself is median
1382   }
1383   if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg))
1384   {
1385      *g = leftg;
1386   }
1387   if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg))
1388   {
1389      *g = rightg;
1390   }
1391   if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb))
1392   {
1393      *b = leftb;
1394   }
1395   if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb))
1396   {
1397      *b = rightb;
1398   }
1399702
1400   filtered.i.r = *r;
1401   filtered.i.g = *g;
1402   filtered.i.b = *b;
1403}
1404
1405// Fix me.
1406INLINE void restore_filter16(int* r, int* g, int* b, UINT16* fbuff, UINT32 fbuff_index, UINT32 hres)
1407{
1408   INT32 leftuppix = -hres - 1;
1409   INT32 leftdownpix = hres - 1;
1410   INT32 toleftpix = -1;
1411   UINT8 tempr, tempg, tempb;
1412   UINT16 pix;
1413   int i;
1414
1415   UINT8 r5 = *r;
1416   UINT8 g5 = *g;
1417   UINT8 b5 = *b;
1418   r5 &= ~7;
1419   g5 &= ~7;
1420   b5 &= ~7;
1421
1422   for (i = 0; i < 3; i++)
703   if (!m_other_modes.image_read_en)
1423704   {
1424      pix = fbuff[leftuppix ^ 1];
1425      tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
1426      tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1427      tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1428      tempr &= ~7;
1429      tempg &= ~7;
1430      tempb &= ~7;
1431      if (tempr > r5)
1432      {
1433         *r += 1;
1434      }
1435      if (tempr < r5)
1436      {
1437         *r -= 1;
1438      }
1439      if (tempg > g5)
1440      {
1441         *g += 1;
1442      }
1443      if (tempg < g5)
1444      {
1445         *g -= 1;
1446      }
1447      if (tempb > b5)
1448      {
1449         *b += 1;
1450      }
1451      if (tempb < b5)
1452      {
1453         *b -= 1;
1454      }
1455      leftuppix++;
705      memory_cvg = 7;
1456706   }
1457707
1458   for (i = 0; i < 3; i++)
1459   {
1460      pix = fbuff[leftdownpix ^ 1];
1461      tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
1462      tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1463      tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1464      tempr &= ~7;
1465      tempg &= ~7;
1466      tempb &= ~7;
1467      if (tempr > r5)
1468      {
1469         *r += 1;
1470      }
1471      if (tempr < r5)
1472      {
1473         *r -= 1;
1474      }
1475      if (tempg > g5)
1476      {
1477         *g += 1;
1478      }
1479      if (tempg < g5)
1480      {
1481         *g -= 1;
1482      }
1483      if (tempb > b5)
1484      {
1485         *b += 1;
1486      }
1487      if (tempb < b5)
1488      {
1489         *b -= 1;
1490      }
1491      leftdownpix++;
1492   }
1493   for(i = 0; i < 3; i++)
1494   {
1495      if (!(i & 1))
1496      {
1497         pix = fbuff[toleftpix ^ 1];
1498         tempr = ((pix >> 8) & 0xf8) | (pix >> 13);
1499         tempg = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
1500         tempb = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
1501         tempr &= ~7;
1502         tempg &= ~7;
1503         tempb &= ~7;
1504         if (tempr > r5)
1505         {
1506            *r += 1;
1507         }
1508         if (tempr < r5)
1509         {
1510            *r -= 1;
1511         }
1512         if (tempg > g5)
1513         {
1514            *g += 1;
1515         }
1516         if (tempg < g5)
1517         {
1518            *g -= 1;
1519         }
1520         if (tempb > b5)
1521         {
1522            *b += 1;
1523         }
1524         if (tempb < b5)
1525         {
1526            *b -= 1;
1527         }
1528      }
1529      toleftpix++;
1530   }
1531}
708   bool overflow = ((memory_cvg + m_misc_state.m_curpixel_cvg - 1) > 7);
709   m_misc_state.m_curpixel_overlap = (m_other_modes.force_blend || (!overflow && m_other_modes.antialias_en && farther));
1532710
1533INLINE void restore_filter16_buffer(INT32* r, INT32* g, INT32* b, COLOR* vibuff, UINT32 hres)
1534{
1535   COLOR filtered;
1536   COLOR leftuppix, leftdownpix, leftpix;
1537   COLOR rightuppix, rightdownpix, rightpix;
1538   COLOR uppix, downpix;
1539   INT32 ihres = (INT32)hres; //can't apply unary minus to unsigned
1540
1541   leftuppix = vibuff[-ihres - 1];
1542   leftdownpix = vibuff[ihres - 1];
1543   leftpix = vibuff[-1];
1544
1545   rightuppix = vibuff[-ihres + 1];
1546   rightdownpix = vibuff[ihres + 1];
1547   rightpix = vibuff[1];
1548
1549   uppix = vibuff[-ihres];
1550   downpix = vibuff[ihres];
1551   filtered = *vibuff;
1552
1553   restore_two(&filtered, &leftuppix);
1554   restore_two(&filtered, &uppix);
1555   restore_two(&filtered, &rightuppix);
1556
1557   restore_two(&filtered, &leftpix);
1558   restore_two(&filtered, &rightpix);
1559
1560   restore_two(&filtered, &leftdownpix);
1561   restore_two(&filtered, &downpix);
1562   restore_two(&filtered, &rightdownpix);
1563
1564   *r = filtered.i.r;
1565   *g = filtered.i.g;
1566   *b = filtered.i.b;
1567
1568   *r = CLIP(*r, 0, 0xff);
1569   *g = CLIP(*g, 0, 0xff);
1570   *b = CLIP(*b, 0, 0xff);
1571}
1572
1573// This is wrong, only the 5 upper bits are compared.
1574INLINE void restore_two(COLOR* filtered, COLOR* neighbour)
1575{
1576   if (neighbour->i.r > filtered->i.r)
711   if (m_other_modes.z_mode == 1 && infront && farther && overflow)
1577712   {
1578      filtered->i.r += 1;
713      cvgcoeff = ((dzmem >> dznew) - (sz >> dznew)) & 0xf;
714      m_misc_state.m_curpixel_cvg = ((cvgcoeff * (m_misc_state.m_curpixel_cvg - 1)) >> 3) & 0xf;
1579715   }
1580   if (neighbour->i.r < filtered->i.r)
716   if (m_misc_state.m_curpixel_cvg > 8)
1581717   {
1582      filtered->i.r -= 1;
718      m_misc_state.m_curpixel_cvg = 8;
1583719   }
1584   if (neighbour->i.g > filtered->i.g)
1585   {
1586      filtered->i.g += 1;
1587   }
1588   if (neighbour->i.g < filtered->i.g)
1589   {
1590      filtered->i.g -= 1;
1591   }
1592   if (neighbour->i.b > filtered->i.b)
1593   {
1594      filtered->i.b += 1;
1595   }
1596   if (neighbour->i.b < filtered->i.b)
1597   {
1598      filtered->i.b -= 1;
1599   }
1600}
1601720
1602INLINE void video_max(UINT32* Pixels, UINT8* max, UINT32* enb)
1603{
1604   int pos = 0;
1605   UINT32 temp = 0;
1606   if (Pixels[0] > Pixels[pos])
721   switch(m_other_modes.z_mode)
1607722   {
1608      temp |= 1;
723      case 0: // Opaque
724         return (max || (overflow ? infront : nearer));
725         break;
726      case 1: // Interpenetrating
727         return (max || (overflow ? infront : nearer));
728         break;
729      case 2: // Transparent
730         return (infront || max);
731         break;
732      case 3: // Decal
733         return (farther && nearer && !max);
734         break;
735      default:
736         fatalerror( "z_mode = %d", m_other_modes.z_mode);
737         break;
1609738   }
1610   else if (Pixels[0] < Pixels[pos])
1611   {
1612      temp |= 1;
1613   }
1614
1615   if (Pixels[1] > Pixels[pos])
1616   {
1617      temp |= 2;
1618      pos = 1;
1619   }
1620   else if (Pixels[1] < Pixels[pos])
1621   {
1622      temp |= 2;
1623   }
1624   else
1625   {
1626      pos = 1;
1627   }
1628
1629   if (Pixels[2] > Pixels[pos])
1630   {
1631      temp |= 4;
1632      pos = 2;
1633   }
1634   else if (Pixels[2] < Pixels[pos])
1635   {
1636      temp |= 4;
1637   }
1638   else
1639   {
1640      pos = 2;
1641   }
1642
1643   if (Pixels[3] > Pixels[pos])
1644   {
1645      temp |= 8;
1646      pos = 3;
1647   }
1648   else if (Pixels[3] < Pixels[pos])
1649   {
1650      temp |= 8;
1651   }
1652   else
1653   {
1654      pos = 3;
1655   }
1656
1657   if (Pixels[4] > Pixels[pos])
1658   {
1659      temp |= 16;
1660      pos = 4;
1661   }
1662   else if (Pixels[4] < Pixels[pos])
1663   {
1664      temp |= 16;
1665   }
1666   else
1667   {
1668      pos = 4;
1669   }
1670
1671   if (Pixels[5] > Pixels[pos])
1672   {
1673      temp |= 32;
1674      pos = 5;
1675   }
1676   else if (Pixels[5] < Pixels[pos])
1677   {
1678      temp |= 32;
1679   }
1680   else
1681   {
1682      pos = 5;
1683   }
1684
1685   if (Pixels[6] > Pixels[pos])
1686   {
1687      temp |= 64;
1688      pos = 6;
1689   }
1690   else if (Pixels[6] < Pixels[pos])
1691   {
1692      temp |= 64;
1693   }
1694   else
1695   {
1696      pos = 6;
1697   }
1698
1699   if (Pixels[7] > Pixels[pos])
1700   {
1701      temp |= 128;
1702      pos = 7;
1703   }
1704   else if (Pixels[7] < Pixels[pos])
1705   {
1706      temp |= 128;
1707   }
1708   else
1709   {
1710      pos = 7;
1711   }
1712
1713   *enb = temp;
1714   *max = Pixels[pos];
1715739}
1716740
1717/*
1718INLINE void video_max(UINT32* Pixels, UINT8* max, UINT32* enb)
741UINT32 N64::RDP::Processor::GetLog2(UINT32 lod_clamp)
1719742{
1720    int i;
1721    int pos = 0;
1722    *enb = 0;
1723    for(i = 0; i < 7; i++)
1724    {
1725        if (Pixels[i] > Pixels[pos])
1726        {
1727            *enb += (1 << i);
1728            pos = i;
1729        }
1730        else if (Pixels[i] < Pixels[pos])
1731        {
1732            *enb += (1 << i);
1733        }
1734        else
1735        {
1736            pos = i;
1737        }
1738    }
1739    *max = Pixels[pos];
1740}
1741*/
1742
1743INLINE UINT32 ge_two(UINT32 enb)
1744{
1745   if(enb & 1)
1746   {
1747      if(enb & 2)
1748         return 1;
1749      if(enb & 4)
1750         return 1;
1751      if(enb & 8)
1752         return 1;
1753      if(enb & 16)
1754         return 1;
1755      if(enb & 32)
1756         return 1;
1757      if(enb & 64)
1758         return 1;
1759      if(enb & 128)
1760         return 1;
1761      return 0;
1762   }
1763   else if(enb & 2)
1764   {
1765      if(enb & 4)
1766         return 1;
1767      if(enb & 8)
1768         return 1;
1769      if(enb & 16)
1770         return 1;
1771      if(enb & 32)
1772         return 1;
1773      if(enb & 64)
1774         return 1;
1775      if(enb & 128)
1776         return 1;
1777      return 0;
1778   }
1779   else if(enb & 4)
1780   {
1781      if(enb & 8)
1782         return 1;
1783      if(enb & 16)
1784         return 1;
1785      if(enb & 32)
1786         return 1;
1787      if(enb & 64)
1788         return 1;
1789      if(enb & 128)
1790         return 1;
1791      return 0;
1792   }
1793   else if(enb & 8)
1794   {
1795      if(enb & 16)
1796         return 1;
1797      if(enb & 32)
1798         return 1;
1799      if(enb & 64)
1800         return 1;
1801      if(enb & 128)
1802         return 1;
1803      return 0;
1804   }
1805   else if(enb & 16)
1806   {
1807      if(enb & 32)
1808         return 1;
1809      if(enb & 64)
1810         return 1;
1811      if(enb & 128)
1812         return 1;
1813      return 0;
1814   }
1815   else if(enb & 32)
1816   {
1817      if(enb & 64)
1818         return 1;
1819      if(enb & 128)
1820         return 1;
1821      return 0;
1822   }
1823   else if(enb & 64)
1824   {
1825      if(enb & 128)
1826         return 1;
1827      return 0;
1828   }
1829   return 0;
1830}
1831
1832INLINE void calculate_clamp_diffs(UINT32 prim_tile)
1833{
1834   int start, end;
1835   if (other_modes.tex_lod_en || prim_tile == 7)
1836   {
1837      start = 0;
1838      end = 7;
1839   }
1840   else
1841   {
1842      start = prim_tile;
1843      end = prim_tile + 1;
1844   }
1845   for (; start <= end; start++)
1846   {
1847      clamp_s_diff[start] = (tile[start].sh >> 2) - (tile[start].sl >> 2);
1848      clamp_t_diff[start] = (tile[start].th >> 2) - (tile[start].tl >> 2);
1849   }
1850}
1851
1852INLINE void rgb_dither(INT32* r, INT32* g, INT32* b, int dith)
1853{
1854   if ((*r & 7) > dith)
1855   {
1856      *r = (*r & 0xf8) + 8;
1857      if (*r > 247)
1858         *r = 255;
1859   }
1860   if ((*g & 7) > dith)
1861   {
1862      *g = (*g & 0xf8) + 8;
1863      if (*g > 247)
1864         *g = 255;
1865   }
1866   if ((*b & 7) > dith)
1867   {
1868      *b = (*b & 0xf8) + 8;
1869      if (*b > 247)
1870         *b = 255;
1871   }
1872}
1873
1874INLINE UINT32 getlog2(UINT32 lod_clamp)
1875{
1876743   if (lod_clamp < 2)
1877744   {
1878745      return 0;
r7675r7676
1887754         }
1888755      }
1889756   }
757
1890758   return 0;
1891759}
1892760
1893INLINE void copy_colors(COLOR* dst, COLOR* src)
1894{
1895   dst->c = src->c;
1896}
1897
1898INLINE void BILERP_AND_WRITE(UINT32* src0, UINT32* src1, UINT32* dest)
1899{
1900   UINT32 col0 = *src0;
1901   UINT32 col1 = *src1;
1902   UINT32 r1 = (((col0 >> 16) & 0xff) + ((col1 >> 16) & 0xff))>>1;
1903   UINT32 g1 = (((col0 >> 8) & 0xff) + ((col1 >> 8) & 0xff))>>1;
1904   UINT32 b1 = (((col0 >> 0) & 0xff) + ((col1 >> 0) & 0xff))>>1;
1905   *dest = (r1 << 16) | (g1 << 8) | b1;
1906}
1907
1908INLINE void tcdiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst)
1909{
1910   int w_carry;
1911   int shift;
1912
1913   if (!(sw & 0x7fff))
1914   {
1915      w_carry = 1;
1916   }
1917   else
1918   {
1919      w_carry = 0;
1920   }
1921
1922   sw &= 0x7fff;
1923   for(shift = 1; shift <= 14 && !((sw << shift) & 0x8000); shift++);
1924   shift -= 1;
1925
1926   int normout = ((sw << shift) & 0x3fff) >> 8;
1927   int wnorm = ((sw << shift) & 0xff) << 2;
1928
1929   int tlu_rcp = ((-(NormSlopeRom[normout] * wnorm)) >> 10) + NormPointRom[normout];
1930
1931   if(shift == 14)
1932   {
1933      *sss = (SIGN16(ss) * tlu_rcp) << 1;
1934      *sst = (SIGN16(st) * tlu_rcp) << 1;
1935   }
1936   else
1937   {
1938      int shift_value = 13 - shift;
1939      *sss = (SIGN16(ss) * tlu_rcp) >> shift_value;
1940      *sst = (SIGN16(st) * tlu_rcp) >> shift_value;
1941   }
1942}
1943
1944#ifdef UNUSED_FUNCTION
1945void col_decode16(UINT16* addr, COLOR* col)
1946{
1947   col->i.r = (((*addr >> 11) & 0x1f) << 3) | (((*addr >> 11) & 0x1f) >> 2);
1948   col->i.g = (((*addr >> 6) & 0x1f) << 3) | (((*addr >> 6) & 0x1f) >> 2);
1949   col->i.b = (((*addr >> 1) & 0x1f) << 3) | (((*addr >> 6) & 0x1f) >> 2);
1950   col->i.a = (*addr & 1) ? 0xff : 0;
1951}
1952#endif
1953
1954761/*****************************************************************************/
1955762
1956INLINE int BLENDER1_32(UINT32 *fb, COLOR c)
763static void fill_rectangle_32bit(running_machine *machine, N64::RDP::Rectangle *rect)
1957764{
1958   UINT32 mem = *fb;
1959   int r, g, b;
765   _n64_state *state = (_n64_state *)machine->driver_data;
1960766
1961   // Alpha compare
1962   if (!alpha_compare(c.i.a))
1963   {
1964      return 0;
1965   }
1966   if (!curpixel_cvg)
1967   {
1968      return 0;
1969   }
1970
1971   pixel_color.c = c.c;
1972   //copy_colors(&pixel_color, &c);
1973   if (!other_modes.z_compare_en)
1974   {
1975      curpixel_overlap = 0;
1976   }
1977
1978   //memory_color.c = mem;
1979   memory_color.i.r = (mem >> 24) & 0xff;
1980   memory_color.i.g = (mem >> 16) & 0xff;
1981   memory_color.i.b = (mem >> 8) & 0xff;
1982
1983   if (other_modes.image_read_en)
1984   {
1985      memory_color.i.a = mem & 0xe0;
1986   }
1987   else
1988   {
1989      memory_color.i.a = 0xe0;
1990   }
1991
1992   if (!curpixel_overlap && !other_modes.force_blend)
1993   {
1994      r = *blender1a_r[0];
1995      g = *blender1a_g[0];
1996      b = *blender1a_b[0];
1997   }
1998   else
1999   {
2000      inv_pixel_color.i.a = 0xff - *blender1b_a[0];
2001
2002      if(other_modes.force_blend)
2003      {
2004         BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel0);
2005      }
2006      else
2007      {
2008         BLENDER_EQUATION0_NFORCE(&r, &g, &b, special_bsel0);
2009      }
2010   }
2011
2012   return  (FBWRITE_32(fb,r,g,b));
2013}
2014
2015INLINE int BLENDER2_32(UINT32 *fb, COLOR c1, COLOR c2)
2016{
2017   UINT32 mem = *fb;
2018   int r, g, b;
2019
2020   // Alpha compare
2021   if (!alpha_compare(c2.i.a))
2022   {
2023      return 0;
2024   }
2025   if (!curpixel_cvg)
2026   {
2027      return 0;
2028   }
2029
2030   pixel_color.c = c2.c;
2031   //copy_colors(&pixel_color, &c2);
2032   if (!other_modes.z_compare_en)
2033   {
2034      curpixel_overlap = 0;
2035   }
2036
2037   //memory_color.c = mem;
2038   memory_color.i.r = (mem >>24) & 0xff;
2039   memory_color.i.g = (mem >> 16) & 0xff;
2040   memory_color.i.b = (mem >> 8) & 0xff;
2041
2042   if (other_modes.image_read_en)
2043   {
2044      memory_color.i.a = (mem & 0xe0);
2045   }
2046   else
2047   {
2048      memory_color.i.a = 0xe0;
2049   }
2050
2051   inv_pixel_color.i.a = 0xff - *blender1b_a[0];
2052
2053   if(other_modes.force_blend)
2054   {
2055      BLENDER_EQUATION0_FORCE(&r, &g, &b, special_bsel0);
2056   }
2057   else
2058   {
2059      BLENDER_EQUATION0_NFORCE(&r, &g, &b, special_bsel0);
2060   }
2061
2062   blended_pixel_color.i.r = r;
2063   blended_pixel_color.i.g = g;
2064   blended_pixel_color.i.b = b;
2065
2066   pixel_color.i.r = r;
2067   pixel_color.i.g = g;
2068   pixel_color.i.b = b;
2069
2070   if (!curpixel_overlap && !other_modes.force_blend)
2071   {
2072      r = *blender1a_r[1];
2073      g = *blender1a_g[1];
2074      b = *blender1a_b[1];
2075   }
2076   else
2077   {
2078      inv_pixel_color.i.a = 0xff - *blender1b_a[1];
2079
2080      if(other_modes.force_blend)
2081      {
2082         BLENDER_EQUATION1_FORCE(&r, &g, &b, special_bsel1);
2083      }
2084      else
2085      {
2086         BLENDER_EQUATION1_NFORCE(&r, &g, &b, special_bsel1);
2087      }
2088   }
2089
2090   return  (FBWRITE_32(fb,r,g,b));
2091}
2092
2093static void fill_rectangle_32bit(RECTANGLE *rect)
2094{
2095   UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)];
2096   int x1 = rect->xh;
2097   int x2 = rect->xl;
2098   int y1 = rect->yh;
2099   int y2 = rect->yl;
767   UINT32 *fb = (UINT32*)&rdram[(state->m_rdp.GetMiscState()->m_fb_address / 4)];
768   int x1 = rect->m_xh;
769   int x2 = rect->m_xl;
770   int y1 = rect->m_yh;
771   int y2 = rect->m_yl;
2100772   int fill_cvg = 0;
2101773
2102774   // clip
2103   if (x1 < clip.xh)
775   if (x1 < state->m_rdp.GetScissor()->m_xh)
2104776   {
2105      x1 = clip.xh;
777      x1 = state->m_rdp.GetScissor()->m_xh;
2106778   }
2107   if (y1 < clip.yh)
779   if (y1 < state->m_rdp.GetScissor()->m_yh)
2108780   {
2109      y1 = clip.yh;
781      y1 = state->m_rdp.GetScissor()->m_yh;
2110782   }
2111   if (x2 >= clip.xl)
783   if (x2 >= state->m_rdp.GetScissor()->m_xl)
2112784   {
2113      x2 = clip.xl - 1;
785      x2 = state->m_rdp.GetScissor()->m_xl - 1;
2114786   }
2115   if (y2 >= clip.yl)
787   if (y2 >= state->m_rdp.GetScissor()->m_yl)
2116788   {
2117      y2 = clip.yl - 1;
789      y2 = state->m_rdp.GetScissor()->m_yl - 1;
2118790   }
2119791
2120   shade_color.c = 0;
792   state->m_rdp.GetShadeColor()->c = 0;
2121793
2122   fill_cvg = ((fill_color >> 5) & 7) + 1;
794   fill_cvg = ((state->m_rdp.GetFillColor32() >> 5) & 7) + 1;
2123795
2124   if (other_modes.cycle_type == CYCLE_TYPE_FILL)
796   if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_FILL)
2125797   {
2126798      for (int j = y1; j <= y2; j++)
2127799      {
2128         int index = j * fb_width;
800         int index = j * state->m_rdp.GetMiscState()->m_fb_width;
2129801
2130802         for (int i = x1; i <= x2; i++)
2131803         {
2132            fb[(index + i)^1] = fill_color;
804            fb[(index + i)^1] = state->m_rdp.GetFillColor32();
2133805         }
2134806      }
2135807   }
2136   else if (other_modes.cycle_type == CYCLE_TYPE_1)
808   else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_1)
2137809   {
2138810      for (int j = y1; j <= y2; j++)
2139811      {
2140         COLOR c;
2141         int index = j * fb_width;
812         N64::RDP::Color c1;
813         int index = j * state->m_rdp.GetMiscState()->m_fb_width;
2142814         for (int i = x1; i <= x2; i++)
2143815         {
2144            curpixel_cvg = fill_cvg;
2145            COLOR_COMBINER1(c);
2146            BLENDER1_32(&fb[(index + i)], c);
816            state->m_rdp.GetMiscState()->m_curpixel_cvg = fill_cvg;
817
818            c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1],
819                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1],
820                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1],
821                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]);
822            c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1],
823                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1],
824                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1],
825                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]);
826            c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1],
827                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1],
828                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1],
829                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]);
830            c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1],
831                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1],
832                          *state->m_rdp.GetColorInputs()->combiner_alphamul[1],
833                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]);
834            state->m_rdp.GetAlphaCvg(&c1.i.a);
835
836            state->m_rdp.GetBlender()->Blend(&fb[(index + i)], NULL, c1, *state->m_rdp.GetZero(), 0);
2147837         }
2148838      }
2149839   }
2150   else if (other_modes.cycle_type == CYCLE_TYPE_2)
840   else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2)
2151841   {
2152842      for (int j = y1; j <= y2; j++)
2153843      {
2154         COLOR c1, c2;
2155         int index = j * fb_width;
844         N64::RDP::Color c1, c2;
845         int index = j * state->m_rdp.GetMiscState()->m_fb_width;
2156846         for (int i = x1; i <= x2; i++)
2157847         {
2158            curpixel_cvg = fill_cvg;
2159            COLOR_COMBINER2_C0(c1);
2160            COLOR_COMBINER2_C1(c2);
2161            BLENDER2_32(&fb[(index + i)], c1, c2);
848            state->m_rdp.GetMiscState()->m_curpixel_cvg = fill_cvg;
849
850            c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[0],
851                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[0],
852                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[0],
853                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[0]);
854            c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[0],
855                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[0],
856                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[0],
857                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[0]);
858            c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[0],
859                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[0],
860                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[0],
861                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[0]);
862            c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[0],
863                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[0],
864                          *state->m_rdp.GetColorInputs()->combiner_alphamul[0],
865                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[0]);
866            state->m_rdp.GetCombinedColor()->c = c1.c;
867            c2.c = state->m_rdp.GetTexel0Color()->c;
868            state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexel1Color()->c;
869            state->m_rdp.GetTexel1Color()->c = c2.c;
870            c2.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1],
871                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1],
872                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1],
873                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]);
874            c2.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1],
875                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1],
876                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1],
877                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]);
878            c2.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1],
879                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1],
880                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1],
881                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]);
882            c2.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1],
883                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1],
884                          *state->m_rdp.GetColorInputs()->combiner_alphamul[1],
885                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]);
886            state->m_rdp.GetAlphaCvg(&c2.i.a);
887
888            state->m_rdp.GetBlender()->Blend(&fb[(index + i)], NULL, c1, c2, 0);
889            //BLENDER2_32(&fb[(index + i)], c1, c2);
2162890         }
2163891      }
2164892   }
r7675r7676
2168896   }
2169897}
2170898
2171INLINE void texture_rectangle_32bit(TEX_RECTANGLE *rect)
899INLINE void texture_rectangle_32bit(running_machine *machine, N64::RDP::TexRectangle *rect)
2172900{   // TODO: Z-compare and Z-update
2173   UINT32 *fb = (UINT32*)&rdram[(fb_address / 4)];
901   _n64_state *state = (_n64_state *)machine->driver_data;
2174902
2175   UINT32 tilenum = rect->tilenum;
903   UINT32 *fb = (UINT32*)&rdram[(state->m_rdp.GetMiscState()->m_fb_address / 4)];
904
905   UINT32 tilenum = rect->m_tilenum;
2176906   UINT32 tilenum2 = 0;
2177   TILE *tex_tile = &tile[rect->tilenum];
2178   TILE *tex_tile2 = NULL;
907   N64::RDP::Tile *tex_tile = &state->m_rdp.GetTiles()[rect->m_tilenum];
908   N64::RDP::Tile *tex_tile2 = NULL;
2179909
2180   int x1 = rect->xh;
2181   int x2 = rect->xl;
2182   int y1 = rect->yh;
2183   int y2 = rect->yl;
910   int x1 = rect->m_xh;
911   int x2 = rect->m_xl;
912   int y1 = rect->m_yh;
913   int y2 = rect->m_yl;
2184914
2185   if (other_modes.cycle_type == CYCLE_TYPE_FILL || other_modes.cycle_type == CYCLE_TYPE_COPY)
915   if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_FILL || state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_COPY)
2186916   {
2187      rect->dsdx /= 4;
917      rect->m_dsdx /= 4;
2188918      x2 += 1;
2189919      y2 += 1;
2190920   }
2191921
2192922   // clip
2193   if (x1 < clip.xh)
923   if (x1 < state->m_rdp.GetScissor()->m_xh)
2194924   {
2195      x1 = clip.xh;
925      x1 = state->m_rdp.GetScissor()->m_xh;
2196926   }
2197   if (y1 < clip.yh)
927   if (y1 < state->m_rdp.GetScissor()->m_yh)
2198928   {
2199      y1 = clip.yh;
929      y1 = state->m_rdp.GetScissor()->m_yh;
2200930   }
2201   if (x2 >= clip.xl)
931   if (x2 >= state->m_rdp.GetScissor()->m_xl)
2202932   {
2203      x2 = clip.xl - 1;
933      x2 = state->m_rdp.GetScissor()->m_xl - 1;
2204934   }
2205   if (y2 >= clip.yl)
935   if (y2 >= state->m_rdp.GetScissor()->m_yl)
2206936   {
2207      y2 = clip.yl - 1;
937      y2 = state->m_rdp.GetScissor()->m_yl - 1;
2208938   }
2209939
2210   calculate_clamp_diffs(tex_tile->num);
940   state->m_rdp.GetTexPipe()->CalculateClampDiffs(tex_tile->num);
2211941
2212   if (other_modes.cycle_type == CYCLE_TYPE_2)
942   if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2)
2213943   {
2214      if (!other_modes.tex_lod_en)
944      if (!state->m_rdp.GetOtherModes()->tex_lod_en)
2215945      {
2216946         tilenum2 = (tilenum + 1) & 7;
2217         tex_tile2 = &tile[tilenum2];
947         tex_tile2 = &state->m_rdp.GetTiles()[tilenum2];
2218948      }
2219949      else
2220950      {
2221951         tilenum2 = (tilenum + 1) & 7;
2222         tex_tile2 = &tile[tilenum2];
952         tex_tile2 = &state->m_rdp.GetTiles()[tilenum2];
2223953      }
2224954   }
2225955
2226   shade_color.c = 0;   // Needed by Pilotwings 64
956   state->m_rdp.GetShadeColor()->c = 0;   // Needed by Pilotwings 64
2227957
2228   int t = (int)(rect->t) << 5;
958   int t = (int)(rect->m_t) << 5;
2229959
2230   if (other_modes.cycle_type == CYCLE_TYPE_1)
960   if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_1)
2231961   {
2232      CACHE_TEXTURE_PARAMS(tex_tile);
2233
2234962      for (int j = y1; j < y2; j++)
2235963      {
2236         int fb_index = j * fb_width;
964         int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width;
2237965
2238         int s = (int)(rect->s) << 5;
966         int s = (int)(rect->m_s) << 5;
2239967
2240968         for (int i = x1; i < x2; i++)
2241969         {
2242            COLOR c;
970            N64::RDP::Color c1;
2243971            int ss = s >> 5;
2244972            int st = t >> 5;
2245973
2246            curpixel_cvg = 8;
974            state->m_rdp.GetMiscState()->m_curpixel_cvg = 8;
2247975
2248            if (rect->flip)
976            if (rect->m_flip)
2249977            {
2250               texel0_color.c = TEXTURE_PIPELINE(st, ss, tex_tile);
978               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile);
2251979            }
2252980            else
2253981            {
2254               texel0_color.c = TEXTURE_PIPELINE(ss, st, tex_tile);
982               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile);
2255983            }
2256984
2257            COLOR_COMBINER1(c);
985            c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1],
986                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1],
987                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1],
988                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]);
989            c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1],
990                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1],
991                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1],
992                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]);
993            c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1],
994                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1],
995                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1],
996                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]);
997            c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1],
998                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1],
999                          *state->m_rdp.GetColorInputs()->combiner_alphamul[1],
1000                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]);
1001            state->m_rdp.GetAlphaCvg(&c1.i.a);
22581002
2259            BLENDER1_32(&fb[(fb_index + i)], c);
1003            state->m_rdp.GetBlender()->Blend(&fb[(fb_index + i)], NULL, c1, *state->m_rdp.GetZero(), 0);
22601004
2261            s += rect->dsdx;
1005            s += rect->m_dsdx;
22621006         }
22631007
2264         t += rect->dtdy;
1008         t += rect->m_dtdy;
22651009      }
22661010   }
2267   else if (other_modes.cycle_type == CYCLE_TYPE_2)
1011   else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_2)
22681012   {
22691013      for (int j = y1; j < y2; j++)
22701014      {
2271         int fb_index = j * fb_width;
1015         int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width;
22721016
2273         int s = (int)(rect->s) << 5;
1017         int s = (int)(rect->m_s) << 5;
22741018
22751019         for (int i = x1; i < x2; i++)
22761020         {
2277            COLOR c1, c2;
1021            N64::RDP::Color c1, c2;
22781022            int ss = s >> 5;
22791023            int st = t >> 5;
22801024
2281            curpixel_cvg=8;
1025            state->m_rdp.GetMiscState()->m_curpixel_cvg = 8;
22821026
2283            if (rect->flip)
1027            if (rect->m_flip)
22841028            {
2285               CACHE_TEXTURE_PARAMS(tex_tile);
2286               texel0_color.c = TEXTURE_PIPELINE(st, ss, tex_tile);
2287
2288               CACHE_TEXTURE_PARAMS(tex_tile2);
2289               texel1_color.c = TEXTURE_PIPELINE(st, ss, tex_tile2);
1029               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile);
1030               state->m_rdp.GetTexel1Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile2);
22901031            }
22911032            else
22921033            {
2293               CACHE_TEXTURE_PARAMS(tex_tile);
2294               texel0_color.c = TEXTURE_PIPELINE(ss, st, tex_tile);
2295
2296               CACHE_TEXTURE_PARAMS(tex_tile2);
2297               texel1_color.c = TEXTURE_PIPELINE(ss, st, tex_tile2);
1034               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile);
1035               state->m_rdp.GetTexel1Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile2);
22981036            }
22991037
2300            COLOR_COMBINER2_C0(c1);
2301            COLOR_COMBINER2_C1(c2);
1038            c1.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[0],
1039                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[0],
1040                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[0],
1041                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[0]);
1042            c1.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[0],
1043                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[0],
1044                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[0],
1045                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[0]);
1046            c1.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[0],
1047                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[0],
1048                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[0],
1049                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[0]);
1050            c1.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[0],
1051                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[0],
1052                          *state->m_rdp.GetColorInputs()->combiner_alphamul[0],
1053                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[0]);
1054            state->m_rdp.GetCombinedColor()->c = c1.c;
1055            c2.c = state->m_rdp.GetTexel0Color()->c;
1056            state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexel1Color()->c;
1057            state->m_rdp.GetTexel1Color()->c = c2.c;
1058            c2.i.r = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_r[1],
1059                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_r[1],
1060                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_r[1],
1061                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_r[1]);
1062            c2.i.g = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_g[1],
1063                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_g[1],
1064                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_g[1],
1065                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_g[1]);
1066            c2.i.b = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_rgbsub_a_b[1],
1067                          *state->m_rdp.GetColorInputs()->combiner_rgbsub_b_b[1],
1068                          *state->m_rdp.GetColorInputs()->combiner_rgbmul_b[1],
1069                          *state->m_rdp.GetColorInputs()->combiner_rgbadd_b[1]);
1070            c2.i.a = LookUpCC(*state->m_rdp.GetColorInputs()->combiner_alphasub_a[1],
1071                          *state->m_rdp.GetColorInputs()->combiner_alphasub_b[1],
1072                          *state->m_rdp.GetColorInputs()->combiner_alphamul[1],
1073                          *state->m_rdp.GetColorInputs()->combiner_alphaadd[1]);
1074            state->m_rdp.GetAlphaCvg(&c2.i.a);
23021075
2303            BLENDER2_32(&fb[(fb_index + i)], c1, c2);
1076            state->m_rdp.GetBlender()->Blend(&fb[(fb_index + i)], NULL, c1, c2, 0);
23041077
2305            s += rect->dsdx;
1078            s += rect->m_dsdx;
23061079         }
23071080
2308         t += rect->dtdy;
1081         t += rect->m_dtdy;
23091082      }
23101083   }
2311   else if (other_modes.cycle_type == CYCLE_TYPE_COPY)
1084   else if (state->m_rdp.GetOtherModes()->cycle_type == CYCLE_TYPE_COPY)
23121085   {
2313      CACHE_TEXTURE_PARAMS(tex_tile);
2314
23151086      for (int j = y1; j < y2; j++)
23161087      {
2317         int fb_index = j * fb_width;
1088         int fb_index = j * state->m_rdp.GetMiscState()->m_fb_width;
23181089
2319         int s = (int)(rect->s) << 5;
1090         int s = (int)(rect->m_s) << 5;
23201091
23211092         for (int i = x1; i < x2; i++)
23221093         {
23231094            int ss = s >> 5;
23241095            int st = t >> 5;
2325            if (rect->flip)
1096            if (rect->m_flip)
23261097            {
2327               texel0_color.c = TEXTURE_PIPELINE(st, ss, tex_tile);
1098               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(st, ss, tex_tile);
23281099            }
23291100            else
23301101            {
2331               texel0_color.c = TEXTURE_PIPELINE(ss, st, tex_tile);
1102               state->m_rdp.GetTexel0Color()->c = state->m_rdp.GetTexPipe()->Fetch(ss, st, tex_tile);
23321103            }
23331104
2334            fb[fb_index + i] = (texel0_color.i.r << 24) | (texel0_color.i.g << 16) | (texel0_color.i.b << 8)|1;
1105            fb[fb_index + i] = (state->m_rdp.GetTexel0Color()->i.r << 24) | (state->m_rdp.GetTexel0Color()->i.g << 16) | (state->m_rdp.GetTexel0Color()->i.b << 8)|1;
23351106
2336            s += rect->dsdx;
1107            s += rect->m_dsdx;
23371108         }
23381109
2339         t += rect->dtdy;
1110         t += rect->m_dtdy;
23401111      }
23411112   }
23421113   else
23431114   {
2344      fatalerror("texture_rectangle_32bit: unknown cycle type %d\n", other_modes.cycle_type);
1115      fatalerror("texture_rectangle_32bit: unknown cycle type %d\n", state->m_rdp.GetOtherModes()->cycle_type);
23451116   }
23461117}
23471118
2348
2349static void render_spans_32(int start, int end, TILE* tex_tile, int shade, int texture, int zbuffer, int flip)
2350{
2351   UINT32 *fb = (UINT32*)&rdram[fb_address / 4];
2352   UINT16 *zb = (UINT16*)&rdram[zb_address / 4];
2353   UINT8 *zhb = &hidden_bits[zb_address >> 1];
2354   int tilenum = tex_tile->num;
2355
2356   UINT32 tilenum2 = 0;
2357   TILE *tex_tile2 = NULL;
2358
2359   SPAN_PARAM dr = span[0].dr;
2360   SPAN_PARAM dg = span[0].dg;
2361   SPAN_PARAM db = span[0].db;
2362   SPAN_PARAM da = span[0].da;
2363   SPAN_PARAM dz = span[0].dz;
2364   SPAN_PARAM ds = span[0].ds;
2365   SPAN_PARAM dt = span[0].dt;
2366   SPAN_PARAM dw = span[0].dw;
2367   int dzpix = span[0].dzpix;
2368   int xinc = flip ? 1 : -1;
2369
2370   calculate_clamp_diffs(tilenum);
2371
2372   if (other_modes.cycle_type == CYCLE_TYPE_2 && texture)
2373   {
2374      if (!other_modes.tex_lod_en)
2375      {
2376         tilenum2 = (tilenum + 1) & 7;
2377         tex_tile2 = &tile[tilenum2];
2378      }
2379      else
2380      {
2381         tilenum2 = (tilenum + 1) & 7;
2382         tex_tile2 = &tile[tilenum2];
2383      }
2384   }
2385
2386   if (start < clip.yh)
2387   {
2388      start = clip.yh;
2389   }
2390   if (start >= clip.yl)
2391   {
2392      start = clip.yl - 1;
2393   }
2394   if (end < clip.yh)
2395   {
2396      end = clip.yh;
2397   }
2398   if (end >= clip.yl)
2399   {
2400      end = clip.yl - 1;
2401   }
2402
2403   int drinc = flip ? (dr.w) : -dr.w;
2404   int dginc = flip ? (dg.w) : -dg.w;
2405   int dbinc = flip ? (db.w) : -db.w;
2406   int dainc = flip ? (da.w) : -da.w;
2407   int dzinc = flip ? (dz.w) : -dz.w;
2408   int dsinc = flip ? (ds.w) : -ds.w;
2409   int dtinc = flip ? (dt.w) : -dt.w;
2410   int dwinc = flip ? (dw.w) : -dw.w;
2411
2412   if(!shade)
2413   {
2414      shade_color.c = prim_color.c;
2415   }
2416
2417   CACHE_TEXTURE_PARAMS(tex_tile);
2418
2419   for (int i = start; i <= end; i++)
2420   {
2421      int xstart = span[i].lx;
2422      int xend = span[i].rx;
2423      SPAN_PARAM r = span[i].r;
2424      SPAN_PARAM g = span[i].g;
2425      SPAN_PARAM b = span[i].b;
2426      SPAN_PARAM a = span[i].a;
2427      SPAN_PARAM z = span[i].z;
2428      SPAN_PARAM s = span[i].s;
2429      SPAN_PARAM t = span[i].t;
2430      SPAN_PARAM w = span[i].w;
2431
2432      int x = xend;
2433      int fb_index = fb_width * i;
2434      int length = flip ? (xstart - xend) : (xend - xstart);
2435
2436      for (int j = 0; j <= length; j++)
2437      {
2438         UINT32 sz = z.w >> 13;
2439         if (other_modes.z_source_sel)
2440         {
2441            sz = (((UINT32)primitive_z) << 3) & 0x3ffff;
2442            dzpix = primitive_delta_z;
2443         }
2444
2445         if (x >= clip.xh && x < clip.xl)
2446         {
2447            curpixel_cvg = span[i].cvg[x];
2448            if (curpixel_cvg)
2449            {
2450               COLOR c1, c2;
2451               int curpixel = fb_index + x;
2452               UINT32* fbcur = &fb[curpixel];
2453               UINT16* zbcur = &zb[curpixel ^ WORD_ADDR_XOR];
2454               UINT8* zhbcur = &zhb[curpixel ^ BYTE_ADDR_XOR];
2455               UINT8* hbcur = 0;
2456               int z_compare_result = 1;
2457
2458               c1.i.r = c1.i.g = c1.i.b = c1.i.a = 0;
2459               c2.i.r = c2.i.g = c2.i.b = c2.i.a = 0;
2460
2461               if (shade)
2462               {
2463                  int sr = r.h.h;
2464                  int sg = g.h.h;
2465                  int sb = b.h.h;
2466                  int sa = a.h.h;
2467
2468                  // Needed by Superman
2469                  if (sr > 0xff) sr = 0xff;
2470                  if (sg > 0xff) sg = 0xff;
2471                  if (sb > 0xff) sb = 0xff;
2472                  if (sa > 0xff) sa = 0xff;
2473                  if (sr < 0) sr = 0;
2474                  if (sg < 0) sg = 0;
2475                  if (sb < 0) sb = 0;
2476                  if (sa < 0) sa = 0;
2477                  shade_color.i.r = sr;
2478                  shade_color.i.g = sg;
2479                  shade_color.i.b = sb;
2480                  shade_color.i.a = sa;
2481               }
2482
2483               if (texture)
2484               {
2485                  int ss = s.h.h;
2486                  int st = t.h.h;
2487                  int sw = w.h.h;
2488                  int sss = 0;
2489                  int sst = 0;
2490
2491                  if (other_modes.persp_tex_en)
2492                  {
2493                     tcdiv(ss, st, sw, &sss, &sst);
2494                  }
2495                  else
2496                  {
2497                     sss = ss;
2498                     sst = st;
2499                  }
2500
2501                  if (other_modes.cycle_type == CYCLE_TYPE_1)
2502                  {
2503                     texel0_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile);
2504                  }
2505                  else
2506                  {
2507                     CACHE_TEXTURE_PARAMS(tex_tile);
2508                     texel0_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile);
2509
2510                     CACHE_TEXTURE_PARAMS(tex_tile2);
2511                     texel1_color.c = TEXTURE_PIPELINE(sss, sst, tex_tile2);
2512                  }
2513               }
2514
2515               if (other_modes.cycle_type == CYCLE_TYPE_1)
2516               {
2517                  COLOR_COMBINER1(c1);
2518               }
2519               else if (other_modes.cycle_type == CYCLE_TYPE_2)
2520               {
2521                  COLOR_COMBINER2_C0(c1);
2522                  COLOR_COMBINER2_C1(c2);
2523               }
2524
2525               if ((zbuffer || other_modes.z_source_sel) && other_modes.z_compare_en)
2526               {
2527                  z_compare_result = z_compare(fbcur, hbcur, zbcur, zhbcur, sz, dzpix);
2528               }
2529
2530               if(z_compare_result)
2531               {
2532                  int rendered = 0;
2533
2534                  if (other_modes.cycle_type == CYCLE_TYPE_1)
2535                  {
2536                     rendered = BLENDER1_32(fbcur, c1);
2537                  }
2538                      else
2539                      {
2540                     rendered = BLENDER2_32(fbcur, c1, c2);
2541                  }
2542
2543                  if (other_modes.z_update_en && rendered)
2544                  {
2545                     z_store(zbcur, zhbcur, sz, dzpix);
2546                  }
2547               }
2548            }
2549         }
2550
2551         r.w += drinc;
2552         g.w += dginc;
2553         b.w += dbinc;
2554         a.w += dainc;
2555         z.w += dzinc;
2556         s.w += dsinc;
2557         t.w += dtinc;
2558         w.w += dwinc;
2559
2560         x += xinc;
2561      }
2562   }
2563}
2564
25651119/*****************************************************************************/
25661120
2567/*
2568static void triangle(UINT32 w1, UINT32 w2, int shade, int texture, int zbuffer)
1121UINT32 N64::RDP::Processor::ReadData(UINT32 address)
25691122{
2570    int j;
2571    int xleft, xright, xleft_inc, xright_inc;
2572    int xstart, xend;
2573    int r = 0, g = 0, b = 0, a = 0, z = 0, s = 0, t = 0, w = 0;
2574    int dr, dg, db, da;
2575    int drdx = 0, dgdx = 0, dbdx = 0, dadx = 0, dzdx = 0, dsdx = 0, dtdx = 0, dwdx = 0;
2576    int drdy = 0, dgdy = 0, dbdy = 0, dady = 0, dzdy = 0, dsdy = 0, dtdy = 0, dwdy = 0;
2577    int drde = 0, dgde = 0, dbde = 0, dade = 0, dzde = 0, dsde = 0, dtde = 0, dwde = 0;
2578    int tilenum;
2579    int flip = (w1 & 0x800000) ? 1 : 0;
2580
2581    INT32 yl, ym, yh;
2582    INT32 xl, xm, xh;
2583    INT32 dxldy, dxhdy, dxmdy;
2584    int dzdy_dz, dzdx_dz;
2585    int dsdylod, dtdylod;
2586    UINT32 w3, w4, w5, w6, w7, w8;
2587
2588    int k = 0;
2589
2590    INT32 limcvg = 0;
2591    INT32 startcvg = 0;
2592
2593    int sign_dxldy = 0;
2594    int sign_dxmdy = 0;
2595    int samesign = 0;
2596
2597    int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0;
2598    int sign_dxhdy = 0;
2599
2600    int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0, dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0;
2601    int do_offset = 0;
2602
2603    int xfrac = 0;
2604    int dseoff = 0, dteoff = 0, dweoff = 0, dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0, dzeoff = 0;
2605
2606    int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0;
2607
2608    int m_inc;
2609    UINT32 min=0, max=3;
2610    INT32 maxxmx = 0, minxmx = 0, maxxhx = 0, minxhx = 0;
2611
2612    int spix = 0; // Current subpixel
2613    int ycur;
2614    int ylfar;
2615    int ldflag;
2616    int yhpix;
2617    int ympix;
2618    int ylpix;
2619
2620    int shade_base = rdp_cmd_cur + 8;
2621    int texture_base = rdp_cmd_cur + 8;
2622    int zbuffer_base = rdp_cmd_cur + 8;
2623
2624    if (shade)
2625    {
2626        texture_base += 16;
2627        zbuffer_base += 16;
2628    }
2629    if (texture)
2630    {
2631        zbuffer_base += 16;
2632    }
2633
2634    w3 = rdp_cmd_data[rdp_cmd_cur+2];
2635    w4 = rdp_cmd_data[rdp_cmd_cur+3];
2636    w5 = rdp_cmd_data[rdp_cmd_cur+4];
2637    w6 = rdp_cmd_data[rdp_cmd_cur+5];
2638    w7 = rdp_cmd_data[rdp_cmd_cur+6];
2639    w8 = rdp_cmd_data[rdp_cmd_cur+7];
2640
2641    yl = (w1 & 0x3fff);
2642    ym = ((w2 >> 16) & 0x3fff);
2643    yh = ((w2 >>  0) & 0x3fff);
2644    xl = (INT32)(w3 & 0x3fffffff);
2645    xh = (INT32)(w5 & 0x3fffffff);
2646    xm = (INT32)(w7 & 0x3fffffff);
2647    // Inverse slopes in 16.16 format
2648    dxldy = (INT32)(w4);
2649    dxhdy = (INT32)(w6);
2650    dxmdy = (INT32)(w8);
2651
2652    max_level = ((w1 >> 19) & 7);
2653    tilenum = (w1 >> 16) & 0x7;
2654
2655    if (yl & 0x2000)  yl |= 0xffffc000;
2656    if (ym & 0x2000)  ym |= 0xffffc000;
2657    if (yh & 0x2000)  yh |= 0xffffc000;
2658
2659    if (xl & 0x20000000)  xl |= 0xc0000000;
2660    if (xm & 0x20000000)  xm |= 0xc0000000;
2661    if (xh & 0x20000000)  xh |= 0xc0000000;
2662
2663    z = 0;
2664    s = 0;  t = 0;  w = 0;
2665    dr = 0;     dg = 0;     db = 0;     da = 0;
2666
2667    if (shade)
2668    {
2669        r    = (rdp_cmd_data[shade_base+0 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
2670        g    = ((rdp_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+4 ] & 0x0000ffff);
2671        b    = (rdp_cmd_data[shade_base+1 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
2672        a    = ((rdp_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+5 ] & 0x0000ffff);
2673        drdx = (rdp_cmd_data[shade_base+2 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
2674        dgdx = ((rdp_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+6 ] & 0x0000ffff);
2675        dbdx = (rdp_cmd_data[shade_base+3 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
2676        dadx = ((rdp_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+7 ] & 0x0000ffff);
2677        drde = (rdp_cmd_data[shade_base+8 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
2678        dgde = ((rdp_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+12] & 0x0000ffff);
2679        dbde = (rdp_cmd_data[shade_base+9 ] & 0xffff0000) | ((rdp_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
2680        dade = ((rdp_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+13] & 0x0000ffff);
2681        drdy = (rdp_cmd_data[shade_base+10] & 0xffff0000) | ((rdp_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
2682        dgdy = ((rdp_cmd_data[shade_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+14] & 0x0000ffff);
2683        dbdy = (rdp_cmd_data[shade_base+11] & 0xffff0000) | ((rdp_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
2684        dady = ((rdp_cmd_data[shade_base+11] << 16) & 0xffff0000) | (rdp_cmd_data[shade_base+15] & 0x0000ffff);
2685    }
2686    if (texture)
2687    {
2688        s    = (rdp_cmd_data[texture_base+0 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
2689        t    = ((rdp_cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+4 ] & 0x0000ffff);
2690        w    = (rdp_cmd_data[texture_base+1 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
2691        dsdx = (rdp_cmd_data[texture_base+2 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
2692        dtdx = ((rdp_cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+6 ] & 0x0000ffff);
2693        dwdx = (rdp_cmd_data[texture_base+3 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
2694        dsde = (rdp_cmd_data[texture_base+8 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
2695        dtde = ((rdp_cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+12] & 0x0000ffff);
2696        dwde = (rdp_cmd_data[texture_base+9 ] & 0xffff0000) | ((rdp_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
2697        dsdy = (rdp_cmd_data[texture_base+10] & 0xffff0000) | ((rdp_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
2698        dtdy = ((rdp_cmd_data[texture_base+10] << 16) & 0xffff0000) | (rdp_cmd_data[texture_base+14] & 0x0000ffff);
2699        dwdy = (rdp_cmd_data[texture_base+11] & 0xffff0000) | ((rdp_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
2700    }
2701    if (zbuffer)
2702    {
2703        z    = rdp_cmd_data[zbuffer_base+0];
2704        dzdx = rdp_cmd_data[zbuffer_base+1];
2705        dzde = rdp_cmd_data[zbuffer_base+2];
2706        dzdy = rdp_cmd_data[zbuffer_base+3];
2707    }
2708
2709    span[0].ds.w = dsdx;
2710    span[0].dt.w = dtdx;
2711    span[0].dw.w = dwdx;
2712    span[0].dr.w = drdx & ~0x1f;
2713    span[0].dg.w = dgdx & ~0x1f;
2714    span[0].db.w = dbdx & ~0x1f;
2715    span[0].da.w = dadx & ~0x1f;
2716    span[0].dz.w = dzdx;
2717    dzdy_dz = (dzdy >> 16) & 0xffff;
2718    dzdx_dz = (dzdx >> 16) & 0xffff;
2719    span[0].dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
2720    span[0].dzpix = normalize_dzpix(span[0].dzpix);
2721    dsdylod = dsdy >> 16;
2722    dtdylod = dtdy >> 16;
2723    if (dsdylod & 0x20000)
2724    {
2725        dsdylod = ~dsdylod & 0x1ffff;
2726    }
2727    if (dtdylod & 0x20000)
2728    {
2729        dtdylod = ~dtdylod & 0x1ffff;
2730    }
2731    span[0].dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
2732
2733    xleft_inc = dxmdy >> 2;
2734    xright_inc = dxhdy >> 2;
2735
2736    xright = xh;
2737    xleft = xm;
2738
2739    limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
2740    if (limcvg < 0)
2741    {
2742        limcvg = 0;
2743    }
2744
2745    startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
2746    for (k = startcvg; k <= limcvg; k++)
2747    {
2748        memset((void*)&span[k].cvg[0],0,640);
2749    }
2750
2751    sign_dxldy = (dxldy & 0x80000000) ? 1 : 0;
2752    sign_dxmdy = (dxmdy & 0x80000000) ? 1 : 0;
2753    samesign = !(sign_dxldy ^ sign_dxmdy);
2754
2755    sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
2756
2757    do_offset = !(sign_dxhdy ^ (flip));
2758
2759    if (do_offset)
2760    {
2761        dsdeh = dsde >> 9;  dsdyh = dsdy >> 9;
2762        dtdeh = dtde >> 9;  dtdyh = dtdy >> 9;
2763        dwdeh = dwde >> 9;  dwdyh = dwdy >> 9;
2764        drdeh = drde >> 9;  drdyh = drdy >> 9;
2765        dgdeh = dgde >> 9;  dgdyh = dgdy >> 9;
2766        dbdeh = dbde >> 9;  dbdyh = dbdy >> 9;
2767        dadeh = dade >> 9;  dadyh = dady >> 9;
2768        dzdeh = dzde >> 9;  dzdyh = dzdy >> 9;
2769
2770        dsdiff = (dsdeh*3 - dsdyh*3) << 7;
2771        dtdiff = (dtdeh*3 - dtdyh*3) << 7;
2772        dwdiff = (dwdeh*3 - dwdyh*3) << 7;
2773        drdiff = (drdeh*3 - drdyh*3) << 7;
2774        dgdiff = (dgdeh*3 - dgdyh*3) << 7;
2775        dbdiff = (dbdeh*3 - dbdyh*3) << 7;
2776        dadiff = (dadeh*3 - dadyh*3) << 7;
2777        dzdiff = (dzdeh*3 - dzdyh*3) << 7;
2778    }
2779    else
2780    {
2781        dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0;
2782    }
2783
2784    if (do_offset)
2785    {
2786        dseoff = (dsdeh*3) << 7;
2787        dteoff = (dtdeh*3) << 7;
2788        dweoff = (dwdeh*3) << 7;
2789        dreoff = (drdeh*3) << 7;
2790        dgeoff = (dgdeh*3) << 7;
2791        dbeoff = (dbdeh*3) << 7;
2792        daeoff = (dadeh*3) << 7;
2793        dzeoff = (dzdeh*3) << 7;
2794    }
2795    else
2796    {
2797        dseoff = dteoff = dweoff = dreoff = dgeoff = dbeoff = daeoff = dzeoff = 0;
2798    }
2799#define adjust_deoff_only()     \
2800{                           \
2801            span[j].s = s + dseoff;             \
2802            span[j].t = t + dteoff;             \
2803            span[j].w = w + dweoff;             \
2804            span[j].r = r + dreoff;             \
2805            span[j].g = g + dgeoff;             \
2806            span[j].b = b + dbeoff;             \
2807            span[j].a = a + daeoff;             \
2808            span[j].z = z + dzeoff;             \
2809}
2810
2811#define addleft(x) addleftcvg(x,k)
2812#define addright(x) addrightcvg(x,k)
2813#define setvalues() {                   \
2814            addvalues();                \
2815            adjust_attr();  \
2816}
2817
2818    dsdxh = dsdx >> 8;
2819    dtdxh = dtdx >> 8;
2820    dwdxh = dwdx >> 8;
2821    drdxh = drdx >> 8;
2822    dgdxh = dgdx >> 8;
2823    dbdxh = dbdx >> 8;
2824    dadxh = dadx >> 8;
2825    dzdxh = dzdx >> 8;
2826
2827#define adjust_attr()       \
2828{                           \
2829            span[j].s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;               \
2830            span[j].t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;               \
2831            span[j].w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;               \
2832            span[j].r.w = r + drdiff - (xfrac * drdxh);             \
2833            span[j].g.w = g + dgdiff - (xfrac * dgdxh);             \
2834            span[j].b.w = b + dbdiff - (xfrac * dbdxh);             \
2835            span[j].a.w = a + dadiff - (xfrac * dadxh);             \
2836            span[j].z.w = z + dzdiff - (xfrac * dzdxh);             \
2837}
2838
2839#define adjust_diffonly()       \
2840{                           \
2841            span[j].s = s + dsdiff;             \
2842            span[j].t = t + dtdiff;             \
2843            span[j].w = w + dwdiff;             \
2844            span[j].r = r + drdiff;             \
2845            span[j].g = g + dgdiff;             \
2846            span[j].b = b + dbdiff;             \
2847            span[j].a = a + dadiff;             \
2848            span[j].z = z + dzdiff;             \
2849}
2850
2851#define addvalues() {   \
2852            s += dsde;  \
2853            t += dtde;  \
2854            w += dwde; \
2855            r += drde; \
2856            g += dgde; \
2857            b += dbde; \
2858            a += dade; \
2859            z += dzde; \
2860}
2861
2862#define justassign()        \
2863{                           \
2864            span[j].s = s & ~0x1f;              \
2865            span[j].t = t & ~0x1f;              \
2866            span[j].w = w & ~0x1f;              \
2867            span[j].r = r;              \
2868            span[j].g = g;              \
2869            span[j].b = b;              \
2870            span[j].a = a;              \
2871            span[j].z = z;              \
2872}
2873
2874    m_inc = flip ? 1 : -1;
2875
2876    ycur =  yh & ~3;
2877    ylfar = yl | 3;
2878    ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
2879    yhpix = yh >> 2;
2880    ympix = ym >> 2;
2881    ylpix = yl >> 2;
2882
2883    for (k = ycur; k <= ylfar; k++)
2884    {
2885        if (k == ym)
2886        {
2887            xleft = xl;
2888            xleft_inc = dxldy >> 2;
2889        }
2890
2891        xstart = xleft >> 16;
2892        xend = xright >> 16;
2893        j = k >> 2;
2894        spix = k & 3;
2895
2896        if (k >= 0 && k < 0x1000)
2897        {
2898            int m = 0;
2899            int n = 0;
2900            int length = 0;
2901            min = 0; max = 3;
2902            if (j == yhpix)
2903            {
2904                min = yh & 3;
2905            }
2906            if (j == ylpix)
2907            {
2908                max = yl & 3;
2909            }
2910            if (spix >= min && spix <= max)
2911            {
2912                if (spix == min)
2913                {
2914                    minxmx = maxxmx = xstart;
2915                    minxhx = maxxhx = xend;
2916                }
2917                else
2918                {
2919                    minxmx = (xstart < minxmx) ? xstart : minxmx;
2920                    maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
2921                    minxhx = (xend < minxhx) ? xend : minxhx;
2922                    maxxhx = (xend > maxxhx) ? xend : maxxhx;
2923                }
2924            }
2925
2926            if (spix == max)
2927            {
2928                if (flip)
2929                {
2930                    span[j].lx = maxxmx;
2931                    span[j].rx = minxhx;
2932                }
2933                else
2934                {
2935                    span[j].lx = minxmx;
2936                    span[j].rx = maxxhx;
2937                }
2938            }
2939
2940            length = flip ? (xstart - xend) : (xend - xstart);
2941
2942            if (spix == ldflag)
2943            {
2944                xfrac = ((xright >> 8) & 0xff);
2945                adjust_attr();
2946            }
2947
2948            m = flip ? (xend+1) : (xend-1);
2949
2950            if (k >= yh && length >= 0 && k <= yl)
2951            {
2952                if (xstart>=0 && xstart <1024)
2953                {
2954                    if (!flip)
2955                    {
2956                        span[j].cvg[xstart] += addleft(xleft);
2957                    }
2958                    else
2959                    {
2960                        span[j].cvg[xstart] += addright(xleft);
2961                    }
2962                }
2963                if (xend>=0 && xend<1024)
2964                {
2965                    if (xstart != xend)
2966                    {
2967                        if (!flip)
2968                        {
2969                            span[j].cvg[xend] += addright(xright);
2970                        }
2971                        else
2972                        {
2973                            span[j].cvg[xend] += addleft(xright);
2974                        }
2975                    }
2976                    else
2977                    {
2978                        if (!flip)
2979                        {
2980                            span[j].cvg[xend] -= (2 - addright(xright));
2981                        }
2982                        else
2983                        {
2984                            span[j].cvg[xend] -= (2 - addleft(xright));
2985                        }
2986                        if (span[j].cvg[xend] > 200)
2987                        {
2988                            span[j].cvg[xend] = 0;
2989                        }
2990                    }
2991                }
2992                for (n = 0; n < (length - 1); n++)
2993                {
2994                    if (m>=0 && m < 640)
2995                    {
2996                        span[j].cvg[m] += 2;
2997                    }
2998
2999                    m += m_inc;
3000                }
3001            }
3002        }
3003
3004        if (spix == 3)
3005        {
3006            addvalues();
3007        }
3008        xleft += xleft_inc;
3009        xright += xright_inc;
3010    }
3011
3012    switch (fb_size) // 8bpp needs to be implemented
3013    {
3014        case PIXEL_SIZE_16BIT:  render_spans_16(yh>>2, yl>>2, &tile[tilenum], shade, texture, zbuffer, flip); break;
3015        case PIXEL_SIZE_32BIT:  render_spans_32(yh>>2, yl>>2, &tile[tilenum], shade, texture, zbuffer, flip); break;
3016        default: break; // V-Rally2 does this, fb_size=0
3017    }
3018}
3019*/
3020
3021/*****************************************************************************/
3022
3023INLINE UINT32 READ_RDP_DATA(UINT32 address)
3024{
3025   if (dp_status & 0x1)      // XBUS_DMEM_DMA enabled
1123   if (m_status & 0x1)      // XBUS_DMEM_DMA enabled
30261124   {
30271125      return rsp_dmem[(address & 0xfff) / 4];
30281126   }
r7675r7676
31031201   8         // 0x3f, Set_Color_Image
31041202};
31051203
3106static int rdp_dasm(char *buffer)
1204void N64::RDP::Processor::Dasm(char *buffer)
31071205{
31081206   int i;
31091207   int tile;
r7675r7676
31251223   UINT32 length;
31261224   UINT32 command;
31271225
3128   length = rdp_cmd_ptr * 4;
1226   length = m_cmd_ptr * 4;
31291227   if (length < 8)
31301228   {
31311229      sprintf(buffer, "ERROR: length = %d\n", length);
3132      return 0;
1230      return;
31331231   }
31341232
3135   cmd[0] = rdp_cmd_data[rdp_cmd_cur+0];
3136   cmd[1] = rdp_cmd_data[rdp_cmd_cur+1];
1233   cmd[0] = m_cmd_data[m_cmd_cur+0];
1234   cmd[1] = m_cmd_data[m_cmd_cur+1];
31371235
31381236   tile = (cmd[1] >> 24) & 0x7;
31391237   sprintf(sl, "%4.2f", (float)((cmd[0] >> 12) & 0xfff) / 4.0f);
r7675r7676
31601258         if (length != rdp_command_length[command])
31611259         {
31621260            sprintf(buffer, "ERROR: Tri_NoShade length = %d\n", length);
3163            return 0;
1261            return;
31641262         }
31651263
3166         cmd[2] = rdp_cmd_data[rdp_cmd_cur+2];
3167         cmd[3] = rdp_cmd_data[rdp_cmd_cur+3];
3168         cmd[4] = rdp_cmd_data[rdp_cmd_cur+4];
3169         cmd[5] = rdp_cmd_data[rdp_cmd_cur+5];
3170         cmd[6] = rdp_cmd_data[rdp_cmd_cur+6];
3171         cmd[7] = rdp_cmd_data[rdp_cmd_cur+7];
1264         cmd[2] = m_cmd_data[m_cmd_cur+2];
1265         cmd[3] = m_cmd_data[m_cmd_cur+3];
1266         cmd[4] = m_cmd_data[m_cmd_cur+4];
1267         cmd[5] = m_cmd_data[m_cmd_cur+5];
1268         cmd[6] = m_cmd_data[m_cmd_cur+6];
1269         cmd[7] = m_cmd_data[m_cmd_cur+7];
31721270
31731271         sprintf(yl,      "%4.4f", (float)((cmd[0] >>  0) & 0x1fff) / 4.0f);
31741272         sprintf(ym,      "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
r7675r7676
31901288         if (length < rdp_command_length[command])
31911289         {
31921290            sprintf(buffer, "ERROR: Tri_Tex length = %d\n", length);
3193            return 0;
1291            return;
31941292         }
31951293
31961294         for (i=2; i < 24; i++)
31971295         {
3198            cmd[i] = rdp_cmd_data[rdp_cmd_cur+i];
1296            cmd[i] = m_cmd_data[m_cmd_cur+i];
31991297         }
32001298
32011299         sprintf(yl,      "%4.4f", (float)((cmd[0] >>  0) & 0x1fff) / 4.0f);
r7675r7676
32401338         if (length != rdp_command_length[command])
32411339         {
32421340            sprintf(buffer, "ERROR: Tri_Shade length = %d\n", length);
3243            return 0;
1341            return;
32441342         }
32451343
32461344         for (i=2; i < 24; i++)
32471345         {
3248            cmd[i] = rdp_cmd_data[i];
1346            cmd[i] = m_cmd_data[i];
32491347         }
32501348
32511349         sprintf(yl,      "%4.4f", (float)((cmd[0] >>  0) & 0x1fff) / 4.0f);
r7675r7676
32921390         if (length < rdp_command_length[command])
32931391         {
32941392            sprintf(buffer, "ERROR: Tri_TexShade length = %d\n", length);
3295            return 0;
1393            return;
32961394         }
32971395
32981396         for (i=2; i < 40; i++)
32991397         {
3300            cmd[i] = rdp_cmd_data[rdp_cmd_cur+i];
1398            cmd[i] = m_cmd_data[m_cmd_cur+i];
33011399         }
33021400
33031401         sprintf(yl,      "%4.4f", (float)((cmd[0] >>  0) & 0x1fff) / 4.0f);
r7675r7676
33661464         if (length < 16)
33671465         {
33681466            sprintf(buffer, "ERROR: Texture_Rectangle length = %d\n", length);
3369            return 0;
1467            return;
33701468         }
3371         cmd[2] = rdp_cmd_data[rdp_cmd_cur+2];
3372         cmd[3] = rdp_cmd_data[rdp_cmd_cur+3];
1469         cmd[2] = m_cmd_data[m_cmd_cur+2];
1470         cmd[3] = m_cmd_data[m_cmd_cur+3];
33731471         sprintf(s,    "%4.4f", (float)(INT16)((cmd[2] >> 16) & 0xffff) / 32.0f);
33741472         sprintf(t,    "%4.4f", (float)(INT16)((cmd[2] >>  0) & 0xffff) / 32.0f);
33751473         sprintf(dsdx, "%4.4f", (float)(INT16)((cmd[3] >> 16) & 0xffff) / 1024.0f);
r7675r7676
34061504      case 0x3f:   sprintf(buffer, "Set_Color_Image        %s, %s, %d, %08X", format, size, (cmd[0] & 0x1ff)+1, cmd[1]); break;
34071505      default:   sprintf(buffer, "??? (%08X %08X)", cmd[0], cmd[1]); break;
34081506   }
1507}
34091508
3410   return rdp_command_length[command];
1509/*****************************************************************************/
1510
1511N64::RDP::Triangle::Triangle(running_machine *machine, bool shade, bool texture, bool zbuffer)
1512{
1513   InitFromData(machine, shade, texture, zbuffer);
34111514}
34121515
1516void N64::RDP::Triangle::InitFromData(running_machine *machine, bool shade, bool texture, bool zbuffer)
1517{
1518   m_machine = machine;
1519   m_rdp = &((_n64_state *)machine->driver_data)->m_rdp;
1520   m_cmd_data = m_rdp->GetCommandData();
1521   m_misc_state = m_rdp->GetMiscState();
1522   m_shade = shade;
1523   m_texture = texture;
1524   m_zbuffer = zbuffer;
1525}
1526
1527void N64::RDP::Triangle::Draw()
1528{
1529   UINT32 w1 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+0];
1530   UINT32 w2 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+1];
1531
1532   int flip = (w1 & 0x800000) ? 1 : 0;
1533   int sign = (w1 & 0x800000) ? -1 : 1;
1534   int inv_sign = (w1 & 0x800000) ?  1 : -1;
1535
1536   int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0;
1537   int dseoff = 0, dteoff = 0, dweoff = 0, dreoff = 0, dgeoff = 0, dbeoff = 0, daeoff = 0, dzeoff = 0;
1538   int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0;
1539   int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0;
1540   int dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0;
1541   int xfrac = 0;
1542
1543   INT32 maxxmx = 0;
1544   INT32 minxmx = 0;
1545   INT32 maxxhx = 0;
1546   INT32 minxhx = 0;
1547
1548   int shade_base = 0;
1549   int texture_base = 0;
1550   int zbuffer_base = 0;
1551   if(m_shade)
1552   {
1553      shade_base = 8;
1554      if(m_texture)
1555      {
1556         texture_base = 24;
1557         if(m_zbuffer)
1558         {
1559            zbuffer_base = 40;
1560         }
1561      }
1562      else if(m_zbuffer)
1563      {
1564         zbuffer_base = 24;
1565      }
1566   }
1567   else if(m_texture)
1568   {
1569      texture_base = 8;
1570      if(m_zbuffer)
1571      {
1572         zbuffer_base = 24;
1573      }
1574   }
1575   else if(m_zbuffer)
1576   {
1577      zbuffer_base = 8;
1578   }
1579
1580   UINT32 w3 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+2];
1581   UINT32 w4 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+3];
1582   UINT32 w5 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+4];
1583   UINT32 w6 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+5];
1584   UINT32 w7 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+6];
1585   UINT32 w8 = m_cmd_data[m_rdp->GetCurrFIFOIndex()+7];
1586
1587   INT32 yl = (w1 & 0x3fff);
1588   INT32 ym = ((w2 >> 16) & 0x3fff);
1589   INT32 yh = ((w2 >>  0) & 0x3fff);
1590   INT32 xl = (INT32)(w3 & 0x3fffffff);
1591   INT32 xh = (INT32)(w5 & 0x3fffffff);
1592   INT32 xm = (INT32)(w7 & 0x3fffffff);
1593   // Inverse slopes in 16.16 format
1594   INT32 dxldy = (INT32)(w4);
1595   INT32 dxhdy = (INT32)(w6);
1596   INT32 dxmdy = (INT32)(w8);
1597
1598   m_misc_state->m_max_level = ((w1 >> 19) & 7);
1599   int tilenum = (w1 >> 16) & 0x7;
1600
1601   if (yl & 0x2000)  yl |= 0xffffc000;
1602   if (ym & 0x2000)  ym |= 0xffffc000;
1603   if (yh & 0x2000)  yh |= 0xffffc000;
1604
1605   if (xl & 0x20000000)  xl |= 0xc0000000;
1606   if (xm & 0x20000000)  xm |= 0xc0000000;
1607   if (xh & 0x20000000)  xh |= 0xc0000000;
1608
1609   int r    = (m_cmd_data[shade_base+0 ] & 0xffff0000) | ((m_cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
1610   int g    = ((m_cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+4 ] & 0x0000ffff);
1611   int b    = (m_cmd_data[shade_base+1 ] & 0xffff0000) | ((m_cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
1612   int a    = ((m_cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+5 ] & 0x0000ffff);
1613   int drdx = (m_cmd_data[shade_base+2 ] & 0xffff0000) | ((m_cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
1614   int dgdx = ((m_cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+6 ] & 0x0000ffff);
1615   int dbdx = (m_cmd_data[shade_base+3 ] & 0xffff0000) | ((m_cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
1616   int dadx = ((m_cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+7 ] & 0x0000ffff);
1617   int drde = (m_cmd_data[shade_base+8 ] & 0xffff0000) | ((m_cmd_data[shade_base+12] >> 16) & 0x0000ffff);
1618   int dgde = ((m_cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+12] & 0x0000ffff);
1619   int dbde = (m_cmd_data[shade_base+9 ] & 0xffff0000) | ((m_cmd_data[shade_base+13] >> 16) & 0x0000ffff);
1620   int dade = ((m_cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (m_cmd_data[shade_base+13] & 0x0000ffff);
1621   int drdy = (m_cmd_data[shade_base+10] & 0xffff0000) | ((m_cmd_data[shade_base+14] >> 16) & 0x0000ffff);
1622   int dgdy = ((m_cmd_data[shade_base+10] << 16) & 0xffff0000) | (m_cmd_data[shade_base+14] & 0x0000ffff);
1623   int dbdy = (m_cmd_data[shade_base+11] & 0xffff0000) | ((m_cmd_data[shade_base+15] >> 16) & 0x0000ffff);
1624   int dady = ((m_cmd_data[shade_base+11] << 16) & 0xffff0000) | (m_cmd_data[shade_base+15] & 0x0000ffff);
1625   int s    = (m_cmd_data[texture_base+0 ] & 0xffff0000) | ((m_cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
1626   int t    = ((m_cmd_data[texture_base+0 ] << 16) & 0xffff0000)   | (m_cmd_data[texture_base+4 ] & 0x0000ffff);
1627   int w    = (m_cmd_data[texture_base+1 ] & 0xffff0000) | ((m_cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
1628   int dsdx = (m_cmd_data[texture_base+2 ] & 0xffff0000) | ((m_cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
1629   int dtdx = ((m_cmd_data[texture_base+2 ] << 16) & 0xffff0000)   | (m_cmd_data[texture_base+6 ] & 0x0000ffff);
1630   int dwdx = (m_cmd_data[texture_base+3 ] & 0xffff0000) | ((m_cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
1631   int dsde = (m_cmd_data[texture_base+8 ] & 0xffff0000) | ((m_cmd_data[texture_base+12] >> 16) & 0x0000ffff);
1632   int dtde = ((m_cmd_data[texture_base+8 ] << 16) & 0xffff0000)   | (m_cmd_data[texture_base+12] & 0x0000ffff);
1633   int dwde = (m_cmd_data[texture_base+9 ] & 0xffff0000) | ((m_cmd_data[texture_base+13] >> 16) & 0x0000ffff);
1634   int dsdy = (m_cmd_data[texture_base+10] & 0xffff0000) | ((m_cmd_data[texture_base+14] >> 16) & 0x0000ffff);
1635   int dtdy = ((m_cmd_data[texture_base+10] << 16) & 0xffff0000)   | (m_cmd_data[texture_base+14] & 0x0000ffff);
1636   int dwdy = (m_cmd_data[texture_base+11] & 0xffff0000) | ((m_cmd_data[texture_base+15] >> 16) & 0x0000ffff);
1637   int z    = m_cmd_data[zbuffer_base+0];
1638   int dzdx = m_cmd_data[zbuffer_base+1];
1639   int dzde = m_cmd_data[zbuffer_base+2];
1640   int dzdy = m_cmd_data[zbuffer_base+3];
1641
1642   int dzdy_dz = (dzdy >> 16) & 0xffff;
1643   int dzdx_dz = (dzdx >> 16) & 0xffff;
1644   int dsdylod = dsdy >> 16;
1645   int dtdylod = dtdy >> 16;
1646   if (dsdylod & 0x20000)
1647   {
1648      dsdylod = ~dsdylod & 0x1ffff;
1649   }
1650   if (dtdylod & 0x20000)
1651   {
1652      dtdylod = ~dtdylod & 0x1ffff;
1653   }
1654
1655   int xleft_inc = dxmdy >> 2;
1656   int xright_inc = dxhdy >> 2;
1657
1658   int xright = xh;
1659   int xleft = xm;
1660
1661   INT32 limcvg = ((yl>>2) <= 1023) ? (yl>>2) : 1023; // Needed by 40 Winks
1662   if (limcvg < 0)
1663   {
1664      limcvg = 0;
1665   }
1666
1667   INT32 startcvg = ((yh>>2)>=0) ? (yh>>2) : 0;
1668   for (int k = startcvg; k <= limcvg; k++)
1669   {
1670      memset((void*)&m_rdp->GetSpans()[k].m_cvg[0],0,640);
1671   }
1672
1673   int sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
1674   int do_offset = !(sign_dxhdy ^ (flip));
1675
1676   if (do_offset)
1677   {
1678      dsdeh = dsde >> 9;   dsdyh = dsdy >> 9;
1679      dtdeh = dtde >> 9;   dtdyh = dtdy >> 9;
1680      dwdeh = dwde >> 9;   dwdyh = dwdy >> 9;
1681      drdeh = drde >> 9;   drdyh = drdy >> 9;
1682      dgdeh = dgde >> 9;   dgdyh = dgdy >> 9;
1683      dbdeh = dbde >> 9;   dbdyh = dbdy >> 9;
1684      dadeh = dade >> 9;   dadyh = dady >> 9;
1685      dzdeh = dzde >> 9;   dzdyh = dzdy >> 9;
1686
1687      dsdiff = (dsdeh*3 - dsdyh*3) << 7;
1688      dtdiff = (dtdeh*3 - dtdyh*3) << 7;
1689      dwdiff = (dwdeh*3 - dwdyh*3) << 7;
1690      drdiff = (drdeh*3 - drdyh*3) << 7;
1691      dgdiff = (dgdeh*3 - dgdyh*3) << 7;
1692      dbdiff = (dbdeh*3 - dbdyh*3) << 7;
1693      dadiff = (dadeh*3 - dadyh*3) << 7;
1694      dzdiff = (dzdeh*3 - dzdyh*3) << 7;
1695   }
1696   else
1697   {
1698      dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0;
1699   }
1700
1701   if (do_offset)
1702   {
1703      dseoff = (dsdeh*3) << 7;
1704      dteoff = (dtdeh*3) << 7;
1705      dweoff = (dwdeh*3) << 7;
1706      dreoff = (drdeh*3) << 7;
1707      dgeoff = (dgdeh*3) << 7;
1708      dbeoff = (dbdeh*3) << 7;
1709      daeoff = (dadeh*3) << 7;
1710      dzeoff = (dzdeh*3) << 7;
1711   }
1712   else
1713   {
1714      dseoff = dteoff = dweoff = dreoff = dgeoff = dbeoff = daeoff = dzeoff = 0;
1715   }
1716
1717   dsdxh = dsdx >> 8;
1718   dtdxh = dtdx >> 8;
1719   dwdxh = dwdx >> 8;
1720   drdxh = drdx >> 8;
1721   dgdxh = dgdx >> 8;
1722   dbdxh = dbdx >> 8;
1723   dadxh = dadx >> 8;
1724   dzdxh = dzdx >> 8;
1725
1726   int ycur =   yh & ~3;
1727   int ylfar = yl | 3;
1728   int ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
1729   int yhpix = yh >> 2;
1730   int ylpix = yl >> 2;
1731
1732   if(ylfar >= 0x1000)
1733   {
1734      ylfar = 0x0fff;
1735   }
1736
1737   if(flip)
1738   {
1739      for (int k = ycur; k <= ylfar; k++)
1740      {
1741         if (k == ym)
1742         {
1743            xleft = xl;
1744            xleft_inc = dxldy >> 2;
1745         }
1746
1747         int xstart = xleft >> 16;
1748         int xend = xright >> 16;
1749         int j = k >> 2;
1750         int spix = k & 3;
1751
1752         int m = 0;
1753         int n = 0;
1754         UINT32 min = 0;
1755         UINT32 max = 3;
1756         if (j == yhpix)
1757         {
1758            min = yh & 3;
1759         }
1760         if (j == ylpix)
1761         {
1762            max = yl & 3;
1763         }
1764         if (spix >= min && spix <= max)
1765         {
1766            if (spix == min)
1767            {
1768               minxmx = maxxmx = xstart;
1769               minxhx = maxxhx = xend;
1770            }
1771            else
1772            {
1773               minxmx = (xstart < minxmx) ? xstart : minxmx;
1774               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
1775               minxhx = (xend < minxhx) ? xend : minxhx;
1776               maxxhx = (xend > maxxhx) ? xend : maxxhx;
1777            }
1778         }
1779
1780         if (spix == max)
1781         {
1782            m_rdp->GetSpans()[j].m_lx = maxxmx;
1783            m_rdp->GetSpans()[j].m_rx = minxhx;
1784            m_rdp->GetSpans()[j].m_dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
1785            if(m_shade)
1786            {
1787               m_rdp->GetSpans()[j].m_dr.w = drdx & ~0x1f;
1788               m_rdp->GetSpans()[j].m_dg.w = dgdx & ~0x1f;
1789               m_rdp->GetSpans()[j].m_db.w = dbdx & ~0x1f;
1790               m_rdp->GetSpans()[j].m_da.w = dadx & ~0x1f;
1791            }
1792            if(m_texture)
1793            {
1794               m_rdp->GetSpans()[j].m_ds.w = dsdx;
1795               m_rdp->GetSpans()[j].m_dt.w = dtdx;
1796               m_rdp->GetSpans()[j].m_dw.w = dwdx;
1797            }
1798            if(m_zbuffer)
1799            {
1800               m_rdp->GetSpans()[j].m_dz.w = dzdx;
1801               m_rdp->GetSpans()[j].m_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
1802               m_rdp->GetSpans()[j].m_dzpix = m_rdp->NormalizeDZPix(m_rdp->GetSpans()[j].m_dzpix);
1803            }
1804         }
1805
1806         int length = (xend - xstart) * sign;
1807
1808         if (spix == ldflag)
1809         {
1810            xfrac = ((xright >> 8) & 0xff);
1811            if(m_shade)
1812            {
1813               m_rdp->GetSpans()[j].m_r.w = r + drdiff - (xfrac * drdxh);
1814               m_rdp->GetSpans()[j].m_g.w = g + dgdiff - (xfrac * dgdxh);
1815               m_rdp->GetSpans()[j].m_b.w = b + dbdiff - (xfrac * dbdxh);
1816               m_rdp->GetSpans()[j].m_a.w = a + dadiff - (xfrac * dadxh);
1817            }
1818            if(m_texture)
1819            {
1820               m_rdp->GetSpans()[j].m_s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;
1821               m_rdp->GetSpans()[j].m_t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;
1822               m_rdp->GetSpans()[j].m_w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;
1823            }
1824            if(m_zbuffer)
1825            {
1826               m_rdp->GetSpans()[j].m_z.w = z + dzdiff - (xfrac * dzdxh);
1827            }
1828         }
1829
1830         m = xend + 1;
1831
1832         if (k >= yh && length >= 0 && k <= yl)
1833         {
1834            if (xstart>=0 && xstart <1024)
1835            {
1836               m_rdp->GetSpans()[j].m_cvg[xstart] += m_rdp->AddRightCvg(xleft, k);
1837            }
1838            if (xend>=0 && xend<1024)
1839            {
1840               if (xstart != xend)
1841               {
1842                  m_rdp->GetSpans()[j].m_cvg[xend] += m_rdp->AddLeftCvg(xright, k);
1843               }
1844               else
1845               {
1846                  m_rdp->GetSpans()[j].m_cvg[xend] -= (2 - m_rdp->AddLeftCvg(xright, k));
1847                  if (m_rdp->GetSpans()[j].m_cvg[xend] > 200)
1848                  {
1849                     m_rdp->GetSpans()[j].m_cvg[xend] = 0;
1850                  }
1851               }
1852            }
1853            for (n = 0; n < (length - 1); n++)
1854            {
1855               if (m>=0 && m < 640)
1856               {
1857                  m_rdp->GetSpans()[j].m_cvg[m] += 2;
1858               }
1859
1860               m += inv_sign;
1861            }
1862         }
1863
1864         if (spix == 3)
1865         {
1866            if(m_shade)
1867            {
1868               r += drde;
1869               g += dgde;
1870               b += dbde;
1871               a += dade;
1872            }
1873            if(m_texture)
1874            {
1875               s += dsde;
1876               t += dtde;
1877               w += dwde;
1878            }
1879            if(m_zbuffer)
1880            {
1881               z += dzde;
1882            }
1883         }
1884         xleft += xleft_inc;
1885         xright += xright_inc;
1886      }
1887   }
1888   else
1889   {
1890      for (int k = ycur; k <= ylfar; k++)
1891      {
1892         if (k == ym)
1893         {
1894            xleft = xl;
1895            xleft_inc = dxldy >> 2;
1896         }
1897
1898         int xstart = xleft >> 16;
1899         int xend = xright >> 16;
1900         int j = k >> 2;
1901         int spix = k & 3;
1902
1903         int m = 0;
1904         int n = 0;
1905         UINT32 min = 0;
1906         UINT32 max = 3;
1907         if (j == yhpix)
1908         {
1909            min = yh & 3;
1910         }
1911         if (j == ylpix)
1912         {
1913            max = yl & 3;
1914         }
1915         if (spix >= min && spix <= max)
1916         {
1917            if (spix == min)
1918            {
1919               minxmx = maxxmx = xstart;
1920               minxhx = maxxhx = xend;
1921            }
1922            else
1923            {
1924               minxmx = (xstart < minxmx) ? xstart : minxmx;
1925               maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
1926               minxhx = (xend < minxhx) ? xend : minxhx;
1927               maxxhx = (xend > maxxhx) ? xend : maxxhx;
1928            }
1929         }
1930
1931         if (spix == max)
1932         {
1933            m_rdp->GetSpans()[j].m_lx = minxmx;
1934            m_rdp->GetSpans()[j].m_rx = maxxhx;
1935            m_rdp->GetSpans()[j].m_dymax = (dsdylod > dtdylod)? dsdylod : dtdylod;
1936            if(m_shade)
1937            {
1938               m_rdp->GetSpans()[j].m_dr.w = drdx & ~0x1f;
1939               m_rdp->GetSpans()[j].m_dg.w = dgdx & ~0x1f;
1940               m_rdp->GetSpans()[j].m_db.w = dbdx & ~0x1f;
1941               m_rdp->GetSpans()[j].m_da.w = dadx & ~0x1f;
1942            }
1943            if(m_texture)
1944            {
1945               m_rdp->GetSpans()[j].m_ds.w = dsdx;
1946               m_rdp->GetSpans()[j].m_dt.w = dtdx;
1947               m_rdp->GetSpans()[j].m_dw.w = dwdx;
1948            }
1949            if(m_zbuffer)
1950            {
1951               m_rdp->GetSpans()[j].m_dz.w = dzdx;
1952               m_rdp->GetSpans()[j].m_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
1953               m_rdp->GetSpans()[j].m_dzpix = m_rdp->NormalizeDZPix(m_rdp->GetSpans()[j].m_dzpix);
1954            }
1955         }
1956
1957         int length = (xend - xstart) * sign;
1958
1959         if (spix == ldflag)
1960         {
1961            xfrac = ((xright >> 8) & 0xff);
1962            if(m_texture)
1963            {
1964               m_rdp->GetSpans()[j].m_s.w = (s + dsdiff - (xfrac * dsdxh)) & ~0x1f;
1965               m_rdp->GetSpans()[j].m_t.w = (t + dtdiff - (xfrac * dtdxh)) & ~0x1f;
1966               m_rdp->GetSpans()[j].m_w.w = (w + dwdiff - (xfrac * dwdxh)) & ~0x1f;
1967            }
1968            if(m_shade)
1969            {
1970               m_rdp->GetSpans()[j].m_r.w = r + drdiff - (xfrac * drdxh);
1971               m_rdp->GetSpans()[j].m_g.w = g + dgdiff - (xfrac * dgdxh);
1972               m_rdp->GetSpans()[j].m_b.w = b + dbdiff - (xfrac * dbdxh);
1973               m_rdp->GetSpans()[j].m_a.w = a + dadiff - (xfrac * dadxh);
1974            }
1975            if(m_zbuffer)
1976            {
1977               m_rdp->GetSpans()[j].m_z.w = z + dzdiff - (xfrac * dzdxh);
1978            }
1979         }
1980
1981         m = xend - 1;
1982
1983         if (k >= yh && length >= 0 && k <= yl)
1984         {
1985            if (xstart>=0 && xstart <1024)
1986            {
1987               m_rdp->GetSpans()[j].m_cvg[xstart] += m_rdp->AddLeftCvg(xleft, k);
1988            }
1989            if (xend>=0 && xend<1024)
1990            {
1991               if (xstart != xend)
1992               {
1993                  m_rdp->GetSpans()[j].m_cvg[xend] += m_rdp->AddRightCvg(xright, k);
1994               }
1995               else
1996               {
1997                  m_rdp->GetSpans()[j].m_cvg[xend] -= (2 - m_rdp->AddRightCvg(xright, k));
1998                  if (m_rdp->GetSpans()[j].m_cvg[xend] > 200)
1999                  {
2000                     m_rdp->GetSpans()[j].m_cvg[xend] = 0;
2001                  }
2002               }
2003            }
2004            for (n = 0; n < (length - 1); n++)
2005            {
2006               if (m>=0 && m < 640)
2007               {
2008                  m_rdp->GetSpans()[j].m_cvg[m] += 2;
2009               }
2010
2011               m += inv_sign;
2012            }
2013         }
2014
2015         if (spix == 3)
2016         {
2017            if(m_shade)
2018            {
2019               r += drde;
2020               g += dgde;
2021               b += dbde;
2022               a += dade;
2023            }
2024            if(m_texture)
2025            {
2026               s += dsde;
2027               t += dtde;
2028               w += dwde;
2029            }
2030            if(m_zbuffer)
2031            {
2032               z += dzde;
2033            }
2034         }
2035         xleft += xleft_inc;
2036         xright += xright_inc;
2037      }
2038   }
2039
2040   m_rdp->RenderSpans(yh >> 2, yl >> 2, tilenum, m_shade, m_texture, m_zbuffer, flip);
2041}
2042
34132043/*****************************************************************************/
34142044
34152045////////////////////////
34162046// RDP COMMANDS
34172047////////////////////////
34182048
3419typedef void (*rdp_command_func)(running_machine *machine, UINT32 w1, UINT32 w2);
3420#define RDP_COMMAND(name) void name(running_machine *machine, UINT32 w1, UINT32 w2)
3421
3422static RDP_COMMAND( rdp_invalid )
2049void N64::RDP::Processor::Triangle(bool shade, bool texture, bool zbuffer)
34232050{
3424   fatalerror("RDP: invalid command  %d, %08X %08X\n", (w1 >> 24) & 0x3f, w1, w2);
2051   N64::RDP::Triangle tri(m_machine, shade, texture, zbuffer);
2052   tri.Draw();
34252053}
34262054
3427static RDP_COMMAND( rdp_noop )
2055void N64::RDP::Processor::CmdTriangle(UINT32 w1, UINT32 w2)
34282056{
2057   Triangle(false, false, false);
2058}
34292059
2060void N64::RDP::Processor::CmdTriangleZ(UINT32 w1, UINT32 w2)
2061{
2062   Triangle(false, false, true);
34302063}
34312064
3432static RDP_COMMAND( rdp_tri_noshade )
2065void N64::RDP::Processor::CmdTriangleT(UINT32 w1, UINT32 w2)
34332066{
3434   triangle_ns_nt_nz(w1, w2);
2067   Triangle(false, true, false);
34352068}
34362069
3437static RDP_COMMAND( rdp_tri_noshade_z )
2070void N64::RDP::Processor::CmdTriangleTZ(UINT32 w1, UINT32 w2)
34382071{
3439   triangle_ns_nt_z(w1, w2);
2072   Triangle(false, true, true);
34402073}
34412074
3442static RDP_COMMAND( rdp_tri_tex )
2075void N64::RDP::Processor::CmdTriangleS(UINT32 w1, UINT32 w2)
34432076{
3444   triangle_ns_t_nz(w1, w2);
2077   Triangle(true, false, false);
34452078}
34462079
3447static RDP_COMMAND( rdp_tri_tex_z )
2080void N64::RDP::Processor::CmdTriangleSZ(UINT32 w1, UINT32 w2)
34482081{
3449   triangle_ns_t_z(w1, w2);
2082   Triangle(true, false, true);
34502083}
34512084
3452static RDP_COMMAND( rdp_tri_shade )
2085void N64::RDP::Processor::CmdTriangleST(UINT32 w1, UINT32 w2)
34532086{
3454   triangle_s_nt_nz(w1, w2);
2087   Triangle(true, true, false);
34552088}
34562089
3457static RDP_COMMAND( rdp_tri_shade_z )
2090void N64::RDP::Processor::CmdTriangleSTZ(UINT32 w1, UINT32 w2)
34582091{
3459   triangle_s_nt_z(w1, w2);
2092   Triangle(true, true, true);
34602093}
34612094
3462static RDP_COMMAND( rdp_tri_texshade )
2095void N64::RDP::Rectangle::InitFromBuffer(UINT32 *data)
34632096{
3464   triangle_s_t_nz(w1, w2);
2097   m_xl      = ((data[0] >> 12) & 0xfff) >> 2;
2098   m_yl      = ((data[0] >>  0) & 0xfff) >> 2;
2099   m_xh      = ((data[1] >> 12) & 0xfff) >> 2;
2100   m_yh      = ((data[1] >>  0) & 0xfff) >> 2;
34652101}
34662102
3467static RDP_COMMAND( rdp_tri_texshade_z )
2103void N64::RDP::TexRectangle::InitFromBuffer(UINT32 *data)
34682104{
3469   triangle_s_t_z(w1, w2);
2105   m_tilenum   = (data[1] >> 24) & 0x7;
2106   m_xl      = ((data[0] >> 12) & 0xfff) >> 2;
2107   m_yl      = ((data[0] >>  0) & 0xfff) >> 2;
2108   m_xh      = ((data[1] >> 12) & 0xfff) >> 2;
2109   m_yh      = ((data[1] >>  0) & 0xfff) >> 2;
2110   m_s         = (data[2] >> 16) & 0xffff;
2111   m_t         = (data[2] >>  0) & 0xffff;
2112   m_dsdx      = (data[3] >> 16) & 0xffff;
2113   m_dtdy      = (data[3] >>  0) & 0xffff;
34702114}
34712115
3472static RDP_COMMAND( rdp_tex_rect )
2116void N64::RDP::Processor::CmdTexRect(UINT32 w1, UINT32 w2)
34732117{
3474   TEX_RECTANGLE rect;
3475   UINT32 w3 = rdp_cmd_data[rdp_cmd_cur+2];
3476   UINT32 w4 = rdp_cmd_data[rdp_cmd_cur+3];
2118   N64::RDP::TexRectangle rect(m_machine, m_cmd_data + m_cmd_cur, 0);
34772119
3478   rect.tilenum   = (w2 >> 24) & 0x7;
3479   rect.xl         = ((w1 >> 12) & 0xfff) >> 2;
3480   rect.yl         = ((w1 >>  0) & 0xfff) >> 2;
3481   rect.xh         = ((w2 >> 12) & 0xfff) >> 2;
3482   rect.yh         = ((w2 >>  0) & 0xfff) >> 2;
3483   rect.s         = (w3 >> 16) & 0xffff;
3484   rect.t         = (w3 >>  0) & 0xffff;
3485   rect.dsdx      = (w4 >> 16) & 0xffff;
3486   rect.dtdy      = (w4 >>  0) & 0xffff;
3487   rect.flip      = 0;
3488
3489   switch (fb_size)
2120   switch (m_misc_state.m_fb_size)
34902121   {
3491      case PIXEL_SIZE_16BIT:      texture_rectangle_16bit(&rect); break;
3492      case PIXEL_SIZE_32BIT:      texture_rectangle_32bit(&rect); break;
2122      case PIXEL_SIZE_16BIT:
2123         rect.Draw();
2124         break;
2125      case PIXEL_SIZE_32BIT:
2126         texture_rectangle_32bit(m_machine, &rect);
2127         break;
34932128   }
34942129}
34952130
3496static RDP_COMMAND( rdp_tex_rect_flip )
2131void N64::RDP::Processor::CmdTexRectFlip(UINT32 w1, UINT32 w2)
34972132{
3498   TEX_RECTANGLE rect;
3499   UINT32 w3 = rdp_cmd_data[rdp_cmd_cur+2];
3500   UINT32 w4 = rdp_cmd_data[rdp_cmd_cur+3];
2133   N64::RDP::TexRectangle rect(m_machine, m_cmd_data + m_cmd_cur, 1);
35012134
3502   rect.tilenum   = (w2 >> 24) & 0x7;
3503   rect.xl         = ((w1 >> 12) & 0xfff) >> 2;
3504   rect.yl         = ((w1 >>  0) & 0xfff) >> 2;
3505   rect.xh         = ((w2 >> 12) & 0xfff) >> 2;
3506   rect.yh         = ((   w2 >>  0) & 0xfff) >> 2;
3507   rect.t         = (w3 >> 16) & 0xffff;
3508   rect.s         = (w3 >>  0) & 0xffff;
3509   rect.dtdy      = (w4 >> 16) & 0xffff;
3510   rect.dsdx      = (w4 >>  0) & 0xffff;
3511   rect.flip      = 1;
3512
3513   switch (fb_size)
2135   switch (m_misc_state.m_fb_size)
35142136   {
3515      case PIXEL_SIZE_16BIT:      texture_rectangle_16bit(&rect); break;
3516      case PIXEL_SIZE_32BIT:      texture_rectangle_32bit(&rect); break;
2137      case PIXEL_SIZE_16BIT:      rect.Draw(); break;
2138      case PIXEL_SIZE_32BIT:      texture_rectangle_32bit(m_machine, &rect); break;
35172139   }
35182140}
35192141
3520static RDP_COMMAND( rdp_sync_load )
2142void N64::RDP::Processor::CmdSyncLoad(UINT32 w1, UINT32 w2)
35212143{
35222144   // Nothing to do?
35232145}
35242146
3525static RDP_COMMAND( rdp_sync_pipe )
2147void N64::RDP::Processor::CmdSyncPipe(UINT32 w1, UINT32 w2)
35262148{
35272149   // Nothing to do?
35282150}
35292151
3530static RDP_COMMAND( rdp_sync_tile )
2152void N64::RDP::Processor::CmdSyncTile(UINT32 w1, UINT32 w2)
35312153{
35322154   // Nothing to do?
35332155}
35342156
3535static RDP_COMMAND( rdp_sync_full )
2157void N64::RDP::Processor::CmdSyncFull(UINT32 w1, UINT32 w2)
35362158{
3537   dp_full_sync(machine);
2159   dp_full_sync(m_machine);
35382160}
35392161
3540static RDP_COMMAND( rdp_set_key_gb )
2162void N64::RDP::Processor::CmdSetKeyGB(UINT32 w1, UINT32 w2)
35412163{
3542   key_scale.i.b = w2 & 0xff;
3543   key_scale.i.g = (w2 >> 16) & 0xff;
2164   m_key_scale.i.b = w2 & 0xff;
2165   m_key_scale.i.g = (w2 >> 16) & 0xff;
35442166}
35452167
3546static RDP_COMMAND( rdp_set_key_r )
2168void N64::RDP::Processor::CmdSetKeyR(UINT32 w1, UINT32 w2)
35472169{
3548   key_scale.i.r = w2 & 0xff;
2170   m_key_scale.i.r = w2 & 0xff;
35492171}
35502172
3551static RDP_COMMAND( rdp_set_convert )
2173void N64::RDP::Processor::CmdSetFillColor32(UINT32 w1, UINT32 w2)
35522174{
3553   k0 = (w1 >> 13) & 0xff;
2175   m_fill_color = w2;
2176}
2177
2178void N64::RDP::Processor::CmdSetConvert(UINT32 w1, UINT32 w2)
2179{
2180   INT32 k0 = (w1 >> 13) & 0xff;
2181   INT32 k1 = (w1 >> 4) & 0xff;
2182   INT32 k2 = ((w1 & 7) << 5) | ((w2 >> 27) & 0x1f);
2183   INT32 k3 = (w2 >> 18) & 0xff;
2184   INT32 k4 = (w2 >> 9) & 0xff;
2185   INT32 k5 = w2 & 0xff;
35542186   k0 = ((w1 >> 21) & 1) ? (-(0x100 - k0)) : k0;
3555   k1 = (w1 >> 4) & 0xff;
35562187   k1 = ((w1 >> 12) & 1) ?   (-(0x100 - k1)) : k1;
3557   k2 = ((w1 & 7) << 5) | ((w2 >> 27) & 0x1f);
35582188   k2 = (w1 & 0xf) ? (-(0x100 - k2)) : k2;
3559   k3 = (w2 >> 18) & 0xff;
35602189   k3 = ((w2 >> 26) & 1) ? (-(0x100 - k3)) : k3;
3561   k4 = (w2 >> 9) & 0xff;
35622190   k4 = ((w2 >> 17) & 1) ? (-(0x100 - k4)) : k4;
3563   k5 = w2 & 0xff;
35642191   k5 = ((w2 >> 8) & 1) ? (-(0x100 - k5)) : k5;
2192   SetYUVFactors(k0, k1, k2, k3, k4, k5);
35652193}
35662194
3567static RDP_COMMAND( rdp_set_scissor )
2195void N64::RDP::Processor::CmdSetScissor(UINT32 w1, UINT32 w2)
35682196{
3569   clip.xh = (w1 >> 12) & 0xfff;
3570   clip.yh = (w1 >>  0) & 0xfff;
3571   clip.xl = (w2 >> 12) & 0xfff;
3572   clip.yl = (w2 >>  0) & 0xfff;
2197   m_scissor.m_xh = ((w1 >> 12) & 0xfff) >> 2;
2198   m_scissor.m_yh = ((w1 >>  0) & 0xfff) >> 2;
2199   m_scissor.m_xl = ((w2 >> 12) & 0xfff) >> 2;
2200   m_scissor.m_yl = ((w2 >>  0) & 0xfff) >> 2;
35732201
3574   clip.xh >>= 2;
3575   clip.yh >>= 2;
3576   clip.xl >>= 2;
3577   clip.yl >>= 2;
3578
35792202   // TODO: handle f & o?
35802203}
35812204
3582static RDP_COMMAND( rdp_set_prim_depth )
2205void N64::RDP::Processor::CmdSetPrimDepth(UINT32 w1, UINT32 w2)
35832206{
3584   primitive_z = (UINT16)(w2 >> 16) & 0x7fff;
3585   primitive_delta_z = (UINT16)(w1);
2207   m_misc_state.m_primitive_z = (UINT16)(w2 >> 16) & 0x7fff;
2208   m_misc_state.m_primitive_delta_z = (UINT16)(w1);
2209
35862210}
35872211
3588static RDP_COMMAND( rdp_set_other_modes )
2212void N64::RDP::Processor::CmdSetOtherModes(UINT32 w1, UINT32 w2)
35892213{
3590   other_modes.cycle_type         = (w1 >> 20) & 0x3;
3591   other_modes.persp_tex_en      = (w1 & 0x80000) ? true : false;
3592   other_modes.detail_tex_en      = (w1 & 0x40000) ? true : false;
3593   other_modes.sharpen_tex_en      = (w1 & 0x20000) ? true : false;
3594   other_modes.tex_lod_en         = (w1 & 0x10000) ? true : false;
3595   other_modes.en_tlut            = (w1 & 0x08000) ? true : false;
3596   other_modes.tlut_type         = (w1 & 0x04000) ? true : false;
3597   other_modes.sample_type         = (w1 & 0x02000) ? true : false;
3598   other_modes.mid_texel         = (w1 & 0x01000) ? true : false;
3599   other_modes.bi_lerp0         = (w1 & 0x00800) ? true : false;
3600   other_modes.bi_lerp1         = (w1 & 0x00400) ? true : false;
3601   other_modes.convert_one         = (w1 & 0x00200) ? true : false;
3602   other_modes.key_en            = (w1 & 0x00100) ? true : false;
3603   other_modes.rgb_dither_sel      = (w1 >> 6) & 0x3;
3604   other_modes.alpha_dither_sel   = (w1 >> 4) & 0x3;
3605   other_modes.blend_m1a_0         = (w2 >> 30) & 0x3;
3606   other_modes.blend_m1a_1         = (w2 >> 28) & 0x3;
3607   other_modes.blend_m1b_0         = (w2 >> 26) & 0x3;
3608   other_modes.blend_m1b_1         = (w2 >> 24) & 0x3;
3609   other_modes.blend_m2a_0         = (w2 >> 22) & 0x3;
3610   other_modes.blend_m2a_1         = (w2 >> 20) & 0x3;
3611   other_modes.blend_m2b_0         = (w2 >> 18) & 0x3;
3612   other_modes.blend_m2b_1         = (w2 >> 16) & 0x3;
3613   other_modes.force_blend         = (w2 & 0x4000) ? true : false;
3614   other_modes.alpha_cvg_select   = (w2 & 0x2000) ? true : false;
3615   other_modes.cvg_times_alpha      = (w2 & 0x1000) ? true : false;
3616   other_modes.z_mode            = (w2 >> 10) & 0x3;
3617   other_modes.cvg_dest         = (w2 >> 8) & 0x3;
3618   other_modes.color_on_cvg      = (w2 & 0x80) ? true : false;
3619   other_modes.image_read_en      = (w2 & 0x40) ? true : false;
3620   other_modes.z_update_en         = (w2 & 0x20) ? true : false;
3621   other_modes.z_compare_en      = (w2 & 0x10) ? true : false;
3622   other_modes.antialias_en      = (w2 & 0x08) ? true : false;
3623   other_modes.z_source_sel      = (w2 & 0x04) ? true : false;
3624   other_modes.dither_alpha_en      = (w2 & 0x02) ? true : false;
3625   other_modes.alpha_compare_en   = (w2 & 0x01) ? true : false;
2214   m_other_modes.cycle_type      = (w1 >> 20) & 0x3;
2215   m_other_modes.persp_tex_en      = (w1 & 0x80000) ? true : false;
2216   m_other_modes.detail_tex_en      = (w1 & 0x40000) ? true : false;
2217   m_other_modes.sharpen_tex_en   = (w1 & 0x20000) ? true : false;
2218   m_other_modes.tex_lod_en      = (w1 & 0x10000) ? true : false;
2219   m_other_modes.en_tlut         = (w1 & 0x08000) ? true : false;
2220   m_other_modes.tlut_type         = (w1 & 0x04000) ? true : false;
2221   m_other_modes.sample_type      = (w1 & 0x02000) ? true : false;
2222   m_other_modes.mid_texel         = (w1 & 0x01000) ? true : false;
2223   m_other_modes.bi_lerp0         = (w1 & 0x00800) ? true : false;
2224   m_other_modes.bi_lerp1         = (w1 & 0x00400) ? true : false;
2225   m_other_modes.convert_one      = (w1 & 0x00200) ? true : false;
2226   m_other_modes.key_en         = (w1 & 0x00100) ? true : false;
2227   m_other_modes.rgb_dither_sel   = (w1 >> 6) & 0x3;
2228   m_other_modes.alpha_dither_sel   = (w1 >> 4) & 0x3;
2229   m_other_modes.blend_m1a_0      = (w2 >> 30) & 0x3;
2230   m_other_modes.blend_m1a_1      = (w2 >> 28) & 0x3;
2231   m_other_modes.blend_m1b_0      = (w2 >> 26) & 0x3;
2232   m_other_modes.blend_m1b_1      = (w2 >> 24) & 0x3;
2233   m_other_modes.blend_m2a_0      = (w2 >> 22) & 0x3;
2234   m_other_modes.blend_m2a_1      = (w2 >> 20) & 0x3;
2235   m_other_modes.blend_m2b_0      = (w2 >> 18) & 0x3;
2236   m_other_modes.blend_m2b_1      = (w2 >> 16) & 0x3;
2237   m_other_modes.force_blend      = (w2 & 0x4000) ? true : false;
2238   m_other_modes.alpha_cvg_select   = (w2 & 0x2000) ? true : false;
2239   m_other_modes.cvg_times_alpha   = (w2 & 0x1000) ? true : false;
2240   m_other_modes.z_mode         = (w2 >> 10) & 0x3;
2241   m_other_modes.cvg_dest         = (w2 >> 8) & 0x3;
2242   m_other_modes.color_on_cvg      = (w2 & 0x80) ? true : false;
2243   m_other_modes.image_read_en      = (w2 & 0x40) ? true : false;
2244   m_other_modes.z_update_en      = (w2 & 0x20) ? true : false;
2245   m_other_modes.z_compare_en      = (w2 & 0x10) ? true : false;
2246   m_other_modes.antialias_en      = (w2 & 0x08) ? true : false;
2247   m_other_modes.z_source_sel      = (w2 & 0x04) ? true : false;
2248   m_other_modes.dither_alpha_en   = (w2 & 0x02) ? true : false;
2249   m_other_modes.alpha_compare_en   = (w2 & 0x01) ? true : false;
36262250
3627   texture_rectangle_16bit = rdp_texture_rectangle_16bit_func[((((other_modes.z_update_en | other_modes.z_source_sel) << 3) | ((other_modes.z_compare_en | other_modes.z_source_sel) << 2) | other_modes.cycle_type) << 2) | other_modes.rgb_dither_sel];
3628   fill_rectangle_16bit = rdp_fill_rectangle_16bit_func[(other_modes.cycle_type << 2) | other_modes.rgb_dither_sel];
3629
3630   alpha_cvg_get = rdp_alpha_cvg_func[(other_modes.cvg_times_alpha << 1) | (other_modes.alpha_cvg_select ? 1 : 0)];
3631
3632   alpha_compare = rdp_alpha_compare_func[(other_modes.alpha_compare_en << 1) | (other_modes.dither_alpha_en ? 1 : 0)];
3633
3634   z_compare = rdp_z_compare_func[(other_modes.z_mode << 2) | (other_modes.antialias_en << 1) | (other_modes.image_read_en ? 1 : 0)];
3635
3636   render_spans_16_ns_nt_nz_nf = rdp_render_spans_16_func[0 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3637   render_spans_16_ns_nt_z_nf = rdp_render_spans_16_func[2 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3638   render_spans_16_ns_t_nz_nf = rdp_render_spans_16_func[4 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3639   render_spans_16_ns_t_z_nf = rdp_render_spans_16_func[6 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3640   render_spans_16_s_nt_nz_nf = rdp_render_spans_16_func[8 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3641   render_spans_16_s_nt_z_nf = rdp_render_spans_16_func[10 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3642   render_spans_16_s_t_nz_nf = rdp_render_spans_16_func[12 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3643   render_spans_16_s_t_z_nf = rdp_render_spans_16_func[14 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3644   render_spans_16_ns_nt_nz_f = rdp_render_spans_16_func[16 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3645   render_spans_16_ns_nt_z_f = rdp_render_spans_16_func[18 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3646   render_spans_16_ns_t_nz_f = rdp_render_spans_16_func[20 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3647   render_spans_16_ns_t_z_f = rdp_render_spans_16_func[22 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3648   render_spans_16_s_nt_nz_f = rdp_render_spans_16_func[24 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3649   render_spans_16_s_nt_z_f = rdp_render_spans_16_func[26 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3650   render_spans_16_s_t_nz_f = rdp_render_spans_16_func[28 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3651   render_spans_16_s_t_z_f = rdp_render_spans_16_func[30 + ((other_modes.cycle_type & 1) | (other_modes.z_compare_en << 5) | (other_modes.z_update_en << 6) | (other_modes.rgb_dither_sel << 7))];
3652
3653   for(int index = 0; index < 8; index++)
3654   {
3655      tile[index].fetch_index = (tile[index].size << 5) | (tile[index].format << 2) | (other_modes.en_tlut << 1) | (other_modes.tlut_type ? 1 : 0);
3656   }
3657
3658   FBWRITE_16 = rdp_fbwrite_16_func[(other_modes.color_on_cvg << 3) | (other_modes.image_read_en << 2) | other_modes.cvg_dest];
3659   FBWRITE_32 = rdp_fbwrite_32_func[(other_modes.color_on_cvg << 3) | (other_modes.image_read_en << 2) | other_modes.cvg_dest];
3660
3661   BLENDER1_16_DITH = rdp_blender1_16_dith_func[(other_modes.force_blend << 4) | (other_modes.image_read_en << 3) | (other_modes.z_compare_en << 2) | ((other_modes.rgb_dither_sel >> 1) << 1) | (other_modes.alpha_compare_en ? 1 : 0)];
3662   BLENDER2_16_DITH = rdp_blender2_16_dith_func[(other_modes.force_blend << 4) | (other_modes.image_read_en << 3) | (other_modes.z_compare_en << 2) | ((other_modes.rgb_dither_sel >> 1) << 1) | (other_modes.alpha_compare_en ? 1 : 0)];
3663   BLENDER1_16_NDITH = rdp_blender1_16_ndith_func[(other_modes.force_blend << 3) | (other_modes.image_read_en << 2) | (other_modes.z_compare_en << 1) | (other_modes.alpha_compare_en ? 1 : 0)];
3664   BLENDER2_16_NDITH = rdp_blender2_16_ndith_func[(other_modes.force_blend << 3) | (other_modes.image_read_en << 2) | (other_modes.z_compare_en << 1) | (other_modes.alpha_compare_en ? 1 : 0)];
3665
3666   SET_BLENDER_INPUT(0, 0, &blender1a_r[0], &blender1a_g[0], &blender1a_b[0], &blender1b_a[0],
3667                 other_modes.blend_m1a_0, other_modes.blend_m1b_0);
3668   SET_BLENDER_INPUT(0, 1, &blender2a_r[0], &blender2a_g[0], &blender2a_b[0], &blender2b_a[0],
3669                 other_modes.blend_m2a_0, other_modes.blend_m2b_0);
3670   SET_BLENDER_INPUT(1, 0, &blender1a_r[1], &blender1a_g[1], &blender1a_b[1], &blender1b_a[1],
3671                 other_modes.blend_m1a_1, other_modes.blend_m1b_1);
3672   SET_BLENDER_INPUT(1, 1, &blender2a_r[1], &blender2a_g[1], &blender2a_b[1], &blender2b_a[1],
3673                 other_modes.blend_m2a_1, other_modes.blend_m2b_1);
3674
3675   special_bsel0 = (blender2b_a[0] == &memory_color.i.a) ? 2 : 0;
3676   special_bsel1 = (blender2b_a[1] == &memory_color.i.a) ? 2 : 0;
2251   // These should belong to the Blender class
2252   SetBlenderInput(0, 0, &m_color_inputs.blender1a_r[0], &m_color_inputs.blender1a_g[0], &m_color_inputs.blender1a_b[0], &m_color_inputs.blender1b_a[0], m_other_modes.blend_m1a_0, m_other_modes.blend_m1b_0);
2253   SetBlenderInput(0, 1, &m_color_inputs.blender2a_r[0], &m_color_inputs.blender2a_g[0], &m_color_inputs.blender2a_b[0], &m_color_inputs.blender2b_a[0], m_other_modes.blend_m2a_0, m_other_modes.blend_m2b_0);
2254   SetBlenderInput(1, 0, &m_color_inputs.blender1a_r[1], &m_color_inputs.blender1a_g[1], &m_color_inputs.blender1a_b[1], &m_color_inputs.blender1b_a[1], m_other_modes.blend_m1a_1, m_other_modes.blend_m1b_1);
2255   SetBlenderInput(1, 1, &m_color_inputs.blender2a_r[1], &m_color_inputs.blender2a_g[1], &m_color_inputs.blender2a_b[1], &m_color_inputs.blender2b_a[1], m_other_modes.blend_m2a_1, m_other_modes.blend_m2b_1);
2256   m_misc_state.m_special_bsel0 = (m_color_inputs.blender2b_a[0] == &m_memory_color.i.a) ? 2 : 0;
2257   m_misc_state.m_special_bsel1 = (m_color_inputs.blender2b_a[1] == &m_memory_color.i.a) ? 2 : 0;
36772258}
36782259
3679static RDP_COMMAND( rdp_load_tlut )
2260void N64::RDP::Processor::CmdLoadTLUT(UINT32 w1, UINT32 w2)
36802261{
36812262   const int tilenum = (w2 >> 24) & 7;
3682   TILE* tex_tile = &tile[tilenum];
2263   N64::RDP::Tile* tex_tile = &m_tiles[tilenum];
36832264
3684   int sl = tex_tile->sl = ((w1 >> 12) & 0xfff);
3685   int tl = tex_tile->tl =  w1 & 0xfff;
3686   int sh = tex_tile->sh = ((w2 >> 12) & 0xfff);
2265   int sl = tex_tile->sl = (w1 >> 12) & 0xfff;
2266   int tl = tex_tile->tl = (w1 >>  0) & 0xfff;
2267   int sh = tex_tile->sh = (w2 >> 12) & 0xfff;
36872268
3688   switch (ti_size)
2269   switch (m_misc_state.m_ti_size)
36892270   {
36902271      case PIXEL_SIZE_16BIT:
36912272      {
3692         //UINT16 *src = (UINT16*)&rdram[(ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 2];
36932273         UINT16 *src = (UINT16*)rdram;
3694         UINT32 srcstart = (ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 1;
3695         UINT16 *dst = (UINT16*)&TMEM[tex_tile->tmem];
2274         UINT32 srcstart = (m_misc_state.m_ti_address + (tl >> 2) * (m_misc_state.m_ti_width << 1) + (sl >> 1)) >> 1;
2275         UINT16 *dst = (UINT16*)&m_tmem[tex_tile->tmem];
36962276         int count = ((sh >> 2) - (sl >> 2)) + 1;
36972277
36982278         for (int i = 0; i < count; i++)
r7675r7676
37042284               dst[i*4+2] = 0;
37052285               dst[i*4+3] = 0;
37062286            }
3707            //tlut[i] = src[i];
37082287         }
37092288         break;
37102289      }
3711      /*
3712        case PIXEL_SIZE_16BIT:
3713        {
3714            UINT16 *src = (UINT16*)&rdram[(ti_address + (tl >> 2) * (ti_width << 1) + (sl >> 1)) >> 2];
3715
3716            for (i = (sl >> 2); i <= (sh >> 2); i++)
3717            {
3718                tlut[i] = src[i];
3719            }
3720            break;
3721        }*/
3722      default:   fatalerror("RDP: load_tlut: size = %d\n", ti_size);
2290      default:   fatalerror("RDP::LoadTLUT: size = %d\n", m_misc_state.m_ti_size);
37232291   }
37242292}
37252293
3726static RDP_COMMAND( rdp_set_tile_size )
2294void N64::RDP::Processor::CmdSetTileSize(UINT32 w1, UINT32 w2)
37272295{
3728   int tilenum = (w2 >> 24) & 0x7;
2296   const int tilenum = (w2 >> 24) & 0x7;
37292297
3730   tile[tilenum].sl = (w1 >> 12) & 0xfff;
3731   tile[tilenum].tl = (w1 >>  0) & 0xfff;
3732   tile[tilenum].sh = (w2 >> 12) & 0xfff;
3733   tile[tilenum].th = (w2 >>  0) & 0xfff;
2298   m_tiles[tilenum].sl = (w1 >> 12) & 0xfff;
2299   m_tiles[tilenum].tl = (w1 >>  0) & 0xfff;
2300   m_tiles[tilenum].sh = (w2 >> 12) & 0xfff;
2301   m_tiles[tilenum].th = (w2 >>  0) & 0xfff;
37342302}
37352303
3736static RDP_COMMAND( rdp_load_block )
2304void N64::RDP::Processor::CmdLoadBlock(UINT32 w1, UINT32 w2)
37372305{
37382306   const int tilenum = (w2 >> 24) & 0x7;
3739   const UINT32 ti_address2 = ti_address - ((ti_address & 3) ? 4 : 0);
2307   const UINT32 ti_address2 = m_misc_state.m_ti_address - ((m_misc_state.m_ti_address & 3) ? 4 : 0);
37402308   UINT16 *ram16 = (UINT16*)rdram;
3741   int ti_width2 = ti_width;
2309   int ti_width2 = m_misc_state.m_ti_width;
37422310   int slindwords = 0;
37432311
3744   UINT32 sl = tile[tilenum].sl = ((w1 >> 12) & 0xfff);
3745   UINT32 tl = tile[tilenum].tl = ((w1 >>  0) & 0xfff);
3746   UINT32 sh = tile[tilenum].sh = ((w2 >> 12) & 0xfff);
2312   UINT32 sl = m_tiles[tilenum].sl = ((w1 >> 12) & 0xfff);
2313   UINT32 tl = m_tiles[tilenum].tl = ((w1 >>  0) & 0xfff);
2314   UINT32 sh = m_tiles[tilenum].sh = ((w2 >> 12) & 0xfff);
37472315   UINT32 dxt   = ((w2 >>  0) & 0xfff);
37482316
37492317   int width = (sh - sl) + 1;
r7675r7676
37532321      width = 2048;
37542322   }
37552323
3756   if ((ti_address & 3) && (ti_address & 0xffffff00) != 0xf8a00)
2324   if ((m_misc_state.m_ti_address & 3) && (m_misc_state.m_ti_address & 0xffffff00) != 0xf8a00)
37572325   {
3758      fatalerror( "load block: unaligned ti_address 0x%x",ti_address ); // Rat Attack, Frogger 2 prototype
2326      fatalerror( "load block: unaligned ti_address 0x%x",m_misc_state.m_ti_address ); // Rat Attack, Frogger 2 prototype
37592327   }
37602328
37612329   UINT32* src = (UINT32*)&ram16[ti_address2 >> 1];
3762   UINT32* tc = (UINT32*)TMEM;
3763   UINT32 tb = tile[tilenum].tmem >> 2;
2330   UINT32* tc = GetTMEM32();
2331   UINT32 tb = m_tiles[tilenum].tmem >> 2;
37642332
37652333   slindwords = sl;
37662334
3767   switch (ti_size) // slindwords Neededby Vigilante 8
2335   switch (m_misc_state.m_ti_size) // slindwords Neededby Vigilante 8
37682336   {
3769      case PIXEL_SIZE_4BIT:   ti_width2 >>= 1;   slindwords >>= 3;   width >>= 1;   break;
3770      case PIXEL_SIZE_8BIT:                  slindwords >>= 2;               break;
2337      case PIXEL_SIZE_4BIT:   ti_width2 >>= 1;    slindwords >>= 3;    width >>= 1;   break;
2338      case PIXEL_SIZE_8BIT:                   slindwords >>= 2;               break;
37712339      case PIXEL_SIZE_16BIT:   ti_width2 <<= 1;   slindwords >>= 1;   width <<= 1;   break;
3772      case PIXEL_SIZE_32BIT:   ti_width2 <<= 2;                  width <<= 2;   break;
2340      case PIXEL_SIZE_32BIT:   ti_width2 <<= 2;                   width <<= 2;   break;
37732341   }
37742342
37752343   if ((tb + (width >> 2)) > 0x400)
r7675r7676
37882356      int t = 0;
37892357      int oldt = 0;
37902358      int ptr;
3791      int xorval = (fb_size == PIXEL_SIZE_16BIT && ti_size == PIXEL_SIZE_32BIT ) ? 2 : 1; // Wave Race-specific
2359      int xorval = (m_misc_state.m_fb_size == PIXEL_SIZE_16BIT &&
2360                 m_misc_state.m_ti_size == PIXEL_SIZE_32BIT ) ? 2 : 1; // Wave Race-specific
37922361      UINT32 srcstart = ((tl * ti_width2) >> 2) + slindwords;
37932362      src = &src[srcstart];
37942363      for (int i = 0; i < (width >> 2); i += 2)
r7675r7676
37972366         t = ((j >> 11) & 1) ? xorval : 0;
37982367         if (t > oldt)
37992368         {
3800            i += ((tile[tilenum].line >> 3) << 1);
2369            i += ((m_tiles[tilenum].line >> 3) << 1);
38012370         }
38022371         ptr = tb + i;
38032372         tc[ptr & 0x3ff] = src[i ^ t];
38042373         tc[(ptr + 1) & 0x3ff] = src[(i + 1) ^ t];
38052374         j += dxt;
38062375      }
3807      tile[tilenum].th = tl + (j >> 11);
2376      m_tiles[tilenum].th = tl + (j >> 11);
38082377   }
38092378   else // Needed by Pilotwings 64 intro, Top Gear Rally intro
38102379   {
38112380      UINT32 srcstart = ((tl * ti_width2) >> 2) + slindwords;
38122381      memcpy(&tc[tb],&src[srcstart],width);
3813      tile[tilenum].th = tl;
2382      m_tiles[tilenum].th = tl;
38142383   }
38152384}
38162385
3817static RDP_COMMAND( rdp_load_tile )
2386void N64::RDP::Processor::CmdLoadTile(UINT32 w1, UINT32 w2)
38182387{
38192388   const int tilenum = (w2 >> 24) & 0x7;
3820   TILE *tex_tile = &tile[tilenum];
2389   N64::RDP::Tile *tex_tile = &m_tiles[tilenum];
38212390   int line = tex_tile->line; // Per Ziggy
38222391   int toppad = 0;
38232392
r7675r7676
38312400   tex_tile->sh = ((w2 >> 12) & 0xfff);
38322401   tex_tile->th = ((w2 >>  0) & 0xfff);
38332402
3834   UINT16 sl = tex_tile->sl / 4;
3835   UINT16 tl = tex_tile->tl / 4;
3836   UINT16 sh = tex_tile->sh / 4;
3837   UINT16 th = tex_tile->th / 4;
2403   UINT16 sl = tex_tile->sl >> 2;
2404   UINT16 tl = tex_tile->tl >> 2;
2405   UINT16 sh = tex_tile->sh >> 2;
2406   UINT16 th = tex_tile->th >> 2;
38382407
38392408   int width = (sh - sl) + 1;
38402409   int height = (th - tl) + 1;
38412410
3842   if (ti_size < 3)
2411   if (m_misc_state.m_ti_size < 3)
38432412   {
3844      toppad = (width * ti_size) & 0x7;
2413      toppad = (width * m_misc_state.m_ti_size) & 0x7;
38452414   }
38462415   else
38472416   {
r7675r7676
38492418   }
38502419   toppad = 0; // Currently disabled
38512420
3852   switch (ti_size)
2421   switch (m_misc_state.m_ti_size)
38532422   {
38542423      case PIXEL_SIZE_8BIT:
38552424      {
38562425         UINT8 *src = (UINT8*)rdram;
3857         UINT8 *tc = (UINT8*)TMEM;
3858         int tb = tile[tilenum].tmem;
2426         UINT8 *tc = GetTMEM();
2427         int tb = m_tiles[tilenum].tmem;
38592428
38602429         if (tb + (width * height) > 4096)
38612430         {
r7675r7676
38652434         for (int j = 0; j < height; j++)
38662435         {
38672436            int tline = tb + (tex_tile->line * j);
3868            int s = ((j + tl) * ti_width) + sl;
2437            int s = ((j + tl) * m_misc_state.m_ti_width) + sl;
38692438#define BYTE_XOR_DWORD_SWAP 7
38702439            int xorval8 = ((j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR); // Per Ziggy
38712440
38722441            for (int i = 0; i < width; i++)
38732442            {
3874               tc[(tline + i) ^ xorval8] = src[(ti_address + s + i) ^ BYTE_ADDR_XOR];
2443               tc[(tline + i) ^ xorval8] = src[(m_misc_state.m_ti_address + s + i) ^ BYTE_ADDR_XOR];
38752444            }
38762445         }
38772446         break;
r7675r7676
38792448      case PIXEL_SIZE_16BIT:
38802449      {
38812450         UINT16 *src = (UINT16*)rdram;
3882         UINT32 ti_addr16 = ti_address >> 1;
3883         UINT16 *tc = (UINT16*)TMEM;
2451         UINT32 ti_addr16 = m_misc_state.m_ti_address >> 1;
2452         UINT16 *tc = GetTMEM16();
38842453         int tb = (tex_tile->tmem / 2);
38852454         int taddr;
38862455
r7675r7676
38982467            {
38992468               tline = tb + (tex_tile->line * j);
39002469            }
3901            s = ((j + tl) * ti_width) + sl;
2470            s = ((j + tl) * m_misc_state.m_ti_width) + sl;
39022471#define WORD_XOR_DWORD_SWAP 3
39032472            xorval16 = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
39042473
r7675r7676
39192488      }
39202489      case PIXEL_SIZE_32BIT:
39212490      {
3922         UINT32 *src = (UINT32*)&rdram[ti_address / 4];
3923         UINT32 *tc = (UINT32*)TMEM;
2491         UINT32 *src = (UINT32*)&rdram[m_misc_state.m_ti_address / 4];
2492         UINT32 *tc = GetTMEM32();
39242493         int tb = (tex_tile->tmem / 4);
3925         int xorval32 = ((fb_size == PIXEL_SIZE_16BIT) ? 2 : 1);
2494         int xorval32 = ((m_misc_state.m_fb_size == PIXEL_SIZE_16BIT) ? 2 : 1);
39262495
39272496         if (tb + (width * height) > 1024)
39282497         {
r7675r7676
39322501         for (int j = 0; j < height; j++)
39332502         {
39342503            int tline = tb + ((tex_tile->line / 2) * j);
3935            int s = ((j + tl) * ti_width) + sl;
2504            int s = ((j + tl) * m_misc_state.m_ti_width) + sl;
39362505            int xorval32cur = (j & 1) ? xorval32 : 0;
39372506            for (int i = 0; i < width; i++)
39382507            {
r7675r7676
39422511         break;
39432512      }
39442513
3945      default:   fatalerror("RDP: load_tile: size = %d\n", ti_size);
2514      default:   fatalerror("RDP: load_tile: size = %d\n", m_misc_state.m_ti_size);
39462515   }
3947
39482516}
39492517
3950static RDP_COMMAND( rdp_set_tile )
2518void N64::RDP::Processor::CmdSetTile(UINT32 w1, UINT32 w2)
39512519{
39522520   int tilenum = (w2 >> 24) & 0x7;
3953   TILE* tex_tile = &tile[tilenum];
2521   N64::RDP::Tile* tex_tile = &m_tiles[tilenum];
39542522
39552523   tex_tile->format   = (w1 >> 21) & 0x7;
39562524   tex_tile->size      = (w1 >> 19) & 0x3;
r7675r7676
39652533   tex_tile->ms      = (w2 >>  8) & 0x1;
39662534   tex_tile->mask_s   = (w2 >>  4) & 0xf;
39672535   tex_tile->shift_s   = (w2 >>  0) & 0xf;
3968   tex_tile->fetch_index = (tex_tile->size << 5) | (tex_tile->format << 2) | (other_modes.en_tlut << 1) | (other_modes.tlut_type ? 1 : 0);
39692536
39702537   tex_tile->mask_s = (tex_tile->mask_s > 10) ? 10 : tex_tile->mask_s;
39712538   tex_tile->mask_t = (tex_tile->mask_t > 10) ? 10 : tex_tile->mask_t;
39722539}
39732540
3974static RDP_COMMAND( rdp_fill_rect )
2541void N64::RDP::Processor::CmdFillRect(UINT32 w1, UINT32 w2)
39752542{
3976   RECTANGLE rect;
3977   rect.xl = (w1 >> 14) & 0x3ff;
3978   rect.yl = (w1 >>  2) & 0x3ff;
3979   rect.xh = (w2 >> 14) & 0x3ff;
3980   rect.yh = (w2 >>  2) & 0x3ff;
2543   N64::RDP::Rectangle rect(m_machine, m_cmd_data + m_cmd_cur);
39812544
3982   switch (fb_size)
2545   switch (m_misc_state.m_fb_size)
39832546   {
3984      case PIXEL_SIZE_16BIT:      fill_rectangle_16bit(&rect); break;
3985      case PIXEL_SIZE_32BIT:      fill_rectangle_32bit(&rect); break;
2547      case PIXEL_SIZE_16BIT:
2548         rect.Draw();
2549         break;
2550      case PIXEL_SIZE_32BIT:
2551         fill_rectangle_32bit(m_machine, &rect);
2552         break;
39862553   }
39872554}
39882555
3989static RDP_COMMAND( rdp_set_fill_color )
2556void N64::RDP::Processor::CmdSetFogColor(UINT32 w1, UINT32 w2)
39902557{
3991   fill_color = w2;
2558   m_fog_color.c = w2;
39922559}
39932560
3994static RDP_COMMAND( rdp_set_fog_color )
2561void N64::RDP::Processor::CmdSetBlendColor(UINT32 w1, UINT32 w2)
39952562{
3996   fog_color.c = w2;
3997   //fog_color.i.r = (w2 >> 24) & 0xff;
3998   //fog_color.i.g = (w2 >> 16) & 0xff;
3999   //fog_color.i.b = (w2 >>  8) & 0xff;
4000   //fog_color.i.a = (w2 >>  0) & 0xff;
2563   m_blend_color.c = w2;
40012564}
40022565
4003static RDP_COMMAND( rdp_set_blend_color )
2566void N64::RDP::Processor::CmdSetPrimColor(UINT32 w1, UINT32 w2)
40042567{
4005   blend_color.c = w2;
4006   //blend_color.i.r = (w2 >> 24) & 0xff;
4007   //blend_color.i.g = (w2 >> 16) & 0xff;
4008   //blend_color.i.b = (w2 >>  8) & 0xff;
4009   //blend_color.i.a = (w2 >>  0) & 0xff;
2568   m_misc_state.m_min_level = (w1 >> 8) & 0x1f;
2569   m_prim_lod_frac = w1 & 0xff;
2570   m_prim_color.c = w2;
40102571}
40112572
4012static RDP_COMMAND( rdp_set_prim_color )
2573void N64::RDP::Processor::CmdSetEnvColor(UINT32 w1, UINT32 w2)
40132574{
4014   min_level = (w1 >> 8) & 0x1f;
4015   primitive_lod_frac = (w1 & 0xff);
4016   prim_color.c = w2;
4017   //prim_color.i.r = (w2 >> 24) & 0xff;
4018   //prim_color.i.g = (w2 >> 16) & 0xff;
4019   //prim_color.i.b = (w2 >>  8) & 0xff;
4020   //prim_color.i.a = (w2 >>  0) & 0xff;
2575   m_env_color.c = w2;
40212576}
40222577
4023static RDP_COMMAND( rdp_set_env_color )
2578void N64::RDP::Processor::CmdSetCombine(UINT32 w1, UINT32 w2)
40242579{
4025   env_color.c = w2;
4026   //env_color.i.r = (w2 >> 24) & 0xff;
4027   //env_color.i.g = (w2 >> 16) & 0xff;
4028   //env_color.i.b = (w2 >>  8) & 0xff;
4029   //env_color.i.a = (w2 >>  0) & 0xff;
4030}
2580   m_combine.sub_a_rgb0   = (w1 >> 20) & 0xf;
2581   m_combine.mul_rgb0      = (w1 >> 15) & 0x1f;
2582   m_combine.sub_a_a0      = (w1 >> 12) & 0x7;
2583   m_combine.mul_a0      = (w1 >>  9) & 0x7;
2584   m_combine.sub_a_rgb1   = (w1 >>  5) & 0xf;
2585   m_combine.mul_rgb1      = (w1 >>  0) & 0x1f;
40312586
4032static RDP_COMMAND( rdp_set_combine )
4033{
4034   combine.sub_a_rgb0   = (w1 >> 20) & 0xf;
4035   combine.mul_rgb0   = (w1 >> 15) & 0x1f;
4036   combine.sub_a_a0   = (w1 >> 12) & 0x7;
4037   combine.mul_a0      = (w1 >>  9) & 0x7;
4038   combine.sub_a_rgb1   = (w1 >>  5) & 0xf;
4039   combine.mul_rgb1   = (w1 >>  0) & 0x1f;
2587   m_combine.sub_b_rgb0   = (w2 >> 28) & 0xf;
2588   m_combine.sub_b_rgb1   = (w2 >> 24) & 0xf;
2589   m_combine.sub_a_a1      = (w2 >> 21) & 0x7;
2590   m_combine.mul_a1      = (w2 >> 18) & 0x7;
2591   m_combine.add_rgb0      = (w2 >> 15) & 0x7;
2592   m_combine.sub_b_a0      = (w2 >> 12) & 0x7;
2593   m_combine.add_a0      = (w2 >>  9) & 0x7;
2594   m_combine.add_rgb1      = (w2 >>  6) & 0x7;
2595   m_combine.sub_b_a1      = (w2 >>  3) & 0x7;
2596   m_combine.add_a1      = (w2 >>  0) & 0x7;
40402597
4041   combine.sub_b_rgb0   = (w2 >> 28) & 0xf;
4042   combine.sub_b_rgb1   = (w2 >> 24) & 0xf;
4043   combine.sub_a_a1   = (w2 >> 21) & 0x7;
4044   combine.mul_a1      = (w2 >> 18) & 0x7;
4045   combine.add_rgb0   = (w2 >> 15) & 0x7;
4046   combine.sub_b_a0   = (w2 >> 12) & 0x7;
4047   combine.add_a0      = (w2 >>  9) & 0x7;
4048   combine.add_rgb1   = (w2 >>  6) & 0x7;
4049   combine.sub_b_a1   = (w2 >>  3) & 0x7;
4050   combine.add_a1      = (w2 >>  0) & 0x7;
2598   SetSubAInputRGB(&m_color_inputs.combiner_rgbsub_a_r[0], &m_color_inputs.combiner_rgbsub_a_g[0], &m_color_inputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0);
2599   SetSubBInputRGB(&m_color_inputs.combiner_rgbsub_b_r[0], &m_color_inputs.combiner_rgbsub_b_g[0], &m_color_inputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0);
2600   SetMulInputRGB(&m_color_inputs.combiner_rgbmul_r[0], &m_color_inputs.combiner_rgbmul_g[0], &m_color_inputs.combiner_rgbmul_b[0], m_combine.mul_rgb0);
2601   SetAddInputRGB(&m_color_inputs.combiner_rgbadd_r[0], &m_color_inputs.combiner_rgbadd_g[0], &m_color_inputs.combiner_rgbadd_b[0], m_combine.add_rgb0);
2602   SetSubInputAlpha(&m_color_inputs.combiner_alphasub_a[0], m_combine.sub_a_a0);
2603   SetSubInputAlpha(&m_color_inputs.combiner_alphasub_b[0], m_combine.sub_b_a0);
2604   SetMulInputAlpha(&m_color_inputs.combiner_alphamul[0], m_combine.mul_a0);
2605   SetSubInputAlpha(&m_color_inputs.combiner_alphaadd[0], m_combine.add_a0);
40512606
4052   SET_SUBA_RGB_INPUT(&combiner_rgbsub_a_r[0], &combiner_rgbsub_a_g[0], &combiner_rgbsub_a_b[0], combine.sub_a_rgb0);
4053   SET_SUBB_RGB_INPUT(&combiner_rgbsub_b_r[0], &combiner_rgbsub_b_g[0], &combiner_rgbsub_b_b[0], combine.sub_b_rgb0);
4054   SET_MUL_RGB_INPUT(&combiner_rgbmul_r[0], &combiner_rgbmul_g[0], &combiner_rgbmul_b[0], combine.mul_rgb0);
4055   SET_ADD_RGB_INPUT(&combiner_rgbadd_r[0], &combiner_rgbadd_g[0], &combiner_rgbadd_b[0], combine.add_rgb0);
4056   SET_SUB_ALPHA_INPUT(&combiner_alphasub_a[0], combine.sub_a_a0);
4057   SET_SUB_ALPHA_INPUT(&combiner_alphasub_b[0], combine.sub_b_a0);
4058   SET_MUL_ALPHA_INPUT(&combiner_alphamul[0], combine.mul_a0);
4059   SET_SUB_ALPHA_INPUT(&combiner_alphaadd[0], combine.add_a0);
4060
4061   SET_SUBA_RGB_INPUT(&combiner_rgbsub_a_r[1], &combiner_rgbsub_a_g[1], &combiner_rgbsub_a_b[1], combine.sub_a_rgb1);
4062   SET_SUBB_RGB_INPUT(&combiner_rgbsub_b_r[1], &combiner_rgbsub_b_g[1], &combiner_rgbsub_b_b[1], combine.sub_b_rgb1);
4063   SET_MUL_RGB_INPUT(&combiner_rgbmul_r[1], &combiner_rgbmul_g[1], &combiner_rgbmul_b[1], combine.mul_rgb1);
4064   SET_ADD_RGB_INPUT(&combiner_rgbadd_r[1], &combiner_rgbadd_g[1], &combiner_rgbadd_b[1], combine.add_rgb1);
4065   SET_SUB_ALPHA_INPUT(&combiner_alphasub_a[1], combine.sub_a_a1);
4066   SET_SUB_ALPHA_INPUT(&combiner_alphasub_b[1], combine.sub_b_a1);
4067   SET_MUL_ALPHA_INPUT(&combiner_alphamul[1], combine.mul_a1);
4068   SET_SUB_ALPHA_INPUT(&combiner_alphaadd[1], combine.add_a1);
4069
4070   /*
4071    if(combiner_rgbsub_a_r[1] == &noise_color.i.r)
4072    {
4073        COLOR_COMBINER1 = COLOR_COMBINER1_NOISE;
4074        COLOR_COMBINER2_C0 = COLOR_COMBINER2_C0_NOISE;
4075        COLOR_COMBINER2_C1 = COLOR_COMBINER2_C1_NOISE;
4076    }
4077    else
4078    {
4079        COLOR_COMBINER1 = COLOR_COMBINER1_NNOISE;
4080        COLOR_COMBINER2_C0 = COLOR_COMBINER2_C0_NNOISE;
4081        COLOR_COMBINER2_C1 = COLOR_COMBINER2_C1_NNOISE;
4082    }
4083    */
2607   SetSubAInputRGB(&m_color_inputs.combiner_rgbsub_a_r[1], &m_color_inputs.combiner_rgbsub_a_g[1], &m_color_inputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1);
2608   SetSubBInputRGB(&m_color_inputs.combiner_rgbsub_b_r[1], &m_color_inputs.combiner_rgbsub_b_g[1], &m_color_inputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1);
2609   SetMulInputRGB(&m_color_inputs.combiner_rgbmul_r[1], &m_color_inputs.combiner_rgbmul_g[1], &m_color_inputs.combiner_rgbmul_b[1], m_combine.mul_rgb1);
2610   SetAddInputRGB(&m_color_inputs.combiner_rgbadd_r[1], &m_color_inputs.combiner_rgbadd_g[1], &m_color_inputs.combiner_rgbadd_b[1], m_combine.add_rgb1);
2611   SetSubInputAlpha(&m_color_inputs.combiner_alphasub_a[1], m_combine.sub_a_a1);
2612   SetSubInputAlpha(&m_color_inputs.combiner_alphasub_b[1], m_combine.sub_b_a1);
2613   SetMulInputAlpha(&m_color_inputs.combiner_alphamul[1], m_combine.mul_a1);
2614   SetSubInputAlpha(&m_color_inputs.combiner_alphaadd[1], m_combine.add_a1);
40842615}
40852616
4086static RDP_COMMAND( rdp_set_texture_image )
2617void N64::RDP::Processor::CmdSetTextureImage(UINT32 w1, UINT32 w2)
40872618{
4088   ti_format   = (w1 >> 21) & 0x7;
4089   ti_size      = (w1 >> 19) & 0x3;
4090   ti_width   = (w1 & 0x3ff) + 1;
4091   ti_address   = w2 & 0x01ffffff;
2619   m_misc_state.m_ti_format   = (w1 >> 21) & 0x7;
2620   m_misc_state.m_ti_size      = (w1 >> 19) & 0x3;
2621   m_misc_state.m_ti_width   = (w1 & 0x3ff) + 1;
2622   m_misc_state.m_ti_address   = w2 & 0x01ffffff;
40922623}
40932624
4094static RDP_COMMAND( rdp_set_mask_image )
2625void N64::RDP::Processor::CmdSetMaskImage(UINT32 w1, UINT32 w2)
40952626{
4096   zb_address   = w2 & 0x01ffffff;
2627   m_misc_state.m_zb_address = w2 & 0x01ffffff;
40972628}
40982629
4099static RDP_COMMAND( rdp_set_color_image )
2630void N64::RDP::Processor::CmdSetColorImage(UINT32 w1, UINT32 w2)
41002631{
4101   fb_format   = (w1 >> 21) & 0x7;
4102   fb_size      = (w1 >> 19) & 0x3;
4103   fb_width   = (w1 & 0x3ff) + 1;
4104   fb_address   = w2 & 0x01ffffff;
4105   if (fb_format && fb_format != 2) // Jet Force Gemini sets the format to 4, Intensity.  Protection?
2632   m_misc_state.m_fb_format   = (w1 >> 21) & 0x7;
2633   m_misc_state.m_fb_size      = (w1 >> 19) & 0x3;
2634   m_misc_state.m_fb_width      = (w1 & 0x3ff) + 1;
2635   m_misc_state.m_fb_address   = w2 & 0x01ffffff;
2636
2637   if (m_misc_state.m_fb_format && m_misc_state.m_fb_format != 2) // Jet Force Gemini sets the format to 4, Intensity.  Protection?
41062638   {
4107      if (fb_size == 1)
2639      if (m_misc_state.m_fb_size == 1)
41082640      {
4109         fb_format = 2;
2641         m_misc_state.m_fb_format = 2;
41102642      }
41112643      else
41122644      {
4113         fb_format = 0;
2645         m_misc_state.m_fb_format = 0;
41142646      }
41152647   }
41162648
4117   if (fb_format != 0)
2649   if (m_misc_state.m_fb_format != 0)
41182650   {
4119      fb_format = 0;
2651      m_misc_state.m_fb_format = 0;
41202652   }
41212653}
41222654
4123/*****************************************************************************/
4124
4125static const rdp_command_func rdp_command_table[64] =
2655UINT32 N64::RDP::Processor::AddRightCvg(UINT32 x, UINT32 k)
41262656{
4127   /* 0x00 */
4128   rdp_noop,         rdp_invalid,         rdp_invalid,         rdp_invalid,
4129   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4130   rdp_tri_noshade,   rdp_tri_noshade_z,      rdp_tri_tex,         rdp_tri_tex_z,
4131   rdp_tri_shade,      rdp_tri_shade_z,      rdp_tri_texshade,      rdp_tri_texshade_z,
4132   /* 0x10 */
4133   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4134   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4135   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4136   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4137   /* 0x20 */
4138   rdp_invalid,      rdp_invalid,         rdp_invalid,         rdp_invalid,
4139   rdp_tex_rect,      rdp_tex_rect_flip,      rdp_sync_load,         rdp_sync_pipe,
4140   rdp_sync_tile,      rdp_sync_full,         rdp_set_key_gb,         rdp_set_key_r,
4141   rdp_set_convert,   rdp_set_scissor,      rdp_set_prim_depth,      rdp_set_other_modes,
4142   /* 0x30 */
4143   rdp_load_tlut,      rdp_invalid,         rdp_set_tile_size,      rdp_load_block,
4144   rdp_load_tile,      rdp_set_tile,         rdp_fill_rect,         rdp_set_fill_color,
4145   rdp_set_fog_color,   rdp_set_blend_color,   rdp_set_prim_color,      rdp_set_env_color,
4146   rdp_set_combine,   rdp_set_texture_image,   rdp_set_mask_image,      rdp_set_color_image
4147};
4148
4149void rdp_process_list(running_machine *machine)
4150{
4151   int i;
4152   UINT32 cmd, length, cmd_length;
4153
4154   length = dp_end - dp_current;
4155
4156   // load command data
4157   for (i=0; i < length; i += 4)
4158   {
4159      rdp_cmd_data[rdp_cmd_ptr++] = READ_RDP_DATA((dp_current & 0x1fffffff) + i);
4160      if (rdp_cmd_ptr >= 0x1000)
4161      {
4162         fatalerror("rdp_process_list: rdp_cmd_ptr overflow\n");
4163      }
4164   }
4165
4166   dp_current = dp_end;
4167
4168   cmd = (rdp_cmd_data[0] >> 24) & 0x3f;
4169   cmd_length = (rdp_cmd_ptr + 1) * 4;
4170
4171   // check if more data is needed
4172   if (cmd_length < rdp_command_length[cmd])
4173   {
4174      return;
4175   }
4176
4177   while (rdp_cmd_cur < rdp_cmd_ptr)
4178   {
4179      cmd = (rdp_cmd_data[rdp_cmd_cur] >> 24) & 0x3f;
4180   //  if (((rdp_cmd_data[rdp_cmd_cur] >> 24) & 0xc0) != 0xc0)
4181   //  {
4182   //      fatalerror("rdp_process_list: invalid rdp command %08X at %08X\n", rdp_cmd_data[rdp_cmd_cur], dp_start+(rdp_cmd_cur * 4));
4183   //  }
4184
4185      if (((rdp_cmd_ptr-rdp_cmd_cur) * 4) < rdp_command_length[cmd])
4186      {
4187         return;
4188         //fatalerror("rdp_process_list: not enough rdp command data: cur = %d, ptr = %d, expected = %d\n", rdp_cmd_cur, rdp_cmd_ptr, rdp_command_length[cmd]);
4189      }
4190
4191      if (LOG_RDP_EXECUTION)
4192      {
4193         char string[4000];
4194         rdp_dasm(string);
4195
4196         fprintf(rdp_exec, "%08X: %08X %08X   %s\n", dp_start+(rdp_cmd_cur * 4), rdp_cmd_data[rdp_cmd_cur+0], rdp_cmd_data[rdp_cmd_cur+1], string);
4197      }
4198
4199      // execute the command
4200      rdp_command_table[cmd](machine, rdp_cmd_data[rdp_cmd_cur+0], rdp_cmd_data[rdp_cmd_cur+1]);
4201
4202      rdp_cmd_cur += rdp_command_length[cmd] / 4;
4203   };
4204   rdp_cmd_ptr = 0;
4205   rdp_cmd_cur = 0;
4206
4207   dp_start = dp_current = dp_end;
4208}
4209
4210//INLINE void COMBINER_EQUATION(UINT8 *out, UINT8 *A, UINT8 *B, UINT8 *C, UINT8 *D)
4211//{
4212   //*out = cc_lut_base[(*D << 17) + (*C << 9) + *A - *B];
4213   /* The speedy, lookup table enabled version */
4214   //*out = cc_lut2[(cc_lut1[(*A << 16) | (*B << 8) | *C] << 8) | *D];
4215
4216   /*
4217    The slow, branchy version
4218
4219    INT32 color = (((*A-*B)* *C) + (*D << 8) + 0x80);
4220    color >>= 8;
4221    if (color > 255)
4222    {
4223        *out = 255;
4224    }
4225    else if (color < 0)
4226    {
4227        *out = 0;
4228    }
4229    else
4230    {
4231        *out = (UINT8)color;
4232    }
4233    */
4234//}
4235
4236INLINE void BLENDER_EQUATION0_FORCE(INT32* r, INT32* g, INT32* b, int bsel_special)
4237{
4238   int blend1a = *blender1b_a[0];
4239   INT32 tr, tg, tb;
4240   if (bsel_special)
4241   {
4242      blend1a &= 0xe0;
4243   }
4244
4245   tr = ((int)(*blender1a_r[0]) * blend1a + (int)(*blender2a_r[0]) * *blender2b_a[0] + ((int)(*blender2a_r[0]) << (3 + bsel_special))) >> 8;
4246   tg = ((int)(*blender1a_g[0]) * blend1a + (int)(*blender2a_g[0]) * *blender2b_a[0] + ((int)(*blender2a_g[0]) << (3 + bsel_special))) >> 8;
4247   tb = ((int)(*blender1a_b[0]) * blend1a + (int)(*blender2a_b[0]) * *blender2b_a[0] + ((int)(*blender2a_b[0]) << (3 + bsel_special))) >> 8;
4248
4249   if (tr > 255) *r = 255; else *r = tr;
4250   if (tg > 255) *g = 255; else *g = tg;
4251   if (tb > 255) *b = 255; else *b = tb;
4252}
4253
4254INLINE void BLENDER_EQUATION0_NFORCE(INT32* r, INT32* g, INT32* b, int bsel_special)
4255{
4256   UINT8 blend1a, blend2a;
4257   UINT32 sum = 0;
4258   INT32 tr, tg, tb;
4259   blend1a = *blender1b_a[0];
4260   blend2a = *blender2b_a[0];
4261   if (bsel_special)
4262   {
4263      blend1a &= 0xe0;
4264   }
4265
4266   sum = (((blend1a >> 5) + (blend2a >> 5) + 1) & 0xf) << 5;
4267
4268   tr = (((int)(*blender1a_r[0]) * (int)(blend1a))) +
4269      (((int)(*blender2a_r[0]) * (int)(blend2a)));
4270   tr += (bsel_special) ? (((int)(*blender2a_r[0])) << 5) : (((int)(*blender2a_r[0])) << 3);
4271
4272   tg = (((int)(*blender1a_g[0]) * (int)(blend1a))) +
4273      (((int)(*blender2a_g[0]) * (int)(blend2a)));
4274   tg += (bsel_special) ? ((int)((*blender2a_g[0])) << 5) : (((int)(*blender2a_g[0])) << 3);
4275
4276   tb = (((int)(*blender1a_b[0]) * (int)(blend1a))) +
4277      (((int)(*blender2a_b[0]) * (int)(blend2a)));
4278   tb += (bsel_special) ? (((int)(*blender2a_b[0])) << 5) : (((int)(*blender2a_b[0])) << 3);
4279
4280   if (sum)
4281   {
4282      tr /= sum;
4283      tg /= sum;
4284      tb /= sum;
4285   }
4286   else
4287   {
4288      *r = *g = *b = 0xff;
4289      return;
4290   }
4291
4292
4293   if (tr > 255) *r = 255; else *r = tr;
4294   if (tg > 255) *g = 255; else *g = tg;
4295   if (tb > 255) *b = 255; else *b = tb;
4296}
4297
4298INLINE void BLENDER_EQUATION1_FORCE(INT32* r, INT32* g, INT32* b, int bsel_special)
4299{
4300   UINT8 blend1a, blend2a;
4301   UINT32 sum = 0;
4302   INT32 tr, tg, tb;
4303   blend1a = *blender1b_a[1];
4304   blend2a = *blender2b_a[1];
4305   if (bsel_special)
4306   {
4307      blend1a &= 0xe0;
4308   }
4309
4310   sum = (((blend1a >> 5) + (blend2a >> 5) + 1) & 0xf) << 5;
4311
4312   tr = (((int)(*blender1a_r[1]) * (int)(blend1a))) +
4313      (((int)(*blender2a_r[1]) * (int)(blend2a)));
4314   tr += (bsel_special) ? (((int)(*blender2a_r[1])) << 5) : (((int)(*blender2a_r[1])) << 3);
4315
4316   tg = (((int)(*blender1a_g[1]) * (int)(blend1a))) +
4317      (((int)(*blender2a_g[1]) * (int)(blend2a)));
4318   tg += (bsel_special) ? ((int)((*blender2a_g[1])) << 5) : (((int)(*blender2a_g[1])) << 3);
4319
4320   tb = (((int)(*blender1a_b[1]) * (int)(blend1a))) +
4321      (((int)(*blender2a_b[1]) * (int)(blend2a)));
4322   tb += (bsel_special) ? (((int)(*blender2a_b[1])) << 5) : (((int)(*blender2a_b[1])) << 3);
4323
4324   tr >>= 8;
4325   tg >>= 8;
4326   tb >>= 8;
4327
4328   if (tr > 255) *r = 255; else *r = tr;
4329   if (tg > 255) *g = 255; else *g = tg;
4330   if (tb > 255) *b = 255; else *b = tb;
4331}
4332
4333INLINE void BLENDER_EQUATION1_NFORCE(INT32* r, INT32* g, INT32* b, int bsel_special)
4334{
4335   UINT8 blend1a, blend2a;
4336   UINT32 sum = 0;
4337   INT32 tr, tg, tb;
4338   blend1a = *blender1b_a[1];
4339   blend2a = *blender2b_a[1];
4340   if (bsel_special)
4341   {
4342      blend1a &= 0xe0;
4343   }
4344
4345   sum = (((blend1a >> 5) + (blend2a >> 5) + 1) & 0xf) << 5;
4346
4347   tr = (((int)(*blender1a_r[1]) * (int)(blend1a))) +
4348      (((int)(*blender2a_r[1]) * (int)(blend2a)));
4349   tr += (bsel_special) ? (((int)(*blender2a_r[1])) << 5) : (((int)(*blender2a_r[1])) << 3);
4350
4351   tg = (((int)(*blender1a_g[1]) * (int)(blend1a))) +
4352      (((int)(*blender2a_g[1]) * (int)(blend2a)));
4353   tg += (bsel_special) ? ((int)((*blender2a_g[1])) << 5) : (((int)(*blender2a_g[1])) << 3);
4354
4355   tb = (((int)(*blender1a_b[1]) * (int)(blend1a))) +
4356      (((int)(*blender2a_b[1]) * (int)(blend2a)));
4357   tb += (bsel_special) ? (((int)(*blender2a_b[1])) << 5) : (((int)(*blender2a_b[1])) << 3);
4358
4359   if (sum)
4360   {
4361      tr /= sum;
4362      tg /= sum;
4363      tb /= sum;
4364   }
4365   else
4366   {
4367      *r = *g = *b = 0xff;
4368      return;
4369   }
4370
4371   if (tr > 255) *r = 255; else *r = tr;
4372   if (tg > 255) *g = 255; else *g = tg;
4373   if (tb > 255) *b = 255; else *b = tb;
4374}
4375
4376INLINE UINT32 addrightcvg(UINT32 x, UINT32 k)
4377{
43782657//#undef FULL_SUBPIXELS
43792658#define FULL_SUBPIXELS
43802659   UINT32 coveredsubpixels=((x >> 14) & 3);
r7675r7676
43982677#endif
43992678   if (!(k & 1))
44002679   {
4401      return (coveredsubpixels < 2) ? 1 : 2;
2680      return (coveredsubpixels<2) ? 1 : 2;
44022681   }
44032682   else
44042683   {
r7675r7676
44172696   }
44182697}
44192698
4420INLINE UINT32 addleftcvg(UINT32 x, UINT32 k)
2699UINT32 N64::RDP::Processor::AddLeftCvg(UINT32 x, UINT32 k)
44212700{
44222701   UINT32 coveredsubpixels = 3 - ((x >> 14) & 3);
44232702   if (!(x & 0xffff))
r7675r7676
44592738   }
44602739}
44612740
4462#include "video/rdpacomp.c"
2741/*****************************************************************************/
44632742
4464#include "video/rdpacvg.c"
2743void N64::RDP::Processor::CmdInvalid(UINT32 w1, UINT32 w2)
2744{
2745   fatalerror("N64::RDP::Processor::Invalid: %d, %08x %08x\n", (w1 >> 24) & 0x3f, w1, w2);
2746}
44652747
4466#define COLOR_ON_CVG
4467   #include "video/rdpfb.c"
4468#undef COLOR_ON_CVG
4469   #include "video/rdpfb.c"
2748void N64::RDP::Processor::CmdNoOp(UINT32 w1, UINT32 w2)
2749{
2750   // Do nothing
2751}
44702752
4471#define FORCEBLEND
4472   #define ALPHACOMPARE
4473      #define IMGREAD
4474         #define ZCOMPARE
4475            #define RGBDITHER1
4476               #include "video/rdpblend.c"
4477            #undef RGBDITHER1
4478               #include "video/rdpblend.c"
4479         #undef ZCOMPARE
4480            #define RGBDITHER1
4481               #include "video/rdpblend.c"
4482            #undef RGBDITHER1
4483               #include "video/rdpblend.c"
4484      #undef IMGREAD
4485         #define ZCOMPARE
4486            #define RGBDITHER1
4487               #include "video/rdpblend.c"
4488            #undef RGBDITHER1
4489               #include "video/rdpblend.c"
4490         #undef ZCOMPARE
4491            #define RGBDITHER1
4492               #include "video/rdpblend.c"
4493            #undef RGBDITHER1
4494               #include "video/rdpblend.c"
4495   #undef ALPHACOMPARE
4496      #define IMGREAD
4497         #define ZCOMPARE
4498            #define RGBDITHER1
4499               #include "video/rdpblend.c"
4500            #undef RGBDITHER1
4501               #include "video/rdpblend.c"
4502         #undef ZCOMPARE
4503            #define RGBDITHER1
4504               #include "video/rdpblend.c"
4505            #undef RGBDITHER1
4506               #include "video/rdpblend.c"
4507      #undef IMGREAD
4508         #define ZCOMPARE
4509            #define RGBDITHER1
4510               #include "video/rdpblend.c"
4511            #undef RGBDITHER1
4512               #include "video/rdpblend.c"
4513         #undef ZCOMPARE
4514            #define RGBDITHER1
4515               #include "video/rdpblend.c"
4516            #undef RGBDITHER1
4517               #include "video/rdpblend.c"
4518#undef FORCEBLEND
4519   #define ALPHACOMPARE
4520      #define IMGREAD
4521         #define ZCOMPARE
4522            #define RGBDITHER1
4523               #include "video/rdpblend.c"
4524            #undef RGBDITHER1
4525               #include "video/rdpblend.c"
4526         #undef ZCOMPARE
4527            #define RGBDITHER1
4528               #include "video/rdpblend.c"
4529            #undef RGBDITHER1
4530               #include "video/rdpblend.c"
4531      #undef IMGREAD
4532         #define ZCOMPARE
4533            #define RGBDITHER1
4534               #include "video/rdpblend.c"
4535            #undef RGBDITHER1
4536               #include "video/rdpblend.c"
4537         #undef ZCOMPARE
4538            #define RGBDITHER1
4539               #include "video/rdpblend.c"
4540            #undef RGBDITHER1
4541               #include "video/rdpblend.c"
4542   #undef ALPHACOMPARE
4543      #define IMGREAD
4544         #define ZCOMPARE
4545            #define RGBDITHER1
4546               #include "video/rdpblend.c"
4547            #undef RGBDITHER1
4548               #include "video/rdpblend.c"
4549         #undef ZCOMPARE
4550            #define RGBDITHER1
4551               #include "video/rdpblend.c"
4552            #undef RGBDITHER1
4553               #include "video/rdpblend.c"
4554      #undef IMGREAD
4555         #define ZCOMPARE
4556            #define RGBDITHER1
4557               #include "video/rdpblend.c"
4558            #undef RGBDITHER1
4559               #include "video/rdpblend.c"
4560         #undef ZCOMPARE
4561            #define RGBDITHER1
4562               #include "video/rdpblend.c"
4563            #undef RGBDITHER1
4564               #include "video/rdpblend.c"
45652753
4566#include "video/rdpfetch.c"
2754void N64::RDP::Processor::ProcessList()
2755{
2756   UINT32 length = m_end - m_current;
45672757
4568#define SHIFT_T
4569   #define SHIFT_S
4570      #define DOT
4571         #define DOS
4572            #define COPY
4573               #include "video/rdptpipe.c"
4574            #undef COPY
4575               #include "video/rdptpipe.c"
4576         #undef DOS
4577            #define COPY
4578               #include "video/rdptpipe.c"
4579            #undef COPY
4580               #include "video/rdptpipe.c"
4581      #undef DOT
4582         #define DOS
4583            #define COPY
4584               #include "video/rdptpipe.c"
4585            #undef COPY
4586               #include "video/rdptpipe.c"
4587         #undef DOS
4588            #define COPY
4589               #include "video/rdptpipe.c"
4590            #undef COPY
4591               #include "video/rdptpipe.c"
4592   #undef SHIFT_S
4593      #define DOT
4594         #define DOS
4595            #define COPY
4596               #include "video/rdptpipe.c"
4597            #undef COPY
4598               #include "video/rdptpipe.c"
4599         #undef DOS
4600            #define COPY
4601               #include "video/rdptpipe.c"
4602            #undef COPY
4603               #include "video/rdptpipe.c"
4604      #undef DOT
4605         #define DOS
4606            #define COPY
4607               #include "video/rdptpipe.c"
4608            #undef COPY
4609               #include "video/rdptpipe.c"
4610         #undef DOS
4611            #define COPY
4612               #include "video/rdptpipe.c"
4613            #undef COPY
4614               #include "video/rdptpipe.c"
4615#undef SHIFT_T
4616   #define SHIFT_S
4617      #define DOT
4618         #define DOS
4619            #define COPY
4620               #include "video/rdptpipe.c"
4621            #undef COPY
4622               #include "video/rdptpipe.c"
4623         #undef DOS
4624            #define COPY
4625               #include "video/rdptpipe.c"
4626            #undef COPY
4627               #include "video/rdptpipe.c"
4628      #undef DOT
4629         #define DOS
4630            #define COPY
4631               #include "video/rdptpipe.c"
4632            #undef COPY
4633               #include "video/rdptpipe.c"
4634         #undef DOS
4635            #define COPY
4636               #include "video/rdptpipe.c"
4637            #undef COPY
4638               #include "video/rdptpipe.c"
4639   #undef SHIFT_S
4640      #define DOT
4641         #define DOS
4642            #define COPY
4643               #include "video/rdptpipe.c"
4644            #undef COPY
4645               #include "video/rdptpipe.c"
4646         #undef DOS
4647            #define COPY
4648               #include "video/rdptpipe.c"
4649            #undef COPY
4650               #include "video/rdptpipe.c"
4651      #undef DOT
4652         #define DOS
4653            #define COPY
4654               #include "video/rdptpipe.c"
4655            #undef COPY
4656               #include "video/rdptpipe.c"
4657         #undef DOS
4658            #define COPY
4659               #include "video/rdptpipe.c"
4660            #undef COPY
4661               #include "video/rdptpipe.c"
2758   // load command data
2759   for(int i = 0; i < length; i += 4)
2760   {
2761      m_cmd_data[m_cmd_ptr++] = ReadData((m_current & 0x1fffffff) + i);
2762   }
46622763
4663#define ZCOMPARE
4664   #define ZUPDATE
4665      #define MAGICDITHER
4666         #include "video/rdptrect.c"
4667      #undef MAGICDITHER
4668      #define BAYERDITHER
4669         #include "video/rdptrect.c"
4670      #undef BAYERDITHER
4671         #include "video/rdptrect.c"
4672   #undef ZUPDATE
4673      #define MAGICDITHER
4674         #include "video/rdptrect.c"
4675      #undef MAGICDITHER
4676      #define BAYERDITHER
4677         #include "video/rdptrect.c"
4678      #undef BAYERDITHER
4679         #include "video/rdptrect.c"
4680#undef ZCOMPARE
4681   #define ZUPDATE
4682      #define MAGICDITHER
4683         #include "video/rdptrect.c"
4684      #undef MAGICDITHER
4685      #define BAYERDITHER
4686         #include "video/rdptrect.c"
4687      #undef BAYERDITHER
4688         #include "video/rdptrect.c"
4689   #undef ZUPDATE
4690      #define MAGICDITHER
4691         #include "video/rdptrect.c"
4692      #undef MAGICDITHER
4693      #define BAYERDITHER
4694         #include "video/rdptrect.c"
4695      #undef BAYERDITHER
4696         #include "video/rdptrect.c"
2764   m_current = m_end;
46972765
4698#define MAGICDITHER
4699   #include "video/rdpfrect.c"
4700#undef MAGICDITHER
4701#define BAYERDITHER
4702   #include "video/rdpfrect.c"
4703#undef BAYERDITHER
4704   #include "video/rdpfrect.c"
2766   UINT32 cmd = (m_cmd_data[0] >> 24) & 0x3f;
2767   UINT32 cmd_length = (m_cmd_ptr + 1) * 4;
47052768
4706#define MAGICDITHER
4707   #define SHADE
4708      #define TEXTURE
4709         #define ZBUF
4710            #define FLIP
4711               #define ZUPDATE
4712                  #define ZCOMPARE
4713                     #include "video/rdpspn16.c"
4714                  #undef ZCOMPARE
4715                     #include "video/rdpspn16.c"
4716               #undef ZUPDATE
4717                  #define ZCOMPARE
4718                     #include "video/rdpspn16.c"
4719                  #undef ZCOMPARE
4720                     #include "video/rdpspn16.c"
4721            #undef FLIP
4722               #define ZUPDATE
4723                  #define ZCOMPARE
4724                     #include "video/rdpspn16.c"
4725                  #undef ZCOMPARE
4726                     #include "video/rdpspn16.c"
4727               #undef ZUPDATE
4728                  #define ZCOMPARE
4729                     #include "video/rdpspn16.c"
4730                  #undef ZCOMPARE
4731                     #include "video/rdpspn16.c"
4732         #undef ZBUF
4733            #define FLIP
4734               #define ZUPDATE
4735                  #define ZCOMPARE
4736                     #include "video/rdpspn16.c"
4737                  #undef ZCOMPARE
4738                     #include "video/rdpspn16.c"
4739               #undef ZUPDATE
4740                  #define ZCOMPARE
4741                     #include "video/rdpspn16.c"
4742                  #undef ZCOMPARE
4743                     #include "video/rdpspn16.c"
4744            #undef FLIP
4745               #define ZUPDATE
4746                  #define ZCOMPARE
4747                     #include "video/rdpspn16.c"
4748                  #undef ZCOMPARE
4749                     #include "video/rdpspn16.c"
4750               #undef ZUPDATE
4751                  #define ZCOMPARE
4752                     #include "video/rdpspn16.c"
4753                  #undef ZCOMPARE
4754                     #include "video/rdpspn16.c"
4755      #undef TEXTURE
4756         #define ZBUF
4757            #define FLIP
4758               #define ZUPDATE
4759                  #define ZCOMPARE
4760                     #include "video/rdpspn16.c"
4761                  #undef ZCOMPARE
4762                     #include "video/rdpspn16.c"
4763               #undef ZUPDATE
4764                  #define ZCOMPARE
4765                     #include "video/rdpspn16.c"
4766                  #undef ZCOMPARE
4767                     #include "video/rdpspn16.c"
4768            #undef FLIP
4769               #define ZUPDATE
4770                  #define ZCOMPARE
4771                     #include "video/rdpspn16.c"
4772                  #undef ZCOMPARE
4773                     #include "video/rdpspn16.c"
4774               #undef ZUPDATE
4775                  #define ZCOMPARE
4776                     #include "video/rdpspn16.c"
4777                  #undef ZCOMPARE
4778                     #include "video/rdpspn16.c"
4779         #undef ZBUF
4780            #define FLIP
4781               #define ZUPDATE
4782                  #define ZCOMPARE
4783                     #include "video/rdpspn16.c"
4784                  #undef ZCOMPARE
4785                     #include "video/rdpspn16.c"
4786               #undef ZUPDATE
4787                  #define ZCOMPARE
4788                     #include "video/rdpspn16.c"
4789                  #undef ZCOMPARE
4790                     #include "video/rdpspn16.c"
4791            #undef FLIP
4792               #define ZUPDATE
4793                  #define ZCOMPARE
4794                     #include "video/rdpspn16.c"
4795                  #undef ZCOMPARE
4796                     #include "video/rdpspn16.c"
4797               #undef ZUPDATE
4798                  #define ZCOMPARE
4799                     #include "video/rdpspn16.c"
4800                  #undef ZCOMPARE
4801                     #include "video/rdpspn16.c"
4802   #undef SHADE
4803      #define TEXTURE
4804         #define ZBUF
4805            #define FLIP
4806               #define ZUPDATE
4807                  #define ZCOMPARE
4808                     #include "video/rdpspn16.c"
4809                  #undef ZCOMPARE
4810                     #include "video/rdpspn16.c"
4811               #undef ZUPDATE
4812                  #define ZCOMPARE
4813                     #include "video/rdpspn16.c"
4814                  #undef ZCOMPARE
4815                     #include "video/rdpspn16.c"
4816            #undef FLIP
4817               #define ZUPDATE
4818                  #define ZCOMPARE
4819                     #include "video/rdpspn16.c"
4820                  #undef ZCOMPARE
4821                     #include "video/rdpspn16.c"
4822               #undef ZUPDATE
4823                  #define ZCOMPARE
4824                     #include "video/rdpspn16.c"
4825                  #undef ZCOMPARE
4826                     #include "video/rdpspn16.c"
4827         #undef ZBUF
4828            #define FLIP
4829               #define ZUPDATE
4830                  #define ZCOMPARE
4831                     #include "video/rdpspn16.c"
4832                  #undef ZCOMPARE
4833                     #include "video/rdpspn16.c"
4834               #undef ZUPDATE
4835                  #define ZCOMPARE
4836                     #include "video/rdpspn16.c"
4837                  #undef ZCOMPARE
4838                     #include "video/rdpspn16.c"
4839            #undef FLIP
4840               #define ZUPDATE
4841                  #define ZCOMPARE
4842                     #include "video/rdpspn16.c"
4843                  #undef ZCOMPARE
4844                     #include "video/rdpspn16.c"
4845               #undef ZUPDATE
4846                  #define ZCOMPARE
4847                     #include "video/rdpspn16.c"
4848                  #undef ZCOMPARE
4849                     #include "video/rdpspn16.c"
4850      #undef TEXTURE
4851         #define ZBUF
4852            #define FLIP
4853               #define ZUPDATE
4854                  #define ZCOMPARE
4855                     #include "video/rdpspn16.c"
4856                  #undef ZCOMPARE
4857                     #include "video/rdpspn16.c"
4858               #undef ZUPDATE
4859                  #define ZCOMPARE
4860                     #include "video/rdpspn16.c"
4861                  #undef ZCOMPARE
4862                     #include "video/rdpspn16.c"
4863            #undef FLIP
4864               #define ZUPDATE
4865                  #define ZCOMPARE
4866                     #include "video/rdpspn16.c"
4867                  #undef ZCOMPARE
4868                     #include "video/rdpspn16.c"
4869               #undef ZUPDATE
4870                  #define ZCOMPARE
4871                     #include "video/rdpspn16.c"
4872                  #undef ZCOMPARE
4873                     #include "video/rdpspn16.c"
4874         #undef ZBUF
4875            #define FLIP
4876               #define ZUPDATE
4877                  #define ZCOMPARE
4878                     #include "video/rdpspn16.c"
4879                  #undef ZCOMPARE
4880                     #include "video/rdpspn16.c"
4881               #undef ZUPDATE
4882                  #define ZCOMPARE
4883                     #include "video/rdpspn16.c"
4884                  #undef ZCOMPARE
4885                     #include "video/rdpspn16.c"
4886            #undef FLIP
4887               #define ZUPDATE
4888                  #define ZCOMPARE
4889                     #include "video/rdpspn16.c"
4890                  #undef ZCOMPARE
4891                     #include "video/rdpspn16.c"
4892               #undef ZUPDATE
4893                  #define ZCOMPARE
4894                     #include "video/rdpspn16.c"
4895                  #undef ZCOMPARE
4896                     #include "video/rdpspn16.c"
4897#undef MAGICDITHER
4898#define BAYERDITHER
4899   #define SHADE
4900      #define TEXTURE
4901         #define ZBUF
4902            #define FLIP
4903               #define ZUPDATE
4904                  #define ZCOMPARE
4905                     #include "video/rdpspn16.c"
4906                  #undef ZCOMPARE
4907                     #include "video/rdpspn16.c"
4908               #undef ZUPDATE
4909                  #define ZCOMPARE
4910                     #include "video/rdpspn16.c"
4911                  #undef ZCOMPARE
4912                     #include "video/rdpspn16.c"
4913            #undef FLIP
4914               #define ZUPDATE
4915                  #define ZCOMPARE
4916                     #include "video/rdpspn16.c"
4917                  #undef ZCOMPARE
4918                     #include "video/rdpspn16.c"
4919               #undef ZUPDATE
4920                  #define ZCOMPARE
4921                     #include "video/rdpspn16.c"
4922                  #undef ZCOMPARE
4923                     #include "video/rdpspn16.c"
4924         #undef ZBUF
4925            #define FLIP
4926               #define ZUPDATE
4927                  #define ZCOMPARE
4928                     #include "video/rdpspn16.c"
4929                  #undef ZCOMPARE
4930                     #include "video/rdpspn16.c"
4931               #undef ZUPDATE
4932                  #define ZCOMPARE
4933                     #include "video/rdpspn16.c"
4934                  #undef ZCOMPARE
4935                     #include "video/rdpspn16.c"
4936            #undef FLIP
4937               #define ZUPDATE
4938                  #define ZCOMPARE
4939                     #include "video/rdpspn16.c"
4940                  #undef ZCOMPARE
4941                     #include "video/rdpspn16.c"
4942               #undef ZUPDATE
4943                  #define ZCOMPARE
4944                     #include "video/rdpspn16.c"
4945                  #undef ZCOMPARE
4946                     #include "video/rdpspn16.c"
4947      #undef TEXTURE
4948         #define ZBUF
4949            #define FLIP
4950               #define ZUPDATE
4951                  #define ZCOMPARE
4952                     #include "video/rdpspn16.c"
4953                  #undef ZCOMPARE
4954                     #include "video/rdpspn16.c"
4955               #undef ZUPDATE
4956                  #define ZCOMPARE
4957                     #include "video/rdpspn16.c"
4958                  #undef ZCOMPARE
4959                     #include "video/rdpspn16.c"
4960            #undef FLIP
4961               #define ZUPDATE
4962                  #define ZCOMPARE
4963                     #include "video/rdpspn16.c"
4964                  #undef ZCOMPARE
4965                     #include "video/rdpspn16.c"
4966               #undef ZUPDATE
4967                  #define ZCOMPARE
4968                     #include "video/rdpspn16.c"
4969                  #undef ZCOMPARE
4970                     #include "video/rdpspn16.c"
4971         #undef ZBUF
4972            #define FLIP
4973               #define ZUPDATE
4974                  #define ZCOMPARE
4975                     #include "video/rdpspn16.c"
4976                  #undef ZCOMPARE
4977                     #include "video/rdpspn16.c"
4978               #undef ZUPDATE
4979                  #define ZCOMPARE
4980                     #include "video/rdpspn16.c"
4981                  #undef ZCOMPARE
4982                     #include "video/rdpspn16.c"
4983            #undef FLIP
4984               #define ZUPDATE
4985                  #define ZCOMPARE
4986                     #include "video/rdpspn16.c"
4987                  #undef ZCOMPARE
4988                     #include "video/rdpspn16.c"
4989               #undef ZUPDATE
4990                  #define ZCOMPARE
4991                     #include "video/rdpspn16.c"
4992                  #undef ZCOMPARE
4993                     #include "video/rdpspn16.c"
4994   #undef SHADE
4995      #define TEXTURE
4996         #define ZBUF
4997            #define FLIP
4998               #define ZUPDATE
4999                  #define ZCOMPARE
5000                     #include "video/rdpspn16.c"
5001                  #undef ZCOMPARE
5002                     #include "video/rdpspn16.c"
5003               #undef ZUPDATE
5004                  #define ZCOMPARE
5005                     #include "video/rdpspn16.c"
5006                  #undef ZCOMPARE
5007                     #include "video/rdpspn16.c"
5008            #undef FLIP
5009               #define ZUPDATE
5010                  #define ZCOMPARE
5011                     #include "video/rdpspn16.c"
5012                  #undef ZCOMPARE
5013                     #include "video/rdpspn16.c"
5014               #undef ZUPDATE
5015                  #define ZCOMPARE
5016                     #include "video/rdpspn16.c"
5017                  #undef ZCOMPARE
5018                     #include "video/rdpspn16.c"
5019         #undef ZBUF
5020            #define FLIP
5021               #define ZUPDATE
5022                  #define ZCOMPARE
5023                     #include "video/rdpspn16.c"
5024                  #undef ZCOMPARE
5025                     #include "video/rdpspn16.c"
5026               #undef ZUPDATE
5027                  #define ZCOMPARE
5028                     #include "video/rdpspn16.c"
5029                  #undef ZCOMPARE
5030                     #include "video/rdpspn16.c"
5031            #undef FLIP
5032               #define ZUPDATE
5033                  #define ZCOMPARE
5034                     #include "video/rdpspn16.c"
5035                  #undef ZCOMPARE
5036                     #include "video/rdpspn16.c"
5037               #undef ZUPDATE
5038                  #define ZCOMPARE
5039                     #include "video/rdpspn16.c"
5040                  #undef ZCOMPARE
5041                     #include "video/rdpspn16.c"
5042      #undef TEXTURE
5043         #define ZBUF
5044            #define FLIP
5045               #define ZUPDATE
5046                  #define ZCOMPARE
5047                     #include "video/rdpspn16.c"
5048                  #undef ZCOMPARE
5049                     #include "video/rdpspn16.c"
5050               #undef ZUPDATE
5051                  #define ZCOMPARE
5052                     #include "video/rdpspn16.c"
5053                  #undef ZCOMPARE
5054                     #include "video/rdpspn16.c"
5055            #undef FLIP
5056               #define ZUPDATE
5057                  #define ZCOMPARE
5058                     #include "video/rdpspn16.c"
5059                  #undef ZCOMPARE
5060                     #include "video/rdpspn16.c"
5061               #undef ZUPDATE
5062                  #define ZCOMPARE
5063                     #include "video/rdpspn16.c"
5064                  #undef ZCOMPARE
5065                     #include "video/rdpspn16.c"
5066         #undef ZBUF
5067            #define FLIP
5068               #define ZUPDATE
5069                  #define ZCOMPARE
5070                     #include "video/rdpspn16.c"
5071                  #undef ZCOMPARE
5072                     #include "video/rdpspn16.c"
5073               #undef ZUPDATE
5074                  #define ZCOMPARE
5075                     #include "video/rdpspn16.c"
5076                  #undef ZCOMPARE
5077                     #include "video/rdpspn16.c"
5078            #undef FLIP
5079               #define ZUPDATE
5080                  #define ZCOMPARE
5081                     #include "video/rdpspn16.c"
5082                  #undef ZCOMPARE
5083                     #include "video/rdpspn16.c"
5084               #undef ZUPDATE
5085                  #define ZCOMPARE
5086                     #include "video/rdpspn16.c"
5087                  #undef ZCOMPARE
5088                     #include "video/rdpspn16.c"
5089#undef BAYERDITHER
5090   #define SHADE
5091      #define TEXTURE
5092         #define ZBUF
5093            #define FLIP
5094               #define ZUPDATE
5095                  #define ZCOMPARE
5096                     #include "video/rdpspn16.c"
5097                  #undef ZCOMPARE
5098                     #include "video/rdpspn16.c"
5099               #undef ZUPDATE
5100                  #define ZCOMPARE
5101                     #include "video/rdpspn16.c"
5102                  #undef ZCOMPARE
5103                     #include "video/rdpspn16.c"
5104            #undef FLIP
5105               #define ZUPDATE
5106                  #define ZCOMPARE
5107                     #include "video/rdpspn16.c"
5108                  #undef ZCOMPARE
5109                     #include "video/rdpspn16.c"
5110               #undef ZUPDATE
5111                  #define ZCOMPARE
5112                     #include "video/rdpspn16.c"
5113                  #undef ZCOMPARE
5114                     #include "video/rdpspn16.c"
5115         #undef ZBUF
5116            #define FLIP
5117               #define ZUPDATE
5118                  #define ZCOMPARE
5119                     #include "video/rdpspn16.c"
5120                  #undef ZCOMPARE
5121                     #include "video/rdpspn16.c"
5122               #undef ZUPDATE
5123                  #define ZCOMPARE
5124                     #include "video/rdpspn16.c"
5125                  #undef ZCOMPARE
5126                     #include "video/rdpspn16.c"
5127            #undef FLIP
5128               #define ZUPDATE
5129                  #define ZCOMPARE
5130                     #include "video/rdpspn16.c"
5131                  #undef ZCOMPARE
5132                     #include "video/rdpspn16.c"
5133               #undef ZUPDATE
5134                  #define ZCOMPARE
5135                     #include "video/rdpspn16.c"
5136                  #undef ZCOMPARE
5137                     #include "video/rdpspn16.c"
5138      #undef TEXTURE
5139         #define ZBUF
5140            #define FLIP
5141               #define ZUPDATE
5142                  #define ZCOMPARE
5143                     #include "video/rdpspn16.c"
5144                  #undef ZCOMPARE
5145                     #include "video/rdpspn16.c"
5146               #undef ZUPDATE
5147                  #define ZCOMPARE
5148                     #include "video/rdpspn16.c"
5149                  #undef ZCOMPARE
5150                     #include "video/rdpspn16.c"
5151            #undef FLIP
5152               #define ZUPDATE
5153                  #define ZCOMPARE
5154                     #include "video/rdpspn16.c"
5155                  #undef ZCOMPARE
5156                     #include "video/rdpspn16.c"
5157               #undef ZUPDATE
5158                  #define ZCOMPARE
5159                     #include "video/rdpspn16.c"
5160                  #undef ZCOMPARE
5161                     #include "video/rdpspn16.c"
5162         #undef ZBUF
5163            #define FLIP
5164               #define ZUPDATE
5165                  #define ZCOMPARE
5166                     #include "video/rdpspn16.c"
5167                  #undef ZCOMPARE
5168                     #include "video/rdpspn16.c"
5169               #undef ZUPDATE
5170                  #define ZCOMPARE
5171                     #include "video/rdpspn16.c"
5172                  #undef ZCOMPARE
5173                     #include "video/rdpspn16.c"
5174            #undef FLIP
5175               #define ZUPDATE
5176                  #define ZCOMPARE
5177                     #include "video/rdpspn16.c"
5178                  #undef ZCOMPARE
5179                     #include "video/rdpspn16.c"
5180               #undef ZUPDATE
5181                  #define ZCOMPARE
5182                     #include "video/rdpspn16.c"
5183                  #undef ZCOMPARE
5184                     #include "video/rdpspn16.c"
5185   #undef SHADE
5186      #define TEXTURE
5187         #define ZBUF
5188            #define FLIP
5189               #define ZUPDATE
5190                  #define ZCOMPARE
5191                     #include "video/rdpspn16.c"
5192                  #undef ZCOMPARE
5193                     #include "video/rdpspn16.c"
5194               #undef ZUPDATE
5195                  #define ZCOMPARE
5196                     #include "video/rdpspn16.c"
5197                  #undef ZCOMPARE
5198                     #include "video/rdpspn16.c"
5199            #undef FLIP
5200               #define ZUPDATE
5201                  #define ZCOMPARE
5202                     #include "video/rdpspn16.c"
5203                  #undef ZCOMPARE
5204                     #include "video/rdpspn16.c"
5205               #undef ZUPDATE
5206                  #define ZCOMPARE
5207                     #include "video/rdpspn16.c"
5208                  #undef ZCOMPARE
5209                     #include "video/rdpspn16.c"
5210         #undef ZBUF
5211            #define FLIP
5212               #define ZUPDATE
5213                  #define ZCOMPARE
5214                     #include "video/rdpspn16.c"
5215                  #undef ZCOMPARE
5216                     #include "video/rdpspn16.c"
5217               #undef ZUPDATE
5218                  #define ZCOMPARE
5219                     #include "video/rdpspn16.c"
5220                  #undef ZCOMPARE
5221                     #include "video/rdpspn16.c"
5222            #undef FLIP
5223               #define ZUPDATE
5224                  #define ZCOMPARE
5225                     #include "video/rdpspn16.c"
5226                  #undef ZCOMPARE
5227                     #include "video/rdpspn16.c"
5228               #undef ZUPDATE
5229                  #define ZCOMPARE
5230                     #include "video/rdpspn16.c"
5231                  #undef ZCOMPARE
5232                     #include "video/rdpspn16.c"
5233      #undef TEXTURE
5234         #define ZBUF
5235            #define FLIP
5236               #define ZUPDATE
5237                  #define ZCOMPARE
5238                     #include "video/rdpspn16.c"
5239                  #undef ZCOMPARE
5240                     #include "video/rdpspn16.c"
5241               #undef ZUPDATE
5242                  #define ZCOMPARE
5243                     #include "video/rdpspn16.c"
5244                  #undef ZCOMPARE
5245                     #include "video/rdpspn16.c"
5246            #undef FLIP
5247               #define ZUPDATE
5248                  #define ZCOMPARE
5249                     #include "video/rdpspn16.c"
5250                  #undef ZCOMPARE
5251                     #include "video/rdpspn16.c"
5252               #undef ZUPDATE
5253                  #define ZCOMPARE
5254                     #include "video/rdpspn16.c"
5255                  #undef ZCOMPARE
5256                     #include "video/rdpspn16.c"
5257         #undef ZBUF
5258            #define FLIP
5259               #define ZUPDATE
5260                  #define ZCOMPARE
5261                     #include "video/rdpspn16.c"
5262                  #undef ZCOMPARE
5263                     #include "video/rdpspn16.c"
5264               #undef ZUPDATE
5265                  #define ZCOMPARE
5266                     #include "video/rdpspn16.c"
5267                  #undef ZCOMPARE
5268                     #include "video/rdpspn16.c"
5269            #undef FLIP
5270               #define ZUPDATE
5271                  #define ZCOMPARE
5272                     #include "video/rdpspn16.c"
5273                  #undef ZCOMPARE
5274                     #include "video/rdpspn16.c"
5275               #undef ZUPDATE
5276                  #define ZCOMPARE
5277                     #include "video/rdpspn16.c"
5278                  #undef ZCOMPARE
5279                     #include "video/rdpspn16.c"
2769   // check if more data is needed
2770   if (cmd_length < rdp_command_length[cmd])
2771   {
2772      return;
2773   }
52802774
5281#include "video/rdptri.c"
2775   while (m_cmd_cur < m_cmd_ptr)
2776   {
2777      cmd = (m_cmd_data[m_cmd_cur] >> 24) & 0x3f;
52822778
5283#define MASK_S
5284   #define MASK_T
5285      #include "video/rdpmask.c"
5286   #undef MASK_T
5287      #include "video/rdpmask.c"
5288#undef MASK_S
5289   #define MASK_T
5290      #include "video/rdpmask.c"
5291   #undef MASK_T
5292      #include "video/rdpmask.c"
2779      if (((m_cmd_ptr - m_cmd_cur) * 4) < rdp_command_length[cmd])
2780      {
2781         return;
2782         //fatalerror("rdp_process_list: not enough rdp command data: cur = %d, ptr = %d, expected = %d\n", m_cmd_cur, m_cmd_ptr, rdp_command_length[cmd]);
2783      }
2784
2785      if (LOG_RDP_EXECUTION)
2786      {
2787         char string[4000];
2788         Dasm(string);
2789
2790         fprintf(rdp_exec, "%08X: %08X %08X   %s\n", m_start+(m_cmd_cur * 4), m_cmd_data[m_cmd_cur+0], m_cmd_data[m_cmd_cur+1], string);
2791         fflush(rdp_exec);
2792      }
2793
2794      // execute the command
2795      UINT32 w1 = m_cmd_data[m_cmd_cur+0];
2796      UINT32 w2 = m_cmd_data[m_cmd_cur+1];
2797
2798      switch(cmd)
2799      {
2800         case 0x00:   CmdNoOp(w1, w2);         break;
2801
2802         case 0x08:   CmdTriangle(w1, w2);      break;
2803         case 0x09:   CmdTriangleZ(w1, w2);      break;
2804         case 0x0a:   CmdTriangleT(w1, w2);      break;
2805         case 0x0b:   CmdTriangleTZ(w1, w2);      break;
2806         case 0x0c:   CmdTriangleS(w1, w2);      break;
2807         case 0x0d:   CmdTriangleSZ(w1, w2);      break;
2808         case 0x0e:   CmdTriangleST(w1, w2);      break;
2809         case 0x0f:   CmdTriangleSTZ(w1, w2);      break;
2810
2811         case 0x24:   CmdTexRect(w1, w2);         break;
2812         case 0x25:   CmdTexRectFlip(w1, w2);      break;
2813
2814         case 0x26:   CmdSyncLoad(w1, w2);      break;
2815         case 0x27:   CmdSyncPipe(w1, w2);      break;
2816         case 0x28:   CmdSyncTile(w1, w2);      break;
2817         case 0x29:   CmdSyncFull(w1, w2);      break;
2818
2819         case 0x2a:   CmdSetKeyGB(w1, w2);      break;
2820         case 0x2b:   CmdSetKeyR(w1, w2);         break;
2821
2822         case 0x2c:   CmdSetConvert(w1, w2);      break;
2823         case 0x3c:   CmdSetCombine(w1, w2);      break;
2824         case 0x2d:   CmdSetScissor(w1, w2);      break;
2825         case 0x2e:   CmdSetPrimDepth(w1, w2);   break;
2826         case 0x2f:   CmdSetOtherModes(w1, w2);   break;
2827
2828         case 0x30:   CmdLoadTLUT(w1, w2);      break;
2829         case 0x33:   CmdLoadBlock(w1, w2);      break;
2830         case 0x34:   CmdLoadTile(w1, w2);      break;
2831
2832         case 0x32:   CmdSetTileSize(w1, w2);      break;
2833         case 0x35:   CmdSetTile(w1, w2);         break;
2834
2835         case 0x36:   CmdFillRect(w1, w2);      break;
2836
2837         case 0x37:   CmdSetFillColor32(w1, w2);   break;
2838         case 0x38:   CmdSetFogColor(w1, w2);      break;
2839         case 0x39:   CmdSetBlendColor(w1, w2);   break;
2840         case 0x3a:   CmdSetPrimColor(w1, w2);   break;
2841         case 0x3b:   CmdSetEnvColor(w1, w2);      break;
2842
2843         case 0x3d:   CmdSetTextureImage(w1, w2);   break;
2844         case 0x3e:   CmdSetMaskImage(w1, w2);   break;
2845         case 0x3f:   CmdSetColorImage(w1, w2);   break;
2846      }
2847
2848      m_cmd_cur += rdp_command_length[cmd] / 4;
2849   };
2850   m_cmd_ptr = 0;
2851   m_cmd_cur = 0;
2852
2853   m_start = m_current = m_end;
2854}
2855
2856/*****************************************************************************/
2857
2858VIDEO_START(n64)
2859{
2860   _n64_state *state = (_n64_state *)machine->driver_data;
2861
2862   state->m_rdp.SetMachine(machine);
2863   state->m_rdp.InitInternalState();
2864
2865   state->m_rdp.GetBlender()->SetOtherModes(state->m_rdp.GetOtherModes());
2866   state->m_rdp.GetBlender()->SetMiscState(state->m_rdp.GetMiscState());
2867   state->m_rdp.GetBlender()->SetMachine(machine);
2868   state->m_rdp.GetBlender()->SetProcessor(&state->m_rdp);
2869
2870   state->m_rdp.GetFramebuffer()->SetOtherModes(state->m_rdp.GetOtherModes());
2871   state->m_rdp.GetFramebuffer()->SetMiscState(state->m_rdp.GetMiscState());
2872
2873   state->m_rdp.GetTexPipe()->SetMachine(machine);
2874
2875   if (LOG_RDP_EXECUTION)
2876   {
2877      rdp_exec = fopen("rdp_execute.txt", "wt");
2878   }
2879}
2880
2881VIDEO_UPDATE(n64)
2882{
2883   _n64_state *state = (_n64_state *)screen->machine->driver_data;
2884
2885    int height = state->m_rdp.GetMiscState()->m_fb_height;
2886   //UINT16 *frame_buffer = (UINT16*)&rdram[(n64_vi_origin & 0xffffff) >> 2];
2887   //UINT8  *cvg_buffer = &state->m_rdp.GetHiddenBits()[((n64_vi_origin & 0xffffff) >> 2) >> 1];
2888    //int vibuffering = ((n64_vi_control & 2) && fsaa && divot);
2889
2890   //vibuffering = 0; // Disabled for now
2891
2892   /*
2893    if (vibuffering && ((n64_vi_control & 3) == 2))
2894    {
2895        if (frame_buffer)
2896        {
2897            for (j=0; j < vres; j++)
2898            {
2899                for (i=0; i < hres; i++)
2900                {
2901                    UINT16 pix;
2902                    pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
2903                    curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable
2904                    if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa)
2905                    {
2906                        newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64_vi_width);
2907                        ViBuffer[i][j] = newc;
2908                    }
2909                    else
2910                    {
2911                        newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13);
2912                        newc.i.g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
2913                        newc.i.b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);
2914                        ViBuffer[i][j] = newc;
2915                    }
2916                    pixels++;
2917                }
2918                pixels += invisiblewidth;
2919            }
2920        }
2921    }
2922    */
2923
2924    if (n64_vi_blank)
2925    {
2926        for (int j = 0; j <height; j++)
2927        {
2928            UINT32 *d = BITMAP_ADDR32(bitmap, j, 0);
2929            for (int i = 0; i < state->m_rdp.GetMiscState()->m_fb_width; i++)
2930            {
2931                d[BYTE_XOR_BE(i)] = 0;
2932            }
2933        }
2934        return 0;
2935    }
2936
2937   state->m_rdp.VideoUpdate(bitmap);
2938
2939   return 0;
2940}
src/mame/video/n64.h
r0r7676
1#ifndef _VIDEO_N64_H_
2#define _VIDEO_N64_H_
3
4#include "emu.h"
5#include "video/rdpblend.h"
6#include "video/rdptri.h"
7#include "video/rdpfb.h"
8#include "video/rdpfrect.h"
9#include "video/rdptrect.h"
10#include "video/rdptpipe.h"
11#include "video/rdpspn16.h"
12#include "video/rdpfetch.h"
13
14/*****************************************************************************/
15
16#define PIXEL_SIZE_4BIT         0
17#define PIXEL_SIZE_8BIT         1
18#define PIXEL_SIZE_16BIT      2
19#define PIXEL_SIZE_32BIT      3
20
21#define CYCLE_TYPE_1         0
22#define CYCLE_TYPE_2         1
23#define CYCLE_TYPE_COPY         2
24#define CYCLE_TYPE_FILL         3
25
26#define SAMPLE_TYPE_1x1         0
27#define SAMPLE_TYPE_2x2         1
28
29#define BYTE_ADDR_XOR      BYTE4_XOR_BE(0)
30#define WORD_ADDR_XOR      (WORD_XOR_BE(0) >> 1)
31
32#define XOR_SWAP_BYTE_SHIFT      2
33#define XOR_SWAP_WORD_SHIFT      1
34#define XOR_SWAP_DWORD_SHIFT   0
35
36#define XOR_SWAP_BYTE   4
37#define XOR_SWAP_WORD   2
38#define XOR_SWAP_DWORD   1
39
40//sign-extension macros
41#define SIGN17(x)   (((x) & 0x10000) ? ((x) | ~0x1ffff) : ((x) & 0x1ffff))
42#define SIGN16(x)   (((x) & 0x8000) ? ((x) | ~0xffff) : ((x) & 0xffff))
43#define SIGN11(x)   (((x) & 0x400) ? ((x) | ~0x7ff) : ((x) & 0x7ff))
44
45/*****************************************************************************/
46
47namespace N64
48{
49
50namespace RDP
51{
52
53class Processor;
54class MiscState;
55class OtherModes;
56
57class Color
58{
59   public:
60      Color()
61      {
62         c = 0;
63      }
64
65      union
66      {
67         UINT32 c;
68#ifdef LSB_FIRST
69         struct { UINT8 a, b, g, r; } i;
70#else
71         struct { UINT8 r, g, b, a; } i;
72#endif
73      };
74};
75
76enum
77{
78   BIT_DEPTH_32 = 0,
79   BIT_DEPTH_16,
80
81   BIT_DEPTH_COUNT
82};
83
84class Tile
85{
86   public:
87      int format;   // Image data format: RGBA, YUV, CI, IA, I
88      int size; // Size of texel element: 4b, 8b, 16b, 32b
89      UINT32 line; // Size of tile line in bytes
90      UINT32 tmem; // Starting tmem address for this tile in bytes
91      int palette; // Palette number for 4b CI texels
92      int ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction
93      int mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts
94      UINT16 sl, tl, sh, th;      // 10.2 fixed-point, starting and ending texel row / column
95      int num;
96};
97
98class MiscState
99{
100   public:
101      MiscState()
102      {
103         m_curpixel_cvg = 0;
104         m_curpixel_overlap = 0;
105
106         m_max_level = 0;
107         m_min_level = 0;
108      }
109
110      int m_fb_format;
111      int m_fb_size;
112      int m_fb_width;
113      int m_fb_height;
114      UINT32 m_fb_address;
115
116      UINT32 m_zb_address;
117
118      int m_ti_format;
119      int m_ti_size;
120      int m_ti_width;
121      UINT32 m_ti_address;
122
123      UINT32 m_curpixel_cvg;
124      UINT32 m_curpixel_overlap;
125
126      UINT8 m_random_seed;
127
128      int m_special_bsel0;
129      int m_special_bsel1;
130
131      UINT32 m_max_level;
132      UINT32 m_min_level;
133
134      UINT16 m_primitive_z;
135      UINT16 m_primitive_delta_z;
136};
137
138class CombineModes
139{
140   public:
141      int sub_a_rgb0;
142      int sub_b_rgb0;
143      int mul_rgb0;
144      int add_rgb0;
145      int sub_a_a0;
146      int sub_b_a0;
147      int mul_a0;
148      int add_a0;
149
150      int sub_a_rgb1;
151      int sub_b_rgb1;
152      int mul_rgb1;
153      int add_rgb1;
154      int sub_a_a1;
155      int sub_b_a1;
156      int mul_a1;
157      int add_a1;
158};
159
160class OtherModes
161{
162   public:
163      int cycle_type;
164      bool persp_tex_en;
165      bool detail_tex_en;
166      bool sharpen_tex_en;
167      bool tex_lod_en;
168      bool en_tlut;
169      bool tlut_type;
170      bool sample_type;
171      bool mid_texel;
172      bool bi_lerp0;
173      bool bi_lerp1;
174      bool convert_one;
175      bool key_en;
176      int rgb_dither_sel;
177      int alpha_dither_sel;
178      int blend_m1a_0;
179      int blend_m1a_1;
180      int blend_m1b_0;
181      int blend_m1b_1;
182      int blend_m2a_0;
183      int blend_m2a_1;
184      int blend_m2b_0;
185      int blend_m2b_1;
186      int tex_edge;
187      bool force_blend;
188      bool alpha_cvg_select;
189      bool cvg_times_alpha;
190      int z_mode;
191      int cvg_dest;
192      bool color_on_cvg;
193      bool image_read_en;
194      bool z_update_en;
195      bool z_compare_en;
196      bool antialias_en;
197      bool z_source_sel;
198      bool dither_alpha_en;
199      bool alpha_compare_en;
200};
201
202class ColorInputs
203{
204   public:
205      // combiner inputs
206      UINT8 *combiner_rgbsub_a_r[2];
207      UINT8 *combiner_rgbsub_a_g[2];
208      UINT8 *combiner_rgbsub_a_b[2];
209      UINT8 *combiner_rgbsub_b_r[2];
210      UINT8 *combiner_rgbsub_b_g[2];
211      UINT8 *combiner_rgbsub_b_b[2];
212      UINT8 *combiner_rgbmul_r[2];
213      UINT8 *combiner_rgbmul_g[2];
214      UINT8 *combiner_rgbmul_b[2];
215      UINT8 *combiner_rgbadd_r[2];
216      UINT8 *combiner_rgbadd_g[2];
217      UINT8 *combiner_rgbadd_b[2];
218
219      UINT8 *combiner_alphasub_a[2];
220      UINT8 *combiner_alphasub_b[2];
221      UINT8 *combiner_alphamul[2];
222      UINT8 *combiner_alphaadd[2];
223
224      // blender input
225      UINT8 *blender1a_r[2];
226      UINT8 *blender1a_g[2];
227      UINT8 *blender1a_b[2];
228      UINT8 *blender1b_a[2];
229      UINT8 *blender2a_r[2];
230      UINT8 *blender2a_g[2];
231      UINT8 *blender2a_b[2];
232      UINT8 *blender2b_a[2];
233};
234
235class Processor
236{
237   public:
238      Processor()
239      {
240         m_cmd_ptr = 0;
241         m_cmd_cur = 0;
242
243         m_start = 0;
244         m_end = 0;
245         m_current = 0;
246         m_status = 0x88;
247
248         for(int i = 0; i < (1 << 16); i++)
249         {
250            UINT8 r = ((i >> 8) & 0xf8) | (i >> 13);
251            UINT8 g = ((i >> 3) & 0xf8) | ((i >>  8) & 0x07);
252            UINT8 b = ((i << 2) & 0xf8) | ((i >>  3) & 0x07);
253            UINT8 a = (i & 1) ? 0xff : 0;
254            m_rgb16_to_rgb32_lut[i] = (r << 24) | (g << 16) | (b << 8) | a;
255
256            r = g = b = (i >> 8) & 0xff;
257            a = i & 0xff;
258            m_ia8_to_rgb32_lut[i] = (r << 24) | (g << 16) | (b << 8) | a;
259         }
260
261         for(int i = 0; i < (1 << 24); i++)
262         {
263            UINT8 A = (i >> 16) & 0x000000ff;
264            UINT8 B = (i >> 8) & 0x000000ff;
265            UINT8 C = i & 0x000000ff;
266            m_cc_lut1[i] = (INT16)((((((INT32)A - (INT32)B) * (INT32)C) + 0x80) >> 8) & 0x0000ffff);
267         }
268
269         for(int i = 0; i < (1 << 16); i++)
270         {
271            for(int j = 0; j < (1 << 8); j++)
272            {
273               INT32 temp = (INT32)((INT16)i) + j;
274               if(temp > 255)
275               {
276                  m_cc_lut2[(i << 8) | j] = 255;
277               }
278               else if(temp < 0)
279               {
280                  m_cc_lut2[(i << 8) | j] = 0;
281               }
282               else
283               {
284                  m_cc_lut2[(i << 8) | j] = (UINT8)temp;
285               }
286            }
287         }
288
289         for (int i = 0; i < 8; i++)
290         {
291            m_tiles[i].num = i;
292         }
293
294         m_one_color.c = 0xffffffff;
295         m_zero_color.c = 0x00000000;
296
297         m_color_inputs.combiner_rgbsub_a_r[0] = m_color_inputs.combiner_rgbsub_a_r[1] = &m_one_color.i.r;
298         m_color_inputs.combiner_rgbsub_a_g[0] = m_color_inputs.combiner_rgbsub_a_g[1] = &m_one_color.i.g;
299         m_color_inputs.combiner_rgbsub_a_b[0] = m_color_inputs.combiner_rgbsub_a_b[1] = &m_one_color.i.b;
300         m_color_inputs.combiner_rgbsub_b_r[0] = m_color_inputs.combiner_rgbsub_b_r[1] = &m_one_color.i.r;
301         m_color_inputs.combiner_rgbsub_b_g[0] = m_color_inputs.combiner_rgbsub_b_g[1] = &m_one_color.i.g;
302         m_color_inputs.combiner_rgbsub_b_b[0] = m_color_inputs.combiner_rgbsub_b_b[1] = &m_one_color.i.b;
303         m_color_inputs.combiner_rgbmul_r[0] = m_color_inputs.combiner_rgbmul_r[1] = &m_one_color.i.r;
304         m_color_inputs.combiner_rgbmul_g[0] = m_color_inputs.combiner_rgbmul_g[1] = &m_one_color.i.g;
305         m_color_inputs.combiner_rgbmul_b[0] = m_color_inputs.combiner_rgbmul_b[1] = &m_one_color.i.b;
306         m_color_inputs.combiner_rgbadd_r[0] = m_color_inputs.combiner_rgbadd_r[1] = &m_one_color.i.r;
307         m_color_inputs.combiner_rgbadd_g[0] = m_color_inputs.combiner_rgbadd_g[1] = &m_one_color.i.g;
308         m_color_inputs.combiner_rgbadd_b[0] = m_color_inputs.combiner_rgbadd_b[1] = &m_one_color.i.b;
309
310         m_color_inputs.combiner_alphasub_a[0] = m_color_inputs.combiner_alphasub_a[1] = &m_one_color.i.a;
311         m_color_inputs.combiner_alphasub_b[0] = m_color_inputs.combiner_alphasub_b[1] = &m_one_color.i.a;
312         m_color_inputs.combiner_alphamul[0] = m_color_inputs.combiner_alphamul[1] = &m_one_color.i.a;
313         m_color_inputs.combiner_alphaadd[0] = m_color_inputs.combiner_alphaadd[1] = &m_one_color.i.a;
314
315         m_color_inputs.blender1a_r[0] = m_color_inputs.blender1a_r[1] = &m_pixel_color.i.r;
316         m_color_inputs.blender1a_g[0] = m_color_inputs.blender1a_g[1] = &m_pixel_color.i.r;
317         m_color_inputs.blender1a_b[0] = m_color_inputs.blender1a_b[1] = &m_pixel_color.i.r;
318         m_color_inputs.blender1b_a[0] = m_color_inputs.blender1b_a[1] = &m_pixel_color.i.r;
319         m_color_inputs.blender2a_r[0] = m_color_inputs.blender2a_r[1] = &m_pixel_color.i.r;
320         m_color_inputs.blender2a_g[0] = m_color_inputs.blender2a_g[1] = &m_pixel_color.i.r;
321         m_color_inputs.blender2a_b[0] = m_color_inputs.blender2a_b[1] = &m_pixel_color.i.r;
322         m_color_inputs.blender2b_a[0] = m_color_inputs.blender2b_a[1] = &m_pixel_color.i.r;
323
324         m_tmem = NULL;
325
326         m_machine = NULL;
327
328         memset(m_hidden_bits, 3, 4194304); // Hack / fix for letters in Rayman 2
329
330         m_prim_lod_frac = 0;
331         m_lod_frac = 0;
332
333         for (int i = 0; i < 256; i++)
334         {
335            m_gamma_table[i] = sqrt((float)(i << 6));
336            m_gamma_table[i] <<= 1;
337         }
338
339         for (int i = 0; i < 0x4000; i++)
340         {
341            m_gamma_dither_table[i] = sqrt((float)i);
342            m_gamma_dither_table[i] <<= 1;
343         }
344
345         BuildCompressedZTable();
346      }
347
348      ~Processor() { }
349
350      void    Dasm(char *buffer);
351
352      void    ProcessList();
353      UINT32    ReadData(UINT32 address);
354
355      void    InitInternalState()
356      {
357         if(m_machine)
358         {
359            m_tmem = auto_alloc_array(m_machine, UINT8, 0x1000);
360            memset(m_tmem, 0, 0x1000);
361
362            UINT8 *normpoint = memory_region(m_machine, "normpoint");
363            UINT8 *normslope = memory_region(m_machine, "normslope");
364
365            for(int i = 0; i < 64; i++)
366            {
367               m_norm_point_rom[i] = (normpoint[(i << 1) + 1] << 8) | normpoint[i << 1];
368               m_norm_slope_rom[i] = (normslope[(i << 1) + 1] << 8) | normslope[i << 1];
369            }
370         }
371      }
372
373      void      SetMachine(running_machine* machine) { m_machine = machine; }
374
375      // CPU-visible registers
376      void      SetStartReg(UINT32 val) { m_start = val; }
377      UINT32      GetStartReg() { return m_start; }
378
379      void      SetEndReg(UINT32 val) { m_end = val; }
380      UINT32      GetEndReg() { return m_end; }
381
382      void      SetCurrentReg(UINT32 val) { m_current = val; }
383      UINT32      GetCurrentReg() { return m_current; }
384
385      void      SetStatusReg(UINT32 val) { m_status = val; }
386      UINT32      GetStatusReg() { return m_status; }
387
388      // Functional blocks
389      Blender*      GetBlender() { return &m_blender; }
390      Framebuffer*   GetFramebuffer() { return &m_framebuffer; }
391      TexturePipe*   GetTexPipe() { return &m_tex_pipe; }
392
393      // Internal state
394      OtherModes*      GetOtherModes() { return &m_other_modes; }
395      ColorInputs*   GetColorInputs() { return &m_color_inputs; }
396      CombineModes*   GetCombine() { return &m_combine; }
397      MiscState*      GetMiscState() { return &m_misc_state; }
398
399      // Color constants
400      Color*      GetBlendColor() { return &m_blend_color; }
401      void      SetBlendColor(UINT32 color) { m_blend_color.c = color; }
402
403      Color*      GetPixelColor() { return &m_pixel_color; }
404      void      SetPixelColor(UINT32 color) { m_pixel_color.c = color; }
405
406      Color*      GetInvPixelColor() { return &m_inv_pixel_color; }
407      void      SetInvPixelColor(UINT32 color) { m_inv_pixel_color.c = color; }
408
409      Color*      GetBlendedColor() { return &m_blended_pixel_color; }
410      void      SetBlendedColor(UINT32 color) { m_blended_pixel_color.c = color; }
411
412      Color*      GetMemoryColor() { return &m_memory_color; }
413      void      SetMemoryColor(UINT32 color) { m_memory_color.c = color; }
414
415      Color*      GetPrimColor() { return &m_prim_color; }
416      void      SetPrimColor(UINT32 color) { m_prim_color.c = color; }
417
418      Color*      GetEnvColor() { return &m_env_color; }
419      void      SetEnvColor(UINT32 color) { m_env_color.c = color; }
420
421      Color*      GetFogColor() { return &m_fog_color; }
422      void      SetFogColor(UINT32 color) { m_fog_color.c = color; }
423
424      Color*      GetCombinedColor() { return &m_combined_color; }
425      void      SetCombinedColor(UINT32 color) { m_combined_color.c = color; }
426
427      Color*      GetTexel0Color() { return &m_texel0_color; }
428      void      SetTexel0Color(UINT32 color) { m_texel0_color.c = color; }
429
430      Color*      GetTexel1Color() { return &m_texel1_color; }
431      void      SetTexel1Color(UINT32 color) { m_texel1_color.c = color; }
432
433      Color*      GetShadeColor() { return &m_shade_color; }
434      void      SetShadeColor(UINT32 color) { m_shade_color.c = color; }
435
436      Color*      GetKeyScale() { return &m_key_scale; }
437      void      SetKeyScale(UINT32 scale) { m_key_scale.c = scale; }
438
439      Color*      GetNoiseColor() { return &m_noise_color; }
440      void      SetNoiseColor(UINT32 color) { m_noise_color.c = color; }
441
442      Color*      GetOne() { return &m_one_color; }
443      Color*      GetZero() { return &m_zero_color; }
444
445      UINT8*      GetLODFrac() { return &m_lod_frac; }
446      void      SetLODFrac(UINT8 lod_frac) { m_lod_frac = lod_frac; }
447
448      UINT8*      GetPrimLODFrac() { return &m_prim_lod_frac; }
449      void      SetPrimLODFrac(UINT8 prim_lod_frac) { m_prim_lod_frac = prim_lod_frac; }
450
451      // Color Combiner
452      void       SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code);
453      void       SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code);
454      void       SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code);
455      void       SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code);
456      void       SetSubInputAlpha(UINT8 **input, int code);
457      void       SetMulInputAlpha(UINT8 **input, int code);
458
459      // Texture memory
460      UINT8*      GetTMEM() { return m_tmem; }
461      UINT16*      GetTMEM16() { return (UINT16*)m_tmem; }
462      UINT32*      GetTMEM32() { return (UINT32*)m_tmem; }
463      UINT16*      GetTLUT() { return (UINT16*)(m_tmem + 0x800); }
464      Tile*      GetTiles(){ return m_tiles; }
465
466      // Emulation Accelerators
467      UINT32      LookUp16To32(UINT16 in) { return m_rgb16_to_rgb32_lut[in]; }
468      UINT32      LookUpIA8To32(UINT16 in) { return m_ia8_to_rgb32_lut[in]; }
469      UINT16*      GetCCLUT1() { return m_cc_lut1; }
470      UINT8*      GetCCLUT2() { return m_cc_lut2; }
471      UINT8      GetRandom() { return m_misc_state.m_random_seed += 0x13; }
472
473      // YUV Factors
474      void      SetYUVFactors(INT32 k0, INT32 k1, INT32 k2, INT32 k3, INT32 k4, INT32 k5) { m_k0 = k0; m_k1 = k1; m_k2 = k2; m_k3 = k3; m_k4 = k4; m_k5 = k5; }
475      INT32      GetK0() { return m_k0; }
476      INT32      GetK1() { return m_k1; }
477      INT32      GetK2() { return m_k2; }
478      INT32      GetK3() { return m_k3; }
479      INT32*      GetK4() { return &m_k4; }
480      INT32*      GetK5() { return &m_k5; }
481
482      // Blender-related (move into RDP::Blender)
483      void       SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b);
484
485      // Render-related (move into eventual drawing-related classes?)
486      Rectangle*      GetScissor() { return &m_scissor; }
487      void          TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst);
488      UINT32         GetLog2(UINT32 lod_clamp);
489      void          RenderSpans(int start, int end, int tilenum, bool shade, bool texture, bool zbuffer, bool flip);
490      UINT8*         GetHiddenBits() { return m_hidden_bits; }
491      void         GetAlphaCvg(UINT8 *comb_alpha);
492      const UINT8*   GetBayerMatrix() { return s_bayer_matrix; }
493      const UINT8*   GetMagicMatrix() { return s_magic_matrix; }
494      Span*         GetSpans() { return m_span; }
495      int            GetCurrFIFOIndex() { return m_cmd_cur; }
496      UINT32         GetFillColor32() { return m_fill_color; }
497
498      void         ZStore(UINT16* zb, UINT8* zhb, UINT32 z, UINT32 deltaz);
499      UINT32          DecompressZ(UINT16 *zb);
500      UINT16          DecompressDZ(UINT16* zb, UINT8* zhb);
501      INT32          NormalizeDZPix(INT32 sum);
502      bool         ZCompare(void* fb, UINT8* hb, UINT16* zb, UINT8* zhb, UINT32 sz, UINT16 dzpix);
503
504      // Fullscreen update-related
505      void         VideoUpdate(bitmap_t *bitmap);
506
507      // Commands
508      void       CmdInvalid(UINT32 w1, UINT32 w2);
509      void      CmdNoOp(UINT32 w1, UINT32 w2);
510      void      CmdTriangle(UINT32 w1, UINT32 w2);
511      void      CmdTriangleZ(UINT32 w1, UINT32 w2);
512      void      CmdTriangleT(UINT32 w1, UINT32 w2);
513      void      CmdTriangleTZ(UINT32 w1, UINT32 w2);
514      void      CmdTriangleS(UINT32 w1, UINT32 w2);
515      void      CmdTriangleSZ(UINT32 w1, UINT32 w2);
516      void      CmdTriangleST(UINT32 w1, UINT32 w2);
517      void      CmdTriangleSTZ(UINT32 w1, UINT32 w2);
518      void       CmdTexRect(UINT32 w1, UINT32 w2);
519      void       CmdTexRectFlip(UINT32 w1, UINT32 w2);
520      void       CmdSyncLoad(UINT32 w1, UINT32 w2);
521      void       CmdSyncPipe(UINT32 w1, UINT32 w2);
522      void       CmdSyncTile(UINT32 w1, UINT32 w2);
523      void       CmdSyncFull(UINT32 w1, UINT32 w2);
524      void       CmdSetKeyGB(UINT32 w1, UINT32 w2);
525      void       CmdSetKeyR(UINT32 w1, UINT32 w2);
526      void       CmdSetFillColor32(UINT32 w1, UINT32 w2);
527      void       CmdSetConvert(UINT32 w1, UINT32 w2);
528      void       CmdSetScissor(UINT32 w1, UINT32 w2);
529      void       CmdSetPrimDepth(UINT32 w1, UINT32 w2);
530      void       CmdSetOtherModes(UINT32 w1, UINT32 w2);
531      void      CmdLoadTLUT(UINT32 w1, UINT32 w2);
532      void      CmdSetTileSize(UINT32 w1, UINT32 w2);
533      void       CmdLoadBlock(UINT32 w1, UINT32 w2);
534      void       CmdLoadTile(UINT32 w1, UINT32 w2);
535      void      CmdFillRect(UINT32 w1, UINT32 w2);
536      void       CmdSetTile(UINT32 w1, UINT32 w2);
537      void       CmdSetFogColor(UINT32 w1, UINT32 w2);
538      void       CmdSetBlendColor(UINT32 w1, UINT32 w2);
539      void       CmdSetPrimColor(UINT32 w1, UINT32 w2);
540      void       CmdSetEnvColor(UINT32 w1, UINT32 w2);
541      void       CmdSetCombine(UINT32 w1, UINT32 w2);
542      void       CmdSetTextureImage(UINT32 w1, UINT32 w2);
543      void       CmdSetMaskImage(UINT32 w1, UINT32 w2);
544      void       CmdSetColorImage(UINT32 w1, UINT32 w2);
545
546      void      Triangle(bool shade, bool texture, bool zbuffer);
547      UINT32       AddRightCvg(UINT32 x, UINT32 k);
548      UINT32       AddLeftCvg(UINT32 x, UINT32 k);
549
550      UINT32*      GetCommandData() { return m_cmd_data; }
551
552   protected:
553      Blender         m_blender;
554      Framebuffer      m_framebuffer;
555      TexturePipe      m_tex_pipe;
556
557      OtherModes       m_other_modes;
558      MiscState      m_misc_state;
559      ColorInputs      m_color_inputs;
560      CombineModes   m_combine;
561
562      Color       m_pixel_color;
563      Color       m_inv_pixel_color;
564      Color       m_blended_pixel_color;
565      Color       m_memory_color;
566      Color      m_blend_color;
567
568      Color      m_prim_color;
569      Color      m_env_color;
570      Color      m_fog_color;
571      Color      m_combined_color;
572      Color      m_texel0_color;
573      Color      m_texel1_color;
574      Color      m_shade_color;
575      Color      m_key_scale;
576      Color      m_noise_color;
577      UINT8      m_lod_frac;
578      UINT8      m_prim_lod_frac;
579
580      Color       m_one_color;
581      Color       m_zero_color;
582
583      UINT32      m_fill_color;
584
585      UINT16       m_cc_lut1[(1<<24)];
586      UINT8       m_cc_lut2[(1<<24)];
587      UINT32       m_rgb16_to_rgb32_lut[(1 << 16)];
588      UINT32      m_ia8_to_rgb32_lut[(1 << 16)];
589
590      UINT32      m_cmd_data[0x1000];
591      int       m_cmd_ptr;
592      int       m_cmd_cur;
593
594      UINT32      m_start;
595      UINT32      m_end;
596      UINT32      m_current;
597      UINT32      m_status;
598
599      UINT8*      m_tmem;
600
601      Tile      m_tiles[8];
602
603      running_machine* m_machine;
604
605      // YUV factors
606      INT32 m_k0;
607      INT32 m_k1;
608      INT32 m_k2;
609      INT32 m_k3;
610      INT32 m_k4;
611      INT32 m_k5;
612
613      // Render-related (move into eventual drawing-related classes?)
614      Rectangle m_scissor;
615
616      // Texture perspective division
617      INT32 m_norm_point_rom[64];
618      INT32 m_norm_slope_rom[64];
619
620      UINT8 m_hidden_bits[0x800000];
621
622      Span m_span[4096];
623
624      static const UINT8 s_bayer_matrix[16];
625      static const UINT8 s_magic_matrix[16];
626
627      INT32 m_gamma_table[256];
628      INT32 m_gamma_dither_table[0x4000];
629
630      class ZDecompressEntry
631      {
632         public:
633            UINT32 shift;
634            UINT32 add;
635      };
636
637      void BuildCompressedZTable();
638      UINT16 m_z_compress_table[0x40000];
639      static const ZDecompressEntry m_z_decompress_table[8];
640
641      // Internal screen-update functions
642      void         VideoUpdate16(bitmap_t *bitmap);
643      void         VideoUpdate32(bitmap_t *bitmap);
644
645      typedef void (*Command)(UINT32 w1, UINT32 w2);
646
647      static const Command m_commands[0x40];
648};
649
650} // namespace RDP
651
652} // namespace N64
653
654#endif // _VIDEO_N64_H_
No newline at end of file
src/mess/mess.mak
r7675r7676
11141114   $(MESS_DRIVERS)/snes.o      \
11151115   $(MESS_DRIVERS)/n64.o      \
11161116   $(MAME_MACHINE)/n64.o      \
1117   $(MAME_VIDEO)/n64.o         \
1117   $(MAME_VIDEO)/n64.o      \
1118   $(MAME_VIDEO)/rdpblend.o   \
1119   $(MAME_VIDEO)/rdpfb.o      \
1120   $(MAME_VIDEO)/rdpfetch.o   \
1121   $(MAME_VIDEO)/rdptpipe.o   \
1122   $(MAME_VIDEO)/rdpspn16.o   \
1123   $(MAME_VIDEO)/rdptrect.o   \
1124   $(MAME_VIDEO)/rdpfrect.o   \
11181125   $(MESS_MACHINE)/pokemini.o   \
11191126   $(MESS_DRIVERS)/pokemini.o   \
11201127   $(MESS_DRIVERS)/vboy.o      \
r7675r7676
16211628   $(MESS_DRIVERS)/fidelz80.o   \
16221629   $(MESS_DRIVERS)/pv9234.o    \
16231630   $(MESS_DRIVERS)/dm7000.o    \
1631   $(MESS_DRIVERS)/v6741.o      \
16241632
16251633
16261634
src/mess/drivers/n64.c
r7675r7676
144144}
145145
146146static MACHINE_DRIVER_START( n64 )
147
148   MDRV_DRIVER_DATA(_n64_state)
149
147150   /* basic machine hardware */
148151   MDRV_CPU_ADD("maincpu", VR4300BE, 93750000)
149152   MDRV_CPU_CONFIG(config)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team