Skip to content

Commit e94ac81

Browse files
committed
mouse input now affects both paddles in a paddle pair
this undoes a lot of the work done in 5b6afb0 including the removal of the PADDLEA and PADDLEB options
1 parent 536537b commit e94ac81

File tree

6 files changed

+31
-37
lines changed

6 files changed

+31
-37
lines changed

debugger/commands.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,11 +1835,8 @@ func (dbg *Debugger) processTokens(tokens *commandline.Tokens) error {
18351835
dbg.vcs.FingerprintPeripheral(id)
18361836
case "STICK":
18371837
err = dbg.vcs.RIOT.Ports.Plug(id, controllers.NewStick)
1838-
case "PADDLE", "PADDLEA":
1839-
err = dbg.vcs.RIOT.Ports.Plug(id, controllers.NewPaddlePair)
1840-
case "PADDLEB":
1841-
err = dbg.vcs.RIOT.Ports.Plug(id, controllers.NewPaddlePair)
1842-
dbg.controllers.SwappedPaddles(true)
1838+
case "PADDLE":
1839+
err = dbg.vcs.RIOT.Ports.Plug(id, controllers.NewPaddles)
18431840
case "KEYPAD":
18441841
err = dbg.vcs.RIOT.Ports.Plug(id, controllers.NewKeypad)
18451842
case "GAMEPAD":

debugger/commands_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var commandTemplate = []string{
131131
cmdDWARF + " [FUNCTIONS|GLOBALS (DERIVATION)|LOCALS {DERIVATION|RANGES}|FRAMEBASE (DERIVATION)|LINE %<file:line>S|CALLSTACK|CALLERS %<function>S]",
132132

133133
// user input
134-
cmdPeripheral + " ([LEFT|RIGHT] (AUTO|STICK|PADDLE|PADDLEA|PADDLEB|KEYPAD|GAMEPAD|SAVEKEY|ATARIVOX)|SWAP)",
134+
cmdPeripheral + " ([LEFT|RIGHT] (AUTO|STICK|PADDLE|KEYPAD|GAMEPAD|SAVEKEY|ATARIVOX)|SWAP)",
135135
cmdPanel + " (SET [P0PRO|P1PRO|P0AM|P1AM|COL|BW]|TOGGLE [P0|P1|COL]|[HOLD|RELEASE] [SELECT|RESET])",
136136
cmdStick + " [LEFT|RIGHT] [LEFT|RIGHT|UP|DOWN|FIRE|NOLEFT|NORIGHT|NOUP|NODOWN|NOFIRE]",
137137
cmdKeypad + " [LEFT|RIGHT] [NONE|0|1|2|3|4|5|6|7|8|9|*|#]",

hardware/peripherals/controllers/paddle.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ func (pdl *Paddles) HandleEvent(event ports.Event, data ports.EventData) (bool,
193193
}
194194

195195
// handle the incoming data
196-
handle := func(d ports.EventDataPaddle) error {
196+
var handle func(d ports.EventDataPaddle) error
197+
handle = func(d ports.EventDataPaddle) error {
198+
if d.Paddle == -1 {
199+
d.Paddle = 0
200+
_ = handle(d)
201+
d.Paddle = 1
202+
_ = handle(d)
203+
return nil
204+
}
205+
197206
if d.Paddle < 0 || d.Paddle > 1 {
198207
return fmt.Errorf("paddle: %#v: paddle field must be 0 or 1", d)
199208
}

hardware/peripherals/fingerprint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func Fingerprint(port plugging.PortID, loader cartridgeloader.Loader) ports.NewP
6565
}
6666
} else {
6767
if fingerprintPaddle(port, loader) {
68-
return controllers.NewPaddlePair
68+
return controllers.NewPaddles
6969
}
7070
}
7171

hardware/riot/ports/events.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ type EventDataPlayback string
9191
// Event data for stick types.
9292
type EventDataStick string
9393

94-
// Event data for paddle types. The Paddle field indicates which paddle the data refers to.
94+
// Event data for paddle types. The Paddle field indicates which paddle the data refers to. A paddle
95+
// value of -1 indicates that both paddles in the pair are being controlled
9596
//
9697
// Values in the motion field are relative (to the current position) if the Relative field is set to
9798
// true. For non-relative values (ie. absolute values) the value should be scaled to be in the range
9899
// of -32768 and +32767
99100
type EventDataPaddle struct {
100-
Paddle int // 0 or 1
101+
Paddle int // 0 or 1 or -1
101102
Motion int16
102103
Relative bool
103104
}

userinput/controllers.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ const ThumbstickDeadzone = 10000
2525

2626
// Controllers keeps track of hardware userinput options.
2727
type Controllers struct {
28-
inputHandler HandleInput
29-
swappedPorts bool
30-
swappedPaddles bool
28+
inputHandler HandleInput
29+
swappedPorts bool
3130
}
3231

3332
// Controllers is the preferred method of initialisation for the Controllers type.
@@ -42,12 +41,6 @@ func (c *Controllers) SwappedPorts(swapped bool) {
4241
c.swappedPorts = swapped
4342
}
4443

45-
// SwappedPaddles is similar to SwapperPorts but affects which paddle of a paddle pair is to be
46-
// controlled by user input
47-
func (c *Controllers) SwappedPaddles(swapped bool) {
48-
c.swappedPaddles = swapped
49-
}
50-
5144
// handlePortSwap returns the required PortID relative to the supplied PortID if the
5245
// controls have been swapped
5346
func (c Controllers) handlePortSwap(port plugging.PortID) plugging.PortID {
@@ -62,14 +55,6 @@ func (c Controllers) handlePortSwap(port plugging.PortID) plugging.PortID {
6255
return port
6356
}
6457

65-
// handlePaddleSwap returns the required paddle number according to whether the player
66-
func (c Controllers) handlePaddleSwap() int {
67-
if c.swappedPaddles {
68-
return 1
69-
}
70-
return 0
71-
}
72-
7358
// handleEvents sends the port/event information to each HandleInput
7459
// implementation.
7560
//
@@ -102,7 +87,7 @@ func (c *Controllers) mouseMotion(ev EventMouseMotion) (bool, error) {
10287
}
10388

10489
return c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.PaddleSet, ports.EventDataPaddle{
105-
Paddle: c.handlePaddleSwap(),
90+
Paddle: -1,
10691
Motion: motion,
10792
Relative: true,
10893
})
@@ -112,17 +97,19 @@ func (c *Controllers) mouseButton(ev EventMouseButton) (bool, error) {
11297
switch ev.Button {
11398
case MouseButtonLeft:
11499
if ev.Down {
115-
if c.swappedPaddles {
116-
return c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.SecondFire, true)
117-
} else {
118-
return c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.Fire, true)
100+
a, err := c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.Fire, true)
101+
if err != nil {
102+
return false, err
119103
}
104+
b, err := c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.SecondFire, true)
105+
return a && b, err
120106
} else {
121-
if c.swappedPaddles {
122-
return c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.SecondFire, false)
123-
} else {
124-
return c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.Fire, false)
107+
a, err := c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.Fire, false)
108+
if err != nil {
109+
return false, err
125110
}
111+
b, err := c.handleEvents(c.handlePortSwap(plugging.PortLeft), ports.SecondFire, false)
112+
return a && b, err
126113
}
127114
}
128115

@@ -464,7 +451,7 @@ func (c *Controllers) stelladaptor(ev EventStelladaptor) (bool, error) {
464451

465452
case plugging.PeriphPaddles:
466453
return c.handleEvents(c.handlePortSwap(ev.ID), ports.PaddleSet, ports.EventDataPaddle{
467-
Paddle: c.handlePaddleSwap(),
454+
Paddle: -1,
468455
Motion: -ev.Horiz - 1,
469456
})
470457
}

0 commit comments

Comments
 (0)