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