aboutsummaryrefslogtreecommitdiff
path: root/sword2/driver/d_draw.cpp
blob: 26cf7a93b10a50420bd91ceace7d4d88c07cedbb (plain)
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
/* Copyright (C) 1994-2003 Revolution Software Ltd
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 */

#define WIN32_LEAN_AND_MEAN

//#include <windows.h>
//#include <windowsx.h>
//#include <mmsystem.h>
#include <stdio.h>

//#include "ddraw.h"

#include "stdafx.h"
#include "driver96.h"
#include "rdwin.h"
#include "_mouse.h"
#include "d_draw.h"
#include "palette.h"

//#include "ddutil.h"
//CDisplay	*g_pDisplay        = NULL;





#define SCREENYOFFSET	40

#define MILLISECSPERCYCLE 83



/*
LPDIRECTDRAW7        m_pDD;


static LPDIRECTDRAW		lpDraw;				// DirectDraw object
LPDIRECTDRAW2			lpDD2;				// DirectDraw2 object
LPDIRECTDRAWSURFACE		lpPrimarySurface;	// DirectDraw primary surface
LPDIRECTDRAWSURFACE		lpBackBuffer;		// DirectDraw back surface
LPDIRECTDRAWPALETTE		lpPalette = NULL;	// DirectDraw palette

static PALETTEENTRY AppPalette[256];		// Application wide logical palette
*/


// Game screen metrics
int16			screenDeep;
int16			screenWide;


// Set to 1 if vertical blank status cannot be checked.
static BOOL		noVbl = 0;
BOOL			bFullScreen = 0;



// Scroll variables.  scrollx and scrolly hold the current scroll position, 
//	and scrollxTarget and scrollyTarget are the target position for the end
//	of the game cycle.

int16			scrollx;
int16			scrolly;
static	int16	scrollxTarget;
static	int16	scrollyTarget;
static	int16	scrollxOld;
static	int16	scrollyOld;
static	int16	failCount = 0;
//static	DDCAPS	driverCaps;

int32			renderCaps = 0;
int32			dxHalCaps = 0;
int32			dxHelCaps = 0;
//DDCOLORKEY		blackColorKey;


//static int32 platformIsNT = 0;


//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------


void FatalDirectDrawError(char *str, int32 code, char *filename, int32 line)
{

	char string[256];

	RestoreDisplay();

	sprintf(string, "FATAL: %s - code 0x%.8x - file %s - line %d", str, code, filename, line);
	//MessageBox(hwnd, string, "DDraw error", MB_OK);
	warning("%s", string);

}




//----------------------------------------------------------------------------------------------------------------



int32 PlotDots(int16 x, int16 y, int16 count)

{

	warning("stub PlotDots( %d, %d, %d )", x, y, count);
/*
	int16			i;
	uint8			*dst;

	DDSURFACEDESC	ddDescription;
	HRESULT			hr;

	ddDescription.dwSize = sizeof(ddDescription);
	
	hr = IDirectDrawSurface2_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	if (hr != DD_OK)
	{
		RestoreSurfaces();
		hr = IDirectDrawSurface2_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	}

	if (hr == DD_OK)
	{

		dst = (uint8 *) ddDescription.lpSurface + y * ddDescription.lPitch + x;

		for (i=0; i<=count; i++)
		{
			*dst = 184;
			dst += 2;
		}
		dst = (uint8 *) ddDescription.lpSurface + (y+1) * ddDescription.lPitch + x;
		for (i=0; i<=count/10; i++)
		{
			*dst = 184;
			dst += 20;
		}
		IDirectDrawSurface2_Unlock(lpBackBuffer, ddDescription.lpSurface);
	}
*/
	return(RD_OK);

}
//----------------------------------------------------------------------------------------------------------------



void RestoreSurfaces(void)

{
	warning("stub RestoreSurfaces");
/*
	IDirectDrawSurface2_Restore(lpPrimarySurface);
	IDirectDrawSurface2_Restore(lpBackBuffer);
*/
}

//----------------------------------------------------------------------------------------------------------------

/*
static PALETTEENTRY *CreateAppPalette(PALETTEENTRY *pe)
{

	HDC	screen_dc;

//  Fill the palette with system colours
	screen_dc = GetDC(NULL);
	GetSystemPaletteEntries(screen_dc, 0, 256, pe);
	ReleaseDC(NULL, screen_dc);

	return pe;

}
*/


//----------------------------------------------------------------------------------------------------------------

int32 RestoreDisplay(void)

{
	warning("stub RestoreDisplay");
/*
    if( lpDraw != NULL )
    {
        if( lpPrimarySurface != NULL )
        {
            IDirectDrawSurface2_Release(lpPrimarySurface);
            lpPrimarySurface = NULL;
        }
        if( lpPalette != NULL )
        {
            IDirectDrawPalette_Release(lpPalette);
            lpPalette = NULL;
        }
		if (lpDD2 != NULL)
		{
			IDirectDraw2_Release(lpDD2);
			lpDD2 = NULL;
		}

		IDirectDraw_Release(lpDraw);
		lpDraw = NULL;
    }
*/
	return(RD_OK);

}


//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------

int32 InitialiseDisplay(int16 width, int16 height, int16 colourDepth, int32 windowType)
{
/*
	DDSURFACEDESC       ddsd;
    DDSCAPS             ddscaps;
    HRESULT             hr;
	DDCAPS				helCaps;
	LARGE_INTEGER timerFrequency;
	int32 capsError = 0;


   OSVERSIONINFO VersionInfo;
   VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   
   if (GetVersionEx(&VersionInfo))
   {

	   switch (VersionInfo.dwPlatformId)
	   {
	   case VER_PLATFORM_WIN32s :
	   case VER_PLATFORM_WIN32_WINDOWS :
		  break;
	   case VER_PLATFORM_WIN32_NT	:
		   platformIsNT = 1;
		   break;
	   }
   }


	if (windowType == RD_FULLSCREEN)
		bFullScreen = TRUE;
	else
		bFullScreen = FALSE;

	// Colour depths of 8 bits only are currently supported
	if (colourDepth != 8)
	{
		return(RDERR_COLOURDEPTH);
	}

	screenWide = width;
	screenDeep = height;

	// Create the directDraw object
    hr = DirectDrawCreate(NULL, &lpDraw, NULL);
//	hr=DirectDrawCreateEx( NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL );


    if ( hr != DD_OK )
	{
//		Zdebug(" DirectDrawCreate failed!");

        DirectDrawError("DirectDraw unavailable", hr);
		return(hr);
	}


    // Get exclusive mode
	if (bFullScreen)
	{

//		hr = m_pDD->SetCooperativeLevel( hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN );
	    hr = IDirectDraw2_SetCooperativeLevel(lpDraw, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
		if (hr != DD_OK)
		{
			DirectDrawError("Exclusive mode unavailable", hr);
			return(hr);
		}

		// TONY TEMP	


		hr = IDirectDraw2_QueryInterface(lpDraw, &IID_IDirectDraw2, (LPVOID *) &lpDD2);
		if (hr != DD_OK)
		{
			DirectDrawError("DirectDraw2 unavailable", hr);
			return(hr);
		}

		// Set up the display mode which has been requested
//		hr = lpDD2->lpVtbl->SetDisplayMode(lpDD2, width, height, colourDepth, 0, 0);
		hr = IDirectDraw2_SetDisplayMode(lpDD2, width, height, colourDepth, 0, 0);
		if (hr != DD_OK)
		{
			DirectDrawError("Unable to set display mode", hr);
			return(hr);
		}

	    // Set up the primary surface descriptor
		ddsd.dwSize = sizeof(ddsd);
	    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
	    ddsd.dwBackBufferCount = 1;

		// Create the primary surface
	    hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, &lpPrimarySurface, NULL);
		if (hr != DD_OK)
		{
		    DirectDrawError("Cannot create primary surface", hr);
			return(hr);
		}

		// Create the back buffer as a page flipping surface
		ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	    hr = IDirectDrawSurface2_GetAttachedSurface(lpPrimarySurface, &ddscaps, &lpBackBuffer);
		if (hr != DD_OK)
		{
		    DirectDrawError("Unable to attach back buffer", hr);
			return(hr);
		}

		EraseBackBuffer();
		FlipScreens();
		EraseBackBuffer();
		FlipScreens();

		// Create a palette object
		hr = IDirectDraw2_CreatePalette(lpDD2, DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
				CreateAppPalette(AppPalette), &lpPalette, NULL);
	    if (hr != DD_OK )
		{
			DirectDrawError("Cannot create 8-bit palette", hr);
			return(hr);
		}

		// Set our palette object active
		hr = IDirectDrawSurface2_SetPalette(lpPrimarySurface, lpPalette);
	    if (hr != DD_OK )
		{
			DirectDrawError("Unable to set palette", hr);
			return(hr);
		}

	}
	else
	{
        RECT rcWork;
        RECT rc;
        HDC hdc;
        DWORD dwStyle;
		uint32 GameBPP;



		hr = IDirectDraw_SetCooperativeLevel(lpDraw, hwnd, DDSCL_NORMAL);
		if (hr != DD_OK)
		{
			DirectDrawError("Cannot set normal cooperative level", hr);
			return(hr);
		}



		hr = IDirectDraw_QueryInterface(lpDraw, &IID_IDirectDraw2, (LPVOID *) &lpDD2);
		if (hr != DD_OK)
		{
			DirectDrawError("DirectDraw2 unavailable", hr);
			return(hr);
		}

        //
        //  when in windows we should use the current mode
        //
        hdc = GetDC(NULL);
        GameBPP = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
        ReleaseDC(NULL, hdc);

		if ((GameBPP != 8) && (GameBPP != 16))
		{
			MessageBox(hwnd, "Cannot execute in high colour mode - going to full screen", "Broken Sword II", MB_OK);
			return(RDERR_GOFULLSCREEN);
		}
		else if (GameBPP != 8)
		{
			if (MessageBox(hwnd, "Your display is not in 256 colour mode.  Would you like to go to full screen mode (better performance)", "Broken Sword II", MB_YESNO) == IDYES)
			{
				return(RDERR_GOFULLSCREEN);
			}
		}

        //
        // if we are still a WS_POPUP window we should convert to a
        // normal app window so we look like a windows app.
        //
        dwStyle = GetWindowStyle(hwnd);
        dwStyle &= ~WS_POPUP;
        dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX;
        SetWindowLong(hwnd, GWL_STYLE, dwStyle);

//        if (bStretch)
//            SetRect(&rc, 0, 0, GameMode.cx*2, GameMode.cy*2);
//        else
//            SetRect(&rc, 0, 0, GameMode.cx, GameMode.cy);
		SetRect(&rc, 0, 0, 640, 480);

        AdjustWindowRectEx(&rc,
            GetWindowStyle(hwnd),
            GetMenu(hwnd) != NULL,
            GetWindowExStyle(hwnd));

        SetWindowPos(hwnd, NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top,
            SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

        SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
            SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);

        //
        //  make sure our window does not hang outside of the work area
        //  this will make people who have the tray on the top or left
        //  happy.
        //
        SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);
        GetWindowRect(hwnd, &rc);
        if (rc.left < rcWork.left) rc.left = rcWork.left;
        if (rc.top  < rcWork.top)  rc.top  = rcWork.top;
        SetWindowPos(hwnd, NULL, rc.left, rc.top, 0, 0,
            SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);




	    // Set up the primary surface descriptor
		ddsd.dwSize = sizeof(ddsd);
	    ddsd.dwFlags = DDSD_CAPS;
	    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

		// Create the primary surface
		hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, &lpPrimarySurface, NULL);
	    if (hr != DD_OK)
		{
			DirectDrawError("Cannot create primary surface", hr);
			return(hr);
		}

		// Create the back buffer as a page flipping surface
	    memset( &ddsd, 0, sizeof( ddsd ) );
		ddsd.dwSize = sizeof( ddsd );
		ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;

		ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
	    ddsd.dwHeight = 480;
	    ddsd.dwWidth = 640;

	    hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, &lpBackBuffer, NULL );
	    if (hr != DD_OK)
		{
	        DirectDrawError("Cannot attach back buffer", hr);
			return(hr);
		}

	//    DDClear();

		if (IDirectDrawSurface2_GetDC(lpPrimarySurface, &hdc) == DD_OK)
	    {
		    char *szMsg = "Broken Sword II is loading.......please wait.";
			SetTextColor(hdc, RGB(255,255,255));
	        SetBkMode(hdc, TRANSPARENT);
		    TextOut(hdc, rcWindow.left, rcWindow.top, szMsg, lstrlen(szMsg));
			IDirectDrawSurface2_ReleaseDC(lpPrimarySurface, hdc);
	    }

		// Create a palette object - only if we have a palette!
		if (GameBPP == 8)
		{
			hr = IDirectDraw2_CreatePalette(lpDD2, DDPCAPS_8BIT, CreateAppPalette(AppPalette), &lpPalette, NULL);
			if (hr != DD_OK )
			{
				DirectDrawError("Cannot create 8-bit palette", hr);
				return(hr);
			}

			hr = IDirectDrawSurface2_SetPalette(lpPrimarySurface, lpPalette);
			if (hr != DD_OK )
			{
				DirectDrawError("Cannot set palette", hr);
				return(hr);
			}
		}
	}

	// Set my capability bits.
	memset(&driverCaps, 0, sizeof(DDCAPS));
	memset(&helCaps, 0, sizeof(DDCAPS));
	driverCaps.dwSize = sizeof(DDCAPS);
	helCaps.dwSize = sizeof(DDCAPS);
	hr = IDirectDraw2_GetCaps(lpDD2, &driverCaps, &helCaps);
	if (hr != DD_OK)
	{
		driverCaps.dwSize = sizeof(DDCAPS_DX3);
		helCaps.dwSize = sizeof(DDCAPS_DX3);
		hr = IDirectDraw2_GetCaps(lpDD2, &driverCaps, &helCaps);
		if (hr != DD_OK)
		{
			MessageBox(hwnd, "Cannot get hardware capabilities.  Software emulation only.  Re-install DirectX!", "DDraw error", MB_OK);
			capsError = 1;
		}
	}

	blackColorKey.dwColorSpaceLowValue = 0;
	blackColorKey.dwColorSpaceHighValue = 0;

	if (capsError)
	{
		helCaps.dwCaps = DDCAPS_BLT + DDCAPS_BLTSTRETCH + DDCAPS_COLORKEY;
		helCaps.dwCKeyCaps = DDCKEYCAPS_SRCBLT;
		dxHelCaps += RDCAPS_BLTSTRETCH;
		dxHelCaps += RDCAPS_SRCBLTCKEY;
		renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
						 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA;
	}
	else
	{
		if ((helCaps.dwCaps & DDCAPS_BLT == 0) || 
			(helCaps.dwCaps & DDCAPS_BLTSTRETCH == 0) ||
			(helCaps.dwCaps & DDCAPS_COLORKEY == 0) ||
			(helCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT == 0))
		{
			RestoreDisplay();
			return(RDERR_NOEMULATION);
		}

//		if (driverCaps.dwCaps & DDCAPS_BLTSTRETCH)
//		{
//			if (driverCaps.dwFXCaps & (DDFXCAPS_BLTSHRINKX + DDFXCAPS_BLTSHRINKY + DDFXCAPS_BLTSTRETCHX + DDFXCAPS_BLTSTRETCHY) == 
//				DDFXCAPS_BLTSHRINKX + DDFXCAPS_BLTSHRINKY + DDFXCAPS_BLTSTRETCHX + DDFXCAPS_BLTSTRETCHY)
//				dxHalCaps += RDCAPS_BLTSTRETCH;
//			else if (helCaps.dwCaps & DDCAPS_BLTSTRETCH)
//				dxHelCaps += RDCAPS_BLTSTRETCH;
//			else 
//				return RDERR_DDRAWNOEMULATION;
//		}
//		else if (helCaps.dwCaps & DDCAPS_BLTSTRETCH)
//			dxHelCaps += RDCAPS_BLTSTRETCH;
//		else
//			return(RDERR_DDRAWNOEMULATION);

		if (helCaps.dwCaps & DDCAPS_BLTSTRETCH)
			dxHelCaps += RDCAPS_BLTSTRETCH;
		else
			return(RDERR_DDRAWNOEMULATION);

		if ((driverCaps.dwCaps & DDCAPS_BLT) && (driverCaps.dwCaps & DDCAPS_COLORKEY) && (driverCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT))
			dxHalCaps += RDCAPS_SRCBLTCKEY;
		else if ((helCaps.dwCaps & DDCAPS_BLT) && (helCaps.dwCaps & DDCAPS_COLORKEY) && (helCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT))
			dxHelCaps += RDCAPS_SRCBLTCKEY;
		else
			return(RDERR_DDRAWNOEMULATION);


		
		// Do computer speed testing here to set bits. - this is the path we go through:
		//
		//	if (Can everything be done in hardware?)
		//		renderCaps = RDBLTFX_ALLHARDWARE;
		//	else
		//		if (Everything fast enough in software)
		//			turn everything on in software
		//		else
		//			Turn blending off
		//			if (can everything but blending be done in hardware?)
		//				renderCaps = RDBLTFX_ALLHARDWARE
		//			else
		//				if (everything but blending fast enough in software)
		//					Do everything but blending in software
		//				else
		//					Turn off sprite effects
		//				endif
		//			endif
		//		endif
		//	endif




		if ((driverCaps.dwCaps & DDCAPS_BLT) && (driverCaps.dwCaps & DDCAPS_COLORKEY) && (driverCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT)
			&& (driverCaps.dwCaps & DDSCAPS_ALPHA) && (driverCaps.dwAlphaBltConstBitDepths))
			renderCaps = RDBLTFX_ALLHARDWARE | RDBLTFX_GRADEDALPHA | RDBLTFX_FLATALPHA;
		else if	((driverCaps.dwCaps & DDCAPS_BLT) && (driverCaps.dwCaps & DDCAPS_COLORKEY) && (driverCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT))
			renderCaps = RDBLTFX_ALLHARDWARE;
		else
			renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
						 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA;

		if (QueryPerformanceFrequency(&timerFrequency) == TRUE)
			if (timerFrequency.QuadPart > 700000)
				renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
						 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA;

	//	if ((driverCaps.dwCaps & DDCAPS_BLT) && (driverCaps.dwCaps & DDCAPS_COLORKEY) && (driverCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT))
	//		renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
	//					 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA | RDBLTFX_FGPARALLAX;
	//	else
	//		renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
	//					 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA;

		//	renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_ALLHARDWARE;
	}
*/
	return(RD_OK);

}
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------



int32 RenderHard(void)
{
	warning("stub RenderHard");
/*
	if (renderCaps & RDBLTFX_ALLHARDWARE)
		return(RDERR_ALREADYON);
	if	((driverCaps.dwCaps & DDCAPS_BLT) && (driverCaps.dwCaps & DDCAPS_COLORKEY) && (driverCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT))
		renderCaps = RDBLTFX_ALLHARDWARE;
	else
		return(RDERR_NOHARDWARE);

*/
	return(RD_OK);
}

int32 RenderSoft(void)
{
	warning("stub RenderSoft");
/*
	if (!(renderCaps & RDBLTFX_ALLHARDWARE))
		return(RDERR_ALREADYON);
	renderCaps = RDBLTFX_MOUSEBLT | RDBLTFX_ARITHMETICSTRETCH | RDBLTFX_EDGEBLEND |
			 RDBLTFX_SHADOWBLEND | RDBLTFX_FLATALPHA | RDBLTFX_GRADEDALPHA;
*/
	return(RD_OK);
}

int32 SetBltFx(void)
{
	renderCaps |= RDBLTFX_EDGEBLEND + RDBLTFX_ARITHMETICSTRETCH;
	return(RD_OK);
}

int32 ClearBltFx(void)
{
	renderCaps &= (0xffffffff - RDBLTFX_EDGEBLEND - RDBLTFX_ARITHMETICSTRETCH);
	return(RD_OK);
}

int32 ClearShadowFx(void)
{
	renderCaps &= (0xffffffff - RDBLTFX_SHADOWBLEND);
	return(RD_OK);
}

int32 SetShadowFx(void)
{
	renderCaps |= RDBLTFX_SHADOWBLEND;
	return RD_OK;
}

int32 GetRenderType(void)
{
	if (renderCaps & RDBLTFX_ALLHARDWARE)
	{
		return (0);
	}
	else
	{
		if (renderCaps & (RDBLTFX_EDGEBLEND + RDBLTFX_ARITHMETICSTRETCH))
			return (3);
		else
		{
			if (renderCaps & RDBLTFX_SHADOWBLEND)
				return(2);
			else
				return (1);
		}
	}
}

int32 FlipScreens(void)

{
	warning("stub FlipScreens");
/*
    HRESULT		hr;
	BOOL		vbl;
	int32		startTime;

	DrawMouse();

	if (bFullScreen)
	{
		startTime = timeGetTime();

		while(TRUE)
	    {
			if (!noVbl)
			{
				hr = IDirectDraw2_GetVerticalBlankStatus(lpDD2, &vbl);
				if (hr != DD_OK)
				{
					DirectDrawError("Vertical blank status unavailable", hr);
				}
			}

			if (vbl || noVbl)
			{
				hr = IDirectDrawSurface2_Flip(lpPrimarySurface, NULL, 0);
				if (hr == DD_OK)
    			{
					break;
				}

				if (hr == DDERR_SURFACELOST)
				{
					if (gotTheFocus)
					{
    					hr = IDirectDrawSurface2_Restore(lpPrimarySurface);
					
        				if(hr != DD_OK)
	          			{
							if (++failCount == 32)
								return(RDERR_CANNOTFLIP);
						}
					}

				}
				else
					failCount = 0;

				if(hr != DDERR_WASSTILLDRAWING)
		  		{
				    break;
				}
			}
			if (timeGetTime() - startTime > 20)
			{
				noVbl = 1;
			}
		}
    }
	else
	{

		hr = IDirectDrawSurface2_Blt(lpPrimarySurface, &rcWindow, lpBackBuffer, NULL, DDBLT_WAIT, NULL);
		if (hr != DD_OK)
		{
			return(RDERR_UNKNOWN);
		}
	}
*/
	return(RD_OK);

}



int32 WaitForVbl(void)
{
	warning("stub WaitForVbl");
/*
	BOOL		vbl;
	HRESULT		hr;
	uint32		counter = 0;


	while(1)
	{
		hr = IDirectDraw2_GetVerticalBlankStatus(lpDD2, &vbl);
		
		if (hr != DD_OK)
		{
			DirectDrawError("Cannot get vertical blank status", hr);
			return(hr);
		}

		if (vbl || noVbl)
			break;
		
		if (++counter == 250000)
			noVbl = 1;
	}
*/	
	return(RD_OK);

}




int32 EraseBackBuffer( void )
{
	warning("stub EraseBackBuffer");
/*
    DDBLTFX     ddbltfx;
    HRESULT     hr;
	RECT		r = {0, 0, screenWide, screenDeep};


    //	Erase the background
    ddbltfx.dwSize = sizeof(ddbltfx);
    ddbltfx.dwFillColor = 0;

    while( 1 )
    {

        hr = IDirectDrawSurface2_Blt(lpBackBuffer, &r, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );

		if (hr == DDERR_SURFACELOST)
        {

			RestoreSurfaces();

	        hr = IDirectDrawSurface2_Blt(lpBackBuffer, &r, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );

            if (hr != DD_OK)
            {
				if (++failCount == 32)
				{
	                DirectDrawError("Cannot render back buffer", hr);
					return(hr);
				}
				else
				{
					failCount = 0;
					return(RD_OK);
				}
            }

        }

		if (hr == DD_OK)
        {
            break;
        }
    
		if (hr != DDERR_WASSTILLDRAWING)
        {
            DirectDrawError("Cannot render back buffer", hr);
			return(hr);
        }
    }
*/	
	return(RD_OK);

}




int32 SaveScreenShot(uint8 *buffer, uint8 *palette)
{

	static uint16 pcxCount = 0;
  int virtualWidth;
  int pix;
  int keyPix;
  int line;
  int i;
  int runLength;
  char filename[80];
  unsigned char ch;
  unsigned char *pcxData;
  unsigned char pal[256*3];
  FILE *fp;
  _pcxHeader pcxHead;

  sprintf(filename, "snap%.4d.pcx", pcxCount);

  fp = fopen(filename, "wb");
  if (fp == NULL)
  {
    sprintf(filename, "c:\\snap%.4d.pcx", pcxCount);
    fp = fopen(filename, "wb");
    if (fp == NULL)
    {
      return(0);
    }
  }
  pcxCount += 1;

  // Set up and write the header
  pcxHead.manufacturer = 0x0a;
  pcxHead.version = 5;
  pcxHead.encoding = 1;
  pcxHead.bitsPerPixel = 8;
  pcxHead.xmin = 0;
  pcxHead.ymin = 0;
  pcxHead.xmax = 639;
  pcxHead.ymax = 479;
  pcxHead.hres = 72;
  pcxHead.vres = 72;
  pcxHead.reserved = 0;
  pcxHead.colourPlanes = 1;
  pcxHead.bytesPerLine = 640;
  pcxHead.paletteType = 1;
  fwrite(&pcxHead , sizeof(pcxHead), 1, fp);

  // The simplest job is to write out the entire file as a series of single units

  virtualWidth = 640;
//  char *pcxDataBase = buffer;           //GetBitMap() + (GetHeight()-1)* virtualWidth ;
  for (line = 0 ; line < 480; line++)
  {       
          pcxData = (unsigned char *)buffer;   //pcxDataBase;

          // Look to compress this line of 'width' pixels
          pix = 0;
          while (pix < 640)
          {       // Look for some run length coding
                  keyPix = pcxData[pix++];
                  runLength = 1;
                  while ( (pix < 640) && (keyPix == pcxData[pix]) )
                  {       runLength++;
                          pix++;
                  }
                  while (runLength > 1)
                  {       // We have a run length bit. Runs are a maximum of 0x3f
                          int lRun = runLength > 0x3f ? 0x3f : runLength;
                          runLength -= lRun;
                          lRun |= 0xc0;
                          ch = (unsigned char) lRun;
                          fwrite(&ch, 1, 1, fp);
                          ch = (unsigned char) keyPix;
                          fwrite(&ch, 1, 1, fp);
//                          fFile.WriteChar(lRun);
//                          fFile.WriteChar(keyPix);
                  }
                  if (runLength)
                  {       // Single pixel. If its <= 0x3f it goes straight in, otherwise it is a single run length
                          if (keyPix < 0xc0)
                          {
                                  ch = (unsigned char) keyPix;
                                  fwrite(&ch, 1, 1, fp);
//                                  fFile.WriteChar(keyPix);
                          }
                          else
                          {
                             ch = 0xc1;
                             fwrite(&ch, 1, 1, fp);
                             ch = (unsigned char) keyPix;
                             fwrite(&ch, 1, 1, fp);
//                                  fFile.WriteChar(0xc1);
//                                  fFile.WriteChar(keyPix);
                          }
                  }
          }
//          pcxDataBase -= virtualWidth;
          buffer += virtualWidth;
  }

  // Convert and write out the palette
//  StringClass sPal(768);
//  unsigned char *pal = palette;
//  for (int count = 0 ; count < 256 ; count++)
//  {       *(pal++) = bmi.bmiColors[count].rgbRed;
//          *(pal++) = bmi.bmiColors[count].rgbGreen;
//          *(pal++) = bmi.bmiColors[count].rgbBlue;
//  }
  ch = 0x0c;
  fwrite(&ch, 1, 1, fp);

  for (i=0; i<256*3; i++)
  {
    pal[i] = *((unsigned char *) palette + i);
  }

//  fFile.WriteChar(0x0c);
  fwrite(pal, 256*3, 1, fp);
//  if (fFile.Write(sPal , 768)!=768)
//          return(-1);
  fclose(fp);

  return(1);

}






int32 GrabScreenShot(void)

{
	warning("stub GrabScreenShot");
/*
	uint8			*screenGrabBuffer;
	uint8			*palette;
	DDSURFACEDESC	ddsd;
	HRESULT			hr;
	int32			i;


	screenGrabBuffer = (uint8 *) malloc(screenWide * screenDeep);
	if (screenGrabBuffer == NULL)
		return(RDERR_OUTOFMEMORY);

	ddsd.dwSize = sizeof(DDSURFACEDESC);
	hr = IDirectDrawSurface2_Lock(lpPrimarySurface, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	if (hr != DD_OK)
	{
		free(screenGrabBuffer);
		return(RDERR_LOCKFAILED);
	}
	
	for (i=0; i<screenDeep; i++)
	{
		memcpy(screenGrabBuffer + i * screenWide, (uint8 *) ddsd.lpSurface + ddsd.lPitch * i, screenWide);
	}
	IDirectDrawSurface2_Unlock(lpPrimarySurface, ddsd.lpSurface);


	palette = (uint8 *) malloc(256 * 3);
	if (palette == NULL)
	{
		free(screenGrabBuffer);
		return(RDERR_OUTOFMEMORY);
	}

	for (i=0; i<256; i++)
	{
		palette[i*3] = palCopy[i][0];
		palette[i*3+1] = palCopy[i][1];
		palette[i*3+2] = palCopy[i][2];
	}

	hr = SaveScreenShot(screenGrabBuffer,palette);


	free(palette);
	free(screenGrabBuffer);
*/
	return(RD_OK);
}



int32 NextSmackerFrame(void)
{
	warning("stub NextSmackerFrame");
	return(RD_OK);
}


uint32 textSurface = 0;

void OpenTextObject(_movieTextObject *obj)
{
	CreateSurface(obj->textSprite, &textSurface);
}

void CloseTextObject(_movieTextObject *obj)
{
	DeleteSurface(textSurface);
	textSurface = 0;
}

void DrawTextObject(_movieTextObject *obj)
{
	warning("stub DrawTextObject");
/*
	HRESULT				hr;
	RECT				rd, rs;
	LPDIRECTDRAWSURFACE	dds;
	_spriteInfo *s = obj->textSprite;
	char myString[256];


	dds = (LPDIRECTDRAWSURFACE) textSurface;

	// Set startx and starty for the screen buffer		ADDED THIS!
	if (s->type & RDSPR_DISPLAYALIGN)
		rd.top = s->y;
	else
		rd.top = s->y - scrolly;
		
	if (s->type & RDSPR_DISPLAYALIGN)
		rd.left = s->x;
	else
		rd.left = s->x - scrollx;

	rs.left = 0;
	rs.right = s->w;
	rs.top = 0;
	rs.bottom = s->h;
	if (s->scale & 0xff)
	{
		rd.right = rd.left + s->scaledWidth;
		rd.bottom = rd.top + s->scaledHeight;
		// Do clipping
		if (rd.top < 40)
		{
			rs.top = (40 - rd.top) * 256 / s->scale;
			rd.top = 40;
		}
		if (rd.bottom > 440)
		{
			rs.bottom -= ((rd.bottom - 440) * 256 / s->scale);
			rd.bottom = 440;
		}
		if (rd.left < 0)
		{
			rs.left = (0 - rd.left) * 256 / s->scale;
			rd.left = 0;
		}
		if (rd.right > 640)
		{
			rs.right -= ((rd.right - 640) * 256 / s->scale);
			rd.right = 640;
		}
	}
	else
	{
		rd.right = rd.left + s->w;
		rd.bottom = rd.top + s->h;

		// Do clipping
		if (rd.top < 40)
		{
			rs.top = 40 - rd.top;
			rd.top = 40;
		}
		if (rd.bottom > 440)
		{
			rs.bottom -= (rd.bottom - 440);
			rd.bottom = 440;
		}
		if (rd.left < 0)
		{
			rs.left = 0 - rd.left;
			rd.left = 0;
		}
		if (rd.right > 640)
		{
			rs.right -= (rd.right - 640);
			rd.right = 640;
		}
	}

	if (s->type & RDSPR_TRANS)
	{
		hr = IDirectDrawSurface2_Blt(lpPrimarySurface, &rd, dds, &rs, DDBLT_WAIT | DDBLT_KEYSRC, NULL);
		if (hr)
		{
			if (hr == DDERR_SURFACELOST)
				hr = RDERR_SURFACELOST;
			else if (dxHalCaps & RDCAPS_BLTSTRETCH)
				dxHalCaps -= RDCAPS_BLTSTRETCH;
			else
			{
				sprintf(myString, "Cannot print smacker text x%d y%d w%d h%d s%d t%d\n", s->x, s->y, s->w, s->h, s->scale, s->type);
				DirectDrawError(myString, hr);
			}
		}
	}
	else
	{
		hr = IDirectDrawSurface2_Blt(lpPrimarySurface, &rd, dds, &rs, DDBLT_WAIT, NULL);
		if (hr)
		{
			if (hr == DDERR_SURFACELOST)
				hr = RDERR_SURFACELOST;
			else
			{
				sprintf(myString, "Cannot print smacker text x%d y%d w%d h%d s%d t%d\n", s->x, s->y, s->w, s->h, s->scale, s->type);
				DirectDrawError(myString, hr);
			}
		}
	}
*/
}


extern uint8 musicMuted;

int32 PlaySmacker(char *filename, _movieTextObject *text[], uint8 *musicOut)
{
	warning("stub PlaySmacker %s", filename);
	return(RD_OK);

}



void GetDrawStatus(_drvDrawStatus *s)
{
//	s->hwnd				= hwnd;
//	s->lpDraw			= lpDraw;
//	s->lpDD2			= lpDD2;
//	s->lpPrimarySurface = lpPrimarySurface;
//	s->lpBackBuffer		= lpBackBuffer;
//	s->lpPalette		= lpPalette;
	s->screenDeep		= screenDeep;
	s->screenWide		= screenWide;
	s->scrollx			= scrollx;
	s->scrolly			= scrolly;
	s->scrollxTarget	= scrollxTarget;
	s->scrollyTarget	= scrollyTarget;
	s->scrollxOld		= scrollxOld;
	s->scrollyOld		= scrollyOld;
	s->failCount		= failCount;
	s->renderCaps		= renderCaps;
	s->dxHalCaps		= dxHalCaps;
	s->dxHelCaps		= dxHelCaps;
	s->noVbl			= noVbl;
	s->bFullScreen		= bFullScreen;
	
//	memcpy(&s->driverCaps,	 &driverCaps,	sizeof(DDCAPS));
//	memset(&blackColorKey, 0, sizeof(DDCOLORKEY));
}



void SetDrawStatus(_drvDrawStatus *s)
{
//	hwnd			= s->hwnd;
//	lpDraw			= s->lpDraw;
//	lpDD2			= s->lpDD2;
//	lpPrimarySurface= s->lpPrimarySurface;
//	lpBackBuffer	= s->lpBackBuffer;
//	lpPalette		= s->lpPalette;
	screenDeep		= s->screenDeep;
	screenWide		= s->screenWide;
	scrollx			= s->scrollx;
	scrolly			= s->scrolly;
	scrollxTarget	= s->scrollxTarget;
	scrollyTarget	= s->scrollyTarget;
	scrollxOld		= s->scrollxOld;
	scrollyOld		= s->scrollyOld;
	failCount		= s->failCount;
//	renderCaps		= s->renderCaps;
	dxHalCaps		= s->dxHalCaps;
	dxHelCaps		= s->dxHelCaps;
	noVbl			= s->noVbl;
	bFullScreen		= s->bFullScreen;
	
//	memcpy(&driverCaps,	 &s->driverCaps,	sizeof(DDCAPS));
//	memset(&blackColorKey, 0, sizeof(DDCOLORKEY));
}