Condense emulator zeml layout, include function in zeml
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "app/gui/pipeline.h"
|
||||
#include "app/gui/style.h"
|
||||
#include "app/gui/widgets.h"
|
||||
#include "app/gui/zeml.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/overworld/overworld.h"
|
||||
|
||||
|
||||
@@ -173,12 +173,29 @@ void Emulator::RenderEmulator() {
|
||||
}
|
||||
TableNextColumn {
|
||||
BeginChild id="##" size="0,0" flags="NoMove|NoScrollbar" {
|
||||
CollapsingHeader id="cpuState" title="Register Values" open=true {
|
||||
Columns id="registersColumns" count="2" {
|
||||
Text text="A: 0x%04X" data="cpu.A",
|
||||
Text text="D: 0x%04X" data="cpu.D",
|
||||
Text text="X: 0x%04X" data="cpu.X",
|
||||
Text text="DB: 0x%02X" data="cpu.DB",
|
||||
Text text="Y: 0x%04X" data="cpu.Y",
|
||||
Text text="PB: 0x%02X" data="cpu.PB",
|
||||
Text text="PC: 0x%04X" data="cpu.PC",
|
||||
Text text="E: %d" data="cpu.E"
|
||||
}
|
||||
}
|
||||
Function id="CpuState"
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
auto emulator_node = gui::zeml::Parse(emulator_layout);
|
||||
const std::map<std::string, void*> data_bindings = {
|
||||
{"cpu.A", &snes_.cpu().A}, {"cpu.D", &snes_.cpu().D},
|
||||
{"cpu.X", &snes_.cpu().X}, {"cpu.DB", &snes_.cpu().DB},
|
||||
{"cpu.Y", &snes_.cpu().Y}, {"cpu.PB", &snes_.cpu().PB},
|
||||
{"cpu.PC", &snes_.cpu().PC}, {"cpu.E", &snes_.cpu().E}};
|
||||
auto emulator_node = gui::zeml::Parse(emulator_layout, data_bindings);
|
||||
Bind(emulator_node.GetNode("CpuInstructionLog"),
|
||||
[&]() { RenderCpuInstructionLog(snes_.cpu().instruction_log_); });
|
||||
Bind(emulator_node.GetNode("SnesPpu"), [&]() { RenderSnesPpu(); });
|
||||
@@ -186,7 +203,6 @@ void Emulator::RenderEmulator() {
|
||||
[&]() { RenderBreakpointList(); });
|
||||
Bind(emulator_node.GetNode("CpuState"),
|
||||
[&]() { RenderCpuState(snes_.cpu()); });
|
||||
|
||||
gui::zeml::Render(emulator_node);
|
||||
}
|
||||
|
||||
@@ -272,28 +288,6 @@ void Emulator::RenderBreakpointList() {
|
||||
}
|
||||
|
||||
void Emulator::RenderCpuState(Cpu& cpu) {
|
||||
std::string cpu_state_layout = R"(
|
||||
CollapsingHeader id="cpuState" title="Register Values" open=true {
|
||||
Columns id="registersColumns" count="2" {
|
||||
Text text="A: 0x%04X" data="cpu.A",
|
||||
Text text="D: 0x%04X" data="cpu.D",
|
||||
Text text="X: 0x%04X" data="cpu.X",
|
||||
Text text="DB: 0x%02X" data="cpu.DB",
|
||||
Text text="Y: 0x%04X" data="cpu.Y",
|
||||
Text text="PB: 0x%02X" data="cpu.PB",
|
||||
Text text="PC: 0x%04X" data="cpu.PC",
|
||||
Text text="E: %d" data="cpu.E"
|
||||
}
|
||||
}
|
||||
)";
|
||||
const std::map<std::string, void*> data_bindings = {
|
||||
{"cpu.A", &cpu.A}, {"cpu.D", &cpu.D}, {"cpu.X", &cpu.X},
|
||||
{"cpu.DB", &cpu.DB}, {"cpu.Y", &cpu.Y}, {"cpu.PB", &cpu.PB},
|
||||
{"cpu.PC", &cpu.PC}, {"cpu.E", &cpu.E}};
|
||||
gui::zeml::Node cpu_state_node =
|
||||
gui::zeml::Parse(cpu_state_layout, data_bindings);
|
||||
gui::zeml::Render(cpu_state_node);
|
||||
|
||||
// Call Stack
|
||||
if (ImGui::CollapsingHeader("Call Stack", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
// For each return address in the call stack:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -75,7 +76,7 @@ WidgetType MapType(const std::string& type) {
|
||||
}
|
||||
|
||||
Node ParseNode(const std::vector<Token>& tokens, size_t& index,
|
||||
const std::map<std::string, void*>& data_bindings) {
|
||||
const std::map<std::string, void*>& data_bindings) {
|
||||
Node node;
|
||||
if (index >= tokens.size() || tokens[index].type == TokenType::EndOfStream) {
|
||||
return node;
|
||||
@@ -265,7 +266,7 @@ void Render(Node& node) {
|
||||
}
|
||||
|
||||
Node Parse(const std::string& yazon_input,
|
||||
const std::map<std::string, void*>& data_bindings) {
|
||||
const std::map<std::string, void*>& data_bindings) {
|
||||
size_t index = 0;
|
||||
auto tokens = Tokenize(yazon_input);
|
||||
return ParseNode(tokens, index, data_bindings);
|
||||
@@ -281,13 +282,15 @@ void ExecuteActions(const std::vector<Action>& actions, ActionType type) {
|
||||
|
||||
void Bind(Node* node, std::function<void()> callback) {
|
||||
if (node) {
|
||||
node->actions.push_back({ActionType::Click, callback});
|
||||
Action action = {ActionType::Click, callback};
|
||||
node->actions.push_back(action);
|
||||
}
|
||||
}
|
||||
|
||||
void BindAction(Node* node, ActionType type, std::function<void()> callback) {
|
||||
if (node) {
|
||||
node->actions.push_back({type, callback});
|
||||
Action action = {type, callback};
|
||||
node->actions.push_back(action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user