1 |
32 |
robfinch |
#pragma once
|
2 |
|
|
#include "stdafx.h"
|
3 |
|
|
|
4 |
|
|
extern clsSystem system1;
|
5 |
|
|
extern bool isRunning;
|
6 |
|
|
|
7 |
|
|
namespace emuThor {
|
8 |
|
|
|
9 |
|
|
using namespace System;
|
10 |
|
|
using namespace System::ComponentModel;
|
11 |
|
|
using namespace System::Collections;
|
12 |
|
|
using namespace System::Windows::Forms;
|
13 |
|
|
using namespace System::Data;
|
14 |
|
|
using namespace System::Drawing;
|
15 |
|
|
using namespace System::Threading;
|
16 |
|
|
|
17 |
|
|
/// <summary>
|
18 |
|
|
/// Summary for fmrFreeRun
|
19 |
|
|
/// </summary>
|
20 |
|
|
public ref class fmrFreeRun : public System::Windows::Forms::Form
|
21 |
|
|
{
|
22 |
|
|
public:
|
23 |
|
|
Mutex^ mut;
|
24 |
|
|
fmrFreeRun(Mutex^ m)
|
25 |
|
|
{
|
26 |
|
|
mut = m;
|
27 |
|
|
InitializeComponent();
|
28 |
|
|
//
|
29 |
|
|
//TODO: Add the constructor code here
|
30 |
|
|
//
|
31 |
|
|
InitializeBackgroundWorker();
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
protected:
|
35 |
|
|
/// <summary>
|
36 |
|
|
/// Clean up any resources being used.
|
37 |
|
|
/// </summary>
|
38 |
|
|
~fmrFreeRun()
|
39 |
|
|
{
|
40 |
|
|
if (components)
|
41 |
|
|
{
|
42 |
|
|
delete components;
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
private: System::Windows::Forms::Label^ label1;
|
46 |
|
|
protected:
|
47 |
|
|
private: System::Windows::Forms::NumericUpDown^ numSeconds;
|
48 |
|
|
private: System::Windows::Forms::Button^ button1;
|
49 |
|
|
private: System::Windows::Forms::Button^ button2;
|
50 |
|
|
private: System::Windows::Forms::ProgressBar^ progressBar1;
|
51 |
|
|
private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
|
52 |
|
|
|
53 |
|
|
private:
|
54 |
|
|
/// <summary>
|
55 |
|
|
/// Required designer variable.
|
56 |
|
|
/// </summary>
|
57 |
|
|
System::ComponentModel::Container ^components;
|
58 |
|
|
|
59 |
|
|
#pragma region Windows Form Designer generated code
|
60 |
|
|
/// <summary>
|
61 |
|
|
/// Required method for Designer support - do not modify
|
62 |
|
|
/// the contents of this method with the code editor.
|
63 |
|
|
/// </summary>
|
64 |
|
|
void InitializeComponent(void)
|
65 |
|
|
{
|
66 |
|
|
this->label1 = (gcnew System::Windows::Forms::Label());
|
67 |
|
|
this->numSeconds = (gcnew System::Windows::Forms::NumericUpDown());
|
68 |
|
|
this->button1 = (gcnew System::Windows::Forms::Button());
|
69 |
|
|
this->button2 = (gcnew System::Windows::Forms::Button());
|
70 |
|
|
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
|
71 |
|
|
this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
|
72 |
|
|
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numSeconds))->BeginInit();
|
73 |
|
|
this->SuspendLayout();
|
74 |
|
|
//
|
75 |
|
|
// label1
|
76 |
|
|
//
|
77 |
|
|
this->label1->AutoSize = true;
|
78 |
|
|
this->label1->Location = System::Drawing::Point(20, 20);
|
79 |
|
|
this->label1->Name = L"label1";
|
80 |
|
|
this->label1->Size = System::Drawing::Size(86, 26);
|
81 |
|
|
this->label1->TabIndex = 0;
|
82 |
|
|
this->label1->Text = L"Number of Steps\r\n(1,000\'s)";
|
83 |
|
|
//
|
84 |
|
|
// numSeconds
|
85 |
|
|
//
|
86 |
|
|
this->numSeconds->Location = System::Drawing::Point(112, 18);
|
87 |
|
|
this->numSeconds->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {100000000, 0, 0, 0});
|
88 |
|
|
this->numSeconds->Name = L"numSeconds";
|
89 |
|
|
this->numSeconds->Size = System::Drawing::Size(101, 20);
|
90 |
|
|
this->numSeconds->TabIndex = 1;
|
91 |
|
|
//
|
92 |
|
|
// button1
|
93 |
|
|
//
|
94 |
|
|
this->button1->Location = System::Drawing::Point(138, 101);
|
95 |
|
|
this->button1->Name = L"button1";
|
96 |
|
|
this->button1->Size = System::Drawing::Size(75, 23);
|
97 |
|
|
this->button1->TabIndex = 2;
|
98 |
|
|
this->button1->Text = L"Start";
|
99 |
|
|
this->button1->UseVisualStyleBackColor = true;
|
100 |
|
|
this->button1->Click += gcnew System::EventHandler(this, &fmrFreeRun::button1_Click);
|
101 |
|
|
//
|
102 |
|
|
// button2
|
103 |
|
|
//
|
104 |
|
|
this->button2->DialogResult = System::Windows::Forms::DialogResult::Cancel;
|
105 |
|
|
this->button2->Enabled = false;
|
106 |
|
|
this->button2->Location = System::Drawing::Point(23, 101);
|
107 |
|
|
this->button2->Name = L"button2";
|
108 |
|
|
this->button2->Size = System::Drawing::Size(75, 23);
|
109 |
|
|
this->button2->TabIndex = 3;
|
110 |
|
|
this->button2->Text = L"Cancel";
|
111 |
|
|
this->button2->UseVisualStyleBackColor = true;
|
112 |
|
|
this->button2->Click += gcnew System::EventHandler(this, &fmrFreeRun::button2_Click);
|
113 |
|
|
//
|
114 |
|
|
// progressBar1
|
115 |
|
|
//
|
116 |
|
|
this->progressBar1->Location = System::Drawing::Point(23, 59);
|
117 |
|
|
this->progressBar1->Name = L"progressBar1";
|
118 |
|
|
this->progressBar1->Size = System::Drawing::Size(190, 23);
|
119 |
|
|
this->progressBar1->TabIndex = 4;
|
120 |
|
|
//
|
121 |
|
|
// backgroundWorker1
|
122 |
|
|
//
|
123 |
|
|
this->backgroundWorker1->WorkerReportsProgress = true;
|
124 |
|
|
this->backgroundWorker1->WorkerSupportsCancellation = true;
|
125 |
|
|
//
|
126 |
|
|
// fmrFreeRun
|
127 |
|
|
//
|
128 |
|
|
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
|
129 |
|
|
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
|
130 |
|
|
this->ClientSize = System::Drawing::Size(234, 141);
|
131 |
|
|
this->Controls->Add(this->progressBar1);
|
132 |
|
|
this->Controls->Add(this->button2);
|
133 |
|
|
this->Controls->Add(this->button1);
|
134 |
|
|
this->Controls->Add(this->numSeconds);
|
135 |
|
|
this->Controls->Add(this->label1);
|
136 |
|
|
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
|
137 |
|
|
this->MaximizeBox = false;
|
138 |
|
|
this->Name = L"fmrFreeRun";
|
139 |
|
|
this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
|
140 |
|
|
this->Text = L"emuThor - Free Run";
|
141 |
|
|
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numSeconds))->EndInit();
|
142 |
|
|
this->ResumeLayout(false);
|
143 |
|
|
this->PerformLayout();
|
144 |
|
|
|
145 |
|
|
}
|
146 |
|
|
#pragma endregion
|
147 |
|
|
private: void InitializeBackgroundWorker() {
|
148 |
|
|
backgroundWorker1->DoWork += gcnew DoWorkEventHandler(this, &fmrFreeRun::backgroundWorker1_DoWork);
|
149 |
|
|
backgroundWorker1->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler(this, &fmrFreeRun::backgroundWorker1_RunWorkerCompleted);
|
150 |
|
|
backgroundWorker1->ProgressChanged += gcnew ProgressChangedEventHandler(this, &fmrFreeRun::backgroundWorker1_ProgressChanged);
|
151 |
|
|
}
|
152 |
|
|
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
|
153 |
|
|
int xx;
|
154 |
|
|
int ticks = (int)this->numSeconds->Value * 1000;
|
155 |
|
|
|
156 |
|
|
this->button1->Enabled = false;
|
157 |
|
|
backgroundWorker1->RunWorkerAsync(ticks);
|
158 |
|
|
this->button2->Enabled = true;
|
159 |
|
|
progressBar1->Value = 0;
|
160 |
|
|
}
|
161 |
|
|
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
|
162 |
|
|
backgroundWorker1->CancelAsync();
|
163 |
|
|
this->button2->Enabled = false;
|
164 |
|
|
}
|
165 |
|
|
private: void backgroundWorker1_DoWork(Object^ sender, DoWorkEventArgs^ e) {
|
166 |
|
|
int xx;
|
167 |
|
|
BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
|
168 |
|
|
int div = safe_cast<Int32>(e->Argument) / 100;
|
169 |
|
|
int percentComplete = 0;
|
170 |
|
|
|
171 |
|
|
mut->WaitOne();
|
172 |
|
|
isRunning = true;
|
173 |
|
|
mut->ReleaseMutex();
|
174 |
|
|
for (xx = 0; xx < safe_cast<Int32>(e->Argument) && isRunning; xx++) {
|
175 |
|
|
if (worker->CancellationPending) {
|
176 |
|
|
e->Cancel = true;
|
177 |
|
|
xx = safe_cast<Int32>(e->Argument);
|
178 |
|
|
}
|
179 |
|
|
if (xx % div == 0) {
|
180 |
|
|
worker->ReportProgress(percentComplete);
|
181 |
|
|
percentComplete++;
|
182 |
|
|
}
|
183 |
|
|
mut->WaitOne();
|
184 |
|
|
system1.Run();
|
185 |
|
|
mut->ReleaseMutex();
|
186 |
|
|
}
|
187 |
|
|
mut->WaitOne();
|
188 |
|
|
isRunning = false;
|
189 |
|
|
mut->ReleaseMutex();
|
190 |
|
|
e->Result = 0;
|
191 |
|
|
}
|
192 |
|
|
private: void backgroundWorker1_ProgressChanged(Object^ sender, ProgressChangedEventArgs^ e) {
|
193 |
|
|
this->progressBar1->Value = e->ProgressPercentage;
|
194 |
|
|
}
|
195 |
|
|
private: void backgroundWorker1_RunWorkerCompleted( Object^ , RunWorkerCompletedEventArgs^ e) {
|
196 |
|
|
if (e->Error != nullptr) {
|
197 |
|
|
MessageBox::Show(e->Error->Message);
|
198 |
|
|
}
|
199 |
|
|
else if (e->Cancelled) {
|
200 |
|
|
/* possibly display cancelled message in a label */
|
201 |
|
|
}
|
202 |
|
|
else {
|
203 |
|
|
/* possibly display result status */
|
204 |
|
|
}
|
205 |
|
|
this->button2->Enabled = false;
|
206 |
|
|
this->button1->Enabled = true;
|
207 |
|
|
this->progressBar1->Value = 0;
|
208 |
|
|
}
|
209 |
|
|
};
|
210 |
|
|
}
|