Path: blob/master/libmupen64plus/mupen64plus-video-glide64/src/Debugger.cpp
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013*4* This program is free software; you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation; either version 2 of the License, or7* 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 of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public15* Licence along with this program; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,17* Boston, MA 02110-1301, USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)23// Project started on December 29th, 200124//25// To modify Glide64:26// * 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.27// * 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.28//29// Official Glide64 development channel: #Glide64 on EFnet30//31// Original author: Dave2001 ([email protected])32// Other authors: Gonetz, Gugaman33//34//****************************************************************3536#define M64P_PLUGIN_PROTOTYPES 137#include "m64p_types.h"38#include "m64p_plugin.h"39#include "m64p_config.h"40#include "m64p_vidext.h"41#include "Util.h"42#include "Debugger.h"43#include <stdio.h>44#include "Gfx1.3.h"45#ifndef _WIN3246#include <stdarg.h>47#include <string.h>48#endif // _WIN324950DEBUGGER debug;5152const char *FBLa[] = { "G_BL_CLR_IN", "G_BL_CLR_MEM", "G_BL_CLR_BL", "G_BL_CLR_FOG" };53const char *FBLb[] = { "G_BL_A_IN", "G_BL_A_FOG", "G_BL_A_SHADE", "G_BL_0" };54const char *FBLc[] = { "G_BL_CLR_IN", "G_BL_CLR_MEM", "G_BL_CLR_BL", "G_BL_CLR_FOG"};55const char *FBLd[] = { "G_BL_1MA", "G_BL_A_MEM", "G_BL_1", "G_BL_0" };56const char *str_lod[] = { "1", "2", "4", "8", "16", "32", "64", "128", "256" };57const char *str_aspect[] = { "1x8", "1x4", "1x2", "1x1", "2x1", "4x1", "8x1" };5859#define SX(x) ((x)*rdp.scale_1024)60#define SY(x) ((x)*rdp.scale_768)6162#ifdef COLORED_DEBUGGER63#define COL_CATEGORY() grConstantColorValue(0xD288F400)64#define COL_UCC() grConstantColorValue(0xFF000000)65#define COL_CC() grConstantColorValue(0x88C3F400)66#define COL_UAC() grConstantColorValue(0xFF808000)67#define COL_AC() grConstantColorValue(0x3CEE5E00)68#define COL_TEXT() grConstantColorValue(0xFFFFFF00)69#define COL_SEL(x) grConstantColorValue((x)?0x00FF00FF:0x800000FF)70#else71#define COL_CATEGORY()72#define COL_UCC()73#define COL_CC()74#define COL_UAC()75#define COL_AC()76#define COL_TEXT()77#define COL_SEL(x)78#endif7980#define COL_GRID 0xFFFFFF808182BOOL grid = 0;8384//85// debug_init - initialize the debugger86//8788void debug_init ()89{90debug.capture = 0;91debug.selected = SELECTED_TRI;92debug.screen = NULL;93debug.tri_list = NULL;94debug.tri_last = NULL;95debug.tri_sel = NULL;96debug.tmu = 0;9798debug.tex_scroll = 0;99debug.tex_sel = 0;100101debug.draw_mode = 0;102}103104//105// debug_cacheviewer - views the debugger's cache106//107108void debug_cacheviewer ()109{110grCullMode (GR_CULL_DISABLE);111112int i;113for (i=0; i<2; i++)114{115grTexFilterMode (i,116(settings.filter_cache)?GR_TEXTUREFILTER_BILINEAR:GR_TEXTUREFILTER_POINT_SAMPLED,117(settings.filter_cache)?GR_TEXTUREFILTER_BILINEAR:GR_TEXTUREFILTER_POINT_SAMPLED);118grTexClampMode (i,119GR_TEXTURECLAMP_CLAMP,120GR_TEXTURECLAMP_CLAMP);121}122123switch (debug.draw_mode)124{125case 0:126grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,127GR_COMBINE_FACTOR_ONE,128GR_COMBINE_LOCAL_NONE,129GR_COMBINE_OTHER_TEXTURE,130FXFALSE);131grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,132GR_COMBINE_FACTOR_ONE,133GR_COMBINE_LOCAL_NONE,134GR_COMBINE_OTHER_TEXTURE,135FXFALSE);136break;137case 1:138grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,139GR_COMBINE_FACTOR_ONE,140GR_COMBINE_LOCAL_NONE,141GR_COMBINE_OTHER_TEXTURE,142FXFALSE);143grAlphaCombine (GR_COMBINE_FUNCTION_LOCAL,144GR_COMBINE_FACTOR_NONE,145GR_COMBINE_LOCAL_CONSTANT,146GR_COMBINE_OTHER_NONE,147FXFALSE);148grConstantColorValue (0xFFFFFFFF);149break;150case 2:151grColorCombine (GR_COMBINE_FUNCTION_LOCAL,152GR_COMBINE_FACTOR_NONE,153GR_COMBINE_LOCAL_CONSTANT,154GR_COMBINE_OTHER_NONE,155FXFALSE);156grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,157GR_COMBINE_FACTOR_ONE,158GR_COMBINE_LOCAL_NONE,159GR_COMBINE_OTHER_TEXTURE,160FXFALSE);161grConstantColorValue (0xFFFFFFFF);162}163164if (debug.tmu == 1)165{166grTexCombine (GR_TMU1,167GR_COMBINE_FUNCTION_LOCAL,168GR_COMBINE_FACTOR_NONE,169GR_COMBINE_FUNCTION_LOCAL,170GR_COMBINE_FACTOR_NONE,171FXFALSE,172FXFALSE);173174grTexCombine (GR_TMU0,175GR_COMBINE_FUNCTION_SCALE_OTHER,176GR_COMBINE_FACTOR_ONE,177GR_COMBINE_FUNCTION_SCALE_OTHER,178GR_COMBINE_FACTOR_ONE,179FXFALSE,180FXFALSE);181}182else183{184grTexCombine (GR_TMU0,185GR_COMBINE_FUNCTION_LOCAL,186GR_COMBINE_FACTOR_NONE,187GR_COMBINE_FUNCTION_LOCAL,188GR_COMBINE_FACTOR_NONE,189FXFALSE,190FXFALSE);191}192193grAlphaBlendFunction (GR_BLEND_SRC_ALPHA,194GR_BLEND_ONE_MINUS_SRC_ALPHA,195GR_BLEND_ONE,196GR_BLEND_ZERO);197198// Draw texture memory199for (i=0; i<4; i++)200{201for (DWORD x=0; x<16; x++)202{203DWORD y = i+debug.tex_scroll;204if (x+y*16 >= (DWORD)rdp.n_cached[debug.tmu]) break;205206VERTEX v[4] = {207{ SX(x*64.0f), SY(512+64.0f*i), 1, 1, 0, 0, 0, 0, {0, 0, 0, 0} },208{ SX(x*64.0f+64.0f*rdp.cache[debug.tmu][x+y*16].scale_x), SY(512+64.0f*i), 1, 1, 255*rdp.cache[debug.tmu][x+y*16].scale_x, 0, 0, 0, {0, 0, 0, 0} },209{ SX(x*64.0f), SY(512+64.0f*i+64.0f*rdp.cache[debug.tmu][x+y*16].scale_y), 1, 1, 0, 255*rdp.cache[debug.tmu][x+y*16].scale_y, 0, 0, {0, 0, 0, 0} },210{ SX(x*64.0f+64.0f*rdp.cache[debug.tmu][x+y*16].scale_x), SY(512+64.0f*i+64.0f*rdp.cache[debug.tmu][x+y*16].scale_y), 1, 1, 255*rdp.cache[debug.tmu][x+y*16].scale_x, 255*rdp.cache[debug.tmu][x+y*16].scale_y, 0, 0, {0, 0, 0, 0} } };211for (int i=0; i<4; i++)212{213v[i].u1 = v[i].u0;214v[i].v1 = v[i].v0;215}216217ConvertCoordsConvert (v, 4);218219grTexSource(debug.tmu,220grTexMinAddress(debug.tmu) + rdp.cache[debug.tmu][x+y*16].tmem_addr,221GR_MIPMAPLEVELMASK_BOTH,222&rdp.cache[debug.tmu][x+y*16].t_info);223224grDrawTriangle (&v[2], &v[1], &v[0]);225grDrawTriangle (&v[2], &v[3], &v[1]);226}227}228229/* for (i=0; i<4; i++)230{231for (DWORD x=0; x<16; x++)232{233DWORD y = i+debug.tex_scroll;234if (x+y*16 >= (DWORD)rdp.n_cached[debug.tmu]) break;235236VERTEX v[4] = {237{ SX(x*64.0f), SY(768-64.0f*i), 1, 1, 0, 0, 0, 0, 0, 0, 0 },238{ SX(x*64.0f+64.0f), SY(768-64.0f*i), 1, 1, 255, 0, 0, 0, 0, 0, 0 },239{ SX(x*64.0f), SY(768-64.0f*i-64.0f), 1, 1, 0, 255, 0, 0, 0, 0, 0 },240{ SX(x*64.0f+64.0f), SY(768-64.0f*i-64.0f), 1, 1, 255, 255, 0, 0, 0, 0, 0 } };241for (int i=0; i<4; i++)242{243v[i].u1 = v[i].u0;244v[i].v1 = v[i].v0;245}246247ConvertCoordsConvert (v, 4);248249grTexSource(debug.tmu,250grTexMinAddress(debug.tmu) + rdp.cache[debug.tmu][x+y*16].tmem_addr,251GR_MIPMAPLEVELMASK_BOTH,252&rdp.cache[debug.tmu][x+y*16].t_info);253254grDrawTriangle (&v[2], &v[1], &v[0]);255grDrawTriangle (&v[2], &v[3], &v[1]);256}257}*/258}259260//261// debug_capture - does a frame capture event (for debugging)262//263#ifdef _WIN32264void debug_capture ()265{266DWORD i,j;267268if (debug.tri_list == NULL) goto END;269debug.tri_sel = debug.tri_list;270debug.selected = SELECTED_TRI;271272// Connect the list273debug.tri_last->pNext = debug.tri_list;274275while (!(GetAsyncKeyState(VK_INSERT) & 0x0001))276{277// Check for clicks278if (GetAsyncKeyState(GetSystemMetrics(SM_SWAPBUTTON)?VK_RBUTTON:VK_LBUTTON) & 0x0001)279{280POINT pt;281GetCursorPos (&pt);282283//int diff = settings.scr_res_y-settings.res_y;284285if (pt.y <= (int)settings.res_y)286{287int x = pt.x;288int y = pt.y;//settings.res_y - (pt.y - diff);289290TRI_INFO *start;291TRI_INFO *tri;292if (debug.tri_sel == NULL) tri = debug.tri_list, start = debug.tri_list;293else tri = debug.tri_sel->pNext, start = debug.tri_sel;294295// Select a triangle (start from the currently selected one)296do {297if (tri->v[0].x == tri->v[1].x &&298tri->v[0].y == tri->v[1].y)299{300tri = tri->pNext;301continue;302}303304for (i=0; i<tri->nv; i++)305{306j=i+1;307if (j==tri->nv) j=0;308309if ((y-tri->v[i].y)*(tri->v[j].x-tri->v[i].x) -310(x-tri->v[i].x)*(tri->v[j].y-tri->v[i].y) < 0)311break; // It's outside312}313314if (i==tri->nv) // all lines passed315{316debug.tri_sel = tri;317break;318}319320for (i=0; i<tri->nv; i++)321{322j=i+1;323if (j==tri->nv) j=0;324325if ((y-tri->v[i].y)*(tri->v[j].x-tri->v[i].x) -326(x-tri->v[i].x)*(tri->v[j].y-tri->v[i].y) > 0)327break; // It's outside328}329330if (i==tri->nv) // all lines passed331{332debug.tri_sel = tri;333break;334}335336tri = tri->pNext;337} while (tri != start);338}339else340{341// on a texture342debug.tex_sel = (((DWORD)((pt.y-SY(512))/SY(64))+debug.tex_scroll)*16) +343(DWORD)(pt.x/SX(64));344}345}346347debug_keys ();348349grBufferClear (0, 0, 0xFFFF);350351// Copy the screen capture back to the screen:352// Lock the backbuffer353GrLfbInfo_t info;354while (!grLfbLock (GR_LFB_WRITE_ONLY,355GR_BUFFER_BACKBUFFER,356GR_LFBWRITEMODE_565,357GR_ORIGIN_UPPER_LEFT,358FXFALSE,359&info));360361DWORD offset_src=0/*(settings.scr_res_y-settings.res_y)*info.strideInBytes*/, offset_dst=0;362363// Copy the screen364for (DWORD y=0; y<settings.res_y; y++)365{366memcpy ((BYTE*)info.lfbPtr + offset_src, debug.screen + offset_dst, settings.res_x << 1);367offset_dst += settings.res_x << 1;368offset_src += info.strideInBytes;369}370371// Unlock the backbuffer372grLfbUnlock (GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER);373374// Do the cacheviewer375debug_cacheviewer ();376377// **378// 3/16/02: Moved texture viewer out of loop, remade it. Now it's simpler, and379// supports TMU1. [Dave2001]380// Original by Gugaman381382if (debug.page == PAGE_TEX_INFO)383{384grTexSource(debug.tmu,385grTexMinAddress(debug.tmu) + rdp.cache[debug.tmu][debug.tex_sel].tmem_addr,386GR_MIPMAPLEVELMASK_BOTH,387&rdp.cache[debug.tmu][debug.tex_sel].t_info);388389#ifdef SHOW_FULL_TEXVIEWER390float scx = 1.0f;391float scy = 1.0f;392#else393float scx = rdp.cache[debug.tmu][debug.tex_sel].scale_x;394float scy = rdp.cache[debug.tmu][debug.tex_sel].scale_y;395#endif396VERTEX v[4] = {397{ SX(704.0f), SY(221.0f), 1, 1, 0, 0, 0, 0, 0, 0, 0 },398{ SX(704.0f+256.0f*scx), SY(221.0f), 1, 1, 255*scx, 0, 255*scx, 0, 0, 0, 0 },399{ SX(704.0f), SY(221.0f+256.0f*scy), 1, 1, 0, 255*scy, 0, 255*scy, 0, 0, 0 },400{ 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 } };401ConvertCoordsConvert (v, 4);402VERTEX *varr[4] = { &v[0], &v[1], &v[2], &v[3] };403grDrawVertexArray (GR_TRIANGLE_STRIP, 4, varr);404}405406// **407408grTexFilterMode (GR_TMU0,409GR_TEXTUREFILTER_BILINEAR,410GR_TEXTUREFILTER_BILINEAR);411412grColorCombine (GR_COMBINE_FUNCTION_LOCAL,413GR_COMBINE_FACTOR_NONE,414GR_COMBINE_LOCAL_CONSTANT,415GR_COMBINE_OTHER_NONE,416FXFALSE);417418grAlphaCombine (GR_COMBINE_FUNCTION_LOCAL,419GR_COMBINE_FACTOR_NONE,420GR_COMBINE_LOCAL_CONSTANT,421GR_COMBINE_OTHER_NONE,422FXFALSE);423424grConstantColorValue (0x0000FFFF);425426VERTEX *v[8];427if (debug.tri_sel)428{429// Draw the outline around the selected triangle430for (i=0; i<debug.tri_sel->nv; i++)431{432j=i+1;433if (j>=debug.tri_sel->nv) j=0;434435grDrawLine (&debug.tri_sel->v[i], &debug.tri_sel->v[j]);436437v[i] = &debug.tri_sel->v[i];438}439}440441// and the selected texture442DWORD t_y = ((debug.tex_sel & 0xFFFFFFF0) >> 4) - debug.tex_scroll;443DWORD t_x = debug.tex_sel & 0xF;444VERTEX vt[4] = {445{ SX(t_x*64.0f), SY(512+64.0f*t_y), 1, 1 },446{ SX(t_x*64.0f+64.0f), SY(512+64.0f*t_y), 1, 1 },447{ SX(t_x*64.0f), SY(512+64.0f*t_y+64.0f), 1, 1 },448{ SX(t_x*64.0f+64.0f), SY(512+64.0f*t_y+64.0f), 1, 1 } };449if (t_y < 4)450{451grDrawLine (&vt[0], &vt[1]);452grDrawLine (&vt[1], &vt[3]);453grDrawLine (&vt[3], &vt[2]);454grDrawLine (&vt[2], &vt[0]);455}456457grConstantColorValue (0xFF000020);458459if (t_y < 4)460{461grDrawTriangle (&vt[2], &vt[1], &vt[0]);462grDrawTriangle (&vt[2], &vt[3], &vt[1]);463}464465if (debug.tri_sel)466grDrawVertexArray (GR_TRIANGLE_FAN, debug.tri_sel->nv, &v);467468// Draw the outline of the cacheviewer469if (debug.page == PAGE_TEX_INFO)470{471/*grConstantColorValue (0xFF0000FF);472float scx = rdp.cache[debug.tmu][debug.tex_sel].scale_x;473float scy = rdp.cache[debug.tmu][debug.tex_sel].scale_y;474VERTEX v[4] = {475{ SX(704.0f), SY(271.0f), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },476{ SX(704.0f+256.0f*scx), SY(271.0f), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },477{ SX(704.0f), SY(271.0f-256.0f*scy), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },478{ SX(704.0f+256.0f*scx), SY(271.0f-256.0f*scy), 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };479VERTEX *varr[5] = { &v[0], &v[1], &v[3], &v[2], &v[0] };480grDrawVertexArray (GR_LINE_STRIP, 5, varr);*/481482float scx = rdp.cache[debug.tmu][debug.tex_sel].scale_x;483float scy = rdp.cache[debug.tmu][debug.tex_sel].scale_y;484485// And the grid486if (grid)487{488grConstantColorValue (COL_GRID);489490float scale_y = (256.0f * scy) / (float)rdp.cache[debug.tmu][debug.tex_sel].height;491for (int y=0; y<=(int)rdp.cache[debug.tmu][debug.tex_sel].height; y++)492{493float y_val = SY(221.0f+y*scale_y);494VERTEX vh[2] = {495{ SX(704.0f), y_val, 1, 1 },496{ SX(704.0f+255.0f*scx), y_val, 1, 1 } };497grDrawLine (&vh[0], &vh[1]);498}499500float scale_x = (256.0f * scx) / (float)rdp.cache[debug.tmu][debug.tex_sel].width;501for (int x=0; x<=(int)rdp.cache[debug.tmu][debug.tex_sel].width; x++)502{503float x_val = SX(704.0f+x*scale_x);504VERTEX vv[2] = {505{ x_val, SX(221.0f), 1, 1 },506{ x_val, SX(221.0f+256.0f*scy), 1, 1 } };507grDrawLine (&vv[0], &vv[1]);508}509}510}511512grTexCombine (GR_TMU0,513GR_COMBINE_FUNCTION_LOCAL,514GR_COMBINE_FACTOR_NONE,515GR_COMBINE_FUNCTION_LOCAL,516GR_COMBINE_FACTOR_NONE,517FXFALSE,518FXFALSE);519520grColorCombine (GR_COMBINE_FUNCTION_LOCAL,521GR_COMBINE_FACTOR_NONE,522GR_COMBINE_LOCAL_CONSTANT,523GR_COMBINE_OTHER_NONE,524FXFALSE);525526grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,527GR_COMBINE_FACTOR_ONE,528GR_COMBINE_LOCAL_NONE,529GR_COMBINE_OTHER_TEXTURE,530FXFALSE);531532grConstantColorValue (0xFFFFFF00);533534// Output the information about the selected triangle535grTexSource(GR_TMU0, // Text536grTexMinAddress(debug.tmu)+ offset_font,537GR_MIPMAPLEVELMASK_BOTH,538&fontTex);539540static char *cycle_mode_s[4] = { "1 cycle (0)", "2 cycle (1)", "copy (2)", "fill (3)" };541542#define OUTPUT(fmt,other) output(642,(float)i,1,fmt,other); i-=16;543#define OUTPUT1(fmt,other,other1) output(642,(float)i,1,fmt,other,other1); i-=16;544#define OUTPUT_(fmt,cc) COL_SEL(cc); x=642; output(x,(float)i,1,fmt,0); x+=8*(strlen(fmt)+1)545#define _OUTPUT(fmt,cc) COL_SEL(cc); output(x,(float)i,1,fmt,0); x+=8*(strlen(fmt)+1)546i = 740;547float x;548if (debug.page == PAGE_GENERAL && debug.tri_sel)549{550COL_CATEGORY();551OUTPUT ("GENERAL (page 1):",0);552COL_TEXT();553OUTPUT ("tri #%d", debug.tri_sel->tri_n);554OUTPUT ("type: %s", tri_type[debug.tri_sel->type]);555OUTPUT ("geom: 0x%08lx", debug.tri_sel->geom_mode);556OUTPUT ("othermode_h: 0x%08lx", debug.tri_sel->othermode_h);557OUTPUT ("othermode_l: 0x%08lx", debug.tri_sel->othermode_l);558OUTPUT ("flags: 0x%08lx", debug.tri_sel->flags);559OUTPUT ("",0);560COL_CATEGORY();561OUTPUT ("COMBINE:",0);562COL_TEXT();563OUTPUT ("cycle_mode: %s", cycle_mode_s[debug.tri_sel->cycle_mode]);564OUTPUT ("cycle1: 0x%08lx", debug.tri_sel->cycle1);565OUTPUT ("cycle2: 0x%08lx", debug.tri_sel->cycle2);566if (debug.tri_sel->uncombined & 1)567COL_UCC();568else569COL_CC();570OUTPUT ("a0: %s", Mode0[(debug.tri_sel->cycle1)&0x0000000F]);571OUTPUT ("b0: %s", Mode1[(debug.tri_sel->cycle1>>4)&0x0000000F]);572OUTPUT ("c0: %s", Mode2[(debug.tri_sel->cycle1>>8)&0x0000001F]);573OUTPUT ("d0: %s", Mode3[(debug.tri_sel->cycle1>>13)&0x00000007]);574if (debug.tri_sel->uncombined & 2)575COL_UAC();576else577COL_AC();578OUTPUT ("Aa0: %s", Alpha0[(debug.tri_sel->cycle1>>16)&0x00000007]);579OUTPUT ("Ab0: %s", Alpha1[(debug.tri_sel->cycle1>>19)&0x00000007]);580OUTPUT ("Ac0: %s", Alpha2[(debug.tri_sel->cycle1>>22)&0x00000007]);581OUTPUT ("Ad0: %s", Alpha3[(debug.tri_sel->cycle1>>25)&0x00000007]);582if (debug.tri_sel->uncombined & 1)583COL_UCC();584else585COL_CC();586OUTPUT ("a1: %s", Mode0[(debug.tri_sel->cycle2)&0x0000000F]);587OUTPUT ("b1: %s", Mode1[(debug.tri_sel->cycle2>>4)&0x0000000F]);588OUTPUT ("c1: %s", Mode2[(debug.tri_sel->cycle2>>8)&0x0000001F]);589OUTPUT ("d1: %s", Mode3[(debug.tri_sel->cycle2>>13)&0x00000007]);590if (debug.tri_sel->uncombined & 2)591COL_UAC();592else593COL_AC();594OUTPUT ("Aa1: %s", Alpha0[(debug.tri_sel->cycle2>>16)&0x00000007]);595OUTPUT ("Ab1: %s", Alpha1[(debug.tri_sel->cycle2>>19)&0x00000007]);596OUTPUT ("Ac1: %s", Alpha2[(debug.tri_sel->cycle2>>22)&0x00000007]);597OUTPUT ("Ad1: %s", Alpha3[(debug.tri_sel->cycle2>>25)&0x00000007]);598}599if ((debug.page == PAGE_TEX1 || debug.page == PAGE_TEX2) && debug.tri_sel)600{601COL_CATEGORY ();602OUTPUT1 ("TEXTURE %d (page %d):", debug.page-PAGE_TEX1, 2+debug.page-PAGE_TEX1);603COL_TEXT();604int tmu = debug.page - PAGE_TEX1;605OUTPUT1 ("cur cache: %d,%d", debug.tri_sel->t[tmu].cur_cache[tmu]&0x0F, debug.tri_sel->t[tmu].cur_cache[tmu]>>4);606OUTPUT ("tex_size: %d", debug.tri_sel->t[tmu].size);607OUTPUT ("tex_format: %d", debug.tri_sel->t[tmu].format);608OUTPUT ("width: %d", debug.tri_sel->t[tmu].width);609OUTPUT ("height: %d", debug.tri_sel->t[tmu].height);610OUTPUT ("palette: %d", debug.tri_sel->t[tmu].palette);611OUTPUT ("clamp_s: %d", debug.tri_sel->t[tmu].clamp_s);612OUTPUT ("clamp_t: %d", debug.tri_sel->t[tmu].clamp_t);613OUTPUT ("mirror_s: %d", debug.tri_sel->t[tmu].mirror_s);614OUTPUT ("mirror_t: %d", debug.tri_sel->t[tmu].mirror_t);615OUTPUT ("mask_s: %d", debug.tri_sel->t[tmu].mask_s);616OUTPUT ("mask_t: %d", debug.tri_sel->t[tmu].mask_t);617OUTPUT ("shift_s: %d", debug.tri_sel->t[tmu].shift_s);618OUTPUT ("shift_t: %d", debug.tri_sel->t[tmu].shift_t);619OUTPUT ("ul_s: %d", debug.tri_sel->t[tmu].ul_s);620OUTPUT ("ul_t: %d", debug.tri_sel->t[tmu].ul_t);621OUTPUT ("lr_s: %d", debug.tri_sel->t[tmu].lr_s);622OUTPUT ("lr_t: %d", debug.tri_sel->t[tmu].lr_t);623OUTPUT ("t_ul_s: %d", debug.tri_sel->t[tmu].t_ul_s);624OUTPUT ("t_ul_t: %d", debug.tri_sel->t[tmu].t_ul_t);625OUTPUT ("t_lr_s: %d", debug.tri_sel->t[tmu].t_lr_s);626OUTPUT ("t_lr_t: %d", debug.tri_sel->t[tmu].t_lr_t);627OUTPUT ("scale_s: %f", debug.tri_sel->t[tmu].scale_s);628OUTPUT ("scale_t: %f", debug.tri_sel->t[tmu].scale_t);629OUTPUT ("s_mode: %s", str_cm[((debug.tri_sel->t[tmu].clamp_s << 1) | debug.tri_sel->t[tmu].mirror_s)&3]);630OUTPUT ("t_mode: %s", str_cm[((debug.tri_sel->t[tmu].clamp_t << 1) | debug.tri_sel->t[tmu].mirror_t)&3]);631}632if (debug.page == PAGE_COLORS && debug.tri_sel)633{634COL_CATEGORY();635OUTPUT ("COLORS (page 4)", 0);636COL_TEXT();637OUTPUT ("fill: %08lx", debug.tri_sel->fill_color);638OUTPUT ("prim: %08lx", debug.tri_sel->prim_color);639OUTPUT ("blend: %08lx", debug.tri_sel->blend_color);640OUTPUT ("env: %08lx", debug.tri_sel->env_color);641OUTPUT ("fog: %08lx", debug.tri_sel->fog_color);642OUTPUT ("prim_lodmin: %d", debug.tri_sel->prim_lodmin);643OUTPUT ("prim_lodfrac: %d", debug.tri_sel->prim_lodfrac);644}645if (debug.page == PAGE_FBL && debug.tri_sel)646{647COL_CATEGORY();648OUTPUT ("BLENDER", 0);649COL_TEXT();650OUTPUT ("fbl_a0: %s", FBLa[(debug.tri_sel->othermode_l>>30)&0x3]);651OUTPUT ("fbl_b0: %s", FBLb[(debug.tri_sel->othermode_l>>26)&0x3]);652OUTPUT ("fbl_c0: %s", FBLc[(debug.tri_sel->othermode_l>>22)&0x3]);653OUTPUT ("fbl_d0: %s", FBLd[(debug.tri_sel->othermode_l>>18)&0x3]);654OUTPUT ("fbl_a1: %s", FBLa[(debug.tri_sel->othermode_l>>28)&0x3]);655OUTPUT ("fbl_b1: %s", FBLb[(debug.tri_sel->othermode_l>>24)&0x3]);656OUTPUT ("fbl_c1: %s", FBLc[(debug.tri_sel->othermode_l>>20)&0x3]);657OUTPUT ("fbl_d1: %s", FBLd[(debug.tri_sel->othermode_l>>16)&0x3]);658OUTPUT ("", 0);659OUTPUT ("fbl: %08lx", debug.tri_sel->othermode_l&0xFFFF0000);660OUTPUT ("fbl #1: %08lx", debug.tri_sel->othermode_l&0xCCCC0000);661OUTPUT ("fbl #2: %08lx", debug.tri_sel->othermode_l&0x33330000);662}663if (debug.page == PAGE_OTHERMODE_L && debug.tri_sel)664{665DWORD othermode_l = debug.tri_sel->othermode_l;666COL_CATEGORY ();667OUTPUT ("OTHERMODE_L: %08lx", othermode_l);668OUTPUT_ ("AC_NONE", (othermode_l & 3) == 0);669_OUTPUT ("AC_THRESHOLD", (othermode_l & 3) == 1);670_OUTPUT ("AC_DITHER", (othermode_l & 3) == 3);671i -= 16;672OUTPUT_ ("ZS_PIXEL", !(othermode_l & 4));673_OUTPUT ("ZS_PRIM", (othermode_l & 4));674i -= 32;675COL_CATEGORY ();676OUTPUT ("RENDERMODE: %08lx", othermode_l);677OUTPUT_ ("AA_EN", othermode_l & 0x08);678i -= 16;679OUTPUT_ ("Z_CMP", othermode_l & 0x10);680i -= 16;681OUTPUT_ ("Z_UPD", othermode_l & 0x20);682i -= 16;683OUTPUT_ ("IM_RD", othermode_l & 0x40);684i -= 16;685OUTPUT_ ("CLR_ON_CVG", othermode_l & 0x80);686i -= 16;687OUTPUT_ ("CVG_DST_CLAMP", (othermode_l & 0x300) == 0x000);688_OUTPUT ("CVG_DST_WRAP", (othermode_l & 0x300) == 0x100);689_OUTPUT (".._FULL", (othermode_l & 0x300) == 0x200);690_OUTPUT (".._SAVE", (othermode_l & 0x300) == 0x300);691i -= 16;692OUTPUT_ ("ZM_OPA", (othermode_l & 0xC00) == 0x000);693_OUTPUT ("ZM_INTER", (othermode_l & 0xC00) == 0x400);694_OUTPUT ("ZM_XLU", (othermode_l & 0xC00) == 0x800);695_OUTPUT ("ZM_DEC", (othermode_l & 0xC00) == 0xC00);696i -= 16;697OUTPUT_ ("CVG_X_ALPHA", othermode_l & 0x1000);698i -= 16;699OUTPUT_ ("ALPHA_CVG_SEL", othermode_l & 0x2000);700i -= 16;701OUTPUT_ ("FORCE_BL", othermode_l & 0x4000);702}703if (debug.page == PAGE_OTHERMODE_H && debug.tri_sel)704{705DWORD othermode_h = debug.tri_sel->othermode_h;706COL_CATEGORY ();707OUTPUT ("OTHERMODE_H: %08lx", othermode_h);708OUTPUT_ ("CK_NONE", (othermode_h & 0x100) == 0);709_OUTPUT ("CK_KEY", (othermode_h & 0x100) == 1);710i -= 16;711OUTPUT_ ("TC_CONV", (othermode_h & 0xE00) == 0x200);712_OUTPUT ("TC_FILTCONV", (othermode_h & 0xE00) == 0xA00);713_OUTPUT ("TC_FILT", (othermode_h & 0xE00) == 0xC00);714i -= 16;715OUTPUT_ ("TF_POINT", (othermode_h & 0x3000) == 0x0000);716_OUTPUT ("TF_AVERAGE", (othermode_h & 0x3000) == 0x3000);717_OUTPUT ("TF_BILERP", (othermode_h & 0x3000) == 0x2000);718i -= 16;719OUTPUT_ ("TT_NONE", (othermode_h & 0xC000) == 0x0000);720_OUTPUT ("TT_RGBA16", (othermode_h & 0xC000) == 0x8000);721_OUTPUT ("TT_IA16", (othermode_h & 0xC000) == 0xC000);722i -= 16;723OUTPUT_ ("TL_TILE", (othermode_h & 0x10000) == 0x00000);724_OUTPUT ("TL_LOD", (othermode_h & 0x10000) == 0x10000);725i -= 16;726OUTPUT_ ("TD_CLAMP", (othermode_h & 0x60000) == 0x00000);727_OUTPUT ("TD_SHARPEN", (othermode_h & 0x60000) == 0x20000);728_OUTPUT ("TD_DETAIL", (othermode_h & 0x60000) == 0x40000);729i -= 16;730OUTPUT_ ("TP_NONE", (othermode_h & 0x80000) == 0x00000);731_OUTPUT ("TP_PERSP", (othermode_h & 0x80000) == 0x80000);732i -= 16;733OUTPUT_ ("1CYCLE", (othermode_h & 0x300000) == 0x000000);734_OUTPUT ("2CYCLE", (othermode_h & 0x300000) == 0x100000);735_OUTPUT ("COPY", (othermode_h & 0x300000) == 0x200000);736_OUTPUT ("FILL", (othermode_h & 0x300000) == 0x300000);737i -= 16;738OUTPUT_ ("PM_1PRIM", (othermode_h & 0x400000) == 0x000000);739_OUTPUT ("PM_NPRIM", (othermode_h & 0x400000) == 0x400000);740}741if (debug.page == PAGE_TEXELS && debug.tri_sel)742{743// change these to output whatever you need, ou for triangles, or u0 for texrects744COL_TEXT();745OUTPUT ("n: %d", debug.tri_sel->nv);746OUTPUT ("",0);747for (j=0; j<debug.tri_sel->nv; j++)748{749OUTPUT1 ("v[%d].s0: %f", j, debug.tri_sel->v[j].ou);750OUTPUT1 ("v[%d].t0: %f", j, debug.tri_sel->v[j].ov);751}752OUTPUT ("",0);753for (j=0; j<debug.tri_sel->nv; j++)754{755OUTPUT1 ("v[%d].s1: %f", j, debug.tri_sel->v[j].u0);756OUTPUT1 ("v[%d].t1: %f", j, debug.tri_sel->v[j].v0);757}758}759if (debug.page == PAGE_COORDS && debug.tri_sel)760{761COL_TEXT();762OUTPUT ("n: %d", debug.tri_sel->nv);763for (j=0; j<debug.tri_sel->nv; j++)764{765OUTPUT1 ("v[%d].x: %f", j, debug.tri_sel->v[j].x);766OUTPUT1 ("v[%d].y: %f", j, debug.tri_sel->v[j].y);767OUTPUT1 ("v[%d].z: %f", j, debug.tri_sel->v[j].z);768OUTPUT1 ("v[%d].w: %f", j, debug.tri_sel->v[j].w);769OUTPUT1 ("v[%d].f: %f", j, 1.0f/debug.tri_sel->v[j].f);770OUTPUT1 ("v[%d].r: %d", j, debug.tri_sel->v[j].r);771OUTPUT1 ("v[%d].g: %d", j, debug.tri_sel->v[j].g);772OUTPUT1 ("v[%d].b: %d", j, debug.tri_sel->v[j].b);773OUTPUT1 ("v[%d].a: %d", j, debug.tri_sel->v[j].a);774}775}776if (debug.page == PAGE_TEX_INFO && debug.tex_sel < (DWORD)rdp.n_cached[debug.tmu])777{778COL_CATEGORY();779OUTPUT ("CACHE (page 0)", 0);780COL_TEXT();781//OUTPUT ("t_mem: %08lx", rdp.cache[0][debug.tex_sel].t_mem);782//OUTPUT ("crc: %08lx", rdp.cache[0][debug.tex_sel].crc);783OUTPUT ("addr: %08lx", rdp.cache[debug.tmu][debug.tex_sel].addr);784OUTPUT ("scale_x: %f", rdp.cache[debug.tmu][debug.tex_sel].scale_x);785OUTPUT ("scale_y: %f", rdp.cache[debug.tmu][debug.tex_sel].scale_y);786OUTPUT ("tmem_addr: %08lx", rdp.cache[debug.tmu][debug.tex_sel].tmem_addr);787OUTPUT ("palette: %08lx", rdp.cache[debug.tmu][debug.tex_sel].palette);788OUTPUT ("set_by: %08lx", rdp.cache[debug.tmu][debug.tex_sel].set_by);789OUTPUT ("texrecting: %d", rdp.cache[debug.tmu][debug.tex_sel].texrecting);790791OUTPUT ("mod: %08lx", rdp.cache[debug.tmu][debug.tex_sel].mod);792OUTPUT ("mod_col: %08lx", rdp.cache[debug.tmu][debug.tex_sel].mod_color);793OUTPUT ("mod_col1: %08lx", rdp.cache[debug.tmu][debug.tex_sel].mod_color1);794i=740;795output(800,(float)i,1,"width: %d", rdp.cache[debug.tmu][debug.tex_sel].width);796i-=16;797output(800,(float)i,1,"height: %d", rdp.cache[debug.tmu][debug.tex_sel].height);798i-=16;799output(800,(float)i,1,"format: %d", rdp.cache[debug.tmu][debug.tex_sel].format);800i-=16;801output(800,(float)i,1,"size: %d", rdp.cache[debug.tmu][debug.tex_sel].size);802i-=16;803output(800,(float)i,1,"crc: %08lx", rdp.cache[debug.tmu][debug.tex_sel].crc);804i-=16;805output(800,(float)i,1,"line: %d", rdp.cache[debug.tmu][debug.tex_sel].line);806i-=16;807output(800,(float)i,1,"mod_factor: %08lx", rdp.cache[debug.tmu][debug.tex_sel].mod_factor);808i-=32;809810output(800,(float)i,1,"lod: %s", str_lod[rdp.cache[debug.tmu][debug.tex_sel].lod]);811i-=16;812output(800,(float)i,1,"aspect: %s", str_aspect[rdp.cache[debug.tmu][debug.tex_sel].aspect + 3]);813814// debug_texture(debug.tmu, rdp.cache[debug.tmu][debug.tex_sel].addr, debug.tex_sel);815}816817// Draw the vertex numbers818if (debug.tri_sel)819{820for (i=0; i<debug.tri_sel->nv; i++)821{822grConstantColorValue (0x000000FF);823output (debug.tri_sel->v[i].x+1, settings.scr_res_y-debug.tri_sel->v[i].y+1, 1,824"%d", i);825grConstantColorValue (0xFFFFFFFF);826output (debug.tri_sel->v[i].x, settings.scr_res_y-debug.tri_sel->v[i].y, 1,827"%d", i);828}829}830831// Draw the cursor832debug_mouse ();833834grBufferSwap (1);835}836837END:838// Release all data839delete [] debug.screen;840TRI_INFO *tri;841for (tri=debug.tri_list; tri != debug.tri_last;)842{843TRI_INFO *tmp = tri;844tri = tri->pNext;845delete [] tmp->v;846delete tmp;847}848delete [] tri->v;849delete tri;850851// Reset all values852debug.capture = 0;853debug.selected = SELECTED_TRI;854debug.screen = NULL;855debug.tri_list = NULL;856debug.tri_last = NULL;857debug.tri_sel = NULL;858debug.tex_sel = 0;859}860861//862// debug_mouse - draws the debugger mouse863//864865void debug_mouse ()866{867grColorCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,868GR_COMBINE_FACTOR_ONE,869GR_COMBINE_LOCAL_NONE,870GR_COMBINE_OTHER_TEXTURE,871FXFALSE);872873grAlphaCombine (GR_COMBINE_FUNCTION_SCALE_OTHER,874GR_COMBINE_FACTOR_ONE,875GR_COMBINE_LOCAL_NONE,876GR_COMBINE_OTHER_TEXTURE,877FXFALSE);878879// Draw the cursor880POINT pt;881GetCursorPos (&pt);882float cx = (float)pt.x;883float cy = (float)pt.y;884885VERTEX v[4] = {886{ cx, cy, 1, 1, 0, 0, 0, 0, 0, 0, 0 },887{ cx+32, cy, 1, 1, 255, 0, 0, 0, 0, 0, 0 },888{ cx, cy+32, 1, 1, 0, 255, 0, 0, 0, 0, 0 },889{ cx+32, cy+32, 1, 1, 255, 255, 0, 0, 0, 0, 0 } };890891ConvertCoordsKeep (v, 4);892893grTexSource(GR_TMU0,894grTexMinAddress(GR_TMU0) + offset_cursor,895GR_MIPMAPLEVELMASK_BOTH,896&cursorTex);897898if (num_tmu >= 3)899grTexCombine (GR_TMU2,900GR_COMBINE_FUNCTION_NONE,901GR_COMBINE_FACTOR_NONE,902GR_COMBINE_FUNCTION_NONE,903GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);904if (num_tmu >= 2)905grTexCombine (GR_TMU1,906GR_COMBINE_FUNCTION_NONE,907GR_COMBINE_FACTOR_NONE,908GR_COMBINE_FUNCTION_NONE,909GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);910grTexCombine (GR_TMU0,911GR_COMBINE_FUNCTION_LOCAL,912GR_COMBINE_FACTOR_NONE,913GR_COMBINE_FUNCTION_LOCAL,914GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE);915916grDrawTriangle (&v[0], &v[1], &v[2]);917grDrawTriangle (&v[1], &v[3], &v[2]);918}919920//921// debug_keys - receives debugger key input922//923924void debug_keys ()925{926if ((GetAsyncKeyState (VK_RIGHT) & 0x0001) && debug.tri_sel)927{928TRI_INFO *start = debug.tri_sel;929930while (debug.tri_sel->pNext != start)931debug.tri_sel = debug.tri_sel->pNext;932}933934if ((GetAsyncKeyState (VK_LEFT) & 0x0001) && debug.tri_sel)935debug.tri_sel = debug.tri_sel->pNext;936937// Check for page changes938if (GetAsyncKeyState ('1') & 0x0001)939debug.page = PAGE_GENERAL;940if (GetAsyncKeyState ('2') & 0x0001)941debug.page = PAGE_TEX1;942if (GetAsyncKeyState ('3') & 0x0001)943debug.page = PAGE_TEX2;944if (GetAsyncKeyState ('4') & 0x0001)945debug.page = PAGE_COLORS;946if (GetAsyncKeyState ('5') & 0x0001)947debug.page = PAGE_FBL;948if (GetAsyncKeyState ('6') & 0x0001)949debug.page = PAGE_OTHERMODE_L;950if (GetAsyncKeyState ('7') & 0x0001)951debug.page = PAGE_OTHERMODE_H;952if (GetAsyncKeyState ('8') & 0x0001)953debug.page = PAGE_TEXELS;954if (GetAsyncKeyState ('9') & 0x0001)955debug.page = PAGE_COORDS;956if (GetAsyncKeyState ('0') & 0x0001)957debug.page = PAGE_TEX_INFO;958if (GetAsyncKeyState ('Q') & 0x0001)959debug.tmu = 0;960if (GetAsyncKeyState ('W') & 0x0001)961debug.tmu = 1;962963if (GetAsyncKeyState ('G') & 0x0001)964grid = !grid;965966// Go to texture967if (GetAsyncKeyState (VK_SPACE) & 0x0001)968{969int tile = -1;970if (debug.page == PAGE_TEX2)971tile = 1;972else973tile = 0;974if (tile != -1)975{976debug.tmu = debug.tri_sel->t[tile].tmu;977debug.tex_sel = debug.tri_sel->t[tile].cur_cache[debug.tmu];978debug.tex_scroll = (debug.tri_sel->t[tile].cur_cache[debug.tmu] >> 4) - 1;979}980}981982// Go to triangle983if (GetAsyncKeyState (VK_LCONTROL) & 0x0001)984{985int count = rdp.debug_n - rdp.cache[debug.tmu][debug.tex_sel].uses - 1;986if (rdp.cache[debug.tmu][debug.tex_sel].last_used == frame_count)987{988TRI_INFO *t = debug.tri_list;989while (count && t) {990t = t->pNext;991count --;992}993debug.tri_sel = t;994}995else996debug.tri_sel = NULL;997}998999if (GetAsyncKeyState ('A') & 0x0001)1000debug.draw_mode = 0; // texture & texture alpha1001if (GetAsyncKeyState ('S') & 0x0001)1002debug.draw_mode = 1; // texture1003if (GetAsyncKeyState ('D') & 0x0001)1004debug.draw_mode = 2; // texture alpha10051006// Check for texture scrolling1007if (GetAsyncKeyState (VK_DOWN) & 0x0001)1008debug.tex_scroll ++;1009if (GetAsyncKeyState (VK_UP) & 0x0001)1010debug.tex_scroll --;1011}1012#endif // _WIN321013//1014// output - output debugger text1015//10161017void output (float x, float y, BOOL scale, const char *fmt, ...)1018{1019va_list ap;1020va_start(ap,fmt);1021vsprintf(out_buf, fmt, ap);1022va_end(ap);10231024BYTE c,r;1025for (DWORD i=0; i<strlen(out_buf); i++)1026{1027c = ((out_buf[i]-32) & 0x1F) * 8;//<< 3;1028r = (((out_buf[i]-32) & 0xE0) >> 5) * 16;//<< 4;1029VERTEX v[4] = { { SX(x), SY(768-y), 1, 1, (float)c, r+16.0f, 0, 0, {0, 0, 0, 0} },1030{ SX(x+8), SY(768-y), 1, 1, c+8.0f, r+16.0f, 0, 0, {0, 0, 0, 0} },1031{ SX(x), SY(768-y-16), 1, 1, (float)c, (float)r, 0, 0, {0, 0, 0, 0} },1032{ SX(x+8), SY(768-y-16), 1, 1, c+8.0f, (float)r, 0, 0, {0, 0, 0, 0} } };1033if (!scale)1034{1035v[0].x = x;1036v[0].y = y;1037v[1].x = x+8;1038v[1].y = y;1039v[2].x = x;1040v[2].y = y-16;1041v[3].x = x+8;1042v[3].y = y-16;1043}10441045ConvertCoordsKeep (v, 4);10461047grDrawTriangle (&v[0], &v[1], &v[2]);1048grDrawTriangle (&v[1], &v[3], &v[2]);10491050x+=8;1051}1052}1053105410551056