mirror of
https://github.com/ApfelTeeSaft/Z80-Emu.git
synced 2026-08-26 19:43:28 +00:00
minor stuff
This commit is contained in:
+14
-3
@@ -10,6 +10,7 @@ std::vector<std::vector<Button>> 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<char>(buffer[offset++]); // Button code
|
||||
if (code == '\n') {
|
||||
// New line marker, we add a row separation
|
||||
buttonLayout.push_back(std::vector<Button>()); // Start a new row
|
||||
continue;
|
||||
}
|
||||
|
||||
if (offset + 2 >= buffer.size()) {
|
||||
std::cerr << "Error: Incomplete button data in ROM." << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t span = buffer[offset++]; // Button column span
|
||||
uint8_t imprintSize = buffer[offset++]; // Imprint size
|
||||
if (offset + imprintSize > buffer.size()) {
|
||||
std::cerr << "Error: Imprint size out of bounds." << std::endl;
|
||||
break;
|
||||
}
|
||||
std::string imprint((char*)&buffer[offset], imprintSize); // Imprint text
|
||||
offset += imprintSize;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user