shithub: rc

Download patch

ref: e3dc64f9404e3100f5ef0f8bdbe1cf549450d999
parent: 21eb04d20dc0b71e10e25d70e9d9bad618f2db85
author: qwx <qwx@sciops.net>
date: Tue Aug 31 18:01:43 EDT 2021

add joy: universal joy script, remove joynes/gba, update wrappers

--- a/bin/2600
+++ b/bin/2600
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba | {games/2600 -a $*(3-) || games/2600 $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy | {games/2600 -a $*(3-) || games/2600 $*(3-)}
 if not
 	games/2600 -a $* || games/2600 $*
--- a/bin/gba
+++ b/bin/gba
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba | {games/gba -a $*(3-) || games/gba $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy | {games/gba -a $*(3-) || games/gba $*(3-)}
 if not
 	games/gba -a $* || games/gba $*
--- a/bin/gbc
+++ b/bin/gbc
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba | {games/gb -a $*(3-) || games/gb $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy | {games/gb -a $*(3-) || games/gb $*(3-)}
 if not
 	games/gb -a $* || games/gb $*
--- /dev/null
+++ b/bin/joy
@@ -1,0 +1,39 @@
+#!/bin/rc
+# usage: nusb/joy epX.Y | joy [1|2]
+~ $#* 0 && *=''
+awk -safe -v 'joy='$1 '
+	/^axis 0 0/   { k[0] = "left " }
+	/^axis 0 255/ { k[0] = "right " }
+	/^axis 0 128/ { k[0] = "" }
+
+	/^axis 1 0/   { k[1] = "up " }
+	/^axis 1 255/ { k[1] = "down " }
+	/^axis 1 128/ { k[1] = "" }
+
+	/^down 1$/ { k[3] = "b " }
+	/^down 5$/ { k[2] = "a " }
+	/^down 6$/ { k[8] = "x " }
+	/^down 2$/ { k[9] = "y " }
+	/^down 3$/ { k[4] = "control " }
+	/^down 4$/ { k[5] = "start " }
+	/^down 7$/ { k[6] = "l1 " }
+	/^down 8$/ { k[7] = "r1 " }
+
+	/^up 1$/ { k[3] = "" }
+	/^up 5$/ { k[2] = "" }
+	/^up 6$/ { k[8] = "" }
+	/^up 2$/ { k[9] = "" }
+	/^up 3$/ { k[4] = "" }
+	/^up 4$/ { k[5] = "" }
+	/^up 7$/ { k[6] = "" }
+	/^up 8$/ { k[7] = "" }
+
+	{
+		if(joy != "")
+			printf "joy%s ", joy
+		for(i in k)
+			printf k[i]
+		printf "\n"
+		fflush
+	}
+'
--- a/bin/joygba
+++ /dev/null
@@ -1,37 +1,0 @@
-#!/bin/rc
-# run as "nusb/joy epX.Y | joygba"
-
-awk -safe '
-	BEGIN { k[0] = "" }
-
-	/^axis 0 0/   { k[0] = "left " }
-	/^axis 0 255/ { k[0] = "right " }
-	/^axis 0 128/ { k[0] = "" }
-
-	/^axis 1 0/   { k[1] = "up " }
-	/^axis 1 255/ { k[1] = "down " }
-	/^axis 1 128/ { k[1] = "" }
-
-	/^down 1$/ { k[3] = "b " }
-	/^down 5$/ { k[2] = "a " }
-	/^down 6$/ { k[8] = "x " }
-	/^down 2$/ { k[9] = "y " }
-	/^down 3$/ { k[4] = "control " }
-	/^down 4$/ { k[5] = "start " }
-	/^down 7$/ { k[6] = "l1 " }
-	/^down 8$/ { k[7] = "r1 " }
-
-	/^up 1$/ { k[3] = "" }
-	/^up 5$/ { k[2] = "" }
-	/^up 6$/ { k[8] = "" }
-	/^up 2$/ { k[9] = "" }
-	/^up 3$/ { k[4] = "" }
-	/^up 4$/ { k[5] = "" }
-	/^up 7$/ { k[6] = "" }
-	/^up 8$/ { k[7] = "" }
-
-	{
-		print k[0] k[1] k[2] k[3] k[4] k[5] k[6] k[7] k[8] k[9]
-		fflush
-	}
-'
--- a/bin/joynes
+++ /dev/null
@@ -1,33 +1,0 @@
-#!/bin/rc
-# run as "nusb/joy epX.Y | joynes N", where N=[1,2]
-
-awk -safe -v 'joy='joy$1 '
-	BEGIN { k[0] = "" }
-
-	/^axis 0 0/   { k[0] = "left " }
-	/^axis 0 255/ { k[0] = "right " }
-	/^axis 0 128/ { k[0] = "" }
-
-	/^axis 1 0/   { k[1] = "up " }
-	/^axis 1 255/ { k[1] = "down " }
-	/^axis 1 128/ { k[1] = "" }
-
-	/^down 2$/ { k[3] = "b " }
-	/^down 1$/ { k[2] = "a " }
-	#/^down 3$/ { k[4] = "control " }
-	#/^down 4$/ { k[5] = "start " }
-	/^down 7$/ { k[4] = "control " }
-	/^down 8$/ { k[5] = "start " }
-
-	/^up 2$/ { k[3] = "" }
-	/^up 1$/ { k[2] = "" }
-	#/^up 3$/ { k[4] = "" }
-	#/^up 4$/ { k[5] = "" }
-	/^up 7$/ { k[4] = "" }
-	/^up 8$/ { k[5] = "" }
-
-	{
-		print joy " " k[0] k[1] k[2] k[3] k[4] k[5]
-		fflush
-	}
-'
--- a/bin/md
+++ b/bin/md
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba | {games/md -a $*(3-) || games/md $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy | {games/md -a $*(3-) || games/md $*(3-)}
 if not
 	games/md -a $* || games/md $*
--- a/bin/nes
+++ b/bin/nes
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba 1 | {games/nes -a $*(3-) || games/nes $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy 1 | {games/nes -a $*(3-) || games/nes $*(3-)}
 if not
 	games/nes -a $* || games/nes $*
--- a/bin/snes
+++ b/bin/snes
@@ -10,6 +10,6 @@
 	}'
 } >/dev/wctl
 if(~ $1 -j)
-	nusb/joy /dev/usb/ep^$2^.0 | joygba | {games/snes -a $*(3-) || games/snes $*(3-)}
+	nusb/joy /dev/usb/ep^$2^.0 | joy | {games/snes -a $*(3-) || games/snes $*(3-)}
 if not
 	games/snes -a $* || games/snes $*