2 // This file is part of the PicoDrive Megadrive Emulator
\r
4 // This code is licensed under the GNU General Public License version 2.0 and the MAME License.
\r
5 // You can choose the license that has the most advantages for you.
\r
7 // SVN repository can be found at http://code.google.com/p/cyclone68000/
\r
11 static int ScreenNum=0;
\r
13 int DebugScreenGrab()
\r
15 unsigned char *screen=NULL;
\r
17 unsigned char *line=NULL;
\r
20 unsigned char head[0x12];
\r
22 memset(filename,0,sizeof(filename));
\r
23 memset(head,0,sizeof(head));
\r
25 // Allocate memory for one line
\r
26 line=(unsigned char *)malloc(GXDisp.cxWidth*3); if (line==NULL) return 1;
\r
27 memset(line,0,GXDisp.cxWidth*3);
\r
29 // Get pointer to screen:
\r
30 screen=(unsigned char *)GXBeginDraw(); if (screen==NULL) { free(line); return 1; }
\r
32 // Open screenshot file:
\r
35 sprintf(filename,"\\Screen%.3d.tga",ScreenNum);
\r
37 // Does this file exist?
\r
38 file=fopen(filename,"rb"); if (file==NULL) break; // No - use this
\r
40 // Exists, try next file
\r
41 fclose(file); ScreenNum++;
\r
42 if (ScreenNum>=1000) break;
\r
45 // Use this filename
\r
46 file=fopen(filename,"wb"); if (file==NULL) { GXEndDraw(); free(line); return 1; }
\r
48 head[0x02]=0x02; //?
\r
49 head[0x0c]=(unsigned char) GXDisp.cxWidth;
\r
50 head[0x0d]=(unsigned char)(GXDisp.cxWidth>>8);
\r
51 head[0x0e]=(unsigned char) GXDisp.cyHeight;
\r
52 head[0x0f]=(unsigned char)(GXDisp.cyHeight>>8);
\r
53 head[0x10]=24; // Number of bits per pixel
\r
56 fwrite(head,1,sizeof(head),file);
\r
58 for (y=0;y<(int)GXDisp.cyHeight;y++)
\r
60 unsigned char *ps=NULL,*pd=NULL;
\r
64 ry=GXDisp.cyHeight-y-1;
\r
65 ps=screen+ry*GXDisp.cbyPitch;
\r
68 // Copy pixel to our line buffer
\r
69 for (x=0;x<(int)GXDisp.cxWidth; x++,ps+=GXDisp.cbxPitch,pd+=3)
\r
71 pix=*(unsigned short *)ps;
\r
73 pd[0]=(unsigned char)((pix&0x001f)<<3); // Red
\r
74 pd[1]=(unsigned char)((pix&0x07e0)>>3); // Green
\r
75 pd[2]=(unsigned char)((pix&0xf800)>>8); // Blue
\r
78 fwrite(line,1,GXDisp.cxWidth*3,file);
\r
81 fclose(file); file=NULL;
\r