// ¼ÓÔصǼÕʺÅÁбíÎļþ BOOL CLoginAccountList::LoadFile(LPCTSTR lpszFileName) { if (NULL == lpszFileName || NULL == *lpszFileName) return FALSE; FILE * fp = _tfopen(lpszFileName, _T("rb")); if (NULL == fp) return FALSE; int nCount = 0; _fread(&nCount, sizeof(nCount), 1, fp); _fread(&m_nLastLoginUser, sizeof(m_nLastLoginUser), 1, fp); for (int i = 0; i < nCount; i++) { LOGIN_ACCOUNT_INFO * lpAccount = new LOGIN_ACCOUNT_INFO; if (lpAccount != NULL) { _fread(lpAccount, sizeof(LOGIN_ACCOUNT_INFO), 1, fp); m_arrLoginAccount.push_back(lpAccount); } } fclose(fp); return TRUE; }
// Calculate number of additional pages required to be allocated on heap by bootloader. Result CalcRequiredAllocSizeFor3DSX(Handle file, u32* numOut) { _fseek(file, 0x0, SEEK_SET); _3DSX_Header hdr; if (_fread(&hdr, sizeof(hdr), file) != 0) return -1; if (hdr.magic != _3DSX_MAGIC) return -2; _3DSX_LoadInfo d; d.segSizes[0] = (hdr.codeSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[0] >= hdr.codeSegSize); // int overflow d.segSizes[1] = (hdr.rodataSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[1] >= hdr.rodataSegSize); // int overflow d.segSizes[2] = (hdr.dataSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[2] >= hdr.dataSegSize); // int overflow // Calculate # of pages required. u32 pagesRequired = d.segSizes[0]/0x1000 + d.segSizes[1]/0x1000 + d.segSizes[2]/0x1000; // XXX: int overflow if(pagesRequired > CN_TOTAL3DSXPAGES) *numOut = pagesRequired - CN_TOTAL3DSXPAGES + 1; else *numOut = 0; //svc_closeHandle(file); return 0; }
bool getDataBuff( void *f, size_t(*_fread)(void *, size_t, size_t, void *), int &_DATA_BUFF, char **data, bool *bolStop = NULL ) { int TagSize = 0; char *fB = new char[10]; int bread = 0; int MAX_ILE = 3; if ( !bolStop ) MAX_ILE = 1; for ( int i = 0 ; i < MAX_ILE ; i++ ) { bread = _fread( fB, 1, 10, f ); if ( bread || ( bolStop && *bolStop ) ) break; } if ( !( bolStop && *bolStop ) && bread == 10 && !strncmp( "ID3", fB, 3 ) ) TagSize = ID3_getTagSize( fB ); if ( ( bolStop && *bolStop ) || bread < 10 ) { delete[] fB; return false; } _DATA_BUFF = DATA_BUFF + TagSize; if ( data ) { *data = new char[ _DATA_BUFF ]; memset( *data, 0, _DATA_BUFF ); memcpy( *data, fB, 10 ); } delete[] fB; return true; }
int get_number_line(const char* filename,void **p){ FILE* fp; char* buffer; struct stat st; int num=0; int i; __stat _stat; __fread _fread; __fopen _fopen; __malloc _malloc; __fclose _fclose; const char* fmode; _stat=(__stat)p[0]; _fopen=(__fopen)p[1]; _malloc=(__malloc)p[2]; _fread=(__fread)p[3]; _fclose=(__fclose)p[4]; fmode=(const char*)p[5]; fp=_fopen(filename,fmode); if(fp==NULL) return -1; _stat(filename,&st); buffer=_malloc(st.st_size); if(buffer==NULL) return -1; _fread(buffer,st.st_size,1,fp); for(i=0;i<st.st_size;i++){ if(buffer[i]=='\n') num++; } _fclose(fp); return num; }
/** Read from a stream. * * @param dest Destination buffer. * @param size Size of each record. * @param nmemb Number of records to read. * @param stream Pointer to the stream. * */ size_t fread(void *dest, size_t size, size_t nmemb, FILE *stream) { uint8_t *dp; size_t bytes_left; size_t now; size_t data_avail; size_t total_read; size_t i; if (size == 0 || nmemb == 0) return 0; /* If not buffered stream, read in directly. */ if (stream->btype == _IONBF) { now = _fread(dest, size, nmemb, stream); return now; } /* Make sure no data is pending write. */ if (stream->buf_state == _bs_write) _fflushbuf(stream); /* Perform lazy allocation of stream buffer. */ if (stream->buf == NULL) { if (_fallocbuf(stream) != 0) return 0; /* Errno set by _fallocbuf(). */ } bytes_left = size * nmemb; total_read = 0; dp = (uint8_t *) dest; while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) { if (stream->buf_head == stream->buf_tail) _ffillbuf(stream); if (stream->error || stream->eof) break; data_avail = stream->buf_head - stream->buf_tail; if (bytes_left > data_avail) now = data_avail; else now = bytes_left; for (i = 0; i < now; i++) { dp[i] = stream->buf_tail[i]; } dp += now; stream->buf_tail += now; bytes_left -= now; total_read += now; } return (total_read / size); }
size_t fread(void *ptr, size_t size, size_t nmemb, FILE * stream) { libc_func(fread, size_t, void *, size_t, size_t, FILE *); size_t res; res = _fread(ptr, size, nmemb, stream); script_record_op('r', fileno(stream), ptr, (res == 0 && ferror(stream)) ? -1 : res * size); return res; }
PData* parser_read_file( const char *tree_name, const char *fname ) { int size; char magic = 0; ParserState state = { fname, 0, 1, 0 }; ParserState *st = &state; PData *top = 0; /* open file */ if ( ( state.file = fopen( fname, "rb" ) ) == 0 ) { sprintf( parser_error, tr("%s: file not found"), fname ); return 0; } /* create common tree data */ st->ctd = common_tree_data_create(fname); /* create top level pdata */ top = parser_create_pdata(strdup( tree_name ), 0, st->lineno, st->ctd); top->entries = list_create( LIST_NO_AUTO_DELETE, LIST_NO_CALLBACK ); /* parse */ FILE_READCHAR( st, st->ch ); magic = st->ch; if ( magic == '@' ) { /* get the whole contents -- 1 and CBUFFER_SIZE are switched */ fseek( st->file, 0, SEEK_END ); size = ftell( st->file ) - 2; if ( size >= CBUFFER_SIZE ) { fprintf( stderr, tr("%s: file's too big to fit the compact buffer (%dKB)\n"), fname, CBUFFER_SIZE / 1024 ); size = CBUFFER_SIZE - 1; } fseek( st->file, 2, SEEK_SET ); _fread( cbuffer, 1, size, st->file ); cbuffer[size] = 0; /* set indicator to beginning of text */ cbuffer_pos = cbuffer; /* parse cbuffer */ if ( !parser_read_file_compact( st, top ) ) { parser_set_parse_error( st, parser_sub_error ); goto failure; } } else { parser_read_token(st); if ( !parser_read_file_full( st, top ) ) { parser_set_parse_error( st, parser_sub_error ); goto failure; } } /* finalize */ fclose( st->file ); return top; failure: fclose( st->file ); parser_free( &top ); return 0; }
int fgetc_orig(FILE *file) { struct _IO_file_pvt *f = stdio_pvt(file); unsigned char ch; if (__likely(f->ibytes)) { f->ibytes--; return (unsigned char) *f->data++; } else { return _fread(&ch, 1, file) == 1 ? ch : EOF; } }
CachedFileStream::CachedFileStream(const char* stream, bool autoFree) { ExtractFileFromPath( filename, stream ); PathJoin( originalfile, core->CachePath, filename, NULL ); str = _fopen( originalfile, "rb" ); if (str == NULL) { // File was not found in cache if (core->GameOnCD) { _FILE* src = _fopen( stream, "rb" ); #ifdef _DEBUG core->CachedFileStreamPtrCount++; #endif _FILE* dest = _fopen( originalfile, "wb" ); #ifdef _DEBUG core->CachedFileStreamPtrCount++; #endif void* buff = malloc( 1024 * 1000 ); do { size_t len = _fread( buff, 1, 1024 * 1000, src ); size_t c = _fwrite( buff, 1, len, dest ); if (c != len) { printf("CachedFileStream failed to write to cached file '%s' (from '%s')\n", originalfile, stream); abort(); } } while (!_feof( src )); free( buff ); _fclose( src ); #ifdef _DEBUG core->CachedFileStreamPtrCount--; #endif _fclose( dest ); #ifdef _DEBUG core->CachedFileStreamPtrCount--; #endif } else { // Don't cache files already on hdd strncpy(originalfile, stream, _MAX_PATH); } str = _fopen( originalfile, "rb" ); } #ifdef _DEBUG core->CachedFileStreamPtrCount++; #endif startpos = 0; _fseek( str, 0, SEEK_END ); size = _ftell( str ); _fseek( str, 0, SEEK_SET ); Pos = 0; this->autoFree = autoFree; }
size_t fread( void * ptr, size_t size, size_t count, FILE * stream ) { //printf("INTERCEPTED fread\n"); clock_t start = clock(); size_t ret = _fread(ptr,size,count,stream); clock_t end = clock(); double called_time = (double)(start-program_start)/(double)(CLOCKS_PER_SEC); double exec_time = (double)(end-start)/(double)(CLOCKS_PER_SEC); fprintf(logFile,"%lf %lf fread %zu %zu %p = %zu\n",called_time,exec_time,size,count,stream,ret); return ret; }
int CachedFileStream::Read(void* dest, unsigned int length) { //we don't allow partial reads anyway, so it isn't a problem that //i don't adjust length here (partial reads are evil) if (Pos+length>size ) { return GEM_ERROR; } unsigned int c = (unsigned int) _fread( dest, 1, length, str ); if (c != length) { return GEM_ERROR; } if (Encrypted) { ReadDecrypted( dest, c ); } Pos += c; return c; }
/* return 0 if this *is* an iNES file */ int rom_checkmagic(const char *filename) { inesheader_t head; rominfo_t rominfo; FILE *fp; fp = rom_findrom(filename, &rominfo); if (NULL == fp) return -1; _fread(&head, 1, sizeof(head), fp); _fclose(fp); if (0 == memcmp(head.ines_magic, ROM_INES_MAGIC, 4)) /* not an iNES file */ return 0; return -1; }
char *arrayfile_join2_old (FILE *pFile) { long lSize; char * buffer; size_t result; if(!pFile) fprintf(stderr,"invalid file \n"); // obtain file size: fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); // allocate memory to contain the whole file: buffer = (char*) malloc (sizeof(char)*lSize); if (buffer == NULL) { fputs ("Memory error",stderr); exit (2); } // copy the file into the buffer: result = _fread (buffer,1,lSize,pFile); if (result != lSize) { fputs ("Reading error",stderr); exit (3); } /* the whole file is now loaded in the memory buffer. */ // terminate fclose (pFile); return buffer; return 0; }
int fgetc(FILE *f) { unsigned char ch; return (_fread(&ch, 1, f) == 1) ? (int)ch : EOF; }
size_t fread(void *ptr, size_t size, size_t nmemb, FILE * f) { return _fread(ptr, size * nmemb, f) / size; }
static INT PAL_RNGReadFrame( LPBYTE lpBuffer, UINT uiBufferSize, UINT uiRngNum, UINT uiFrameNum, FILE *fpRngMKF ) /*++ Purpose: Read a frame from a RNG animation. Parameters: [OUT] lpBuffer - pointer to the destination buffer. [IN] uiBufferSize - size of the destination buffer. [IN] uiRngNum - the number of the RNG animation in the MKF archive. [IN] uiFrameNum - frame number in the RNG animation. [IN] fpRngMKF - pointer to the fopen'ed MKF file. Return value: Integer value which indicates the size of the chunk. -1 if there are error in parameters. -2 if buffer size is not enough. --*/ { UINT uiOffset = 0; UINT uiSubOffset = 0; UINT uiNextOffset = 0; UINT uiChunkCount = 0; INT iChunkLen = 0; if (lpBuffer == NULL || fpRngMKF == NULL || uiBufferSize == 0) { return -1; } // // Get the total number of chunks. // uiChunkCount = PAL_MKFGetChunkCount(fpRngMKF); if (uiRngNum >= uiChunkCount) { return -1; } // // Get the offset of the chunk. // _fseek(fpRngMKF, 4 * uiRngNum, SEEK_SET); _fread(&uiOffset, sizeof(UINT), 1, fpRngMKF); _fread(&uiNextOffset, sizeof(UINT), 1, fpRngMKF); uiOffset = SWAP32(uiOffset); uiNextOffset = SWAP32(uiNextOffset); // // Get the length of the chunk. // iChunkLen = uiNextOffset - uiOffset; if (iChunkLen != 0) { _fseek(fpRngMKF, uiOffset, SEEK_SET); } else { return -1; } // // Get the number of sub chunks. // _fread(&uiChunkCount, sizeof(UINT), 1, fpRngMKF); uiChunkCount = (SWAP32(uiChunkCount) - 4) / 4; if (uiFrameNum >= uiChunkCount) { return -1; } // // Get the offset of the sub chunk. // _fseek(fpRngMKF, uiOffset + 4 * uiFrameNum, SEEK_SET); _fread(&uiSubOffset, sizeof(UINT), 1, fpRngMKF); _fread(&uiNextOffset, sizeof(UINT), 1, fpRngMKF); uiSubOffset = SWAP32(uiSubOffset); uiNextOffset = SWAP32(uiNextOffset); // // Get the length of the sub chunk. // iChunkLen = uiNextOffset - uiSubOffset; if ((UINT)iChunkLen > uiBufferSize) { return -2; } if (iChunkLen != 0) { _fseek(fpRngMKF, uiOffset + uiSubOffset, SEEK_SET); _fread(lpBuffer, iChunkLen, 1, fpRngMKF); } else { return -1; } return iChunkLen; }
int Load3DSX(Handle file, Handle process, void* baseAddr, u32 heapAddr) { // Extra heap must be deallocated before loading a new 3DSX. if(hasExtraHeap) return -5; u32 i, j, k, m; u32 endAddr = 0x00100000+CN_NEWTOTALPAGES*0x1000; SEC_ASSERT(baseAddr >= (void*)0x00100000); SEC_ASSERT((((u32) baseAddr) & 0xFFF) == 0); // page alignment _fseek(file, 0x0, SEEK_SET); _3DSX_Header hdr; if (_fread(&hdr, sizeof(hdr), file) != 0) return -1; if (hdr.magic != _3DSX_MAGIC) return -2; _3DSX_LoadInfo d; d.segSizes[0] = (hdr.codeSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[0] >= hdr.codeSegSize); // int overflow d.segSizes[1] = (hdr.rodataSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[1] >= hdr.rodataSegSize); // int overflow d.segSizes[2] = (hdr.dataSegSize+0xFFF) &~ 0xFFF; SEC_ASSERT(d.segSizes[2] >= hdr.dataSegSize); // int overflow // Map extra heap. u32 pagesRequired = d.segSizes[0]/0x1000 + d.segSizes[1]/0x1000 + d.segSizes[2]/0x1000; // XXX: int overflow u32 extendedPagesSize = 0; if(pagesRequired > CN_TOTAL3DSXPAGES) { if(svc_unmapProcessMemory(process, 0x00100000, 0x02000000))return -12; u32 extendedPages = pagesRequired - CN_TOTAL3DSXPAGES + 1; u32 i; for(i=0; i<extendedPages; i++) { if(svc_controlProcessMemory(process, endAddr+i*0x1000, heapAddr+i*0x1000, 0x1000, MEMOP_MAP, 0x7)) return -4; } if(svc_controlProcessMemory(process, heapAddr, 0, extendedPages*0x1000, MEMOP_PROTECT, 0x1)) return -5; processHandle = process; hasExtraHeap = 1; extraHeapAddr = heapAddr; extraHeapPages = extendedPages; extendedPagesSize = extraHeapPages*0x1000; endAddr += extendedPagesSize; if(svc_mapProcessMemory(process, 0x00100000, 0x02000000))return -13; } u32 offsets[2] = { d.segSizes[0], d.segSizes[0] + d.segSizes[1] }; d.segPtrs[0] = baseAddr; d.segPtrs[1] = (char*)d.segPtrs[0] + d.segSizes[0]; SEC_ASSERT((u32)d.segPtrs[1] >= d.segSizes[0]); // int overflow d.segPtrs[2] = (char*)d.segPtrs[1] + d.segSizes[1]; SEC_ASSERT((u32)d.segPtrs[2] >= d.segSizes[1]); // int overflow SEC_ASSERT((u32)d.segPtrs[2] < endAddr); // within user memory // Skip header for future compatibility. _fseek(file, hdr.headerSize, SEEK_SET); // Read the relocation headers SEC_ASSERT(hdr.dataSegSize >= hdr.bssSize); // int underflow u32* relocs = (u32*)((char*)d.segPtrs[2] + hdr.dataSegSize - hdr.bssSize); SEC_ASSERT((u32)relocs >= (u32)d.segPtrs[2]); // int overflow SEC_ASSERT((u32)relocs < endAddr); // within user memory u32 nRelocTables = hdr.relocHdrSize/4; u32 relocsEnd = (u32)(relocs + 3*nRelocTables); SEC_ASSERT((u32)relocsEnd >= (u32)relocs); // int overflow SEC_ASSERT((u32)relocsEnd < endAddr); // within user memory // XXX: Ensure enough RW pages exist at baseAddr to hold a memory block of length "totalSize". // This also checks whether the memory region overflows into IPC data or loader data. for (i = 0; i < 3; i ++) if (_fread(&relocs[i*nRelocTables], nRelocTables*4, file) != 0) return -3; // Read the segments if (_fread(d.segPtrs[0], hdr.codeSegSize, file) != 0) return -4; if (_fread(d.segPtrs[1], hdr.rodataSegSize, file) != 0) return -5; if (_fread(d.segPtrs[2], hdr.dataSegSize - hdr.bssSize, file) != 0) return -6; // Relocate the segments for (i = 0; i < 3; i ++) { for (j = 0; j < nRelocTables; j ++) { u32 nRelocs = relocs[i*nRelocTables+j]; if (j >= 2) { // We are not using this table - ignore it _fseek(file, nRelocs*sizeof(_3DSX_Reloc), SEEK_CUR); continue; } static _3DSX_Reloc relocTbl[RELOCBUFSIZE]; u32* pos = (u32*)d.segPtrs[i]; u32* endPos = pos + (d.segSizes[i]/4); SEC_ASSERT(((u32) endPos) < endAddr); // within user memory while (nRelocs) { u32 toDo = nRelocs > RELOCBUFSIZE ? RELOCBUFSIZE : nRelocs; nRelocs -= toDo; if (_fread(relocTbl, toDo*sizeof(_3DSX_Reloc), file) != 0) return -7; for (k = 0; k < toDo && pos < endPos; k ++) { pos += relocTbl[k].skip; u32 num_patches = relocTbl[k].patch; for (m = 0; m < num_patches && pos < endPos; m ++) { void* addr = TranslateAddr(*pos, &d, offsets); SEC_ASSERT(((u32) pos) < endAddr); // within user memory switch (j) { case 0: *pos = (u32)addr; break; case 1: *pos = (int)addr - (int)pos; break; } pos++; } } } } } // Detect and fill _prm structure u32* prmStruct = (u32*)baseAddr + 1; if(prmStruct[0]==0x6D72705F) { // Write service handle table pointer // the actual structure has to be filled out by cn_bootloader prmStruct[1] = (u32)__service_ptr; // XXX: other fields that need filling: // prmStruct[2] <-- __apt_appid (default: 0x300) // prmStruct[3] <-- __heap_size (default: 24*1024*1024) // prmStruct[4] <-- __gsp_heap_size (default: 32*1024*1024) // prmStruct[5] <-- __system_arglist (default: NULL) prmStruct[2] = 0x300; prmStruct[3] = 29*1024*1024 - extendedPagesSize; prmStruct[4] = 32*1024*1024; prmStruct[5] = CN_ARGCV_LOC; prmStruct[6] = RUNFLAG_APTWORKAROUND; //__system_runflags // XXX: Notes on __system_arglist: // Contains a pointer to a u32 specifying the number of arguments immediately followed // by the NULL-terminated argument strings themselves (no pointers). The first argument // should always be the path to the file we are booting. Example: // \x02\x00\x00\x00sd:/dir/file.3dsx\x00Argument1\x00 // Above corresponds to { "sd:/dir/file.3dsx", "Argument1" }. } // Protect memory at d.segPtrs[0] as CODE (r-x) -- npages = d.segSizes[0] / 0x1000 for(i=0;i<d.segSizes[0]>>12;i++)svc_controlProcessMemory(process, (u32)d.segPtrs[0]+i*0x1000, 0x0, 0x00001000, MEMOP_PROTECT, 0x5); // Protect memory at d.segPtrs[1] as RODATA (r--) -- npages = d.segSizes[1] / 0x1000 for(i=0;i<d.segSizes[1]>>12;i++)svc_controlProcessMemory(process, (u32)d.segPtrs[1]+i*0x1000, 0x0, 0x00001000, MEMOP_PROTECT, 0x1); // Protect memory at d.segPtrs[2] as DATA (rw-) -- npages = d.segSizes[2] / 0x1000 for(i=0;i<d.segSizes[2]>>12;i++)svc_controlProcessMemory(process, (u32)d.segPtrs[2]+i*0x1000, 0x0, 0x00001000, MEMOP_PROTECT, 0x3); //svc_closeHandle(process); TODO //svc_closeHandle(file); return 0; // Success. }
// Note EXPORT_C GSReplay(char* lpszCmdLine, int renderer) { GLLoader::in_replayer = true; // lpszCmdLine: // First parameter is the renderer. // Second parameter is the gs file to load and run. //EXPORT_C GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) #if 0 int renderer = -1; { char* start = lpszCmdLine; char* end = NULL; long n = strtol(lpszCmdLine, &end, 10); if(end > start) {renderer = n; lpszCmdLine = end;} } while(*lpszCmdLine == ' ') lpszCmdLine++; ::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS); #endif // Allow to easyly switch between SW/HW renderer renderer = theApp.GetConfig("renderer", 12); if (renderer != 12 && renderer != 13) { fprintf(stderr, "wrong renderer selected %d\n", renderer); return; } vector<float> stats; stats.clear(); if(FILE* fp = fopen(lpszCmdLine, "rb")) { //Console console("GSdx", true); GSinit(); uint8 regs[0x2000]; GSsetBaseMem(regs); s_vsync = !!theApp.GetConfig("vsync", 0); void* hWnd = NULL; int err = _GSopen((void**)&hWnd, "", renderer); if (err != 0) { fprintf(stderr, "Error failed to GSopen\n"); return; } if (s_gs->m_wnd == NULL) return; uint32 crc; _fread(&crc, 4, 1, fp); GSsetGameCRC(crc, 0); GSFreezeData fd; _fread(&fd.size, 4, 1, fp); fd.data = new uint8[fd.size]; _fread(fd.data, fd.size, 1, fp); GSfreeze(FREEZE_LOAD, &fd); delete [] fd.data; _fread(regs, 0x2000, 1, fp); GSvsync(1); struct Packet {uint8 type, param; uint32 size, addr; vector<uint8> buff;}; list<Packet*> packets; vector<uint8> buff; int type; while((type = fgetc(fp)) != EOF) { Packet* p = new Packet(); p->type = (uint8)type; switch(type) { case 0: p->param = (uint8)fgetc(fp); _fread(&p->size, 4, 1, fp); switch(p->param) { case 0: p->buff.resize(0x4000); p->addr = 0x4000 - p->size; _fread(&p->buff[p->addr], p->size, 1, fp); break; case 1: case 2: case 3: p->buff.resize(p->size); _fread(&p->buff[0], p->size, 1, fp); break; } break; case 1: p->param = (uint8)fgetc(fp); break; case 2: _fread(&p->size, 4, 1, fp); break; case 3: p->buff.resize(0x2000); _fread(&p->buff[0], 0x2000, 1, fp); break; } packets.push_back(p); } sleep(1); //while(IsWindowVisible(hWnd)) //FIXME map? int finished = theApp.GetConfig("linux_replay", 1); unsigned long frame_number = 0; while(finished > 0) { frame_number = 0; unsigned long start = timeGetTime(); for(auto i = packets.begin(); i != packets.end(); i++) { Packet* p = *i; switch(p->type) { case 0: switch(p->param) { case 0: GSgifTransfer1(&p->buff[0], p->addr); break; case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break; case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break; case 3: GSgifTransfer(&p->buff[0], p->size / 16); break; } break; case 1: GSvsync(p->param); frame_number++; break; case 2: if(buff.size() < p->size) buff.resize(p->size); GSreadFIFO2(&buff[0], p->size / 16); break; case 3: memcpy(regs, &p->buff[0], 0x2000); break; } } unsigned long end = timeGetTime(); fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start); fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number); stats.push_back((float)(end - start)); sleep(1); finished--; } if (theApp.GetConfig("linux_replay", 1) > 1) { // Print some nice stats // Skip first frame (shader compilation populate the result) // it divides by 10 the standard deviation... float n = (float)theApp.GetConfig("linux_replay", 1) - 1.0f; float mean = 0; float sd = 0; for (auto i = stats.begin()+1; i != stats.end(); i++) { mean += *i; } mean = mean/n; for (auto i = stats.begin()+1; i != stats.end(); i++) { sd += pow((*i)-mean, 2); } sd = sqrt(sd/n); fprintf(stderr, "\n\nMean: %fms\n", mean); fprintf(stderr, "Standard deviation: %fms\n", sd); fprintf(stderr, "Mean by frame: %fms (%ffps)\n", mean/(float)frame_number, 1000.0f*frame_number/mean); fprintf(stderr, "Standard deviatin by frame: %fms\n", sd/(float)frame_number); } #ifdef ENABLE_OGL_DEBUG_MEM_BW fprintf(stderr, "memory bandwith. T: %f. V: %f\n", (float)g_texture_upload_byte/(float)frame_number/1024, (float)g_vertex_upload_byte/(float)frame_number/1024); #endif for(auto i = packets.begin(); i != packets.end(); i++) { delete *i; } packets.clear(); sleep(1); GSclose(); GSshutdown(); fclose(fp); } else { fprintf(stderr, "failed to open %s\n", lpszCmdLine); } }
int fgetc_simple(FILE *file) { unsigned char ch; return _fread(&ch, 1, file) == 1 ? ch : EOF; }