forked from snesrev/smw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.html
More file actions
219 lines (207 loc) · 9.64 KB
/
shell.html
File metadata and controls
219 lines (207 loc) · 9.64 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
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>Super Metroid</title>
<link rel="canonical" href="https://enderandrew.com/sm/" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="apple-touch-icon" href="./apple-touch-icon.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./favicon-16x16.png">
<link rel="manifest" href="./site.webmanifest">
<link rel="mask-icon" href="./safari-pinned-tab.svg" color="#5bbad5">
<meta name="apple-mobile-web-app-title" content="Super Metroid">
<meta name="application-name" content="Super Metroid">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta property="og:type" content="website" />
<meta property="og:title" content="Super Metroid" />
<meta property="og:description" content="Play Super Metroid directly in the browser" />
<meta property="og:image" content="https://enderandrew.com/sm/logo.png" />
<!-- Google tag (gtag.js) -->
<meta name="google-site-verification" content="Fw32VtOfNNMYuxwq-LDxGbzuY7QIxjvQmLuWnv6FTGY" />
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C7FZLTKS4Q"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-C7FZLTKS4Q');
</script>
<meta name="description" content="Classic Super Metroid ported for the web">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0.0, viewport-fit=cover">
<style>
#spinner,.info-overlay{position:absolute;margin:auto;top:0;bottom:0;left:0;right:0}a{color:#867ae0;text-decoration:none}a:hover{text-decoration:underline}body{color:#ccc;font-family:Monospace;font-size:16px;background-color:#000;margin:0;display:flex;justify-content:center}canvas{overflow:auto;width:100vw}@media screen and (min-width:576px){canvas{height:100vh;width:auto}}@keyframes page-loader{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.info-overlay{text-align:center;width:200px;height:200px;display:none}#spinner{content:"";border-radius:50%;width:48px;height:48px;border-top:2px solid #222;border-right:2px solid #222;border-bottom:2px solid #222;border-left:2px solid #867ae0;transform:translateZ(0);animation:1.1s linear infinite page-loader}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
</head>
<body>
<hr/>
<figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>emscripten</strong></center></figure>
<div class="emscripten" id="status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<div class="emscripten_border">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<hr/>
<div class="emscripten">
<input type="file" id="romfile" name="romfile" accept="application/vnd.nintendo.snes.rom" onchange="Module.loadRomFile()" />ROM file
<input type="checkbox" id="resize">Resize canvas
<input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
document.getElementById('resize').checked)">
</div>
<hr/>
<textarea class="emscripten" id="output" rows="8"></textarea>
<hr>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
var romfileInputElement = document.getElementById("romfile");
const EXPECTED_HASH = '6b47bb75d16514b6a476aa0c73a683a2a4c18765';
function buf2hex(buffer) {
return [...new Uint8Array(buffer)]
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}
var Module = {
loadRomFile: (function() {
console.log('loadRomFile');
for (const file of romfileInputElement.files) {
console.log(file);
// TODO if sha1 matches, store in indexedDB FS ??
let reader = new FileReader();
reader.onload = function() {
console.log('File is %d bytes long', reader.result.byteLength);
// Check SHA-1 hash
crypto.subtle.digest("SHA-1", reader.result).then(hash => {
if (EXPECTED_HASH !== buf2hex(hash)) {
console.error('Wrong rom file hash: %s. Expected %s.', buf2hex(hash), EXPECTED_HASH);
alert('Wrong rom file!');
} else {
// ROM is correct
console.log('Storing file into IndexedDB filesystem...');
var fd = FS.open('/roms/smw.sfc', "w+");
FS.write(fd, new Uint8Array(reader.result), 0, reader.result.byteLength, 0);
FS.close(fd);
FS.syncfs(function (err) {
if (err) {
console.error(err);
alert('Failed to store selected file');
} else {
console.log('Starting game with selected rom file...');
this.callMain();
}
});
}
});
};
reader.onerror = function() {
console.error('Failed to read selected file');
alert('Failed to read selected file');
};
console.log('Reading selected file...');
reader.readAsArrayBuffer(file);
}
}),
preRun: [
(async function() {
console.log("preRun hook: look for rom in IndexedDB filesystem");
// Mount 'roms' directory in browser's persistent IndexedDB
FS.mkdir('/roms');
FS.mount(IDBFS, {}, '/roms');
FS.syncfs(true, function (err) {
if (err) {
console.error(err);
alert('Failed to mount \'roms\' filesystem');
} else {
var rompath = FS.analyzePath('/roms/smw.sfc', true);
console.log(rompath);
if (rompath.exists) {
console.log('ROM file already in filesystem');
console.log('Starting game with stored rom file...');
this.callMain();
}
}
});
})
],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return (...args) => {
var text = args.join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&");
//text = text.replace(/</g, "<");
//text = text.replace(/>/g, ">");
//text = text.replace('\n', '<br>', 'g');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
canvas: (() => {
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", (e) => { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: (text) => {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: (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 = () => {
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = (text) => {
if (text) console.error('[post-exception status] ' + text);
};
};
</script>
{{{ SCRIPT }}}
</body>
</html>