DeSmuME source code query [Programming]

Discussion in 'NDS - Emulation and Homebrew' started by Dan_Tsukasa, Jan 14, 2015.

  1. Dan_Tsukasa
    OP

    Dan_Tsukasa GBAtemp Regular

    Member
    172
    43
    Oct 14, 2014
    Tokyo Japan
    Hey Guys.

    So, looking at the DeSmuMe source I see this:

    Code:
    //only dump this from ogl renderer. for now, softrasterizer creates things in an incompatible pixel format
    //#define DEBUG_DUMP_TEXTURE
    
    Now its commented out, but there is a texture dumper in there, further down it has this:
    I did uncomment it of course, thinking it'd be that simple.
    Code:
    #if defined (DEBUG_DUMP_TEXTURE) && defined (WIN32)
    #define DO_DEBUG_DUMP_TEXTURE
    static void DebugDumpTexture(TexCacheItem* item)
    {
        static int ctr=0;
        char fname[100];
        sprintf(fname,"c:\\dump\\%d.bmp", ctr);
        ctr++;
     
        NDS_WriteBMP_32bppBuffer(item->sizeX,item->sizeY,item->decoded,fname);
    }
    #endif
    
    My thoughts on this are that theres a built in texture dumper in DeSmuMe, which isn't much of a surprise, but simply enabling it doesn't seem to do anything.

    Thats all in texcache.cpp, nothing edited there, all default.

    My question is, thats the only reference to DEBUG_TEXTURE_DUMP in the whole project, how am I supposed to dump the textures then? Theres no key, or shortcut or anything, nor do they get dumped as they load into memory.

    Note:
    I am aware there are various other methods to ripping textures from NDS games, and those work great, I'm mostly interested in understanding how this code works, and when its supposed to initiate.

    I'm not much of a coder so chances are I'm just overlooking something stupidly simple here.
     
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,874
    9,783
    Nov 21, 2005
    United Kingdom
    I am not sure about this particular issue but a lot of the debugging side of things with desmume is more placeholder than anything else, 3d being especially troubled by this situation.
     
    Dan_Tsukasa likes this.
  3. Dan_Tsukasa
    OP

    Dan_Tsukasa GBAtemp Regular

    Member
    172
    43
    Oct 14, 2014
    Tokyo Japan
    Was really hoping somebody might be able to chip in with some advice, I'm still stumped even now.
     
  4. Nagato

    Nagato GBAtemp Advanced Fan

    Member
    531
    514
    Jul 15, 2011
    United States
    At the top of texcache.cpp, look for the line that says "//#define DEBUG_DUMP_TEXTURE". Uncomment that line (make it just say "#define DEBUG_DUMP_TEXTURE", without the "//" before it). Start Desmume with the OpenGL renderer settings. It should automatically dump the textures to the C:\dump\ folder. If that folder doesn't exist then you'll need to make it yourself. That's all that should need to be done, judging from the code I looked at.
     
  5. Dan_Tsukasa
    OP

    Dan_Tsukasa GBAtemp Regular

    Member
    172
    43
    Oct 14, 2014
    Tokyo Japan
    I figured it out. What you said is what I thought, and it was also correct, it wasn't dumping (and still isn't) to the c:\dump folder, its actually dumping to the folder the exe is in (or in the previous case it was dumping to the save state folder). So I was being stupid, but also I'd left it as \\ instead of \, plus the c was lower case (might mean nothing, but its uppercase now and it works so I'm using that as a thumbs up.

    Awesome, so with that figured out, now I need to figure out where to place the snippets of this code to dump the 3d models. (hopefully it won't dump hundreds for every movement like the texture dump does).

    Code:
    //texcache.cpp
     
    //only dump this from ogl renderer. for now, softrasterizer creates things in an incompatible pixel format
     
    //#define DEBUG_DUMP_TEXTURE//szfzafa
     
     
     
     
     
    //gfx3d.h
     
    //szfzafa
     
    extern unsigned char szfzafadumpmodelmark;
     
    void gfx3d_szfzafadumpmodels();
     
     
     
    //gfx3d.cpp
     
    unsigned char szfzafadumpmodelmark=0;//szfzafa
     
    static void gfx3d_doFlush()
     
    {
     
        //szfzafa
     
            if(szfzafadumpmodelmark)
     
            gfx3d_szfzafadumpmodels();
     
        //szfzafa
     
            gfx3d.frameCtr++;
     
    ……
     
     
     
    //szfzafa:dump models!
     
    //-------------savestate
     
     
     
    void gfx3d_szfzafadumpmodels()
     
    {
     
        if(gfx3d.vertlist->count>4&&gfx3d.polylist->count>1)
     
            szfzafadumpmodelmark=0;
     
        else
     
            {
     
                      printf("szfzafa ripping failed~\n");
     
            return;
     
        }
     
     
     
        FILE *file;
     
        if ((file = fopen("c:\\dump\\szfzafa.obj","wb")) == NULL)
     
            return;
     
        //dump the render lists
     
            printf("szfzafa ripping %d verts %d polys~\n",gfx3d.vertlist->count,gfx3d.polylist->count);
     
        for(int i=0;i<gfx3d.vertlist->count;i++)
     
        {
     
              //fprintf(file,"v\t%f\t%f\t%f\t%f\n",gfx3d.vertlist->list[i].x,gfx3d.vertlist->list[i].y,gfx3d.vertlist->list[i].z,gfx3d.vertlist->list[i].w);
     
                      fprintf(file,"v\t%f\t%f\t%f\t%f\n",
     
                  gfx3d.vertlist->list[i].y*3.0/-32.0,
     
                  gfx3d.vertlist->list[i].x/8.0,
     
                  gfx3d.vertlist->list[i].z/-2.0,
     
                  gfx3d.vertlist->list[i].w);
     
            //fprintf(file,"vt\t%f\t%f\n",gfx3d.vertlist->list[i].u,gfx3d.vertlist->list[i].v);
     
                      fprintf(file,"vt\t%f\t%f\n",gfx3d.vertlist->list[i].u,-gfx3d.vertlist->list[i].v);
     
        }
     
     
     
        //char szfzafatex[32];
     
            u32 szfzafapa1=gfx3d.polylist->list[0].polyAttr;
     
        u32 szfzafapa2=gfx3d.polylist->list[0].texPalette;
     
        u32 szfzafapa3=gfx3d.polylist->list[0].texParam;
     
        fprintf(file,"g\t%x_%x_%x\n",szfzafapa1,szfzafapa2,szfzafapa3);
     
        //printf("usemtl\t%x\n",szfzafapa);
     
            for(int i=0;i<gfx3d.polylist->count;i++)
     
        {
     
            if(szfzafapa1!=gfx3d.polylist->list[i].polyAttr||
     
                  szfzafapa2!=gfx3d.polylist->list[i].texPalette||
     
                  szfzafapa3!=gfx3d.polylist->list[i].texParam)
     
            {
     
                  szfzafapa1=gfx3d.polylist->list[i].polyAttr;
     
                  szfzafapa2=gfx3d.polylist->list[i].texPalette;
     
                  szfzafapa3=gfx3d.polylist->list[i].texParam;
     
                  fprintf(file,"g\t%x_%x_%x\n",szfzafapa1,szfzafapa2,szfzafapa3);
     
            }
     
            switch(gfx3d.polylist->list[i].type)
     
            {
     
            case 4:  fprintf(file,"f\t%d/%d\t%d/%d\t%d/%d\t%d/%d\n",
     
                          1+gfx3d.polylist->list[i].vertIndexes[0],1+gfx3d.polylist->list[i].vertIndexes[0],
     
                          1+gfx3d.polylist->list[i].vertIndexes[1],1+gfx3d.polylist->list[i].vertIndexes[1],
     
                          1+gfx3d.polylist->list[i].vertIndexes[2],1+gfx3d.polylist->list[i].vertIndexes[2],
     
                          1+gfx3d.polylist->list[i].vertIndexes[3],1+gfx3d.polylist->list[i].vertIndexes[3]);
     
                  break;
     
            case 3:  fprintf(file,"f\t%d/%d\t%d/%d\t%d/%d\n",
     
                          1+gfx3d.polylist->list[i].vertIndexes[0],1+gfx3d.polylist->list[i].vertIndexes[0],
     
                          1+gfx3d.polylist->list[i].vertIndexes[1],1+gfx3d.polylist->list[i].vertIndexes[1],
     
                          1+gfx3d.polylist->list[i].vertIndexes[2],1+gfx3d.polylist->list[i].vertIndexes[2]);
     
                  break;
     
            default:;
     
            }
     
        }
     
        fclose(file);
     
    }
    
    I know where it says the section, sort of, and It makes it clear what cpp or .h file to past the code in, the downside is, it doesn't say much where, or even how to activate it at all.