aboutsummaryrefslogtreecommitdiff
path: root/cmd/gones
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/gones')
-rw-r--r--cmd/gones/main.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/gones/main.go b/cmd/gones/main.go
index 57b1b6e..0a1fbe7 100644
--- a/cmd/gones/main.go
+++ b/cmd/gones/main.go
@@ -96,6 +96,7 @@ func run(romPath string) error {
}
}
+ console.SetButtons(0, heldButtons())
console.StepFrame()
// UpdateRGBA multiplies the pitch by 4 itself, so this is in pixels, not bytes
@@ -126,3 +127,26 @@ func run(romPath string) error {
}
}
}
+
+// keyboard layout for controller 1
+var keyMap = map[sdl.Scancode]uint8{
+ sdl.SCANCODE_X: nes.ButtonA,
+ sdl.SCANCODE_Y: nes.ButtonB,
+ sdl.SCANCODE_RSHIFT: nes.ButtonSelect,
+ sdl.SCANCODE_RETURN: nes.ButtonStart,
+ sdl.SCANCODE_UP: nes.ButtonUp,
+ sdl.SCANCODE_DOWN: nes.ButtonDown,
+ sdl.SCANCODE_LEFT: nes.ButtonLeft,
+ sdl.SCANCODE_RIGHT: nes.ButtonRight,
+}
+
+func heldButtons() uint8 {
+ keys := sdl.GetKeyboardState()
+ var b uint8
+ for scancode, button := range keyMap {
+ if keys[scancode] != 0 {
+ b |= button
+ }
+ }
+ return b
+}