Exemplo n.º 1
0
std::unique_ptr<CISOFileReader> CISOFileReader::Create(File::IOFile file)
{
    CISOHeader header;
    if (file.Seek(0, SEEK_SET) && file.ReadArray(&header, 1) && header.magic == CISO_MAGIC)
        return std::unique_ptr<CISOFileReader>(new CISOFileReader(std::move(file)));

    return nullptr;
}
Exemplo n.º 2
0
static void LogFPSToFile(unsigned long val)
{
	if (!s_bench_file.IsOpen())
		s_bench_file.Open(File::GetUserPath(D_LOGS_IDX) + "fps.txt", "w");

	char buffer[256];
	snprintf(buffer, 256, "%ld\n", val);
	s_bench_file.WriteArray(buffer, strlen(buffer));
}
Exemplo n.º 3
0
void InitFPSCounter()
{
	s_counter = s_fps_last_counter = 0;
	s_fps = 0;
	s_last_update_time = Common::Timer::GetTimeMs();

	if (s_bench_file.IsOpen())
		s_bench_file.Close();
}
Exemplo n.º 4
0
bool IsGCZBlob(File::IOFile& file)
{
  const u64 position = file.Tell();
  if (!file.Seek(0, SEEK_SET))
    return false;
  CompressedBlobHeader header;
  bool is_gcz = file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC;
  file.Seek(position, SEEK_SET);
  return is_gcz;
}
Exemplo n.º 5
0
void StartTrace(bool write)
{
	if (write)
	{
		tracefile.Open("L:\\trace.dat", "wb");
		bReadTrace = false;
		bWriteTrace = true;
	}
	else
	{
		tracefile.Open("L:\\trace.dat", "rb");
		bReadTrace = true;
		bWriteTrace = false;
	}
}
Exemplo n.º 6
0
CChunkFileReader::Error CChunkFileReader::LoadFileHeader(File::IOFile &pFile, SChunkHeader &header, std::string *title) {
	if (!pFile) {
		ERROR_LOG(COMMON, "ChunkReader: Can't open file for reading");
		return ERROR_BAD_FILE;
	}

	const u64 fileSize = pFile.GetSize();
	u64 headerSize = sizeof(SChunkHeader);
	if (fileSize < headerSize) {
		ERROR_LOG(COMMON, "ChunkReader: File too small");
		return ERROR_BAD_FILE;
	}

	if (!pFile.ReadArray(&header, 1)) {
		ERROR_LOG(COMMON, "ChunkReader: Bad header size");
		return ERROR_BAD_FILE;
	}

	if (header.Revision < REVISION_MIN) {
		ERROR_LOG(COMMON, "ChunkReader: Wrong file revision, got %d expected >= %d", header.Revision, REVISION_MIN);
		return ERROR_BAD_FILE;
	}

	if (header.Revision >= REVISION_TITLE) {
		char titleFixed[128];
		if (!pFile.ReadArray(titleFixed, sizeof(titleFixed))) {
			ERROR_LOG(COMMON, "ChunkReader: Unable to read title");
			return ERROR_BAD_FILE;
		}

		if (title) {
			*title = titleFixed;
		}

		headerSize += 128;
	} else if (title) {
		title->clear();
	}

	u32 sz = (u32)(fileSize - headerSize);
	if (header.ExpectedSize != sz) {
		ERROR_LOG(COMMON, "ChunkReader: Bad file size, got %u expected %u", sz, header.ExpectedSize);
		return ERROR_BAD_FILE;
	}

	return ERROR_NONE;
}
Exemplo n.º 7
0
void GetNextBlock(File::IOFile& in, u8* buffer)
{
	u64 CurrentOffset = m_BlockCount * m_BlockSize;
	u64 i = CurrentOffset / CLUSTER_SIZE;

	if (m_isScrubbing && m_FreeTable[i])
	{
		DEBUG_LOG(DISCIO, "Freeing 0x%016" PRIx64, CurrentOffset);
		std::fill(buffer, buffer + m_BlockSize, 0xFF);
		in.Seek(m_BlockSize, SEEK_CUR);
	}
	else
	{
		DEBUG_LOG(DISCIO, "Used    0x%016" PRIx64, CurrentOffset);
		in.ReadBytes(buffer, m_BlockSize);
	}

	m_BlockCount++;
}
Exemplo n.º 8
0
static void ImHere()
{
	static File::IOFile f;
	if (ImHereLog)
	{
		if (!f)
			f.Open("log64.txt", "w");

		fprintf(f.GetHandle(), "%08x\n", PC);
	}
	if (been_here.find(PC) != been_here.end())
	{
		been_here.find(PC)->second++;
		if ((been_here.find(PC)->second) & 1023)
			return;
	}
	DEBUG_LOG(DYNA_REC, "I'm here - PC = %08x , LR = %08x", PC, LR);
	been_here[PC] = 1;
}
Exemplo n.º 9
0
u64 FifoDataFile::WriteMemoryUpdates(const std::vector<MemoryUpdate>& memUpdates,
                                     File::IOFile& file)
{
  // Add space for memory update list
  u64 updateListOffset = file.Tell();
  PadFile(memUpdates.size() * sizeof(FileMemoryUpdate), file);

  for (unsigned int i = 0; i < memUpdates.size(); ++i)
  {
    const MemoryUpdate& srcUpdate = memUpdates[i];

    // Write memory
    file.Seek(0, SEEK_END);
    u64 dataOffset = file.Tell();
    file.WriteBytes(srcUpdate.data.data(), srcUpdate.data.size());

    FileMemoryUpdate dstUpdate;
    dstUpdate.address = srcUpdate.address;
    dstUpdate.dataOffset = dataOffset;
    dstUpdate.dataSize = static_cast<u32>(srcUpdate.data.size());
    dstUpdate.fifoPosition = srcUpdate.fifoPosition;
    dstUpdate.type = srcUpdate.type;

    u64 updateOffset = updateListOffset + (i * sizeof(FileMemoryUpdate));
    file.Seek(updateOffset, SEEK_SET);
    file.WriteBytes(&dstUpdate, sizeof(FileMemoryUpdate));
  }

  return updateListOffset;
}
Exemplo n.º 10
0
void UpdateStateFlags(std::function<void(StateFlags*)> update_function)
{
  const std::string file_path =
    Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + WII_STATE;

  File::IOFile file;
  StateFlags state;
  if (File::Exists(file_path))
  {
    file.Open(file_path, "r+b");
    file.ReadBytes(&state, sizeof(state));
  }
  else
  {
    File::CreateFullPath(file_path);
    file.Open(file_path, "a+b");
    memset(&state, 0, sizeof(state));
  }

  update_function(&state);
  state.UpdateChecksum();

  file.Seek(0, SEEK_SET);
  file.WriteBytes(&state, sizeof(state));
}
Exemplo n.º 11
0
size_t GetNextBlock(File::IOFile& in, u8* buffer)
{
	u64 CurrentOffset = m_BlockCount * m_BlockSize;
	u64 i = CurrentOffset / CLUSTER_SIZE;

	size_t ReadBytes = 0;
	if (m_isScrubbing && m_FreeTable[i])
	{
		DEBUG_LOG(DISCIO, "Freeing 0x%016llx", CurrentOffset);
		std::fill(buffer, buffer + m_BlockSize, 0xFF);
		in.Seek(m_BlockSize, SEEK_CUR);
		ReadBytes = m_BlockSize;
	}
	else
	{
		DEBUG_LOG(DISCIO, "Used    0x%016llx", CurrentOffset);
		in.ReadArray(buffer, m_BlockSize, &ReadBytes);
	}

	m_BlockCount++;
	return ReadBytes;
}
Exemplo n.º 12
0
void FifoDataFile::ReadMemoryUpdates(u64 fileOffset, u32 numUpdates,
                                     std::vector<MemoryUpdate>& memUpdates, File::IOFile& file)
{
  memUpdates.resize(numUpdates);

  for (u32 i = 0; i < numUpdates; ++i)
  {
    u64 updateOffset = fileOffset + (i * sizeof(FileMemoryUpdate));
    file.Seek(updateOffset, SEEK_SET);
    FileMemoryUpdate srcUpdate;
    file.ReadBytes(&srcUpdate, sizeof(FileMemoryUpdate));

    MemoryUpdate& dstUpdate = memUpdates[i];
    dstUpdate.address = srcUpdate.address;
    dstUpdate.fifoPosition = srcUpdate.fifoPosition;
    dstUpdate.data.resize(srcUpdate.dataSize);
    dstUpdate.type = static_cast<MemoryUpdate::Type>(srcUpdate.type);

    file.Seek(srcUpdate.dataOffset, SEEK_SET);
    file.ReadBytes(dstUpdate.data.data(), srcUpdate.dataSize);
  }
}
Exemplo n.º 13
0
void FifoDataFile::PadFile(u32 numBytes, File::IOFile& file)
{
	const u8 zero = 0;
	fwrite(&zero, sizeof(zero), numBytes, file.GetHandle());
}
Exemplo n.º 14
0
BootExecutableReader::BootExecutableReader(File::IOFile file)
{
  file.Seek(0, SEEK_SET);
  m_bytes.resize(file.GetSize());
  file.ReadBytes(m_bytes.data(), m_bytes.size());
}
Exemplo n.º 15
0
bool ImageLoader::ReadPNG(ImageLoaderParams &ImgInfo)
{
	// Set up libpng reading.
	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErrorFn, PNGWarnFn);
	if (!png_ptr)
		return false;
	png_infop info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr)
	{
		png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
		return false;
	}
	png_infop end_info = png_create_info_struct(png_ptr);
	if (!end_info)
	{
		png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
		return false;
	}
	if (setjmp(png_jmpbuf(png_ptr)))
	{
		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
		return false;
	}
	// We read using a FILE*; this could be changed.
	File::IOFile file;
	if (!file.Open(ImgInfo.Path, "rb"))
	{
		return false;
	}
	png_init_io(png_ptr, file.GetHandle());
	png_set_sig_bytes(png_ptr, 0);
	// Process PNG header, etc.
	png_read_info(png_ptr, info_ptr);
	png_uint_32 width, height;
	int bit_depth, color_type, interlace_type, compression_type, filter_method;
	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
	// Force RGB (8 or 16-bit).
	if (color_type == PNG_COLOR_TYPE_PALETTE)
		png_set_palette_to_rgb(png_ptr);
	if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
		png_set_expand_gray_1_2_4_to_8(png_ptr);
	if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
		png_set_gray_to_rgb(png_ptr);
	// Force 8-bit RGB.
	if (bit_depth == 16)
		png_set_strip_16(png_ptr);
	// Force alpha channel (combined with the above, 8-bit RGBA).
	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
		png_set_tRNS_to_alpha(png_ptr);
	else if ((color_type & PNG_COLOR_MASK_ALPHA) == 0)
		png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER);
	png_read_update_info(png_ptr, info_ptr);
	ImgInfo.Width = width;
	ImgInfo.Height = height;
	ImgInfo.data_size = width * height * 4;
	ImgInfo.dst = ImgInfo.request_buffer_delegate(ImgInfo.data_size, false);
	std::vector<u8*> row_pointers(height);
	u8* row_pointer = ImgInfo.dst;
	for (unsigned i = 0; i < height; ++i)
	{
		row_pointers[i] = row_pointer;
		row_pointer += width * 4;
	}
	png_read_image(png_ptr, row_pointers.data());
	png_read_end(png_ptr, end_info);
	png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
	return true;
}
Exemplo n.º 16
0
bool FifoDataFile::Save(const std::string& filename)
{
  File::IOFile file;
  if (!file.Open(filename, "wb"))
    return false;

  // Add space for header
  PadFile(sizeof(FileHeader), file);

  // Add space for frame list
  u64 frameListOffset = file.Tell();
  PadFile(m_Frames.size() * sizeof(FileFrameInfo), file);

  u64 bpMemOffset = file.Tell();
  file.WriteArray(m_BPMem, BP_MEM_SIZE);

  u64 cpMemOffset = file.Tell();
  file.WriteArray(m_CPMem, CP_MEM_SIZE);

  u64 xfMemOffset = file.Tell();
  file.WriteArray(m_XFMem, XF_MEM_SIZE);

  u64 xfRegsOffset = file.Tell();
  file.WriteArray(m_XFRegs, XF_REGS_SIZE);

  u64 texMemOffset = file.Tell();
  file.WriteArray(m_TexMem, TEX_MEM_SIZE);

  // Write header
  FileHeader header;
  header.fileId = FILE_ID;
  header.file_version = VERSION_NUMBER;
  header.min_loader_version = MIN_LOADER_VERSION;

  header.bpMemOffset = bpMemOffset;
  header.bpMemSize = BP_MEM_SIZE;

  header.cpMemOffset = cpMemOffset;
  header.cpMemSize = CP_MEM_SIZE;

  header.xfMemOffset = xfMemOffset;
  header.xfMemSize = XF_MEM_SIZE;

  header.xfRegsOffset = xfRegsOffset;
  header.xfRegsSize = XF_REGS_SIZE;

  header.texMemOffset = texMemOffset;
  header.texMemSize = TEX_MEM_SIZE;

  header.frameListOffset = frameListOffset;
  header.frameCount = (u32)m_Frames.size();

  header.flags = m_Flags;

  file.Seek(0, SEEK_SET);
  file.WriteBytes(&header, sizeof(FileHeader));

  // Write frames list
  for (unsigned int i = 0; i < m_Frames.size(); ++i)
  {
    const FifoFrameInfo& srcFrame = m_Frames[i];

    // Write FIFO data
    file.Seek(0, SEEK_END);
    u64 dataOffset = file.Tell();
    file.WriteBytes(srcFrame.fifoData.data(), srcFrame.fifoData.size());

    u64 memoryUpdatesOffset = WriteMemoryUpdates(srcFrame.memoryUpdates, file);

    FileFrameInfo dstFrame;
    dstFrame.fifoDataSize = static_cast<u32>(srcFrame.fifoData.size());
    dstFrame.fifoDataOffset = dataOffset;
    dstFrame.fifoStart = srcFrame.fifoStart;
    dstFrame.fifoEnd = srcFrame.fifoEnd;
    dstFrame.memoryUpdatesOffset = memoryUpdatesOffset;
    dstFrame.numMemoryUpdates = static_cast<u32>(srcFrame.memoryUpdates.size());

    // Write frame info
    u64 frameOffset = frameListOffset + (i * sizeof(FileFrameInfo));
    file.Seek(frameOffset, SEEK_SET);
    file.WriteBytes(&dstFrame, sizeof(FileFrameInfo));
  }

  if (!file.Close())
    return false;

  return true;
}
Exemplo n.º 17
0
void FifoDataFile::PadFile(size_t numBytes, File::IOFile& file)
{
  for (size_t i = 0; i < numBytes; ++i)
    fputc(0, file.GetHandle());
}
Exemplo n.º 18
0
std::unique_ptr<FifoDataFile> FifoDataFile::Load(const std::string& filename, bool flagsOnly)
{
  File::IOFile file;
  file.Open(filename, "rb");
  if (!file)
    return nullptr;

  FileHeader header;
  file.ReadBytes(&header, sizeof(header));

  if (header.fileId != FILE_ID || header.min_loader_version > VERSION_NUMBER)
  {
    file.Close();
    return nullptr;
  }

  auto dataFile = std::make_unique<FifoDataFile>();

  dataFile->m_Flags = header.flags;
  dataFile->m_Version = header.file_version;

  if (flagsOnly)
  {
    file.Close();
    return dataFile;
  }

  u32 size = std::min<u32>(BP_MEM_SIZE, header.bpMemSize);
  file.Seek(header.bpMemOffset, SEEK_SET);
  file.ReadArray(dataFile->m_BPMem, size);

  size = std::min<u32>(CP_MEM_SIZE, header.cpMemSize);
  file.Seek(header.cpMemOffset, SEEK_SET);
  file.ReadArray(dataFile->m_CPMem, size);

  size = std::min<u32>(XF_MEM_SIZE, header.xfMemSize);
  file.Seek(header.xfMemOffset, SEEK_SET);
  file.ReadArray(dataFile->m_XFMem, size);

  size = std::min<u32>(XF_REGS_SIZE, header.xfRegsSize);
  file.Seek(header.xfRegsOffset, SEEK_SET);
  file.ReadArray(dataFile->m_XFRegs, size);

  // Texture memory saving was added in version 4.
  std::memset(dataFile->m_TexMem, 0, TEX_MEM_SIZE);
  if (dataFile->m_Version >= 4)
  {
    size = std::min<u32>(TEX_MEM_SIZE, header.texMemSize);
    file.Seek(header.texMemOffset, SEEK_SET);
    file.ReadArray(dataFile->m_TexMem, size);
  }

  // Read frames
  for (u32 i = 0; i < header.frameCount; ++i)
  {
    u64 frameOffset = header.frameListOffset + (i * sizeof(FileFrameInfo));
    file.Seek(frameOffset, SEEK_SET);
    FileFrameInfo srcFrame;
    file.ReadBytes(&srcFrame, sizeof(FileFrameInfo));

    FifoFrameInfo dstFrame;
    dstFrame.fifoData.resize(srcFrame.fifoDataSize);
    dstFrame.fifoStart = srcFrame.fifoStart;
    dstFrame.fifoEnd = srcFrame.fifoEnd;

    file.Seek(srcFrame.fifoDataOffset, SEEK_SET);
    file.ReadBytes(dstFrame.fifoData.data(), srcFrame.fifoDataSize);

    ReadMemoryUpdates(srcFrame.memoryUpdatesOffset, srcFrame.numMemoryUpdates,
                      dstFrame.memoryUpdates, file);

    dataFile->AddFrame(dstFrame);
  }

  file.Close();

  return dataFile;
}
Exemplo n.º 19
0
FifoDataFile *FifoDataFile::Load(const std::string &filename, bool flagsOnly)
{
	File::IOFile file;
	file.Open(filename, "rb");
	if (!file)
		return nullptr;

	FileHeader header;
	file.ReadBytes(&header, sizeof(header));

	if (header.fileId != FILE_ID || header.min_loader_version > VERSION_NUMBER)
	{
		file.Close();
		return nullptr;
	}

	FifoDataFile* dataFile = new FifoDataFile;

	dataFile->m_Flags = header.flags;

	if (flagsOnly)
	{
		file.Close();
		return dataFile;
	}

	u32 size = std::min((u32)BP_MEM_SIZE, header.bpMemSize);
	file.Seek(header.bpMemOffset, SEEK_SET);
	file.ReadArray(dataFile->m_BPMem, size);

	size = std::min((u32)CP_MEM_SIZE, header.cpMemSize);
	file.Seek(header.cpMemOffset, SEEK_SET);
	file.ReadArray(dataFile->m_CPMem, size);

	size = std::min((u32)XF_MEM_SIZE, header.xfMemSize);
	file.Seek(header.xfMemOffset, SEEK_SET);
	file.ReadArray(dataFile->m_XFMem, size);

	size = std::min((u32)XF_REGS_SIZE, header.xfRegsSize);
	file.Seek(header.xfRegsOffset, SEEK_SET);
	file.ReadArray(dataFile->m_XFRegs, size);

	// Read frames
	for (u32 i = 0; i < header.frameCount; ++i)
	{
		u64 frameOffset = header.frameListOffset + (i * sizeof(FileFrameInfo));
		file.Seek(frameOffset, SEEK_SET);
		FileFrameInfo srcFrame;
		file.ReadBytes(&srcFrame, sizeof(FileFrameInfo));

		FifoFrameInfo dstFrame;
		dstFrame.fifoData = new u8[srcFrame.fifoDataSize];
		dstFrame.fifoDataSize = srcFrame.fifoDataSize;
		dstFrame.fifoStart = srcFrame.fifoStart;
		dstFrame.fifoEnd = srcFrame.fifoEnd;

		file.Seek(srcFrame.fifoDataOffset, SEEK_SET);
		file.ReadBytes(dstFrame.fifoData, srcFrame.fifoDataSize);

		ReadMemoryUpdates(srcFrame.memoryUpdatesOffset, srcFrame.numMemoryUpdates, dstFrame.memoryUpdates, file);

		dataFile->AddFrame(dstFrame);
	}

	file.Close();

	return dataFile;
}
Exemplo n.º 20
0
int SyncTrace()
{
	if (bWriteTrace)
	{
		tracefile.WriteBytes(&PowerPC::ppcState, stateSize);
		tracefile.Flush();
		return 1;
	}
	if (bReadTrace)
	{
		PowerPC::PowerPCState state;
		if (!tracefile.ReadBytes(&state, stateSize))
			return 1;

		bool difference = false;
		for (int i=0; i<32; i++)
		{
			if (PowerPC::ppcState.gpr[i] != state.gpr[i])
			{
				DEBUG_LOG(POWERPC, "DIFFERENCE - r%i (local %08x, remote %08x)", i, PowerPC::ppcState.gpr[i], state.gpr[i]);
				difference = true;
			}
		}
/*
		for (int i=0; i<32; i++)
		{
			for (int j=0; j<2; j++)
			{
				if (PowerPC::ppcState.ps[i][j] != state.ps[i][j])
				{
					LOG(GEKKO, "DIFFERENCE - ps%i_%i (local %f, remote %f)", i, j, PowerPC::ppcState.ps[i][j], state.ps[i][j]);
					difference = true;
				}
			}
		}*/
		/*
		if (GetCR() != state.cr)
		{
			LOG(GEKKO, "DIFFERENCE - CR (local %08x, remote %08x)", PowerPC::ppcState.cr, state.cr);
			difference = true;
		}
		if (PowerPC::ppcState.pc != state.pc)
		{
			LOG(GEKKO, "DIFFERENCE - PC (local %08x, remote %08x)", PowerPC::ppcState.pc, state.pc);
			difference = true;
		}
		if (PowerPC::ppcState.npc != state.npc)
		{
			LOG(GEKKO, "DIFFERENCE - NPC (local %08x, remote %08x)", PowerPC::ppcState.npc, state.npc);
			difference = true;
		}
		if (PowerPC::ppcState.msr != state.msr)
		{
			LOG(GEKKO, "DIFFERENCE - MSR (local %08x, remote %08x)", PowerPC::ppcState.msr, state.msr);
			difference = true;
		}
		if (PowerPC::ppcState.fpscr != state.fpscr)
		{
			LOG(GEKKO, "DIFFERENCE - FPSCR (local %08x, remote %08x)", PowerPC::ppcState.fpscr, state.fpscr);
			difference = true;
		}
*/
		if (difference)
		{
			Host_UpdateLogDisplay();
			//Also show drec compare window here
			//CDynaViewDlg::Show(true);
			//CDynaViewDlg::ViewAddr(m_BlockStart);
			//CDynaViewDlg::Show(true);
			//PanicAlert("Hang on");
			//Sleep(INFINITE);
			return 0;
		}
		else
		{
			return 1;
			//LOG(GEKKO, "No difference!");
		}
	}
	return 1;

}
Exemplo n.º 21
0
void StopTrace()
{
	tracefile.Close();
}