long GBAMethods::FindFreeSpace(long bNo, u8 bConst){//bNo is how many bytes, bConst is what //value to look for // returns offset of "free space" block // or -1 if no such block found FILE* file = fopen(GBA.FileLoc,"rb"); if(!file) return -1; bNo+=0x100;//Look for an extra free 256 bytes. -- still not sure what this does, // but whatever int ch; long runstart = -1; long runcount = 0; while(1) { ch = fgetc(file); // get character (byte) if(ch == EOF) // if end of file { runstart = -1; // eof reached before we found block break; } if((u8)ch == bConst) { if(!runcount) // start of run runstart = (long)ftell(file) - 1; ++runcount; if(runcount >= bNo) // block found break; } else { runstart = -1; runcount = 0; } } fclose(file); return runstart; }