minor : holy shit the calculator layout works

This commit is contained in:
ApfelTeeSaft
2024-10-09 09:48:28 +02:00
parent 7fe88f1173
commit 2850dc70d9
2 changed files with 8 additions and 13 deletions
+4 -3
View File
@@ -20,12 +20,13 @@ void generateCalculatorROM(const std::string& filepath) {
0x81, // ADD A, C
0xC9 // RET
};
romFile.write(reinterpret_cast<const char*>(programData.data()), programData.size());
const char* title = "Calculator";
romFile.write(title, strlen(title) + 1);
std::string title = "Calculator";
title.resize(32, '\0');
romFile.write(title.c_str(), title.size());
// Button Layout Section (Second half)
std::vector<uint8_t> buttonLayoutData = {
'7', 1, 1, '7', // Button '7'
'8', 1, 1, '8', // Button '8'
+4 -10
View File
@@ -4,13 +4,9 @@
#include <vector>
#include <cstring>
std::vector<std::vector<Button>> buttonLayout;
std::string buttonLayoutTitle;
bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startAddress) {
std::ifstream file(filepath, std::ios::binary);
if (!file.is_open()) {
@@ -27,7 +23,6 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA
return false;
}
size_t offset = 0;
size_t halfSize = buffer.size() / 2;
for (size_t i = 0; i < halfSize; ++i) {
@@ -35,16 +30,14 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA
}
emulator.setProgramCounter(startAddress);
buttonLayoutTitle.clear();
while (buffer[offset] != '\0' && offset < buffer.size()) {
while (buffer[offset] != '\0' && offset < 32) { // Read the title within the first 32 bytes
buttonLayoutTitle += buffer[offset++];
}
offset++;
offset = 32;
std::cout << "Layout Title: " << buttonLayoutTitle << std::endl;
buttonLayout.clear();
while (offset < buffer.size()) {
char code = static_cast<char>(buffer[offset++]);
@@ -68,7 +61,8 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA
std::cerr << "Error: Imprint size out of bounds." << std::endl;
break;
}
std::string imprint((char*)&buffer[offset], imprintSize);
std::string imprint(reinterpret_cast<const char*>(&buffer[offset]), imprintSize);
offset += imprintSize;
if (buttonLayout.empty()) {