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 /****************************************/
44 int InitVirtualVideo(void)
48 if(!XBuf) /* Some driver code may allocate XBuf externally. */
49 if(!(XBuf = (uint8*) (FCEU_malloc((256+16) * 240 + 8))))
59 memset(XBuf,128,272*240);
64 static uint8 pcxheader[128] =
66 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,
67 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,
68 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,
69 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
72 int SaveSnapshot(void)
81 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"pcx")),"rb");
86 if(!(pp=fopen(fn,"wb")))
90 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
92 tmp=XBuf+8+FSettings.FirstSLine*272;
94 pcxheader[10]=totallines;
95 fwrite(pcxheader,1,128,pp);
96 for(y=0;y<totallines;y++)
100 if(*tmp>=0xc0) fputc(0xC1,pp);
113 FCEUD_GetPalette(x,&r,&g,&b);
128 static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
139 if(fwrite(tempo,4,1,fp)!=1)
141 if(fwrite(type,4,1,fp)!=1)
145 if(fwrite(data,1,size,fp)!=size)
148 crc=CalcCRC32(0,(uint8 *)type,4);
150 crc=CalcCRC32(crc,data,size);
157 if(fwrite(tempo,4,1,fp)!=1)
162 int SaveSnapshot(void)
165 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
169 uint32 compmemsize=totallines*263+12;
171 if(!(compmem=FCEU_malloc(compmemsize)))
176 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"png")),"rb");
181 if(!(pp=fopen(fn,"wb")))
184 static uint8 header[8]={137,80,78,71,13,10,26,10};
185 if(fwrite(header,8,1,pp)!=1)
192 chunko[0]=chunko[1]=chunko[3]=0;
193 chunko[2]=0x1; // Width of 256
195 chunko[4]=chunko[5]=chunko[6]=0;
196 chunko[7]=totallines; // Height
198 chunko[8]=8; // bit depth
199 chunko[9]=3; // Color type; indexed 8-bit
200 chunko[10]=0; // compression: deflate
201 chunko[11]=0; // Basic adapative filter set(though none are used).
202 chunko[12]=0; // No interlace.
204 if(!WritePNGChunk(pp,13,"IHDR",chunko))
211 //void FCEUD_GetPalette(uint8 i,uint8 *r, unsigned char *g, unsigned char *b);
213 FCEUD_GetPalette(x,(uint8*)(pdata+x*3),(unsigned char*)(pdata+x*3+1),(unsigned char*)(pdata+x*3+2));
214 // static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
215 if(!WritePNGChunk(pp,256*3,"PLTE",(uint8 *)pdata))
220 uint8 *tmp=XBuf+FSettings.FirstSLine*272+8;
221 uint8 *dest,*mal,*mork;
223 /* If memory couldn't be allocated, just use XBuf(screen contents
224 will be corrupted for one frame, though.
226 if(!(mal=mork=dest=malloc((totallines<<8)+totallines)))
229 for(y=0;y<totallines;y++)
231 *dest=0; // No filter.
233 for(x=256;x;x--,tmp++,dest++)
238 if(compress(compmem,&compmemsize,mork,(totallines<<8)+totallines)!=Z_OK)
244 if(!WritePNGChunk(pp,compmemsize,"IDAT",compmem))
247 if(!WritePNGChunk(pp,0,"IEND",0))