-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinput.js
116 lines (116 loc) · 3.87 KB
/
input.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
106
107
108
109
110
111
112
113
114
115
116
var io;
(function (io) {
var Input = (function () {
function Input(document, window, cpu) {
this.OUT_PORT2 = 0;
this.OUT_PORT3 = 0;
this.OUT_PORT4LO = 0;
this.OUT_PORT4HI = 0;
this.OUT_PORT5 = 0;
this.IN_PORT1 = 0;
this.IN_PORT2 = 0;
this.SINGLE = 0x53;
this.MULTIPLAYER = 0xBA;
this.COIN = 0x43;
this.LEFT = 0x25;
this.RIGHT = 0x27;
this.SPACE = 0x20;
this.P = 0x50;
this.RESET = 0x52;
this.document = document;
this.window = window;
this.cpu = cpu;
this.mapper = [];
this.paused = false;
var ref = this;
this.document.onkeydown = function (e) {
ref.mapper[e.keyCode] = true;
if(ref.mapper[ref.P]) {
if(!ref.paused) {
clearInterval(ref.id);
} else {
ref.id = setInterval(ref.window.run, 16);
}
ref.paused = !ref.paused;
}
};
this.document.onkeyup = function (e) {
ref.mapper[e.keyCode] = false;
};
}
Input.prototype.init = function () {
this.IN_PORT2 |= (0x1 | 0x2);
this.IN_PORT2 |= (0x80);
};
Input.prototype.update = function () {
this.IN_PORT1 = this.IN_PORT1 & (~(0x1 | 0x2 | 0x4 | 0x10 | 0x20 | 0x40));
this.IN_PORT2 = this.IN_PORT2 & (~(0x4 | 0x10 | 0x20 | 0x40));
if(this.mapper[this.COIN]) {
this.IN_PORT1 |= 0x1;
}
if(this.mapper[this.MULTIPLAYER]) {
this.IN_PORT1 |= 0x2;
}
if(this.mapper[this.SINGLE]) {
this.IN_PORT1 |= 0x4;
}
if(this.mapper[this.LEFT]) {
this.IN_PORT1 |= 0x20;
this.IN_PORT2 |= 0x20;
}
if(this.mapper[this.RIGHT]) {
this.IN_PORT1 |= 0x40;
this.IN_PORT2 |= 0x40;
}
if(this.mapper[this.SPACE]) {
this.IN_PORT1 |= 0x10;
this.IN_PORT2 |= 0x10;
}
if(this.mapper[this.RESET]) {
this.cpu.Reset();
}
};
Input.prototype.OutPutPort = function (port, value) {
switch(port) {
case 2:
this.OUT_PORT2 = value;
break;
case 3:
this.OUT_PORT3 = value;
break;
case 4:
this.OUT_PORT4LO = this.OUT_PORT4HI;
this.OUT_PORT4HI = value;
break;
case 5:
this.OUT_PORT5 = value;
break;
}
};
Input.prototype.InputPort = function (port) {
var result = 0;
switch(port) {
case 1:
result = this.IN_PORT1;
break;
case 2:
result = this.IN_PORT2;
break;
case 3:
result = ((((this.OUT_PORT4HI << 8) | this.OUT_PORT4LO) << this.OUT_PORT2) >> 8);
break;
}
return result;
};
Object.defineProperty(Input.prototype, "interval", {
set: function (intervalID) {
this.id = intervalID;
},
enumerable: true,
configurable: true
});
return Input;
})();
io.Input = Input;
})(io || (io = {}));
//@ sourceMappingURL=input.js.map