minor type shit

This commit is contained in:
ApfelTeeSaft
2024-10-09 08:54:41 +02:00
parent 1d154ba347
commit a7fd82687f
2 changed files with 29 additions and 26 deletions
+5 -9
View File
@@ -58,9 +58,9 @@ void renderImGui(Z80Emulator& emulator) {
loadRomFromFile(emulator);
}
// Display the current program counter
ImGui::Text("Program Counter: 0x%04X", emulator.getProgramCounter());
// Control buttons
if (ImGui::Button("Run##run")) {
emulator.run();
std::cout << "Emulator started" << std::endl;
@@ -94,15 +94,11 @@ void renderImGui(Z80Emulator& emulator) {
for (const auto& row : buttonLayout) {
for (const auto& button : row) {
if (button.code == '\n') {
ImGui::NewLine();
}
else {
if (ImGui::Button(button.imprint.c_str(), ImVec2(50 * button.span, 50))) {
std::cout << "Button '" << button.imprint << "' pressed!" << std::endl;
}
ImGui::SameLine();
if (ImGui::Button(button.imprint.c_str(), ImVec2(50 * button.span, 50))) {
std::cout << "Button '" << button.imprint << "' pressed!" << std::endl;
// Handle button press
}
ImGui::SameLine();
}
ImGui::NewLine();
}
+24 -17
View File
@@ -2,11 +2,12 @@
#include <fstream>
#include <iostream>
#include <vector>
#include "CPU.hpp"
#include <cstring>
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()) {
@@ -23,6 +24,7 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA
return false;
}
// Load the program into memory
size_t offset = 0;
size_t halfSize = buffer.size() / 2;
for (size_t i = 0; i < halfSize; ++i) {
@@ -30,30 +32,35 @@ bool loadROM(const std::string& filepath, Z80Emulator& emulator, uint16_t startA
}
emulator.setProgramCounter(startAddress);
// Parse the title (null-terminated string)
buttonLayoutTitle.clear();
while (buffer[offset] != '\0') {
buttonLayoutTitle += buffer[offset++];
}
offset++;
offset++; // Move past the null terminator
std::cout << "Layout Title: " << buttonLayoutTitle << std::endl;
// Parse the button layout
buttonLayout.clear();
uint8_t rowCount = buffer[offset++]; // First byte after the title: number of rows
for (uint8_t row = 0; row < rowCount; ++row) {
std::vector<Button> rowButtons;
while (offset < buffer.size()) {
char code = static_cast<char>(buffer[offset++]); // Button code
uint8_t span = buffer[offset++]; // Button column span
uint8_t imprintSize = buffer[offset++]; // Imprint size
std::string imprint((char*)&buffer[offset], imprintSize); // Imprint text
offset += imprintSize;
if (code == '\n') break;
rowButtons.push_back(Button{ code, imprint, span });
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;
}
buttonLayout.push_back(rowButtons);
uint8_t span = buffer[offset++]; // Button column span
uint8_t imprintSize = buffer[offset++]; // Imprint size
std::string imprint((char*)&buffer[offset], imprintSize); // Imprint text
offset += imprintSize;
if (buttonLayout.empty()) {
buttonLayout.push_back(std::vector<Button>()); // Ensure there's a row for buttons
}
buttonLayout.back().push_back(Button{ code, imprint, span });
std::cout << "Parsed button: '" << imprint << "' with code: " << code << " and span: " << (int)span << std::endl;
}
return true;