我正在用C++编写一个GBC模拟器,这是我读取rom文件的部分代码: void Cartridge::load(const std::string& filePath) {…
- User
我正在用C++编写一个GBC模拟器,这是我读取rom文件的部分代码:
void Cartridge::load(const std::string& filePath) { std::cout << "load file : " << filePath << std::endl; std::ifstream romFile(filePath, std::ios::binary | std::ios::ate); if (!romFile.is_open()) { throw std::runtime_error("Failed to open ROM: " + filePath); }
codestd::streamsize size = romFile.tellg(); romFile.seekg(0, std::ios::beg); std::vector<char> buffer(size); if (!romFile.read(buffer.data(), size)) { throw std::runtime_error("Load ROM file failed: " + filePath); } header_ = (header*)(&buffer + 0x100); header_->title[15] = 0; printf("Title: %s\n", header_->title);}
codetypedef struct { uint8_t entry[4]; uint8_t logo[0x30]; char title[16]; uint16_t new_lic_code; uint8_t sgb_flag; uint8_t type; uint8_t rom_size; uint8_t ram_size; uint8_t dest_code; uint8_t lic_code; uint8_t version; uint8_t checksum; uint16_t global_checksum; } header;现在我的头部读取代码有问题,请帮我修复。
- Assistant