OXYGENHUB
◆ main openmsx / share / scripts / _text_echo.tcl
1.2 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
# TODO: add a way to turn this off...
2
3
namespace eval text_echo {
4
5
set_help_text text_echo \
6
{Echoes all characters printed in text mode to stderr, meaning they will appear on the command line that openMSX was started from.
7
}
8
9
variable graph
10
variable escape
11
variable escape_count
12
13
proc text_echo {} {
14
	variable graph 0
15
	variable escape 0
16
	variable escape_count 0
17
	debug set_bp 0x0018 {[pc_in_slot 0 0]} {text_echo::print}
18
	debug set_bp 0x00A2 {[pc_in_slot 0 0]} {text_echo::print}
19
	return ""
20
}
21
22
proc print {} {
23
	variable graph
24
	variable escape
25
	variable escape_count
26
27
	set char [reg A]
28
	if {$graph} {
29
		#puts -nonewline stderr [format "\[G%x\]" $char]
30
		set graph 0
31
	} elseif {$escape} {
32
		#puts -nonewline stderr [format "\[E%x\]" $char]
33
		if {$escape_count == 0} {
34
			if {$char == 0x59} {
35
				set escape_count 2
36
			} else {
37
				set escape_count 1
38
			}
39
		} else {
40
			incr escape_count -1
41
			if {$escape_count == 0} {
42
				set escape 0
43
			}
44
		}
45
	} elseif {$char == 0x01} {
46
		set graph 1
47
	} elseif {$char == 0x1B} {
48
		set escape 1
49
	} elseif {$char == 0x0A || $char >= 0x20} {
50
		puts -nonewline stderr [format %c $char]
51
	} else {
52
		#puts -nonewline stderr [format "\[N%x\]" $char]
53
	}
54
}
55
56
namespace export text_echo
57
58
} ;# namespace text_echo
59
60
namespace import text_echo::*