Mercurial > repos > blastem
comparison 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 |
comparison
equal
deleted
inserted
replaced
1530:00d788dac91a | 1531:092675db4f37 |
---|---|
22 #include "romdb.h" | 22 #include "romdb.h" |
23 #include "terminal.h" | 23 #include "terminal.h" |
24 #include "arena.h" | 24 #include "arena.h" |
25 #include "config.h" | 25 #include "config.h" |
26 #include "menu.h" | 26 #include "menu.h" |
27 #include "zip.h" | |
27 | 28 |
28 #define BLASTEM_VERSION "0.5.2-pre" | 29 #define BLASTEM_VERSION "0.5.2-pre" |
29 | 30 |
30 #ifdef __ANDROID__ | 31 #ifdef __ANDROID__ |
31 #define FULLSCREEN_DEFAULT 1 | 32 #define FULLSCREEN_DEFAULT 1 |
93 *buffer = dst; | 94 *buffer = dst; |
94 | 95 |
95 return readsize; | 96 return readsize; |
96 } | 97 } |
97 | 98 |
99 uint32_t load_rom_zip(char *filename, void **dst) | |
100 { | |
101 static const char *valid_exts[] = {"bin", "md", "gen", "sms", "rom"}; | |
102 const uint32_t num_exts = sizeof(valid_exts)/sizeof(*valid_exts); | |
103 zip_file *z = zip_open(filename); | |
104 if (!z) { | |
105 return 0; | |
106 } | |
107 | |
108 for (uint32_t i = 0; i < z->num_entries; i++) | |
109 { | |
110 char *ext = path_extension(z->entries[i].name); | |
111 if (!ext) { | |
112 continue; | |
113 } | |
114 for (uint32_t j = 0; j < num_exts; j++) | |
115 { | |
116 if (!strcasecmp(ext, valid_exts[j])) { | |
117 size_t out_size = nearest_pow2(z->entries[i].size); | |
118 *dst = zip_read(z, i, &out_size); | |
119 if (*dst) { | |
120 free(ext); | |
121 zip_close(z); | |
122 return out_size; | |
123 } | |
124 } | |
125 } | |
126 free(ext); | |
127 } | |
128 zip_close(z); | |
129 return 0; | |
130 } | |
131 | |
98 uint32_t load_rom(char * filename, void **dst, system_type *stype) | 132 uint32_t load_rom(char * filename, void **dst, system_type *stype) |
99 { | 133 { |
100 uint8_t header[10]; | 134 uint8_t header[10]; |
135 char *ext = path_extension(filename); | |
136 if (!strcasecmp(ext, "zip")) { | |
137 free(ext); | |
138 return load_rom_zip(filename, dst); | |
139 } | |
140 free(ext); | |
101 ROMFILE f = romopen(filename, "rb"); | 141 ROMFILE f = romopen(filename, "rb"); |
102 if (!f) { | 142 if (!f) { |
103 return 0; | 143 return 0; |
104 } | 144 } |
105 if (sizeof(header) != romread(header, 1, sizeof(header), f)) { | 145 if (sizeof(header) != romread(header, 1, sizeof(header), f)) { |