Skip to content

Commit e273716

Browse files
committed
added right player joystick
using default Stella keys: Up Y Down H Left G Right J Fire F
1 parent 87f3bd1 commit e273716

File tree

7 files changed

+147
-30
lines changed

7 files changed

+147
-30
lines changed

README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,60 @@ Although if want to pass flags to the run mode you'll need to specify it.
208208

209209
## Hand Controllers
210210

211-
Stick, paddle and keypad inputs are supported. Currently, only stick and
212-
paddles for the left player are available but keypad input is available for
213-
both players.
211+
Stick, paddle and keypad inputs are supported.
214212

215213
### Stick
216214

217-
The stick is the most common control method for `Atari 2600` games. The stick
218-
can be operated with the DPad or left thumbstick of a [gamepad](#gamepad) or by
219-
the cursor keys on your computer's keyboard. Fire button is the keyboards space
220-
bar or any of the gamepad's face buttons.
215+
The stick is the most common control method for `Atari 2600` games. The
216+
left-side player is controlled with the following keys.
217+
218+
<table>
219+
<tr>
220+
<th colspan=2>Left-Side Player</th>
221+
</tr>
222+
<tr>
223+
<td align="center">Cursor Keys</td>
224+
<td align="center">Stick Direction</td>
225+
</tr>
226+
<tr>
227+
<td align="center">Space</td>
228+
<td align="center">Fire Button</td>
229+
</tr>
230+
</table>
231+
232+
The right-side player is controlled with the following keys.
233+
234+
<table>
235+
<tr>
236+
<th colspan=2>Right-Side Player</th>
237+
</tr>
238+
<tr>
239+
<td align="center">G</td>
240+
<td align="center">Left</td>
241+
</tr>
242+
<tr>
243+
<td align="center">J</td>
244+
<td align="center">Right</td>
245+
</tr>
246+
<tr>
247+
<td align="center">Y</td>
248+
<td align="center">Up</td>
249+
</tr>
250+
<tr>
251+
<td align="center">H</td>
252+
<td align="center">Down</td>
253+
</tr>
254+
<tr>
255+
<td align="center">F</td>
256+
<td align="center">Fire Button</td>
257+
</tr>
258+
</table>
259+
260+
The stick for the left-side player can also be controlled with a [gamepad](#gamepad).
221261

222262
### Paddle
223263

224-
The paddle can be controlled with the mouse or [gamepad](#gamepad).
264+
The paddle for the left-side player can be controlled with the mouse or a [gamepad](#gamepad).
225265

226266
In the case of the mouse, the mouse must be [captured](#mouse-capture).
227267

@@ -230,17 +270,19 @@ however and which device is used depends on the game. For some games, the
230270
triggers will suffice but other games will perform better when using the mouse.
231271

232272
`Nightdriver` is an example of a game that plays well with the triggers,
233-
whereas `Circus Tricks` is better played with the mouse.
273+
whereas experience says that `Circus Tricks` is better played with the mouse.
274+
275+
The paddle for the right-side player is not currently supported.
234276

235277
### Keypad
236278

237279
Keypad input for both players is supported.
238280

239281
<table>
240282
<tr>
241-
<th colspan=3>Left Hand Player</th>
283+
<th colspan=3>Left-Side Player</th>
242284
<th></th>
243-
<th colspan=3>Right Hand Player</th>
285+
<th colspan=3>Right-Side Player</th>
244286
</tr>
245287
<tr>
246288
<td align="center">1</td>
@@ -294,9 +336,9 @@ need.
294336

295337
### Gamepad
296338

297-
For convenience the joystick and paddle can be controlled through a gamepad.
298-
For the joystick, use the left thumbstick or the DPad. Any of the face buttons
299-
will act as the joystick's fire button.
339+
For convenience the joystick and paddle for the left-side player can be
340+
controlled through a gamepad. For the joystick, use the left thumbstick or the
341+
DPad. Any of the face buttons will act as the joystick's fire button.
300342

301343
To control the paddle use the left and right analogue triggers. Note that you
302344
will need to 'waggle' the triggers a couple of times for the emulator to detect

gui/requests.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ const (
6666
// of the controller.
6767
ReqControllerChange FeatureReq = "ReqControllerChange" // plugging.PortID, plugging.PeripheralID
6868

69-
7069
ReqCartridgeEvent FeatureReq = "ReqCartridgeEvent" // mapper.Event
7170
)

gui/sdlimgui/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ func (img *SdlImgui) serviceKeyboard(ev *sdl.KeyboardEvent) {
344344
}
345345
}
346346

347-
// forward keypresses to userinput.Event channel if in playmore or gui is
348-
// in captured state
347+
// forward keypresses to userinput.Event channel
349348
if img.isPlaymode() || img.isCaptured() {
350349
mod := userinput.KeyModNone
351350

hardware/riot/ports/plugging/plugging.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type PeripheralID string
3535

3636
// List of valid PeripheralID values.
3737
const (
38+
PeriphNone PeripheralID = "None"
3839
PeriphPanel PeripheralID = "Panel"
3940
PeriphStick PeripheralID = "Stick"
4041
PeriphPaddle PeripheralID = "Paddle"

hardware/riot/ports/ports.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ func (p *Ports) GetPlayback() error {
306306
return nil
307307
}
308308

309-
// HandleEvent forwards the Event and EventData to the device connected to the
310-
// specified PortID.
309+
// HandleEvent implements userinput.HandleInput interface.
311310
func (p *Ports) HandleEvent(id plugging.PortID, ev Event, d EventData) error {
312311
var err error
313312

@@ -333,6 +332,20 @@ func (p *Ports) HandleEvent(id plugging.PortID, ev Event, d EventData) error {
333332
return nil
334333
}
335334

335+
// PeripheralID implements userinput.HandleInput interface.
336+
func (p *Ports) PeripheralID(id plugging.PortID) plugging.PeripheralID {
337+
switch id {
338+
case plugging.PortPanel:
339+
return p.Panel.ID()
340+
case plugging.PortLeftPlayer:
341+
return p.LeftPlayer.ID()
342+
case plugging.PortRightPlayer:
343+
return p.RightPlayer.ID()
344+
}
345+
346+
return plugging.PeriphNone
347+
}
348+
336349
// WriteSWCHx implements the MemoryAccess interface.
337350
func (p *Ports) WriteSWCHx(id plugging.PortID, data uint8) {
338351
switch id {

userinput/controllers.go

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
7070
case "F5":
7171
err = handle.HandleEvent(plugging.PortPanel, ports.PanelTogglePlayer1Pro, nil)
7272

73-
// joystick
73+
// joystick (left player)
7474
case "Left":
7575
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.Left, ports.DataStickTrue)
7676
case "Right":
@@ -82,6 +82,11 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
8282
case "Space":
8383
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.Fire, true)
8484

85+
// joystick (right player)
86+
// * keypad and joystick share some keys (see below for other inputs)
87+
case "J":
88+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Right, ports.DataStickTrue)
89+
8590
// keypad (left player)
8691
case "1", "2", "3":
8792
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.KeypadDown, rune(ev.Key[0]))
@@ -105,6 +110,7 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
105110
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.KeypadDown, '#')
106111

107112
// keypad (right player)
113+
// * keypad and joystick share some keys (see below for other inputs)
108114
case "4":
109115
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '1')
110116
case "5":
@@ -115,20 +121,39 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
115121
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '4')
116122
case "T":
117123
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '5')
118-
case "Y":
119-
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '6')
120-
case "F":
121-
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '7')
122-
case "G":
123-
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '8')
124-
case "H":
125-
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '9')
126124
case "V":
127125
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '*')
128126
case "B":
129127
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '0')
130128
case "N":
131129
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '#')
130+
131+
// keypad (right player) *OR* joystick (right player)
132+
// * keypad and joystick share some keys (see above for other inputs)
133+
case "Y":
134+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
135+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '6')
136+
} else {
137+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Up, ports.DataStickTrue)
138+
}
139+
case "F":
140+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
141+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '7')
142+
} else {
143+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Fire, true)
144+
}
145+
case "G":
146+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
147+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '8')
148+
} else {
149+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Left, ports.DataStickTrue)
150+
}
151+
case "H":
152+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
153+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadDown, '9')
154+
} else {
155+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Down, ports.DataStickTrue)
156+
}
132157
}
133158
} else {
134159
switch ev.Key {
@@ -138,7 +163,7 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
138163
case "F2":
139164
err = handle.HandleEvent(plugging.PortPanel, ports.PanelReset, false)
140165

141-
// josytick
166+
// josytick (left player)
142167
case "Left":
143168
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.Left, ports.DataStickFalse)
144169
case "Right":
@@ -150,13 +175,46 @@ func (c *Controllers) keyboard(ev EventKeyboard, handle HandleInput) error {
150175
case "Space":
151176
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.Fire, false)
152177

178+
// joystick (right player)
179+
// * keypad and joystick share some keys (see below for other inputs)
180+
case "J":
181+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Right, ports.DataStickFalse)
182+
153183
// keyboard (left player)
154184
case "1", "2", "3", "Q", "W", "E", "A", "S", "D", "Z", "X", "C":
155185
err = handle.HandleEvent(plugging.PortLeftPlayer, ports.KeypadUp, nil)
156186

157187
// keyboard (right player)
158-
case "4", "5", "6", "R", "T", "Y", "F", "G", "H", "V", "B", "N":
188+
// * keypad and joystick share some keys (see below for other inputs)
189+
case "4", "5", "6", "R", "T", "V", "B", "N":
159190
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadUp, nil)
191+
192+
// keypad (right player) *OR* joystick (right player)
193+
// * keypad and joystick share some keys (see above for other inputs)
194+
case "Y":
195+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
196+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadUp, nil)
197+
} else {
198+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Up, ports.DataStickFalse)
199+
}
200+
case "F":
201+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
202+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadUp, nil)
203+
} else {
204+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Fire, false)
205+
}
206+
case "G":
207+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
208+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadUp, nil)
209+
} else {
210+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Left, ports.DataStickFalse)
211+
}
212+
case "H":
213+
if handle.PeripheralID(plugging.PortRightPlayer) == plugging.PeriphKeypad {
214+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.KeypadUp, nil)
215+
} else {
216+
err = handle.HandleEvent(plugging.PortRightPlayer, ports.Down, ports.DataStickFalse)
217+
}
160218
}
161219
}
162220

userinput/userinput.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ import (
2222

2323
// HandleInput conceptualises data being sent to the console ports.
2424
type HandleInput interface {
25+
// HandleEvent forwards the Event and EventData to the device connected to the
26+
// specified PortID.
2527
HandleEvent(id plugging.PortID, ev ports.Event, d ports.EventData) error
28+
29+
// PeripheralID identifies the device currently attached to the port.
30+
PeripheralID(id plugging.PortID) plugging.PeripheralID
2631
}

0 commit comments

Comments
 (0)