File: autoplug.tcl

package info (click to toggle)
openmsx 20.0%2Bdfsg-1.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,544 kB
  • sloc: cpp: 236,922; xml: 49,948; tcl: 15,056; python: 5,385; perl: 281; sh: 77; makefile: 53
file content (55 lines) | stat: -rw-r--r-- 1,450 bytes parent folder | download
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
# if this machine has a cassetteport, then automatically plug
# in the cassetteplayer
# always plug in the msxjoysticks, so by default they can be used (with the
# mapping that was set up)

proc get_pluggable_for_connector {connector} {
	set t [plug $connector]
	return [string range $t [string first ": " $t]+2 end]
}

namespace eval autoplug {

proc plug_if_empty {connector pluggable} {
	set plugged [get_pluggable_for_connector $connector]
	if {$plugged eq ""} {
		# only when nothing already plugged
		plug $connector $pluggable
	}
}

proc do_autoplug {} {
	# do not do any auto plug stuff when replaying, because a reset
	# command in the replay will trigger autoplug and will cause the
	# replay to get interrupted with the plug event.
	if {[dict get [reverse status] status] ne "replaying"} {
		set connectors [list]
		catch {
			#can fail when you activate an 'empty' machine
			set connectors [machine_info connector]
		}
		set pluggables [list]
		catch {
			#can fail when you activate an 'empty' machine
			set pluggables [machine_info pluggable]
		}

		# cassette port
		if {"cassetteport" in $connectors} {
			plug_if_empty cassetteport cassetteplayer
		}

		# joystick ports
		if {"joyporta" in $connectors} {
			plug_if_empty joyporta msxjoystick1
		}
		if {"joyportb" in $connectors} {
			plug_if_empty joyportb msxjoystick2
		}
	}
	after boot [namespace code do_autoplug]
}

};# namespace autoplug

after boot autoplug::do_autoplug