OXYGENHUB
◆ main openmsx / share / scripts / trace.tcl
2.1 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
1
namespace eval trace {
2
3
# vdpcmdtrace
4
5
user_setting create boolean vdpcmdtrace "VDP command tracing on/off" false
6
7
proc trace_vdpcmd {} {
8
	set cmd [debug probe read "VDP.command"]
9
	if {$cmd eq ""} return
10
	puts stderr $cmd
11
}
12
13
variable probe_bp_id
14
proc vdp_setting_changed {name1 name2 op} {
15
	variable probe_bp_id
16
17
	if {$::vdpcmdtrace} {;# setting changed from disabled to enabled
18
		set probe_bp_id [debug probe set_bp "VDP.command" 1 [namespace code trace_vdpcmd]]
19
	} else { ;# setting changed from enabled to disabled
20
		catch { debug probe remove_bp $probe_bp_id }
21
	}
22
}
23
24
trace add variable ::vdpcmdtrace "write" [namespace code vdp_setting_changed]
25
vdp_setting_changed ::vdpcmdtrace {} write
26
27
# cputrace
28
29
user_setting create boolean my_cputrace "CPU tracing on/off" false
30
31
# Note: this prints the instruction and register values from *before* that
32
# instruction has executed. This is different from earlier openMSX version
33
# (which already showed update register values).
34
# Both conventions are used in tracing, but the current one is more common.
35
proc trace_cpu {} {
36
	# This reads 8 16-bit registers and formats them as hex.
37
	# The obvious way would be via '[reg nn]' and '[format %04x ..]'.
38
	# But benchmarking showed this way is significantly faster.
39
	set hex [binary encode hex [debug read_block "CPU regs" 0 24]]
40
	set af [string range $hex  0  3]
41
	set bc [string range $hex  4  7]
42
	set de [string range $hex  8 11]
43
	set hl [string range $hex 12 15]
44
	set ix [string range $hex 32 35]
45
	set iy [string range $hex 36 39]
46
	set pc [string range $hex 40 43]
47
	set sp [string range $hex 44 47]
48
	set instr [lindex [debug disasm "0x$pc"] 0]
49
	puts stderr "$pc : $instr AF=$af BC=$bc DE=$de HL=$hl IX=$ix IY=$iy SP=$sp"
50
}
51
52
variable cond_id
53
proc cpu_setting_changed {name1 name2 op} {
54
	variable cond_id
55
56
	if {$::my_cputrace} {;# setting changed from disabled to enabled
57
		set cond_id [debug condition create -command [namespace code trace_cpu]]
58
	} else { ;# setting changed from enabled to disabled
59
		catch { debug condition remove $cond_id }
60
	}
61
}
62
trace add variable ::my_cputrace "write" [namespace code cpu_setting_changed]
63
cpu_setting_changed ::my_cputrace {} write
64
65
} ;# namespace eval trace