1 #include "3dc.h"
2 
3 #if debug
4 
5 #include "ourasert.h"
6 #include "dxlog.h"
7 #include "debuglog.h"
8 
9 /*
10  * D3DAppErrorToString
11  */
12 static char*
D3DAppErrorToString(HRESULT error)13 D3DAppErrorToString(HRESULT error)
14 {
15     switch(error) {
16         case DD_OK:
17             return "No error.\0";
18         case DDERR_ALREADYINITIALIZED:
19             return "This object is already initialized.\0";
20         case DDERR_BLTFASTCANTCLIP:
21             return "Return if a clipper object is attached to the source surface passed into a BltFast call.\0";
22         case DDERR_CANNOTATTACHSURFACE:
23             return "This surface can not be attached to the requested surface.\0";
24         case DDERR_CANNOTDETACHSURFACE:
25             return "This surface can not be detached from the requested surface.\0";
26         case DDERR_CANTCREATEDC:
27             return "Windows can not create any more DCs.\0";
28         case DDERR_CANTDUPLICATE:
29             return "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created.\0";
30         case DDERR_CLIPPERISUSINGHWND:
31             return "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd.\0";
32         case DDERR_COLORKEYNOTSET:
33             return "No src color key specified for this operation.\0";
34         case DDERR_CURRENTLYNOTAVAIL:
35             return "Support is currently not available.\0";
36         case DDERR_DIRECTDRAWALREADYCREATED:
37             return "A DirectDraw object representing this driver has already been created for this process.\0";
38         case DDERR_EXCEPTION:
39             return "An exception was encountered while performing the requested operation.\0";
40         case DDERR_EXCLUSIVEMODEALREADYSET:
41             return "An attempt was made to set the cooperative level when it was already set to exclusive.\0";
42         case DDERR_GENERIC:
43             return "Generic failure.\0";
44         case DDERR_HEIGHTALIGN:
45             return "Height of rectangle provided is not a multiple of reqd alignment.\0";
46         case DDERR_HWNDALREADYSET:
47             return "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created.\0";
48         case DDERR_HWNDSUBCLASSED:
49             return "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state.\0";
50         case DDERR_IMPLICITLYCREATED:
51             return "This surface can not be restored because it is an implicitly created surface.\0";
52         case DDERR_INCOMPATIBLEPRIMARY:
53             return "Unable to match primary surface creation request with existing primary surface.\0";
54         case DDERR_INVALIDCAPS:
55             return "One or more of the caps bits passed to the callback are incorrect.\0";
56         case DDERR_INVALIDCLIPLIST:
57             return "DirectDraw does not support the provided cliplist.\0";
58         case DDERR_INVALIDDIRECTDRAWGUID:
59             return "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.\0";
60         case DDERR_INVALIDMODE:
61             return "DirectDraw does not support the requested mode.\0";
62         case DDERR_INVALIDOBJECT:
63             return "DirectDraw received a pointer that was an invalid DIRECTDRAW object.\0";
64         case DDERR_INVALIDPARAMS:
65             return "One or more of the parameters passed to the function are incorrect.\0";
66         case DDERR_INVALIDPIXELFORMAT:
67             return "The pixel format was invalid as specified.\0";
68         case DDERR_INVALIDPOSITION:
69             return "Returned when the position of the overlay on the destination is no longer legal for that destination.\0";
70         case DDERR_INVALIDRECT:
71             return "Rectangle provided was invalid.\0";
72         case DDERR_LOCKEDSURFACES:
73             return "Operation could not be carried out because one or more surfaces are locked.\0";
74         case DDERR_NO3D:
75             return "There is no 3D present.\0";
76         case DDERR_NOALPHAHW:
77             return "Operation could not be carried out because there is no alpha accleration hardware present or available.\0";
78         case DDERR_NOBLTHW:
79             return "No blitter hardware present.\0";
80         case DDERR_NOCLIPLIST:
81             return "No cliplist available.\0";
82         case DDERR_NOCLIPPERATTACHED:
83             return "No clipper object attached to surface object.\0";
84         case DDERR_NOCOLORCONVHW:
85             return "Operation could not be carried out because there is no color conversion hardware present or available.\0";
86         case DDERR_NOCOLORKEY:
87             return "Surface doesn't currently have a color key\0";
88         case DDERR_NOCOLORKEYHW:
89             return "Operation could not be carried out because there is no hardware support of the destination color key.\0";
90         case DDERR_NOCOOPERATIVELEVELSET:
91             return "Create function called without DirectDraw object method SetCooperativeLevel being called.\0";
92         case DDERR_NODC:
93             return "No DC was ever created for this surface.\0";
94         case DDERR_NODDROPSHW:
95             return "No DirectDraw ROP hardware.\0";
96         case DDERR_NODIRECTDRAWHW:
97             return "A hardware-only DirectDraw object creation was attempted but the driver did not support any hardware.\0";
98         case DDERR_NOEMULATION:
99             return "Software emulation not available.\0";
100         case DDERR_NOEXCLUSIVEMODE:
101             return "Operation requires the application to have exclusive mode but the application does not have exclusive mode.\0";
102         case DDERR_NOFLIPHW:
103             return "Flipping visible surfaces is not supported.\0";
104         case DDERR_NOGDI:
105             return "There is no GDI present.\0";
106         case DDERR_NOHWND:
107             return "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND.\0";
108         case DDERR_NOMIRRORHW:
109             return "Operation could not be carried out because there is no hardware present or available.\0";
110         case DDERR_NOOVERLAYDEST:
111             return "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on to establish a destination.\0";
112         case DDERR_NOOVERLAYHW:
113             return "Operation could not be carried out because there is no overlay hardware present or available.\0";
114         case DDERR_NOPALETTEATTACHED:
115             return "No palette object attached to this surface.\0";
116         case DDERR_NOPALETTEHW:
117             return "No hardware support for 16 or 256 color palettes.\0";
118         case DDERR_NORASTEROPHW:
119             return "Operation could not be carried out because there is no appropriate raster op hardware present or available.\0";
120         case DDERR_NOROTATIONHW:
121             return "Operation could not be carried out because there is no rotation hardware present or available.\0";
122         case DDERR_NOSTRETCHHW:
123             return "Operation could not be carried out because there is no hardware support for stretching.\0";
124         case DDERR_NOT4BITCOLOR:
125             return "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette.\0";
126         case DDERR_NOT4BITCOLORINDEX:
127             return "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette.\0";
128         case DDERR_NOT8BITCOLOR:
129             return "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color.\0";
130         case DDERR_NOTAOVERLAYSURFACE:
131             return "Returned when an overlay member is called for a non-overlay surface.\0";
132         case DDERR_NOTEXTUREHW:
133             return "Operation could not be carried out because there is no texture mapping hardware present or available.\0";
134         case DDERR_NOTFLIPPABLE:
135             return "An attempt has been made to flip a surface that is not flippable.\0";
136         case DDERR_NOTFOUND:
137             return "Requested item was not found.\0";
138         case DDERR_NOTLOCKED:
139             return "Surface was not locked.  An attempt to unlock a surface that was not locked at all, or by this process, has been attempted.\0";
140         case DDERR_NOTPALETTIZED:
141             return "The surface being used is not a palette-based surface.\0";
142         case DDERR_NOVSYNCHW:
143             return "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations.\0";
144         case DDERR_NOZBUFFERHW:
145             return "Operation could not be carried out because there is no hardware support for zbuffer blitting.\0";
146         case DDERR_NOZOVERLAYHW:
147             return "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays.\0";
148         case DDERR_OUTOFCAPS:
149             return "The hardware needed for the requested operation has already been allocated.\0";
150         case DDERR_OUTOFMEMORY:
151             return "DirectDraw does not have enough memory to perform the operation.\0";
152         case DDERR_OUTOFVIDEOMEMORY:
153             return "DirectDraw does not have enough video memory to perform the operation.\0";
154         case DDERR_OVERLAYCANTCLIP:
155             return "The hardware does not support clipped overlays.\0";
156         case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
157             return "Can only have ony color key active at one time for overlays.\0";
158         case DDERR_OVERLAYNOTVISIBLE:
159             return "Returned when GetOverlayPosition is called on a hidden overlay.\0";
160         case DDERR_PALETTEBUSY:
161             return "Access to this palette is being refused because the palette is already locked by another thread.\0";
162         case DDERR_PRIMARYSURFACEALREADYEXISTS:
163             return "This process already has created a primary surface.\0";
164         case DDERR_REGIONTOOSMALL:
165             return "Region passed to Clipper::GetClipList is too small.\0";
166         case DDERR_SURFACEALREADYATTACHED:
167             return "This surface is already attached to the surface it is being attached to.\0";
168         case DDERR_SURFACEALREADYDEPENDENT:
169             return "This surface is already a dependency of the surface it is being made a dependency of.\0";
170         case DDERR_SURFACEBUSY:
171             return "Access to this surface is being refused because the surface is already locked by another thread.\0";
172         case DDERR_SURFACEISOBSCURED:
173             return "Access to surface refused because the surface is obscured.\0";
174         case DDERR_SURFACELOST:
175             return "Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have Restore called on it.\0";
176         case DDERR_SURFACENOTATTACHED:
177             return "The requested surface is not attached.\0";
178         case DDERR_TOOBIGHEIGHT:
179             return "Height requested by DirectDraw is too large.\0";
180         case DDERR_TOOBIGSIZE:
181             return "Size requested by DirectDraw is too large, but the individual height and width are OK.\0";
182         case DDERR_TOOBIGWIDTH:
183             return "Width requested by DirectDraw is too large.\0";
184         case DDERR_UNSUPPORTED:
185             return "Action not supported.\0";
186         case DDERR_UNSUPPORTEDFORMAT:
187             return "FOURCC format requested is unsupported by DirectDraw.\0";
188         case DDERR_UNSUPPORTEDMASK:
189             return "Bitmask in the pixel format requested is unsupported by DirectDraw.\0";
190         case DDERR_VERTICALBLANKINPROGRESS:
191             return "Vertical blank is in progress.\0";
192         case DDERR_WASSTILLDRAWING:
193             return "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete.\0";
194         case DDERR_WRONGMODE:
195             return "This surface can not be restored because it was created in a different mode.\0";
196         case DDERR_XALIGN:
197             return "Rectangle provided was not horizontally aligned on required boundary.\0";
198         case D3DERR_BADMAJORVERSION:
199             return "D3DERR_BADMAJORVERSION\0";
200         case D3DERR_BADMINORVERSION:
201             return "D3DERR_BADMINORVERSION\0";
202         case D3DERR_EXECUTE_LOCKED:
203             return "D3DERR_EXECUTE_LOCKED\0";
204         case D3DERR_EXECUTE_NOT_LOCKED:
205             return "D3DERR_EXECUTE_NOT_LOCKED\0";
206         case D3DERR_EXECUTE_CREATE_FAILED:
207             return "D3DERR_EXECUTE_CREATE_FAILED\0";
208         case D3DERR_EXECUTE_DESTROY_FAILED:
209             return "D3DERR_EXECUTE_DESTROY_FAILED\0";
210         case D3DERR_EXECUTE_LOCK_FAILED:
211             return "D3DERR_EXECUTE_LOCK_FAILED\0";
212         case D3DERR_EXECUTE_UNLOCK_FAILED:
213             return "D3DERR_EXECUTE_UNLOCK_FAILED\0";
214         case D3DERR_EXECUTE_FAILED:
215             return "D3DERR_EXECUTE_FAILED\0";
216         case D3DERR_EXECUTE_CLIPPED_FAILED:
217             return "D3DERR_EXECUTE_CLIPPED_FAILED\0";
218         case D3DERR_TEXTURE_NO_SUPPORT:
219             return "D3DERR_TEXTURE_NO_SUPPORT\0";
220         case D3DERR_TEXTURE_NOT_LOCKED:
221             return "D3DERR_TEXTURE_NOT_LOCKED\0";
222         case D3DERR_TEXTURE_LOCKED:
223             return "D3DERR_TEXTURELOCKED\0";
224         case D3DERR_TEXTURE_CREATE_FAILED:
225             return "D3DERR_TEXTURE_CREATE_FAILED\0";
226         case D3DERR_TEXTURE_DESTROY_FAILED:
227             return "D3DERR_TEXTURE_DESTROY_FAILED\0";
228         case D3DERR_TEXTURE_LOCK_FAILED:
229             return "D3DERR_TEXTURE_LOCK_FAILED\0";
230         case D3DERR_TEXTURE_UNLOCK_FAILED:
231             return "D3DERR_TEXTURE_UNLOCK_FAILED\0";
232         case D3DERR_TEXTURE_LOAD_FAILED:
233             return "D3DERR_TEXTURE_LOAD_FAILED\0";
234         case D3DERR_MATRIX_CREATE_FAILED:
235             return "D3DERR_MATRIX_CREATE_FAILED\0";
236         case D3DERR_MATRIX_DESTROY_FAILED:
237             return "D3DERR_MATRIX_DESTROY_FAILED\0";
238         case D3DERR_MATRIX_SETDATA_FAILED:
239             return "D3DERR_MATRIX_SETDATA_FAILED\0";
240         case D3DERR_SETVIEWPORTDATA_FAILED:
241             return "D3DERR_SETVIEWPORTDATA_FAILED\0";
242         case D3DERR_MATERIAL_CREATE_FAILED:
243             return "D3DERR_MATERIAL_CREATE_FAILED\0";
244         case D3DERR_MATERIAL_DESTROY_FAILED:
245             return "D3DERR_MATERIAL_DESTROY_FAILED\0";
246         case D3DERR_MATERIAL_SETDATA_FAILED:
247             return "D3DERR_MATERIAL_SETDATA_FAILED\0";
248         case D3DERR_LIGHT_SET_FAILED:
249             return "D3DERR_LIGHT_SET_FAILED\0";
250         case D3DRMERR_BADOBJECT:
251             return "D3DRMERR_BADOBJECT\0";
252         case D3DRMERR_BADTYPE:
253             return "D3DRMERR_BADTYPE\0";
254         case D3DRMERR_BADALLOC:
255             return "D3DRMERR_BADALLOC\0";
256         case D3DRMERR_FACEUSED:
257             return "D3DRMERR_FACEUSED\0";
258         case D3DRMERR_NOTFOUND:
259             return "D3DRMERR_NOTFOUND\0";
260         case D3DRMERR_NOTDONEYET:
261             return "D3DRMERR_NOTDONEYET\0";
262         case D3DRMERR_FILENOTFOUND:
263             return "The file was not found.\0";
264         case D3DRMERR_BADFILE:
265             return "D3DRMERR_BADFILE\0";
266         case D3DRMERR_BADDEVICE:
267             return "D3DRMERR_BADDEVICE\0";
268         case D3DRMERR_BADVALUE:
269             return "D3DRMERR_BADVALUE\0";
270         case D3DRMERR_BADMAJORVERSION:
271             return "D3DRMERR_BADMAJORVERSION\0";
272         case D3DRMERR_BADMINORVERSION:
273             return "D3DRMERR_BADMINORVERSION\0";
274         case D3DRMERR_UNABLETOEXECUTE:
275             return "D3DRMERR_UNABLETOEXECUTE\0";
276         default:
277             return "Unrecognized error value.\0";
278     }
279 }
280 
281 #define LOGFILE_NAME "dx_errorM.log"
282 
283 static LOGFILE * dxlog = 0;
284 static int closed_once = 0;
285 
dx_err_log(HRESULT error,int line,char const * file)286 void dx_err_log(HRESULT error, int line, char const * file)
287 {
288 	if (DD_OK==error) return;
289 	if (closed_once) return;
290 
291 
292 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
293 
294 	lfprintf(dxlog,"Line %d of %s:\n%s\n\n",line,file,D3DAppErrorToString(error));
295 }
296 
dx_str_log(char const * str,int line,char const * file)297 void dx_str_log(char const * str, int line, char const * file)
298 {
299 	if (closed_once) return;
300 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
301 
302 	lfprintf(dxlog,"Line %d of %s:\n%s\n\n",line,file,str);
303 }
304 
dx_line_log(int line,char const * file)305 void dx_line_log(int line, char const * file)
306 {
307 	if (closed_once) return;
308 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
309 
310 	lfprintf(dxlog,"Line %d of %s:\n",line,file);
311 }
312 
dx_strf_log(char const * fmt,...)313 void dx_strf_log(char const * fmt, ... )
314 {
315 	if (closed_once) return;
316 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
317 	{
318 		va_list ap;
319 		va_start(ap, fmt);
320 		vlfprintf(dxlog,fmt,ap);
321 		va_end(ap);
322 	}
323 	lfputs(dxlog,"\n\n");
324 }
325 
326 #undef exit
GlobalAssertFired(char * Filename,int LineNum,char * Condition)327 int GlobalAssertFired(char * Filename, int LineNum,char * Condition)
328 {
329 	extern void exit_break_point_fucntion ();
330 	exit_break_point_fucntion();
331 	if (closed_once) return 0;
332 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
333 
334 	lfprintf(dxlog,"Line %d of %s:\nGAF: %s\n",LineNum,Filename,Condition);
335 	lfclose(dxlog);
336 	closed_once = 1;
337 	textprint("Line %d of %s:\nGAF: %s\n",LineNum,Filename,Condition);
338 	WaitForReturn();
339 
340 	ExitSystem();
341 	exit(0xffff);
342 }
343 
LocalAssertFired(char * Filename,int LineNum,char * Condition)344 int LocalAssertFired(char * Filename, int LineNum,char * Condition)
345 {
346 	extern void exit_break_point_fucntion ();
347 	exit_break_point_fucntion();
348 	if (closed_once) return 0;
349 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
350 
351 	lfprintf(dxlog,"Line %d of %s:\nLAF: %s\n",LineNum,Filename,Condition);
352 	lfclose(dxlog);
353 	closed_once = 1;
354 	textprint("Line %d of %s:\nLAF: %s\n",LineNum,Filename,Condition);
355 	WaitForReturn();
356 
357 	ExitSystem();
358 	exit(0xfffe);
359 }
360 
361 
DXLOGHandleCompilerWarningMessage(void)362 void DXLOGHandleCompilerWarningMessage(void)
363 {
364 	int temp;
365 
366 	temp = D3DRMMAP_PERSPCORRECT;
367 	temp = D3DRMMAP_WRAPU;
368 	temp = D3DRMMAP_WRAPV;
369 	temp = D3DRMGROUP_ALLGROUPS;
370 }
371 
ExitFired(char * Filename,int LineNum,int ExitCode)372 void ExitFired(char* Filename, int LineNum, int ExitCode)
373 {
374 	extern void exit_break_point_fucntion ();
375 	exit_break_point_fucntion();
376 	if (closed_once) return ;
377 	if (!dxlog) dxlog = lfopen(LOGFILE_NAME);
378 
379 	lfprintf(dxlog,"Line %d of %s:\nExit: %x\n",LineNum,Filename,ExitCode);
380 	lfclose(dxlog);
381 	closed_once = 1;
382 
383 	exit(ExitCode);
384 }
385 #endif
386