-
Notifications
You must be signed in to change notification settings - Fork 3
/
core.html
695 lines (664 loc) · 25.9 KB
/
core.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
<!DOCTYPE html>
<html lang="jp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>KEMU Emulator</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<h1>KEMU Emulator</h1>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default" onclick="buttonRunStop()">
<span class="glyphicon glyphicon-play" aria-hidden="true"></span> 実行/停止
</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li role="presentation"i class="disabled"><a role="menuitem" disabled="disabled">実行速度</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 0">最高</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 1">1kHz</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 2">500Hz</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 5">200Hz</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 10">100Hz</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 100">10Hz</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" onclick="runningTimerInterval = 1000">1Hz</a></li>
</ul>
<button type="button" class="btn btn-default" onclick="buttonStep()">
<span class="glyphicon glyphicon-step-forward" aria-hidden="true"></span> ステップ実行
</button>
<button type="button" class="btn btn-default" onclick="buttonPhase()">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> フェーズを実行
</button>
<button type="button" class="btn btn-default" onclick="buttonReset()">
<span class="glyphicon glyphicon-eject" aria-hidden="true"></span> リセット
</button>
<button type="button" class="btn btn-default" onclick="buttonClear()">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> メモリのクリア
</button>
</div>
<div id="statusbox"></div>
<div id="infobox">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
<span id="infobox_text"></span>
</div>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a id="tab_reassemble" href="#content_reassemble"
aria-controls="content_reassemble" role="tab" data-toggle="tab">逆アセンブル</a>
</li>
<li role="presentation">
<a id="tab_memory_program" href="#content_memory"
aria-controls="content_memory" role="tab" data-toggle="tab">プログラムメモリ</a>
</li>
<li role="presentation">
<a id="tab_memory_user" href="#content_user"
aria-controls="content_user" role="tab" data-toggle="tab">ユーザーメモリ</a>
</li>
<li role="presentation">
<a id="tab_trace" href="#content_trace"
aria-controls="content_trace" role="tab" data-toggle="tab">トレース</a>
</li>
<li role="presentation">
<a id="tab_statistics" href="#content_statistics"
aria-controls="content_statistics" role="tab" data-toggle="tab">統計</a>
</li>
<li role="presentation">
<a id="tab_io" href="#content_io"
aria-controls="content_io" role="tab" data-toggle="tab">外部接続</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="content_reassemble">
<div style="max-height: 36em; overflow: scroll; margin: 1em 0;">
<table class="table table-bordered" style="margin: 0">
<thead>
<th style="width: 4em;">Addr</th>
<th style="width: 2em;">BP</th>
<th>機械語</th>
<th>逆アセンブル</th>
</thead>
<tbody id="dasm_body">
</tbody>
</table>
</div>
<button type="button" class="btn btn-default" style="float: right" onclick="buttonDisassemble()">
<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> 再アセンブル
</button>
</div>
<div role="tabpanel" class="tab-pane" id="content_memory">
</div>
<div role="tabpanel" class="tab-pane" id="content_user">
</div>
<div role="tabpanel" class="tab-pane" id="content_trace">
<p>「トレースを有効にする」にチェックを入れたら、「ステップ実行」または「フェーズ実行」を選択してください。<br>
「実行・停止」ではトレースは記録されません。</p>
<table class="table table-bordered" style="margin: 1em 0 0 0; table-layout: fixed">
<thead>
<th>Addr</th>
<th>Phase</th>
<th>PC</th>
<th>FLAG</th>
<th>ACC</th>
<th>IX</th>
<th>MAR</th>
<th>IR</th>
</thead>
</table>
<div id="trace_area" style="max-height: 36em; overflow: scroll; margin: 0; padding: 0">
<table class="table table-bordered" style="margin: 0; table-layout: fixed">
<tbody id="trace_body">
</tbody>
</table>
</div>
<label style="display: block; padding: 0.5em; float: left; width: 24em;"><input type="checkbox" id="trace_enabled">トレースを有効にする</label>
<label style="display: block; padding: 0.5em; float: left; width: 24em;"><input type="checkbox" id="revive_bugs" checked>KUE-CHIP2のバグを再現(フェーズ実行時)</label>
<button type="button" class="btn btn-default" style="float: right" onclick="buttonTraceClear()">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> クリア
</button>
</div>
<div role="tabpanel" class="tab-pane" id="content_statistics">
<h2>統計</h2>
<p>統計を使用するには、「実行/停止」を選択してください</p>
<table class="table table-bordered" style="margin: 1em 0 0 0; table-layout: fixed">
<thead>
<th>名前</th>
<th>値</th>
</thead>
<tbody>
<tr><td>総実行時間</td><td><span id="statistics_process_time"></span></td></tr>
<tr><td>総命令数</td><td><span id="statistics_instruction_count"></span></td></tr>
<tr><td>総フェーズ数</td><td><span id="statistics_phase_count"></span></td></tr>
<tr><td>実効動作周波数</td><td><span id="statistics_effective_freq"></span></td></tr>
<tr><td>フェーズ最大処理時間</td><td><span id="statistics_max_phase_time"></span></td></tr>
<tr><td>フェーズ平均処理時間</td><td><span id="statistics_ave_phase_time"></span></td></tr>
<tr><td>命令最大処理時間</td><td><span id="statistics_max_instruction_time"></span></td></tr>
<tr><td>命令平均処理時間</td><td><span id="statistics_ave_instruction_time"></span></td></tr>
</tbody>
</table>
</div>
<div role="tabpanel" class="tab-pane" id="content_io">
<h2>別のKUE-CHIP2と接続する</h2>
<p>
現在実行中のKUE-CHIP2のOBUFを、他の実行中のKUE-CHIP2のIBUFに接続することが出来ます。<br>
接続を行うには、同じWebブラウザ上で新しいKUE-CHIP2インスタンスを起動してください。<br>
Chromeの場合、バックグラウンドタブではプログラムの動作が極端に遅くなります。
接続するKUE-CHIP2は別ウィンドウで開き、常に表示された状態にしておくことをおすすめします。
</p>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default" onclick="window.open('index.html', '_blank')">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> 新しいKEMU-IDEを開く
</button>
</div>
<h3>現在の接続状態</h3>
<table class="table table-bordered" style="table-layout: fixed;">
<thead>
<th></th>
<th>ポート名</th>
<th>名前</th>
</thead>
<tbody>
<tr><td>このKUE-CHIP2</td><td>OUT</td><td><span id="io_name"></span></td></tr>
<tr><td>接続先のKUE-CHIP2</td><td>IN</td><td><span id="io_connected_name">接続していません</span></td></tr>
</tbody>
</table>
<h3>接続可能なKUE-CHIP2</h3>
<div id="io_connect_list" class="list-group">
<div class="list-group-item">接続可能なKUE-CHIP2はありません</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/kemu.js"></script>
<script>
var userMemoryModified = false;
var programMemoryModified = false;
var statusControl = {
"ACC": null, "IX": null, "FLAG": null, "IR": null, "PC": null, "MAR": null, "IBUF": null,
"OBUF": null, "PHASE": null
};
var memoryControl = {};
var core = new KUEChip2Core();
var pc = 0;
var breakpoints = {};
var traceEnabled = false, reviveBugs = true;
var kemuName = Math.random().toString(36).slice(-8);
var connectedName = null;
var connectTimer = null;
core.ioPreHandler = function(){
var me = JSON.parse(localStorage["KEMU-" + kemuName]);
core.flag["IBUF"] = me.iflag || false;
core.reg["IBUF"] = me.ibuf || 0;
if (!connectedName) return;
var target = JSON.parse(localStorage["KEMU-" + connectedName]);
if (!target) return;
core.flag["OBUF"] = !!target.iflag;
};
core.ioPostHandler = function(){
var obj = {
timestamp: +new Date(),
obuf: core.reg["OBUF"],
ibuf: core.reg["IBUF"],
oflag: core.flag["OBUF"],
iflag: core.flag["IBUF"]
};
localStorage.setItem("KEMU-" + kemuName, JSON.stringify(obj));
if (connectedName) {
obj = JSON.parse(localStorage.getItem("KEMU-" + connectedName));
if (obj.iflag != core.flag["OBUF"] || obj.ibuf == core.reg["OBUF"]) {
obj.iflag = core.flag["OBUF"];
obj.ibuf = core.reg["OBUF"];
localStorage.setItem("KEMU-" + connectedName, JSON.stringify(obj));
}
}
};
function connectCore(core) {
}
function loadHex(s) {
var i = 0, n = 0;
while (true) {
while (i < s.length && s[i].match(/\s/)) i++;
if (i >= s.length) break;
var str = "";
while (i < s.length && s[i].match(/[0-9a-fA-F]/)) str += s[i++];
if (i < s.length && !s[i].match(/\s/)) return false;
var val = parseInt(str, 16);
if ((val & ~0xFF) != 0) return false;
core.memory[n++] = val;
}
if (n > 0x200) return false;
while (n < 0x200) core.memory[n++] = 0;
return true;
}
function initializeInterface() {
var initMemTable = function(n, $e){
var t = $('<table>')
.css('margin', '1em 0')
.addClass("table")
.addClass("table-bordered");
var tr = $('<tr>').append($('<th>').css('text-align', 'center').text(("00" + n.toString(16)).slice(-3)));
// n >>= 4;
for(var i = 0; i < 16; i++){
tr.append($('<th>').text(("0"+i.toString(16)).slice(-2).toUpperCase()).css('text-align', 'center'));
}
t.append($('<thead>').append(tr));
var tb = $('<tbody>');
for(var i = 0; i < 16; i++){
var tr = $('<tr>').append($('<th>')
.text(((n + i).toString(16) + "0").slice(-2).toUpperCase())
.css('text-align', 'right'));
for(var k = 0; k < 16; k++){
var d = $('<input>')
.attr("type", "text")
.data("addr", (n + (i << 4) + k))
.css('width', '3em')
.css('border', 'none')
.css('padding', '0.5em')
.addClass("text-center");
var changeEvent = function(){
var d = $(this);
var s = d.val().slice(0, d.get(0).selectionStart).replace(/[^0-9A-Fa-f]/g,'');
var addr = parseInt(d.data('addr'));
while (s.length > 0 && addr < 0x200) {
if (addr < 0x100) programMemoryModified = true;
else userMemoryModified = true;
if (s.length >= 2) {
core.memory[addr++] = parseInt(s.slice(0, 2), 16);
s = s.slice(2);
} else {
core.memory[addr] = parseInt(s.slice(0, 1), 16) << 4;
break;
}
}
updateInterface();
if (addr < 0x200) {
memoryControl[addr].focus();
memoryControl[addr].get(0).selectionStart = s.length > 0 ? 1 : 0;
memoryControl[addr].get(0).selectionEnd = s.length > 0 ? 1 : 0;
}
};
d.keyup(changeEvent);
d.change(changeEvent);
memoryControl[n + (i << 4) + k] = d;
tr.append($("<td>").css("padding", "0").css('width', '2em').append(d));
}
tb.append(tr);
}
t.append(tb);
$e.append(t);
};
var $area = $('#statusbox');
$area.empty();
for(k in statusControl){
if (!k) continue;
statusControl[k] = $('<input>').attr('type', 'text').addClass('text-center').data('name', k);
$area.append($('<div>').text(k).append(statusControl[k]));
var changeEvent = function() {
core.reg[$(this).data('name')] = parseInt($(this).val(), 16);
if ($(this).data('name') == "PC") {
core.reg["PHASE"] = 0;
pc = parseInt($(this).val(), 16);
core.halted = false;
}
updateInterface();
};
statusControl[k].change(changeEvent);
}
initMemTable(0, $('#content_memory'));
initMemTable(0x100, $('#content_user'));
}
function updateInterface(anim) {
var message = "";
$('.warning').removeClass('warning');
$('.pc_active').removeClass('pc_active');
if (core.flag["IBUF"]) message += "IFLAGがオンです\n";
if (core.flag["OBUF"]) message += "OFLAGがオンです\n";
for (var key in core.reg) {
if (!key) continue;
var s = ("0" + core.reg[key].toString(16)).toUpperCase().slice(-2);
if (anim && statusControl[key].val() != s)
statusControl[key].addClass('warning');
statusControl[key].val(s);
}
for (var i = 0; i < 0x200; i++) {
var data1 = ('0' + core.memory[i].toString(16).toUpperCase()).slice(-2);
var data0 = memoryControl[i].val();
if (data0 != data1) {
if (anim) memoryControl[i].addClass('warning');
memoryControl[i].val(data1);
if (anim && data0 != "") message += "メモリの" + ("00" + i.toString(16).toUpperCase()).split(-3) + "H番地が" +
data0 + "Hから" + data1 + "Hに書き換わりました\n";
} else if (i < 0x100 && i == core.reg['PC']) {
memoryControl[i].addClass('pc_active');
}
}
$('.dasm-line').css('background-color', '');
$('.dasm-line-' + pc.toString()).css('background-color', '#FF6');
$('.break-button').css('color', 'white');
for (var addr in breakpoints) {
if (addr !== undefined) {
$('.break-button-' + addr.toString()).css('color', '#F33');
}
}
if (runningDelta != -1) {
message += "プログラムの実行時間は " + runningDelta + "ミリ秒 でした\n";
runningDelta = -1;
}
if (core.halted) {
message += "プログラムの実行が停止しました。初期状態に戻すには「リセット」を選択してください。";;
} else if (pc == 0){
if (traceEnabled) message += "トレース実行するには、「ステップ実行」または「フェーズ実行」を選択してください";
else message += "実行するには、「実行/停止」もしくは「ステップ実行」、「フェーズ実行」を選択してください";
}
$('#infobox_text').html(message.replace(/\n/g, "<br>"));
KemuStatistics.showStatistics();
}
function disassemble() {
$('#dasm_body').empty();
breakpoints = {};
var res = core.disassemble();
var max = res.length - 1;
while (max > 0 && res[max].disassemble[0] == "NOP") max--;
for (var i = 0; i <= max; i++) {
var text = "", cmd = res[i].disassemble;
var count = 0;
var tr = $('<tr>').addClass('dasm-line').addClass('dasm-line-' + res[i].addr.toString());
tr.append($('<td>').text(res[i].addr.toString(16).toUpperCase()));
for (var j = 0; j < res[i].binary.length; j++) {
text += ("0" + res[i].binary[j].toString(16).toUpperCase()).slice(-2) + " ";
}
tr.append($('<td>').append($('<span>')
.text("●")
.data('addr', res[i].addr.toString())
.css('cursor', 'pointer')
.css('padding', '0.5em')
.addClass('break-button')
.addClass('break-button-' + res[i].addr.toString())
.click(function(){
var addr = parseInt($(this).data('addr'));
if (breakpoints[addr] != undefined) {
delete breakpoints[addr];
} else {
breakpoints[addr] = "";
}
updateInterface();
})));
tr.append($('<td>').html(text));
text = "";
for (var j = 0; j < cmd.length; j++) {
var td = $('<td>');
if (typeof cmd[j] == "number") {
var s = ("0" + cmd[j].toString(16)).toUpperCase().slice(-2) + "H";
count += s.length;
// text += '<span class="hover_val" data-script="core.memory[' + cmd[j].toString(10) + ']">'
// + s + "</span>";
text += s;
} else {
var cmdTable = {
"ACC": "core.reg['ACC']",
"IX" : "core.reg['IX']"
};
if (cmd[j] in cmdTable) {
text += '<span class="hover_val" data-script="' + cmdTable[cmd[j]] + '">'
+ cmd[j] + "</span>";
} else {
text += cmd[j];
}
count += cmd[j].length;
}
if (((typeof cmd[0]) != "number") && (j == 0 || cmd[j] == ",")) {
while (count % 8 != 0) text += ' ', count++;
}
}
tr.append($('<td>').html(text));
$('#dasm_body').append(tr);
}
}
function updateCoreList() {
$('#io_connect_list').empty();
var count = 0, enabled = false;
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
var rex = key.match(/^KEMU-(.*)$/);
if (rex) {
var name = rex[1];
if (name == kemuName) continue;
if (+new Date() - JSON.parse(localStorage.getItem("KEMU-" + name)).timestamp > 1800) {
localStorage.removeItem("KEMU-" + name);
i--;
continue;
}
if (name == connectedName) enabled = true;
var div = $('<a>').addClass('list-group-item').addClass('button').text(name).click(function(){
connectedName = $(this).text();
$('#io_connected_name').text(connectedName);
});
$('#io_connect_list').append(div);
count++;
}
}
if (enabled == false && connectedName != null) {
connectedName = null;
$('#io_connected_name').text("接続していません");
$('#infobox_text').text("接続先のKUE-CHIP2との通信が途絶えました");
}
if (count == 0) {
$('#io_connect_list').append($('<div>').addClass('list-group-item').text("現在接続可能なKUE-CHIP2はありません"));
} else {
$('#io_connect_list').append($('<a>').addClass('list-group-item').text("接続を解除").click(function(){
connectedName = null;
$('#io_connected_name').text("接続していません");
}));
}
}
$(function(){
// Drag and Drop
var cancelEvent = function(e){
e.preventDefault();
e.stopPropagation();
return false;
}
if (localStorage['KEMU_EMU_HEX']) {
if (!loadHex(localStorage['KEMU_EMU_HEX'])) {
alert("データの読み込みに失敗しました。");
}
else delete localStorage['KEMU_EMU_HEX'];
}
initializeInterface();
disassemble();
updateInterface();
$('#trace_enabled').change(function(){
traceEnabled = $('#trace_enabled').prop('checked') ? true : false;
updateInterface();
if (traceEnabled && pc != 0) $('#infobox_text').text("最初からトレースを実行するには、「リセット」を選択してください");
});
$('#revive_bugs').change(function(){
reviveBugs = $('#revive_bugs').prop('checked') ? true : false;
updateInterface();
});
$('#io_name').text(kemuName);
updateCoreList();
core.ioPostHandler();
connectTimer = setTimeout(function connectTimerFunction(){
var val = localStorage.getItem("KEMU-" + kemuName);
if (val) {
var obj = JSON.parse(val);
obj.timestamp = +new Date();
localStorage.setItem("KEMU-" + kemuName, JSON.stringify(obj));
}
updateCoreList();
connectedTimer = setTimeout(connectTimerFunction, 600);
}, 600);
});
var KemuStatistics = (function(core, $){
var phaseBeginTime = 0;
var instructionBeginTime = 0;
var beginTime = 0, endTime = 0;
var phaseCount = 0, instructionCount = 0;
var phaseTime = 0, maxPhaseTime = 0;
var instructionTime = 0, maxInstructionTime = 0;
return {
showStatistics: function(){
var now = +new Date();
var processTime = endTime == 0 ? now - beginTime : endTime - beginTime;
if (beginTime == 0) processTime = 0;
$('#statistics_process_time').text(processTime.toString() + "ms");
$('#statistics_instruction_count').text(instructionCount.toString());
$('#statistics_phase_count').text(phaseCount.toString());
$('#statistics_max_phase_time').text((maxPhaseTime * 1000).toFixed(2) + "us");
$('#statistics_ave_phase_time').text(phaseCount == 0 ? "-" : (phaseTime / phaseCount * 1000).toFixed(2) + "us");
$('#statistics_max_instruction_time').text(maxInstructionTime.toFixed(2) + "ms");
$('#statistics_ave_instruction_time').text(instructionCount == 0 ? "-" : (instructionTime / instructionCount).toFixed(2) + "ms");
var ratio = phaseCount / processTime * 1000;
var s = ratio.toFixed(2) + "Hz";
if (ratio > 1000) s = (ratio / 1000).toFixed(2) + "kHz";
if (processTime == 0) s = "-";
$('#statistics_effective_freq').text(s);
},
start: function(){
this.reset();
beginTime = +new Date();
},
stop: function(){
endTime = +new Date();
},
prePhase: function(){
var now = +new Date();
phaseBeginTime = now;
if (core.reg["PHASE"] == 0)
instructionBeginTime = now;
},
postPhase: function(){
var now = +new Date();
var delta = now - phaseBeginTime;
phaseTime += delta;
phaseCount++;
if (delta > maxPhaseTime) maxPhaseTime = delta;
if (core.reg["PHASE"] == 0) {
delta = now - instructionBeginTime;
instructionCount++;
instructionTime += delta;
if (delta > maxInstructionTime) maxInstructionTime = delta;
}
},
reset: function(){
phaseBeginTime = instructionBeginTime = beginTime
= endTime = phaseCount = instructionCount
= phaseTime = instructionTime = maxPhaseTime
= maxInstructionTime = 0;
}
};
})(core, jQuery);
function runPhase(mode) {
if (core.halted) return;
var p = core.reg["PHASE"];
if (mode == 0) KemuStatistics.prePhase();
core.runSinglePhase();
if (mode == 2 && reviveBugs) core.srFlagSave = false;
if (mode == 0) KemuStatistics.postPhase();
if (traceEnabled && mode != 0) {
var tr = $('<tr>')
.append($('<td>').text(("0" + pc.toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(p))
.append($('<td>').text(("0" + core.reg["PC"].toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(("0" + core.reg["FLAG"].toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(("0" + core.reg["ACC"].toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(("0" + core.reg["IX"].toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(("0" + core.reg["MAR"].toString(16)).slice(-2).toUpperCase()))
.append($('<td>').text(("0" + core.reg["IR"].toString(16)).slice(-2).toUpperCase()));
$('#trace_body').append(tr);
$('#trace_area').scrollTop(document.getElementById('trace_area').scrollHeight);
}
if (core.reg["PHASE"] == 0) pc = core.reg["PC"];
}
function runInstruction() {
if (core.halted) return;
do {
runPhase(1);
} while (core.reg["PHASE"] != 0);
pc = core.reg["PC"];
}
function buttonOpenFile() {
$("#droparea").toggle();
return false;
}
var runningTimerInterval = 100;
var runningTimer = null;
var runningStart = -1;
var runningDelta = -1;
function buttonRunStop() {
if (runningTimer != null) {
KemuStatistics.stop();
clearTimeout(runningTimer);
runningTimer = null;
} else {
KemuStatistics.start();
core.halted = false;
runningStart = +new Date();
var timerCount = 0, timerTime, lastUpdatedTime = runningStart;
runningTimer = setTimeout(function runningTimerCallback(){
timerTime = +new Date();
runPhase(0);
if (core.halted || (core.reg["PHASE"] == 0 && breakpoints[pc] != undefined)) {
KemuStatistics.stop();
runningTimer = null;
if (timerCount > 0) runningDelta = timerTime - runningStart;
updateInterface(true);
return;
} else {
if (timerTime - lastUpdatedTime > 50) {
updateInterface(true);
lastUpdatedTime = timerTime;
}
runningTimer = setTimeout(runningTimerCallback, Math.max(0, runningTimerInterval - (+new Date() - timerTime)));
}
timerCount++;
}, 0);
}
}
function buttonStep() {
if (runningTimer != null) return false;
core.halted = false;
runInstruction();
updateInterface(true);
return false;
}
function buttonPhase() {
if (runningTimer != null) return false;
core.halted = false;
runPhase(2);
updateInterface(true);
return false;
}
function buttonReset() {
if (runningTimer != null) {
clearTimeout(runningTimer);
runningTimer = null;
}
core.reset();
KemuStatistics.reset();
pc = 0;
updateInterface(false);
return false;
}
function buttonClear() {
if (!userMemoryModified || confirm("メモリの内容が変更されています。本当に初期化してよろしいですか?")) {
for (var i = 0x100; i < 0x200; i++) core.memory[i] = 0;
userMemoryModified = false;
updateInterface();
}
}
function buttonDisassemble() {
disassemble();
updateInterface();
return false;
}
function buttonTraceClear() {
$('#trace_body').empty();
}
</script>
</body>
</html>