MCPcopy Create free account
hub / github.com/dborth/fceugx / LoadRAM

Function LoadRAM

source/fceuram.cpp:176–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool 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);

Callers 2

LoadRAMAutoFunction · 0.85
MenuGameSavesFunction · 0.85

Calls 15

FindDeviceFunction · 0.85
AllocSaveBufferFunction · 0.85
LoadFileFunction · 0.85
goomba_is_sramFunction · 0.85
goomba_cleanupFunction · 0.85
ErrorPromptFunction · 0.85
goomba_last_errorFunction · 0.85
stateheader_firstFunction · 0.85
stateheader_plausibleFunction · 0.85
little_endian_conv_16Function · 0.85
stateheader_advanceFunction · 0.85
goomba_extractFunction · 0.85

Tested by

no test coverage detected