Пример #1
0
bool FreeImageData::loadFile(const std::wstring &filename)
{
    void* theFile;
    void* theMap;
    void* theAddress;
    theFile = CreateFileW(filename.c_str(), GENERIC_READ, 1, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (theFile == INVALID_HANDLE_VALUE)
        return false;

    DWORD size = GetFileSize(theFile, NULL);

    theMap = CreateFileMappingW(theFile, NULL, PAGE_READONLY, 0, 0, NULL);
    if( theMap == NULL )
    {
        CloseHandle(theFile);
        return false;
    }
    theAddress = MapViewOfFile(theMap, FILE_MAP_READ, 0, 0, size);
    if(theAddress == NULL)
    {
        CloseHandle(theMap);
        CloseHandle(theFile);
        return false;
    }

    bool reply = loadMem((unsigned char*)theAddress, size, WStr2Str(filename));

    try{ UnmapViewOfFile(theAddress); } catch(void * /*e*/) {}
    try{ CloseHandle(theMap); } catch(void * /*e*/) {}
    try{ CloseHandle(theFile);} catch(void* /*e*/) {}

    return reply;
}
Пример #2
0
static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name)
{
	char filePath[512];

	const char* shaderPath = "shaders/dx9/";

	switch (bgfx::getRendererType() )
	{
	case bgfx::RendererType::Direct3D11:
		shaderPath = "shaders/dx11/";
		break;

	case bgfx::RendererType::OpenGL:
		shaderPath = "shaders/glsl/";
		break;

	case bgfx::RendererType::OpenGLES:
		shaderPath = "shaders/gles/";
		break;

	default:
		break;
	}

	strcpy(filePath, shaderPath);
	strcat(filePath, _name);
	strcat(filePath, ".bin");

	return bgfx::createShader(loadMem(_reader, filePath) );
}
Пример #3
0
bgfx::ShaderHandle pumpkinLoadShader(bx::FileReaderI* _reader, const char* _name)
{
	char filePath[512];

	std::string shaderPath = "shaders/";//SHADER_FILE_PATH;

	switch (bgfx::getRendererType() )
	{
	case bgfx::RendererType::Noop:
	case bgfx::RendererType::Direct3D9:  shaderPath += "dx9/";   break;
	case bgfx::RendererType::Direct3D11:
	case bgfx::RendererType::Direct3D12: shaderPath += "dx11/";  break;
	case bgfx::RendererType::Gnm:        shaderPath += "pssl/";  break;
	case bgfx::RendererType::Metal:      shaderPath += "metal/"; break;
	case bgfx::RendererType::OpenGL:     shaderPath += "glsl/";  break;
	case bgfx::RendererType::OpenGLES:   shaderPath += "essl/";  break;
	case bgfx::RendererType::Vulkan:     shaderPath += "spirv/"; break;

	case bgfx::RendererType::Count:
		BX_CHECK(false, "You should not be here!");
		break;
	}

	strcpy(filePath, shaderPath.c_str());
	strcat(filePath, _name);
	strcat(filePath, ".bin");

	return bgfx::createShader(loadMem(_reader, filePath) );
}
Пример #4
0
bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info)
{
	char filePath[512];
	strcpy(filePath, "textures/");
	strcat(filePath, _name);

	const bgfx::Memory* mem = loadMem(_reader, filePath);

	return bgfx::createTexture(mem, _flags, _skip, _info);
}
Пример #5
0
void* Sound_Load(Asset &asset) {
	unsigned char *musicbuf;
	auto sz = FS_ReadFile(asset.path, (void **)&musicbuf);

	if (sz <= 0) {
		return nullptr;
	}

	switch (asset.type) {
		case ASSET_SOUND: {
			auto sound = new SoLoud::Wav();
			sound->loadMem(musicbuf, sz, false, true);
			return (void*)sound;
		}

		case ASSET_MOD: {
			auto mod = new SoLoud::Openmpt();
			mod->loadMem(musicbuf, sz, false, true);
			return (void*)mod;
		}
	}

	return nullptr;
}
Пример #6
0
// -----------------------------------------------------------------------------
// Returns the sprite matching [name], loading it from resources if necessary.
// Sprite name also supports wildcards (?)
// -----------------------------------------------------------------------------
const MapTextureManager::Texture& MapTextureManager::sprite(
	std::string_view name,
	std::string_view translation,
	std::string_view palette)
{
	// Don't bother looking for nameless sprites
	if (name.empty())
		return tex_invalid;

	// Get sprite matching name
	/*auto hashname = StrUtil::upper(name);
	if (!translation.empty())
		hashname += StrUtil::lower(translation);
	if (!palette.empty())
		hashname += StrUtil::upper(palette);*/
	auto hashname = fmt::format("{}{}{}", name, translation, palette);
	StrUtil::upperIP(hashname);
	auto& mtex = sprites_[hashname];

	// Get desired filter type
	auto filter = OpenGL::TexFilter::Linear;
	if (map_tex_filter == 0)
		filter = OpenGL::TexFilter::NearestLinearMin;
	else if (map_tex_filter == 1)
		filter = OpenGL::TexFilter::Linear;
	else if (map_tex_filter == 2)
		filter = OpenGL::TexFilter::Linear;
	else if (map_tex_filter == 3)
		filter = OpenGL::TexFilter::NearestMipmap;

	// If the texture is loaded
	if (mtex.gl_id)
	{
		// If the texture filter matches the desired one, return it
		auto& tex_info = OpenGL::Texture::info(mtex.gl_id);
		if (tex_info.filter == filter)
			return mtex;
		else
		{
			// Otherwise, reload the texture
			OpenGL::Texture::clear(mtex.gl_id);
			mtex.gl_id = 0;
		}
	}

	// Sprite not found, look for it
	bool   found  = false;
	bool   mirror = false;
	SImage image;
	// Palette8bit* pal = getResourcePalette();
	auto entry = App::resources().getPatchEntry(name, "sprites", archive_);
	if (!entry)
		entry = App::resources().getPatchEntry(name, "", archive_);
	if (!entry && name.length() == 8)
	{
		std::string newname{ name };
		newname[4] = name[6];
		newname[5] = name[7];
		newname[6] = name[4];
		newname[7] = name[5];
		entry      = App::resources().getPatchEntry(newname, "sprites", archive_);
		if (entry)
			mirror = true;
	}
	if (entry)
	{
		found = true;
		Misc::loadImageFromEntry(&image, entry);
	}
	else // Try composite textures then
	{
		auto ctex = App::resources().getTexture(name, archive_);
		if (ctex && ctex->toImage(image, archive_, palette_.get(), true))
			found = true;
	}

	// We have a valid image either from an entry or a composite texture.
	if (found)
	{
		auto pal = palette_.get();

		// Apply translation
		if (!translation.empty())
			image.applyTranslation(translation, pal, true);

		// Apply palette override
		if (!palette.empty())
		{
			auto newpal = App::resources().getPaletteEntry(palette, archive_);
			if (newpal && newpal->size() == 768)
			{
				pal = image.palette();
				pal->loadMem(newpal->data());
			}
		}

		// Apply mirroring
		if (mirror)
			image.mirror(false);

		// Turn into GL texture
		mtex.gl_id = OpenGL::Texture::createFromImage(image, pal, filter, false);
		return mtex;
	}
	else if (name.back() == '?')
	{
		name.remove_suffix(1);
		auto stex = &sprite(fmt::format("{}0", name), translation, palette);
		if (!stex->gl_id)
			stex = &sprite(fmt::format("{}1", name), translation, palette);
		if (stex->gl_id)
			return *stex;
		if (!stex->gl_id && name.length() == 5)
		{
			for (char chr = 'A'; chr <= ']'; ++chr)
			{
				stex = &sprite(fmt::format("{}0{}0", name, chr), translation, palette);
				if (stex->gl_id)
					return *stex;
				stex = &sprite(fmt::format("{}1{}1", name, chr), translation, palette);
				if (stex->gl_id)
					return *stex;
			}
		}
	}

	return tex_invalid;
}
Пример #7
0
int main(int argc, char **argv)
{
	int cycles_to_run;
	
	char *machine_code; // This will hold our "ASCII Object File"
	
	char debug_command[180]="init";
	char *cmdptr;
	unsigned int dbg_addr;
	
		printf("6502 simulator front end for CS 2208a.\n\n");

		// Did the user specify an object file on the command line?
		// If not... help them.
		if(argc < 3) {
			printf("Usage: %s [ASCII Object File name] [# cycles to simulate] {-d}\n",argv[0]);
			printf(" e.g.: %s test.obj 3000 -d\n\n",argv[0]);
			exit(-1);
		}
	
		// Read the object file into a string.
		machine_code = read_obj_file(argv[1]);
	
	// Fire up the system RAM
	initMem();
	
	// Load the object file from the string into our simulated RAM,
	// starting at memory location 'code_location'.
	loadMem(machine_code,code_location);

		// We did something horribly underhanded in read_obj_file()... 
		// we allocated memory with 'malloc' and then passed back a pointer.
		// But note that the onus is on us, the C programmer, to _remember_ 
		// that we did that and free up the memory when it's no longer needed.
		// Not a big deal here, but imagine a bigger program where you're keeping
		// track of hundreds of mallocs and frees. Now you know why C programs
		// leak memory like the titanic.
		free(machine_code);

	
	// Initialize the 6502
	init6502();
	reset6502();
	
	PC = code_location; // Make sure the program counter points to our code!
	
	
	// All set to run the simulator now!
	
	
	// Everything below is just fanciness to give you a rudimentry 6502 debugger
	// to help with your assignment. Without the fancyness, all we're really doing
	// is one call:
	//
	// exec6502(num_cycles);
	
	
	// Run in debug mode, if requested
	if( (argc > 3) && (!strcmp(argv[3],"-d"))) {

		printf("Running in DEBUG MODE.\n\nType '?' for help.\n");
		
		// Debug loop
		while(strcmp(debug_command,"quit")) {

			
			//dumpMem(0x0021); // Check the value we stored to the zero page
			//dumpMem(0x01FF); // Peek at the top of the stack. Remember, the stack
						     // is hard-coded to addresses $0100–$01FF.
			//dump6502reg();	// print registers to the screen
			
			printf("debug> ");
			
			if( (gets(debug_command))[0] != '\0'){
			
			  cmdptr = strtok(debug_command," ");
			
			  switch(cmdptr[0]) {
			
				case 'p':
					if(cmdptr = strtok(NULL," ")) {
					  sscanf(cmdptr, "%x", &dbg_addr);
					  dumpMem((WORD)dbg_addr);
					}
					break;
				
				case 'r':
					dump6502reg();
					break;
					
				case 's':
					exec6502(1); // Execute 1 command
					break;
					
				case '?':
					printf("\n\np [0xAddress] - print value at memory location\n");
					printf("r - print register values\n");
					printf("s - step through program\n");
					printf("quit - exit\n\n");
					break;
			
				default:
					(cmdptr[0] % 2) ? printf("Herp.\n") : printf("Derp.\n");
					
			  }
			}
						
		}
	} else {
	// Otherwise, run in regular mode.
		exec6502(atoi(argv[2]));
	}
}
Пример #8
0
void DialogDasm::RefreshDasm()
{

    if ( pPC->pCPU->pDEBUG->debugged)
    {
        QString	text;

        if (! IsAdrInList(pPC->pCPU->pDEBUG->DasmAdr))
        {
            if (MaxAdr > pPC->pCPU->pDEBUG->DasmAdr)
            {
                // effacer tout et recommencer au debut
                ui->codelistWidget->clear();

                Index		= 0;
                MaxAdr		= pPC->pCPU->pDEBUG->DasmAdr;
                NextMaxAdr	= pPC->pCPU->pDEBUG->NextDasmAdr;
            }
            else
            {
                if (pPC->pCPU->pDEBUG->DasmAdr > NextMaxAdr)
                {
                    // Insert a separator
                    text = QString("%1:---------------------").arg(pPC->pCPU->pDEBUG->DasmAdr-1,5,16,QChar('0'));
                    QListWidgetItem *item = new QListWidgetItem(text);
                    int adr = pPC->pCPU->pDEBUG->DasmAdr;
                    item->setData(Qt::UserRole,QVariant(adr));
                    ui->codelistWidget->addItem(item);
                    selectRow(ui->codelistWidget->count()-1);

                    NextMaxAdr = pPC->pCPU->pDEBUG->NextDasmAdr;
                    Index++;
                }
                MaxAdr		= pPC->pCPU->pDEBUG->DasmAdr;
                NextMaxAdr	= pPC->pCPU->pDEBUG->NextDasmAdr;
            }

            QListWidgetItem *item = new QListWidgetItem(pPC->pCPU->pDEBUG->Buffer);
            int adr = pPC->pCPU->pDEBUG->DasmAdr;
            item->setData(Qt::UserRole,adr);
            ui->codelistWidget->addItem(item);
            selectRow(ui->codelistWidget->count()-1);
            Index++;
// full until 15 lines
            for (int j=Index;j<15;j++)
            {
                pPC->pCPU->pDEBUG->DisAsm_1(NextMaxAdr);
                MaxAdr		= pPC->pCPU->pDEBUG->DasmAdr;
                NextMaxAdr	= pPC->pCPU->pDEBUG->NextDasmAdr;
                QListWidgetItem *item = new QListWidgetItem(pPC->pCPU->pDEBUG->Buffer);
                int adr = pPC->pCPU->pDEBUG->DasmAdr;
                item->setData(Qt::UserRole,adr);

                ui->codelistWidget->addItem(item);
                Index++;
            }
        }

    }
    if (regwidget) regwidget->refresh();
    loadImem();
    loadMem();

}