-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions viewer which will later show disassembled instructio…
…ns, clean up ui
- Loading branch information
Showing
8 changed files
with
247 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include "assembly.h" | ||
|
||
#include <spdlog/spdlog.h> | ||
#include <cstdint> | ||
#include <imgui.h> | ||
|
||
#ifdef _MSC_VER | ||
#define _PRISizeT "I" | ||
#define ImSnprintf _snprintf | ||
#else | ||
#define _PRISizeT "z" | ||
#define ImSnprintf snprintf | ||
#endif | ||
|
||
void AssemblyViewer::initialize(const registers *regs_) { | ||
spdlog::trace("Initialzing AssemblyViewer"); | ||
regs = regs_; | ||
} | ||
|
||
void AssemblyViewer::draw() { | ||
if (ImGui::BeginPopup("Options")) { | ||
ImGui::Checkbox("Auto-scroll", &auto_scroll); | ||
ImGui::EndPopup(); | ||
} | ||
|
||
if (ImGui::Button("Options")) { | ||
ImGui::OpenPopup("Options"); | ||
} | ||
|
||
if (ImGui::BeginChild("scrolling", ImVec2(0, 0), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar)) | ||
{ | ||
ImGuiStyle &style = ImGui::GetStyle(); | ||
|
||
const int line_total_count = regs->mem.size() / 2; | ||
float line_height = ImGui::GetTextLineHeight(); | ||
|
||
ImGuiListClipper clipper; | ||
clipper.Begin(line_total_count, line_height); | ||
|
||
const char* format_address = "%0*" _PRISizeT "X: "; | ||
const char* format_data = " %0*" _PRISizeT "X"; | ||
|
||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); | ||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); | ||
|
||
while (clipper.Step()) { | ||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i += 1) { | ||
size_t addr = static_cast<uint16_t>(i * 2); | ||
bool is_current_line = addr == regs->pc; | ||
|
||
uint8_t hi = regs->mem[addr]; | ||
uint8_t lo = regs->mem[addr + 1]; | ||
|
||
bool is_greyed_out = (addr < kRomStartIndex) && (hi == 0 && lo == 0); | ||
|
||
if (is_current_line) { | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 1.0, 0, 1.0)); | ||
} | ||
|
||
ImGui::Text(format_address, 3, addr); | ||
|
||
if (is_current_line) { | ||
ImGui::PopStyleColor(); | ||
} | ||
|
||
if (is_greyed_out) { | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5, 0.5, 0.5, 1.0)); | ||
} else if (is_current_line) { | ||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 1.0, 0, 1.0)); | ||
} | ||
|
||
ImGui::SameLine(); | ||
ImGui::Text(format_data, 2, hi); | ||
ImGui::SameLine(); | ||
ImGui::Text(format_data, 2, lo); | ||
|
||
if (is_greyed_out || is_current_line) { | ||
ImGui::PopStyleColor(); | ||
} | ||
} | ||
} | ||
|
||
if (auto_scroll) { | ||
float scroll_y = line_height * (regs->pc >> 1); | ||
ImGui::SetScrollY(scroll_y); | ||
} | ||
|
||
ImGui::PopStyleVar(2); | ||
} | ||
ImGui::EndChild(); | ||
} | ||
|
||
void AssemblyViewer::cleanup() { | ||
spdlog::trace("Initialzing AssemblyViewer"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "registers.h" | ||
class AssemblyViewer { | ||
public: | ||
void initialize(const registers *regs); | ||
void draw(); | ||
void cleanup(); | ||
|
||
private: | ||
bool auto_scroll = true; | ||
|
||
const registers *regs; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.