more accuracy fixes
[picodrive.git] / Pico / Cart.c
index 0762473..a847088 100644 (file)
@@ -1,7 +1,7 @@
 // This is part of Pico Library\r
 \r
 // (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006 notaz, All rights reserved.\r
+// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas\r
 // Free for non-commercial use.\r
 \r
 // For commercial use, separate licencing terms must be obtained.\r
@@ -12,6 +12,7 @@
 #include "../unzip/unzip.h"\r
 #include "../unzip/unzip_stream.h"\r
 \r
+\r
 static char *rom_exts[] = { "bin", "gen", "smd", "iso" };\r
 \r
 \r
@@ -78,6 +79,9 @@ zip_failed:
   f = fopen(path, "rb");\r
   if (f == NULL) return NULL;\r
 \r
+  /* we use our own buffering */\r
+  setvbuf(f, NULL, _IONBF, 0);\r
+\r
   file = malloc(sizeof(*file));\r
   if (file == NULL) {\r
     fclose(f);\r
@@ -120,10 +124,16 @@ int pm_seek(pm_file *stream, long offset, int whence)
 {\r
   if (stream->type == PMT_UNCOMPRESSED)\r
   {\r
-    return fseek(stream->file, offset, whence);\r
+    fseek(stream->file, offset, whence);\r
+    return ftell(stream->file);\r
   }\r
   else if (stream->type == PMT_ZIP)\r
   {\r
+    if (PicoMessage != NULL && offset > 6*1024*1024) {\r
+      long pos = gztell((gzFile) stream->param);\r
+      if (offset < pos || offset - pos > 6*1024*1024)\r
+        PicoMessage("Decompressing data...");\r
+    }\r
     return gzseek((gzFile) stream->param, offset, whence);\r
   }\r
   else\r
@@ -243,7 +253,10 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize)
 \r
   // Allocate space for the rom plus padding\r
   rom=PicoCartAlloc(size);\r
-  if (rom==NULL) return 1; // { fclose(f); return 1; }\r
+  if (rom==NULL) {\r
+    printf("out of memory (wanted %i)\n", size);\r
+    return 1;\r
+  }\r
 \r
   pm_read(rom,size,f); // Load up the rom\r
 \r