Browse code

Add source code of the XiPC emulator

Pawel Jablonski authored on 17/03/2023 16:46:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,789 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#include "emu.h"
13
+#include "ui_emu.h"
14
+
15
+/**
16
+ * Constructor for the emulator class
17
+ *
18
+ * @param parent Parent object
19
+ */
20
+Emu::Emu(QWidget *parent) : QMainWindow(parent), ui(new Ui::Emu)
21
+{
22
+	ui->setupUi(this);
23
+
24
+	this->loaded = false;
25
+	this->started = false;
26
+	this->running = false;
27
+
28
+	this->ui->fileUrom0PathLabel->setText("");
29
+	this->ui->fileUrom1PathLabel->setText("");
30
+	this->ui->fileRomPathLabel->setText("");
31
+	this->ui->fileFSDirPathLabel->setText("");
32
+
33
+	this->reset();
34
+	this->update();
35
+
36
+	this->ui->speakerVolumeSlider->setValue(50);
37
+	this->ui->speakerVolumeValueLabel->setText("50%");
38
+
39
+	this->setFocus();
40
+
41
+	QObject::connect(&this->cpu, SIGNAL(updateSignal()), this, SLOT(updateSlot()));
42
+
43
+	QObject::connect(&this->io, SIGNAL(updateLCDBufferSignal(LCD::Buffer)), ui->lcdBufferView, SLOT(drawSlot(LCD::Buffer)));
44
+
45
+	QObject::connect(&this->io, SIGNAL(updateLEDRunSignal(bool)), this, SLOT(updateLEDRunSlot(bool)));
46
+	QObject::connect(&this->io, SIGNAL(updateLEDErrorSignal(bool)), this, SLOT(updateLEDErrorSlot(bool)));
47
+
48
+	QObject::connect(&this->io, SIGNAL(updateRS232TxSignal(unsigned char)), this, SLOT(updateRS232TxSlot(unsigned char)));
49
+	QObject::connect(&this->io, SIGNAL(updateRS232RxSignal(unsigned char)), this, SLOT(updateRS232RxSlot(unsigned char)));
50
+
51
+	QObject::connect(&this->io, SIGNAL(updateRTCDateTimeSignal(QDateTime)), this, SLOT(updateRTCDateTimeSlot(QDateTime)));
52
+
53
+	QObject::connect(&this->io, SIGNAL(updateSpeakerStatusSignal(int)), this, SLOT(updateSpeakerStatusSlot(int)));
54
+
55
+	QObject::connect(&this->cpu, SIGNAL(outSignal(unsigned char)), &this->io, SLOT(outSlot(unsigned char)));
56
+	QObject::connect(&this->io, SIGNAL(inSignal(unsigned char)), &this->cpu, SLOT(inSlot(unsigned char)));
57
+}
58
+
59
+//! Destructor for the emulator class
60
+Emu::~Emu()
61
+{
62
+	QObject::disconnect(&this->io);
63
+	QObject::disconnect(&this->cpu);
64
+
65
+	QObject::disconnect(this);
66
+
67
+	delete ui;
68
+}
69
+
70
+//! Reset the UI elements
71
+void Emu::reset()
72
+{
73
+	this->ui->regAValueHexLabel->setText("");
74
+	this->ui->regAValueDecLabel->setText("");
75
+	this->ui->regAValueBinLabel->setText("");
76
+
77
+	this->ui->regBValueHexLabel->setText("");
78
+	this->ui->regBValueDecLabel->setText("");
79
+	this->ui->regBValueBinLabel->setText("");
80
+
81
+	this->ui->regXValueHexLabel->setText("");
82
+	this->ui->regXValueDecLabel->setText("");
83
+	this->ui->regXValueBinLabel->setText("");
84
+
85
+	this->ui->regYValueHexLabel->setText("");
86
+	this->ui->regYValueDecLabel->setText("");
87
+	this->ui->regYValueBinLabel->setText("");
88
+
89
+	this->ui->regINValueHexLabel->setText("");
90
+	this->ui->regINValueDecLabel->setText("");
91
+	this->ui->regINValueBinLabel->setText("");
92
+
93
+	this->ui->regOUTValueHexLabel->setText("");
94
+	this->ui->regOUTValueDecLabel->setText("");
95
+	this->ui->regOUTValueBinLabel->setText("");
96
+
97
+	this->ui->regIValueHexLabel->setText("");
98
+	this->ui->regIValueBinLabel->setText("");
99
+
100
+	this->ui->regPCHValueLabel->setText("");
101
+	this->ui->regPCLValueLabel->setText("");
102
+
103
+	this->ui->regCValueLabel->setText("");
104
+	this->ui->regZValueLabel->setText("");
105
+
106
+	this->ui->regSPHValueLabel->setText("");
107
+	this->ui->regSPLValueLabel->setText("");
108
+	this->ui->regSPLMaxValueLabel->setText("");
109
+
110
+	this->ui->emuTimeValueLabel->setText("");
111
+
112
+	this->ui->lcdBufferView->reset();
113
+
114
+	this->ui->ledRunValueLabel->setText("");
115
+	this->ui->ledRunValueLabel->setStyleSheet("");
116
+
117
+	this->ui->ledErrorValueLabel->setText("");
118
+	this->ui->ledErrorValueLabel->setStyleSheet("");
119
+
120
+	this->romSetPage(0);
121
+	this->ramSetPage(0);
122
+
123
+	this->ui->rs232RxText->clear();
124
+	this->ui->rs232TxText->clear();
125
+	this->ui->rs232RxEdit->clear();
126
+
127
+	QDateTime dateTime;
128
+	dateTime.setDate(QDate(2000, 1, 1));
129
+
130
+	this->ui->rtcValueLabel->setText(dateTime.toString("yyyy.MM.dd hh:mm:ss"));
131
+
132
+	this->ui->speakerBufferValueLabel->setText("0");
133
+}
134
+
135
+//! Update internal statuses and UI elements
136
+void Emu::update()
137
+{
138
+	if(!this->started)
139
+	{
140
+		if((!this->ui->fileUrom0PathLabel->text().isEmpty()) && (!this->ui->fileUrom1PathLabel->text().isEmpty()) && (!this->ui->fileRomPathLabel->text().isEmpty()) && (!this->ui->fileFSDirPathLabel->text().isEmpty()))
141
+		{
142
+			this->loaded = true;
143
+		}
144
+		else
145
+		{
146
+			this->loaded = false;
147
+		}
148
+	}
149
+
150
+	this->ui->fileUrom0OpenButton->setEnabled(!this->started);
151
+	this->ui->fileUrom1OpenButton->setEnabled(!this->started);
152
+	this->ui->fileRomOpenButton->setEnabled(!this->started);
153
+	this->ui->fileFSDirOpenButton->setEnabled(!this->started);
154
+
155
+	this->ui->fileUrom0ReloadButton->setEnabled((!this->started) && (!this->ui->fileUrom0PathLabel->text().isEmpty()));
156
+	this->ui->fileUrom1ReloadButton->setEnabled((!this->started) && (!this->ui->fileUrom1PathLabel->text().isEmpty()));
157
+	this->ui->fileRomReloadButton->setEnabled((!this->started) && (!this->ui->fileRomPathLabel->text().isEmpty()));
158
+
159
+	if(this->loaded)
160
+	{
161
+		if(this->running)
162
+		{
163
+			this->ui->emuStatusValueLabel->setText("Running");
164
+		}
165
+		else
166
+		{
167
+			if(this->started)
168
+			{
169
+				this->ui->emuStatusValueLabel->setText("Paused");
170
+			}
171
+			else
172
+			{
173
+				this->ui->emuStatusValueLabel->setText("Stopped");
174
+			}
175
+		}
176
+	}
177
+	else
178
+	{
179
+		this->ui->emuStatusValueLabel->setText("");
180
+	}
181
+
182
+	this->ui->emuControlRunButton->setEnabled(this->loaded && (!this->running));
183
+	this->ui->emuControlStepButton->setEnabled(this->loaded && (!this->running));
184
+	this->ui->emuControlPauseButton->setEnabled(this->running);
185
+	this->ui->emuControlStopButton->setEnabled(this->started);
186
+
187
+	this->ui->romGoToOSButton->setEnabled(this->started);
188
+	this->ui->romGoToAppButton->setEnabled(this->started);
189
+
190
+	this->ui->ramGoToOSButton->setEnabled(this->started);
191
+	this->ui->ramGoToSPButton->setEnabled(this->started);
192
+	this->ui->ramGoToAppButton->setEnabled(this->started);
193
+
194
+	this->ui->rs232RxSendButton->setEnabled(this->started);
195
+	this->ui->rtcSetCurrentButton->setEnabled(this->started);
196
+	this->ui->speakerVolumeSlider->setEnabled(this->started);
197
+}
198
+
199
+/**
200
+ * Set ROM page to show
201
+ *
202
+ * @param page Page number
203
+ */
204
+void Emu::romSetPage(int page)
205
+{
206
+	if((page >= 0) && (((CPU::MEMORY_SIZE * 2) / CPU::MEMORY_PAGE_SIZE) > page))
207
+	{
208
+		this->romPage = page;
209
+
210
+		this->ui->romText->clear();
211
+
212
+		if(this->started)
213
+		{
214
+			const CPU::Memory &rom = (((CPU::MEMORY_SIZE / CPU::MEMORY_PAGE_SIZE) > page) ? this->cpu.getRom() : this->cpu.getRamHigh());
215
+
216
+			QString text = "";
217
+
218
+			for(int i = 0; i < CPU::MEMORY_PAGE_SIZE; i++)
219
+			{
220
+				if(((i % 16) == 0) && (i != 0))
221
+				{
222
+					text.append("\n");
223
+				}
224
+				else if((i % 16) != 0)
225
+				{
226
+					text.append(" ");
227
+				}
228
+
229
+				if((CPU::MEMORY_SIZE / CPU::MEMORY_PAGE_SIZE) > page)
230
+				{
231
+					text.append(QString("%1").arg(rom.data[(this->romPage * CPU::MEMORY_PAGE_SIZE) + i], 2, 16, QChar('0')));
232
+				}
233
+				else
234
+				{
235
+					text.append(QString("%1").arg(rom.data[((this->romPage - (CPU::MEMORY_SIZE / CPU::MEMORY_PAGE_SIZE)) * CPU::MEMORY_PAGE_SIZE) + i], 2, 16, QChar('0')));
236
+				}
237
+			}
238
+
239
+			this->ui->romText->setPlainText(text);
240
+
241
+			this->ui->romMinusButton->setEnabled(page != 0);
242
+			this->ui->romPlusButton->setEnabled(page < (((CPU::MEMORY_SIZE * 2) / CPU::MEMORY_PAGE_SIZE) - 1));
243
+		}
244
+		else
245
+		{
246
+			this->ui->romMinusButton->setEnabled(false);
247
+			this->ui->romPlusButton->setEnabled(false);
248
+		}
249
+	}
250
+
251
+	QString addressPrefix = QString("%1").arg(this->romPage, 2, 16, QChar('0')).toUpper();
252
+	QString address = "";
253
+
254
+	address.append(addressPrefix);
255
+	address.append("00 - ");
256
+	address.append(addressPrefix);
257
+	address.append("FF");
258
+
259
+	this->ui->romAddressLabel->setText(QString().append(address));
260
+}
261
+
262
+/**
263
+ * Set RAM page to show
264
+ *
265
+ * @param page Page number
266
+ */
267
+void Emu::ramSetPage(int page)
268
+{
269
+	if((page >= 0) && ((CPU::MEMORY_SIZE / CPU::MEMORY_PAGE_SIZE) > page))
270
+	{
271
+		this->ramPage = page;
272
+
273
+		this->ui->ramText->clear();
274
+
275
+		if(this->started)
276
+		{
277
+			const CPU::Memory &ram = this->cpu.getRamLow();
278
+
279
+			QString text = "";
280
+
281
+			for(int i = 0; i < CPU::MEMORY_PAGE_SIZE; i++)
282
+			{
283
+				if(((i % 16) == 0) && (i != 0))
284
+				{
285
+					text.append("\n");
286
+				}
287
+				else if((i % 16) != 0)
288
+				{
289
+					text.append(" ");
290
+				}
291
+
292
+				text.append(QString("%1").arg(ram.data[(this->ramPage * CPU::MEMORY_PAGE_SIZE) + i], 2, 16, QChar('0')));
293
+			}
294
+
295
+			this->ui->ramText->setPlainText(text);
296
+
297
+			this->ui->ramMinusButton->setEnabled(page != 0);
298
+			this->ui->ramPlusButton->setEnabled(page < ((CPU::MEMORY_SIZE / CPU::MEMORY_PAGE_SIZE) - 1));
299
+		}
300
+		else
301
+		{
302
+			this->ui->ramMinusButton->setEnabled(false);
303
+			this->ui->ramPlusButton->setEnabled(false);
304
+		}
305
+	}
306
+
307
+	QString addressPrefix = QString("%1").arg(this->ramPage, 2, 16, QChar('0')).toUpper();
308
+	QString address = "";
309
+
310
+	address.append(addressPrefix);
311
+	address.append("00 - ");
312
+	address.append(addressPrefix);
313
+	address.append("FF");
314
+
315
+	this->ui->ramAddressLabel->setText(QString().append(address));
316
+}
317
+
318
+/**
319
+ * Load data from file to the memory buffer
320
+ *
321
+ * @param path Path to the file to load
322
+ * @param memory Buffer of the memory to fill
323
+ *
324
+ * @return Status of loading data to the memory buffer
325
+ */
326
+bool Emu::loadMemoryFile(const QString &path, CPU::Memory &memory)
327
+{
328
+	QFile file(path);
329
+
330
+	if(!file.open(QIODevice::ReadOnly))
331
+	{
332
+		QMessageBox::critical(this, "Error", "Unable to open file");
333
+		return(false);
334
+	}
335
+
336
+	if(CPU::MEMORY_SIZE != file.read(reinterpret_cast<char *>(memory.data.data()), CPU::MEMORY_SIZE))
337
+	{
338
+		QMessageBox::critical(this, "Error", "Bad size of file");
339
+		return(false);
340
+	}
341
+
342
+	file.close();
343
+
344
+	return(true);
345
+}
346
+
347
+/**
348
+ * Process the mouse press event
349
+ *
350
+ * @param event Mouse event
351
+ */
352
+void Emu::mousePressEvent(QMouseEvent *)
353
+{
354
+	this->setFocus();
355
+}
356
+
357
+/**
358
+ * Process the focus selector event
359
+ *
360
+ * @param next Search direction of the focus
361
+ *
362
+ * @return Status of finding next/previous widget to give the keyboard focus to
363
+ */
364
+bool Emu::focusNextPrevChild(bool)
365
+{
366
+	return(false);
367
+}
368
+
369
+/**
370
+ * Process the key press event
371
+ *
372
+ * @param event Key event
373
+ */
374
+void Emu::keyPressEvent(QKeyEvent *event)
375
+{
376
+	if(this->running)
377
+	{
378
+		this->io.keyboardKeyPress(event->key(), event->modifiers());
379
+	}
380
+}
381
+
382
+//! Update time, registers, memory view UI elements
383
+void Emu::updateSlot()
384
+{
385
+	unsigned long long ticks = this->cpu.getTicks();
386
+
387
+	QString timeMs = QString("%1").arg(((ticks / (CPU::FREQUENCY / 1000)) % 1000), 3, 10, QChar('0'));
388
+	QString timeSec = QString("%1").arg(((ticks / CPU::FREQUENCY) % 60), 2, 10, QChar('0'));
389
+	QString timeMin = QString("%1").arg(((ticks / (60 * CPU::FREQUENCY)) % 60), 2, 10, QChar('0'));
390
+	QString timeHour = QString("%1").arg(((ticks / (60 * CPU::FREQUENCY) / 60)), 2, 10, QChar('0'));
391
+
392
+	this->ui->emuTimeValueLabel->setText(QString("%1:%2:%3.%4").arg(timeHour, timeMin, timeSec, timeMs));
393
+
394
+	const CPU::Reg &reg = this->cpu.getReg();
395
+
396
+	this->ui->regAValueHexLabel->setText(QString("%1").arg(reg.a, 2, 16, QChar('0')));
397
+	this->ui->regAValueDecLabel->setText(QString("%1").arg(reg.a));
398
+	this->ui->regAValueBinLabel->setText(QString("%1").arg(reg.a, 8, 2, QChar('0')));
399
+
400
+	this->ui->regBValueHexLabel->setText(QString("%1").arg(reg.b, 2, 16, QChar('0')));
401
+	this->ui->regBValueDecLabel->setText(QString("%1").arg(reg.b));
402
+	this->ui->regBValueBinLabel->setText(QString("%1").arg(reg.b, 8, 2, QChar('0')));
403
+
404
+	this->ui->regXValueHexLabel->setText(QString("%1").arg(reg.x, 2, 16, QChar('0')));
405
+	this->ui->regXValueDecLabel->setText(QString("%1").arg(reg.x));
406
+	this->ui->regXValueBinLabel->setText(QString("%1").arg(reg.x, 8, 2, QChar('0')));
407
+
408
+	this->ui->regYValueHexLabel->setText(QString("%1").arg(reg.y, 2, 16, QChar('0')));
409
+	this->ui->regYValueDecLabel->setText(QString("%1").arg(reg.y));
410
+	this->ui->regYValueBinLabel->setText(QString("%1").arg(reg.y, 8, 2, QChar('0')));
411
+
412
+	this->ui->regINValueHexLabel->setText(QString("%1").arg(reg.in, 2, 16, QChar('0')));
413
+	this->ui->regINValueDecLabel->setText(QString("%1").arg(reg.in));
414
+	this->ui->regINValueBinLabel->setText(QString("%1").arg(reg.in, 8, 2, QChar('0')));
415
+
416
+	this->ui->regOUTValueHexLabel->setText(QString("%1").arg(reg.out, 2, 16, QChar('0')));
417
+	this->ui->regOUTValueDecLabel->setText(QString("%1").arg(reg.out));
418
+	this->ui->regOUTValueBinLabel->setText(QString("%1").arg(reg.out, 8, 2, QChar('0')));
419
+
420
+	this->ui->regIValueHexLabel->setText(QString("%1").arg(reg.i, 2, 16, QChar('0')));
421
+	this->ui->regIValueBinLabel->setText(QString("%1").arg(reg.i, 8, 2, QChar('0')));
422
+
423
+	this->ui->regPCHValueLabel->setText(QString("%1").arg(reg.pch, 2, 16, QChar('0')));
424
+	this->ui->regPCLValueLabel->setText(QString("%1").arg(reg.pcl, 2, 16, QChar('0')));
425
+
426
+	this->ui->regCValueLabel->setText(reg.c ? QString("1") : QString("0"));
427
+	this->ui->regZValueLabel->setText(reg.z ? QString("1") : QString("0"));
428
+
429
+	this->ui->regSPHValueLabel->setText(QString("%1").arg(reg.sph, 2, 16, QChar('0')));
430
+	this->ui->regSPLValueLabel->setText(QString("%1").arg(reg.spl, 2, 16, QChar('0')));
431
+	this->ui->regSPLMaxValueLabel->setText(QString("%1").arg(reg.maxSpl, 2, 16, QChar('0')));
432
+
433
+	this->romSetPage(this->romPage);
434
+	this->ramSetPage(this->ramPage);
435
+}
436
+
437
+/**
438
+ * Update status of run LED
439
+ *
440
+ * @param enable LED enable
441
+ */
442
+void Emu::updateLEDRunSlot(bool enable)
443
+{
444
+	this->ui->ledRunValueLabel->setText(enable ? "ON" : "");
445
+	this->ui->ledRunValueLabel->setStyleSheet(enable ? "QLabel { color : blue; }" : "");
446
+}
447
+
448
+/**
449
+ * Update status of error LED
450
+ *
451
+ * @param enable LED enable
452
+ */
453
+void Emu::updateLEDErrorSlot(bool enable)
454
+{
455
+	this->ui->ledErrorValueLabel->setText(enable ? "ON" : "");
456
+	this->ui->ledErrorValueLabel->setStyleSheet(enable ? "QLabel { color : red; }" : "");
457
+}
458
+
459
+/**
460
+ * Update status of transmited data via RS232
461
+ *
462
+ * @param c Transmited char
463
+ */
464
+void Emu::updateRS232TxSlot(unsigned char c)
465
+{
466
+	this->ui->rs232TxText->moveCursor(QTextCursor::End);
467
+
468
+	if(c != 0)
469
+	{
470
+		this->ui->rs232TxText->insertPlainText(QString(c));
471
+	}
472
+	else
473
+	{
474
+		this->ui->rs232TxText->insertPlainText("\n");
475
+	}
476
+
477
+	QScrollBar *scrollBar = this->ui->rs232TxText->verticalScrollBar();
478
+
479
+	scrollBar->setValue(scrollBar->maximum());
480
+}
481
+
482
+/**
483
+ * Update status of received data via RS232
484
+ *
485
+ * @param c Received char
486
+ */
487
+void Emu::updateRS232RxSlot(unsigned char c)
488
+{
489
+	this->ui->rs232RxText->moveCursor(QTextCursor::End);
490
+
491
+	if(c != 0)
492
+	{
493
+		this->ui->rs232RxText->insertPlainText(QString(c));
494
+	}
495
+	else
496
+	{
497
+		this->ui->rs232RxText->insertPlainText("\n");
498
+	}
499
+
500
+	QScrollBar *scrollBar = this->ui->rs232RxText->verticalScrollBar();
501
+
502
+	scrollBar->setValue(scrollBar->maximum());
503
+}
504
+
505
+/**
506
+ * Update status of date and time
507
+ *
508
+ * @param dateTime Date and time
509
+ */
510
+void Emu::updateRTCDateTimeSlot(const QDateTime &dateTime)
511
+{
512
+	this->ui->rtcValueLabel->setText(dateTime.toString("yyyy.MM.dd hh:mm:ss"));
513
+}
514
+
515
+/**
516
+ * Update status of the speaker buffer usage
517
+ *
518
+ * @param bufferUsed Buffer usage
519
+ */
520
+void Emu::updateSpeakerStatusSlot(int bufferUsed)
521
+{
522
+	this->ui->speakerBufferValueLabel->setText(QString("%1").arg(bufferUsed));
523
+}
524
+
525
+//! Process first uROM open event
526
+void Emu::on_fileUrom0OpenButton_clicked()
527
+{
528
+	QString path = QFileDialog::getOpenFileName(this, "", "", "UROM 0 (*.bin)");
529
+
530
+	if(!path.isEmpty())
531
+	{
532
+		CPU::Memory urom0;
533
+
534
+		if(this->loadMemoryFile(path, urom0))
535
+		{
536
+			this->ui->fileUrom0PathLabel->setText(path);
537
+
538
+			this->cpu.setUrom0(urom0);
539
+		}
540
+		else
541
+		{
542
+			this->ui->fileUrom0PathLabel->setText("");
543
+		}
544
+
545
+		this->update();
546
+	}
547
+}
548
+
549
+//! Process second uROM open event
550
+void Emu::on_fileUrom1OpenButton_clicked()
551
+{
552
+	QString path = QFileDialog::getOpenFileName(this, "", "", "UROM 1 (*.bin)");
553
+
554
+	if(!path.isEmpty())
555
+	{
556
+		CPU::Memory urom1;
557
+
558
+		if(this->loadMemoryFile(path, urom1))
559
+		{
560
+			this->ui->fileUrom1PathLabel->setText(path);
561
+
562
+			this->cpu.setUrom1(urom1);
563
+		}
564
+		else
565
+		{
566
+			this->ui->fileUrom1PathLabel->setText("");
567
+		}
568
+
569
+		this->update();
570
+	}
571
+}
572
+
573
+//! Process ROM open event
574
+void Emu::on_fileRomOpenButton_clicked()
575
+{
576
+	QString path = QFileDialog::getOpenFileName(this, "", "", "ROM (*.bin)");
577
+
578
+	if(!path.isEmpty())
579
+	{
580
+		CPU::Memory rom;
581
+
582
+		if(this->loadMemoryFile(path, rom))
583
+		{
584
+			this->ui->fileRomPathLabel->setText(path);
585
+
586
+			this->cpu.setRom(rom);
587
+		}
588
+		else
589
+		{
590
+			this->ui->fileRomPathLabel->setText("");
591
+		}
592
+
593
+		this->update();
594
+	}
595
+}
596
+
597
+//! Process file system open event
598
+void Emu::on_fileFSDirOpenButton_clicked()
599
+{
600
+	QString path = QFileDialog::getExistingDirectory(this, "", "");
601
+
602
+	if(!path.isEmpty())
603
+	{
604
+		this->ui->fileFSDirPathLabel->setText(path);
605
+
606
+		this->io.fsSetPath(path);
607
+
608
+		this->update();
609
+	}
610
+}
611
+
612
+//! Process first uROM reload event
613
+void Emu::on_fileUrom0ReloadButton_clicked()
614
+{
615
+	CPU::Memory urom0;
616
+
617
+	if(this->loadMemoryFile(this->ui->fileUrom0PathLabel->text(), urom0))
618
+	{
619
+		this->cpu.setUrom0(urom0);
620
+	}
621
+	else
622
+	{
623
+		this->ui->fileUrom0PathLabel->setText("");
624
+	}
625
+
626
+	this->update();
627
+}
628
+
629
+//! Process second uROM reload event
630
+void Emu::on_fileUrom1ReloadButton_clicked()
631
+{
632
+	CPU::Memory urom1;
633
+
634
+	if(this->loadMemoryFile(this->ui->fileUrom1PathLabel->text(), urom1))
635
+	{
636
+		this->cpu.setUrom1(urom1);
637
+	}
638
+	else
639
+	{
640
+		this->ui->fileUrom1PathLabel->setText("");
641
+	}
642
+
643
+	this->update();
644
+}
645
+
646
+//! Process ROM reload event
647
+void Emu::on_fileRomReloadButton_clicked()
648
+{
649
+	CPU::Memory rom;
650
+
651
+	if(this->loadMemoryFile(this->ui->fileRomPathLabel->text(), rom))
652
+	{
653
+		this->cpu.setRom(rom);
654
+	}
655
+	else
656
+	{
657
+		this->ui->fileRomPathLabel->setText("");
658
+	}
659
+
660
+	this->update();
661
+}
662
+
663
+//! Process run emulation event
664
+void Emu::on_emuControlRunButton_clicked()
665
+{
666
+	this->started = true;
667
+	this->running = true;
668
+
669
+	this->update();
670
+
671
+	this->cpu.run();
672
+}
673
+
674
+//! Process a make step emulation event
675
+void Emu::on_emuControlStepButton_clicked()
676
+{
677
+	this->started = true;
678
+
679
+	this->update();
680
+
681
+	this->cpu.step();
682
+}
683
+
684
+//! Process pause emulation event
685
+void Emu::on_emuControlPauseButton_clicked()
686
+{
687
+	this->running = false;
688
+
689
+	this->update();
690
+
691
+	this->cpu.pause();
692
+}
693
+
694
+//! Process stop emulation event
695
+void Emu::on_emuControlStopButton_clicked()
696
+{
697
+	this->started = false;
698
+	this->running = false;
699
+
700
+	this->cpu.stop();
701
+	this->io.reset();
702
+
703
+	this->reset();
704
+	this->update();
705
+}
706
+
707
+/**
708
+ * Process set volume level event
709
+ *
710
+ * @param value Volume level
711
+ */
712
+void Emu::on_speakerVolumeSlider_valueChanged(int value)
713
+{
714
+	this->io.speakerSetVolume(static_cast<unsigned int>(value));
715
+
716
+	this->ui->speakerVolumeValueLabel->setText(QString("%1%").arg(value));
717
+}
718
+
719
+//! Process set current time event
720
+void Emu::on_rtcSetCurrentButton_clicked()
721
+{
722
+	QDateTime dateTime = QDateTime::currentDateTime();
723
+
724
+	this->io.rtcSetDateTime(dateTime);
725
+}
726
+
727
+//! Process go to the OS section for ROM event
728
+void Emu::on_romGoToOSButton_clicked()
729
+{
730
+	this->romSetPage(CPU::ROM_OS_ADDRESS / CPU::MEMORY_PAGE_SIZE);
731
+}
732
+
733
+//! Process go to the application section for ROM event
734
+void Emu::on_romGoToAppButton_clicked()
735
+{
736
+	this->romSetPage(CPU::ROM_APP_ADDRESS / CPU::MEMORY_PAGE_SIZE);
737
+}
738
+
739
+//! Process go to the previous page for ROM event
740
+void Emu::on_romMinusButton_clicked()
741
+{
742
+	this->romSetPage(this->romPage - 1);
743
+}
744
+
745
+//! Process go to the next page for ROM event
746
+void Emu::on_romPlusButton_clicked()
747
+{
748
+	this->romSetPage(this->romPage + 1);
749
+}
750
+
751
+//! Process go to the OS section for RAM event
752
+void Emu::on_ramGoToOSButton_clicked()
753
+{
754
+	this->ramSetPage(CPU::RAM_OS_ADDRESS / CPU::MEMORY_PAGE_SIZE);
755
+}
756
+
757
+//! Process go to the Stack section for RAM event
758
+void Emu::on_ramGoToSPButton_clicked()
759
+{
760
+	this->ramSetPage(CPU::RAM_SP_ADDRESS / CPU::MEMORY_PAGE_SIZE);
761
+}
762
+
763
+//! Process go to the application section for RAM event
764
+void Emu::on_ramGoToAppButton_clicked()
765
+{
766
+	this->ramSetPage(CPU::RAM_APP_ADDRESS / CPU::MEMORY_PAGE_SIZE);
767
+}
768
+
769
+//! Process go to the previous page for RAM event
770
+void Emu::on_ramMinusButton_clicked()
771
+{
772
+	this->ramSetPage(this->ramPage - 1);
773
+}
774
+
775
+//! Process go to the next page for RAM event
776
+void Emu::on_ramPlusButton_clicked()
777
+{
778
+	this->ramSetPage(this->ramPage + 1);
779
+}
780
+
781
+//! Process send the transmit buffer data via RS232 event
782
+void Emu::on_rs232RxSendButton_clicked()
783
+{
784
+	QString text = this->ui->rs232RxEdit->text();
785
+
786
+	this->ui->rs232RxEdit->clear();
787
+
788
+	this->io.rs232Receive(text);
789
+}