-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.html
1387 lines (1201 loc) · 63.9 KB
/
main.html
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="FRISCjs - FRISC processor simulator in JavaScript" />
<meta name="author" content="Ivan Zuzak" />
<title> FRISCjs - FRISC processor simulator in JavaScript</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />
<link rel="stylesheet" href="ace-mode-frisc.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://raw.github.com/izuzak/FRISCjs/master/friscasm.js"></script>
<script type="text/javascript" src="https://raw.github.com/izuzak/FRISCjs/master/friscjs.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-tab.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-button.js"></script>
<script type="text/javascript" src="https://raw.github.com/madrobby/keymaster/master/keymaster.js"></script>
<script type="text/javascript" src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<script type="text/javascript" src="https://raw.github.com/ajaxorg/ace-builds/master/src/ace.js"></script>
<script type="text/javascript" src="https://raw.github.com/izuzak/FRISCjs/master/ace-mode-frisc.js"></script>
<style>
#cpustate {
margin-top: 8px;
}
.cpu-state-div {
font-size: 12pt;
margin-top: 5px;
display: inline-block;
height: 40px;
border: 1px solid rgb(102, 102, 102);
width: 160px;
margin-right: 2px;
}
.cpu-reg-label {
width: 54px;
}
.cpu-reg-value {
width: 105px;
}
.cpu-sr-label {
width:105px;
}
.cpu-sr-value {
width: 54px;
}
.cpu-state-lab {
height: 40px;
border-right: 1px solid rgb(102, 102, 102);
background-color: #D4CDCF;
display: table-cell;
vertical-align: middle;
text-align: center;
font-weight: bold;
}
.cpu-state-val {
height: 40px;
background-color: rgba(230, 228, 228, 0.53);
display: table-cell;
vertical-align: middle;
text-align: center;
}
.evenLineMemoryView {
background-color : #ffffff;
}
.oddLineMemoryView {
background-color : #f8f8f8;
}
.currentCpuLine {
background-color : orange;
}
.memoryChangeLine {
background-color : lightblue;
}
.label {
position: relative;
top: -1px;
padding: 2px 4px 2px;
}
</style>
</head>
<body>
<div class="container" style="width: 1140px">
<h1> FRISCjs <small> FRISC processor simulator in JavaScript </small> </h1>
<ul class="nav nav-tabs">
<li class="active"><a id="frisc-sim-link" href="#frisc-sim" data-toggle="tab">Simulator</a></li>
<li><a href="#frisc-saveload" data-toggle="tab">Load/Save</a></li>
<li><a href="#frisc-usage" data-toggle="tab">Usage instructions</a></li>
<li><a href="#frisc-examples" data-toggle="tab">Examples</a></li>
<li><a href="#frisc-about" data-toggle="tab">About</a></li>
</ul>
<div class="tab-content" style="margin-bottom: 20px;">
<div id="frisc-saveload" class="container tab-pane" style="width: auto">
<div class="well">
<h3> Load/save and import/export FRISC configurations </h3>
<p>
This page enables you to save the current configuration of the simulator locally (under a specific name) so that you may load it next time you use FRISCjs.
Currently, a configuration consists of the FRISC assembly program defined in the editor, the CPU speed, memory size and the set of defined I/O units.
In the future, the configuration might be extended to include defined breakpoints, CPU state, etc.
Furthermore, this page enables you to export configurations in text format so that they can be shared (e.g. via e-mail) and saved externally (e.g. as a GitHub gist), and import previously exported configurations.
In order to save/load and import/export, the simulator must be in a stopped state.
</p>
<h4> Save current configuration locally </h4>
<p>
<form class="form-search">
<label class="control-label" for="frisc-cfg-save-name">Configuration name:</label>
<input type="text" id="frisc-cfg-save-name" class="input-medium search-query">
<button id="frisc-cfg-save" type="button" class="btn btn-success"><i class="icon-file icon-white"></i> Save</button>
<span id="frisc-cfg-save-help" class="help-inline"></span>
</form>
</p>
<h4> Load or delete existing configuration </h4>
<p>
<form class="form-search">
<label class="control-label" for="frisc-cfg-select">Select configuration:</label>
<select id="frisc-cfg-select" class="input-medium">
</select>
<button id="frisc-cfg-load" type="button" class="btn btn-success"><i class="icon-download-alt icon-white"></i> Load</button>
<button id="frisc-cfg-delete" type="button" class="btn btn-danger"><i class="icon-remove-sign icon-white"></i> Delete</button>
<span id="frisc-cfg-load-help" class="help-inline"></span>
</form>
</p>
<h4> Export current configuration to text </h4>
<p>
<form class="form-search">
<textarea class="input-xxlarge" id="frisc-cfg-export-text" rows="4"></textarea>
<button id="frisc-cfg-export" type="button" class="btn btn-success"><i class="icon-file icon-white"></i> Export</button>
<span id="frisc-cfg-export-help" class="help-inline"></span>
</form>
</p>
<h4> Import configuration from text as current configuration </h4>
<p>
<form class="form-search">
<textarea class="input-xxlarge" id="frisc-cfg-import-text" rows="4"></textarea>
<button id="frisc-cfg-import" type="button" class="btn btn-success"><i class="icon-download-alt icon-white"></i> Import</button>
<span id="frisc-cfg-import-help" class="help-inline"></span>
</form>
</p>
</div>
</div>
<div id="frisc-usage" class="container tab-pane" style="width: auto;">
<div class="well">
<h3> Basic usage instructions </h3>
<ol>
<li> Enter your FRISC assembler program into the textbox on the left. </li>
<li> Press the <b>"Settings"</b> button to define the CPU speed (in Hz, default is 1000Hz, min is 1Hz) and the memory size (in KB, default is 256KB, min is 1KB, max is 1000KB). These options can't be changed after the program is loaded. Also, select the base for displaying register status (decimal or hexadecimal, default is hex). This option can be changed even while the loaded program is being executed. </li>
<li> Press the <b>"Load"</b> button to parse and assemble the program, and then load it into memory. In case of parsing errors, the error message, line and column numbers will be logged to the log output screen. </li>
<li> After the program loads into memory, the program editor is replaced with a <b>location-by-location view of the complete memory</b>. For each location, the location address, its value in hex and dec base, and value interpreted as a FRISC instruction are shown. Furthermore, the memory view provides several advanced features:
<ul>
<li> <b>search</b> - the search-box below the memory view provides a fast way to jump to any location.</li>
<li> <b>breakpoints</b> - for each location, the memory view also provides a "Break" checkbox which will pause the CPU when it reaches that memory location. </li>
<li> <b>next instruction highlight</b> - the location of the instruction that will be executed next by the CPU is highlighted. </li>
</ul>
<li> Press the <b>"Run all"</b> button to start the CPU with the defined execution speed. As the program is executing, the value of the registers is updated and the log output screen logs every executed instruction and CPU state.</li>
<li> Press the <b>"Pause"</b> button to pause CPU execution.</li>
<li> Press the <b>"Run one"</b> button to force the CPU to execute only the next instruction (step-by-step execution).</li>
<li> Press the <b>"Stop"</b> button to stop the CPU completely, unload the program from memory and return to defining the program in the editor. </li>
<li> Press the <b>"Clear log"</b> button to clear the log output screen. </li>
</ol>
<h3> IO units instructions </h3>
<ol>
<li> IO units must be defined <b>before loading a FRISC program</b> into memory. </li>
<li> Define a <b>unique name</b> to identify an IO unit. </li>
<li> Select the <b>IO unit type</b>. FRISCjs supports 4 IO unit types: Generic IO, FRISC CT, FRISC PIO and FRISC DMA. The <b>Generic IO unit</b> is a unit with no pre-defined behavior or number of memory mapped locations, and enables users to manually set the unit state at runtime. The <b>FRISC CT</b>, <b>FRISC PIO</b> and <b>FRISC DMA</b> units all have pre-defined behavior, parameters and number of memory mapped locations, and their state cannot be set manually during runtime. Multiple units of same type can be added (e.g. two FRISC CT units at the same time). </li>
<li> Select the <b>interrupt level</b> for the unit. Multiple units may be connected to the same interrupt, except for INT3 which is unmaskable. </li>
<li> Define the start of the <b>memory mapping</b> for the unit as a HEX base memory location. Writing to memory locations mapped to an IO unit will result in sending data to the IO unit, not the memory module. Similarly, reading from a memory mapped location will result in receiving data from the IO unit, not the memory module. </li>
<li> Define the <b>number of memory mapped 4-byte locations</b>. This number is pre-defined for standard FRISC IO units, and is configurable for Generic IO units. </li>
<li> Define the required parameters for some units, e.g. the frequency for FRISC CT and PIO units. </li>
<li> Click <b>"Add"</b> to create and display the unit. In case of errors, the error message will be logged to the log output screen. Each unit is displayed with its name, parameters, interrupt state and memory mapped locations. For each location, the address of the location and its value in decimal, hexadecimal and binary bases are shown. The interrupt state and memory mapped location values can be changed manually through the user interface for Generic IO unit types. </li>
<li> Each unit can be removed by clicking the <b>"X"</b> button in the upper left corner, but only while the CPU is stopped. </li>
<li> After adding all desired IO units, load the program into memory as described above. As the program executes, the state of the memory mapped locations and the interrupt state will <b>automatically refresh</b>. </li>
<li> The state of the memory mapped locations for all IO units is <b>automatically reset</b> when the CPU is stopped, as described above. </li>
</ol>
</div>
</div>
<div id="frisc-examples" class="container tab-pane" style="margin-bottom: 15px; width: auto;">
<div class="well">
<h3> Examples </h3>
<p> This page contains examples for using FRISCjs. Each example is given as a brief description and a link to a configuration which can be loaded using the Load/Save tab. Just copy/paste the configuration into the import box and click <b>"Import"</b>. </p>
<h4> FRISC CT example </h4>
<p> This example uses a FRISC CT IO unit for simple counting - an in-memory counter is incremented for every 400 periods of the FRISC CT unit. The configuration contains a FRISC CT unit configured at 1000Hz. </p>
<ul>
<li> <a href="https://raw.github.com/izuzak/FRISCjs/master/examples/frisc_ct.json">Configuration</a> </li>
<li> <a href="https://raw.github.com/izuzak/FRISCjs/master/examples/frisc_ct.frisc">Input program only in a more readable format</a> </li>
</ul>
</div>
</div>
<div id="frisc-about" class="container tab-pane" style="margin-bottom: 15px; width: auto;">
<div class="well">
<h3> About </h3>
<p>
FRISCjs is a simulator of the FRISC processor written in JavaScript.
<a href="http://www.fer.unizg.hr/rasip/knjige/frisc">FRISC</a> is a simple, educational RISC processor developed at the <a href="http://fer.unizg.hr/en">University of Zagreb, Faculty of Electrical Engineering and Computing</a>.
The simulator has two parts: a <a href="https://github.com/izuzak/FRISCjs/blob/master/friscasm.pegjs">FRISC assembler</a> (built using PEGjs) which translates FRISC assembly code to machine code and a <a href="https://github.com/izuzak/FRISCjs/blob/master/friscjs.js">FRISC CPU simulator</a> which executes machine code.
This Web application is a graphical interface for the simulator, while there also exists a <a href="https://github.com/izuzak/FRISCjs/blob/master/main.js">console interface which runs on NodeJS</a>.
</p>
<h3> Source code and bug reports </h3>
<p>
The complete source code for FRISCjs and this Web application is <a href="https://github.com/izuzak/FRISCjs">available on GitHub</a>.
Please use the GitHub <a href="https://github.com/izuzak/FRISCjs/issues">issue tracker</a> for reporting bugs and feature requests.
</p>
<h3> Credits and license </h3>
<p>
FRISCjs was developed by <a href="http://ivanzuzak.info">Ivan Zuzak</a>. License: <a href="https://github.com/izuzak/FRISCjs/blob/master/LICENSE.markdown">Apache 2.0.</a> Contributors: <a href="https://github.com/ibudiselic">Ivan Budiselic</a>, <a href="https://github.com/Stankec">Stanko Krtalic</a>.
</p>
<p>
FRISCjs is built with many open-source projects: <a href="http://pegjs.majda.cz/">PEGjs</a>, <a href="http://nodejs.org">NodeJS</a>, <a href="http://jquery.com">jQuery</a>, <a href="http://twitter.github.com/bootstrap">Bootstrap</a>, <a href="http://ace.ajax.org/">Ace</a>, <a href="https://github.com/janl/mustache.js/">Mustache</a> and <a href="https://github.com/madrobby/keymaster">Keymaster</a>.
</p>
</div>
</div>
<div id="frisc-sim" class="active container-fluid tab-pane" style="padding-left: 0px;">
<div id="frisc-inputdiv" class="sidebar" style="width: 450px; height: 450px;">
</div>
<div class="sidebar ace_editor ace-tm" id="frisc-memorylist-hold" style="width: 450px; height: 445px; display:none;">
<div style="width: 448px; height: 30px; display:inline-block; top:0px; border: 1px solid #dddddd; border-collapse: separate; border-radius: 4px 4px 0px 0px; background-color:#f1f1f1; padding-top:5px;">
<div style='display:table-cell; width:70px; border-right: 1px solid #000000; padding-left: 4px; vertical-align: middle; padding-top: 1px;'>Location</div>
<div style='display:table-cell; width:70px; border-right: 1px solid #000000; padding-left: 4px; vertical-align: middle; padding-top: 1px;'>Value HEX</div>
<div style='display:table-cell; width:85px; border-right: 1px solid #000000; padding-left: 4px; vertical-align: middle; padding-top: 1px;'>Value DEC</div>
<div style='display:table-cell; width:150px; border-right: 1px solid #000000; padding-left: 4px; vertical-align: middle; padding-top: 1px;'>Instruction</div>
<div style='display:table-cell; width:30px; padding-left: 4px; vertical-align: middle; padding-top: 1px;'>Break</div>
</div>
<div id="frisc-memorylist" style="width: 448px; height: 370px; position:absolute; top:31px; overflow: scroll; overflow-x:hidden; display:inline-block; border: 1px solid #dddddd; border-radius: 0px 0px 4px 4px;">
</div>
<div id="frisc-memorylist-search" style="border: 1px solid #dddddd; border-collapse: separate; border-radius: 0px 0px 4px 4px; background-color:#f1f1f1; position:absolute; bottom:0px; width: 448px; height: 35px; padding-top: 6px;">
<div style="padding-left: 6px;">
<form class="form-search">
<input type="text" class="input-medium search-query" id="skrMemLisSearchField">
<button type="submit" class="btn" id="skrMemLisSearch">Go to</button>
</form>
</div>
</div>
</div>
<div class="content" style="margin-left: 460px; height: 450px;">
<div id="frisc-controls" style="float: left; margin-left: 10px;">
<div id="frisc-cpu-controls" class="form-inline" style="width: 666px;">
<button id="frisc-load" type="button" class="btn btn-success"><i class="icon-download-alt icon-white"></i> Load</button>
<button id="frisc-execute" type="button" class="btn btn-primary"><i class="icon-fast-forward icon-white"></i> Run all</button>
<button id="frisc-next" type="button" class="btn btn-primary"><i class="icon-step-forward icon-white"></i> Run one</button>
<button id="frisc-pause" type="button" class="btn btn-primary"><i class="icon-pause icon-white"></i> Pause</button>
<button id="frisc-stop" type="button" class="btn btn-danger"><i class="icon-stop icon-white"></i> Stop</button>
<button id="frisc-clear" type="button" class="btn btn-primary"><i class="icon-remove-sign icon-white"></i> Clear log</button>
<button id="frisc-showhidesettings" type="button" class="btn btn-primary" data-toggle="button"><i class="icon-wrench icon-white"></i> Settings</button>
</div>
<div id="frisc-settings" style="display: none; margin-top: 15px;" class="form-inline">
<label for="frisc-freq" style="margin-bottom: 0px;">CPU frequency (Hz):</label>
<input id="frisc-freq" type="number" min="1" step="1" class="input-mini" style="margin-bottom: 0px;" value="1000">
<label for="frisc-memsize" style="margin-bottom: 0px;">MEM size (KB):</label>
<input id="frisc-memsize" type="number" min="1" step="1" max="1000" class="input-mini" style="margin-bottom: 0px;" value="256">
<label style="margin-bottom: 0px;">Register values:</label>
<div class="btn-group" data-toggle="buttons-radio" style="display:inline-block; vertical-align: middle;">
<button class="btn" id="regBaseRadioDec">DEC</button>
<button class="btn active" id="regBaseRadioHex">HEX</button>
</div>
</div>
<div id="cpuout" style="font-size: 10pt; font-family: courier new; background-color: #D4CDCF; width: 650px; overflow: auto; border: 1px solid #666; padding: 8px; margin-top: 15px; color: black;"></div>
<div id="cpustate" style="margin-top: 8px;" >
<div id="cpu_r0" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R0 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r1" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R1 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r2" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R2 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r3" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R3 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r4" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R4 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r5" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R5 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r6" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R6 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_r7" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> R7 </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_pc" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> PC </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_sr" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> SR </div>
<div class="cpu-reg-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_iif" class="cpu-state-div">
<div class="cpu-reg-label cpu-state-lab"> IIF </div>
<div class="cpu-reg-value cpu-state-val"> 1 </div>
</div>
<br>
<div id="cpu_N" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-N </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_C" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-C </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_V" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-V </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_Z" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-Z </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_EINT0" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-EINT0 </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_EINT1" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-EINT1 </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_EINT2" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-EINT2 </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
<div id="cpu_GIE" class="cpu-state-div">
<div class="cpu-sr-label cpu-state-lab"> SR-GIE </div>
<div class="cpu-sr-value cpu-state-val"> 0 </div>
</div>
</div>
</div>
</div>
<div style="margin-bottom: 15px; width: 1140px;">
<legend style="margin-bottom: 15px;">IO units</legend>
<div class="form-inline" style="margin-bottom: 25px;">
<form id="ioUnitFormStatic">
<input class="span2" type="text" style="margin-bottom: 0px;" id="ioUnitName" required pattern="[A-Za-z_0-9]{3,}" placeholder="Enter IO unit name…">
<select class="span2" id="ioUnitType" required>
<option value="">Select unit type…</option>
<option value="generic">Generic IO unit</option>
<option value="frisc-ct">FRISC CT</option>
<option value="frisc-pio">FRISC PIO</option>
<option value="frisc-dma">FRISC DMA</option>
</select>
<select class="span2" id="ioUnitIntLevel" required>
<option value="">Select interrupt…</option>
<option value="INT0">INT0 (maskable)</option>
<option value="INT1">INT1 (maskable)</option>
<option value="INT2">INT2 (maskable)</option>
<option value="INT3">INT3 (unmaskable)</option>
</select>
<label> Memory mapping start addr (HEX): </label>
<input type="text" class="span1" id="ioUnitMemmapStart" value="0" required>
<label> Number of 4B locations: </label>
<input type="text" class="span1" id="ioUnitMemmapCount" value="0" required>
<button type="submit" class="btn btn-success" id="addIoUnit" value="Search"><i class="icon-plus icon-white"></i> Add</button>
</form>
</div>
<div class="row" id="ioUnits">
</div>
</div>
</div>
</div>
<script type="text/javascript">
var CFGNAMES = "__friscConfigurationNames";
var isLocalStorageAvailable = 'localStorage' in window && window['localStorage'] !== null;
function appendOption(selectSelector, optionValue, optionText) {
var option = document.createElement('option');
option.setAttribute('value', optionValue);
option.appendChild(document.createTextNode(optionText));
$(selectSelector)[0].appendChild(option);
}
function getCfgNames() {
var res = localStorage.getItem(CFGNAMES);
if (typeof res === "undefined" || res === null) {
localStorage.setItem(CFGNAMES, JSON.stringify([]));
res = [];
} else {
res = JSON.parse(res);
}
return res;
}
function saveCfg(name, cfg) {
localStorage.setItem(name, JSON.stringify(cfg));
var cfgNames = getCfgNames();
if (cfgNames.indexOf(name) < 0) {
cfgNames.push(name);
}
localStorage.setItem(CFGNAMES, JSON.stringify(cfgNames));
refreshCfgsSelect();
}
function deleteCfg(name) {
var cfgNames = getCfgNames();
if (cfgNames.indexOf(name) >= 0) {
cfgNames.splice(cfgNames.indexOf(name), 1);
localStorage.removeItem(name);
localStorage.setItem(CFGNAMES, JSON.stringify(cfgNames));
}
refreshCfgsSelect();
}
function getCfg(name) {
return JSON.parse(localStorage.getItem(name));
}
function refreshCfgsSelect() {
$("#frisc-cfg-select option").each(function() {
if ($(this).val() === "" || $(this).is("optgroup")) {
} else {
$(this).remove();
}
});
var cfgNames = getCfgNames();
for (var i=0; i<cfgNames.length; i++) {
appendOption("#frisc-cfg-select", cfgNames[i], cfgNames[i]);
}
}
function extractCurrentCfg() {
var cfg = {};
cfg.program = editor.getSession().getValue();
cfg.cpuFreq = $("#frisc-freq").val();
cfg.memSize = $("#frisc-memsize").val();
cfg.ioUnits = [];
var ioUnits = simulator.IO.getIoUnits();
for (var i=0; i<ioUnits.length; i++) {
cfg.ioUnits.push(simulator.IO.getIoUnit(ioUnits[i]).spec);
}
return cfg;
}
function loadCfg(cfg) {
editor.getSession().setValue(cfg.program);
$("#frisc-freq").val(cfg.cpuFreq);
$("#frisc-memsize").val(cfg.memSize);
$(".io-del").click();
for (var i=0; i<cfg.ioUnits.length; i++) {
$("#ioUnitName").val(cfg.ioUnits[i].ioUnitName);
$("#ioUnitType").val(cfg.ioUnits[i].ioUnitType);
$("#ioUnitIntLevel").val(cfg.ioUnits[i].intLevel);
$("#ioUnitMemmapStart").val(cfg.ioUnits[i].memmapStart);
$("#ioUnitMemmapCount").val(cfg.ioUnits[i].memmapCount);
$("#frisc-ct-freq").val(cfg.ioUnits[i].ioUnitFreq);
$("#ioUnitType").change();
$("#ioUnitFormStatic").submit();
}
}
$("#frisc-cfg-save").click(function() {
if (isLocalStorageAvailable === false) {
$("#frisc-cfg-save-help").text("The required localStorage API is not available in your browser.");
return;
} else {
$("#frisc-cfg-save-help").text("");
}
if (_state !== "stopped") {
$("#frisc-cfg-save-help").text("The simulator must be stopped in order to save/load/delete configurations.");
return;
} else {
$("#frisc-cfg-save-help").text("");
}
var name = $("#frisc-cfg-save-name").val();
if (name === "" || name.indexOf(" ") >=0) {
$("#frisc-cfg-save-help").text("The configuration name must be defined and must not contain whitespace characters.");
return;
} else {
$("#frisc-cfg-save-help").text("");
}
var cfg = extractCurrentCfg();
saveCfg(name, cfg);
});
$("#frisc-cfg-load").click(function() {
if (isLocalStorageAvailable === false) {
$("#frisc-cfg-load-help").text("The required localStorage API is not available in your browser.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
if (_state !== "stopped") {
$("#frisc-cfg-load-help").text("The simulator must be stopped in order to save/load/delete configurations.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
var name = $("#frisc-cfg-select").val();
if (name === null || name.indexOf(" ") >=0) {
$("#frisc-cfg-load-help").text("You must select a configuration.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
var cfg = getCfg(name);
loadCfg(cfg);
});
$("#frisc-cfg-delete").click(function() {
if (isLocalStorageAvailable === false) {
$("#frisc-cfg-load-help").text("The required localStorage API is not available in your browser.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
if (_state !== "stopped") {
$("#frisc-cfg-load-help").text("The simulator must be stopped in order to save/load/delete configurations.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
var name = $("#frisc-cfg-select").val();
if (name === null || name.indexOf(" ") >=0) {
$("#frisc-cfg-load-help").text("You must select a configuration.");
return;
} else {
$("#frisc-cfg-load-help").text("");
}
deleteCfg(name);
});
$("#frisc-cfg-export").click(function() {
if (_state !== "stopped") {
$("#frisc-cfg-export-help").text("The simulator must be stopped in order to import/export configurations.");
return;
} else {
$("#frisc-cfg-export-help").text("");
}
var cfg = extractCurrentCfg();
$("#frisc-cfg-export-text").text(JSON.stringify(cfg, null, 2));
});
$("#frisc-cfg-import").click(function() {
if (_state !== "stopped") {
$("#frisc-cfg-import-help").text("The simulator must be stopped in order to import/export configurations.");
return;
} else {
$("#frisc-cfg-import-help").text("");
}
try {
var cfg = JSON.parse($("#frisc-cfg-import-text").val());
loadCfg(cfg);
} catch (e) {
$("#frisc-cfg-import-help").text("There was an error in parsing your configuration. " + e.toString());
return;
}
});
refreshCfgsSelect();
$("#frisc-sim-link").click(function() {
editor.resize();
});
key('backspace', function(){ return false; });
var height = ($("#frisc-inputdiv").innerHeight() - $("#frisc-cpu-controls").innerHeight()) - 281 + "px";
$("#cpuout").height(height);
$("#memout").height(height);
var _state = "stopped";
// create FRISC
var simulator = new FRISC();
simulator.CPU._frequency = parseFloat($("#frisc-freq").val());
window.onload = function() {
$(function() { $("li").css("color", "#404040"); });
editor = ace.edit("frisc-inputdiv");
var FriscMode = require("ace/mode/frisc").Mode;
editor.getSession().setMode(new FriscMode());
document.getElementById('frisc-inputdiv').style.fontSize='10pt';
document.getElementById('frisc-inputdiv').style.fontFamily='courier new';
$(".ace_gutter").width("40px");
editor.getSession().setValue("; aluop\n\
lab1 ADD R1, R2, R3\n\
lab2 ADD r2, 5, r5\n\
ADD r5, lab1, r2\n\
; cmpop\n\
CMP R1, R2\n\
lab5 CMP R1, 5\n\
lab6 CMP r4, lab5\n\
; moveop\n\
lab7 MOVE R4, R5\n\
lab8 MOVE R5, SR\n\
lab9 MOVE SR, r5\n\
MOVE lab5, r4\n\
lab11 MOVE lab6, sr\n\
; uprop\n\
JP lab2\n\
JP_N 54\n\
lab12 JP_UGE (r1)\n\
lab13 RETI_M\n\
; memop\n\
lab14 STORE r1, (r2)\n\
STORE r4, (r3+23)\n\
STORE r4, (lab14)\n\
lab15 STORE r5, (200)\n\
lab16 POP r3\n\
; asmop\n\
lab17 `ORG 234\n\
`DW 1,2,3,4,5\n\
`DW 54\n\
lab18 `EQU 300\n\
lab19 `DS 12\n\
lab21 `BASE H\n\
lab22 DW 54\n\
DH 34\n\
DB 12\n\
lab20 `END\n\
lab23 ADD R1, R2, R3\n\
; fds fsd';");
editor.resize();
editor.renderer.setHScrollBarAlwaysVisible(false);
changeState("stopped");
};
function simulatorLog(text, marginLeft) {
if (typeof text !== "string") {
text = JSON.stringify(text);
}
if (typeof marginLeft === "undefined") {
marginLeft = "0px";
}
$("#cpuout").append("<div style='font-size: 9pt; margin: 1px; margin-left: " + marginLeft + "; padding: 0px;'>" + text + "</div>");
$("#cpuout").scrollTop($("#cpuout")[0].scrollHeight);
}
function refreshMemoryViewCurrentLine() {
$(".currentCpuLine").removeClass("currentCpuLine");
var currentCpuLocation = formatHexNumber(simulator.CPU._r.pc.toString(16));
$("input[addr=" + currentCpuLocation + "]").parent().parent().addClass("currentCpuLine");
}
var breakpoints = [];
function createMemoryRow(i) {
var lines = [];
var checked = breakpoints.indexOf(i) >= 0 ? " checked" : "";
var addr = formatHexNumber(i.toString(16));
var valHex = formatHexNumber(convertBinaryToInt(convertIntToBinary(simulator.MEM.read(i), 32), 0).toString(16));
var valDec = simulator.MEM.read(i).toString(10);
var decoded = simulator.CPU._decode(simulator.MEM.read(i));
decoded = decoded ? instructionToString(decoded) : "";
decoded = (decoded === "MOVE r0 r0") ? "" : decoded;
lines.push("<div style='display:inline-block; padding-left: 4px; width:70px; border-right: 1px solid #dfdfdf;' class='memoryTableNumbering'>"+addr+"</div>");
lines.push("<div style='display:inline-block; padding-left: 4px; width:70px; border-right: 1px solid #dfdfdf;' class='memoryTableValueHex'>"+valHex+"</div>");
lines.push("<div style='display:inline-block; padding-left: 4px; width:85px; border-right: 1px solid #dfdfdf;' class='memoryTableValueDec'>"+valDec+"</div>");
lines.push("<div style='display:inline-block; padding-left: 4px; width:150px;' class='memoryTableValueIns'>"+decoded+"</div>");
lines.push("<div style='display:inline-block; padding-bottom: 2px; padding-left: 4px; width:30px; text-align: center; border-left: 1px solid #dfdfdf; position: relative; top: -1.5px;'>");
lines.push(" <input type='checkbox' addr='" + addr + "' class='breakpointCheckbox'" + checked + ">");
lines.push("</div>");
return lines.join("");
}
function createMemList(div) {
var rowHeight = 18;
var lastDivMessage="Back to top?"
var ofF = 1.4;
//Don't edit this
var maxRows = Math.floor($('#'+div).height()/rowHeight)*ofF;
maxRows = maxRows ? maxRows : 100;
if(Math.floor(maxRows/2)*2 == maxRows) maxRows++;
var base = 16;
var decoded = "";
var bgColor = "";
$("#"+div).html("");
for (var i=0; i>=0 && i<maxRows*4 && i<simulator.MEM._memory.length; i+=4) {
bgColor = (((i/4)%2)==0) ? "evenLineMemoryView" : "oddLineMemoryView";
$("#"+div).html($("#"+div).html()+"<div class='" + bgColor + "' style='height:"+rowHeight+"px; width:100%; position:absolute; top:"+((i/4)*rowHeight)+"px; border: 1px solid #dfdfdf;'>"+ createMemoryRow(i) + "</div>");
}
$("#"+div).html($("#"+div).html()+"<div style='height:"+rowHeight+"px; background-color:#f1f1f1; position:relative; top:"+((simulator.MEM._memory.length/4)*rowHeight)+"px; border-radius: 0px 0px 4px 4px;'>"+lastDivMessage+"</div>");
function handleBreakpointSet() {
var addr = parseInt($(this).attr('addr'), 16);
if ($(this).is(":checked")) {
breakpoints.push(addr);
} else {
breakpoints.splice(breakpoints.indexOf(addr), 1);
}
}
$(".breakpointCheckbox").click(handleBreakpointSet);
refreshMemoryViewCurrentLine();
var prevScrollPos = 0;
$("#"+div).scroll(function(){
//Normal scrolling
if (prevScrollPos > $("#"+div).scrollTop()) { //scrolled UP
$("#"+div).children().each(function(){
if (($(this).position().top>$("#"+div).height()) && ($(this).html()!=lastDivMessage)){
//Find the lowest child and it's value
var highest = simulator.MEM._memory.length*rowHeight; //highest possible position
var highVal = (simulator.MEM._memory.length*rowHeight);
$("#"+div).children().each(function(){
if (parseInt($(this).css("top").replace("px",""))<highest) {
highest = parseInt($(this).css("top").replace("px",""));
highVal = parseInt($(this).children().html(),base);
}
});
highVal = highVal - 4;
if (highVal>=0) {
$(this).css({ top: ''+(highest-rowHeight)+'px' });
bgColor = (((highVal/4)%2)==0) ? "evenLineMemoryView" : "oddLineMemoryView";
$(this).removeClass("evenLineMemoryView").removeClass("oddLineMemoryView").addClass(bgColor);
$(this).html(createMemoryRow(highVal));
}
}
});
} else { //scrolled DOWN
$("#"+div).children().each(function(){
if (($(this).position().top<(-1*rowHeight)) && ($(this).html()!=lastDivMessage)){
//Find the lowest child and it's value
var highest = simulator.MEM._memory.length*rowHeight*-1; //highest possible position
var highVal = 0;
$("#"+div).children().each(function(){
if ((parseInt($(this).css("top").replace("px",""))>highest) && ($(this).html()!=lastDivMessage)) {
highest = parseInt($(this).css("top").replace("px",""));
highVal = parseInt($(this).children().html(),base);
}
});
highVal = highVal + 4;
if (highVal<simulator.MEM._memory.length) {
$(this).css({ top: ''+(highest+rowHeight)+'px' });
bgColor = (((highVal/4)%2)==0) ? "evenLineMemoryView" : "oddLineMemoryView";
$(this).removeClass("evenLineMemoryView").removeClass("oddLineMemoryView").addClass(bgColor);
$(this).html(createMemoryRow(highVal));
}
}
});
};
prevScrollPos = $("#"+div).scrollTop();
//Check if the user scrolled too fast
var invisibleCounter = 0;
$("#"+div).children().each(function() { if ( (($(this).position().top>$("#"+div).height()) || ($(this).position().top<0)) && ($(this).html()!=lastDivMessage)) { invisibleCounter++; }; });
if (invisibleCounter >= maxRows) { //If all rows are invisible
var i = Math.floor((prevScrollPos / rowHeight)) * 4;
var x = i; //visual bug fix
$("#"+div).children().each(function(){
if (($(this).html()!=lastDivMessage) && (i<simulator.MEM._memory.length) && (i>=0)) {
$(this).css({ top: ''+((i/4)*rowHeight)+'px' });
$(this).html(createMemoryRow(i));
i += 4;
} else if (($(this).html()!=lastDivMessage) && (i>=simulator.MEM._memory.length) && (i>=0) && (x>=0)) { //visual bug fix
//fixes minor glitching when the user drags the scroller to the bottom of the memory view;
$(this).css({ top: ''+((x/4)*rowHeight)+'px' });
$(this).html(createMemoryRow(x));
i += 4;
x -= 4;
};
});
};
$('.breakpointCheckbox').off('click');
$(".breakpointCheckbox").click(handleBreakpointSet);
refreshMemoryViewCurrentLine();
});
}
function changeState(st) {
if (st === "stopped") {
enableElements(["#frisc-load", "#frisc-freq", "#frisc-memsize", ".io-del", "#addIoUnit"]);
disableElements(["#frisc-execute", "#frisc-next", "#frisc-pause", "#frisc-stop"]);
_state = st;
} else if (st ==="loaded") {
enableElements(["#frisc-execute", "#frisc-next", "#frisc-stop"]);
disableElements(["#frisc-load", "#frisc-pause", "#frisc-freq", "#frisc-memsize", ".io-del", "#addIoUnit"]);
_state = st;
} else if (st === "running") {
enableElements(["#frisc-stop", "#frisc-pause"]);
disableElements(["#frisc-execute", "#frisc-load", "#frisc-next", "#frisc-freq", "#frisc-memsize", ".io-del", "#addIoUnit"]);
_state = st;
}
}
function enableElements(elems) {
for (var i=0; i<elems.length; i++) {
$(elems[i]).attr('disabled', false);
}
}
function disableElements(elems) {
for (var i=0; i<elems.length; i++) {
$(elems[i]).attr('disabled', true);
}
}
function getRegisterValue(key) {
var base = $("#regBaseRadioDec").hasClass("active") ? 10 : 16;
if (base === 10) {
return simulator.CPU._r[key];
} else {
return formatHexNumber(convertBinaryToInt(convertIntToBinary(simulator.CPU._r[key], 32), 0).toString(16));
}
}
$("#regBaseRadioDec, #regBaseRadioHex").click(function() {
setTimeout( function() {
updateCpuState();
}, 0);
});
function cpuStateToString() {
var retVal = "";
for (var key in simulator.CPU._r) {
if (key !== 'sr') {
retVal += key + ": " + getRegisterValue(key).toString() + " ";
} else {
retVal += key + ": " + getRegisterValue(key).toString() + " ( ";
for (var flag in simulator.CPU._f) {
retVal += flag + ": " + simulator.CPU._getFlag(simulator.CPU._f[flag]) + " ";
}
retVal += ") ";
}
}
return retVal;
}
function instructionToString(instruction) {
if (typeof instruction.args === 'undefined' || instruction.args === null) {
return instruction.op;
} else {
if (instruction.op === 'RET' && instruction.args[1] === true) {
return 'RETI ' + instruction.args[0];
} else if (instruction.op === 'RET' && instruction.args[2] === true) {
return 'RETN ' + instruction.args[0];
} else if (instruction.op === 'RET') {
return 'RET ' + instruction.args[0];
} else {
return instruction.op + " " + instruction.args.join(" ");
}
}
}
function updateCpuState() {
for (var key in simulator.CPU._r) {
$("#cpu_" + key + " .cpu-state-val").text(getRegisterValue(key));
}
for (var flag in simulator.CPU._f) {
$("#cpu_" + flag + " .cpu-state-val").text(simulator.CPU._getFlag(simulator.CPU._f[flag]));
}
}
updateCpuState();
simulator.CPU.onBeforeRun = function() {
simulatorLog("<span class='label label-success'><b>Starting (or continuing) simulation!</b></span>");
};
var instructionsExecutedAfterBreak = true;
simulator.CPU.onBeforeCycle = function() {
if (_state === "running") {
if (breakpoints.indexOf(simulator.CPU._r.pc) >= 0 && instructionsExecutedAfterBreak) {
simulator.CPU.pause();
changeState("loaded");
simulatorLog("<span class='label label-warning'><b>FRISC processor paused on breakpoint at location " + formatHexNumber(simulator.CPU._r.pc.toString(16)) + "!</b></span>");
instructionsExecutedAfterBreak = false;
return false;
}
}
instructionsExecutedAfterBreak = true;
simulatorLog("<span class='label label-success'><b>New CPU cycle starting!</b></span>");
simulatorLog("<span class='label label-info'>CPU state:</span>" + " " + cpuStateToString(), "10px");
};
simulator.CPU.onAfterCycle = function() {
refreshMemoryViewCurrentLine();
simulatorLog("<span class='label label-info'>CPU state:</span>" + " " + cpuStateToString(), "10px");
updateCpuState();
};
simulator.CPU.onBeforeExecute = function(instruction) {
simulatorLog("<span class='label label-info'>Executing FRISC instruction:</span>" + " " + instructionToString(instruction), "10px");
};
simulator.CPU.onStop = function() {
simulatorLog("<span class='label label-warning'><b>FRISC processor stopped!</b></span>");
changeState("stopped");
onStopInternal();
};
simulator.MEM.onMemoryWrite = function(addr) {
addr &= ~(0x03);
var val = simulator.MEM.read(addr);
addr = formatHexNumber(convertBinaryToInt(convertIntToBinary(addr, 32), 0).toString(16));
var line = $("input[addr=" + addr + "]").parent().parent();
var decoded = simulator.CPU._decode(val);
decoded = decoded ? instructionToString(decoded) : "";
decoded = (decoded === "MOVE r0 r0") ? "" : decoded;
line.children(".memoryTableValueHex").html(formatHexNumber(convertBinaryToInt(convertIntToBinary(val, 32), 0).toString(16)));
line.children(".memoryTableValueDec").html(val.toString());
line.children(".memoryTableValueIns").html(decoded);
line.addClass("memoryChangeLine");
setTimeout(function() {
line.removeClass("memoryChangeLine");
}, 500);
};
$("#frisc-load").click(function() {
if (_state === "stopped") {
try {
simulator.CPU.reset();
breakpoints = [];
var ioUnits = simulator.IO.getIoUnits();
for (var i=0; i<ioUnits.length; i++) {
simulator.IO.getIoUnit(ioUnits[i]).reset();
}
var source = editor.getSession().getValue();
if (source.length > 0 && source[source.length-1] !== '\n') {
source += '\n';
}