-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
219 lines (183 loc) · 6.86 KB
/
index.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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
#output {
width: 100%;
height: 200px;
margin: 0 auto;
margin-top: 10px;
border-left: 0px;
border-right: 0px;
padding-left: 0px;
padding-right: 0px;
display: block;
background-color: black;
color: white;
font-family: 'Lucida Console', Monaco, monospace;
outline: none;
}
/* Medit styling */
html {
background: black;
}
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.cell {
font-family: 'Courier New', Courier, monospace;
display: inline-block;
padding: 0;
margin: 0;
position: fixed;
width: 8px;
height: 17px;
background: rgba(20, 20, 20, 255);
font-size: 14px;
color: rgba(255, 255, 255, 255);
}
#carret {
width: 8px;
height: 17px;
position: fixed;
background: white;
}
#screen {
width: 100%;
height: 100%;
}
#screen:focus {
background: red;
}
</style>
</head>
<body>
<!-- <span id='controls'>
<span><input type="checkbox" id="resize">Resize canvas</span>
<span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer </span>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
document.getElementById('resize').checked)">
</span>
</span> -->
<!-- <div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div> -->
<div id="screen" tabindex="0">
</div>
<div id="carret"></div>
<div class="emscripten_border">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<!-- <textarea id="output" rows="8"></textarea> -->
<script type='module'>
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
var Module = {
preRun: [],
postRun: [],
print: (function () {
// var element = document.getElementById('output');
// if (element) element.value = ''; // clear browser cache
return function (text) {
// if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// if (element) {
// element.value += text + "\n";
// element.scrollTop = element.scrollHeight; // focus on bottom
// }
console.log(text);
};
})(),
printErr: function (text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function () {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function (e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function (text) {
console.log("status: " + text);
},
totalDependencies: 0,
monitorRunDependencies: function (left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies - left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function (event) {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function (text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script async type="text/javascript" src="medit.js"></script>
<script type="module">
let screen = document.getElementById("screen");
let cellWidth = 8;
let cellHeight = 17;
function createCell(x, y) {
let div = document.createElement("div");
div.innerHTML = "";
div.classList.add("cell");
div.style["left"] = cellWidth * x + "px";
div.style["top"] = cellHeight * y + "px";
screen.appendChild(div);
return div;
}
let screenWidth = 80;
let screenHeight = 40;
let cells = [];
for (let y = 0; y < screenHeight; ++y) {
for (let x = 0; x < screenWidth; ++x) {
cells.push(createCell(x, y));
}
}
window.cell = function (x, y) {
return cells[y * screenWidth + x];
}
cell(10, 20).innerHTML = "a";
cell(11, 20).innerHTML = "ö";
cell(12, 20).innerHTML = "{";
window.clearScreen = function () {
for (let cell of cells) {
cell.innerHTML = "";
}
console.log("screen cleared");
}
window.setCell = function (x, y,) {
}
window.rgb = function (r, g, b) {
return "rgb(" + r + "," + g + "," + b + ")";
}
let carret = document.getElementById("carret");
window.moveCarret = function (x, y) {
carret.style.left = x * cellWidth + "px";
carret.style.top = y * cellHeight + "px";
}
document.addEventListener("keydown", function (event) {
let data = [0, 0, 0, 0];
if (event.key.length == 1) {
let raw = new TextEncoder("utf8").encode(event.key);
for (let i in raw) {
data[i] = raw[i];
}
window.Module._keyCallback(1, data[0], data[1], data[2], data[3]);
}
});
</script>
</body>
</html>