X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcart.c;h=9dce38d98ea27c629b889c21c50cc01c57949288;hb=653f0b1399313ecef86d99a2552f40fb9e51b820;hp=debb8a2c048142a63b8ae3468806b3def92f3a02;hpb=30f0fdd42279a99893034a5d21b64439536c60aa;p=picodrive.git diff --git a/pico/cart.c b/pico/cart.c index debb8a2..9dce38d 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -8,10 +8,9 @@ */ #include "pico_int.h" -#include "../zlib/zlib.h" #include "../cpu/debug.h" #include "../unzip/unzip.h" -#include "../unzip/unzip_stream.h" +#include static int rom_alloc_size; @@ -23,6 +22,8 @@ void (*PicoCartMemSetup)(void); void (*PicoCartLoadProgressCB)(int percent) = NULL; void (*PicoCDLoadProgressCB)(const char *fname, int percent) = NULL; // handled in Pico/cd/cd_file.c +int PicoGameLoaded; + static void PicoCartDetect(const char *carthw_cfg); /* cso struct */ @@ -48,7 +49,7 @@ typedef struct _cso_struct } cso_struct; -static int uncompress2(void *dest, int destLen, void *source, int sourceLen) +static int uncompress_buf(void *dest, int destLen, void *source, int sourceLen) { z_stream stream; int err; @@ -98,6 +99,7 @@ pm_file *pm_open(const char *path) return NULL; ext = get_ext(path); +#ifndef NO_ZLIB if (strcasecmp(ext, "zip") == 0) { struct zipent *zipentry; @@ -147,7 +149,9 @@ zip_failed: return NULL; } } - else if (strcasecmp(ext, "cso") == 0) + else +#endif + if (strcasecmp(ext, "cso") == 0) { cso_struct *cso = NULL, *tmp = NULL; int size; @@ -155,7 +159,7 @@ zip_failed: if (f == NULL) goto cso_failed; -#ifndef __EPOC32__ +#ifdef __GP2X__ /* we use our own buffering */ setvbuf(f, NULL, _IONBF, 0); #endif @@ -225,7 +229,7 @@ cso_failed: strncpy(file->ext, ext, sizeof(file->ext) - 1); fseek(f, 0, SEEK_SET); -#ifndef __EPOC32__ // makes things worse on Symbian +#ifdef __GP2X__ if (file->size > 0x400000) /* we use our own buffering */ setvbuf(f, NULL, _IONBF, 0); @@ -242,6 +246,7 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream) { ret = fread(ptr, 1, bytes, stream->file); } +#ifndef NO_ZLIB else if (stream->type == PMT_ZIP) { gzFile gf = stream->param; @@ -252,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 */ gzrewind(gf); } +#endif else if (stream->type == PMT_CSO) { cso_struct *cso = stream->param; @@ -291,7 +297,7 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream) } cso->block_in_buff = block; } - rret = uncompress2(tmp_dst, 2048, cso->in_buff, read_len); + rret = uncompress_buf(tmp_dst, 2048, cso->in_buff, read_len); if (rret != 0) { elprintf(EL_STATUS, "cso: uncompress failed @ %08x with %i", read_pos, rret); break; @@ -327,6 +333,7 @@ int pm_seek(pm_file *stream, long offset, int whence) fseek(stream->file, offset, whence); return ftell(stream->file); } +#ifndef NO_ZLIB else if (stream->type == PMT_ZIP) { if (PicoMessage != NULL && offset > 6*1024*1024) { @@ -336,6 +343,7 @@ int pm_seek(pm_file *stream, long offset, int whence) } return gzseek((gzFile) stream->param, offset, whence); } +#endif else if (stream->type == PMT_CSO) { cso_struct *cso = stream->param; @@ -361,6 +369,7 @@ int pm_close(pm_file *fp) { fclose(fp->file); } +#ifndef NO_ZLIB else if (fp->type == PMT_ZIP) { ZIP *zipfile = fp->file; @@ -368,6 +377,7 @@ int pm_close(pm_file *fp) zipfile->fp = NULL; // gzclose() closed it closezip(zipfile); } +#endif else if (fp->type == PMT_CSO) { free(fp->param); @@ -502,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 if (bytes_read <= 0) { elprintf(EL_STATUS, "read failed"); - free(rom); + plat_munmap(rom, rom_alloc_size); return 3; } @@ -592,6 +602,7 @@ int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_ else PicoPower(); + PicoGameLoaded = 1; return 0; } @@ -621,6 +632,7 @@ void PicoCartUnload(void) plat_munmap(Pico.rom, rom_alloc_size); Pico.rom = NULL; } + PicoGameLoaded = 0; } static unsigned int rom_crc32(void) @@ -639,6 +651,8 @@ static int rom_strcmp(int rom_offset, const char *s1) { int i, len = strlen(s1); const char *s_rom = (const char *)Pico.rom; + if (rom_offset + len > Pico.romsize) + return 0; for (i = 0; i < len; i++) if (s1[i] != s_rom[(i + rom_offset) ^ 1]) return 1; @@ -705,21 +719,45 @@ static int is_expr(const char *expr, char **pr) return 1; } +#include "carthw_cfg.c" + static void parse_carthw(const char *carthw_cfg, int *fill_sram) { int line = 0, any_checks_passed = 0, skip_sect = 0; + const char *s, *builtin = builtin_carthw_cfg; int tmp, rom_crc = 0; char buff[256], *p, *r; FILE *f; f = fopen(carthw_cfg, "r"); - if (f == NULL) { + if (f == NULL) + f = fopen("pico/carthw.cfg", "r"); + if (f == NULL) elprintf(EL_STATUS, "couldn't open carthw.cfg!"); - return; - } - while ((p = fgets(buff, sizeof(buff), f))) + for (;;) { + if (f != NULL) { + p = fgets(buff, sizeof(buff), f); + if (p == NULL) + break; + } + else { + if (*builtin == 0) + break; + for (s = builtin; *s != 0 && *s != '\n'; s++) + ; + while (*s == '\n') + s++; + tmp = s - builtin; + if (tmp > sizeof(buff) - 1) + tmp = sizeof(buff) - 1; + memcpy(buff, builtin, tmp); + buff[tmp] = 0; + p = buff; + builtin = s; + } + line++; p = sskip(p); if (*p == 0 || *p == '#') @@ -869,10 +907,13 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) SRam.flags &= ~SRF_EEPROM; else if (strcmp(p, "filled_sram") == 0) *fill_sram = 1; + else if (strcmp(p, "force_6btn") == 0) + PicoQuirks |= PQUIRK_FORCE_6BTN; else { elprintf(EL_STATUS, "carthw:%d: unsupported prop: %s", line, p); goto bad_nomsg; } + elprintf(EL_STATUS, "game prop: %s", p); continue; } else if (is_expr("eeprom_type", &p)) { @@ -930,7 +971,9 @@ no_checks: skip_sect = 1; continue; } - fclose(f); + + if (f != NULL) + fclose(f); } /* @@ -995,3 +1038,4 @@ static void PicoCartDetect(const char *carthw_cfg) *(int *) (Pico.rom + 0x1f0) = 0x20204520; } +// vim:shiftwidth=2:expandtab