diff --git a/Z80-Emu/ROMLoader.cpp b/Z80-Emu/ROMLoader.cpp index 811f49c..b7d5357 100644 --- a/Z80-Emu/ROMLoader.cpp +++ b/Z80-Emu/ROMLoader.cpp @@ -10,6 +10,7 @@ std::vector> buttonLayout; // Global variable to store the layout title std::string buttonLayoutTitle; +// Function to load a .rom file into the emulator's memory and button layout bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startAddress) { std::ifstream file(filepath, std::ios::binary); if (!file.is_open()) { @@ -26,7 +27,7 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA return false; } - // Load the program into memory + // Load the program into memory (assume first half of the file) size_t offset = 0; size_t halfSize = buffer.size() / 2; for (size_t i = 0; i < halfSize; ++i) { @@ -36,24 +37,34 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA // Parse the title (null-terminated string) buttonLayoutTitle.clear(); - while (buffer[offset] != '\0') { + while (buffer[offset] != '\0' && offset < buffer.size()) { buttonLayoutTitle += buffer[offset++]; } offset++; // Move past the null terminator std::cout << "Layout Title: " << buttonLayoutTitle << std::endl; - // Parse the button layout + // Parse the button layout (assuming it's after the title and program) buttonLayout.clear(); while (offset < buffer.size()) { char code = static_cast(buffer[offset++]); // Button code if (code == '\n') { + // New line marker, we add a row separation buttonLayout.push_back(std::vector