summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/rdptpipe.h
blob: b8c947f4cc1f7029613a4436066b62da44aee012 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/******************************************************************************


    SGI/Nintendo Reality Display Texture Fetch Unit (TF)
    -------------------

    by MooglyGuy
    based on initial C code by Ville Linde
    contains additional improvements from angrylion, Ziggy, Gonetz and Orkin


******************************************************************************/

#ifndef _VIDEO_RDPTEXPIPE_H_
#define _VIDEO_RDPTEXPIPE_H_

#include "emu.h"
#include "video/n64types.h"

class n64_texture_pipe_t
{
	public:
		typedef void (n64_texture_pipe_t::*texel_fetcher_t) (rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		typedef void (n64_texture_pipe_t::*texel_cycler_t) (color_t* TEX, color_t* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux* userdata, const rdp_poly_state& object);

		n64_texture_pipe_t()
		{
			m_maskbits_table[0] = 0xffff;
			for(int i = 1; i < 16; i++)
			{
				m_maskbits_table[i] = ((UINT16)(0xffff) >> (16 - i)) & 0x3ff;
			}
			m_start_span = false;

			for (int idx = 0; idx < 80; idx++)
			{
				m_texel_fetch[idx] = &n64_texture_pipe_t::fetch_nop;
			}

			m_texel_fetch[ 8] = &n64_texture_pipe_t::fetch_rgba16_raw;
			m_texel_fetch[ 9] = &n64_texture_pipe_t::fetch_rgba16_raw;
			m_texel_fetch[10] = &n64_texture_pipe_t::fetch_rgba16_tlut0;
			m_texel_fetch[11] = &n64_texture_pipe_t::fetch_rgba16_tlut1;
			m_texel_fetch[12] = &n64_texture_pipe_t::fetch_rgba32_raw;
			m_texel_fetch[13] = &n64_texture_pipe_t::fetch_rgba32_raw;
			m_texel_fetch[14] = &n64_texture_pipe_t::fetch_rgba32_tlut0;
			m_texel_fetch[15] = &n64_texture_pipe_t::fetch_rgba32_tlut1;

			m_texel_fetch[24] = &n64_texture_pipe_t::fetch_yuv;
			m_texel_fetch[25] = &n64_texture_pipe_t::fetch_yuv;
			m_texel_fetch[26] = &n64_texture_pipe_t::fetch_yuv;
			m_texel_fetch[27] = &n64_texture_pipe_t::fetch_yuv;

			m_texel_fetch[32] = &n64_texture_pipe_t::fetch_ci4_raw;
			m_texel_fetch[33] = &n64_texture_pipe_t::fetch_ci4_raw;
			m_texel_fetch[34] = &n64_texture_pipe_t::fetch_ci4_tlut0;
			m_texel_fetch[35] = &n64_texture_pipe_t::fetch_ci4_tlut1;
			m_texel_fetch[36] = &n64_texture_pipe_t::fetch_ci8_raw;
			m_texel_fetch[37] = &n64_texture_pipe_t::fetch_ci8_raw;
			m_texel_fetch[38] = &n64_texture_pipe_t::fetch_ci8_tlut0;
			m_texel_fetch[39] = &n64_texture_pipe_t::fetch_ci8_tlut1;

			m_texel_fetch[48] = &n64_texture_pipe_t::fetch_ia4_raw;
			m_texel_fetch[49] = &n64_texture_pipe_t::fetch_ia4_raw;
			m_texel_fetch[50] = &n64_texture_pipe_t::fetch_ia4_tlut0;
			m_texel_fetch[51] = &n64_texture_pipe_t::fetch_ia4_tlut1;
			m_texel_fetch[52] = &n64_texture_pipe_t::fetch_ia8_raw;
			m_texel_fetch[53] = &n64_texture_pipe_t::fetch_ia8_raw;
			m_texel_fetch[54] = &n64_texture_pipe_t::fetch_ia8_tlut0;
			m_texel_fetch[55] = &n64_texture_pipe_t::fetch_ia8_tlut1;
			m_texel_fetch[56] = &n64_texture_pipe_t::fetch_ia16_raw;
			m_texel_fetch[57] = &n64_texture_pipe_t::fetch_ia16_raw;
			m_texel_fetch[58] = &n64_texture_pipe_t::fetch_ia16_tlut0;
			m_texel_fetch[59] = &n64_texture_pipe_t::fetch_ia16_tlut1;

			m_texel_fetch[64] = &n64_texture_pipe_t::fetch_i4_raw;
			m_texel_fetch[65] = &n64_texture_pipe_t::fetch_i4_raw;
			m_texel_fetch[66] = &n64_texture_pipe_t::fetch_i4_tlut0;
			m_texel_fetch[67] = &n64_texture_pipe_t::fetch_i4_tlut1;
			m_texel_fetch[68] = &n64_texture_pipe_t::fetch_i8_raw;
			m_texel_fetch[69] = &n64_texture_pipe_t::fetch_i8_raw;
			m_texel_fetch[70] = &n64_texture_pipe_t::fetch_i8_tlut0;
			m_texel_fetch[71] = &n64_texture_pipe_t::fetch_i8_tlut1;

			m_cycle[0] = &n64_texture_pipe_t::cycle_nearest;
			m_cycle[1] = &n64_texture_pipe_t::cycle_nearest_lerp;
			m_cycle[2] = &n64_texture_pipe_t::cycle_linear;
			m_cycle[3] = &n64_texture_pipe_t::cycle_linear_lerp;
		}

		void                cycle_nearest(color_t* TEX, color_t* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                cycle_nearest_lerp(color_t* TEX, color_t* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                cycle_linear(color_t* TEX, color_t* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                cycle_linear_lerp(color_t* TEX, color_t* prev, INT32 SSS, INT32 SST, UINT32 tilenum, UINT32 cycle, rdp_span_aux* userdata, const rdp_poly_state& object);

		texel_cycler_t      m_cycle[4];

		void                copy(color_t* TEX, INT32 SSS, INT32 SST, UINT32 tilenum, const rdp_poly_state& object, rdp_span_aux* userdata);
		void                calculate_clamp_diffs(UINT32 prim_tile, rdp_span_aux* userdata, const rdp_poly_state& object);
		void				tclod_tcclamp(INT32* sss, INT32* sst);
		void				tclod_1cycle_current(INT32* sss, INT32* sst, INT32 nexts, INT32 nextt, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, rdp_span_aux* userdata, const rdp_poly_state& object);
		void				tclod_1cycle_next(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, INT32* pre_lod_frac, rdp_span_aux* userdata, const rdp_poly_state& object);
		void				tclod_2cycle_current(INT32* sss, INT32* sst, INT32 nexts, INT32 nextt, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, INT32* t2, rdp_span_aux* userdata, const rdp_poly_state& object);
		void				tclod_2cycle_next(INT32* sss, INT32* sst, INT32 s, INT32 t, INT32 w, INT32 dsinc, INT32 dtinc, INT32 dwinc, INT32 prim_tile, INT32* t1, INT32* t2, INT32* pre_lod_frac, rdp_span_aux* userdata, const rdp_poly_state& object);
		void				lodfrac_lodtile_signals(bool lodclamp, INT32 lod, UINT32* l_tile, bool* magnify, bool* distant, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                lod_1cycle(INT32* sss, INT32* sst, const INT32 s, const INT32 t, const INT32 w, const INT32 dsinc, const INT32 dtinc, const INT32 dwinc, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                lod_2cycle(INT32* sss, INT32* sst, const INT32 s, const INT32 t, const INT32 w, const INT32 dsinc, const INT32 dtinc, const INT32 dwinc, const INT32 prim_tile, INT32* t1, INT32* t2, rdp_span_aux* userdata, const rdp_poly_state& object);
		void                lod_2cycle_limited(INT32* sss, INT32* sst, const INT32 s, const INT32 t, INT32 w, const INT32 dsinc, const INT32 dtinc, const INT32 dwinc, const INT32 prim_tile, INT32* t1, const rdp_poly_state& object);

		void                set_machine(running_machine& machine);

		bool                m_start_span;

	private:
		void				tclod_4x17_to_15(INT32 scurr, INT32 snext, INT32 tcurr, INT32 tnext, INT32 previous, INT32* lod);
		void                mask(rgbaint_t& sstt, const n64_tile_t& tile);

		rgbaint_t           shift_cycle(rgbaint_t& st, const n64_tile_t& tile);
		void                shift_copy(rgbaint_t& st, const n64_tile_t& tile);

		void                clamp_cycle(rgbaint_t& st, rgbaint_t& stfrac, rgbaint_t& maxst, const INT32 tilenum, const n64_tile_t& tile, rdp_span_aux* userdata);
		void                clamp_cycle_light(rgbaint_t& st, rgbaint_t& maxst, const INT32 tilenum, const n64_tile_t& tile, rdp_span_aux* userdata);

		void                fetch_nop(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		void                fetch_rgba16_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_rgba16_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_rgba16_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_rgba32_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_rgba32_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_rgba32_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		void                fetch_yuv(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		void                fetch_ci4_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ci4_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ci4_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ci8_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ci8_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ci8_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		void                fetch_ia4_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia4_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia4_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia8_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia8_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia8_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia16_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia16_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_ia16_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		void                fetch_i4_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_i4_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_i4_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_i8_tlut0(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_i8_tlut1(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);
		void                fetch_i8_raw(rgbaint_t& out, INT32 s, INT32 t, INT32 tbase, INT32 tpal, rdp_span_aux* userdata);

		texel_fetcher_t     m_texel_fetch[16*5];

		n64_rdp*            m_rdp;

		INT32               m_maskbits_table[16];
		color_t             m_expand_16to32_table[0x10000];
		UINT16              m_lod_lookup[0x80000];
		INT32				m_log2_table[0x100];

		rgbaint_t           m_st2_add;
		rgbaint_t           m_v1;
		rgbaint_t			m_yuv1;
};

#endif // _VIDEO_RDPTEXPIPE_H_