bool CMemMap::ContextLoad(LSS_FILE *fp) { char teststr[100]="XXXXXXXXXXXXXXXXXXXX"; // First put everything to a known state Reset(); // Read back our parameters if(!lss_read(teststr,sizeof(char),20,fp)) return 0; if(strcmp(teststr,"CMemMap::ContextSave")!=0) return 0; if(!lss_read(&mMikieEnabled,sizeof(ULONG),1,fp)) return 0; if(!lss_read(&mSusieEnabled,sizeof(ULONG),1,fp)) return 0; if(!lss_read(&mRomEnabled,sizeof(ULONG),1,fp)) return 0; if(!lss_read(&mVectorsEnabled,sizeof(ULONG),1,fp)) return 0; // The peek will give us the correct value to put back UBYTE mystate=Peek(0); // Now set to un-initialised so the poke will set correctly mSusieEnabled=-1; mMikieEnabled=-1; mRomEnabled=-1; mVectorsEnabled=-1; // Set banks correctly Poke(0,mystate); return 1; }
bool CRom::ContextLoad(LSS_FILE *fp) { char teststr[100]="XXXXXXXXXXXXXXXXX"; if(!lss_read(teststr,sizeof(char),17,fp)) return 0; if(strcmp(teststr,"CRom::ContextSave")!=0) return 0; if(!lss_read(mRomData,sizeof(UBYTE),ROM_SIZE,fp)) return 0; return 1; }
bool CSystem::ContextLoad(char *context) { LSS_FILE *fp; bool status=1; UBYTE *filememory=NULL; ULONG filesize=0; // First check for ZIP file if(IsZip(context)) { // Find the file and read into memory // Try and find a file in the zip unzFile *fp; unz_file_info info; char filename_buf[0x100], *ptr; bool gotIt; if((fp=(unzFile*)unzOpen(context))!=NULL) { if(unzGoToFirstFile(fp)!=UNZ_OK) { unzClose(fp); gError->Warning("ContextLoad(): ZIP File select problems, could not read zip file"); return 1; } gotIt = FALSE; for (;;) { // Get file descriptor and analyse if(unzGetCurrentFileInfo(fp, &info, filename_buf, 0x100, NULL, 0, NULL, 0) != UNZ_OK) { break; } else { ptr = strchr(filename_buf, '.'); if (ptr != NULL) { char buf[4]; ptr++; buf[0] = tolower(*ptr); ptr++; buf[1] = tolower(*ptr); ptr++; buf[2] = tolower(*ptr); buf[3] = 0; if (!strcmp(buf, "lss")) { // Found a likely file so signal gotIt = TRUE; break; } } // No match so lets try the next file if(unzGoToNextFile(fp)!=UNZ_OK) break; } } // Did we strike gold ? if(gotIt) { if(unzOpenCurrentFile(fp)==UNZ_OK) { // Allocate memory for the rom filesize=info.uncompressed_size; filememory=(UBYTE*) new UBYTE[filesize]; // Read it into memory if(unzReadCurrentFile(fp,filememory,filesize)!=(int)info.uncompressed_size) { unzCloseCurrentFile(fp); unzClose(fp); delete filememory; // Throw a wobbly gError->Warning("ContextLoad(): ZIP File load problems, could not read data from the zip file"); return 1; } // Got it! unzCloseCurrentFile(fp); unzClose(fp); } } else { gError->Warning("ContextLoad(): ZIP File load problems, could not find an LSS file in the zip archive"); return 1; } } else { gError->Warning("ContextLoad(): ZIP File load problems, could not open the zip archive"); return 1; } } else { FILE *fp; // Just open an read into memory if((fp=fopen(context,"rb"))==NULL) status=0; fseek(fp,0,SEEK_END); filesize=ftell(fp); fseek(fp,0,SEEK_SET); filememory=(UBYTE*) new UBYTE[filesize]; if(fread(filememory,sizeof(char),filesize,fp)!=filesize) { fclose(fp); return 1; } fclose(fp); } // Setup our read structure fp = new LSS_FILE; fp->memptr=filememory; fp->index=0; fp->index_limit=filesize; char teststr[100]; // Check identifier if(!lss_read(teststr,sizeof(char),4,fp)) status=0; teststr[4]=0; if(strcmp(teststr,LSS_VERSION)==0 || strcmp(teststr,LSS_VERSION_OLD)==0) { bool legacy=FALSE; if(strcmp(teststr,LSS_VERSION_OLD)==0) { legacy=TRUE; } else { ULONG checksum; // Read CRC32 and check against the CART for a match lss_read(&checksum,sizeof(ULONG),1,fp); if(mCart->CRC32()!=checksum) { delete fp; delete filememory; gError->Warning("LSS Snapshot CRC does not match the loaded cartridge image, aborting load"); return 0; } } // Check our block header if(!lss_read(teststr,sizeof(char),20,fp)) status=0; teststr[20]=0; if(strcmp(teststr,"CSystem::ContextSave")!=0) status=0; if(!lss_read(&mCycleCountBreakpoint,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemCycleCount,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gNextTimerEvent,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gCPUWakeupTime,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gCPUBootAddress,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gIRQEntryCycle,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gBreakpointHit,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSingleStepMode,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemIRQ,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemNMI,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemCPUSleep,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemCPUSleep_Saved,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gSystemHalt,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gThrottleMaxPercentage,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gThrottleLastTimerCount,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gThrottleNextCycleCheckpoint,sizeof(ULONG),1,fp)) status=0; ULONG tmp; if(!lss_read(&tmp,sizeof(ULONG),1,fp)) status=0; gTimerCount=tmp; if(!lss_read(gAudioBuffer,sizeof(UBYTE),HANDY_AUDIO_BUFFER_SIZE,fp)) status=0; if(!lss_read(&gAudioBufferPointer,sizeof(ULONG),1,fp)) status=0; if(!lss_read(&gAudioLastUpdateCycle,sizeof(ULONG),1,fp)) status=0; if(!mMemMap->ContextLoad(fp)) status=0; // Legacy support if(legacy) { if(!mCart->ContextLoadLegacy(fp)) status=0; if(!mRom->ContextLoad(fp)) status=0; } else { if(!mCart->ContextLoad(fp)) status=0; } if(!mRam->ContextLoad(fp)) status=0; if(!mMikie->ContextLoad(fp)) status=0; if(!mSusie->ContextLoad(fp)) status=0; if(!mCpu->ContextLoad(fp)) status=0; } else { gError->Warning("Not a recognised LSS file"); } delete fp; delete filememory; return status; }