4 static int ScreenNum=0;
\r
6 int DebugScreenGrab()
\r
8 unsigned char *screen=NULL;
\r
10 unsigned char *line=NULL;
\r
13 unsigned char head[0x12];
\r
15 memset(filename,0,sizeof(filename));
\r
16 memset(head,0,sizeof(head));
\r
18 // Allocate memory for one line
\r
19 line=(unsigned char *)malloc(GXDisp.cxWidth*3); if (line==NULL) return 1;
\r
20 memset(line,0,GXDisp.cxWidth*3);
\r
22 // Get pointer to screen:
\r
23 screen=(unsigned char *)GXBeginDraw(); if (screen==NULL) { free(line); return 1; }
\r
25 // Open screenshot file:
\r
28 sprintf(filename,"\\Screen%.3d.tga",ScreenNum);
\r
30 // Does this file exist?
\r
31 file=fopen(filename,"rb"); if (file==NULL) break; // No - use this
\r
33 // Exists, try next file
\r
34 fclose(file); ScreenNum++;
\r
35 if (ScreenNum>=1000) break;
\r
38 // Use this filename
\r
39 file=fopen(filename,"wb"); if (file==NULL) { GXEndDraw(); free(line); return 1; }
\r
41 head[0x02]=0x02; //?
\r
42 head[0x0c]=(unsigned char) GXDisp.cxWidth;
\r
43 head[0x0d]=(unsigned char)(GXDisp.cxWidth>>8);
\r
44 head[0x0e]=(unsigned char) GXDisp.cyHeight;
\r
45 head[0x0f]=(unsigned char)(GXDisp.cyHeight>>8);
\r
46 head[0x10]=24; // Number of bits per pixel
\r
49 fwrite(head,1,sizeof(head),file);
\r
51 for (y=0;y<(int)GXDisp.cyHeight;y++)
\r
53 unsigned char *ps=NULL,*pd=NULL;
\r
57 ry=GXDisp.cyHeight-y-1;
\r
58 ps=screen+ry*GXDisp.cbyPitch;
\r
61 // Copy pixel to our line buffer
\r
62 for (x=0;x<(int)GXDisp.cxWidth; x++,ps+=GXDisp.cbxPitch,pd+=3)
\r
64 pix=*(unsigned short *)ps;
\r
66 pd[0]=(unsigned char)((pix&0x001f)<<3); // Red
\r
67 pd[1]=(unsigned char)((pix&0x07e0)>>3); // Green
\r
68 pd[2]=(unsigned char)((pix&0xf800)>>8); // Blue
\r
71 fwrite(line,1,GXDisp.cxWidth*3,file);
\r
74 fclose(file); file=NULL;
\r