This repository has been archived by the owner on Aug 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pre.js
105 lines (91 loc) · 1.79 KB
/
pre.js
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
// Emglken prefix code for Hugo
(function(){
// Utility to extend objects
function extend()
{
var old = arguments[0], i = 1, add, name;
while ( i < arguments.length )
{
add = arguments[i++];
for ( name in add )
{
old[name] = add[name];
}
}
return old;
}
var GiDispa
var Glk
var default_options = {
memdir: '',
}
// Give this Emscripten module the Quixe API
var Module = {
// Store the data and options
prepare: function( data, options )
{
// If we are not given a glk option then we cannot continue
if ( !options.Glk )
{
throw new Error( 'A reference to Glk is required' )
}
GiDispa = options.GiDispa
Glk = options.Glk
this.data = data
this.options = extend( {}, default_options, options )
// Cache the game signature
var signature = ''
var i = 0
while ( i < 64 )
{
signature += ( this.data[i] < 0x10 ? '0' : '' ) + this.data[i++].toString( 16 )
}
this.signature = signature
this.loadMem()
},
// Call emgiten()
init: function()
{
// Setup game
this.ccall(
'emhugoen',
null,
[ 'array', 'number' ],
[ this.data, this.data.length ],
{ async: true }
)
delete this.data
},
resume: function( res )
{
this.glem_callback( res )
},
get_signature: function()
{
return this.signature
},
// Find the .mem file
locateFile: function( filename )
{
if ( ENVIRONMENT_IS_NODE )
{
return __dirname + '/' + filename
}
return filename
},
// A dummy XHR to delay loading
memoryInitializerRequest: typeof XMLHttpRequest !== 'undefined' && new XMLHttpRequest(),
// Load memory in the browser
loadMem: function()
{
if ( ENVIRONMENT_IS_WEB )
{
if ( this.options.memdir )
{
memoryInitializer = this.options.memdir + '/' + memoryInitializer
}
doBrowserLoad()
}
delete this.memoryInitializerRequest
},
}