void ROM::mem_init(const char *filename, int fileoffset, int memoffset, int size) { sc_bv<8> byte; int addr = memoffset; int c; ifstream memf(filename, ios::in | ios::binary); memf.seekg(fileoffset); while (!memf.eof() && size > 0) { c = memf.get(); if (memf.eof()) break; byte = c; mem[addr] = byte; addr++; size--; if (addr >= ROMSIZE) break; } memf.close(); }
int CMLODFile::Read(CFile *in) { size = (int)in->SeekToEnd(); in->SeekToBegin(); if (size == 0) return 0; if (data != NULL) delete[] data; data = new unsigned char[size]; UINT bytes_read = in->Read(data, size); CMemFile memf(data, size, 0); p3d_header header; memf.Read(&header, sizeof(p3d_header)); textureList.RemoveAll(); for (int l = 0; l < header.lodcount; l++) { lod_header lodheader; memf.Read(&lodheader, sizeof(lod_header)); // skip vertex & normal data memf.Seek(lodheader.vertices * 16 + lodheader.normals * 12, CMemFile::current); for (int f = 0; f < lodheader.polygons; f++) { poly_data poly; int pos = (int)memf.GetPosition(); unsigned char *strpos = data + pos; textureList.AddTail(strpos); memf.Read(&poly, sizeof(poly_data)); } // skip "TAGG" marker memf.Seek(4, CMemFile::current); tag_header tag; do { memf.Read(&tag, sizeof(tag_header)); memf.Seek(tag.size, CMemFile::current); } while (strncmp(tag.name, "#EndOfFile#", 63) != 0); // skip lod resolution memf.Seek(4, CMemFile::current); } memf.Close(); return size; }
void ROM::mem_dump(const char *filename, int memoffset, int size) { ofstream memf(filename, ios::out | ios::binary); int addr = memoffset; unsigned char c; sc_uint<8> a; while (addr < ROMSIZE && size > 0) { a = mem[addr]; c = a; memf.put(c); addr++; size--; } memf.close(); }