3#include "cartridge.hpp"
11inline std::vector<u8> load_rom(
const char* _filepath){
12 std::ifstream file(_filepath, std::ios::binary);
15 throw std::runtime_error(
"Error opening file");
19 (std::istreambuf_iterator(file)),
20 std::istreambuf_iterator<char>()
22 std::cout <<
"ROM Size: " << (rom.size()/1024) <<
"K" << std::endl;
25 throw std::runtime_error(
"ROM file is empty");
28 if(rom.size() < 0x150){
29 throw std::runtime_error(
"ROM too small");
33 std::memcpy(&_header, &rom[0x100],
sizeof(
rom_header));
37 std::memcpy(title, _header.title, 16);
39 std::cout <<
"Title: " <<
" " << title << std::endl;
40 std::cout <<
"Type: 0x" << std::hex << static_cast<int>(_header.type) <<
"\n";
41 std::cout <<
"ROM: 0x" << std::hex << static_cast<int>(_header.rom_size) <<
"\n";
42 std::cout <<
"RAM: 0x" << std::hex << static_cast<int>(_header.ram_size) <<
"\n";
46 for (
int i = 0x134; i <= 0x14C; i++) {
47 sum = sum - rom[i] - 1;
50 if (sum == _header.checksum)
51 std::cout <<
"Header OK\n" << std::endl;
53 std::cout <<
"Bad header\n" << std::endl;