-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.js
85 lines (62 loc) · 1.76 KB
/
Main.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
let pce = null;
function FileChange(e) {
FileRead(e.target.files[0]);
}
function FileRead(file) {
let reader = new FileReader();
reader.onload = function (e) {
RomChange(e.target.result);
};
reader.readAsArrayBuffer(file);
}
function Pause() {
pce.Pause();
document.querySelector("#pause").disabled = true;
document.querySelector("#start").disabled = false;
}
function Start() {
pce.Start();
document.querySelector("#pause").disabled = false;
document.querySelector("#start").disabled = true;
}
function RomChange(changerom) {
Pause();
let rom;
let u8array = new Uint8Array(changerom);
rom = new Array();
for(let i=0; i<u8array.length; i++)
rom.push(u8array[i]);
pce.Init();
pce.SetROM(rom);
Start();
}
function Set() {
pce = new PCE();
if(!pce.SetCanvas("canvas0"))
return;
window.addEventListener("dragenter",
function (e) {
e.preventDefault();
}, false);
window.addEventListener("dragover",
function (e) {
e.preventDefault();
}, false);
window.addEventListener("drop",
function (e) {
e.preventDefault();
FileRead(e.dataTransfer.files[0]);
}, false);
document.querySelector("#file").addEventListener("change", FileChange, false);
window.addEventListener("gamepadconnected", function(e) {
if(e.gamepad.index == 0)
document.querySelector("#pad0state").innerHTML = e.gamepad.id;
});
window.addEventListener("gamepaddisconnected", function(e) {
if(e.gamepad.index == 0)
document.querySelector("#pad0state").innerHTML = "";
});
document.querySelector("#pause").addEventListener("click", Pause, false);
document.querySelector("#start").addEventListener("click", Start, false);
}
window.addEventListener('load', Set, false);