#include "memory.hh" #include #include #include #include #include int main(int argc, const char* argv[]) { auto usage = [argv]() { std::cerr << "Usage: " << argv[0] << " [-b ]" << std::endl; std::exit(EXIT_FAILURE); }; if (argc < 2) usage(); std::string rom_file, bios_file = "gba_bios.bin"; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if (arg == "-b") { if (++i < argc) bios_file = argv[i]; else usage(); } else { rom_file = arg; } } if (rom_file.empty()) usage(); try { std::ifstream ifile(rom_file, std::ios::in | std::ios::binary); std::vector rom; std::array bios; std::streampos bios_size; if (!ifile.is_open()) { throw std::ios::failure("File not found", std::error_code()); } rom.assign(std::istreambuf_iterator(ifile), std::istreambuf_iterator()); ifile.close(); ifile.open(bios_file, std::ios::in | std::ios::binary); if (!ifile.is_open()) { throw std::ios::failure("BIOS file not found", std::error_code()); } ifile.seekg(0, std::ios::end); bios_size = ifile.tellg(); if (bios_size != Memory::BIOS_SIZE) { throw std::ios::failure("BIOS file has invalid size", std::error_code()); } ifile.seekg(0, std::ios::beg); ifile.read(reinterpret_cast(bios.data()), bios.size()); ifile.close(); Memory memory(std::move(bios), std::move(rom)); } catch (const std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; return 1; } return 0; }