OXYGENHUB
◆ main openmsx / share / scripts / autoplug.tcl
1.4 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
# if this machine has a cassetteport, then automatically plug
2
# in the cassetteplayer
3
# always plug in the msxjoysticks, so by default they can be used (with the
4
# mapping that was set up)
5
6
proc get_pluggable_for_connector {connector} {
7
	set t [plug $connector]
8
	return [string range $t [string first ": " $t]+2 end]
9
}
10
11
namespace eval autoplug {
12
13
proc plug_if_empty {connector pluggable} {
14
	set plugged [get_pluggable_for_connector $connector]
15
	if {$plugged eq ""} {
16
		# only when nothing already plugged
17
		plug $connector $pluggable
18
	}
19
}
20
21
proc do_autoplug {} {
22
	# do not do any auto plug stuff when replaying, because a reset
23
	# command in the replay will trigger autoplug and will cause the
24
	# replay to get interrupted with the plug event.
25
	if {[dict get [reverse status] status] ne "replaying"} {
26
		set connectors [list]
27
		catch {
28
			#can fail when you activate an 'empty' machine
29
			set connectors [machine_info connector]
30
		}
31
		set pluggables [list]
32
		catch {
33
			#can fail when you activate an 'empty' machine
34
			set pluggables [machine_info pluggable]
35
		}
36
37
		# cassette port
38
		if {"cassetteport" in $connectors} {
39
			plug_if_empty cassetteport cassetteplayer
40
		}
41
42
		# joystick ports
43
		if {"joyporta" in $connectors} {
44
			plug_if_empty joyporta msxjoystick1
45
		}
46
		if {"joyportb" in $connectors} {
47
			plug_if_empty joyportb msxjoystick2
48
		}
49
	}
50
	after boot [namespace code do_autoplug]
51
}
52
53
};# namespace autoplug
54
55
after boot autoplug::do_autoplug