Files
Xenia-Canary/src/xenia/cpu/raw_module.cc

61 lines
1.8 KiB
C++

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/cpu/raw_module.h"
#include "poly/platform.h"
#include "poly/string.h"
namespace xe {
namespace cpu {
RawModule::RawModule(Runtime* runtime)
: Module(runtime), base_address_(0), low_address_(0), high_address_(0) {}
RawModule::~RawModule() {}
int RawModule::LoadFile(uint32_t base_address, const std::wstring& path) {
auto fixed_path = poly::to_string(poly::fix_path_separators(path));
FILE* file = fopen(fixed_path.c_str(), "rb");
fseek(file, 0, SEEK_END);
uint32_t file_length = static_cast<uint32_t>(ftell(file));
fseek(file, 0, SEEK_SET);
// Allocate memory.
// Since we have no real heap just load it wherever.
base_address_ = base_address;
uint8_t* p = memory_->TranslateVirtual(base_address_);
std::memset(p, 0, file_length);
// Read into memory.
fread(p, file_length, 1, file);
fclose(file);
// Setup debug info.
auto last_slash = fixed_path.find_last_of(poly::path_separator);
if (last_slash != std::string::npos) {
name_ = fixed_path.substr(last_slash + 1);
} else {
name_ = fixed_path;
}
// TODO(benvanik): debug info
low_address_ = base_address;
high_address_ = base_address + file_length;
return 0;
}
bool RawModule::ContainsAddress(uint32_t address) {
return address >= low_address_ && address < high_address_;
}
} // namespace cpu
} // namespace xe