This file is indexed.

/usr/share/openmsx/scripts/mode.tcl is in openmsx-data 0.8.2-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# TODO mode descriptions are not yet used in any way
# TODO tab completion for the mode setting, so we can remove the hardcoded mentioning of the existing modes

namespace eval mode {

## Mode switching infrastructure

variable modes_info
variable old_mode

proc register {name enter_proc leave_proc description} {
	variable modes_info
	dict set modes_info $name [dict create enter_proc $enter_proc \
	                                       leave_proc $leave_proc \
	                                       description $description]
}

proc mode_changed {name1 name2 op} {
	variable modes_info
	variable old_mode

	set new_mode $::mode
	if {![dict exists $modes_info $new_mode]} {
		# New mode doesn't exist, restore variable and give an error
		set ::mode $old_mode
		error "No such mode: $new_mode. Possible values are: [dict keys $modes_info]"
	}

	# Leave old mode
	eval [dict get $modes_info $old_mode leave_proc]

	# Enter new mode
	eval [dict get $modes_info $new_mode enter_proc]

	set old_mode $new_mode
}



## Define normal mode

proc enter_normal_mode {} {}
proc leave_normal_mode {} {}

register "normal" [namespace code enter_normal_mode] \
                  [namespace code leave_normal_mode] \
         "Mode that is most general purpose."



## Define tas mode

proc enter_tas_mode {} {
	if {![osd exists framecount]} {
		toggle_frame_counter
	}
	if {![osd exists lag_counter]} {
		toggle_lag_counter
	}
	if {![osd exists cursors]} {
		toggle_cursors
	}
	reverse_widgets::enable_reversebar false

	# load/select/save reverse slot
	# Note: this hides the MSX keys 'SELECT' and 'STOP'
	bind_default F6 tas::load_replay_slot
	bind_default F7 tas::open_select_slot_menu
	bind_default F8 tas::save_replay_slot

	# Set up frame advance/reverse
	bind_default END -repeat advance_frame
	bind_default SCROLLOCK -repeat reverse_frame

	puts "WARNING: TAS mode is still very experimental and will almost certainly change next release!"
}

proc leave_tas_mode {} {
	if {[osd exists lag_counter]} {
		toggle_lag_counter
	}
	if {[osd exists framecount]} {
		toggle_frame_counter
	}
	if {[osd exists cursors]} {
		toggle_cursors
	}
	# Leave reverse enabled, including bar

	# Remove reverse slot stuff
	unbind_default F6
	unbind_default F7
	unbind_default F8

	# Remove frame advance/reverse
	unbind_default END
	unbind_default SCROLLOCK
}

register "tas" [namespace code enter_tas_mode] \
               [namespace code leave_tas_mode] \
         "Mode for doing Tool Assisted Speedruns, with TAS widgets and easy ways to save replays."



# Create setting (uses info from registered modes above)

set help_text "This setting switches between different openMSX modes. A mode is a set of settings (mostly keybindings, but also OSD widgets that are activated) that are most suitable for a certain task. Currently these modes exist:"
foreach name [lsort [dict keys $modes_info]] {
	append help_text "\n  $name: [dict get $modes_info $name description]"
}

user_setting create string mode $help_text normal

trace add variable ::mode write [namespace code mode_changed]


## Enter initial mode

set old_mode $::mode
after realtime 0 {eval [dict get $mode::modes_info $::mode enter_proc]}

}