2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
12 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
21 * Permission to use, copy, modify and distribute Snes9x in both binary and
22 * source form, for non-commercial purposes, is hereby granted without fee,
23 * providing that this license information and copyright notice appear with
24 * all copies and any derived work.
26 * This software is provided 'as-is', without any express or implied
27 * warranty. In no event shall the authors be held liable for any damages
28 * arising from the use of this software.
30 * Snes9x is freeware for PERSONAL USE only. Commercial users should
31 * seek permission of the copyright holders first. Commercial use includes
32 * charging money for Snes9x or software derived from Snes9x.
34 * The copyright holders request that bug fixes and improvements to the code
35 * should be forwarded to them so everyone can benefit from the modifications
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
45 /**********************************************************************************************/
47 /* This file contains a function for loading a SNES ROM image from a zip file */
48 /**********************************************************************************************/
58 #ifndef NO_INLINE_SET_GET
59 #define NO_INLINE_SET_GET
65 bool8 LoadZip(const char* zipname,
72 unzFile file = unzOpen(zipname);
76 // find largest file in zip file (under MAX_ROM_SIZE)
77 // or a file with extension .1
80 int port = unzGoToFirstFile(file);
82 while (port == UNZ_OK)
85 unzGetCurrentFileInfo(file, &info, name,128, NULL,0, NULL,0);
88 int calc_size = info.uncompressed_size / 0x2000;
90 if(!(info.uncompressed_size - calc_size == 512 || info.uncompressed_size == calc_size))
92 port = unzGoToNextFile(file);
97 if(info.uncompressed_size > (CMemory::MAX_ROM_SIZE + 512))
99 port = unzGoToNextFile(file);
103 if ((int) info.uncompressed_size > filesize)
105 strcpy(filename,name);
106 filesize = info.uncompressed_size;
109 int len = strlen(name);
110 if(name[len-2] == '.' && name[len-1] == '1')
112 strcpy(filename,name);
113 filesize = info.uncompressed_size;
117 port = unzGoToNextFile(file);
119 if( !(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0)
126 char tmp[2] = { '\0', '\0' };
127 char *ext = strrchr(filename, '.');
131 uint8 *ptr = Memory.ROM;
134 unzLocateFile(file,filename,1);
135 unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0);
137 if( unzOpenCurrentFile(file) != UNZ_OK )
145 int FileSize = info.uncompressed_size;
146 assert(FileSize <= CMemory::MAX_ROM_SIZE + 512);
148 int calc_size = FileSize / 0x2000;
151 int l = unzReadCurrentFile(file,ptr,FileSize);
152 if(unzCloseCurrentFile(file) == UNZ_CRCERROR)
158 if (l <= 0 || l != FileSize)
171 case UNZ_INTERNALERROR:
179 if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) ||
180 Settings.ForceHeader)
182 memmove (ptr, ptr + 512, calc_size);
187 (*TotalFileSize) += FileSize;
190 if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
191 (isdigit (ext [0]) && ext [1] == 0 && ext [0] < '9'))
196 else if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
197 (((len = strlen (filename)) == 7 || len == 8) &&
198 strncasecmp (filename, "sf", 2) == 0 &&
199 isdigit (filename [2]) && isdigit (filename [3]) && isdigit (filename [4]) &&
200 isdigit (filename [5]) && isalpha (filename [len - 1])))
203 filename [len - 1]++;
210 if (unzLocateFile(file,filename,1) != UNZ_OK ||
211 unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0) != UNZ_OK ||
212 unzOpenCurrentFile(file) != UNZ_OK)