File tree Expand file tree Collapse file tree 5 files changed +19
-10
lines changed Expand file tree Collapse file tree 5 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ func (cpu *CPU) Reset(interpreter int) {
112
112
cpu .Keyboard [i ] = false
113
113
}
114
114
115
- cpu .waitForKey = false
115
+ cpu .waitForKey = 0
116
116
cpu .WaitForInt = 0
117
117
cpu .playing = false
118
118
cpu .SD = true
Original file line number Diff line number Diff line change @@ -132,23 +132,32 @@ func (cpu *CPU) Cycle() {
132
132
cpu .v [x ] = cpu .dt
133
133
case 0x0A :
134
134
// Wait for keypress and return key in vX
135
- if cpu .waitForKey {
135
+ switch cpu .waitForKey {
136
+ case 0 :
137
+ cpu .pc -= 2
138
+ for _ , p := range cpu .Keyboard {
139
+ if p {
140
+ return
141
+ }
142
+ }
143
+ cpu .waitForKey = 1
144
+ case 1 :
145
+ cpu .pc -= 2
136
146
for i , p := range cpu .Keyboard {
137
147
if p {
138
148
cpu .v [x ] = uint8 (i )
139
- cpu .waitForKey = false
149
+ cpu .waitForKey = 2
140
150
return
141
151
}
142
152
}
143
- cpu .pc -= 2
144
- } else {
145
- cpu .pc -= 2
153
+ case 2 :
146
154
for _ , p := range cpu .Keyboard {
147
155
if p {
156
+ cpu .pc -= 2
148
157
return
149
158
}
150
159
}
151
- cpu .waitForKey = true
160
+ cpu .waitForKey = 0
152
161
}
153
162
case 0x15 :
154
163
// Set delay timer to value in vX
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ type CPU struct {
44
44
45
45
// Interpreter internal state
46
46
Keyboard [16 ]bool
47
- waitForKey bool // Waiting for key press?
47
+ waitForKey uint8 // Waiting for key press?
48
48
WaitForInt uint8 // Waiting for display refresh "interrupt"?
49
49
playing bool // Playing sound?
50
50
SD bool // Screen dirty?
Original file line number Diff line number Diff line change @@ -52,13 +52,13 @@ module.exports = instance => {
52
52
cyclesPerFrame /= 2 ;
53
53
return instance . setCyclesPerFrame ( cyclesPerFrame ) ;
54
54
default :
55
- if ( Object . keys ( keys ) . includes ( e . keyCode . toString ( ) ) )
55
+ if ( instance && Object . keys ( keys ) . includes ( e . keyCode . toString ( ) ) )
56
56
instance . pressKey ( keys [ e . keyCode ] ) ;
57
57
}
58
58
} ) ;
59
59
60
60
window . addEventListener ( 'keyup' , e => {
61
- if ( instance && keys [ e . keyCode ] )
61
+ if ( instance && Object . keys ( keys ) . includes ( e . keyCode . toString ( ) ) )
62
62
instance . releaseKey ( keys [ e . keyCode ] ) ;
63
63
} ) ;
64
64
You can’t perform that action at this time.
0 commit comments