-
Notifications
You must be signed in to change notification settings - Fork 43
/
Embedding.txt
203 lines (178 loc) · 7.43 KB
/
Embedding.txt
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
Embedding JSSpeccy into your own webpages
=========================================
JSSpeccy has been designed to allow embedding the main emulator window into
your own web pages, independently of the outer UI controls - for example, a
website for a new Spectrum game could have a live instance of the game running
within the browser.
* Download and unpack the distribution archive:
http://jsspeccy.zxdemo.org/downloads/
* Place jsspeccy-core.min.js and jdataview.js somewhere accessible on your web
space. (jdataview.js is optional, but strongly recommended to ensure Firefox
compatibility)
* In the <head> section of your page, import jsspeccy-core.min.js and
jdataview.js :
<script src="/mysite/js/jdataview.js"></script>
<script src="/mysite/js/jsspeccy-core.min.js"></script>
* In the place in your page where you want the emulator to appear, add an empty
HTML element with an ID such as 'speccy':
<div id="speccy"></div>
* Add a snippet of Javascript to call the 'JSSpeccy' function on page load,
passing in the element ID (or alternatively the element itself) and
optionally a collection of configuration settings. A simple complete example
would be as follows:
<!DOCTYPE HTML>
<html>
<head>
<title>My wonderful page</title>
<script src="jdataview.js"></script>
<script src="jsspeccy-core.min.js"></script>
<script>
function go() {
var jsspeccy = JSSpeccy('speccy', {
'autostart': false,
'autoload': true,
'scaleFactor': 1,
'loadFile': 'http://jsspeccy.zxdemo.org/games/manic_miner.z80'
});
}
</script>
</head>
<body onload="go()">
<div id="speccy"></div>
</body>
</html>
If you're using jQuery on your page, it makes sense to place this in a
document 'ready' handler:
<!DOCTYPE HTML>
<html>
<head>
<title>My wonderful page</title>
<script src="jdataview.js"></script>
<script src="jsspeccy-core.min.js"></script>
<script>
$(function() {
var jsspeccy = JSSpeccy('speccy', {
'autostart': false,
'autoload': true,
'scaleFactor': 1,
'loadFile': 'http://jsspeccy.zxdemo.org/games/manic_miner.z80'
});
});
</script>
</head>
<body>
<div id="speccy"></div>
</body>
</html>
Pixel scaling
-------------
Whenever the browser is required to scale up the screen image - either because
a scaleFactor greater than one is in use, or it is being shown on a high-DPI
display (otherwise known as Retina in Apple world...), all mainstream browsers
will use anti-aliasing by default, resulting in soft-edged pixels. To enable
hard-edged pixels instead, set the following CSS rules on the container
element:
<style>
#speccy {
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
</style>
Configuration settings
----------------------
The following options can be passed in the JSSpeccy call to customise
the behaviour:
autoload (default = false)
If true, and a tape file is specified in loadFile, the tape will be loaded
automatically (i.e. the user will not have to enter LOAD "" or select the
128 Tape Loader option).
autostart (default = true)
If true, start the emulator running immediately on page load; if false, the
emulation is initially paused.
audio (default = true)
Indicates whether audio is enabled.
border (default = true)
Whether to display the screen border.
dragToLoad (default = true)
If true, the user can load files by dragging them onto the emulator window.
loadFile
The URL of a tape or snapshot file to load on startup. Note that if this
file is hosted on a different domain to the calling page, you'll need to
configure it to allow a remote AJAX request, which typically means having
it return the HTTP header:
Access-Control-Allow-Origin: *
Also, note that FTP URLs are not supported.
scaleFactor (default = 2)
How big the emulator window should be, as a multiple of the Spectrum's
native screen size (e.g. a scaleFactor of 1 will give one screen pixel for
each Spectrum pixel).
API methods
-----------
The object returned from the 'JSSpeccy' function has a number of method calls
and properties that can be used to interact with the running emulator:
start()
Start the emulator, if it is currently paused
stop()
Pause the emulation
isRunning
Indicates whether the emulator is currently running, rather than paused
isDownloading
Indicates whether the emulator is currently retrieving a file from a
remote URL
loadLocalFile(file, opts)
Load a tape or snapshot file into the emulator. The file is passed as a
File object: http://www.w3.org/TR/FileAPI/
'opts' is a collection of properties to specify how the file is handled;
supported properties are:
autoload - if true, and file is a tape file, it will be loaded
automatically (i.e. the user will not have to enter LOAD "")
reset()
Reset the Spectrum
loadFromUrl(url, opts)
Load a tape or snapshot file from the given URL. Files are fetched with
XMLHttpRequest, so are subject to the standard browser security
restrictions on loading remote files. In particular, files hosted on
remote domains will probably need to return an Access-Control-Allow-Origin
HTTP header.
'opts' is a collection of properties to specify how the file is handled;
supported properties are:
autoload - if true, and file is a tape file, it will be loaded
automatically (i.e. the user will not have to enter LOAD "")
setModel(model)
Set the currently-emulated model of Spectrum. 'model' is a structure of
various properties relating to that model, and currently two such models
are defined: JSSpeccy.Spectrum.MODEL_48K and JSSpeccy.Spectrum.MODEL_128K.
The array JSSpeccy.Spectrum.MODELS contains all available models (this may
be extended in future versions).
getModel()
Return the currently-emulated model of Spectrum, as a structure of
properties relating to that model (see setModel).
deactivateKeyboard()
Stop the emulator responding to keypresses; you probably want to do this
while dialog boxes or other interactive items on your page are active.
activateKeyboard()
Resume responding to keypresses after a previous call to
deactivateKeyboard().
setAudioState(state)
Enable / disable audio by passing true / false respectively.
Events
------
The jsspeccy object also includes a number of event handlers - you can
attach callback functions via the event's 'bind' method to be invoked whenever
a particular event happens. For example:
jsspeccy.onStart.bind(function() {alert('Here we go!');});
onStart
Fired when emulation is started / unpaused
onStop
Fired when emulation is paused
onChangeModel
Fired when the currently emulated model of Spectrum is changed; the model
structure (see setModel above) is passed as a parameter to the callback.
onChangeAudioState
Fired when audio is enabled or disabled; the audio state (true/false) is
passed as a parameter to the callback.