mirror of
https://github.com/ApfelTeeSaft/Z80-Emu.git
synced 2026-08-26 19:43:28 +00:00
minor type shit
This commit is contained in:
+5
-9
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user