Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-rice/src/Debugger.cpp
2 views
1
/*
2
Copyright (C) 2002 Rice1964
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
*/
19
20
#define M64P_PLUGIN_PROTOTYPES 1
21
#include "m64p_plugin.h"
22
#include "typedefs.h"
23
24
#ifndef DEBUGGER
25
void __cdecl DebuggerAppendMsg(const char * Message, ...) {}
26
27
#ifdef WANT_LOG_UCODE
28
#include <varargs.h>
29
#include <stdio.h>
30
void __cdecl LOG_UCODE(const char* szFormat, ...)
31
{
32
{
33
char Msg[400];
34
va_list va;
35
va_start(va, szFormat);
36
vsprintf( Msg, szFormat, va );
37
va_end(va);
38
printf("%s\n", Msg);
39
}
40
}
41
#endif
42
43
#else
44
45
void DumpMatrix2(const Matrix &mtx, const char* prompt);
46
47
bool debuggerWinOpened = false;
48
bool debuggerDrawRenderTexture = false;
49
int debuggerDrawRenderTextureNo = 0;
50
51
bool logCombiners = false;
52
bool logWarning = true;
53
bool logTriangles = false;
54
bool logMatrix = false;
55
bool logVertex = false;
56
bool logTextures = false;
57
bool logTextureBuffer = false;
58
bool logToScreen = true;
59
bool logToFile = false;
60
bool logUcodes = false;
61
bool logMicrocode = false;
62
bool logFog = false;
63
bool logDetails = false;
64
65
FILE *logFp = NULL;
66
67
bool debuggerEnableTexture=true;
68
bool debuggerEnableZBuffer=true;
69
bool debuggerEnableCullFace=true;
70
bool debuggerEnableTestTris=true;
71
bool debuggerEnableAlphaTest=true;
72
bool debuggerContinueWithUnknown=false;
73
74
bool debuggerPause = false;
75
bool pauseAtNext = true;
76
int eventToPause = NEXT_FRAME;
77
int debuggerPauseCount = 340;
78
int countToPause = 1;
79
80
bool debuggerDropCombiners=false;
81
bool debuggerDropGeneralCombiners=false;
82
bool debuggerDropDecodedMux=false;
83
bool debuggerDropCombinerInfos=false;
84
85
char msgBuf[0x20000+2];
86
bool msgBufUpdated = false;
87
extern FiddledVtx * g_pVtxBase;
88
89
uint32 CachedTexIndex = 0;
90
91
const char* otherNexts[] = {
92
"Frame",
93
"Flush Tri",
94
"TextRect",
95
"Triangle",
96
"Set CImg",
97
"ObjTxt Cmd",
98
"Obj BG",
99
"Sprite2D",
100
"FillRect",
101
"DList",
102
"Ucode",
103
"Texture Buffer",
104
"Matrix Cmd",
105
"Vertex Cmd",
106
"New Texture",
107
"Set Texture",
108
"Mux",
109
"Set Light",
110
"Set Mode Cmd",
111
"Set Prim Color",
112
"Texture Cmd",
113
"Unknown Ops",
114
"Scale Image",
115
"LoadTlut",
116
"Ucode Switching",
117
};
118
int numberOfNextOthers = sizeof(otherNexts)/sizeof(char*);
119
120
const char* thingsToDump[] = {
121
"Cur Texture RGBA",
122
"Cur+1 Texture RGBA",
123
"Colors",
124
"Memory At",
125
"Mux",
126
"Simple Mux",
127
"Other Modes",
128
"Texture #",
129
"Tile #",
130
"VI Regs",
131
"Cur Txt to file",
132
"Cur+1 Txt to file",
133
"Cur Texture RGB",
134
"Cur Texture Alpha",
135
"Cur+1 Texture RGB",
136
"Cur+1 Texture Alpha",
137
"Light Info",
138
"Tlut",
139
"Obj Tlut",
140
"Vertexes",
141
"Cached Texture",
142
"Next Texture",
143
"Prev Texture",
144
"Dlist At",
145
"Matrix At",
146
"Combined Matrix",
147
"World Top Matrix",
148
"Projection Matrix",
149
"World Matrix #",
150
"Frame Buffer in RDRAM",
151
"BackBuffer",
152
"TexBuffer #",
153
};
154
int numberOfThingsToDump = sizeof(thingsToDump)/sizeof(char*);
155
156
enum {
157
DUMP_CUR_TEXTURE_RGBA,
158
DUMP_CUR_1_TEXTURE_RGBA,
159
DUMP_COLORS,
160
DUMP_CONTENT_AT,
161
DUMP_CUR_MUX,
162
DUMP_SIMPLE_MUX,
163
DUMP_OTHER_MODE,
164
DUMP_TEXTURE_AT,
165
DUMP_TILE_AT,
166
DUMP_VI_REGS,
167
DUMP_CUR_TEXTURE_TO_FILE,
168
DUMP_CUR_1_TEXTURE_TO_FILE,
169
DUMP_CUR_TEXTURE_RGB,
170
DUMP_CUR_TEXTURE_ALPHA,
171
DUMP_CUR_1_TEXTURE_RGB,
172
DUMP_CUR_1_TEXTURE_ALPHA,
173
DUMP_LIGHT,
174
DUMP_TLUT,
175
DUMP_OBJ_TLUT,
176
DUMP_VERTEXES,
177
DUMP_CACHED_TEX,
178
DUMP_NEXT_TEX,
179
DUMP_PREV_TEX,
180
DUMP_DLIST_AT,
181
DUMP_MATRIX_AT,
182
DUMP_COMBINED_MATRIX,
183
DUMP_WORLD_TOP_MATRIX,
184
DUMP_PROJECTION_MATRIX,
185
DUMP_WORLD_MATRIX_AT,
186
DUMP_FRAME_BUFFER,
187
DUMP_BACKBUFFER,
188
DUMP_TEXBUFFER_AT,
189
};
190
191
//---------------------------------------------------------------------
192
void DumpVIRegisters(void)
193
{
194
DebuggerAppendMsg("----VI Registers----\nSTATUS:\t%08X\nORIGIN:\t%08X\nWIDTH:\t%08X\n\
195
V_SYNC:\t%08X\nH_SYNC:\t%08X\nX_SCALE:\t%08X\nY_SCALE:\t%08X\n\
196
H_START:\t%08X\nV_START:\t%08X\nVI Width=%f(x %f), VI Height=%f(x %f)\n\n",
197
*g_GraphicsInfo.VI_STATUS_REG, *g_GraphicsInfo.VI_ORIGIN_REG, *g_GraphicsInfo.VI_WIDTH_REG, *g_GraphicsInfo.VI_V_SYNC_REG,
198
*g_GraphicsInfo.VI_H_SYNC_REG, *g_GraphicsInfo.VI_X_SCALE_REG, *g_GraphicsInfo.VI_Y_SCALE_REG,
199
*g_GraphicsInfo.VI_H_START_REG, *g_GraphicsInfo.VI_V_START_REG, windowSetting.fViWidth,windowSetting.fMultX,
200
windowSetting.fViHeight,windowSetting.fMultY);
201
DebuggerAppendMsg("Scissor: x0=%d y0=%d x1=%d y1=%d mode=%d",
202
gRDP.scissor.left, gRDP.scissor.top,
203
gRDP.scissor.right, gRDP.scissor.bottom,
204
gRDP.scissor.mode);
205
DebuggerAppendMsg("Effective scissor: x0=%d y0=%d x1=%d y1=%d",
206
gRSP.real_clip_scissor_left, gRSP.real_clip_scissor_top,
207
gRSP.real_clip_scissor_right, gRSP.real_clip_scissor_bottom);
208
DebuggerAppendMsg("Clipping: (%d) left=%f top=%f right=%f bottom=%f",
209
gRSP.clip_ratio_posx, gRSP.real_clip_ratio_negx , gRSP.real_clip_ratio_negy,
210
gRSP.real_clip_ratio_posx, gRSP.real_clip_ratio_posy);
211
DebuggerAppendMsg("Viewport: left=%d top=%d right=%d bottom=%d",
212
gRSP.nVPLeftN, gRSP.nVPTopN , gRSP.nVPRightN,
213
gRSP.nVPBottomN);
214
DebuggerAppendMsg("Current CImg: Addr=0x%08X, Fmt:%s-%sb, Width=%d\n",
215
g_CI.dwAddr, pszImgFormat[g_CI.dwFormat], pszImgSize[g_CI.dwSize], g_CI.dwWidth);
216
DebuggerAppendMsg("Current ZImg: Addr=0x%08X, Fmt:%s-%sb, Width=%d\n",
217
g_ZI.dwAddr, pszImgFormat[g_ZI.dwFormat], pszImgSize[g_ZI.dwSize], g_ZI.dwWidth);
218
}
219
220
void DumpVertexArray(void)
221
{
222
DebuggerAppendMsg("----Vertexes----\n");
223
try
224
{
225
for( int i=0; i<32; i++ )
226
{
227
FiddledVtx &v = g_pVtxBase[i];
228
DebuggerAppendMsg("[%d] x=%d,y=%d,z=%d -- r=%d,g=%d,b=%d,a=%d\n", i, v.x, v.y, v.z,
229
v.rgba.r, v.rgba.g, v.rgba.b, v.rgba.a);
230
DebuggerAppendMsg("\tx=%f,y=%f,z=%f,rhw=%f\n", g_vecProjected[i].x, g_vecProjected[i].y, g_vecProjected[i].z, g_vecProjected[i].w);
231
}
232
}
233
catch(...)
234
{
235
DebuggerAppendMsg("Invalid memory pointer of vertex array\n");
236
}
237
}
238
239
void DumpHex(uint32 rdramAddr, int count);
240
uint32 StrToHex(char *HexStr);
241
242
void DumpTileInfo(uint32 dwTile)
243
{
244
const char *pszOnOff[2] = {"Off", "On"};
245
246
DebuggerAppendMsg("Tile: %d\nFmt: %s/%s Line:%d (Pitch %d) TMem:0x%04x Palette:%d\n",
247
dwTile, pszImgFormat[gRDP.tiles[dwTile].dwFormat], pszImgSize[gRDP.tiles[dwTile].dwSize],
248
gRDP.tiles[dwTile].dwLine, gRDP.tiles[dwTile].dwPitch, gRDP.tiles[dwTile].dwTMem, gRDP.tiles[dwTile].dwPalette);
249
DebuggerAppendMsg("S: Clamp: %s Mirror:%s Mask:0x%x Shift:0x%x\n",
250
pszOnOff[gRDP.tiles[dwTile].bClampS],pszOnOff[gRDP.tiles[dwTile].bMirrorS],
251
gRDP.tiles[dwTile].dwMaskS, gRDP.tiles[dwTile].dwShiftS);
252
DebuggerAppendMsg("T: Clamp: %s Mirror:%s Mask:0x%x Shift:0x%x\n",
253
pszOnOff[gRDP.tiles[dwTile].bClampT],pszOnOff[gRDP.tiles[dwTile].bMirrorT],
254
gRDP.tiles[dwTile].dwMaskT, gRDP.tiles[dwTile].dwShiftT);
255
DebuggerAppendMsg("(%d,%d) -> (%d,%d), hilite [%d, %d]\n",
256
gRDP.tiles[dwTile].sl, gRDP.tiles[dwTile].tl, gRDP.tiles[dwTile].sh, gRDP.tiles[dwTile].th,
257
gRDP.tiles[dwTile].hilite_sl,gRDP.tiles[dwTile].hilite_tl);
258
}
259
260
void DumpTexture(int tex, TextureChannel channel = TXT_RGB )
261
{
262
CRender::GetRender()->DrawTexture(tex, channel);
263
}
264
265
void DumpRenderTexture(int tex=-1)
266
{
267
if( CDeviceBuilder::GetBuilder()->GetGeneralDeviceType() == DIRECTX_DEVICE )
268
{
269
g_pFrameBufferManager->DisplayRenderTexture(tex);
270
}
271
else
272
{
273
debuggerDrawRenderTextureNo = tex;
274
debuggerDrawRenderTexture = true;
275
}
276
}
277
278
void DumpTextureToFile(int tex, TextureChannel channel = TXT_RGB)
279
{
280
CRender::GetRender()->SaveTextureToFile(tex, channel,false);
281
}
282
283
void DumpTlut(uint16* palAddr)
284
{
285
for( uint32 i=0; i<0x100; i+=8 )
286
{
287
DebuggerAppendMsg("0x%4X 0x%4X 0x%4X 0x%4X 0x%4X 0x%4X 0x%4X 0x%4X ",
288
g_wRDPTlut[i], g_wRDPTlut[i+1], g_wRDPTlut[i+2], g_wRDPTlut[i+2],
289
g_wRDPTlut[i+4], g_wRDPTlut[i+5], g_wRDPTlut[i+6], g_wRDPTlut[i+7]);
290
}
291
}
292
293
extern char ucodeNames_GBI1[256];
294
extern char ucodeNames_GBI2[256];
295
296
void DumpDlistAt(uint32 dwPC)
297
{
298
uint32 word0, word1, opcode;
299
char *name;
300
switch( gRSP.ucode )
301
{
302
case 2:
303
case 10:
304
//case 8:
305
name=ucodeNames_GBI2;
306
break;
307
default:
308
name=ucodeNames_GBI1;
309
}
310
311
DebuggerAppendMsg("\n\n");
312
//if( dwPC>100 ) dwPC -= 40;
313
for( uint32 i=0; i<20; i++)
314
{
315
word0 = g_pRDRAMu32[(dwPC>>2)+0];
316
word1 = g_pRDRAMu32[(dwPC>>2)+1];
317
opcode = word0>>24;
318
DebuggerAppendMsg("%08X: %08X, %08X - %s", dwPC, word0, word1, name[opcode] );
319
dwPC+=8;
320
}
321
DebuggerAppendMsg("\n\n");
322
}
323
324
void DumpMatrixAt(uint32 dwPC)
325
{
326
Matrix mat;
327
const float fRecip = 1.0f / 65536.0f;
328
329
for (uint32 dwI = 0; dwI < 4; dwI++)
330
{
331
for (uint32 dwJ = 0; dwJ < 4; dwJ++)
332
{
333
int nDataHi = *(short *)(g_pRDRAMu8 + ((dwPC+(dwI<<3)+(dwJ<<1) )^0x2));
334
int nDataLo = *(uint16 *)(g_pRDRAMu8 + ((dwPC+(dwI<<3)+(dwJ<<1) + 32)^0x2));
335
mat.m[dwI][dwJ] = (float)((nDataHi << 16) | nDataLo) * fRecip;
336
}
337
}
338
339
TRACE0("Dump Matrix in Memory");
340
DebuggerAppendMsg(
341
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
342
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
343
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
344
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n",
345
mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[0][3],
346
mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[1][3],
347
mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[2][3],
348
mat.m[3][0], mat.m[3][1], mat.m[3][2], mat.m[3][3]);
349
}
350
351
// High
352
static const char *alphadithertypes[4] = {"Pattern", "NotPattern", "Noise", "Disable"};
353
static const char *rgbdithertype[4] = {"MagicSQ", "Bayer", "Noise", "Disable"};
354
static const char *convtype[8] = {"Conv", "?", "?", "?", "?", "FiltConv", "Filt", "?"};
355
static const char *filtertype[4] = {"Point", "?", "Bilinear", "Average"};
356
static const char *cycletype[4] = {"1Cycle", "2Cycle", "Copy", "Fill"};
357
static const char *alphacomptype[4] = {"None", "Threshold", "?", "Dither"};
358
static const char * szCvgDstMode[4] = { "Clamp", "Wrap", "Full", "Save" };
359
static const char * szZMode[4] = { "Opa", "Inter", "XLU", "Decal" };
360
static const char * szZSrcSel[2] = { "Pixel", "Primitive" };
361
static const char * sc_szBlClr[4] = { "In", "Mem", "Bl", "Fog" };
362
static const char * sc_szBlA1[4] = { "AIn", "AFog", "AShade", "0" };
363
static const char * sc_szBlA2[4] = { "1-A", "AMem", "1", "0" };
364
365
void DumpOtherMode()
366
{
367
uint16 blender = gRDP.otherMode.blender;
368
RDP_BlenderSetting &bl = *(RDP_BlenderSetting*)(&(blender));
369
DebuggerAppendMsg( "Other Modes");
370
DebuggerAppendMsg( "\talpha_compare:\t%s", alphacomptype[ gRDP.otherMode.alpha_compare ]);
371
DebuggerAppendMsg( "\tdepth_source:\t%s", szZSrcSel[ gRDP.otherMode.depth_source ]);
372
DebuggerAppendMsg( "\taa_en:\t\t%d", gRDP.otherMode.aa_en );
373
DebuggerAppendMsg( "\tz_cmp:\t\t%d", gRDP.otherMode.z_cmp );
374
DebuggerAppendMsg( "\tz_upd:\t\t%d", gRDP.otherMode.z_upd );
375
DebuggerAppendMsg( "\tim_rd:\t\t%d", gRDP.otherMode.im_rd );
376
DebuggerAppendMsg( "\tclr_on_cvg:\t%d", gRDP.otherMode.clr_on_cvg );
377
DebuggerAppendMsg( "\tcvg_dst:\t\t%s", szCvgDstMode[ gRDP.otherMode.cvg_dst ] );
378
DebuggerAppendMsg( "\tzmode:\t\t%s", szZMode[ gRDP.otherMode.zmode ] );
379
DebuggerAppendMsg( "\tcvg_x_alpha:\t%d", gRDP.otherMode.cvg_x_alpha );
380
DebuggerAppendMsg( "\talpha_cvg_sel:\t%d", gRDP.otherMode.alpha_cvg_sel );
381
DebuggerAppendMsg( "\tforce_bl:\t\t%d", gRDP.otherMode.force_bl );
382
DebuggerAppendMsg( "\ttex_edge:\t\t%d", gRDP.otherMode.tex_edge );
383
DebuggerAppendMsg( "\tblender:\t\t%04x - Cycle1:\t%s * %s + %s * %s\n\t\t\tCycle2:\t%s * %s + %s * %s", gRDP.otherMode.blender,
384
sc_szBlClr[bl.c1_m1a], sc_szBlA1[bl.c1_m1b], sc_szBlClr[bl.c1_m2a], sc_szBlA2[bl.c1_m2b],
385
sc_szBlClr[bl.c2_m1a], sc_szBlA1[bl.c2_m1b], sc_szBlClr[bl.c2_m2a], sc_szBlA2[bl.c2_m2b]);
386
DebuggerAppendMsg( "\tblend_mask:\t%d", gRDP.otherMode.blend_mask );
387
DebuggerAppendMsg( "\talpha_dither:\t%s", alphadithertypes[ gRDP.otherMode.alpha_dither ] );
388
DebuggerAppendMsg( "\trgb_dither:\t\t%s", rgbdithertype[ gRDP.otherMode.rgb_dither ] );
389
DebuggerAppendMsg( "\tcomb_key:\t%s", gRDP.otherMode.key_en ? "Key" : "None" );
390
DebuggerAppendMsg( "\ttext_conv:\t\t%s", convtype[ gRDP.otherMode.text_conv ] );
391
DebuggerAppendMsg( "\ttext_filt:\t\t%s", filtertype[ gRDP.otherMode.text_filt ] );
392
DebuggerAppendMsg( "\ttext_tlut:\t\t%s", textluttype[ gRDP.otherMode.text_tlut ] );
393
DebuggerAppendMsg( "\ttext_lod:\t\t%s", gRDP.otherMode.text_lod ? "Yes": "No" );
394
DebuggerAppendMsg( "\ttext_detail:\t\t%s", gRDP.otherMode.text_detail ? "Yes": "No" );
395
DebuggerAppendMsg( "\ttext_sharpen:\t\t%s", gRDP.otherMode.text_sharpen ? "Yes": "No" );
396
DebuggerAppendMsg( "\ttext_persp:\t%s", gRDP.otherMode.text_persp ? "On" : "Off" );
397
DebuggerAppendMsg( "\tcycle_type:\t%s", cycletype[ gRDP.otherMode.cycle_type ] );
398
DebuggerAppendMsg( "\tpipeline:\t\t%s", gRDP.otherMode.atomic_prim ? "1Primitive" : "NPrimitive" );
399
400
DebuggerAppendMsg("\n\nSP render flags:");
401
DebuggerAppendMsg("\tCull mode: %s%s", gRSP.bCullFront?"Cull Front":"", gRSP.bCullBack?" Cull Back":"");
402
DebuggerAppendMsg("\tShade mode: %d", gRSP.shadeMode);
403
DebuggerAppendMsg("\tFog: %s", gRSP.bFogEnabled?"enabled":"disabled");
404
DebuggerAppendMsg("\tZbuffer in SP: %s", gRSP.bZBufferEnabled?"enabled":"disabled");
405
DebuggerAppendMsg("\tLighting: %s", gRSP.bLightingEnable?"enabled":"disabled");
406
DebuggerAppendMsg("\\Number of lights: %d", gRSPnumLights);
407
DebuggerAppendMsg("\tTexture Gen: %s", gRSP.bTextureGen?"enabled":"disabled");
408
DebuggerAppendMsg("\tTexture Gen Linear: %s", (gRDP.geometryMode & G_TEXTURE_GEN_LINEAR)?"enabled":"disabled");
409
}
410
411
void DumpCachedTexture(uint32 index)
412
{
413
TxtrCacheEntry *p = gTextureManager.GetCachedTexture(index);
414
if( p != NULL )
415
{
416
char filename[80];
417
sprintf(filename,"\\Texture%d_rgb", index);
418
CRender::GetRender()->SaveTextureToFile(*(p->pTexture), filename, TXT_RGB);
419
DebuggerAppendMsg("Display cached texture #%d of %d\n", index, gTextureManager.GetNumOfCachedTexture());
420
DebuggerAppendMsg("W:%d, H:%d, RealW:%d, RealH:%d, D3DW:%d, D3DH: %d", p->ti.WidthToCreate, p->ti.HeightToCreate,
421
p->ti.WidthToLoad, p->ti.HeightToLoad, p->pTexture->m_dwCreatedTextureWidth, p->pTexture->m_dwCreatedTextureHeight);
422
DebuggerAppendMsg("ScaledS:%s, ScaledT:%s", p->pTexture->m_bScaledS?"T":"F", p->pTexture->m_bScaledT?"T":"F");
423
}
424
else
425
{
426
DebuggerAppendMsg("No cached texture at index = %d\n", index);
427
}
428
}
429
430
extern uint32 gObjTlutAddr;
431
void DumpInfo(int thingToDump)
432
{
433
switch(thingToDump)
434
{
435
case DUMP_COLORS:
436
DebuggerAppendMsg("----Colors----\nPrim Color:\t%08X\nEnv Color:\t%08X\n"
437
"Fill Color:\t%08X\nFog Color:\t%08X\n"
438
"Prim Depth:\t%f\nPrim LOD Frac:\t%08X\n",
439
GetPrimitiveColor(), GetEnvColor(), gRDP.fillColor,
440
CRender::GetRender()->GetFogColor(), GetPrimitiveDepth(), GetLODFrac());
441
break;
442
case DUMP_CUR_MUX:
443
CRender::GetRender()->m_pColorCombiner->DisplayMuxString();
444
break;
445
case DUMP_LIGHT:
446
DebuggerAppendMsg("----Light Colors----\nNumber of Lights: %d\n",GetNumLights());
447
for( uint32 i=0; i<GetNumLights()+2; i++)
448
{
449
DebuggerAppendMsg("Light %d:\t%08X, (%d,%d,%d)\n", i, gRSPn64lights[i].dwRGBA,gRSPn64lights[i].x,gRSPn64lights[i].y,gRSPn64lights[i].z );
450
}
451
break;
452
case DUMP_TEXTURE_AT:
453
{
454
}
455
break;
456
case DUMP_CUR_TEXTURE_RGBA:
457
DumpTexture(gRSP.curTile, TXT_RGBA);
458
break;
459
case DUMP_CUR_1_TEXTURE_RGBA:
460
DumpTexture((1+gRSP.curTile)%7, TXT_RGBA);
461
break;
462
case DUMP_CUR_TEXTURE_RGB:
463
DumpTexture(gRSP.curTile, TXT_RGB);
464
break;
465
case DUMP_CUR_1_TEXTURE_RGB:
466
DumpTexture((1+gRSP.curTile)%7, TXT_RGB);
467
break;
468
case DUMP_CUR_TEXTURE_TO_FILE:
469
DumpTextureToFile(0,TXT_RGB);
470
DumpTextureToFile(0,TXT_ALPHA);
471
DumpTextureToFile(0,TXT_RGBA);
472
break;
473
case DUMP_CUR_1_TEXTURE_TO_FILE:
474
DumpTextureToFile(1,TXT_RGB);
475
DumpTextureToFile(1,TXT_ALPHA);
476
DumpTextureToFile(1,TXT_RGBA);
477
break;
478
case DUMP_CUR_TEXTURE_ALPHA:
479
DumpTexture(0, TXT_ALPHA);
480
break;
481
case DUMP_CUR_1_TEXTURE_ALPHA:
482
DumpTexture(1, TXT_ALPHA);
483
break;
484
case DUMP_TLUT:
485
DumpTlut(g_wRDPTlut);
486
break;
487
case DUMP_OBJ_TLUT:
488
DumpTlut((uint16*)(g_pRDRAMu8+gObjTlutAddr));
489
break;
490
case DUMP_TILE_AT:
491
{
492
}
493
break;
494
case DUMP_VERTEXES:
495
DumpVertexArray();
496
break;
497
case DUMP_VI_REGS:
498
DumpVIRegisters();
499
break;
500
case DUMP_SIMPLE_MUX:
501
CRender::GetRender()->m_pColorCombiner->DisplaySimpleMuxString();
502
break;
503
case DUMP_OTHER_MODE:
504
DumpOtherMode();
505
break;
506
case DUMP_FRAME_BUFFER:
507
CRender::GetRender()->DrawFrameBuffer(true);
508
break;
509
case DUMP_CONTENT_AT:
510
{
511
}
512
break;
513
case DUMP_DLIST_AT:
514
{
515
}
516
break;
517
case DUMP_MATRIX_AT:
518
{
519
}
520
break;
521
case DUMP_NEXT_TEX:
522
CachedTexIndex++;
523
if( CachedTexIndex >= gTextureManager.GetNumOfCachedTexture() )
524
{
525
CachedTexIndex = 0;
526
}
527
DumpCachedTexture(CachedTexIndex);
528
break;
529
case DUMP_PREV_TEX:
530
CachedTexIndex--;
531
if( CachedTexIndex < 0 || CachedTexIndex >= gTextureManager.GetNumOfCachedTexture() )
532
CachedTexIndex = 0;
533
DumpCachedTexture(CachedTexIndex);
534
break;
535
case DUMP_CACHED_TEX:
536
DumpCachedTexture(CachedTexIndex);
537
break;
538
case DUMP_TEXBUFFER_AT:
539
{
540
}
541
break;
542
case DUMP_COMBINED_MATRIX:
543
DumpMatrix2(gRSPworldProject,"Combined Matrix");
544
break;
545
case DUMP_WORLD_TOP_MATRIX:
546
DumpMatrix2(gRSP.modelviewMtxs[gRSP.modelViewMtxTop],"World Top Matrix");
547
break;
548
case DUMP_WORLD_MATRIX_AT:
549
{
550
}
551
break;
552
case DUMP_PROJECTION_MATRIX:
553
DumpMatrix2(gRSP.projectionMtxs[gRSP.projectionMtxTop],"Projection Top Matrix");
554
break;
555
}
556
}
557
558
559
void SetLogToFile(bool log)
560
{
561
if( log )
562
{
563
if( logFp == NULL )
564
{
565
logFp = fopen("\\RiceVideo.log", "at");
566
}
567
}
568
else
569
{
570
if( logFp != NULL )
571
{
572
fclose(logFp);
573
logFp = NULL;
574
}
575
}
576
}
577
578
579
void __cdecl DebuggerAppendMsg(const char * Message, ...)
580
{
581
if( !logToScreen && !logToFile )
582
return;
583
584
char Msg[5000];
585
va_list ap;
586
587
va_start( ap, Message );
588
vsprintf( Msg, Message, ap );
589
va_end( ap );
590
591
if( Msg[strlen(Msg)-1]!='\n' ) strcat(Msg,"\n");
592
593
if( logToScreen )
594
{
595
DebugMessage(M64MSG_INFO, "Rice Debug: %s", Msg);
596
}
597
598
if( logToFile )
599
{
600
fprintf(logFp, "%s\n", Msg);
601
}
602
}
603
604
605
void DebuggerPause()
606
{
607
while( debuggerPause )
608
{
609
if( debuggerDrawRenderTexture )
610
{
611
g_pFrameBufferManager->DisplayRenderTexture(debuggerDrawRenderTextureNo);
612
debuggerDrawRenderTexture = false;
613
}
614
usleep(100 * 1000);
615
debuggerPause = false;
616
}
617
}
618
619
void __cdecl LOG_UCODE(const char* szFormat, ...)
620
{
621
if( logUcodes)
622
{
623
char Msg[400];
624
va_list va;
625
va_start(va, szFormat);
626
vsprintf( Msg, szFormat, va );
627
va_end(va);
628
DebuggerAppendMsg("%s\n", Msg);
629
}
630
}
631
632
void DumpHex(uint32 rdramAddr, int count)
633
{
634
rdramAddr &= 0xFFFFFFF0;
635
uint32 *ptr = (uint32 *)((rdramAddr&(g_dwRamSize-1))+g_pRDRAMu8);
636
637
for( int i=0; i<(count+3)/4; i++)
638
{
639
DebuggerAppendMsg("%08X: %08X, %08X, %08X, %08X\n",
640
rdramAddr+i*16, ptr[i*4], ptr[i*4+1], ptr[i*4+2], ptr[i*4+3]);
641
}
642
DebuggerAppendMsg("\n");
643
}
644
645
uint32 StrToHex(char *HexStr)
646
{
647
uint32 temp = 0;
648
649
for(uint32 k = 0; k < strlen(HexStr); k++)
650
{
651
if(HexStr[k] <= '9' && HexStr[k] >= '0')
652
{
653
temp = temp << 4;
654
temp += HexStr[k] - '0';
655
}
656
else if(HexStr[k] <= 'F' && HexStr[k] >= 'A')
657
{
658
temp = temp << 4;
659
temp += HexStr[k] - 'A' + 10;
660
}
661
else if(HexStr[k] <= 'f' && HexStr[k] >= 'a')
662
{
663
temp = temp << 4;
664
temp += HexStr[k] - 'a' + 10;
665
}
666
else
667
{
668
return(temp);
669
}
670
}
671
672
return(temp);
673
}
674
675
void DEBUGGER_PAUSE_COUNT_N(uint32 val)
676
{
677
if (eventToPause == (int)val)
678
{
679
if(debuggerPauseCount>0)
680
debuggerPauseCount--;
681
if(debuggerPauseCount==0)
682
{
683
CGraphicsContext::Get()->UpdateFrame();
684
debuggerPause = true;
685
}
686
}
687
}
688
689
void DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(uint32 val)
690
{
691
if(eventToPause == (int)val)
692
{
693
if(debuggerPauseCount>0)
694
debuggerPauseCount--;
695
if(debuggerPauseCount==0)
696
{
697
debuggerPauseCount = countToPause;
698
debuggerPause = true;
699
}
700
}
701
}
702
703
void DumpMatrix2(const Matrix &mat, const char* prompt)
704
{
705
DebuggerAppendMsg(prompt);
706
DebuggerAppendMsg(
707
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
708
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
709
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n"
710
" %#+12.5f %#+12.5f %#+12.5f %#+12.5f\n",
711
mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[0][3],
712
mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[1][3],
713
mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[2][3],
714
mat.m[3][0], mat.m[3][1], mat.m[3][2], mat.m[3][3]);
715
}
716
717
void DumpMatrix(const Matrix &mat, const char* prompt)
718
{
719
if( pauseAtNext && logMatrix )
720
{
721
DumpMatrix2(mat, prompt);
722
}
723
}
724
725
#endif
726
727
728