Mercurial > repos > blastem
diff blastem.c @ 1531:092675db4f37
Add support for loading ROMs from zip files
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 24 Mar 2018 15:33:44 -0700 |
parents | f7fe240a7da6 |
children | c59adc305e46 |
line wrap: on
line diff
--- a/blastem.c Fri Mar 23 22:30:02 2018 -0700 +++ b/blastem.c Sat Mar 24 15:33:44 2018 -0700 @@ -24,6 +24,7 @@ #include "arena.h" #include "config.h" #include "menu.h" +#include "zip.h" #define BLASTEM_VERSION "0.5.2-pre" @@ -95,9 +96,48 @@ return readsize; } +uint32_t load_rom_zip(char *filename, void **dst) +{ + static const char *valid_exts[] = {"bin", "md", "gen", "sms", "rom"}; + const uint32_t num_exts = sizeof(valid_exts)/sizeof(*valid_exts); + zip_file *z = zip_open(filename); + if (!z) { + return 0; + } + + for (uint32_t i = 0; i < z->num_entries; i++) + { + char *ext = path_extension(z->entries[i].name); + if (!ext) { + continue; + } + for (uint32_t j = 0; j < num_exts; j++) + { + if (!strcasecmp(ext, valid_exts[j])) { + size_t out_size = nearest_pow2(z->entries[i].size); + *dst = zip_read(z, i, &out_size); + if (*dst) { + free(ext); + zip_close(z); + return out_size; + } + } + } + free(ext); + } + zip_close(z); + return 0; +} + uint32_t load_rom(char * filename, void **dst, system_type *stype) { uint8_t header[10]; + char *ext = path_extension(filename); + if (!strcasecmp(ext, "zip")) { + free(ext); + return load_rom_zip(filename, dst); + } + free(ext); ROMFILE f = romopen(filename, "rb"); if (!f) { return 0;