summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/epic12in.hxx
blob: c43e24cf480a41bfbdc308c946e8180f64d77c66 (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
// license:BSD-3-Clause
// copyright-holders:David Haywood
/* blitter function */

void epic12_device::FUNCNAME(BLIT_PARAMS)
{
	int yf;

#if REALLY_SIMPLE == 0
	colour_t s_clr;
#endif

#if BLENDED == 1
	colour_t d_clr;

#if _SMODE == 2
#if _DMODE != 0
	colour_t clr0;
#endif
#elif _SMODE == 0
#if _DMODE != 0
#if _DMODE != 5
#if _DMODE != 1
	colour_t clr0;
#endif
#endif
#endif
#else
	colour_t clr0;
#endif

#endif

#if REALLY_SIMPLE == 1
#if TRANSPARENT == 1
	u32 pen;
#endif
#else
	u32 pen;
#endif
	u32 *bmp;

#if FLIPX == 1
	src_x += (dimx-1);
#endif

	if (flipy)  { yf = -1; src_y += (dimy-1); }
	else        { yf = +1;                    }

	int starty = 0;
	const int dst_y_end = dst_y_start + dimy;

	if (dst_y_start < clip->min_y)
		starty = clip->min_y - dst_y_start;

	if (dst_y_end > clip->max_y)
		dimy -= (dst_y_end-1) - clip->max_y;

	// check things are safe to draw (note, if the source would wrap round an edge of the 0x2000*0x1000 vram we don't draw.. not sure what the hw does anyway)
	// ddpdfk triggers this on boss explosions so it needs fixing
#if FLIPX == 1
	if ((src_x & 0x1fff) < ((src_x-(dimx-1)) & 0x1fff))
	{
	//  popmessage("sprite gets clipped off src_x %04x dimx %04x\n", src_x, dimx);
		return;
	}
#else
	if ((src_x & 0x1fff) > ((src_x+(dimx-1)) & 0x1fff))
	{
	//  popmessage("sprite gets clipped off src_x %04x dimx %04x\n", src_x, dimx);
		return;
	}
#endif

	int startx = 0;
	const int dst_x_end = dst_x_start + dimx;

	if (dst_x_start < clip->min_x)
		startx = clip->min_x - dst_x_start;

	if (dst_x_end > clip->max_x)
		dimx -= (dst_x_end-1) - clip->max_x;

// wrong/unsafe slowdown sim
	if (dimy > starty && dimx > startx)
	{
		blit_delay += (dimy - starty) * (dimx - startx);

		//printf("delay is now %d\n", blit_delay);
	}

#if BLENDED == 1
#if _SMODE == 0
#if _DMODE == 0
	const u8* salpha_table = colrtable[s_alpha];
	const u8* dalpha_table = colrtable[d_alpha];
#endif

#if _DMODE == 5
	const u8* salpha_table = colrtable[s_alpha];
#endif
#if _DMODE == 1
	const u8* salpha_table = colrtable[s_alpha];
#endif

#endif

#if _SMODE == 2
#if _DMODE == 0
	const u8* dalpha_table = colrtable[d_alpha];
#endif
#endif
#endif

	for (int y = starty; y < dimy; y++)
	{
		bmp = &bitmap->pix(dst_y_start + y, dst_x_start+startx);
		const int ysrc_index = ((src_y + yf * y) & 0x0fff) * 0x2000;
		u32* gfx2 = gfx + ysrc_index;

		#if FLIPX == 1
			gfx2 += (src_x - startx);
		#else
			gfx2 += (src_x + startx);
		#endif

#if 1
		const u32* end = bmp + (dimx - startx);
#else
		// maybe we can do some SSE type optimizations on larger blocks? right now this just results in more code and slower compiling tho.

		const int width = dimx-startx;
		const u32* end = bmp+(width);

		if (width<0) return;

		int bigblocks = width>>3;

		while (bigblocks)
		{
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"
			#include "epic12pixel.hxx"

			bigblocks--;
		}
#endif
		while (bmp < end)
		{
			#include "epic12pixel.hxx"
		}

	}

//  g_profiler.stop();
}

#undef LOOP_INCREMENTS