summaryrefslogtreecommitdiffstats
path: root/private/mvdm/softpc.new/host/src/nt_munge.c
blob: 5c48df4ee6a3f8e90bfbaba9ead834df592ca9c8 (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
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/*
 * SoftPC Revision 3.0
 *
 * Title	: Win32 mungeing routines.
 *
 * Description	: This module contains the functions required to produce
 *		  destination compatible pixel patterns from SoftPC video
 *		  memory.
 *
 * Author	: Jerry Sexton (based on X_munge.c)
 *
 * Notes	:
 *
 */

#include <windows.h>
#include "insignia.h"
#include "host_def.h"

#include "xt.h"
#include "gvi.h"
#include "gmi.h"
#include "gfx_upd.h"
#include "egagraph.h"
#include <conapi.h>
#include "nt_graph.h"

/*(
========================= ega_colour_hi_munge =============================

PURPOSE:	Munge interleaved EGA plane data to bitmap form using lookup tables.
INPUT:		(unsigned char *) plane0_ptr - ptr to plane0 data
		(int) width - # of groups of 4 bytes on the line
		(unsigned int *) dest_ptr - ptr to output buffer
		(unsigned int *) lut0_ptr - munging luts
		(int) height - # of scanlines to output (1 or 2)
		(int) line_offset - distance to next scanline
OUTPUT:		A nice bitmap in dest_ptr

===========================================================================
)*/

GLOBAL	VOID
ega_colour_hi_munge(unsigned char *plane0_ptr, int width,
		    unsigned int *dest_ptr, unsigned int *lut0_ptr,
		    int height, int line_offset)
{
	unsigned int	*lut1_ptr = lut0_ptr + LUT_OFFSET;
	unsigned int	*lut2_ptr = lut1_ptr + LUT_OFFSET;
	unsigned int	*lut3_ptr = lut2_ptr + LUT_OFFSET;
	FAST unsigned int	hi_res;
	FAST unsigned int	lo_res;
	FAST unsigned int	*l_ptr;
	FAST half_word		*data;

	/* make sure we get the line offset in ints not bytes */
	line_offset /= sizeof(int);
	data = (half_word *) plane0_ptr;

	/* convert each input byte in turn */
	if (get_plane_mask() == 0xf) /* all planes enabled */
	{
	    for ( ; width > 0; width--)
	    {
		/* Get 8 bytes (2 longs) of output data from 1 byte of plane 0
		** data
		*/

		l_ptr = &lut0_ptr [*data++ << 1];
		hi_res = *l_ptr++;
		lo_res = *l_ptr;

		/* Or in the output data from plane 1 */
		l_ptr = &lut1_ptr [*data++ << 1];
		hi_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Or in the output data from plane 2 */
		l_ptr = &lut2_ptr [*data++ << 1];
		hi_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Or in the output data from plane 3 */
		l_ptr = &lut3_ptr [*data++ << 1];
		hi_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Output the data to the buffer */
		if (height == 2)
		{
			/* scanline doubling */
			*(dest_ptr + line_offset) = hi_res;
			*dest_ptr++ = hi_res;
			*(dest_ptr + line_offset) = lo_res;
			*dest_ptr++ = lo_res;
		}
		else
		{
			/* not scanline doubling */
			*dest_ptr++ = hi_res;
			*dest_ptr++ = lo_res;
		}
	    }
	}
	else
	{
	    for ( ; width > 0; width--)
	    {
		/* Get 8 bytes (2 longs) of output data from 1 byte of plane 0
		** data
		*/

		if (get_plane_mask() & 1)
		{
		    l_ptr = &lut0_ptr [*data++ << 1];
		    hi_res = *l_ptr++;
		    lo_res = *l_ptr;
		}
		else
		{
		    hi_res = 0;
		    lo_res = 0;
		    data++;
		}

		/* Conditionally Or in the output data from plane 1 */
		if (get_plane_mask() & 2)
		{
		    l_ptr = &lut1_ptr [*data++ << 1];
		    hi_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Conditionally Or in the output data from plane 2 */
		if (get_plane_mask() & 4)
		{
		    l_ptr = &lut2_ptr [*data++ << 1];
		    hi_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Conditionally Or in the output data from plane 3 */
		if (get_plane_mask() & 8)
		{
		    l_ptr = &lut3_ptr [*data++ << 1];
		    hi_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Output the data to the buffer */
		if (height == 2)
		{
			/* scanline doubling */
			*(dest_ptr + line_offset) = hi_res;
			*dest_ptr++ = hi_res;
			*(dest_ptr + line_offset) = lo_res;
			*dest_ptr++ = lo_res;
		}
		else
		{
			/* not scanline doubling */
			*dest_ptr++ = hi_res;
			*dest_ptr++ = lo_res;
		}
	    }
	}
}	/* ega_colour_hi_munge */

#ifdef	BIGWIN
/*(
========================= ega_colour_hi_munge_big ===========================

PURPOSE:	Munge interleaved EGA plane data to bitmap data for big windows.
INPUT:		(unsigned char *) plane0_ptr - ptr to EGA plane 0 data
		(int) width - number of bytes to convert
		(unsigned int *) dest_ptr - output buffer ptr
		(unsigned int *) lut0_ptr - ptr to luts
		(int) height - # of scanlines to output (1 or 3)
		(int) line_offset - distance to next scanline
OUTPUT:		A nice bitmap in the output buffer

=============================================================================
)*/

GLOBAL	VOID
ega_colour_hi_munge_big(unsigned char *plane0_ptr, int width,
			unsigned int *dest_ptr, unsigned int *lut0_ptr,
			int height, int line_offset)
{
	unsigned int	*lut1_ptr = lut0_ptr + BIG_LUT_OFFSET;
	unsigned int	*lut2_ptr = lut1_ptr + BIG_LUT_OFFSET;
	unsigned int	*lut3_ptr = lut2_ptr + BIG_LUT_OFFSET;
	FAST unsigned int	hi_res;
	FAST unsigned int	med_res;
	FAST unsigned int	lo_res;
	FAST unsigned int	*l_ptr;
	FAST half_word		*data;

	/* make sure we get the line offset in ints not bytes */
	line_offset /= sizeof(int);
	data = (half_word *) plane0_ptr;

	if (get_plane_mask() == 0xf)
	{
	    for ( ; width > 0; width--)
	    {
		/* From one byte of input data in plane 0, get 12 bytes
		** of output data.
		*/

		l_ptr = &lut0_ptr [*data++ * 3];
		hi_res = *l_ptr++;
		med_res = *l_ptr++;
		lo_res = *l_ptr;

		/* Or in the stuff from plane 1 */
		l_ptr = &lut1_ptr [*data++ * 3];
		hi_res |= *l_ptr++;
		med_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Or in the stuff from plane 2 */
		l_ptr = &lut2_ptr [*data++ * 3];
		hi_res |= *l_ptr++;
		med_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Or in the stuff from plane 3 */
		l_ptr = &lut3_ptr [*data++ * 3];
		hi_res |= *l_ptr++;
		med_res |= *l_ptr++;
		lo_res |= *l_ptr;

		/* Output the munged data */
		if (height == 3)
		{
			/* triple the scanlines */
			*(dest_ptr + 2*line_offset) = hi_res;
			*(dest_ptr + line_offset) = hi_res;
			*dest_ptr++ = hi_res;
			*(dest_ptr + 2*line_offset) = med_res;
			*(dest_ptr + line_offset) = med_res;
			*dest_ptr++ = med_res;
			*(dest_ptr + 2*line_offset) = lo_res;
			*(dest_ptr + line_offset) = lo_res;
			*dest_ptr++ = lo_res;
		}
		else
		{
			/* just one scanline */
			*dest_ptr++ = hi_res;
			*dest_ptr++ = med_res;
			*dest_ptr++ = lo_res;
		}
	    }
	}
	else
	{
	    for ( ; width > 0; width--)
	    {
		/* From one byte of input data in plane 0, get 12 bytes
		** of output data.
		*/

		if (get_plane_mask() & 1)
		{
		    l_ptr = &lut0_ptr [*data++ * 3];
		    hi_res = *l_ptr++;
		    med_res = *l_ptr++;
		    lo_res = *l_ptr;
		}
		else
		{
		    data++;
		    hi_res = 0;
		    med_res = 0;
		    lo_res = 0;
		}

		/* Or in the stuff from plane 1 */
		if (get_plane_mask() & 2)
		{
		    l_ptr = &lut1_ptr [*data++ * 3];
		    hi_res |= *l_ptr++;
		    med_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Or in the stuff from plane 2 */
		if (get_plane_mask() & 4)
		{
		    l_ptr = &lut2_ptr [*data++ * 3];
		    hi_res |= *l_ptr++;
		    med_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Or in the stuff from plane 3 */
		if (get_plane_mask() & 8)
		{
		    l_ptr = &lut3_ptr [*data++ * 3];
		    hi_res |= *l_ptr++;
		    med_res |= *l_ptr++;
		    lo_res |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Output the munged data */
		    if (height == 3)
		    {
			/* triple the scanlines */
			*(dest_ptr + 2*line_offset) = hi_res;
			*(dest_ptr + line_offset) = hi_res;
			*dest_ptr++ = hi_res;
			*(dest_ptr + 2*line_offset) = med_res;
			*(dest_ptr + line_offset) = med_res;
			*dest_ptr++ = med_res;
			*(dest_ptr + 2*line_offset) = lo_res;
			*(dest_ptr + line_offset) = lo_res;
			*dest_ptr++ = lo_res;
		    }
		    else
		    {
			/* just one scanline */
			*dest_ptr++ = hi_res;
			*dest_ptr++ = med_res;
			*dest_ptr++ = lo_res;
		    }
	    }
	}
}	/* ega_colour_hi_munge_big */

/*(
========================= ega_colour_hi_munge_huge ========================

PURPOSE:	Munge interleaved EGA plane data to bitmap form using lookup tables.
INPUT:		(unsigned char *) plane0_ptr - ptr to plane0 data
		(int) width - # of bytes on the line
		(unsigned int *) dest_ptr - ptr to output buffer
		(unsigned int *) lut0_ptr - munging luts
		(int) height - # of scanlines to output (1 or 2)
		(int) line_offset - distance to next scanline
OUTPUT:		A nice X image in dest_ptr

===========================================================================
)*/

GLOBAL	VOID
ega_colour_hi_munge_huge(unsigned char *plane0_ptr, int width,
			 unsigned int *dest_ptr, unsigned int *lut0_ptr,
			 int height, int line_offset)
{
	unsigned int	*lut1_ptr = lut0_ptr + HUGE_LUT_OFFSET;
	unsigned int	*lut2_ptr = lut1_ptr + HUGE_LUT_OFFSET;
	unsigned int	*lut3_ptr = lut2_ptr + HUGE_LUT_OFFSET;
	FAST unsigned int	res4;
	FAST unsigned int	res3;
	FAST unsigned int	res2;
	FAST unsigned int	res1;
	FAST unsigned int	*l_ptr;
	FAST half_word		*data;

	/* make sure we get the line offset in ints not bytes */
	line_offset /= sizeof(int);
	data = (half_word *) plane0_ptr;

	/* convert each input byte in turn */
	if (get_plane_mask() == 0xf)
	{
	    for ( ; width > 0; width--)
	    {
		/* Get 16 bytes of output data from 1 byte of plane 0
		** data
		*/

		l_ptr = &lut0_ptr [*data++ << 2];
		res4 = *l_ptr++;
		res3 = *l_ptr++;
		res2 = *l_ptr++;
		res1 = *l_ptr;

		/* Or in the output data from plane 1 */
		l_ptr = &lut1_ptr [*data++ << 2];
		res4 |= *l_ptr++;
		res3 |= *l_ptr++;
		res2 |= *l_ptr++;
		res1 |= *l_ptr;

		/* Or in the output data from plane 2 */
		l_ptr = &lut2_ptr [*data++ << 2];
		res4 |= *l_ptr++;
		res3 |= *l_ptr++;
		res2 |= *l_ptr++;
		res1 |= *l_ptr;

		/* Or in the output data from plane 3 */
		l_ptr = &lut3_ptr [*data++ << 2];
		res4 |= *l_ptr++;
		res3 |= *l_ptr++;
		res2 |= *l_ptr++;
		res1 |= *l_ptr;

		/* Output the data to the buffer */
		if (height == 4)
		{
			/* scanline doubling */
			*(dest_ptr + 3*line_offset) = res4;
			*(dest_ptr + 2*line_offset) = res4;
			*(dest_ptr + line_offset) = res4;
			*dest_ptr++ = res4;
			*(dest_ptr + 3*line_offset) = res3;
			*(dest_ptr + 2*line_offset) = res3;
			*(dest_ptr + line_offset) = res3;
			*dest_ptr++ = res3;
			*(dest_ptr + 3*line_offset) = res2;
			*(dest_ptr + 2*line_offset) = res2;
			*(dest_ptr + line_offset) = res2;
			*dest_ptr++ = res2;
			*(dest_ptr + 3*line_offset) = res1;
			*(dest_ptr + 2*line_offset) = res1;
			*(dest_ptr + line_offset) = res1;
			*dest_ptr++ = res1;
		}
		else
		{
			/* not scanline doubling */
			*dest_ptr++ = res4;
			*dest_ptr++ = res3;
			*dest_ptr++ = res2;
			*dest_ptr++ = res1;
		}
	    }
	}
	else
	{
	    for ( ; width > 0; width--)
	    {
		/* Get 16 bytes of output data from 1 byte of plane 0
		** data
		*/

		if (get_plane_mask() & 1)
		{
		    l_ptr = &lut0_ptr [*data++ << 2];
		    res4 = *l_ptr++;
		    res3 = *l_ptr++;
		    res2 = *l_ptr++;
		    res1 = *l_ptr;
		}
		else
		{
		    res4 = 0;
		    res3 = 0;
		    res2 = 0;
		    res1 = 0;
		    data++;
		}

		/* Or in the output data from plane 1 */
		if (get_plane_mask() & 2)
		{
		    l_ptr = &lut1_ptr [*data++ << 2];
		    res4 |= *l_ptr++;
		    res3 |= *l_ptr++;
		    res2 |= *l_ptr++;
		    res1 |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Or in the output data from plane 2 */
		if (get_plane_mask() & 4)
		{
		    l_ptr = &lut2_ptr [*data++ << 2];
		    res4 |= *l_ptr++;
		    res3 |= *l_ptr++;
		    res2 |= *l_ptr++;
		    res1 |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Or in the output data from plane 3 */
		if (get_plane_mask() & 8)
		{
		    l_ptr = &lut3_ptr [*data++ << 2];
		    res4 |= *l_ptr++;
		    res3 |= *l_ptr++;
		    res2 |= *l_ptr++;
		    res1 |= *l_ptr;
		}
		else
		{
		    data++;
		}

		/* Output the data to the buffer */
		    if (height == 4)
		    {
			/* scanline doubling */
			*(dest_ptr + 3*line_offset) = res4;
			*(dest_ptr + 2*line_offset) = res4;
			*(dest_ptr + line_offset) = res4;
			*dest_ptr++ = res4;
			*(dest_ptr + 3*line_offset) = res3;
			*(dest_ptr + 2*line_offset) = res3;
			*(dest_ptr + line_offset) = res3;
			*dest_ptr++ = res3;
			*(dest_ptr + 3*line_offset) = res2;
			*(dest_ptr + 2*line_offset) = res2;
			*(dest_ptr + line_offset) = res2;
			*dest_ptr++ = res2;
			*(dest_ptr + 3*line_offset) = res1;
			*(dest_ptr + 2*line_offset) = res1;
			*(dest_ptr + line_offset) = res1;
			*dest_ptr++ = res1;
		    }
		    else
		    {
			/* not scanline doubling */
			*dest_ptr++ = res4;
			*dest_ptr++ = res3;
			*dest_ptr++ = res2;
			*dest_ptr++ = res1;
		    }
	    }
	}
}	/* ega_colour_hi_munge_huge */
#endif	/* BIGWIN */