1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /****************************************/
26 /* Some generic high-level video */
27 /* related functions. */
28 /****************************************/
47 int InitVirtualVideo(void)
51 if(!XBuf) /* Some driver code may allocate XBuf externally. */
52 if(!(XBuf = (uint8*) (FCEU_malloc(320 * 240))))
62 memset(XBuf,128,320*240);
67 static uint8 pcxheader[128] =
69 10,5,1,8,1,0,1,0,0,1,240,0,2,1,234,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
70 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,
71 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
72 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
75 int SaveSnapshot(void)
84 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"pcx")),"rb");
89 if(!(pp=fopen(fn,"wb")))
93 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
95 tmp=XBuf+8+FSettings.FirstSLine*272;
97 pcxheader[10]=totallines;
98 fwrite(pcxheader,1,128,pp);
99 for(y=0;y<totallines;y++)
103 if(*tmp>=0xc0) fputc(0xC1,pp);
116 FCEUD_GetPalette(x,&r,&g,&b);
131 static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
142 if(fwrite(tempo,4,1,fp)!=1)
144 if(fwrite(type,4,1,fp)!=1)
148 if(fwrite(data,1,size,fp)!=size)
151 crc=CalcCRC32(0,(uint8 *)type,4);
153 crc=CalcCRC32(crc,data,size);
160 if(fwrite(tempo,4,1,fp)!=1)
165 int SaveSnapshot(void)
168 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
172 uint32 compmemsize=totallines*263+12;
174 if(!(compmem=FCEU_malloc(compmemsize)))
179 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"png")),"rb");
184 if(!(pp=fopen(fn,"wb")))
187 static uint8 header[8]={137,80,78,71,13,10,26,10};
188 if(fwrite(header,8,1,pp)!=1)
195 chunko[0]=chunko[1]=chunko[3]=0;
196 chunko[2]=0x1; // Width of 256
198 chunko[4]=chunko[5]=chunko[6]=0;
199 chunko[7]=totallines; // Height
201 chunko[8]=8; // bit depth
202 chunko[9]=3; // Color type; indexed 8-bit
203 chunko[10]=0; // compression: deflate
204 chunko[11]=0; // Basic adapative filter set(though none are used).
205 chunko[12]=0; // No interlace.
207 if(!WritePNGChunk(pp,13,"IHDR",chunko))
214 //void FCEUD_GetPalette(uint8 i,uint8 *r, unsigned char *g, unsigned char *b);
216 FCEUD_GetPalette(x,(uint8*)(pdata+x*3),(unsigned char*)(pdata+x*3+1),(unsigned char*)(pdata+x*3+2));
217 // static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
218 if(!WritePNGChunk(pp,256*3,"PLTE",(uint8 *)pdata))
223 uint8 *tmp=XBuf+FSettings.FirstSLine*272+8;
224 uint8 *dest,*mal,*mork;
226 /* If memory couldn't be allocated, just use XBuf(screen contents
227 will be corrupted for one frame, though.
229 if(!(mal=mork=dest=malloc((totallines<<8)+totallines)))
232 for(y=0;y<totallines;y++)
234 *dest=0; // No filter.
236 for(x=256;x;x--,tmp++,dest++)
241 if(compress(compmem,&compmemsize,mork,(totallines<<8)+totallines)!=Z_OK)
247 if(!WritePNGChunk(pp,compmemsize,"IDAT",compmem))
250 if(!WritePNGChunk(pp,0,"IEND",0))