2 // This file is part of the PicoDrive Megadrive Emulator
\r
4 // Copyright (c) 2011 FinalDave (emudave (at) gmail.com)
\r
6 // This code is licensed under the GNU General Public License version 2.0 and the MAME License.
\r
7 // You can choose the license that has the most advantages for you.
\r
9 // SVN repository can be found at http://code.google.com/p/cyclone68000/
\r
13 static int ScreenNum=0;
\r
15 int DebugScreenGrab()
\r
17 unsigned char *screen=NULL;
\r
19 unsigned char *line=NULL;
\r
22 unsigned char head[0x12];
\r
24 memset(filename,0,sizeof(filename));
\r
25 memset(head,0,sizeof(head));
\r
27 // Allocate memory for one line
\r
28 line=(unsigned char *)malloc(GXDisp.cxWidth*3); if (line==NULL) return 1;
\r
29 memset(line,0,GXDisp.cxWidth*3);
\r
31 // Get pointer to screen:
\r
32 screen=(unsigned char *)GXBeginDraw(); if (screen==NULL) { free(line); return 1; }
\r
34 // Open screenshot file:
\r
37 sprintf(filename,"\\Screen%.3d.tga",ScreenNum);
\r
39 // Does this file exist?
\r
40 file=fopen(filename,"rb"); if (file==NULL) break; // No - use this
\r
42 // Exists, try next file
\r
43 fclose(file); ScreenNum++;
\r
44 if (ScreenNum>=1000) break;
\r
47 // Use this filename
\r
48 file=fopen(filename,"wb"); if (file==NULL) { GXEndDraw(); free(line); return 1; }
\r
50 head[0x02]=0x02; //?
\r
51 head[0x0c]=(unsigned char) GXDisp.cxWidth;
\r
52 head[0x0d]=(unsigned char)(GXDisp.cxWidth>>8);
\r
53 head[0x0e]=(unsigned char) GXDisp.cyHeight;
\r
54 head[0x0f]=(unsigned char)(GXDisp.cyHeight>>8);
\r
55 head[0x10]=24; // Number of bits per pixel
\r
58 fwrite(head,1,sizeof(head),file);
\r
60 for (y=0;y<(int)GXDisp.cyHeight;y++)
\r
62 unsigned char *ps=NULL,*pd=NULL;
\r
66 ry=GXDisp.cyHeight-y-1;
\r
67 ps=screen+ry*GXDisp.cbyPitch;
\r
70 // Copy pixel to our line buffer
\r
71 for (x=0;x<(int)GXDisp.cxWidth; x++,ps+=GXDisp.cbxPitch,pd+=3)
\r
73 pix=*(unsigned short *)ps;
\r
75 pd[0]=(unsigned char)((pix&0x001f)<<3); // Red
\r
76 pd[1]=(unsigned char)((pix&0x07e0)>>3); // Green
\r
77 pd[2]=(unsigned char)((pix&0xf800)>>8); // Blue
\r
80 fwrite(line,1,GXDisp.cxWidth*3,file);
\r
83 fclose(file); file=NULL;
\r