-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
164 lines (130 loc) · 5.07 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "addressingmode.h"
#include "docking_params.h"
#include "dpi_aware.h"
#include "hello_imgui/hello_imgui.h"
#include "hello_imgui_assets.h"
#include "misc/cpp/imgui_stdlib.h"
#include "imgui.h"
#include "m68hc11x.h"
#include "imguiutil.h"
#include "assembler.h"
#include <TextEditor.h>
#include <fstream>
#include <format>
Assembler assembler;
TextEditor &GetCodeView() {
static TextEditor codeView;
return codeView;
}
void WindowAssembler() {
static TextEditor editor;
ImVec2 editorSize = ImGui::GetContentRegionAvail();
editorSize.y -= 32;
editor.Render("##assembler", false, editorSize);
ImGui::Spacing();
if (ImGui::RightAlignedButton("Assemble")) {
std::stringstream ss(editor.GetText());
assembler.Reset();
std::vector<std::string> finalLines = {};
try {
assembler.Assemble(ss);
} catch (std::runtime_error &e) {
finalLines.emplace_back(std::format("Failed to assemble: {}", e.what()));
}
for (const Row &row : assembler.lines) {
finalLines.push_back(row.str());
}
GetCodeView().SetTextLines(finalLines);
}
}
void WindowCodeView() {
TextEditor &codeView = GetCodeView();
codeView.SetReadOnlyEnabled(true);
codeView.Render("##codeview");
}
typedef void(*WindowCallback)();
HelloImGui::DockableWindow CreateDockingWindow(const char *label, const char *initialDockSpace, WindowCallback callback,
ImGuiWindowFlags flags = ImGuiWindowFlags_None) {
HelloImGui::DockableWindow window;
window.label = label;
window.dockSpaceName = initialDockSpace;
window.GuiFunction = callback;
window.imGuiWindowFlags = flags;
return window;
}
HelloImGui::DockingSplit
CreateDockingSplit(const char *initialDock, const char *newDock, ImGuiDir_ direction, f32 ratio) {
HelloImGui::DockingSplit split;
split.initialDock = initialDock;
split.newDock = newDock;
split.direction = direction;
split.ratio = ratio;
return split;
}
HelloImGui::DockingParams CreateDefaultLayout() {
HelloImGui::DockingParams params;
params.dockableWindows = {
CreateDockingWindow("Code View", "LeftSpace", WindowCodeView),
CreateDockingWindow("Assembler", "RightSpace", WindowAssembler,
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar),
};
params.dockingSplits = {
CreateDockingSplit("MainDockSpace", "LeftSpace", ImGuiDir_Left, 0.5f),
CreateDockingSplit("MainDockSpace", "RightSpace", ImGuiDir_Right, 0.5f),
};
return params;
}
void SaveTestProgram() {
std::ofstream testProgram("testProgram.asm");
for (const auto &inst: AllInstructions) {
testProgram << " * " << inst->description << " * \n";
for (const auto &opcodes: inst->opcodes) {
testProgram << "\t" << inst->mnemonic << " ";
switch (opcodes.first) {
case Assembler_AddressingMode::IMMEDIATE:
testProgram << "1";//\t\t// immediate";
break;
case Assembler_AddressingMode::DIRECT:
testProgram << "2";//\t\t// direct";
break;
case Assembler_AddressingMode::EXTENDED:
testProgram << "$3000";//\t// extended";
break;
case Assembler_AddressingMode::INDEXED_X:
testProgram << "1,X";//\t// indexed by X";
break;
case Assembler_AddressingMode::INDEXED_Y:
testProgram << "2,Y";//\t// indexed by Y";
break;
case Assembler_AddressingMode::INHERENT:
//testProgram << "\t// inherent";
break;
case Assembler_AddressingMode::RELATIVE:
testProgram << "STARTBRANCH";//\t// relative";
break;
}
testProgram << std::endl;
}
}
}
void LoadAdditionalFonts() {
HelloImGui::AssetFileData fileData = HelloImGui::LoadAssetFileData("JetBrainsMono-Regular.ttf");
ImFontConfig FontConfig = ImFontConfig();
FontConfig.OversampleV = 3;
FontConfig.OversampleH = 3;
// NOTE(alex): AddFontFromMemoryTTF takes ownership of the data and frees it for us
ImGui::GetIO().Fonts->AddFontFromMemoryTTF(fileData.data, fileData.dataSize, m68hc11x::DefaultFontSize * HelloImGui::DpiFontLoadingFactor(), &FontConfig);
}
int main(i32, char**) {
HelloImGui::RunnerParams params;
SaveTestProgram();
params.appWindowParams.windowTitle = m68hc11x::WindowTitle;
// NOTE(alex): creates MainDockSpace
params.imGuiWindowParams.defaultImGuiWindowType = HelloImGui::DefaultImGuiWindowType::ProvideFullScreenDockSpace;
// NOTE(alex): allows docking into separate windows entirely
params.imGuiWindowParams.enableViewports = true;
params.callbacks.LoadAdditionalFonts = LoadAdditionalFonts;
params.dockingParams = CreateDefaultLayout();
HelloImGui::Run(params);
return 0;
}