forked from docmarionum1/jsAtari
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
133 lines (114 loc) · 2.7 KB
/
input.js
File metadata and controls
133 lines (114 loc) · 2.7 KB
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
/*
jsAtari
Copyright (C) 2011 Jeremy Neiman
This file is part of jsAtari.
jsAtari is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jsAtari is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jsAtari. If not, see <http://www.gnu.org/licenses/>.
*/
input =
{
keys:
{
TRIGGER: 32,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
RESET: 48,
SELECT: 49,
COLOR: 51,
P0DIF: 54,
P1DIF: 55,
},
onkeydown: function(e)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if (keycode == input.keys.TRIGGER)
{
tia.INPT4 = 0;
tia.ram_changed = true;
}
else if (keycode == input.keys.LEFT)
{
pia.ram[pia.reg.SWCHA] = util.D6_w(pia.ram[pia.reg.SWCHA], 0);
}
else if (keycode == input.keys.UP)
{
pia.ram[pia.reg.SWCHA] = util.D4_w(pia.ram[pia.reg.SWCHA], 0);
}
else if (keycode == input.keys.RIGHT)
{
pia.ram[pia.reg.SWCHA] = util.D7_w(pia.ram[pia.reg.SWCHA], 0);
}
else if (keycode == input.keys.DOWN)
{
pia.ram[pia.reg.SWCHA] = util.D5_w(pia.ram[pia.reg.SWCHA], 0);
}
},
onkeyup: function(e)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if (keycode == input.keys.TRIGGER)
{
tia.INPT4 = 128;
tia.ram_changed = true;
}
else if (keycode == input.keys.LEFT)
{
pia.ram[pia.reg.SWCHA] = util.D6_w(pia.ram[pia.reg.SWCHA], 1);
}
else if (keycode == input.keys.UP)
{
pia.ram[pia.reg.SWCHA] = util.D4_w(pia.ram[pia.reg.SWCHA], 1);
}
else if (keycode == input.keys.RIGHT)
{
pia.ram[pia.reg.SWCHA] = util.D7_w(pia.ram[pia.reg.SWCHA], 1);
}
else if (keycode == input.keys.DOWN)
{
pia.ram[pia.reg.SWCHA] = util.D5_w(pia.ram[pia.reg.SWCHA], 1);
}
},
onkeypress: function(e)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if (keycode == input.keys.COLOR)
{
pia.ram[pia.reg.SWCHB] ^= 8;
debug(pia.ram[pia.reg.SWCHB].toString(2));
}
},
bind_input: function(element)
{
element.onkeydown = input.onkeydown;
element.onkeyup = input.onkeyup;
element.onkeypress = input.onkeypress;
},
__init__: function(element)
{
pia.ram[pia.reg.SWCHA] = 0xff;
pia.ram[pia.reg.SWCHB] = 11;
input.bind_input(element);
}
};