-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.htm
More file actions
139 lines (105 loc) · 3.84 KB
/
match.htm
File metadata and controls
139 lines (105 loc) · 3.84 KB
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
<html>
<head>
<link href='https://schickt.de/font/px8x8.css' rel='stylesheet'>
<link rel="stylesheet" type="text/css" href="style/style.css" media="screen" />
<style>
#log {
overflow: scroll;
height: calc(100% - 16px);
}
</style>
<script src='rc-mrs-whitlow.js'></script>
<script src='rc-zeus.js'></script>
<script src='rc-core.js'></script>
<script src='rc-math.js'></script>
<script src='rc-address-modes.js'></script>
<script src='rc-preprocessor.js'></script>
<script src='rc-assembler.js'></script>
<script src='rc-classes.js'></script>
<script src='rc-instruction-set.js'></script>
<script src='rc-instruction.js'></script>
<script src='ui-common.js'></script>
<script>
var mrs_whitlow
var warriors
function init() {
mrs_whitlow = new MrsWhitlow(new Environment())
// listen to messages from parent window
window.addEventListener('message', message_handler, false)
}
function set_warriors(b64s) {
// decode the warriors and pass them on to Mrs. Whitlow
warriors = []
for (var i = 0; i < b64s.length; i++) {
warriors.push(atob(b64s[i]))
}
}
function message_handler(event) {
items = event.data.split('::')
action = items.shift(0)
switch (action) {
case 'load':
set_warriors(items)
break
case 'environment':
mrs_whitlow.environment = JSON.parse(atob(items[0]))
break
}
}
function log(text) {
const l = document.getElementById('log')
l.innerHTML += text + '<br>'
// force redraw
const d = l.style.display
const q = l.offsetHeight
l.offsetHeight += 1
l.style.display = 'none'
l.style.display = d
}
function clear_log() {
document.getElementById('log').innerHTML = '';
}
function run_match() {
clear_log()
mrs_whitlow.set_warriors(warriors)
mrs_whitlow.run_match(round_ended)
}
function round_ended(results, info) {
clear_log()
var max = 0
results.sort(function (a, b) {
max = Math.max(a.score, Math.max(b.score, max))
return b.score - a.score
})
var max_l = (max + '').length
var max_pos_l = (results.length + '').length
for (var r = 0; r < results.length; r++) {
const result = results[r]
const name = result.name !== undefined ? result.name : '-'
const position = (1 + r + '').padStart(max_pos_l)
log(`${position}. ${(result.score + '').padStart(max_l)} | ${name}`)
}
results.sort(function (a, b) {
return b.score - a.score
})
log(`\nMatch ${info.ran}/${info.total}\n${info.cycles} cycles in ${info.duration} ms\n${info.mips} MIPS.`)
}
function run_tournament() {
mrs_whitlow.set_warriors(warriors)
mrs_whitlow.run_tournament(round_ended)
}
</script>
</head>
<body onload='init()'>
<div class='top light'>
<div>
<pre id='log' class='padded code'><b>nCODE IDE :: MATCH CONSOLE</b><br></pre>
</div>
</div>
<div class='toolbar'>
<input type='button' value='RUN MATCH' onclick='run_match()'>
<input type='button' value='RUN TOURNAMENT' onclick='run_tournament()'>
<input type='button' value='CLEAR LOG' onclick='clear_log()' class='right'>
</div>
</body>
</html>