15eb0001 |
1 | \r |
58db92b9 |
2 | // This file is part of the PicoDrive Megadrive Emulator\r |
3 | \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 |
6 | \r |
7 | // SVN repository can be found at http://code.google.com/p/cyclone68000/\r |
8 | \r |
15eb0001 |
9 | #include "stdafx.h"\r |
10 | \r |
11 | static int ScreenNum=0;\r |
12 | \r |
13 | int DebugScreenGrab()\r |
14 | {\r |
15 | unsigned char *screen=NULL;\r |
16 | FILE *file=NULL;\r |
17 | unsigned char *line=NULL;\r |
18 | int x=0,y=0;\r |
19 | char filename[64];\r |
20 | unsigned char head[0x12];\r |
21 | \r |
22 | memset(filename,0,sizeof(filename));\r |
23 | memset(head,0,sizeof(head));\r |
24 | \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 |
28 | \r |
29 | // Get pointer to screen:\r |
30 | screen=(unsigned char *)GXBeginDraw(); if (screen==NULL) { free(line); return 1; }\r |
31 | \r |
32 | // Open screenshot file:\r |
33 | for (;;)\r |
34 | {\r |
35 | sprintf(filename,"\\Screen%.3d.tga",ScreenNum);\r |
36 | \r |
37 | // Does this file exist?\r |
38 | file=fopen(filename,"rb"); if (file==NULL) break; // No - use this\r |
39 | \r |
40 | // Exists, try next file\r |
41 | fclose(file); ScreenNum++;\r |
42 | if (ScreenNum>=1000) break;\r |
43 | }\r |
44 | \r |
45 | // Use this filename\r |
46 | file=fopen(filename,"wb"); if (file==NULL) { GXEndDraw(); free(line); return 1; }\r |
47 | \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 |
54 | \r |
55 | // Write header:\r |
56 | fwrite(head,1,sizeof(head),file);\r |
57 | \r |
58 | for (y=0;y<(int)GXDisp.cyHeight;y++)\r |
59 | {\r |
60 | unsigned char *ps=NULL,*pd=NULL;\r |
61 | int ry=0;\r |
62 | int pix=0;\r |
63 | \r |
64 | ry=GXDisp.cyHeight-y-1;\r |
65 | ps=screen+ry*GXDisp.cbyPitch;\r |
66 | pd=line;\r |
67 | \r |
68 | // Copy pixel to our line buffer\r |
69 | for (x=0;x<(int)GXDisp.cxWidth; x++,ps+=GXDisp.cbxPitch,pd+=3)\r |
70 | {\r |
71 | pix=*(unsigned short *)ps;\r |
72 | \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 |
76 | }\r |
77 | \r |
78 | fwrite(line,1,GXDisp.cxWidth*3,file);\r |
79 | }\r |
80 | \r |
81 | fclose(file); file=NULL;\r |
82 | \r |
83 | GXEndDraw();\r |
84 | free(line);\r |
85 | \r |
86 | return 0;\r |
87 | }\r |