-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdxrend.cpp
406 lines (362 loc) · 10.8 KB
/
dxrend.cpp
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#include "std.h"
#include "emul.h"
#include "vars.h"
#include "dxrend.h"
#include "dxrcopy.h"
#include "dxr_512.h"
#include "dxr_4bpp.h"
#include "dxr_prof.h"
#include "dxr_atm.h"
#include "draw.h"
#include "util.h"
void rend_small(unsigned char *dst, unsigned pitch)
{
if (temp.obpp == 8) { rend_copy8 (dst, pitch); return; }
if (temp.obpp == 16) { rend_copy16(dst, pitch); return; }
if (temp.obpp == 32) { rend_copy32(dst, pitch); return; }
}
void __fastcall render_small(unsigned char *dst, unsigned pitch)
{
if (conf.noflic)
{
if (temp.obpp == 8) { rend_copy8_nf (dst, pitch); }
if (temp.obpp == 16) { rend_copy16_nf(dst, pitch); }
if (temp.obpp == 32) { rend_copy32_nf(dst, pitch); }
memcpy(rbuf_s, rbuf, temp.scy*temp.scx/4);
return;
}
if (comp.pEFF7 & EFF7_4BPP)
{
rend_p4bpp_small(dst, pitch);
return;
}
if (conf.mem_model == MM_ATM450)
{
rend_atm_1_small(dst, pitch);
return;
}
if (conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3)
{
rend_atm_2_small(dst, pitch);
return;
}
rend_small(dst, pitch);
}
void rend_dbl(unsigned char *dst, unsigned pitch)
{
if (temp.oy > temp.scy && conf.fast_sl)
pitch *= 2;
if (conf.noflic)
{
if (temp.obpp == 8)
{
if (conf.fast_sl)
rend_copy8d1_nf (dst, pitch);
else
rend_copy8d_nf (dst, pitch);
}
else if (temp.obpp == 16)
{
if (conf.fast_sl)
rend_copy16d1_nf(dst, pitch);
else
rend_copy16d_nf(dst, pitch);
}
else if (temp.obpp == 32)
{
if (conf.fast_sl)
rend_copy32d1_nf(dst, pitch);
else
rend_copy32d_nf(dst, pitch);
}
memcpy(rbuf_s, rbuf, temp.scy * temp.scx / 4);
}
else
{
if (temp.obpp == 8)
{
if (conf.fast_sl)
rend_copy8d1 (dst, pitch);
else
rend_copy8d (dst, pitch);
return;
}
if (temp.obpp == 16)
{
if (conf.fast_sl)
rend_copy16d1(dst, pitch);
else
rend_copy16d(dst, pitch);
return;
}
if (temp.obpp == 32)
{
if (conf.fast_sl)
rend_copy32d1(dst, pitch);
else
rend_copy32d(dst, pitch);
return;
}
}
}
void __fastcall render_dbl(unsigned char *dst, unsigned pitch)
{
#ifdef MOD_VID_VD
if ((comp.pVD & 8) && temp.obpp == 8)
{
rend_vd8dbl(dst, pitch);
return;
}
#endif
// todo: add ini option to show zx-screen with palette or with MC
if (comp.pEFF7 & EFF7_512)
{
rend_512(dst, pitch);
return;
}
if (comp.pEFF7 & EFF7_4BPP)
{
rend_p4bpp(dst, pitch);
return;
}
if ((comp.pDFFD & 0x80) && conf.mem_model == MM_PROFI)
{
rend_profi(dst, pitch);
return;
}
if (conf.mem_model == MM_ATM450)
{
rend_atm_1(dst, pitch);
return;
}
if (conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3)
{
rend_atm_2(dst, pitch);
return;
}
rend_dbl(dst, pitch);
}
void __fastcall render_3x(unsigned char *dst, unsigned pitch)
{
if (conf.noflic) {
if (temp.obpp == 8) rend_copy8t_nf (dst, pitch);
if (temp.obpp == 16) rend_copy16t_nf(dst, pitch);
if (temp.obpp == 32) rend_copy32t_nf(dst, pitch);
memcpy(rbuf_s, rbuf, temp.scy*temp.scx/4);
}
else
{
if (temp.obpp == 8) { rend_copy8t (dst, pitch); return; }
if (temp.obpp == 16) { rend_copy16t(dst, pitch); return; }
if (temp.obpp == 32) { rend_copy32t(dst, pitch); return; }
}
}
void __fastcall render_quad(unsigned char *dst, unsigned pitch)
{
if (conf.noflic) {
if (temp.obpp == 8) rend_copy8q_nf (dst, pitch);
if (temp.obpp == 16) rend_copy16q_nf(dst, pitch);
if (temp.obpp == 32) rend_copy32q_nf(dst, pitch);
memcpy(rbuf_s, rbuf, temp.scy*temp.scx/4);
} else {
if (temp.obpp == 8) { rend_copy8q (dst, pitch); return; }
if (temp.obpp == 16) { rend_copy16q(dst, pitch); return; }
if (temp.obpp == 32) { rend_copy32q(dst, pitch); return; }
}
}
void __fastcall render_scale(unsigned char *dst, unsigned pitch)
{
unsigned char *src = rbuf;
unsigned dx = temp.scx / 4;
unsigned char buf[MAX_WIDTH*2];
unsigned x; //Alone Coder 0.36.7
for (unsigned y = 0; y < temp.scy-1; y++)
{
for (x = 0; x < dx; x += 2)
{
unsigned xx = (t.dbl[src[x]] << 16) + t.dbl[src[x+2]];
unsigned yy = (t.dbl[src[x+dx]] << 16) + t.dbl[src[x+dx+2]];
unsigned x1 = xx | (yy & ((xx>>1) | (xx<<1)));
unsigned *tab0 = t.sctab8[0] + (src[x+1] << 4);
*(unsigned*)(dst+x*8+ 0) = tab0[(x1>>28) & 0x0F];
*(unsigned*)(dst+x*8+ 4) = tab0[(x1>>24) & 0x0F];
*(unsigned*)(dst+x*8+ 8) = tab0[(x1>>20) & 0x0F];
*(unsigned*)(dst+x*8+12) = tab0[(x1>>16) & 0x0F];
unsigned *tab1 = t.sctab8[0] + src[x+3];
*(unsigned*)(dst+x*8+16) = tab1[(x1>>12) & 0x0F];
*(unsigned*)(dst+x*8+20) = tab1[(x1>> 8) & 0x0F];
*(unsigned*)(dst+x*8+24) = tab1[(x1>> 4) & 0x0F];
*(unsigned*)(dst+x*8+28) = tab1[(x1>> 0) & 0x0F];
x1 = yy | (xx & ((yy>>1) | (yy<<1)));
*(unsigned*)(buf+x*8+ 0) = tab0[(x1>>28) & 0x0F];
*(unsigned*)(buf+x*8+ 4) = tab0[(x1>>24) & 0x0F];
*(unsigned*)(buf+x*8+ 8) = tab0[(x1>>20) & 0x0F];
*(unsigned*)(buf+x*8+12) = tab0[(x1>>16) & 0x0F];
*(unsigned*)(buf+x*8+16) = tab1[(x1>>12) & 0x0F];
*(unsigned*)(buf+x*8+20) = tab1[(x1>> 8) & 0x0F];
*(unsigned*)(buf+x*8+24) = tab1[(x1>> 4) & 0x0F];
*(unsigned*)(buf+x*8+28) = tab1[(x1>> 0) & 0x0F];
}
dst += pitch;
for (x = 0; x < temp.ox; x += 4)
*(unsigned*)(dst+x) = *(unsigned*)(buf+x);
src += dx; dst += pitch;
}
}
static u64 mask49 = 0x4949494949494949;
static u64 mask92 = 0x9292929292929292;
static void /*__declspec(naked)*/ __fastcall _bil_line1(unsigned char *dst, unsigned char *src)
{
for (unsigned i = 0; i < temp.scx; i += 2)
{
dst[i] = src[i];
dst[i+1] = ((src[i] + src[i+1]) >> 1);
}
/*
__asm {
push ebx
push edi
push ebp
mov ebp, [temp.scx]
xor eax, eax
xor ebx, ebx // ebx - prev. pixel
shr ebp,1
l1:
mov al, [edx]
xadd eax, ebx
shr eax, 1
mov [ecx+1], bl
mov [ecx], al
mov al, [edx+1]
add ecx, 4
xadd eax, ebx
add edx, 2
shr eax, 1
mov [ecx-1], bl
dec ebp
mov [ecx-2], al
jnz l1
pop ebp
pop edi
pop ebx
retn
}
*/
}
static void /*__declspec(naked)*/ __fastcall _bil_line2(unsigned char *dst, unsigned char *s1)
{
u32 *s = (u32 *)s1;
u32 *d = (u32 *)dst;
for (unsigned j = 0; j < temp.ox/4; j++)
{
u32 a = s[j];
u32 b = s[j+2*MAX_WIDTH/4];
u32 x = a & b;
u32 y = (a ^ b) >> 1;
u32 z = a | b;
u32 n = x << 1;
u32 v1 = x ^ y;
v1 &= 0x49494949;
u32 v2 = z & n;
v2 |= x;
v2 &= 0x92929292;
d[j] = v1 | v2;
}
/*
__asm {
mov eax, [temp.ox]
movq mm2, [mask49]
movq mm3, [mask92]
shr eax, 3
m2: movq mm0, [edx]
movq mm1, [edx+MAX_WIDTH*2]
movq mm4, mm0
movq mm5, mm0
pand mm4, mm1 // mm4 = a & b
pxor mm5, mm1 // mm5 = a ^ b
movq mm6, mm0
psrlq mm5, 1 // mm5 = (a ^ b) >> 1
por mm6, mm1 // mm6 = a | b
movq mm7, mm4
pxor mm5, mm4 // mm5 = (a & b) ^ ((a ^ b) >> 1)
psllq mm7, 1 // mm7 = (a & b) << 1
pand mm5, mm2 // mm5 = 0x49494949 & ((a & b) ^ ((a ^ b) >> 1))
pand mm7, mm6 // mm7 = (a|b) & ((a & b) << 1)
por mm7, mm4 // mm7 = (a&b) | ((a|b)&((a&b)<<1))
add ecx, 8
pand mm7, mm3 // mm7 &= 0x92929292
add edx, 8
por mm7, mm5
dec eax
movq [ecx-8], mm7
jnz m2
retn
}
*/
}
void __fastcall render_bil(unsigned char *dst, unsigned pitch)
{
render_small(snbuf, MAX_WIDTH);
unsigned char *src = snbuf;
unsigned char ATTR_ALIGN(16) l1[MAX_WIDTH*4];
#define l2 (l1+MAX_WIDTH*2)
_bil_line1(l1, src); src += MAX_WIDTH;
memcpy(dst, l1, temp.ox);
dst += pitch;
for (unsigned i = temp.scy/2-1; i; i--)
{
_bil_line1(l2, src); src += MAX_WIDTH;
_bil_line2(dst, l1); dst += pitch;
memcpy(dst, l2, temp.ox);
dst += pitch;
_bil_line1(l1, src); src += MAX_WIDTH;
_bil_line2(dst, l1); dst += pitch;
memcpy(dst, l1, temp.ox);
dst += pitch;
}
_bil_line1(l2, src); src += MAX_WIDTH;
_bil_line2(dst, l1); dst += pitch;
memcpy(dst, l2, temp.ox);
dst += pitch;
memcpy(dst, l2, temp.ox);
#undef l2
// _mm_empty();
}
void __fastcall render_tv(unsigned char *dst, unsigned pitch)
{
// ripped from ccs and *highly* simplified and optimized
unsigned char midbuf[MAX_WIDTH*2];
unsigned char line[MAX_WIDTH*2+4*2], line2[MAX_WIDTH*2];
unsigned j; //Alone Coder 0.36.7
for (/*unsigned*/ j = 0; j < MAX_WIDTH/2; j++)
*(unsigned*)(midbuf+j*4) = WORD4(0,0x80,0,0x80);
unsigned char *src = rbuf; unsigned delta = temp.scx/4;
for (unsigned i = temp.scy; i; i--) {
*(unsigned*)line = *(unsigned*)(line+4) = WORD4(0,0x80,0,0x80);
if (conf.noflic) line16_nf(line+8, src, t.sctab16_nf[0]);
else line16(line+8, src, t.sctab16[0]);
src += delta;
for (j = 0; j < temp.scx; j++) {
unsigned Y = line[j*2+8]*9+
line[j*2-2+8]*4+
line[j*2-4+8]*2+
line[j*2-8+8];
/*
unsigned U = line[j*2+8+1]*12 +
line[j*2-2+8+1]*2+
line[j*2-4+8+1]+
line[j*2-8+8+1];
*/
line2[j*2] = Y>>4;
// line2[j*2+1] = U>>4;
line2[j*2+1] = line[j*2+9];
}
// there must be only fixed length fader buffer
for (j = 0; j < temp.scx/2; j++) {
*(unsigned*)(midbuf+j*4) = *(unsigned*)(dst + j*4) =
((*(unsigned*)(midbuf+j*4) & 0xFEFEFEFE)/2 + (*(unsigned*)(line2+j*4) & 0xFEFEFEFE)/2);
}
dst += pitch;
}
if (conf.noflic) memcpy(rbuf_s, rbuf, temp.scy*temp.scx/4);
}