summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/ledutil.sh
blob: 05694d6b9b7f7efa458517b9cc0a412da9f83361 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh

# ============================================================
# 
#   ledutil.sh - Example script for output notifiers
# 
#   Copyright Nicola Salmoria and the MAME Team.
#   Visit http://mamedev.org for licensing and usage restrictions.
#
#   This is a very basic implementation which
#
#   a) Sets kbd leds if led0, led1, led2 is received
#   b) Beeps if led0 is set to on (state=1)
#   c) Writes a message when pause is received
# 
#   use "sh ledutil.sh -h" to get more information
#
# ============================================================

SDLMAME_OUTPUT=/tmp/sdlmame_out

verbose=0
autoclose=0
myname=`basename $0`
paused=0

while [ $# -gt 0 ]; do
	case $1 in
		-v)
		  	verbose=1
			;;
		-a)
			autoclose=1
			;;
		-h)
			echo "Usage: $myname [-a] [-v]"
			echo ""
			echo "  -a   Automatically close when sdlmame ends game" 
			echo "  -v   LOG all messages received"
			echo "  -h   Get help"
			echo ""
			exit
			;; 
		*)
			echo "$myname: invalid option $1"
			echo "Try \`$myname -h' for more information."
			exit
			;;
	esac
	shift
done

if [ ! -e ${SDLMAME_OUTPUT} ]; then
  mkfifo ${SDLMAME_OUTPUT}
fi

while true; do
	cat  ${SDLMAME_OUTPUT} | while read class pidnum what state; do
		[ $verbose = 1 ] && echo LOG: $class $pidnum $what $state
		if [ "$class" = "MAME" ]; then
			case "$what" in
				START)
					echo Process $pidnum starting game $state
					paused=0
					;;
				STOP)
					echo Process $pidnum stopping game $state
					;;
			esac
		fi
		if [ "$class" = "OUT" ]; then
			case "$what" in
				led0)
					[ "$state" = 1 ] && beep
					[ "$state" = 1 ] && xset led 1
					[ "$state" = 0 ] && xset -led 1
					;;
				led1)
					[ "$state" = 1 ] && xset led 2
					[ "$state" = 0 ] && xset -led 2
					;;
				led2)
					[ "$state" = 1 ] && xset led 3
					[ "$state" = 0 ] && xset -led 3
					;;
				pause)
					paused=$state
					echo Pause $paused!
					;;
			esac
		fi	
	done
	[ $autoclose = 1 ] && break;
done

rm -f ${SDLMAME_OUTPUT}