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)
49 if(!XBuf) /* Some driver code may allocate XBuf externally. */
50 if(!(XBuf = (uint8*) (FCEU_malloc(320 * 240))))
60 memset(XBuf,128,320*240);
65 static uint8 pcxheader[128] =
67 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,
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,1,0,1,0,0,0,0,0,0,0,
69 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,
70 0,0,0,0,0,0,0,0,0,0,0,0,0,0,
73 int SaveSnapshot(void)
82 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"pcx")),"rb");
87 if(!(pp=fopen(fn,"wb")))
91 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
93 tmp=XBuf+8+FSettings.FirstSLine*272;
95 pcxheader[10]=totallines;
96 fwrite(pcxheader,1,128,pp);
97 for(y=0;y<totallines;y++)
101 if(*tmp>=0xc0) fputc(0xC1,pp);
114 FCEUD_GetPalette(x,&r,&g,&b);
129 static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
140 if(fwrite(tempo,4,1,fp)!=1)
142 if(fwrite(type,4,1,fp)!=1)
146 if(fwrite(data,1,size,fp)!=size)
149 crc=CalcCRC32(0,(uint8 *)type,4);
151 crc=CalcCRC32(crc,data,size);
158 if(fwrite(tempo,4,1,fp)!=1)
163 int SaveSnapshot(void)
166 int totallines=FSettings.LastSLine-FSettings.FirstSLine+1;
170 uint32 compmemsize=totallines*263+12;
172 if(!(compmem=FCEU_malloc(compmemsize)))
177 pp=fopen((fn=FCEU_MakeFName(FCEUMKF_SNAP,u,"png")),"rb");
182 if(!(pp=fopen(fn,"wb")))
185 static uint8 header[8]={137,80,78,71,13,10,26,10};
186 if(fwrite(header,8,1,pp)!=1)
193 chunko[0]=chunko[1]=chunko[3]=0;
194 chunko[2]=0x1; // Width of 256
196 chunko[4]=chunko[5]=chunko[6]=0;
197 chunko[7]=totallines; // Height
199 chunko[8]=8; // bit depth
200 chunko[9]=3; // Color type; indexed 8-bit
201 chunko[10]=0; // compression: deflate
202 chunko[11]=0; // Basic adapative filter set(though none are used).
203 chunko[12]=0; // No interlace.
205 if(!WritePNGChunk(pp,13,"IHDR",chunko))
212 //void FCEUD_GetPalette(uint8 i,uint8 *r, unsigned char *g, unsigned char *b);
214 FCEUD_GetPalette(x,(uint8*)(pdata+x*3),(unsigned char*)(pdata+x*3+1),(unsigned char*)(pdata+x*3+2));
215 // static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data)
216 if(!WritePNGChunk(pp,256*3,"PLTE",(uint8 *)pdata))
221 uint8 *tmp=XBuf+FSettings.FirstSLine*272+8;
222 uint8 *dest,*mal,*mork;
224 /* If memory couldn't be allocated, just use XBuf(screen contents
225 will be corrupted for one frame, though.
227 if(!(mal=mork=dest=malloc((totallines<<8)+totallines)))
230 for(y=0;y<totallines;y++)
232 *dest=0; // No filter.
234 for(x=256;x;x--,tmp++,dest++)
239 if(compress(compmem,&compmemsize,mork,(totallines<<8)+totallines)!=Z_OK)
245 if(!WritePNGChunk(pp,compmemsize,"IDAT",compmem))
248 if(!WritePNGChunk(pp,0,"IEND",0))