⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loader.cpp

📁 浙江大学的悟空嵌入式系统模拟器
💻 CPP
字号:
/*
*  Copyright (c) 2005 Zhejiang University, P.R.China
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ 

//=============================================================================
/**
*  \file    Arch/MU0/Loader.cpp
*
*  $Id: Loader.cpp,v 1.1 2005/02/19 12:10:05 kehc Exp $
*
*  \author  Huacheng Ke <sese_zju@yahoo.com.cn>
*/
//=============================================================================

#include "stdafx.h"
#include "./Loader.h"
#include <Core/Memory.h>

#include <fstream>

namespace MU0 {

	Loader::Loader(void)
	{
	}

	bool Loader::load_binary(std::string filepath)
	{
		std::ifstream fs((const char *)filepath.c_str());
		if (fs.fail())
		{
			return false;
		}
		
		char magic[4];
		magic[3] = 0;
		fs.read(magic, 3);

		if (strcmp(magic, "MU0"))
		{
			return false;
		}

		char endian;
		fs.get(endian);

		if (endian != 'b' && endian != 'l')
		{
			return false;
		}

		Core::Bytecode_Type buffer;

		char ch;
		while(fs.get(ch))
		{
			buffer.push_back(ch);
		}

		Core::Memory_16Bit * mem = (Core::Memory_16Bit *)Core::Wukong_Get_System().get_memory((Core::u16)0);
		mem->unchecked_access(Core::Memory_16Bit::MEMORY_WRITE, (Core::u16)0, buffer.size(), buffer);

		return true;
	}

	Loader::~Loader(void)
	{
	}

	void Loader::on_create(void)
	{
		name_ = "MU0_Loader";
	}
	
	void Loader::on_destroy(void)
	{

	}

} //namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -