| 174 | } |
| 175 | |
| 176 | bool LoadRAM (char * filepath, bool silent) |
| 177 | { |
| 178 | int offset = 0; |
| 179 | bool retval = false; |
| 180 | int device; |
| 181 | |
| 182 | if(!FindDevice(filepath, &device)) |
| 183 | return 0; |
| 184 | |
| 185 | if(GameInfo->type == GIT_FDS) // RAM saves don't exist for FDS games |
| 186 | return false; |
| 187 | |
| 188 | AllocSaveBuffer (); |
| 189 | |
| 190 | offset = LoadFile(filepath, silent); |
| 191 | |
| 192 | // Check to see if this is a PocketNES save file |
| 193 | if (goomba_is_sram(savebuffer)) |
| 194 | { |
| 195 | void* cleaned = goomba_cleanup(savebuffer); |
| 196 | if (!cleaned) { |
| 197 | ErrorPrompt(goomba_last_error()); |
| 198 | } else if (cleaned != savebuffer) { |
| 199 | memcpy(savebuffer, cleaned, GOOMBA_COLOR_SRAM_SIZE); |
| 200 | free(cleaned); |
| 201 | } |
| 202 | |
| 203 | // Look for just one save file. If there aren't any, or there is more than one, don't read any data. |
| 204 | const stateheader* sh1 = NULL; |
| 205 | const stateheader* sh2 = NULL; |
| 206 | |
| 207 | const stateheader* sh = stateheader_first(savebuffer); |
| 208 | while (sh && stateheader_plausible(sh)) { |
| 209 | if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) { } |
| 210 | else if (sh1 == NULL) { |
| 211 | sh1 = sh; |
| 212 | } |
| 213 | else { |
| 214 | sh2 = sh; |
| 215 | break; |
| 216 | } |
| 217 | sh = stateheader_advance(sh); |
| 218 | } |
| 219 | |
| 220 | if (sh1 == NULL) |
| 221 | { |
| 222 | ErrorPrompt("PocketNES save file has no SRAM."); |
| 223 | offset = 0; |
| 224 | } |
| 225 | else if (sh2 != NULL) |
| 226 | { |
| 227 | ErrorPrompt("PocketNES save file has more than one SRAM."); |
| 228 | offset = 0; |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | goomba_size_t len; |
| 233 | void* extracted = goomba_extract(savebuffer, sh1, &len); |
no test coverage detected