summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/rdpupd16.c
blob: 7ce3a4dc91b81934f60422ab8ee0124220824ae7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#if defined(FSAA)
	#if defined(DIVOT)
		static void video_update_n64_16_fsaa_divot(bitmap_t *bitmap)
	#else
		static void video_update_n64_16_fsaa_nodivot(bitmap_t *bitmap)
	#endif
#else
	#if defined(DIVOT)
		static void video_update_n64_16_nofsaa_divot(bitmap_t *bitmap)
	#else
		static void video_update_n64_16_nofsaa_nodivot(bitmap_t *bitmap)
	#endif
#endif
{
	int i, j;
	UINT32 final = 0;
#if defined(DIVOT)
	UINT32 prev_cvg = 0, next_cvg = 0;
#endif
    //int dither_filter = (n64_vi_control >> 16) & 1;
    //int vibuffering = ((n64_vi_control & 2) && fsaa && divot);

	UINT16 *frame_buffer;
	UINT32 hb;
	UINT8* hidden_buffer;

	UINT32 pixels = 0;
	UINT16 pix = 0;

	INT32 hdiff = (n64_vi_hstart & 0x3ff) - ((n64_vi_hstart >> 16) & 0x3ff);
	float hcoeff = ((float)(n64_vi_xscale & 0xfff) / (1 << 10));
	UINT32 hres = ((float)hdiff * hcoeff);
	INT32 invisiblewidth = n64_vi_width - hres;

	INT32 vdiff = ((n64_vi_vstart & 0x3ff) - ((n64_vi_vstart >> 16) & 0x3ff)) >> 1;
	float vcoeff = ((float)(n64_vi_yscale & 0xfff) / (1 << 10));
	UINT32 vres = ((float)vdiff * vcoeff);

	if (vdiff <= 0 || hdiff <= 0)
	{
		return;
	}

	frame_buffer = (UINT16*)&rdram[(n64_vi_origin & 0xffffff) >> 2];
	hb = ((n64_vi_origin & 0xffffff) >> 2) >> 1;
	hidden_buffer = &hidden_bits[hb];

	if (hres > 640) // Needed by Top Gear Overdrive (E)
	{
		invisiblewidth += (hres - 640);
		hres = 640;
	}

	pixels = 0;

	if (frame_buffer)
	{
		for (j=0; j < vres; j++)
		{
			UINT32 *d = BITMAP_ADDR32(bitmap, j, 0);

			for (i=0; i < hres; i++)
			{
				int r, g, b;

				pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
				curpixel_cvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3);

#if defined(DIVOT)
				if (i > 0 && i < (hres - 1))
				{
					prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
					next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
				}
#endif
				r = ((pix >> 8) & 0xf8) | (pix >> 13);
				g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
				b = ((pix << 2) & 0xf8) | ((pix >>  3) & 0x07);

#if defined(FSAA)
				if (/*!vibuffering &&*/ curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2))
				{
					video_filter16(&r, &g, &b, &frame_buffer[pixels ^ WORD_ADDR_XOR],&hidden_buffer[pixels ^ BYTE_ADDR_XOR], n64_vi_width);
				}
#endif
				//else if (dither_filter && curpixel_cvg == 7 && i > 0 && j > 0 && i < (hres - 1) && j < (vres - 1))
				//{
					//if (vibuffering)
					//{
					//	restore_filter16_buffer(&r, &g, &b, &ViBuffer[i][j], n64_vi_width);
					//}
					//else
					//{
						//restore_filter16(&r, &g, &b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR, n64_vi_width);
					//}
				//}
#if defined(DIVOT)
				if (i > 0 && i < (hres - 1) && (curpixel_cvg != 7 || prev_cvg != 7 || next_cvg != 7))
				{
					//if (vibuffering)
					//{
					//	divot_filter16_buffer(&r, &g, &b, &ViBuffer[i][j]);
					//}
					//else
					//{
						divot_filter16(&r, &g, &b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR);
					//}
				}
#endif

				/*
				if (gamma_dither)
				{
					dith = mame_rand(screen->machine) & 0x3f;
				}
				if (gamma)
				{
					if (gamma_dither)
					{
						r = gamma_dither_table[(r << 6)|dith];
						g = gamma_dither_table[(g << 6)|dith];
						b = gamma_dither_table[(b << 6)|dith];
					}
					else
					{
						r = gamma_table[r];
						g = gamma_table[g];
						b = gamma_table[b];
					}
				}
				else if (gamma_dither)
				{
					if (r < 255)
						r += (dith & 1);
					if (g < 255)
						g += (dith & 1);
					if (b < 255)
						b += (dith & 1);
				}
				*/
				pixels++;

				final = (r << 16) | (g << 8) | b;
				d[i] = final; // Fix me for endianness
			}
			pixels +=invisiblewidth;
		}
	}
}