-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
837 lines (780 loc) · 24.7 KB
/
main.qml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.2
ApplicationWindow {
id: window1
width: 1280
height: 720
minimumHeight: 590
minimumWidth: 973
visible: true
property string fileName: ""
title: "LALWE - Learn Assembly Languages With Ease"
onFileNameChanged: title = getTitle()
property var ramModel1: myModel1
property var ramModel2: myModel2
property int activeRamSlot1: -1
property int activeRamSlot2: -1
property int addressRam1: 0
property int addressRam2: 0
property int ramViewCellAmmount: 0
property int activeRegister: -1
property bool aluActive: false
property bool busToAluActive: false
property bool busFromAluActive: false
property int cycleState: -1
property int pc: 0
property int ind1: 0
property int ind2: 0
property int input: 0
property int accu: 0
property int opc: 0
property int arg: 0
property int dpt: 0
property int spt: 0
property int fpt: 0
property int fla: 0
property int operand: 0
property int result: 0
property string operation: "+"
property string decodedOpcode: "N/A"
property string addressMode: "N/A"
property string effectiveAddress: "N/A"
property string dynOutput: "<style>p{margin:0px}</style><p>Dynamic output:</p>"
property string status: "Ready"
property bool changesSaved: true
onChangesSavedChanged: title = getTitle()
signal saveProgram(string code,string path, int mode)
signal openProgram(string path)
signal playProgram()
signal abortProgram()
signal verifyProgram(string code)
signal assembleProgram(string code)
signal toggleAnimations(bool newState)
signal toggleRamHex(bool newState)
signal animStepForward()
signal windowClosing()
signal setRamViewAddr(int panel, string addr)
signal toggleFollow(bool newState)
signal changeAnimSpeed(real percentage)
signal resetSimulation()
signal sendInput(string text)
onAddressRam1Changed: {
rAMView1.fpIndex = window1.fpt - window1.addressRam1 >= 0 && window1.fpt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam1 : -1
rAMView1.spIndex = window1.spt - window1.addressRam1 >= 0 && window1.spt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam1 : -1
}
onAddressRam2Changed: {
rAMView2.fpIndex = window1.fpt - window1.addressRam2 >= 0 && window1.fpt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam2 : -1
rAMView2.spIndex = window1.spt - window1.addressRam2 >= 0 && window1.spt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam2 : -1
}
onFptChanged: {
rAMView1.fpIndex = window1.fpt - window1.addressRam1 >= 0 && window1.fpt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam1 : -1
rAMView1.spIndex = window1.spt - window1.addressRam1 >= 0 && window1.spt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam1 : -1
rAMView2.fpIndex = window1.fpt - window1.addressRam2 >= 0 && window1.fpt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam2 : -1
rAMView2.spIndex = window1.spt - window1.addressRam2 >= 0 && window1.spt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam2 : -1
}
onSptChanged: {
rAMView1.fpIndex = window1.fpt - window1.addressRam1 >= 0 && window1.fpt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam1 : -1
rAMView1.spIndex = window1.spt - window1.addressRam1 >= 0 && window1.spt - window1.addressRam1 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam1 : -1
rAMView2.fpIndex = window1.fpt - window1.addressRam2 >= 0 && window1.fpt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.fpt - window1.addressRam2 : -1
rAMView2.spIndex = window1.spt - window1.addressRam2 >= 0 && window1.spt - window1.addressRam2 < window1.ramViewCellAmmount ? window1.spt - window1.addressRam2 : -1
}
onStatusChanged: {
if(status == "Ready")
toggleAnimations(doAnimationsMenu.checked)
}
onClosing: {
if(!changesSaved) {
saveDialog.mode = 3
saveDialog.visible = true
close.accepted = false
} else {
windowClosing()
}
}
function printLine(line) {
textArea2.append(line);
}
function getTitle() {
var result = "LALWE - Learn Assembly Languages With Ease"
if(fileName.length > 0) result += " - " + fileName
if(!changesSaved) result += "*"
return result
}
function continueWork(mode) {
changesSaved = true
switch(mode) {
case 1:
textArea1.text = ""
fileName = ""
changesSaved = true
break;
case 2:
fileDialog1.title = "Open..."
fileDialog1.selectExisting = true;
fileDialog1.mode = 0
fileDialog1.visible = true
break;
case 3:
window1.close()
break;
default:
}
}
function getCodeFromFile(code) {
textArea1.text = code
changesSaved = true
}
FileDialog{
property int mode: 0
id:fileDialog1
title: ""
folder: shortcuts.home
selectFolder: false
selectMultiple: false
nameFilters: ["Text files (*.txt)", "All files (*)"]
onAccepted: {
if(title == "Save...") {
saveProgram(textArea1.text,fileUrl.toString().substring(8),mode)
} else {
openProgram(fileUrl.toString().substring(8))
}
}
}
MessageDialog{
id: saveDialog
title: "Save changes..."
standardButtons: StandardButton.Save | StandardButton.Discard | StandardButton.Cancel
property int mode: 0
onAccepted: {
if(fileName.length > 0) {
saveProgram(textArea1.text,fileName,mode)
} else {
fileDialog1.title = "Save..."
fileDialog1.selectExisting = false;
fileDialog1.mode = mode
fileDialog1.visible = true
}
}
onDiscard: {
continueWork(mode)
}
onHelp: {
Qt.openUrlExternally("https://github.com/Multimodcrafter/LALWE/wiki")
}
text: "You have made changes to your currently open program! Do you want to save those changes?"
icon: StandardIcon.Warning
}
Window{
id: aboutDialog
title: "About LALWE..."
width: 300
minimumWidth: 300
maximumWidth: 300
height: 200
minimumHeight: 200
maximumHeight: 200
flags: Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint
modality: Qt.ApplicationModal
Text{
anchors.horizontalCenter: parent.horizontalCenter
y: 30
text: "LALWE - Learn Assembly Languages With Ease\n\nVersion: " + APP_VERSION + "\nCreated with love by Robin Hänni\n\nLALWE is licensed under the GNU gpl v3\nLALWE uses the Qt and stxxl library"
}
Button{
text: "Ok"
y: 150
anchors.horizontalCenter: parent.horizontalCenter
onClicked: aboutDialog.close()
}
}
Window{
id: resetPopup
title: "Resetting..."
width: 300
minimumWidth: 300
maximumWidth: 300
height: 100
minimumHeight: 100
maximumHeight: 100
flags: Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint
modality: Qt.ApplicationModal
Text{
anchors.horizontalCenter: parent.horizontalCenter
y: 30
text: "Resetting simulation...\n\nThis should only take long the first time."
}
}
Timer {
id: resetTimer
interval: 100
running: false
repeat: false
onTriggered: {
resetSimulation()
resetPopup.close()
}
}
menuBar: MenuBar {
Menu {
title: "&File"
MenuItem{
text: "&New"
shortcut: StandardKey.New
onTriggered: {
if(changesSaved) {
textArea1.text = ""
fileName = ""
changesSaved = true
} else {
saveDialog.mode = 1
saveDialog.visible = true
}
}
}
MenuItem{
text: "&Open..."
shortcut: StandardKey.Open
onTriggered: {
if(changesSaved) {
fileDialog1.title = "Open..."
fileDialog1.selectExisting = true;
fileDialog1.mode = 0
fileDialog1.visible = true
} else {
saveDialog.mode = 2
saveDialog.visible = true
}
}
}
MenuItem{
text: "&Save"
shortcut: StandardKey.Save
onTriggered: {
if(fileName.length > 0) {
saveProgram(textArea1.text,fileName,0)
} else {
fileDialog1.title = "Save..."
fileDialog1.selectExisting = false;
fileDialog1.mode = 0
fileDialog1.visible = true
}
}
}
MenuItem{
text: "Save &as..."
shortcut: "Ctrl+Shift+S"
onTriggered: {
fileDialog1.title = "Save..."
fileDialog1.selectExisting = false;
fileDialog1.mode = 0
fileDialog1.visible = true
}
}
MenuItem{
text: "&Exit"
shortcut: "Ctrl+Q"
onTriggered: {
if(changesSaved) {
window1.close()
} else {
saveDialog.mode = 3
saveDialog.visible = true
}
}
}
}
Menu {
title: "&Assembler"
MenuItem {
text: "&Verify program"
enabled: window1.status == "Ready"
shortcut: "Ctrl+I"
onTriggered: verifyProgram(textArea1.text)
}
MenuItem {
text: "&Assemble program"
enabled: window1.status == "Ready"
shortcut: "Ctrl+T"
onTriggered: assembleProgram(textArea1.text)
}
MenuItem {
text: "Assemble program &without animations"
enabled: window1.status == "Ready"
shortcut: "Ctrl+Shift+T"
onTriggered: {
toggleAnimations(false);
assembleProgram(textArea1.text);
}
}
}
Menu {
title:"&Simulation"
MenuItem{
text: "&Start/Stop"
enabled: window1.status != "Assembling..."
shortcut: "F5"
onTriggered: {
playProgram()
}
}
MenuItem{
text: "Step &forward"
enabled: window1.status == "Simulation paused"
shortcut: "F6"
onTriggered: animStepForward()
}
MenuItem{
text: "Abort"
enabled: window1.status == "Simulation paused" || window1.status == "Simulation running..."
shortcut: "F7"
onTriggered: abortProgram()
}
MenuItem{
text: "&Reset"
shortcut: "Ctrl+R"
enabled: window1.status == "Ready"
onTriggered: {
resetPopup.visible = true
resetTimer.start()
}
}
MenuItem{
id: doAnimationsMenu
text: "Play &Animations"
checkable: true
checked: true
shortcut: "Ctrl+Shift+A"
onToggled: toggleAnimations(checked)
}
}
Menu {
title: "&View"
MenuItem{
text: "Toggle hexformat on &components"
shortcut: "Ctrl+H"
onTriggered: {
if(register1.hex || register2.hex ||
register3.hex || register4.hex ||
register5.hex || register6.hex ||
register7.hex || register8.hex ||
register9.hex || register10.hex ||
aLU1.hex) {
register1.hex = false; register2.hex = false
register3.hex = false; register4.hex = false
register5.hex = false; register6.hex = false
register7.hex = false; register8.hex = false
register9.hex = false; register10.hex = false
aLU1.hex = false
} else {
register1.hex = true; register2.hex = true
register3.hex = true; register4.hex = true
register5.hex = true; register6.hex = true
register7.hex = true; register8.hex = true
register9.hex = true; register10.hex = true
aLU1.hex = true
}
}
}
MenuItem{
text: "Format &RAM hexadecimal"
checkable: true
shortcut: "Ctrl+Shift+H"
onToggled: toggleRamHex(checked)
}
MenuItem{
text: "&Folow active RAM cell"
checkable: true
checked: true
shortcut: "Ctrl+F"
onToggled: toggleFollow(checked)
}
}
Menu {
title: "&Help"
MenuItem{
text: "&Documentation..."
shortcut: "F1"
onTriggered: Qt.openUrlExternally("https://github.com/Multimodcrafter/LALWE/wiki")
}
MenuItem{
text: "&About LALWE..."
onTriggered: aboutDialog.visible = true;
}
}
}
statusBar: StatusBar{
Text{
text: window1.status
}
}
TextArea {
id: textArea1
anchors.right: parent.right
anchors.rightMargin: 928
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
anchors.left: parent.left
anchors.leftMargin: 5
anchors.top: parent.top
anchors.topMargin: 5
onTextChanged: changesSaved = false
Component.onCompleted: changesSaved = true
}
ColumnLayout {
id: columnLayout1
x: 358
width: 224
anchors.right: parent.right
anchors.rightMargin: 698
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
anchors.top: parent.top
anchors.topMargin: 5
RAMView {
id: rAMView1
Layout.fillHeight: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
rAMmodel: window1.ramModel1
activeIndex: window1.activeRamSlot1
button1.onClicked: setRamViewAddr(1,rAMView1.textField1.text)
button2.onClicked: setRamViewAddr(1,"dec")
button3.onClicked: setRamViewAddr(1,"inc")
}
RAMView {
id: rAMView2
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
Layout.fillWidth: true
rAMmodel: window1.ramModel2
activeIndex: window1.activeRamSlot2
button1.onClicked: setRamViewAddr(2,rAMView2.textField1.text)
button2.onClicked: setRamViewAddr(2,"dec")
button3.onClicked: setRamViewAddr(2,"inc")
}
}
Controller {
id: controller1
x: 628
height: 172
cyclestate: window1.cycleState
address: window1.effectiveAddress
mode: window1.addressMode
opcode: window1.decodedOpcode
anchors.right: parent.right
anchors.rightMargin: 334
anchors.top: parent.top
anchors.topMargin: 214
}
Rectangle {
id: rectangle1
x: 588
width: 692
height: 147
color: "#ffd232"
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
Register {
id: register1
name: "PC"
active: window1.activeRegister == 0
value: window1.pc
x: 23
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 552
anchors.top: parent.top
anchors.topMargin: 5
}
Register {
id: register2
name: "Indirect 1"
active: window1.activeRegister == 1
value: window1.ind1
x: 160
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 415
anchors.top: parent.top
anchors.topMargin: 5
}
Register {
id: register3
name: "Indirect 2"
active: window1.activeRegister == 2
value: window1.ind2
x: 297
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 278
anchors.top: parent.top
anchors.topMargin: 5
}
Register {
id: register4
name: "In"
active: window1.activeRegister == 3
value: window1.input
x: 434
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 141
anchors.top: parent.top
anchors.topMargin: 5
}
Register {
id: register5
name: "Accumulator"
active: window1.activeRegister == 4
value: window1.accu
x: 594
y: -142
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 5
anchors.top: parent.top
anchors.topMargin: 5
}
Register {
id: register6
name: "OP-Code"
active: window1.activeRegister == 5
value: window1.opc
x: 23
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 552
anchors.top: parent.top
anchors.topMargin: 76
}
Register {
id: register7
name: "Argument"
active: window1.activeRegister == 6
value: window1.arg
x: 160
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 415
anchors.top: parent.top
anchors.topMargin: 76
}
Register {
id: register8
name: "Data pointer"
active: window1.activeRegister == 7
value: window1.dpt
x: 297
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 278
anchors.top: parent.top
anchors.topMargin: 76
}
Register {
id: register9
name: "Stack pointer"
active: window1.activeRegister == 8
value: window1.spt
x: 434
width: 131
height: 65
numberSize: 22
anchors.right: parent.right
anchors.rightMargin: 141
anchors.top: parent.top
anchors.topMargin: 76
}
Register {
id: register10
name: "Frame pointer"
active: window1.activeRegister == 9
value: window1.fpt
x: 594
y: -71
width: 131
height: 65
numberSize: 22
anchors.rightMargin: 5
anchors.top: parent.top
anchors.right: parent.right
anchors.topMargin: 76
}
}
ALU {
id: aLU1
x: 971
width: 304
height: 271
hex: false
flag: window1.fla
active: window1.aluActive
value1: window1.operand
operator: window1.operation
value2: register5.value
value3: window1.result
anchors.right: parent.right
anchors.rightMargin: 5
anchors.top: parent.top
anchors.topMargin: 197
flagTextSize: 10
}
TextArea {
id: textArea2
x: 588
width: 687
text: window1.dynOutput
anchors.right: parent.right
anchors.rightMargin: 5
anchors.bottom: parent.bottom
anchors.bottomMargin: 36
anchors.top: parent.top
anchors.topMargin: 474
readOnly: true
textFormat: TextEdit.RichText
}
TextField {
id: textField1
x: 588
y: 695
width: 687
height: 25
anchors.right: parent.right
anchors.rightMargin: 5
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
placeholderText: qsTr("Dynamic input")
Keys.onReturnPressed: {
sendInput(text);
text = "";
}
}
Bus {
id: bus1
active: window1.activeRegister >= 0 && window1.activeRegister < 10
x: 690
width: 10
height: 67
anchors.right: parent.right
anchors.rightMargin: 579
anchors.top: parent.top
anchors.topMargin: 147
}
Bus {
id: bus2
active: window1.activeRamSlot1 >= 0 || window1.activeRamSlot2 >= 0
x: 582
width: 67
height: 10
anchors.right: parent.right
anchors.rightMargin: 634
anchors.top: parent.top
anchors.topMargin: 228
}
Bus {
id: bus3
active: register5.active
x: 1213
y: 147
width: 10
height: 70
anchors.right: parent.right
anchors.rightMargin: 56
anchors.top: parent.top
anchors.topMargin: 147
}
Bus {
id: bus4
active: window1.busToAluActive
x: 946
width: 47
height: 10
anchors.right: parent.right
anchors.rightMargin: 287
anchors.top: parent.top
anchors.topMargin: 223
z: 1
}
Bus {
id: bus5
active: window1.busFromAluActive
x: 946
y: 368
width: 122
height: 10
anchors.right: parent.right
anchors.rightMargin: 212
z: 2
anchors.top: parent.top
anchors.topMargin: 366
}
Bus {
id: bus6
active: window1.activeRegister == 10
x: 791
width: 10
height: 68
anchors.right: parent.right
anchors.rightMargin: 479
anchors.top: parent.top
anchors.topMargin: 386
}
Bus {
id: bus7
active: bus6.active
x: 801
width: 171
height: 10
anchors.right: parent.right
anchors.rightMargin: 308
anchors.top: parent.top
anchors.topMargin: 444
}
Slider {
id: sliderHorizontal1
x: 588
width: 182
height: 22
stepSize: 1
anchors.right: parent.right
anchors.rightMargin: 510
maximumValue: 100
minimumValue: 0
value: 50
tickmarksEnabled: false
anchors.top: parent.top
anchors.topMargin: 447
onValueChanged: changeAnimSpeed(value)
}
Text {
id: text1
x: 588
text: qsTr("Animation speed:")
anchors.right: parent.right
anchors.rightMargin: 599
anchors.top: parent.top
anchors.topMargin: 427
font.pixelSize: 12
}
}