void (*PicoCartLoadProgressCB)(int percent) = NULL;\r
void (*PicoCDLoadProgressCB)(int percent) = NULL; // handled in Pico/cd/cd_file.c\r
\r
+/* cso struct */\r
+typedef struct _cso_struct\r
+{\r
+ unsigned char in_buff[2*2048];\r
+ unsigned char out_buff[2048];\r
+ struct {\r
+ char magic[4];\r
+ unsigned int unused;\r
+ unsigned int total_bytes;\r
+ unsigned int total_bytes_high; // ignored here\r
+ unsigned int block_size; // 10h\r
+ unsigned char ver;\r
+ unsigned char align;\r
+ unsigned char reserved[2];\r
+ } header;\r
+ unsigned int fpos_in; // input file read pointer\r
+ unsigned int fpos_out; // pos in virtual decompressed file\r
+ int block_in_buff; // block which we have read in in_buff\r
+ int pad;\r
+ int index[0];\r
+}\r
+cso_struct;\r
+\r
+static int uncompress2(void *dest, int destLen, void *source, int sourceLen)\r
+{\r
+ z_stream stream;\r
+ int err;\r
+\r
+ stream.next_in = (Bytef*)source;\r
+ stream.avail_in = (uInt)sourceLen;\r
+ stream.next_out = dest;\r
+ stream.avail_out = (uInt)destLen;\r
+\r
+ stream.zalloc = NULL;\r
+ stream.zfree = NULL;\r
+\r
+ err = inflateInit2(&stream, -15);\r
+ if (err != Z_OK) return err;\r
+\r
+ err = inflate(&stream, Z_FINISH);\r
+ if (err != Z_STREAM_END) {\r
+ inflateEnd(&stream);\r
+ return err;\r
+ }\r
+ //*destLen = stream.total_out;\r
+\r
+ return inflateEnd(&stream);\r
+}\r
\r
pm_file *pm_open(const char *path)\r
{\r
return NULL;\r
}\r
}\r
+ else if (ext && strcasecmp(ext, "cso") == 0)\r
+ {\r
+ cso_struct *cso = NULL, *tmp = NULL;\r
+ int size;\r
+ f = fopen(path, "rb");\r
+ if (f == NULL)\r
+ goto cso_failed;\r
+\r
+ cso = malloc(sizeof(*cso));\r
+ if (cso == NULL)\r
+ goto cso_failed;\r
+\r
+ if (fread(&cso->header, 1, sizeof(cso->header), f) != sizeof(cso->header))\r
+ goto cso_failed;\r
+\r
+ if (strncmp(cso->header.magic, "CISO", 4) != 0) {\r
+ elprintf(EL_STATUS, "cso: bad header");\r
+ goto cso_failed;\r
+ }\r
+\r
+ if (cso->header.block_size != 2048) {\r
+ elprintf(EL_STATUS, "cso: bad block size (%u)", cso->header.block_size);\r
+ goto cso_failed;\r
+ }\r
+\r
+ size = ((cso->header.total_bytes >> 11) + 1)*4 + sizeof(*cso);\r
+ tmp = realloc(cso, size);\r
+ if (tmp == NULL)\r
+ goto cso_failed;\r
+ cso = tmp;\r
+ elprintf(EL_STATUS, "allocated %i bytes for CSO struct", size);\r
+\r
+ size -= sizeof(*cso); // index size\r
+ if (fread(cso->index, 1, size, f) != size) {\r
+ elprintf(EL_STATUS, "cso: premature EOF");\r
+ goto cso_failed;\r
+ }\r
+\r
+ // all ok\r
+ cso->fpos_in = ftell(f);\r
+ cso->fpos_out = 0;\r
+ cso->block_in_buff = -1;\r
+ file = malloc(sizeof(*file));\r
+ if (file == NULL) goto cso_failed;\r
+ file->file = f;\r
+ file->param = cso;\r
+ file->size = cso->header.total_bytes;\r
+ file->type = PMT_CSO;\r
+ return file;\r
+\r
+cso_failed:\r
+ if (cso != NULL) free(cso);\r
+ if (f != NULL) fclose(f);\r
+ return NULL;\r
+ }\r
\r
/* not a zip, treat as uncompressed file */\r
f = fopen(path, "rb");\r
/* we must reset stream pointer or else next seek/read fails */\r
gzrewind(gf);\r
}\r
+ else if (stream->type == PMT_CSO)\r
+ {\r
+ cso_struct *cso = stream->param;\r
+ int read_pos, read_len, out_offs, rret;\r
+ int block = cso->fpos_out >> 11;\r
+ int index = cso->index[block];\r
+ int index_end = cso->index[block+1];\r
+ unsigned char *out = ptr, *tmp_dst;\r
+\r
+ ret = 0;\r
+ while (bytes != 0)\r
+ {\r
+ out_offs = cso->fpos_out&0x7ff;\r
+ if (out_offs == 0 && bytes >= 2048)\r
+ tmp_dst = out;\r
+ else tmp_dst = cso->out_buff;\r
+\r
+ read_pos = (index&0x7fffffff) << cso->header.align;\r
+\r
+ if (index < 0) {\r
+ if (read_pos != cso->fpos_in)\r
+ fseek(stream->file, read_pos, SEEK_SET);\r
+ rret = fread(tmp_dst, 1, 2048, stream->file);\r
+ cso->fpos_in = read_pos + rret;\r
+ if (rret != 2048) break;\r
+ } else {\r
+ read_len = (((index_end&0x7fffffff) << cso->header.align) - read_pos) & 0xfff;\r
+ if (block != cso->block_in_buff)\r
+ {\r
+ if (read_pos != cso->fpos_in)\r
+ { fseek(stream->file, read_pos, SEEK_SET); printf("seek %i\n", read_pos); }\r
+ rret = fread(cso->in_buff, 1, read_len, stream->file);\r
+ cso->fpos_in = read_pos + rret;\r
+ if (rret != read_len) {\r
+ elprintf(EL_STATUS, "cso: read failed @ %08x", read_pos);\r
+ break;\r
+ }\r
+ cso->block_in_buff = block;\r
+ }\r
+ rret = uncompress2(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
+ }\r
+ }\r
+\r
+ rret = 2048;\r
+ if (out_offs != 0 || bytes < 2048) {\r
+ //elprintf(EL_STATUS, "cso: unaligned/nonfull @ %08x, offs=%i, len=%u", cso->fpos_out, out_offs, bytes);\r
+ if (bytes < rret) rret = bytes;\r
+ if (2048 - out_offs < rret) rret = 2048 - out_offs;\r
+ memcpy(out, tmp_dst + out_offs, rret);\r
+ }\r
+ ret += rret;\r
+ out += rret;\r
+ cso->fpos_out += rret;\r
+ bytes -= rret;\r
+ block++;\r
+ index = index_end;\r
+ index_end = cso->index[block+1];\r
+ }\r
+ }\r
else\r
ret = 0;\r
\r
}\r
return gzseek((gzFile) stream->param, offset, whence);\r
}\r
+ else if (stream->type == PMT_CSO)\r
+ {\r
+ cso_struct *cso = stream->param;\r
+ switch (whence)\r
+ {\r
+ case SEEK_CUR: cso->fpos_out += offset; break;\r
+ case SEEK_SET: cso->fpos_out = offset; break;\r
+ case SEEK_END: cso->fpos_out = cso->header.total_bytes - offset; break;\r
+ }\r
+ return cso->fpos_out;\r
+ }\r
else\r
return -1;\r
}\r
zipfile->fp = NULL; // gzclose() closed it\r
closezip(zipfile);\r
}\r
+ else if (fp->type == PMT_CSO)\r
+ {\r
+ free(fp->param);\r
+ fclose(fp->file);\r
+ }\r
else\r
ret = EOF;\r
\r
}\r
else if ( name_cmp("MICRO MACHINES II") == 0 ||\r
(name_cmp(" ") == 0 && // Micro Machines {Turbo Tournament '96, Military - It's a Blast!}\r
- (csum == 0x165e || csum == 0x168b || csum == 0xCEE0 || csum == 0x2C41)))\r
+ (csum == 0x165e || csum == 0x168b || csum == 0xCEE0 || csum == 0x2C41)))\r
{\r
SRam.start = 0x300000;\r
SRam.end = 0x380001;\r
Be sure NOT to use anything but classic mp3 format (don't use things like\r
mp3pro).\r
\r
-ISO files can also be zipped (but not mp3 files, as they are already\r
-compressed). Note that this can cause very long loading times, which may\r
-take up to several minutes. File naming is similar as with uncompressed ISOs.\r
+ISO files can also be .cso compressed or zipped (but not mp3 files, as they\r
+are already compressed). CSO will cause slightly longer loading times, and\r
+is not very good for FMV games. Zipping ISOs is not recommened, as it will\r
+cause very long (several minute) loading times, and make some games\r
+unplayable. File naming is similar as with uncompressed ISOs.\r
Example:\r
\r
-SonicCD.zip data track\r
+SonicCD.cso data track\r
SonicCD_02.mp3 audio track 1 (CD track 2)\r
SonicCD_03.mp3\r
...\r
Incorrectly named/missing mp3s may also be the cause.\r
* Sega/Mega CD: If the background music is missing, you might have named your\r
MP3s incorrectly. Read "How to run Sega/Mega CD games" section again.\r
-* Sega/Mega CD: If the game music plays too fast or too slow, you have encoded\r
- your MP3s incorrectly. You will have to re-encode and/or resample them.\r
+* Sega/Mega CD: If the game music plays too fast/too slow/out of sync, you have\r
+ encoded your MP3s incorrectly. You will have to re-encode and/or resample them.\r
PicoDrive is not a mp3 player, so all mp3s MUST be encoded at 44.1kHz stereo.\r
Badly encoded mp3s can cause various kind of problems, like noises, incorrect\r
playback speeds, not repeating music or even prevent game from starting.\r
+ Some games (like Snatcher) may hang in certain scenes because of this.\r
+ Some mp3 rippers/encoders remove silence and beginning/end of audio tracks,\r
+ what causes audio desyncs and/or mentioned problems.\r
* Sega/Mega CD: If your games hangs at the BIOS screen (with planets shown),\r
you may be using a bad BIOS dump. Try another from a different source.\r
* Some Sega/Mega CD games don't use Z80 for anything, but they leave it active,\r
1.35b\r
* PSP: mp3 code should no longer fail on 1.5 firmware.\r
+ PSP: added gamma adjustment option.\r
+ + Added .cso format support. Useful for non-FMV games.\r
* Fixed a sram bug in memhandlers (fixes Shining in the Darkness saves).\r
* PSP: fixed another bug in memhanlers, which crashed the emu for some games\r
(like NBA Jam).\r