Esempio n. 1
0
/**
 * Load json document from memory buffer.
 * @param  osStr    String
 * @return          true on success. If error occurred it can be received using CPLGetLastErrorMsg method.
 *
 * @since GDAL 2.3
 */
bool CPLJSONDocument::LoadMemory(const std::string &osStr)
{
    if( osStr.empty() )
        return false;
    return LoadMemory( reinterpret_cast<const GByte*>(osStr.data()),
                       static_cast<int>(osStr.size()) );
}
Esempio n. 2
0
bool FifoPlayer::Play()
{
	if (!m_File)
		return false;

	if (m_File->GetFrameCount() == 0)
		return false;

	IsPlayingBackFifologWithBrokenEFBCopies = m_File->HasBrokenEFBCopies();

	m_CurrentFrame = m_FrameRangeStart;

	LoadMemory();

	// This loop replaces the CPU loop that occurs when a game is run
	while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
	{
		if (PowerPC::GetState() == PowerPC::CPU_RUNNING)
		{
			if (m_CurrentFrame >= m_FrameRangeEnd)
			{
				if (m_Loop)
				{
					m_CurrentFrame = m_FrameRangeStart;

					PowerPC::ppcState.downcount = 0;
					CoreTiming::Advance();
				}
				else
				{
					PowerPC::Stop();
					Host_Message(WM_USER_STOP);
				}
			}
			else
			{
				if (m_FrameWrittenCb)
					m_FrameWrittenCb();

				if (m_EarlyMemoryUpdates && m_CurrentFrame == m_FrameRangeStart)
					WriteAllMemoryUpdates();

				WriteFrame(m_File->GetFrame(m_CurrentFrame), m_FrameInfo[m_CurrentFrame]);

				++m_CurrentFrame;
			}
		}
	}

	IsPlayingBackFifologWithBrokenEFBCopies = false;

	return true;
}
Esempio n. 3
0
/**
 * Load json document from file by provided path
 * @param  osPath Path to json file.
 * @return         true on success. If error occurred it can be received using CPLGetLastErrorMsg method.
 *
 * @since GDAL 2.3
 */
bool CPLJSONDocument::Load(const std::string &osPath)
{
    GByte *pabyOut = nullptr;
    vsi_l_offset nSize = 0;
    if( !VSIIngestFile( nullptr, osPath.c_str(), &pabyOut, &nSize, 8 * 1024 * 1024) ) // Maximum 8 Mb allowed
    {
        CPLError( CE_Failure, CPLE_FileIO, "Load json file %s failed", osPath.c_str() );
        return false;
    }

    bool bResult = LoadMemory(pabyOut, static_cast<int>(nSize));
    VSIFree(pabyOut);
    return bResult;
}
Esempio n. 4
0
HRESULT TextureClass::beChessBoard(ID3D11Device* device,
                                   ID3D11DeviceContext* context)
{
    HRESULT hr;
    hr = LoadMemory(device, context,
                    defaultWidth,
                    defaultHeight,
                    (void*)defaultData.chessBoardData,
                    sizeof(unsigned char) * defaultWidth * defaultHeight * 4);
    if (FAILED(hr))
    {
        return hr;
    }
    is_init = true;
    return hr;
}
Esempio n. 5
0
HRESULT TextureClass::LoadFile(ID3D11Device* device,
                               ID3D11DeviceContext* context,
                               MutableString&& filename)
{
    HRESULT hr;
    if (SRV != nullptr)
    {
        return E_FAIL;
    }
    std::string filePath = filename.getMultiByteString();
    if (TGA::TgaLoader::getLoader().judgeTga(filePath.c_str()))
    {
        TGA::TgaData data;
        TGALOAD(filePath.c_str(), &data);
        long pixelCount = long(data.getHeight()) * long(data.getWidth());

        hr = LoadMemory(device, context, data.getWidth(), data.getHeight(),
                        data.getColDataPtr(),
                        sizeof(XMFLOAT4)* pixelCount);
        if (FAILED(hr))
        {
            return E_FAIL;
        }
    }
    else
    {
        hr = D3DX11CreateShaderResourceViewFromFile(
                 device,
                 filename.getWideString().c_str(),
                 nullptr,
                 nullptr,
                 &SRV,
                 nullptr);
        if (FAILED(hr))
        {
            return E_FAIL;
        }
    }
    is_init = true;
    return S_OK;
}
Esempio n. 6
0
bool FifoPlayer::Play()
{
	if (!m_File)
		return false;

	if (m_File->GetFrameCount() == 0)
		return false;

	m_CurrentFrame = m_FrameRangeStart;

	LoadMemory();

	// This loop replaces the CPU loop that occurs when a game is run
	while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
	{
		if (PowerPC::GetState() == PowerPC::CPU_RUNNING)
		{
			if (m_CurrentFrame >= m_FrameRangeEnd)
			{
				m_CurrentFrame = m_FrameRangeStart;

				CoreTiming::downcount = 0;
				CoreTiming::Advance();
			}
			else
			{
				if (m_FrameWrittenCb)
					m_FrameWrittenCb();

				if (m_EarlyMemoryUpdates && m_CurrentFrame == m_FrameRangeStart)
					WriteAllMemoryUpdates();

				WriteFrame(m_File->GetFrame(m_CurrentFrame), m_FrameInfo[m_CurrentFrame]);		

				++m_CurrentFrame;
			}
		}
	}

	return true;
}
Esempio n. 7
0
_XFX_BEGIN





//
// Resource
//

HRESULT Resource::LoadFile( const String& file )
{
	PROFILE( __FUNCTION__, "General" );

	mFilename = file;
	mPhysicalPath.clear( );
	gMess( "Loading %s from file \"%s\"...", mName.c_str( ), file.c_str( ) );

	unsigned long filesize;
	HRESULT hr;
	if( FAILED( hr = FileSystem::Instance( ).FindFile( file, NULL, &mPhysicalPath ) ) ||
		FAILED( hr = FileSystem::Instance( ).GetFileSize( file, filesize ) ) )
	{
		gError( "Can't open file \"%s\"", file.c_str( ) );
		return hr;
	}

	boost::scoped_array< BYTE > pbuf( new BYTE[ filesize ] );

	FileSystem::Instance( ).ReadFile( file, pbuf.get( ) );

	if( FAILED( hr = LoadMemory( pbuf.get( ), filesize ) ) )
		gError( "Loading %s from file \"%s\" failed!", mName.c_str( ), file.c_str( ) );

	return hr;
}
Esempio n. 8
0
int main(int argc, char ** argv)
{
	char * binfilename = NULL;
	char * srcfilename = NULL;
	char * base = NULL;
	int i, cycle;
	bus32 tmp;

	bus8 inst_mem[4096];	/* instruction memory */
	bus8 main_mem[4096];	/* main memory */
	bus32 gnd;				/* ground bus signal */
	bus32 pc;				/* program counter */
	bus32 pc4;				/* PC + 4 bus */
	bus32 ir;				/* instruction register */
	bus32 jmp_addr;		/* jump bus */
	bus32 imm_sext;		/* immediate sign extended bus */
	bus32 imm_shext;		/* immediate sign extended shifted bus */
	bus32 branch_addr;	/* branch bus */
	bus32 mbranch_addr;	/* mbranch bus */

	/* control unit signals */
	wire reg_write, reg_dest;
	wire mem_read, mem_write, mem_toreg;
	wire jump, branch;
	wire alu_src;
	bus3 alu_op;

	/* register memory signals & controls */
	bus32 reg_in, reg_out1, reg_out2;
	bus32 reg_write_addr;

	/* main memory signal */
	bus32 mem_out;
	
	/* alu signals */
	wire zero;
	bus32 alu_src_val, alu_out;

	if (argc == 1) {
		fprintf(stderr, "usage: %s <filename>\n", argv[0]);
		return -1;
	}
	
	srcfilename = argv[1];
	base = _parse_filename(srcfilename);
	if (!base) return -1;
	binfilename = malloc(sizeof(char) * (strlen(base) + 5));
	sprintf(binfilename, "%s.bin", base);

	printf("assembling %s to %s...\n", srcfilename, binfilename);
	if (!Assemble(srcfilename, binfilename)) return -1;

	printf("loading %s into memory...\n", binfilename);
	LoadMemory(binfilename, inst_mem);	


	/* load PC with initial VM address of 0x00000000 */
	setbus32(gnd, "00000000000000000000000000000000");
	setbus32(pc, gnd);

	/* initialize memory */
	InitializeRegisterFileAccess();
	for (i=0; i < 4096; i++) setbus8(main_mem[i], "00000000");

   for(cycle=0; ; cycle++) 
	{
		/* load IR with PC value */
		MemoryAccess(ir, pc, gnd, '0', inst_mem); 

		/* report fetched register values */
		printf("cycle: %d, PC: %.32s (%d), IR: %.32s\n\t", cycle, pc, bus32toint(pc), ir);

		/* halt check */
		if (bus32toint(ir) == 0x0000003F) {
			printf("\nmachine halted\n");
			break;
		}
	
		/* PC + 4 data path */
		RCAdder_32(pc4, gnd, pc, "00000000000000000000000000000100", '0');

		/* jump data path */
		shiftleft2x(jmp_addr, ir);
		jmp_addr[0] = pc4[0];
		jmp_addr[1] = pc4[1];
		jmp_addr[2] = pc4[2];
		jmp_addr[3] = pc4[3];

		/* sign extended / shifted immediate data path */
		signextend(imm_sext, &ir[16]); 
		shiftleft2x(imm_shext, imm_sext); 

		/* control unit data path */
		ControlUnit(ir, &ir[26], &reg_write, &reg_dest,
						&mem_read, &mem_write, &mem_toreg, 
						&jump, &branch, &alu_src, alu_op);

		/* register memory data path - read */
		Mux2_5(reg_write_addr, &ir[11], &ir[16], reg_dest);
		RegisterFileAccess(&reg_out1, &reg_out2, &ir[6], &ir[11], reg_write_addr, reg_in, '0');

		/* alu data path */
		Mux2_32(alu_src_val, reg_out2, imm_sext, alu_src);
		zero = ALU(&alu_out, reg_out1, alu_src_val, alu_op);

		/* branch data path */
		RCAdder_32(branch_addr, gnd, pc4, imm_shext, '0');
		Mux2_32(mbranch_addr, pc4, branch_addr, AND2_1(zero, branch));
		Mux2_32(pc, mbranch_addr, jmp_addr, jump);

		/* main memory data path */
		MemoryAccess(mem_out, alu_out, reg_out2, mem_write, main_mem);
		Mux2_32(reg_in, alu_out, mem_out, mem_toreg);

		/* register memory data path - write */
		RegisterFileAccess(&reg_out1, &reg_out2, &ir[6], &ir[11], reg_write_addr, reg_in, reg_write);

		/* dump register memory and signal information */
		for (i=0; i < 14; i++) {
			inttobusn(i, 5, tmp);
			RegisterFileAccess(&reg_out1, &reg_out2, tmp, &ir[11], reg_write_addr, reg_in, '0');
			printf("R%d: %d, ", i, bus32toint(reg_out1));
		}
		printf("\b\b\n\tbranch_addr = %.32s (%d) jmp_addr = %.32s (%d)\n",
			branch_addr, bus32toint(branch_addr), jmp_addr, bus32toint(jmp_addr));
		printf("\topcode = %.6s, imm_sext = %.32s (%d), imm_shext = %.32s (%d), PC+4 = %.32s (%d)\n",
			ir, imm_sext, bus32toint(imm_sext), imm_shext, bus32toint(imm_shext), pc4, bus32toint(pc4));
		printf("\treg_write = %c, reg_dest = %c, mem_read = %c, mem_write = %c, mem_toreg = %c, jump = %c, branch = %c, alu_src = %c, alu_op = %.3s, zero = %c\n",
			reg_write, reg_dest, mem_read, mem_write, mem_toreg, jump, branch, alu_src, alu_op, zero);
		getchar();
	}

	printf("\ntotal no. cycles: %d\n", cycle);

    // report end of program information

	free(binfilename);
}
Esempio n. 9
0
MemoryInputStream::MemoryInputStream(void *udata, size_t usize,
bool freedataptr) :
		data(0), readLeft(usize) {
	LoadMemory(udata, usize, freedataptr);
}