OXYGENHUB
◆ main openmsx / share / scripts / _vdp_busy.tcl
1.5 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
namespace eval vdp_busy {
2
3
variable last_executing 0
4
variable executing_time 0
5
variable sample_time 0
6
variable display_time 0
7
variable bp_id
8
variable after_id
9
10
proc reset {} {
11
	variable last_executing 0
12
	variable executing_time 0
13
	sample
14
}
15
16
proc sample {} {
17
	variable last_executing
18
	variable executing_time
19
	variable sample_time
20
	set executing [debug probe read VDP.commandExecuting]
21
	set time [machine_info time]
22
	if {$last_executing} {
23
		set executing_time [expr {$time - $sample_time + $executing_time}]
24
	}
25
	set last_executing $executing
26
	set sample_time $time
27
}
28
29
proc display {} {
30
	variable executing_time
31
	variable display_time
32
	variable sample_time
33
	variable after_id
34
	sample
35
	set percentage [expr {round(100 * $executing_time / ($sample_time - $display_time))}]
36
	set display_time $sample_time
37
	osd configure "vdp_busy.text" -text "$percentage%"
38
	reset
39
	set after_id [after time .25 vdp_busy::display]
40
}
41
42
proc toggle_vdp_busy {} {
43
	variable bp_id
44
	variable after_id
45
	if [info exists bp_id] {
46
		debug probe remove_bp $bp_id
47
		after cancel $after_id
48
		osd destroy "vdp_busy"
49
		unset bp_id
50
		unset after_id
51
	} else {
52
		osd create rectangle "vdp_busy" \
53
			-x 5 -y 30 -w 42 -h 20 -alpha 0x80
54
		osd create text "vdp_busy.text" \
55
			-x 5 -y 3 -rgb 0xffffff
56
		reset
57
		set bp_id [debug probe set_bp VDP.commandExecuting {} vdp_busy::sample]
58
		set after_id [after time .25 vdp_busy::display]
59
	}
60
	return ""
61
}
62
63
namespace export toggle_vdp_busy
64
65
} ;# namespace vdp_busy
66
67
namespace import vdp_busy::*