-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
203 lines (179 loc) · 6.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" type="image/ico" href="favicon.ico">
<script src="Z80.js"></script>
<script src="utils.js"></script>
<script src="MinZX.js"></script>
<script src="ZXScreen.js"></script>
<script src="ZXKeyboard.js"></script>
<script src="ZXSound.js"></script>
<title>MinZX - Minimalistic ZX Spectrum 48K emulator</title>
<style>
body {
background: #DDD;
font-family: Arial, Helvetica, sans-serif;
}
#statusmsg {
width: 640px;
text-align: center;
color: #EEE;
background-color: #777;
visibility: hidden;
}
</style>
</head>
<body>
<canvas id=zxscreen></canvas>
<br/><br/>
<button class=btnScale>1x</button>
<button class=btnScale>2x</button>
<button class=btnScale>3x</button>
<button class=btnScale>4x</button>
<button class=btnScale>5x</button>
<button class=btnScale>6x</button>
<button id=btnReset>Reset</button>
<button id=btnLoadSnaFile>Load Snapshot...</button>
<button id=btnSaveQuickSna>Quick Save (F2)</button>
<button id=btnLoadQuickSna>Quick Load (F3)</button>
<br/>
<p id="statusmsg">status</p>
<p>MinZX - Minimalistic ZX Spectrum 48K emulator</p>
<p>Developed in 2020 by <a href="https://github.com/dcrespo3d">DCrespo</a>, see <a href="https://github.com/dcrespo3d/MinZX">source code</a></p>
<script>
/**/
///////////////////////////////////////////////////////////////////////////////
/// @file index.html
///
/// @brief main html file for the MinZX 48K Spectrum emulator
///
/// @author David Crespo Tascon
//////
/// @copyright (c) David Crespo Tascon
/// This code is released under the MIT license,
/// a copy of which is available in the associated LICENSE file,
/// or at http://opensource.org/licenses/MIT
///////////////////////////////////////////////////////////////////////////////
"use strict";
let minzx = null;
window.addEventListener('load', function() {
// create new instance of MinZX emulator,
// using element with id 'zxscr' as canvas,
minzx = new MinZX('zxscreen');
// start emulator
minzx.start();
// chrome starts AudioContext in suspended state.
let resumeOnce = true;
function wakeUpAudioInChrome() {
if (resumeOnce) {
resumeOnce = false;
theAudioContext.resume();
}
}
window.addEventListener('click', function(e) {
wakeUpAudioInChrome();
});
window.addEventListener('keydown', function(e) {
wakeUpAudioInChrome();
preventDefaultKeys(e);
});
// quick save/load keys
window.addEventListener('keyup', function(e) {
if (e.key == 'F2') doQuickSave();
if (e.key == 'F3') doQuickLoad();
preventDefaultKeys(e);
});
function preventDefaultKeys(e) {
if (!e.preventDefault) return;
if (e.key == 'F2' || e.key == 'F3' || e.key == 'Backspace')
e.preventDefault();
}
// load snapshot button
const btnLoadSnaFile = document.getElementById('btnLoadSnaFile');
btnLoadSnaFile.addEventListener('click', function() {
if (resumeOnce) {
resumeOnce = false;
theAudioContext.resume();
}
loadLocalFile(function(filename, data) {
minzx.loadSNA(data);
displayStatus('Loaded Snapshot: ' + filename);
});
});
// reset button
const btnReset = document.getElementById('btnReset');
btnReset.addEventListener('click', function() {
minzx.reset();
displayStatus('Reset');
});
// key for quick snapshot save on local storage
const quickSaveKey = 'MinZX-QuickSave';
let quickSaveEnabled = false;
let quickLoadEnabled = false;
function doQuickSave() {
if (!quickSaveEnabled) return;
enableQuickLoad(true);
const snadata = minzx.saveSNA();
if (snadata == null) {
displayStatus('Cannot Save Quick Snapshot');
return;
}
const snapshot = { data: snadata };
window.localStorage[quickSaveKey] = JSON.stringify(snapshot);
displayStatus('Saved Quick Snapshot');
}
function doQuickLoad() {
if (!quickLoadEnabled) return;
const snapshot = JSON.parse(window.localStorage[quickSaveKey]);
minzx.loadSNA(snapshot.data);
displayStatus('Loaded Quick Snapshot');
}
// quick save button
const btnSaveQuickSna = document.getElementById('btnSaveQuickSna');
btnSaveQuickSna.addEventListener('click', function() {
doQuickSave();
});
// quick load button
const btnLoadQuickSna = document.getElementById('btnLoadQuickSna');
btnLoadQuickSna.addEventListener('click', function() {
doQuickLoad();
});
function enableQuickSave(enabled) { quickSaveEnabled = enabled; btnSaveQuickSna.style.display = enabled ? 'inline-block' : 'none'; }
function enableQuickLoad(enabled) { quickLoadEnabled = enabled; btnLoadQuickSna.style.display = enabled ? 'inline-block' : 'none'; }
if (window.localStorage) {
enableQuickSave(true);
if (quickSaveKey in window.localStorage) enableQuickLoad(true);
else enableQuickLoad(false);
}
else {
enableQuickSave(false);
enableQuickLoad(false);
}
let idDisplayTimeout;
// status line
function displayStatus(text) {
const statusmsg = document.getElementById('statusmsg');
statusmsg.style.visibility = 'visible';
statusmsg.innerText = text;
clearTimeout(idDisplayTimeout);
idDisplayTimeout = setTimeout(function() {
statusmsg.style.visibility = 'hidden';
}, 2000);
}
// scale buttons
const btnScaleArr = document.getElementsByClassName('btnScale');
for (let i = 0; i < btnScaleArr.length; i++) {
const btnScale = btnScaleArr[i];
const scale = parseInt(btnScale.innerText);
btnScale.addEventListener('click', function() {
minzx._screen.setScale(scale);
});
}
});
/**/
</script>
</body>
</html>