-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameBoyAdvanceJoyPad.as
156 lines (147 loc) · 3.23 KB
/
GameBoyAdvanceJoyPad.as
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
package {
public class GameBoyAdvanceJoyPad {
public var IOCore;
public var keyInput;
public var keyInterrupt;
public var keyIRQType;
public var keyIRQEnabled;
public function GameBoyAdvanceJoyPad(IOCore) {
// constructor code
this.IOCore = IOCore;
this.initialize();
}
public function initialize() {
this.keyInput = 0x3FF;
this.keyInterrupt = 0;
this.keyIRQType = false;
this.keyIRQEnabled = false;
}
public function keyPress(keyPressed) {
//switch (keyPressed.toUpperCase()) {
trace("currentkey: " + keyPressed);
switch(keyPressed){
//case "A":
case 90: //z
this.keyInput &= ~0x1;
break;
//case "B":
case 66: //x
this.keyInput &= ~0x2;
break;
//case "SELECT":
case 67: //c
this.keyInput &= ~0x4;
break;
//case "START":
case 86: //v
this.keyInput &= ~0x8;
break;
//case "RIGHT":
case 39:
this.keyInput &= ~0x10;
break;
//case "LEFT":
case 37:
this.keyInput &= ~0x20;
break;
//case "UP":
case 38:
this.keyInput &= ~0x40;
break;
//case "DOWN":
case 40:
this.keyInput &= ~0x80;
break;
//case "R":
case 65: //a
this.keyInput &= ~0x100;
break;
//case "L":
case 83: //s
this.keyInput &= ~0x200;
break;
default:
return;
}
if (this.keyIRQEnabled) {
this.checkForIRQ();
}
this.IOCore.deflagStepper(0x4);
}
public function keyRelease(keyReleased) {
switch (keyReleased) {
case 90:
this.keyInput |= 0x1;
break;
case 66:
this.keyInput |= 0x2;
break;
case 67:
this.keyInput |= 0x4;
break;
case 86:
this.keyInput |= 0x8;
break;
case 39:
this.keyInput |= 0x10;
break;
case 37:
this.keyInput |= 0x20;
break;
case 38:
this.keyInput |= 0x40;
break;
case 40:
this.keyInput |= 0x80;
break;
case 65:
this.keyInput |= 0x100;
break;
case 83:
this.keyInput |= 0x200;
break;
default:
return;
}
if (this.keyIRQEnabled) {
this.checkForIRQ();
}
}
public function checkForIRQ() {
if (this.keyIRQType) {
if (((~this.keyInput) & this.keyInterrupt & 0x3FF) == (this.keyInterrupt & 0x3FF)) {
this.IOCore.irq.requestIRQ(0x1000);
}
}
else if (((~this.keyInput) & this.keyInterrupt & 0x3FF) != 0) {
this.IOCore.irq.requestIRQ(0x1000);
}
}
/*public function nextIRQEventTime{
//Always return -1 here, as we don't input joypad updates at the same time we're running the interp loop:
return -1;
}*/
public function readKeyStatus0() {
return this.keyInput & 0xFF;
}
public function readKeyStatus1() {
return ((this.keyInput >> 8) & 0x3) | 0xFC;
}
public function writeKeyControl0(data) {
this.keyInterrupt &= 0x300;
this.keyInterrupt |= data;
}
public function readKeyControl0() {
return this.keyInterrupt & 0xFF;
}
public function writeKeyControl1(data) {
this.keyInterrupt &= 0xFF;
this.keyInterrupt |= data << 8;
this.keyIRQType = (data > 0x7F);
this.keyIRQEnabled = ((data & 0x40) == 0x40);
}
public function readKeyControl1() {
return ((this.keyInterrupt >> 8) & 0xC3) | 0x3C;
}
}
}