use system's zlib
[picodrive.git] / pico / cart.c
index 6a835b6..9dce38d 100644 (file)
@@ -8,10 +8,9 @@
  */\r
 \r
 #include "pico_int.h"\r
-#include "../zlib/zlib.h"\r
 #include "../cpu/debug.h"\r
 #include "../unzip/unzip.h"\r
-#include "../unzip/unzip_stream.h"\r
+#include <zlib.h>\r
 \r
 \r
 static int rom_alloc_size;\r
@@ -50,7 +49,7 @@ typedef struct _cso_struct
 }\r
 cso_struct;\r
 \r
-static int uncompress2(void *dest, int destLen, void *source, int sourceLen)\r
+static int uncompress_buf(void *dest, int destLen, void *source, int sourceLen)\r
 {\r
     z_stream stream;\r
     int err;\r
@@ -100,6 +99,7 @@ pm_file *pm_open(const char *path)
     return NULL;\r
 \r
   ext = get_ext(path);\r
+#ifndef NO_ZLIB\r
   if (strcasecmp(ext, "zip") == 0)\r
   {\r
     struct zipent *zipentry;\r
@@ -149,7 +149,9 @@ zip_failed:
       return NULL;\r
     }\r
   }\r
-  else if (strcasecmp(ext, "cso") == 0)\r
+  else\r
+#endif\r
+  if (strcasecmp(ext, "cso") == 0)\r
   {\r
     cso_struct *cso = NULL, *tmp = NULL;\r
     int size;\r
@@ -157,7 +159,7 @@ zip_failed:
     if (f == NULL)\r
       goto cso_failed;\r
 \r
-#ifndef __EPOC32__\r
+#ifdef __GP2X__\r
     /* we use our own buffering */\r
     setvbuf(f, NULL, _IONBF, 0);\r
 #endif\r
@@ -227,7 +229,7 @@ cso_failed:
   strncpy(file->ext, ext, sizeof(file->ext) - 1);\r
   fseek(f, 0, SEEK_SET);\r
 \r
-#ifndef __EPOC32__ // makes things worse on Symbian\r
+#ifdef __GP2X__\r
   if (file->size > 0x400000)\r
     /* we use our own buffering */\r
     setvbuf(f, NULL, _IONBF, 0);\r
@@ -244,6 +246,7 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream)
   {\r
     ret = fread(ptr, 1, bytes, stream->file);\r
   }\r
+#ifndef NO_ZLIB\r
   else if (stream->type == PMT_ZIP)\r
   {\r
     gzFile gf = stream->param;\r
@@ -254,6 +257,7 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream)
       /* we must reset stream pointer or else next seek/read fails */\r
       gzrewind(gf);\r
   }\r
+#endif\r
   else if (stream->type == PMT_CSO)\r
   {\r
     cso_struct *cso = stream->param;\r
@@ -293,7 +297,7 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream)
           }\r
           cso->block_in_buff = block;\r
         }\r
-        rret = uncompress2(tmp_dst, 2048, cso->in_buff, read_len);\r
+        rret = uncompress_buf(tmp_dst, 2048, cso->in_buff, read_len);\r
         if (rret != 0) {\r
           elprintf(EL_STATUS, "cso: uncompress failed @ %08x with %i", read_pos, rret);\r
           break;\r
@@ -329,6 +333,7 @@ int pm_seek(pm_file *stream, long offset, int whence)
     fseek(stream->file, offset, whence);\r
     return ftell(stream->file);\r
   }\r
+#ifndef NO_ZLIB\r
   else if (stream->type == PMT_ZIP)\r
   {\r
     if (PicoMessage != NULL && offset > 6*1024*1024) {\r
@@ -338,6 +343,7 @@ int pm_seek(pm_file *stream, long offset, int whence)
     }\r
     return gzseek((gzFile) stream->param, offset, whence);\r
   }\r
+#endif\r
   else if (stream->type == PMT_CSO)\r
   {\r
     cso_struct *cso = stream->param;\r
@@ -363,6 +369,7 @@ int pm_close(pm_file *fp)
   {\r
     fclose(fp->file);\r
   }\r
+#ifndef NO_ZLIB\r
   else if (fp->type == PMT_ZIP)\r
   {\r
     ZIP *zipfile = fp->file;\r
@@ -370,6 +377,7 @@ int pm_close(pm_file *fp)
     zipfile->fp = NULL; // gzclose() closed it\r
     closezip(zipfile);\r
   }\r
+#endif\r
   else if (fp->type == PMT_CSO)\r
   {\r
     free(fp->param);\r
@@ -504,7 +512,7 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms)
     bytes_read = pm_read(rom,size,f); // Load up the rom\r
   if (bytes_read <= 0) {\r
     elprintf(EL_STATUS, "read failed");\r
-    free(rom);\r
+    plat_munmap(rom, rom_alloc_size);\r
     return 3;\r
   }\r
 \r