1 |
30 |
robfinch |
#pragma once
|
2 |
|
|
#include <Windows.h>
|
3 |
|
|
#include <iostream>
|
4 |
|
|
#include <fstream>
|
5 |
|
|
#include <iomanip>
|
6 |
|
|
#include <string>
|
7 |
|
|
#include <vcclr.h>
|
8 |
|
|
#include <string.h>
|
9 |
|
|
#include "frmRegisters.h"
|
10 |
|
|
//#include "frmBreakpoint.h"
|
11 |
|
|
#include "frmScreen.h"
|
12 |
|
|
#include "frmKeyboard.h"
|
13 |
|
|
#include "About.h"
|
14 |
|
|
//#include "fmrPCS.h"
|
15 |
|
|
//#include "frmInterrupts.h"
|
16 |
|
|
//#include "frmStack.h"
|
17 |
|
|
#include "frmMemory.h"
|
18 |
|
|
//#include "Disassem.h"
|
19 |
|
|
#include "clsCPU.h"
|
20 |
|
|
#include "clsPIC.h"
|
21 |
|
|
#include "clsDisassem.h"
|
22 |
|
|
|
23 |
|
|
clsDisassem da;
|
24 |
|
|
extern clsThor cpu1;
|
25 |
|
|
extern clsPIC pic1;
|
26 |
|
|
extern clsSystem system1;
|
27 |
|
|
extern unsigned int breakpoints[30];
|
28 |
|
|
|
29 |
|
|
namespace emuThor {
|
30 |
|
|
|
31 |
|
|
using namespace System;
|
32 |
|
|
using namespace System::ComponentModel;
|
33 |
|
|
using namespace System::Collections;
|
34 |
|
|
using namespace System::Windows::Forms;
|
35 |
|
|
using namespace System::Data;
|
36 |
|
|
using namespace System::Drawing;
|
37 |
|
|
using namespace System::Runtime::InteropServices;
|
38 |
|
|
using namespace System::Threading;
|
39 |
|
|
|
40 |
|
|
/// <summary>
|
41 |
|
|
/// Summary for frmMain
|
42 |
|
|
/// </summary>
|
43 |
|
|
public ref class frmMain : public System::Windows::Forms::Form
|
44 |
|
|
{
|
45 |
|
|
public:
|
46 |
|
|
frmMain(void)
|
47 |
|
|
{
|
48 |
|
|
InitializeComponent();
|
49 |
|
|
//
|
50 |
|
|
//TODO: Add the constructor code here
|
51 |
|
|
//
|
52 |
|
|
frmKeyboard^ keyboardFrm = gcnew frmKeyboard();
|
53 |
|
|
keyboardFrm->Show();
|
54 |
|
|
frmScreen^ screenFrm = gcnew frmScreen();
|
55 |
|
|
screenFrm->Show();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
protected:
|
59 |
|
|
/// <summary>
|
60 |
|
|
/// Clean up any resources being used.
|
61 |
|
|
/// </summary>
|
62 |
|
|
~frmMain()
|
63 |
|
|
{
|
64 |
|
|
if (components)
|
65 |
|
|
{
|
66 |
|
|
delete components;
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
private: System::Windows::Forms::MenuStrip^ menuStrip1;
|
70 |
|
|
protected:
|
71 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ viewToolStripMenuItem;
|
72 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ registersToolStripMenuItem;
|
73 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
|
74 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ runToolStripMenuItem;
|
75 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem;
|
76 |
|
|
private: System::Windows::Forms::ToolStrip^ toolStrip1;
|
77 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton1;
|
78 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton2;
|
79 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton3;
|
80 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton4;
|
81 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton5;
|
82 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton6;
|
83 |
|
|
private: System::Windows::Forms::ToolStripButton^ toolStripButton7;
|
84 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ loadINTELHexFIleToolStripMenuItem;
|
85 |
|
|
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
|
86 |
|
|
private: System::Windows::Forms::Label^ lblChecksumError;
|
87 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ memoryToolStripMenuItem;
|
88 |
|
|
private: System::Windows::Forms::PictureBox^ pictureBox1;
|
89 |
|
|
private: System::Windows::Forms::ListBox^ listBoxAdr;
|
90 |
|
|
private: System::Windows::Forms::ListBox^ listBoxBytes;
|
91 |
|
|
private: System::Windows::Forms::ListBox^ listBoxCode;
|
92 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ stepToolStripMenuItem;
|
93 |
|
|
private: System::Windows::Forms::ToolStripMenuItem^ resetToolStripMenuItem;
|
94 |
|
|
private: System::Windows::Forms::Label^ lblLEDS;
|
95 |
|
|
|
96 |
|
|
private:
|
97 |
|
|
/// <summary>
|
98 |
|
|
/// Required designer variable.
|
99 |
|
|
/// </summary>
|
100 |
|
|
System::ComponentModel::Container ^components;
|
101 |
|
|
|
102 |
|
|
#pragma region Windows Form Designer generated code
|
103 |
|
|
/// <summary>
|
104 |
|
|
/// Required method for Designer support - do not modify
|
105 |
|
|
/// the contents of this method with the code editor.
|
106 |
|
|
/// </summary>
|
107 |
|
|
void InitializeComponent(void)
|
108 |
|
|
{
|
109 |
|
|
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(frmMain::typeid));
|
110 |
|
|
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
|
111 |
|
|
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
112 |
|
|
this->loadINTELHexFIleToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
113 |
|
|
this->runToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
114 |
|
|
this->resetToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
115 |
|
|
this->stepToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
116 |
|
|
this->viewToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
117 |
|
|
this->registersToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
118 |
|
|
this->memoryToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
119 |
|
|
this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
|
120 |
|
|
this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
|
121 |
|
|
this->toolStripButton1 = (gcnew System::Windows::Forms::ToolStripButton());
|
122 |
|
|
this->toolStripButton2 = (gcnew System::Windows::Forms::ToolStripButton());
|
123 |
|
|
this->toolStripButton3 = (gcnew System::Windows::Forms::ToolStripButton());
|
124 |
|
|
this->toolStripButton4 = (gcnew System::Windows::Forms::ToolStripButton());
|
125 |
|
|
this->toolStripButton5 = (gcnew System::Windows::Forms::ToolStripButton());
|
126 |
|
|
this->toolStripButton6 = (gcnew System::Windows::Forms::ToolStripButton());
|
127 |
|
|
this->toolStripButton7 = (gcnew System::Windows::Forms::ToolStripButton());
|
128 |
|
|
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
|
129 |
|
|
this->lblChecksumError = (gcnew System::Windows::Forms::Label());
|
130 |
|
|
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
|
131 |
|
|
this->listBoxAdr = (gcnew System::Windows::Forms::ListBox());
|
132 |
|
|
this->listBoxBytes = (gcnew System::Windows::Forms::ListBox());
|
133 |
|
|
this->listBoxCode = (gcnew System::Windows::Forms::ListBox());
|
134 |
|
|
this->lblLEDS = (gcnew System::Windows::Forms::Label());
|
135 |
|
|
this->menuStrip1->SuspendLayout();
|
136 |
|
|
this->toolStrip1->SuspendLayout();
|
137 |
|
|
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
|
138 |
|
|
this->SuspendLayout();
|
139 |
|
|
//
|
140 |
|
|
// menuStrip1
|
141 |
|
|
//
|
142 |
|
|
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->fileToolStripMenuItem,
|
143 |
|
|
this->runToolStripMenuItem, this->viewToolStripMenuItem, this->aboutToolStripMenuItem});
|
144 |
|
|
this->menuStrip1->Location = System::Drawing::Point(0, 0);
|
145 |
|
|
this->menuStrip1->Name = L"menuStrip1";
|
146 |
|
|
this->menuStrip1->Size = System::Drawing::Size(684, 24);
|
147 |
|
|
this->menuStrip1->TabIndex = 0;
|
148 |
|
|
this->menuStrip1->Text = L"menuStrip1";
|
149 |
|
|
//
|
150 |
|
|
// fileToolStripMenuItem
|
151 |
|
|
//
|
152 |
|
|
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->loadINTELHexFIleToolStripMenuItem});
|
153 |
|
|
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
|
154 |
|
|
this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
|
155 |
|
|
this->fileToolStripMenuItem->Text = L"&File";
|
156 |
|
|
//
|
157 |
|
|
// loadINTELHexFIleToolStripMenuItem
|
158 |
|
|
//
|
159 |
|
|
this->loadINTELHexFIleToolStripMenuItem->Name = L"loadINTELHexFIleToolStripMenuItem";
|
160 |
|
|
this->loadINTELHexFIleToolStripMenuItem->Size = System::Drawing::Size(178, 22);
|
161 |
|
|
this->loadINTELHexFIleToolStripMenuItem->Text = L"&Load INTEL Hex FIle";
|
162 |
|
|
this->loadINTELHexFIleToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::loadINTELHexFIleToolStripMenuItem_Click);
|
163 |
|
|
//
|
164 |
|
|
// runToolStripMenuItem
|
165 |
|
|
//
|
166 |
|
|
this->runToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->resetToolStripMenuItem,
|
167 |
|
|
this->stepToolStripMenuItem});
|
168 |
|
|
this->runToolStripMenuItem->Name = L"runToolStripMenuItem";
|
169 |
|
|
this->runToolStripMenuItem->Size = System::Drawing::Size(40, 20);
|
170 |
|
|
this->runToolStripMenuItem->Text = L"&Run";
|
171 |
|
|
//
|
172 |
|
|
// resetToolStripMenuItem
|
173 |
|
|
//
|
174 |
|
|
this->resetToolStripMenuItem->Name = L"resetToolStripMenuItem";
|
175 |
|
|
this->resetToolStripMenuItem->Size = System::Drawing::Size(152, 22);
|
176 |
|
|
this->resetToolStripMenuItem->Text = L"&Reset";
|
177 |
|
|
this->resetToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::resetToolStripMenuItem_Click);
|
178 |
|
|
//
|
179 |
|
|
// stepToolStripMenuItem
|
180 |
|
|
//
|
181 |
|
|
this->stepToolStripMenuItem->Name = L"stepToolStripMenuItem";
|
182 |
|
|
this->stepToolStripMenuItem->Size = System::Drawing::Size(152, 22);
|
183 |
|
|
this->stepToolStripMenuItem->Text = L"&Step";
|
184 |
|
|
this->stepToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::stepToolStripMenuItem_Click);
|
185 |
|
|
//
|
186 |
|
|
// viewToolStripMenuItem
|
187 |
|
|
//
|
188 |
|
|
this->viewToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->registersToolStripMenuItem,
|
189 |
|
|
this->memoryToolStripMenuItem});
|
190 |
|
|
this->viewToolStripMenuItem->Name = L"viewToolStripMenuItem";
|
191 |
|
|
this->viewToolStripMenuItem->Size = System::Drawing::Size(44, 20);
|
192 |
|
|
this->viewToolStripMenuItem->Text = L"&View";
|
193 |
|
|
//
|
194 |
|
|
// registersToolStripMenuItem
|
195 |
|
|
//
|
196 |
|
|
this->registersToolStripMenuItem->Name = L"registersToolStripMenuItem";
|
197 |
|
|
this->registersToolStripMenuItem->Size = System::Drawing::Size(152, 22);
|
198 |
|
|
this->registersToolStripMenuItem->Text = L"&Registers";
|
199 |
|
|
this->registersToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::registersToolStripMenuItem_Click);
|
200 |
|
|
//
|
201 |
|
|
// memoryToolStripMenuItem
|
202 |
|
|
//
|
203 |
|
|
this->memoryToolStripMenuItem->Name = L"memoryToolStripMenuItem";
|
204 |
|
|
this->memoryToolStripMenuItem->Size = System::Drawing::Size(152, 22);
|
205 |
|
|
this->memoryToolStripMenuItem->Text = L"&Memory";
|
206 |
|
|
this->memoryToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::memoryToolStripMenuItem_Click);
|
207 |
|
|
//
|
208 |
|
|
// aboutToolStripMenuItem
|
209 |
|
|
//
|
210 |
|
|
this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem";
|
211 |
|
|
this->aboutToolStripMenuItem->Size = System::Drawing::Size(52, 20);
|
212 |
|
|
this->aboutToolStripMenuItem->Text = L"&About";
|
213 |
|
|
this->aboutToolStripMenuItem->Click += gcnew System::EventHandler(this, &frmMain::aboutToolStripMenuItem_Click);
|
214 |
|
|
//
|
215 |
|
|
// toolStrip1
|
216 |
|
|
//
|
217 |
|
|
this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(7) {this->toolStripButton1,
|
218 |
|
|
this->toolStripButton2, this->toolStripButton3, this->toolStripButton4, this->toolStripButton5, this->toolStripButton6, this->toolStripButton7});
|
219 |
|
|
this->toolStrip1->Location = System::Drawing::Point(0, 24);
|
220 |
|
|
this->toolStrip1->Name = L"toolStrip1";
|
221 |
|
|
this->toolStrip1->Size = System::Drawing::Size(684, 25);
|
222 |
|
|
this->toolStrip1->TabIndex = 1;
|
223 |
|
|
this->toolStrip1->Text = L"toolStrip1";
|
224 |
|
|
//
|
225 |
|
|
// toolStripButton1
|
226 |
|
|
//
|
227 |
|
|
this->toolStripButton1->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
228 |
|
|
this->toolStripButton1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton1.Image")));
|
229 |
|
|
this->toolStripButton1->ImageTransparentColor = System::Drawing::Color::Magenta;
|
230 |
|
|
this->toolStripButton1->Name = L"toolStripButton1";
|
231 |
|
|
this->toolStripButton1->Size = System::Drawing::Size(23, 22);
|
232 |
|
|
this->toolStripButton1->Text = L"Step Into";
|
233 |
|
|
this->toolStripButton1->Click += gcnew System::EventHandler(this, &frmMain::toolStripButton1_Click);
|
234 |
|
|
//
|
235 |
|
|
// toolStripButton2
|
236 |
|
|
//
|
237 |
|
|
this->toolStripButton2->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
238 |
|
|
this->toolStripButton2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton2.Image")));
|
239 |
|
|
this->toolStripButton2->ImageTransparentColor = System::Drawing::Color::Magenta;
|
240 |
|
|
this->toolStripButton2->Name = L"toolStripButton2";
|
241 |
|
|
this->toolStripButton2->Size = System::Drawing::Size(23, 22);
|
242 |
|
|
this->toolStripButton2->Text = L"Step Over (Bounce)";
|
243 |
|
|
//
|
244 |
|
|
// toolStripButton3
|
245 |
|
|
//
|
246 |
|
|
this->toolStripButton3->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
247 |
|
|
this->toolStripButton3->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton3.Image")));
|
248 |
|
|
this->toolStripButton3->ImageTransparentColor = System::Drawing::Color::Magenta;
|
249 |
|
|
this->toolStripButton3->Name = L"toolStripButton3";
|
250 |
|
|
this->toolStripButton3->Size = System::Drawing::Size(23, 22);
|
251 |
|
|
this->toolStripButton3->Text = L"Step Out Of";
|
252 |
|
|
//
|
253 |
|
|
// toolStripButton4
|
254 |
|
|
//
|
255 |
|
|
this->toolStripButton4->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
256 |
|
|
this->toolStripButton4->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton4.Image")));
|
257 |
|
|
this->toolStripButton4->ImageTransparentColor = System::Drawing::Color::Magenta;
|
258 |
|
|
this->toolStripButton4->Name = L"toolStripButton4";
|
259 |
|
|
this->toolStripButton4->Size = System::Drawing::Size(23, 22);
|
260 |
|
|
this->toolStripButton4->Text = L"Run";
|
261 |
|
|
//
|
262 |
|
|
// toolStripButton5
|
263 |
|
|
//
|
264 |
|
|
this->toolStripButton5->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
265 |
|
|
this->toolStripButton5->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton5.Image")));
|
266 |
|
|
this->toolStripButton5->ImageTransparentColor = System::Drawing::Color::Magenta;
|
267 |
|
|
this->toolStripButton5->Name = L"toolStripButton5";
|
268 |
|
|
this->toolStripButton5->Size = System::Drawing::Size(23, 22);
|
269 |
|
|
this->toolStripButton5->Text = L"Stop";
|
270 |
|
|
//
|
271 |
|
|
// toolStripButton6
|
272 |
|
|
//
|
273 |
|
|
this->toolStripButton6->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
274 |
|
|
this->toolStripButton6->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton6.Image")));
|
275 |
|
|
this->toolStripButton6->ImageTransparentColor = System::Drawing::Color::Magenta;
|
276 |
|
|
this->toolStripButton6->Name = L"toolStripButton6";
|
277 |
|
|
this->toolStripButton6->Size = System::Drawing::Size(23, 22);
|
278 |
|
|
this->toolStripButton6->Text = L"Interrupt";
|
279 |
|
|
//
|
280 |
|
|
// toolStripButton7
|
281 |
|
|
//
|
282 |
|
|
this->toolStripButton7->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
|
283 |
|
|
this->toolStripButton7->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton7.Image")));
|
284 |
|
|
this->toolStripButton7->ImageTransparentColor = System::Drawing::Color::Magenta;
|
285 |
|
|
this->toolStripButton7->Name = L"toolStripButton7";
|
286 |
|
|
this->toolStripButton7->Size = System::Drawing::Size(23, 22);
|
287 |
|
|
this->toolStripButton7->Text = L"Breakpoints";
|
288 |
|
|
//
|
289 |
|
|
// openFileDialog1
|
290 |
|
|
//
|
291 |
|
|
this->openFileDialog1->DefaultExt = L"hex";
|
292 |
|
|
this->openFileDialog1->FileName = L"boot";
|
293 |
|
|
this->openFileDialog1->Filter = L"\"INTEL Hex Files|*.hex|All Files|*.*\"";
|
294 |
|
|
this->openFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &frmMain::openFileDialog1_FileOk);
|
295 |
|
|
//
|
296 |
|
|
// lblChecksumError
|
297 |
|
|
//
|
298 |
|
|
this->lblChecksumError->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
|
299 |
|
|
this->lblChecksumError->AutoSize = true;
|
300 |
|
|
this->lblChecksumError->Location = System::Drawing::Point(75, 522);
|
301 |
|
|
this->lblChecksumError->Name = L"lblChecksumError";
|
302 |
|
|
this->lblChecksumError->Size = System::Drawing::Size(35, 13);
|
303 |
|
|
this->lblChecksumError->TabIndex = 2;
|
304 |
|
|
this->lblChecksumError->Text = L"label1";
|
305 |
|
|
//
|
306 |
|
|
// pictureBox1
|
307 |
|
|
//
|
308 |
|
|
this->pictureBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
|
309 |
|
|
this->pictureBox1->Location = System::Drawing::Point(12, 507);
|
310 |
|
|
this->pictureBox1->Name = L"pictureBox1";
|
311 |
|
|
this->pictureBox1->Size = System::Drawing::Size(218, 12);
|
312 |
|
|
this->pictureBox1->TabIndex = 3;
|
313 |
|
|
this->pictureBox1->TabStop = false;
|
314 |
|
|
this->pictureBox1->Click += gcnew System::EventHandler(this, &frmMain::pictureBox1_Click);
|
315 |
|
|
this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &frmMain::pictureBox1_Paint);
|
316 |
|
|
//
|
317 |
|
|
// listBoxAdr
|
318 |
|
|
//
|
319 |
|
|
this->listBoxAdr->FormattingEnabled = true;
|
320 |
|
|
this->listBoxAdr->Location = System::Drawing::Point(12, 52);
|
321 |
|
|
this->listBoxAdr->Name = L"listBoxAdr";
|
322 |
|
|
this->listBoxAdr->Size = System::Drawing::Size(71, 433);
|
323 |
|
|
this->listBoxAdr->TabIndex = 4;
|
324 |
|
|
//
|
325 |
|
|
// listBoxBytes
|
326 |
|
|
//
|
327 |
|
|
this->listBoxBytes->FormattingEnabled = true;
|
328 |
|
|
this->listBoxBytes->Location = System::Drawing::Point(89, 52);
|
329 |
|
|
this->listBoxBytes->Name = L"listBoxBytes";
|
330 |
|
|
this->listBoxBytes->Size = System::Drawing::Size(141, 433);
|
331 |
|
|
this->listBoxBytes->TabIndex = 5;
|
332 |
|
|
//
|
333 |
|
|
// listBoxCode
|
334 |
|
|
//
|
335 |
|
|
this->listBoxCode->FormattingEnabled = true;
|
336 |
|
|
this->listBoxCode->Location = System::Drawing::Point(236, 52);
|
337 |
|
|
this->listBoxCode->Name = L"listBoxCode";
|
338 |
|
|
this->listBoxCode->Size = System::Drawing::Size(327, 433);
|
339 |
|
|
this->listBoxCode->TabIndex = 6;
|
340 |
|
|
//
|
341 |
|
|
// lblLEDS
|
342 |
|
|
//
|
343 |
|
|
this->lblLEDS->AutoSize = true;
|
344 |
|
|
this->lblLEDS->Location = System::Drawing::Point(275, 507);
|
345 |
|
|
this->lblLEDS->Name = L"lblLEDS";
|
346 |
|
|
this->lblLEDS->Size = System::Drawing::Size(40, 13);
|
347 |
|
|
this->lblLEDS->TabIndex = 7;
|
348 |
|
|
this->lblLEDS->Text = L"lblLeds";
|
349 |
|
|
//
|
350 |
|
|
// frmMain
|
351 |
|
|
//
|
352 |
|
|
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
|
353 |
|
|
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
|
354 |
|
|
this->ClientSize = System::Drawing::Size(684, 548);
|
355 |
|
|
this->Controls->Add(this->lblLEDS);
|
356 |
|
|
this->Controls->Add(this->listBoxCode);
|
357 |
|
|
this->Controls->Add(this->listBoxBytes);
|
358 |
|
|
this->Controls->Add(this->listBoxAdr);
|
359 |
|
|
this->Controls->Add(this->pictureBox1);
|
360 |
|
|
this->Controls->Add(this->lblChecksumError);
|
361 |
|
|
this->Controls->Add(this->toolStrip1);
|
362 |
|
|
this->Controls->Add(this->menuStrip1);
|
363 |
|
|
this->MainMenuStrip = this->menuStrip1;
|
364 |
|
|
this->Name = L"frmMain";
|
365 |
|
|
this->Text = L"Thor ISA Emulator";
|
366 |
|
|
this->menuStrip1->ResumeLayout(false);
|
367 |
|
|
this->menuStrip1->PerformLayout();
|
368 |
|
|
this->toolStrip1->ResumeLayout(false);
|
369 |
|
|
this->toolStrip1->PerformLayout();
|
370 |
|
|
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
|
371 |
|
|
this->ResumeLayout(false);
|
372 |
|
|
this->PerformLayout();
|
373 |
|
|
|
374 |
|
|
}
|
375 |
|
|
#pragma endregion
|
376 |
|
|
private: System::Void registersToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
377 |
|
|
frmRegisters^ form = gcnew frmRegisters();
|
378 |
|
|
form->Show();
|
379 |
|
|
}
|
380 |
|
|
private: System::Void loadINTELHexFIleToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
381 |
|
|
this->openFileDialog1->ShowDialog();
|
382 |
|
|
LoadIntelHexFile();
|
383 |
|
|
return;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
private: int IHChecksumCheck(const char *buf) {
|
387 |
|
|
int nn;
|
388 |
|
|
int sum;
|
389 |
|
|
std::string str;
|
390 |
|
|
std::string str1;
|
391 |
|
|
str = std::string(buf);
|
392 |
|
|
sum = 0;
|
393 |
|
|
for (nn = 1; nn < str.length(); nn+=2) {
|
394 |
|
|
str1 = str.substr(nn,2);
|
395 |
|
|
sum += strtoul(str1.c_str(),NULL,16);
|
396 |
|
|
}
|
397 |
|
|
sum &= 0xff;
|
398 |
|
|
return sum;
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
private: void LoadIntelHexFile() {
|
402 |
|
|
int nc,nn;
|
403 |
|
|
std::string buf;
|
404 |
|
|
std::string str_ad;
|
405 |
|
|
std::string str_insn;
|
406 |
|
|
std::string str_ad_insn;
|
407 |
|
|
std::string str_disassem;
|
408 |
|
|
unsigned int ad;
|
409 |
|
|
unsigned __int64 dat;
|
410 |
|
|
unsigned __int64 b0,b1,b2,b3,b4,b5,b6,b7;
|
411 |
|
|
unsigned int firstAdr;
|
412 |
|
|
char buf2[40];
|
413 |
|
|
unsigned int ad_msbs;
|
414 |
|
|
int chksum;
|
415 |
|
|
int lineno; // 16531
|
416 |
|
|
|
417 |
|
|
char* str = (char*)(void*)Marshal::StringToHGlobalAnsi(this->openFileDialog1->FileName);
|
418 |
|
|
System::Windows::Forms::Cursor::Current = System::Windows::Forms::Cursors::WaitCursor;
|
419 |
|
|
std::ifstream fp_in;
|
420 |
|
|
fp_in.open(str,std::ios::in);
|
421 |
|
|
firstAdr = 0;
|
422 |
|
|
ad_msbs = 0;
|
423 |
|
|
chksum = 0;
|
424 |
|
|
lineno=0;
|
425 |
|
|
system1.WriteROM = true;
|
426 |
|
|
while (!fp_in.eof()) {
|
427 |
|
|
lineno++;
|
428 |
|
|
std::getline(fp_in, buf);
|
429 |
|
|
chksum += IHChecksumCheck(buf.c_str());
|
430 |
|
|
if (buf.c_str()[0]!=':') continue;
|
431 |
|
|
if (buf.c_str()[8]=='4') {
|
432 |
|
|
strncpy(buf2,&((buf.c_str())[9]),4);
|
433 |
|
|
buf2[4] = '\0';
|
434 |
|
|
ad_msbs = strtoul(buf2,NULL,16);
|
435 |
|
|
continue;
|
436 |
|
|
}
|
437 |
|
|
// Process record type #'00'
|
438 |
|
|
if (buf.c_str()[8]=='0') {
|
439 |
|
|
ad = strtoul(buf.substr(3,4).c_str(),NULL,16) | (ad_msbs << 16);
|
440 |
|
|
b0 = strtoul(buf.substr(9,2).c_str(),NULL,16);
|
441 |
|
|
b1 = strtoul(buf.substr(11,2).c_str(),NULL,16);
|
442 |
|
|
b2 = strtoul(buf.substr(13,2).c_str(),NULL,16);
|
443 |
|
|
b3 = strtoul(buf.substr(15,2).c_str(),NULL,16);
|
444 |
|
|
b4 = strtoul(buf.substr(17,2).c_str(),NULL,16);
|
445 |
|
|
b5 = strtoul(buf.substr(19,2).c_str(),NULL,16);
|
446 |
|
|
b6 = strtoul(buf.substr(21,2).c_str(),NULL,16);
|
447 |
|
|
b7 = strtoul(buf.substr(23,2).c_str(),NULL,16);
|
448 |
|
|
dat = b0 |
|
449 |
|
|
(b1 << 8) |
|
450 |
|
|
(b2 << 16) |
|
451 |
|
|
(b3 << 24) |
|
452 |
|
|
(b4 << 32) |
|
453 |
|
|
(b5 << 40) |
|
454 |
|
|
(b6 << 48) |
|
455 |
|
|
(b7 << 56)
|
456 |
|
|
;
|
457 |
|
|
}
|
458 |
|
|
if (!firstAdr)
|
459 |
|
|
firstAdr = ad;
|
460 |
|
|
system1.Write(ad, dat, 0xFF, 0);
|
461 |
|
|
//system1.memory[ad>>2] = dat;
|
462 |
|
|
//sprintf(buf2,"%06X", ad);
|
463 |
|
|
//str_ad = std::string(buf2);
|
464 |
|
|
//sprintf(buf2,"%08X", dat);
|
465 |
|
|
//str_insn = std::string(buf2);
|
466 |
|
|
//str_disassem = Disassem(str_ad,str_insn);
|
467 |
|
|
//str_ad_insn = str_ad + " " + str_insn + " " + str_disassem;
|
468 |
|
|
//label1->Text = gcnew String(str_ad_insn.c_str());
|
469 |
|
|
//this->checkedListBox1->Items->Add(gcnew String(str_ad_insn.c_str()));
|
470 |
|
|
}
|
471 |
|
|
fp_in.close();
|
472 |
|
|
system1.WriteROM = false;
|
473 |
|
|
ad = firstAdr;
|
474 |
|
|
UpdateListBoxes(ad);
|
475 |
|
|
if (chksum != 0) {
|
476 |
|
|
sprintf(buf2, "Checksum Error: %d", chksum);
|
477 |
|
|
this->lblChecksumError->Text = gcnew String(buf2);
|
478 |
|
|
}
|
479 |
|
|
else
|
480 |
|
|
this->lblChecksumError->Text = "Checksum OK";
|
481 |
|
|
System::Windows::Forms::Cursor::Current = System::Windows::Forms::Cursors::Default;
|
482 |
|
|
}
|
483 |
|
|
private: System::Void memoryToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
484 |
|
|
frmMemory^ form = gcnew frmMemory;
|
485 |
|
|
form->Show();
|
486 |
|
|
}
|
487 |
|
|
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
|
488 |
|
|
}
|
489 |
|
|
private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
|
490 |
|
|
Graphics^ gr = e->Graphics;
|
491 |
|
|
int h = pictureBox1->ClientSize.Height;
|
492 |
|
|
int w = h;
|
493 |
|
|
int nn,kk;
|
494 |
|
|
for (kk= 15, nn = 0; nn < 16; nn++, kk--) {
|
495 |
|
|
if (system1.leds & (1 << kk))
|
496 |
|
|
gr->FillEllipse(gcnew SolidBrush(Color::Green),System::Drawing::Rectangle(w*nn,0,w-1,h-1));
|
497 |
|
|
else
|
498 |
|
|
gr->FillEllipse(gcnew SolidBrush(Color::FromArgb(0xFF003000)),System::Drawing::Rectangle(w*nn,0,w-1,h-1));
|
499 |
|
|
}
|
500 |
|
|
}
|
501 |
|
|
private: void UpdateListBoxes(int ad)
|
502 |
|
|
{
|
503 |
|
|
int nn,nb,kk;
|
504 |
|
|
char buf2[100];
|
505 |
|
|
std::string dstr;
|
506 |
|
|
std::string buf;
|
507 |
|
|
int adr[32];
|
508 |
|
|
|
509 |
|
|
listBoxAdr->Items->Clear();
|
510 |
|
|
listBoxBytes->Items->Clear();
|
511 |
|
|
listBoxCode->Items->Clear();
|
512 |
|
|
for (nn = 0; nn < 32; nn++) {
|
513 |
|
|
adr[nn] = ad;
|
514 |
|
|
sprintf(buf2,"%06X", ad);
|
515 |
|
|
buf = std::string(buf2);
|
516 |
|
|
this->listBoxAdr->Items->Add(gcnew String(buf.c_str()));
|
517 |
|
|
dstr = da.Disassem(ad,&nb);
|
518 |
|
|
buf2[0] = '\0';
|
519 |
|
|
for (kk = 0; kk < nb; kk++) {
|
520 |
|
|
sprintf(&buf2[strlen(buf2)], "%02X ", system1.ReadByte(ad));
|
521 |
|
|
ad++;
|
522 |
|
|
}
|
523 |
|
|
buf = std::string(buf2);
|
524 |
|
|
this->listBoxBytes->Items->Add(gcnew String(buf.c_str()));
|
525 |
|
|
this->listBoxCode->Items->Add(gcnew String(dstr.c_str()));
|
526 |
|
|
}
|
527 |
|
|
for (nn = 0; nn < 32; nn++) {
|
528 |
|
|
if (adr[nn]==cpu1.pc) {
|
529 |
|
|
this->listBoxAdr->SetSelected(nn,true);
|
530 |
|
|
this->listBoxBytes->SetSelected(nn,true);
|
531 |
|
|
this->listBoxCode->SetSelected(nn,true);
|
532 |
|
|
}
|
533 |
|
|
}
|
534 |
|
|
}
|
535 |
|
|
private: System::Void stepToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
536 |
|
|
}
|
537 |
|
|
private: System::Void resetToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
538 |
|
|
Reset();
|
539 |
|
|
}
|
540 |
|
|
private: void Reset() {
|
541 |
|
|
system1.Reset();
|
542 |
|
|
pic1.Reset();
|
543 |
|
|
cpu1.Reset();
|
544 |
|
|
UpdateListBoxes(PCIsInList(cpu1.pc-32));
|
545 |
|
|
}
|
546 |
|
|
|
547 |
|
|
// Try and align the disassembled code with the current PC.
|
548 |
|
|
private: int PCIsInList(int as)
|
549 |
|
|
{
|
550 |
|
|
int nn, nb;
|
551 |
|
|
std::string dstr;
|
552 |
|
|
int ae;
|
553 |
|
|
int ad = as;
|
554 |
|
|
|
555 |
|
|
for (ad = as; ad > as-32; ad--) {
|
556 |
|
|
ae = ad;
|
557 |
|
|
for (nn = 0; nn < 64; nn++) {
|
558 |
|
|
if (ae==cpu1.pc)
|
559 |
|
|
return ad;
|
560 |
|
|
dstr = da.Disassem(ae,&nb);
|
561 |
|
|
ae += nb;
|
562 |
|
|
}
|
563 |
|
|
}
|
564 |
|
|
return as;
|
565 |
|
|
}
|
566 |
|
|
|
567 |
|
|
private: void DoStepInto() {
|
568 |
|
|
// animate = false;
|
569 |
|
|
// isRunning = false;
|
570 |
|
|
char buf[100];
|
571 |
|
|
cpu1.Step();
|
572 |
|
|
pic1.Step();
|
573 |
|
|
UpdateListBoxes(PCIsInList(cpu1.pc-32));
|
574 |
|
|
sprintf(buf, "%04X", system1.leds);
|
575 |
|
|
lblLEDS->Text = gcnew String(buf);
|
576 |
|
|
pictureBox1->Refresh();
|
577 |
|
|
}
|
578 |
|
|
private: System::Void toolStripButton1_Click(System::Object^ sender, System::EventArgs^ e) {
|
579 |
|
|
DoStepInto();
|
580 |
|
|
}
|
581 |
|
|
private: System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
|
582 |
|
|
}
|
583 |
|
|
private: System::Void aboutToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
|
584 |
|
|
About^ form = gcnew About;
|
585 |
|
|
form->Show();
|
586 |
|
|
}
|
587 |
|
|
};
|
588 |
|
|
}
|
589 |
|
|
|