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