Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/Debugger.cpp
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.35// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.36//37//****************************************************************3839#include "Gfx_1.3.h"40#include "Util.h"41#include "Debugger.h"4243GLIDE64_DEBUGGER _debugger;4445#define SX(x) ((x)*rdp.scale_1024)46#define SY(x) ((x)*rdp.scale_768)4748#ifdef COLORED_DEBUGGER49#define COL_CATEGORY() grConstantColorValue(0xD288F400)50#define COL_UCC() grConstantColorValue(0xFF000000)51#define COL_CC() grConstantColorValue(0x88C3F400)52#define COL_UAC() grConstantColorValue(0xFF808000)53#define COL_AC() grConstantColorValue(0x3CEE5E00)54#define COL_TEXT() grConstantColorValue(0xFFFFFF00)55#define COL_SEL(x) grConstantColorValue((x)?0x00FF00FF:0x800000FF)56#else57#define COL_CATEGORY()58#define COL_UCC()59#define COL_CC()60#define COL_UAC()61#define COL_AC()62#define COL_TEXT()63#define COL_SEL(x)64#endif6566#define COL_GRID 0xFFFFFF806768int grid = 0;69static const char *tri_type[4] = { "TRIANGLE", "TEXRECT", "FILLRECT", "BACKGROUND" };7071//Platform-specific stuff72#ifndef WIN3273typedef struct dbgPOINT {74int x;75int y;76} POINT;77#endif78void DbgCursorPos(POINT * pt)79{80#ifdef __WINDOWS__81GetCursorPos (pt);82#else //!todo find a way to get cursor position on Unix83pt->x = pt->y = 0;84#endif85}8687//88// debug_init - initialize the debugger89//9091void debug_init ()92{93_debugger.capture = 0;94_debugger.selected = SELECTED_TRI;95_debugger.screen = NULL;96_debugger.tri_list = NULL;97_debugger.tri_last = NULL;98_debugger.tri_sel = NULL;99_debugger.tmu = 0;100101_debugger.tex_scroll = 0;102_debugger.tex_sel = 0;103104_debugger.draw_mode = 0;105}106107//108// debug_cacheviewer - views the debugger's cache109//110111void debug_cacheviewer ()112{113grCullMode (GR_CULL_DISABLE);114115int i;116for (i=0; i<2; i++)117{118grTexFilterMode (i,119(settings.filter_cache)?GR_TEXTUREFILTER_BILINEAR:GR_TEXTUREFILTER_POINT_SAMPLED,120(settings.filter_cache)?GR_TEXTUREFILTER_BILINEAR:GR_TEXTUREFILTER_POINT_SAMPLED);121grTexClampMode (i,122GR_TEXTURECLAMP_CLAMP,123GR_TEXTURECLAMP_CLAMP);124}125126switch (_debugger.draw_mode)127{128case 0:129grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,130GR_COMBINE_FACTOR_ONE,131GR_COMBINE_LOCAL_NONE,132GR_COMBINE_OTHER_TEXTURE,133FXFALSE);134grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,135GR_COMBINE_FACTOR_ONE,136GR_COMBINE_LOCAL_NONE,137GR_COMBINE_OTHER_TEXTURE,138FXFALSE);139break;140case 1:141grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,142GR_COMBINE_FACTOR_ONE,143GR_COMBINE_LOCAL_NONE,144GR_COMBINE_OTHER_TEXTURE,145FXFALSE);146grAlphaCombine (GR_COMBINE_FUNCTION_LOCAL,147GR_COMBINE_FACTOR_NONE,148GR_COMBINE_LOCAL_CONSTANT,149GR_COMBINE_OTHER_NONE,150FXFALSE);151grConstantColorValue (0xFFFFFFFF);152break;153case 2:154grColorCombine (GR_COMBINE_FUNCTION_LOCAL,155GR_COMBINE_FACTOR_NONE,156GR_COMBINE_LOCAL_CONSTANT,157GR_COMBINE_OTHER_NONE,158FXFALSE);159grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,160GR_COMBINE_FACTOR_ONE,161GR_COMBINE_LOCAL_NONE,162GR_COMBINE_OTHER_TEXTURE,163FXFALSE);164grConstantColorValue (0xFFFFFFFF);165}166167if (_debugger.tmu == 1)168{169grTexCombine (GR_TMU1,170GR_COMBINE_FUNCTION_LOCAL,171GR_COMBINE_FACTOR_NONE,172GR_COMBINE_FUNCTION_LOCAL,173GR_COMBINE_FACTOR_NONE,174FXFALSE,175FXFALSE);176177grTexCombine (GR_TMU0,178GR_COMBINE_FUNCTION_SCALE_OTHER,179GR_COMBINE_FACTOR_ONE,180GR_COMBINE_FUNCTION_SCALE_OTHER,181GR_COMBINE_FACTOR_ONE,182FXFALSE,183FXFALSE);184}185else186{187grTexCombine (GR_TMU0,188GR_COMBINE_FUNCTION_LOCAL,189GR_COMBINE_FACTOR_NONE,190GR_COMBINE_FUNCTION_LOCAL,191GR_COMBINE_FACTOR_NONE,192FXFALSE,193FXFALSE);194}195196grAlphaBlendFunction (GR_BLEND_SRC_ALPHA,197GR_BLEND_ONE_MINUS_SRC_ALPHA,198GR_BLEND_ONE,199GR_BLEND_ZERO);200201// Draw texture memory202for (i=0; i<4; i++)203{204for (wxUint32 x=0; x<16; x++)205{206wxUint32 y = i+_debugger.tex_scroll;207if (x+y*16 >= (wxUint32)rdp.n_cached[_debugger.tmu]) break;208CACHE_LUT * cache = voodoo.tex_UMA?rdp.cache[0]:rdp.cache[_debugger.tmu];209210VERTEX v[4] = {211{ SX(x*64.0f), SY(512+64.0f*i), 1, 1, 0, 0, 0, 0, {0, 0, 0, 0} },212{ SX(x*64.0f+64.0f*cache[x+y*16].scale_x), SY(512+64.0f*i), 1, 1, 255*cache[x+y*16].scale_x, 0, 0, 0, {0, 0, 0, 0} },213{ SX(x*64.0f), SY(512+64.0f*i+64.0f*cache[x+y*16].scale_y), 1, 1, 0, 255*cache[x+y*16].scale_y, 0, 0, {0, 0, 0, 0} },214{ SX(x*64.0f+64.0f*cache[x+y*16].scale_x), SY(512+64.0f*i+64.0f*cache[x+y*16].scale_y), 1, 1, 255*cache[x+y*16].scale_x, 255*cache[x+y*16].scale_y, 0, 0, {0, 0, 0, 0} }215};216for217(int i=0; i<4; i++)218{219v[i].u1 = v[i].u0;220v[i].v1 = v[i].v0;221}222223ConvertCoordsConvert (v, 4);224225grTexSource(_debugger.tmu,226voodoo.tex_min_addr[_debugger.tmu] + cache[x+y*16].tmem_addr,227GR_MIPMAPLEVELMASK_BOTH,228&cache[x+y*16].t_info);229230grDrawTriangle (&v[2], &v[1], &v[0]);231grDrawTriangle (&v[2], &v[3], &v[1]);232}233}234235}236237//238// debug_capture - does a frame capture event (for debugging)239//240241void debug_capture ()242{243wxUint32 i,j;244245if (_debugger.tri_list == NULL) goto END;246_debugger.tri_sel = _debugger.tri_list;247_debugger.selected = SELECTED_TRI;248249// Connect the list250_debugger.tri_last->pNext = _debugger.tri_list;251252while (!CheckKeyPressed(G64_VK_INSERT, 0x0001)) //INSERT253{254// Check for clicks255if (CheckKeyPressed(G64_VK_LBUTTON, 0x0001)) //LBUTTON256{257POINT pt;258DbgCursorPos(&pt);259260//int diff = settings.scr_res_y-settings.res_y;261262if (pt.y <= (int)settings.res_y)263{264int x = pt.x;265int y = pt.y;//settings.res_y - (pt.y - diff);266267TRI_INFO *start;268TRI_INFO *tri;269if (_debugger.tri_sel == NULL) tri = _debugger.tri_list, start = _debugger.tri_list;270else tri = _debugger.tri_sel->pNext, start = _debugger.tri_sel;271272// Select a triangle (start from the currently selected one)273do {274if (tri->v[0].x == tri->v[1].x &&275tri->v[0].y == tri->v[1].y)276{277tri = tri->pNext;278continue;279}280281for (i=0; i<tri->nv; i++)282{283j=i+1;284if (j==tri->nv) j=0;285286if ((y-tri->v[i].y)*(tri->v[j].x-tri->v[i].x) -287(x-tri->v[i].x)*(tri->v[j].y-tri->v[i].y) < 0)288break; // It's outside289}290291if (i==tri->nv) // all lines passed292{293_debugger.tri_sel = tri;294break;295}296297for (i=0; i<tri->nv; i++)298{299j=i+1;300if (j==tri->nv) j=0;301302if ((y-tri->v[i].y)*(tri->v[j].x-tri->v[i].x) -303(x-tri->v[i].x)*(tri->v[j].y-tri->v[i].y) > 0)304break; // It's outside305}306307if (i==tri->nv) // all lines passed308{309_debugger.tri_sel = tri;310break;311}312313tri = tri->pNext;314} while (tri != start);315}316else317{318// on a texture319_debugger.tex_sel = (((wxUint32)((pt.y-SY(512))/SY(64))+_debugger.tex_scroll)*16) +320(wxUint32)(pt.x/SX(64));321}322}323324debug_keys ();325326grBufferClear (0, 0, 0xFFFF);327328// Copy the screen capture back to the screen:329grLfbWriteRegion(GR_BUFFER_BACKBUFFER,330(wxUint32)rdp.offset_x,331(wxUint32)rdp.offset_y,332GR_LFB_SRC_FMT_565,333settings.res_x,334settings.res_y,335FXFALSE,336settings.res_x<<1,337_debugger.screen);338339// Do the cacheviewer340debug_cacheviewer ();341342// **343// 3/16/02: Moved texture viewer out of loop, remade it. Now it's simpler, and344// supports TMU1. [Dave2001]345// Original by Gugaman346347CACHE_LUT * cache = voodoo.tex_UMA?rdp.cache[0]:rdp.cache[_debugger.tmu];348if (_debugger.page == PAGE_TEX_INFO)349{350grTexSource(_debugger.tmu,351voodoo.tex_min_addr[_debugger.tmu] + cache[_debugger.tex_sel].tmem_addr,352GR_MIPMAPLEVELMASK_BOTH,353&cache[_debugger.tex_sel].t_info);354355#ifdef SHOW_FULL_TEXVIEWER356float scx = 1.0f;357float scy = 1.0f;358#else359float scx = cache[_debugger.tex_sel].scale_x;360float scy = cache[_debugger.tex_sel].scale_y;361#endif362VERTEX v[4] = {363{ SX(704.0f), SY(221.0f), 1, 1, 0, 0, 0, 0, {0, 0, 0, 0} },364{ SX(704.0f+256.0f*scx), SY(221.0f), 1, 1, 255*scx, 0, 255*scx, 0, {0, 0, 0, 0} },365{ SX(704.0f), SY(221.0f+256.0f*scy), 1, 1, 0, 255*scy, 0, 255*scy, {0, 0, 0, 0} },366{ SX(704.0f+256.0f*scx), SY(221.0f+256.0f*scy), 1, 1, 255*scx, 255*scy, 255*scx, 255*scy, {0, 0, 0, 0} }367};368ConvertCoordsConvert (v, 4);369VERTEX *varr[4] = { &v[0], &v[1], &v[2], &v[3] };370grDrawVertexArray (GR_TRIANGLE_STRIP, 4, varr);371}372373// **374375grTexFilterMode (GR_TMU0,376GR_TEXTUREFILTER_BILINEAR,377GR_TEXTUREFILTER_BILINEAR);378379grColorCombine (GR_COMBINE_FUNCTION_LOCAL,380GR_COMBINE_FACTOR_NONE,381GR_COMBINE_LOCAL_CONSTANT,382GR_COMBINE_OTHER_NONE,383FXFALSE);384385grAlphaCombine (GR_COMBINE_FUNCTION_LOCAL,386GR_COMBINE_FACTOR_NONE,387GR_COMBINE_LOCAL_CONSTANT,388GR_COMBINE_OTHER_NONE,389FXFALSE);390391grConstantColorValue (0x0000FFFF);392393VERTEX *v[8];394if (_debugger.tri_sel)395{396// Draw the outline around the selected triangle397for (i=0; i<_debugger.tri_sel->nv; i++)398{399j=i+1;400if (j>=_debugger.tri_sel->nv) j=0;401402grDrawLine (&_debugger.tri_sel->v[i], &_debugger.tri_sel->v[j]);403404v[i] = &_debugger.tri_sel->v[i];405}406}407408// and the selected texture409wxUint32 t_y = ((_debugger.tex_sel & 0xFFFFFFF0) >> 4) - _debugger.tex_scroll;410wxUint32 t_x = _debugger.tex_sel & 0xF;411VERTEX vt[4] = {412{ SX(t_x*64.0f), SY(512+64.0f*t_y), 1, 1 },413{ SX(t_x*64.0f+64.0f), SY(512+64.0f*t_y), 1, 1 },414{ SX(t_x*64.0f), SY(512+64.0f*t_y+64.0f), 1, 1 },415{ SX(t_x*64.0f+64.0f), SY(512+64.0f*t_y+64.0f), 1, 1 } };416if (t_y < 4)417{418grDrawLine (&vt[0], &vt[1]);419grDrawLine (&vt[1], &vt[3]);420grDrawLine (&vt[3], &vt[2]);421grDrawLine (&vt[2], &vt[0]);422}423424grConstantColorValue (0xFF000020);425426if (t_y < 4)427{428grDrawTriangle (&vt[2], &vt[1], &vt[0]);429grDrawTriangle (&vt[2], &vt[3], &vt[1]);430}431432if (_debugger.tri_sel)433grDrawVertexArray (GR_TRIANGLE_FAN, _debugger.tri_sel->nv, &v);434435// Draw the outline of the cacheviewer436if (_debugger.page == PAGE_TEX_INFO)437{438float scx = cache[_debugger.tex_sel].scale_x;439float scy = cache[_debugger.tex_sel].scale_y;440441// And the grid442if (grid)443{444grConstantColorValue (COL_GRID);445446float scale_y = (256.0f * scy) / (float)cache[_debugger.tex_sel].height;447for (int y=0; y<=(int)cache[_debugger.tex_sel].height; y++)448{449float y_val = SY(221.0f+y*scale_y);450VERTEX vh[2] = {451{ SX(704.0f), y_val, 1, 1 },452{ SX(704.0f+255.0f*scx), y_val, 1, 1 } };453grDrawLine (&vh[0], &vh[1]);454}455456float scale_x = (256.0f * scx) / (float)cache[_debugger.tex_sel].width;457for (int x=0; x<=(int)cache[_debugger.tex_sel].width; x++)458{459float x_val = SX(704.0f+x*scale_x);460VERTEX vv[2] = {461{ x_val, SX(221.0f), 1, 1 },462{ x_val, SX(221.0f+256.0f*scy), 1, 1 } };463grDrawLine (&vv[0], &vv[1]);464}465}466}467468grTexCombine (GR_TMU0,469GR_COMBINE_FUNCTION_LOCAL,470GR_COMBINE_FACTOR_NONE,471GR_COMBINE_FUNCTION_LOCAL,472GR_COMBINE_FACTOR_NONE,473FXFALSE,474FXFALSE);475476grColorCombine (GR_COMBINE_FUNCTION_LOCAL,477GR_COMBINE_FACTOR_NONE,478GR_COMBINE_LOCAL_CONSTANT,479GR_COMBINE_OTHER_NONE,480FXFALSE);481482grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,483GR_COMBINE_FACTOR_ONE,484GR_COMBINE_LOCAL_NONE,485GR_COMBINE_OTHER_TEXTURE,486FXFALSE);487488grConstantColorValue (0xFFFFFF00);489490// Output the information about the selected triangle491grTexSource(GR_TMU0, // Text492voodoo.tex_min_addr[_debugger.tmu]+ offset_font,493GR_MIPMAPLEVELMASK_BOTH,494&fontTex);495496static const char *cycle_mode_s[4] = { "1 cycle (0)", "2 cycle (1)", "copy (2)", "fill (3)" };497498#define OUTPUT(fmt,other) output(642,(float)i,1,fmt,other); i-=16;499#define OUTPUT1(fmt,other,other1) output(642,(float)i,1,fmt,other,other1); i-=16;500#define OUTPUT_(fmt,cc) COL_SEL(cc); x=642; output(x,(float)i,1,fmt,0); x+=8*(strlen(fmt)+1)501#define _OUTPUT(fmt,cc) COL_SEL(cc); output(x,(float)i,1,fmt,0); x+=8*(strlen(fmt)+1)502i = 740;503float x;504if (_debugger.page == PAGE_GENERAL && _debugger.tri_sel)505{506COL_CATEGORY();507OUTPUT ("GENERAL (page 1):",0);508COL_TEXT();509OUTPUT ("tri #%d", _debugger.tri_sel->tri_n);510OUTPUT ("type: %s", tri_type[_debugger.tri_sel->type]);511OUTPUT ("geom: 0x%08lx", _debugger.tri_sel->geom_mode);512OUTPUT ("othermode_h: 0x%08lx", _debugger.tri_sel->othermode_h);513OUTPUT ("othermode_l: 0x%08lx", _debugger.tri_sel->othermode_l);514OUTPUT ("flags: 0x%08lx", _debugger.tri_sel->flags);515OUTPUT ("",0);516COL_CATEGORY();517OUTPUT ("COMBINE:",0);518COL_TEXT();519OUTPUT ("cycle_mode: %s", cycle_mode_s[_debugger.tri_sel->cycle_mode]);520OUTPUT ("cycle1: 0x%08lx", _debugger.tri_sel->cycle1);521OUTPUT ("cycle2: 0x%08lx", _debugger.tri_sel->cycle2);522if (_debugger.tri_sel->uncombined & 1)523COL_UCC();524else525COL_CC();526OUTPUT ("a0: %s", Mode0[(_debugger.tri_sel->cycle1)&0x0000000F]);527OUTPUT ("b0: %s", Mode1[(_debugger.tri_sel->cycle1>>4)&0x0000000F]);528OUTPUT ("c0: %s", Mode2[(_debugger.tri_sel->cycle1>>8)&0x0000001F]);529OUTPUT ("d0: %s", Mode3[(_debugger.tri_sel->cycle1>>13)&0x00000007]);530if (_debugger.tri_sel->uncombined & 2)531COL_UAC();532else533COL_AC();534OUTPUT ("Aa0: %s", Alpha0[(_debugger.tri_sel->cycle1>>16)&0x00000007]);535OUTPUT ("Ab0: %s", Alpha1[(_debugger.tri_sel->cycle1>>19)&0x00000007]);536OUTPUT ("Ac0: %s", Alpha2[(_debugger.tri_sel->cycle1>>22)&0x00000007]);537OUTPUT ("Ad0: %s", Alpha3[(_debugger.tri_sel->cycle1>>25)&0x00000007]);538if (_debugger.tri_sel->uncombined & 1)539COL_UCC();540else541COL_CC();542OUTPUT ("a1: %s", Mode0[(_debugger.tri_sel->cycle2)&0x0000000F]);543OUTPUT ("b1: %s", Mode1[(_debugger.tri_sel->cycle2>>4)&0x0000000F]);544OUTPUT ("c1: %s", Mode2[(_debugger.tri_sel->cycle2>>8)&0x0000001F]);545OUTPUT ("d1: %s", Mode3[(_debugger.tri_sel->cycle2>>13)&0x00000007]);546if (_debugger.tri_sel->uncombined & 2)547COL_UAC();548else549COL_AC();550OUTPUT ("Aa1: %s", Alpha0[(_debugger.tri_sel->cycle2>>16)&0x00000007]);551OUTPUT ("Ab1: %s", Alpha1[(_debugger.tri_sel->cycle2>>19)&0x00000007]);552OUTPUT ("Ac1: %s", Alpha2[(_debugger.tri_sel->cycle2>>22)&0x00000007]);553OUTPUT ("Ad1: %s", Alpha3[(_debugger.tri_sel->cycle2>>25)&0x00000007]);554}555if ((_debugger.page == PAGE_TEX1 || _debugger.page == PAGE_TEX2) && _debugger.tri_sel)556{557COL_CATEGORY ();558OUTPUT1 ("TEXTURE %d (page %d):", _debugger.page-PAGE_TEX1, 2+_debugger.page-PAGE_TEX1);559COL_TEXT();560int tmu = _debugger.page - PAGE_TEX1;561OUTPUT1 ("cur cache: %d,%d", _debugger.tri_sel->t[tmu].cur_cache[tmu]&0x0F, _debugger.tri_sel->t[tmu].cur_cache[tmu]>>4);562OUTPUT ("tex_size: %d", _debugger.tri_sel->t[tmu].size);563OUTPUT ("tex_format: %d", _debugger.tri_sel->t[tmu].format);564OUTPUT ("width: %d", _debugger.tri_sel->t[tmu].width);565OUTPUT ("height: %d", _debugger.tri_sel->t[tmu].height);566OUTPUT ("palette: %d", _debugger.tri_sel->t[tmu].palette);567OUTPUT ("clamp_s: %d", _debugger.tri_sel->t[tmu].clamp_s);568OUTPUT ("clamp_t: %d", _debugger.tri_sel->t[tmu].clamp_t);569OUTPUT ("mirror_s: %d", _debugger.tri_sel->t[tmu].mirror_s);570OUTPUT ("mirror_t: %d", _debugger.tri_sel->t[tmu].mirror_t);571OUTPUT ("mask_s: %d", _debugger.tri_sel->t[tmu].mask_s);572OUTPUT ("mask_t: %d", _debugger.tri_sel->t[tmu].mask_t);573OUTPUT ("shift_s: %d", _debugger.tri_sel->t[tmu].shift_s);574OUTPUT ("shift_t: %d", _debugger.tri_sel->t[tmu].shift_t);575OUTPUT ("ul_s: %d", _debugger.tri_sel->t[tmu].ul_s);576OUTPUT ("ul_t: %d", _debugger.tri_sel->t[tmu].ul_t);577OUTPUT ("lr_s: %d", _debugger.tri_sel->t[tmu].lr_s);578OUTPUT ("lr_t: %d", _debugger.tri_sel->t[tmu].lr_t);579OUTPUT ("t_ul_s: %d", _debugger.tri_sel->t[tmu].t_ul_s);580OUTPUT ("t_ul_t: %d", _debugger.tri_sel->t[tmu].t_ul_t);581OUTPUT ("t_lr_s: %d", _debugger.tri_sel->t[tmu].t_lr_s);582OUTPUT ("t_lr_t: %d", _debugger.tri_sel->t[tmu].t_lr_t);583OUTPUT ("scale_s: %f", _debugger.tri_sel->t[tmu].scale_s);584OUTPUT ("scale_t: %f", _debugger.tri_sel->t[tmu].scale_t);585OUTPUT ("s_mode: %s", str_cm[((_debugger.tri_sel->t[tmu].clamp_s << 1) | _debugger.tri_sel->t[tmu].mirror_s)&3]);586OUTPUT ("t_mode: %s", str_cm[((_debugger.tri_sel->t[tmu].clamp_t << 1) | _debugger.tri_sel->t[tmu].mirror_t)&3]);587}588if (_debugger.page == PAGE_COLORS && _debugger.tri_sel)589{590COL_CATEGORY();591OUTPUT ("COLORS (page 4)", 0);592COL_TEXT();593OUTPUT ("fill: %08lx", _debugger.tri_sel->fill_color);594OUTPUT ("prim: %08lx", _debugger.tri_sel->prim_color);595OUTPUT ("blend: %08lx", _debugger.tri_sel->blend_color);596OUTPUT ("env: %08lx", _debugger.tri_sel->env_color);597OUTPUT ("fog: %08lx", _debugger.tri_sel->fog_color);598OUTPUT ("prim_lodmin: %d", _debugger.tri_sel->prim_lodmin);599OUTPUT ("prim_lodfrac: %d", _debugger.tri_sel->prim_lodfrac);600}601if (_debugger.page == PAGE_FBL && _debugger.tri_sel)602{603COL_CATEGORY();604OUTPUT ("BLENDER", 0);605COL_TEXT();606OUTPUT ("fbl_a0: %s", FBLa[(_debugger.tri_sel->othermode_l>>30)&0x3]);607OUTPUT ("fbl_b0: %s", FBLb[(_debugger.tri_sel->othermode_l>>26)&0x3]);608OUTPUT ("fbl_c0: %s", FBLc[(_debugger.tri_sel->othermode_l>>22)&0x3]);609OUTPUT ("fbl_d0: %s", FBLd[(_debugger.tri_sel->othermode_l>>18)&0x3]);610OUTPUT ("fbl_a1: %s", FBLa[(_debugger.tri_sel->othermode_l>>28)&0x3]);611OUTPUT ("fbl_b1: %s", FBLb[(_debugger.tri_sel->othermode_l>>24)&0x3]);612OUTPUT ("fbl_c1: %s", FBLc[(_debugger.tri_sel->othermode_l>>20)&0x3]);613OUTPUT ("fbl_d1: %s", FBLd[(_debugger.tri_sel->othermode_l>>16)&0x3]);614OUTPUT ("", 0);615OUTPUT ("fbl: %08lx", _debugger.tri_sel->othermode_l&0xFFFF0000);616OUTPUT ("fbl #1: %08lx", _debugger.tri_sel->othermode_l&0xCCCC0000);617OUTPUT ("fbl #2: %08lx", _debugger.tri_sel->othermode_l&0x33330000);618}619if (_debugger.page == PAGE_OTHERMODE_L && _debugger.tri_sel)620{621wxUint32 othermode_l = _debugger.tri_sel->othermode_l;622COL_CATEGORY ();623OUTPUT ("OTHERMODE_L: %08lx", othermode_l);624OUTPUT_ ("AC_NONE", (othermode_l & 3) == 0);625_OUTPUT ("AC_THRESHOLD", (othermode_l & 3) == 1);626_OUTPUT ("AC_DITHER", (othermode_l & 3) == 3);627i -= 16;628OUTPUT_ ("ZS_PIXEL", !(othermode_l & 4));629_OUTPUT ("ZS_PRIM", (othermode_l & 4));630i -= 32;631COL_CATEGORY ();632OUTPUT ("RENDERMODE: %08lx", othermode_l);633OUTPUT_ ("AA_EN", othermode_l & 0x08);634i -= 16;635OUTPUT_ ("Z_CMP", othermode_l & 0x10);636i -= 16;637OUTPUT_ ("Z_UPD", othermode_l & 0x20);638i -= 16;639OUTPUT_ ("IM_RD", othermode_l & 0x40);640i -= 16;641OUTPUT_ ("CLR_ON_CVG", othermode_l & 0x80);642i -= 16;643OUTPUT_ ("CVG_DST_CLAMP", (othermode_l & 0x300) == 0x000);644_OUTPUT ("CVG_DST_WRAP", (othermode_l & 0x300) == 0x100);645_OUTPUT (".._FULL", (othermode_l & 0x300) == 0x200);646_OUTPUT (".._SAVE", (othermode_l & 0x300) == 0x300);647i -= 16;648OUTPUT_ ("ZM_OPA", (othermode_l & 0xC00) == 0x000);649_OUTPUT ("ZM_INTER", (othermode_l & 0xC00) == 0x400);650_OUTPUT ("ZM_XLU", (othermode_l & 0xC00) == 0x800);651_OUTPUT ("ZM_DEC", (othermode_l & 0xC00) == 0xC00);652i -= 16;653OUTPUT_ ("CVG_X_ALPHA", othermode_l & 0x1000);654i -= 16;655OUTPUT_ ("ALPHA_CVG_SEL", othermode_l & 0x2000);656i -= 16;657OUTPUT_ ("FORCE_BL", othermode_l & 0x4000);658}659if (_debugger.page == PAGE_OTHERMODE_H && _debugger.tri_sel)660{661wxUint32 othermode_h = _debugger.tri_sel->othermode_h;662COL_CATEGORY ();663OUTPUT ("OTHERMODE_H: %08lx", othermode_h);664OUTPUT_ ("CK_NONE", (othermode_h & 0x100) == 0);665_OUTPUT ("CK_KEY", (othermode_h & 0x100) == 1);666i -= 16;667OUTPUT_ ("TC_CONV", (othermode_h & 0xE00) == 0x200);668_OUTPUT ("TC_FILTCONV", (othermode_h & 0xE00) == 0xA00);669_OUTPUT ("TC_FILT", (othermode_h & 0xE00) == 0xC00);670i -= 16;671OUTPUT_ ("TF_POINT", (othermode_h & 0x3000) == 0x0000);672_OUTPUT ("TF_AVERAGE", (othermode_h & 0x3000) == 0x3000);673_OUTPUT ("TF_BILERP", (othermode_h & 0x3000) == 0x2000);674i -= 16;675OUTPUT_ ("TT_NONE", (othermode_h & 0xC000) == 0x0000);676_OUTPUT ("TT_RGBA16", (othermode_h & 0xC000) == 0x8000);677_OUTPUT ("TT_IA16", (othermode_h & 0xC000) == 0xC000);678i -= 16;679OUTPUT_ ("TL_TILE", (othermode_h & 0x10000) == 0x00000);680_OUTPUT ("TL_LOD", (othermode_h & 0x10000) == 0x10000);681i -= 16;682OUTPUT_ ("TD_CLAMP", (othermode_h & 0x60000) == 0x00000);683_OUTPUT ("TD_SHARPEN", (othermode_h & 0x60000) == 0x20000);684_OUTPUT ("TD_DETAIL", (othermode_h & 0x60000) == 0x40000);685i -= 16;686OUTPUT_ ("TP_NONE", (othermode_h & 0x80000) == 0x00000);687_OUTPUT ("TP_PERSP", (othermode_h & 0x80000) == 0x80000);688i -= 16;689OUTPUT_ ("1CYCLE", (othermode_h & 0x300000) == 0x000000);690_OUTPUT ("2CYCLE", (othermode_h & 0x300000) == 0x100000);691_OUTPUT ("COPY", (othermode_h & 0x300000) == 0x200000);692_OUTPUT ("FILL", (othermode_h & 0x300000) == 0x300000);693i -= 16;694OUTPUT_ ("PM_1PRIM", (othermode_h & 0x400000) == 0x000000);695_OUTPUT ("PM_NPRIM", (othermode_h & 0x400000) == 0x400000);696}697if (_debugger.page == PAGE_TEXELS && _debugger.tri_sel)698{699// change these to output whatever you need, ou for triangles, or u0 for texrects700COL_TEXT();701OUTPUT ("n: %d", _debugger.tri_sel->nv);702OUTPUT ("",0);703for (j=0; j<_debugger.tri_sel->nv; j++)704{705OUTPUT1 ("v[%d].s0: %f", j, _debugger.tri_sel->v[j].ou);706OUTPUT1 ("v[%d].t0: %f", j, _debugger.tri_sel->v[j].ov);707}708OUTPUT ("",0);709for (j=0; j<_debugger.tri_sel->nv; j++)710{711OUTPUT1 ("v[%d].s1: %f", j, _debugger.tri_sel->v[j].u0);712OUTPUT1 ("v[%d].t1: %f", j, _debugger.tri_sel->v[j].v0);713}714}715if (_debugger.page == PAGE_COORDS && _debugger.tri_sel)716{717COL_TEXT();718OUTPUT ("n: %d", _debugger.tri_sel->nv);719for (j=0; j<_debugger.tri_sel->nv; j++)720{721OUTPUT1 ("v[%d].x: %f", j, _debugger.tri_sel->v[j].x);722OUTPUT1 ("v[%d].y: %f", j, _debugger.tri_sel->v[j].y);723OUTPUT1 ("v[%d].z: %f", j, _debugger.tri_sel->v[j].z);724OUTPUT1 ("v[%d].w: %f", j, _debugger.tri_sel->v[j].w);725OUTPUT1 ("v[%d].f: %f", j, 1.0f/_debugger.tri_sel->v[j].f);726OUTPUT1 ("v[%d].r: %d", j, _debugger.tri_sel->v[j].r);727OUTPUT1 ("v[%d].g: %d", j, _debugger.tri_sel->v[j].g);728OUTPUT1 ("v[%d].b: %d", j, _debugger.tri_sel->v[j].b);729OUTPUT1 ("v[%d].a: %d", j, _debugger.tri_sel->v[j].a);730}731}732if (_debugger.page == PAGE_TEX_INFO && _debugger.tex_sel < (wxUint32)rdp.n_cached[_debugger.tmu])733{734COL_CATEGORY();735OUTPUT ("CACHE (page 0)", 0);736COL_TEXT();737//OUTPUT ("t_mem: %08lx", rdp.cache[0][_debugger.tex_sel].t_mem);738//OUTPUT ("crc: %08lx", rdp.cache[0][_debugger.tex_sel].crc);739OUTPUT ("addr: %08lx", cache[_debugger.tex_sel].addr);740OUTPUT ("scale_x: %f", cache[_debugger.tex_sel].scale_x);741OUTPUT ("scale_y: %f", cache[_debugger.tex_sel].scale_y);742OUTPUT ("tmem_addr: %08lx", cache[_debugger.tex_sel].tmem_addr);743OUTPUT ("palette: %08lx", cache[_debugger.tex_sel].palette);744OUTPUT ("set_by: %08lx", cache[_debugger.tex_sel].set_by);745OUTPUT ("texrecting: %d", cache[_debugger.tex_sel].texrecting);746747OUTPUT ("mod: %08lx", cache[_debugger.tex_sel].mod);748OUTPUT ("mod_col: %08lx", cache[_debugger.tex_sel].mod_color);749OUTPUT ("mod_col1: %08lx", cache[_debugger.tex_sel].mod_color1);750i=740;751output(800,(float)i,1,"width: %d", cache[_debugger.tex_sel].width);752i-=16;753output(800,(float)i,1,"height: %d", cache[_debugger.tex_sel].height);754i-=16;755output(800,(float)i,1,"format: %d", cache[_debugger.tex_sel].format);756i-=16;757output(800,(float)i,1,"size: %d", cache[_debugger.tex_sel].size);758i-=16;759output(800,(float)i,1,"crc: %08lx", cache[_debugger.tex_sel].crc);760i-=16;761#ifdef TEXTURE_FILTER762output(800,(float)i,1,"RiceCrc: %08lx", (wxUint32)(rdp.cache[_debugger.tmu][_debugger.tex_sel].ricecrc&0xFFFFFFFF));763i-=16;764output(800,(float)i,1,"RicePalCrc: %08lx", (wxUint32)(rdp.cache[_debugger.tmu][_debugger.tex_sel].ricecrc>>32));765i-=16;766#endif767output(800,(float)i,1,"flags: %08lx", cache[_debugger.tex_sel].flags);768i-=16;769output(800,(float)i,1,"line: %d", cache[_debugger.tex_sel].line);770i-=16;771output(800,(float)i,1,"mod_factor: %08lx", cache[_debugger.tex_sel].mod_factor);772i-=32;773774output(800,(float)i,1,"lod: %s", str_lod[cache[_debugger.tex_sel].lod]);775i-=16;776output(800,(float)i,1,"aspect: %s", str_aspect[cache[_debugger.tex_sel].aspect + 3]);777778// debug_texture(_debugger.tmu, cache[_debugger.tex_sel].addr, _debugger.tex_sel);779}780781// Draw the vertex numbers782if (_debugger.tri_sel)783{784for (i=0; i<_debugger.tri_sel->nv; i++)785{786grConstantColorValue (0x000000FF);787output (_debugger.tri_sel->v[i].x+1, settings.scr_res_y-_debugger.tri_sel->v[i].y+1, 1,788"%d", i);789grConstantColorValue (0xFFFFFFFF);790output (_debugger.tri_sel->v[i].x, settings.scr_res_y-_debugger.tri_sel->v[i].y, 1,791"%d", i);792}793}794795// Draw the cursor796debug_mouse ();797798grBufferSwap (1);799}800801END:802// Release all data803delete [] _debugger.screen;804TRI_INFO *tri;805for (tri=_debugger.tri_list; tri != _debugger.tri_last;)806{807TRI_INFO *tmp = tri;808tri = tri->pNext;809delete [] tmp->v;810delete tmp;811}812delete [] tri->v;813delete tri;814815// Reset all values816_debugger.capture = 0;817_debugger.selected = SELECTED_TRI;818_debugger.screen = NULL;819_debugger.tri_list = NULL;820_debugger.tri_last = NULL;821_debugger.tri_sel = NULL;822_debugger.tex_sel = 0;823}824825//826// debug_mouse - draws the debugger mouse827//828829void debug_mouse ()830{831grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,832GR_COMBINE_FACTOR_ONE,833GR_COMBINE_LOCAL_NONE,834GR_COMBINE_OTHER_TEXTURE,835FXFALSE);836837grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,838GR_COMBINE_FACTOR_ONE,839GR_COMBINE_LOCAL_NONE,840GR_COMBINE_OTHER_TEXTURE,841FXFALSE);842843// Draw the cursor844POINT pt;845DbgCursorPos(&pt);846float cx = (float)pt.x;847float cy = (float)pt.y;848849VERTEX v[4] = {850{ cx, cy, 1, 1, 0, 0, 0, 0, {0, 0, 0, 0} },851{ cx+32, cy, 1, 1, 255, 0, 0, 0, {0, 0, 0, 0} },852{ cx, cy+32, 1, 1, 0, 255, 0, 0, {0, 0, 0, 0} },853{ cx+32, cy+32, 1, 1, 255, 255, 0, 0, {0, 0, 0, 0} }854};855856ConvertCoordsKeep (v, 4);857858grTexSource(GR_TMU0,859voodoo.tex_min_addr[GR_TMU0] + offset_cursor,860GR_MIPMAPLEVELMASK_BOTH,861&cursorTex);862863if (voodoo.num_tmu >= 3)864grTexCombine (GR_TMU2,865GR_COMBINE_FUNCTION_NONE,866GR_COMBINE_FACTOR_NONE,867GR_COMBINE_FUNCTION_NONE,868GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);869if (voodoo.num_tmu >= 2)870grTexCombine (GR_TMU1,871GR_COMBINE_FUNCTION_NONE,872GR_COMBINE_FACTOR_NONE,873GR_COMBINE_FUNCTION_NONE,874GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);875grTexCombine (GR_TMU0,876GR_COMBINE_FUNCTION_LOCAL,877GR_COMBINE_FACTOR_NONE,878GR_COMBINE_FUNCTION_LOCAL,879GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);880881grDrawTriangle (&v[0], &v[1], &v[2]);882grDrawTriangle (&v[1], &v[3], &v[2]);883}884885//886// debug_keys - receives debugger key input887//888889void debug_keys ()890{891if (CheckKeyPressed(G64_VK_RIGHT, 0x0001) && _debugger.tri_sel)892{893TRI_INFO *start = _debugger.tri_sel;894895while (_debugger.tri_sel->pNext != start)896_debugger.tri_sel = _debugger.tri_sel->pNext;897}898899if (CheckKeyPressed(G64_VK_LEFT, 0x0001) && _debugger.tri_sel)900_debugger.tri_sel = _debugger.tri_sel->pNext;901902// Check for page changes903if (CheckKeyPressed(G64_VK_1, 0x0001))904_debugger.page = PAGE_GENERAL;905if (CheckKeyPressed(G64_VK_2, 0x0001))906_debugger.page = PAGE_TEX1;907if (CheckKeyPressed(G64_VK_3, 0x0001))908_debugger.page = PAGE_TEX2;909if (CheckKeyPressed(G64_VK_4, 0x0001))910_debugger.page = PAGE_COLORS;911if (CheckKeyPressed(G64_VK_5, 0x0001))912_debugger.page = PAGE_FBL;913if (CheckKeyPressed(G64_VK_6, 0x0001))914_debugger.page = PAGE_OTHERMODE_L;915if (CheckKeyPressed(G64_VK_7, 0x0001))916_debugger.page = PAGE_OTHERMODE_H;917if (CheckKeyPressed(G64_VK_8, 0x0001))918_debugger.page = PAGE_TEXELS;919if (CheckKeyPressed(G64_VK_9, 0x0001))920_debugger.page = PAGE_COORDS;921if (CheckKeyPressed(G64_VK_0, 0x0001))922_debugger.page = PAGE_TEX_INFO;923if (CheckKeyPressed(G64_VK_Q, 0x0001))924_debugger.tmu = 0;925if (CheckKeyPressed(G64_VK_W, 0x0001))926_debugger.tmu = 1;927928if (CheckKeyPressed(G64_VK_G, 0x0001))929grid = !grid;930931// Go to texture932if (CheckKeyPressed(G64_VK_SPACE, 0x0001))933{934int tile = -1;935if (_debugger.page == PAGE_TEX2)936tile = 1;937else938tile = 0;939if (tile != -1)940{941_debugger.tmu = _debugger.tri_sel->t[tile].tmu;942_debugger.tex_sel = _debugger.tri_sel->t[tile].cur_cache[_debugger.tmu];943_debugger.tex_scroll = (_debugger.tri_sel->t[tile].cur_cache[_debugger.tmu] >> 4) - 1;944}945}946947// Go to triangle948CACHE_LUT * cache = voodoo.tex_UMA?rdp.cache[0]:rdp.cache[_debugger.tmu];949if (CheckKeyPressed(G64_VK_CONTROL, 0x0001))950{951int count = rdp.debug_n - cache[_debugger.tex_sel].uses - 1;952if (cache[_debugger.tex_sel].last_used == frame_count)953{954TRI_INFO *t = _debugger.tri_list;955while (count && t) {956t = t->pNext;957count --;958}959_debugger.tri_sel = t;960}961else962_debugger.tri_sel = NULL;963}964965if (CheckKeyPressed(G64_VK_A, 0x0001))966_debugger.draw_mode = 0; // texture & texture alpha967if (CheckKeyPressed(G64_VK_S, 0x0001))968_debugger.draw_mode = 1; // texture969if (CheckKeyPressed(G64_VK_D, 0x0001))970_debugger.draw_mode = 2; // texture alpha971972// Check for texture scrolling973if (CheckKeyPressed(G64_VK_DOWN, 0x0001))974_debugger.tex_scroll ++;975if (CheckKeyPressed(G64_VK_UP, 0x0001))976_debugger.tex_scroll --;977}978979//980// output - output debugger text981//982983void output (float x, float y, int scale, const char *fmt, ...)984{985/*986va_list ap;987va_start(ap,fmt);988vsprintf(out_buf, fmt, ap);989va_end(ap);990991wxUint8 c,r;992for (wxUint32 i=0; i<strlen(out_buf); i++)993{994c = ((out_buf[i]-32) & 0x1F) * 8;//<< 3;995r = (((out_buf[i]-32) & 0xE0) >> 5) * 16;//<< 4;996VERTEX v[4] = { { SX(x), SY(768-y), 1, 1, (float)c, r+16.0f, 0, 0, {0, 0, 0, 0} },997{ SX(x+8), SY(768-y), 1, 1, c+8.0f, r+16.0f, 0, 0, {0, 0, 0, 0} },998{ SX(x), SY(768-y-16), 1, 1, (float)c, (float)r, 0, 0, {0, 0, 0, 0} },999{ SX(x+8), SY(768-y-16), 1, 1, c+8.0f, (float)r, 0, 0, {0, 0, 0, 0} }1000};1001if (!scale)1002{1003v[0].x = x;1004v[0].y = y;1005v[1].x = x+8;1006v[1].y = y;1007v[2].x = x;1008v[2].y = y-16;1009v[3].x = x+8;1010v[3].y = y-16;1011}10121013ConvertCoordsKeep (v, 4);10141015grDrawTriangle (&v[0], &v[1], &v[2]);1016grDrawTriangle (&v[1], &v[3], &v[2]);10171018x+=8;1019}1020*/1021}102210231024