1 set ::concmdlist [dict create
]
2 set ::concmdhelp [dict create
]
5 proc ::con::showhelp {cn
} {
7 if {[dict exists
$concmdhelp $cn]} {
9 cputs
"\x02$cn: $concmdhelp($cn)"
14 proc ::con::helpcomplete {args
} {
17 set cl
[dict keys
$concmdhelp]
20 if {[llength $args] < 1} {
21 cputs
"\x01help is available for:"
22 foreach cmd
[lsort [dict keys
$concmdhelp]] { cputs
"\x01$cmd" }
23 set lpx
[tcl
::prefix longest
$cl ""]
25 set cmd
[lindex $args 0]
26 if {[dict exists
$concmdhelp $cmd]} {
30 set lst
[tcl
::prefix all
$cl $cmd]
31 if {[llength $lst] == 1} {
32 set lpx
[lindex $lst 0]
33 } elseif
{[llength $lst] > 1} {
34 foreach c
[lsort $lst] { cputs
"\x01$c" }
35 set lpx
[tcl
::prefix longest
$lst $cmd]
46 dict
set concmdlist help
[lambda
{args
} {
49 #cputs "help: <$args>"
50 if {[llength $args] < 2} {
51 cputs
"help is available for:"
52 foreach cn
[dict keys
$concmdhelp] {
56 set cn
[lindex $args 1]
57 if {[dict exists
$concmdhelp $cn]} {
61 # show autocomplete or help
62 set cl
[dict keys
$concmdhelp]
63 set lst
[tcl
::prefix all
$cl $cn]
64 if {[llength $lst] == 1} { tailcall
::con::showhelp $cn }
65 if {[llength $lst] > 1} {
66 set lpx
[tcl
::prefix longest
$lst $cn]
74 proc concmd_simple_command
{cmd args
} {
75 if {[llength $args] > 0} { $cmd {*}$args } else { cputs
"$cmd: [$cmd]" }
78 proc concmd_simple_command_noprint
{cmd args
} {
83 proc concmd_info_command
{cmd args
} {
84 cputs
"$cmd: [$cmd {*}$args]"
88 proc concmdlist-register
{handler lst
} {
89 set len
[llength $lst]
90 for {set idx
0} {$idx < $len} {} {
91 set cn
[lindex $lst $idx]
93 dict
set ::concmdlist $cn $handler
94 if {$idx < $len && [lindex $lst $idx] eq
"-help"} {
97 dict
set ::concmdhelp $cn [string trim
[lindex $lst $idx]]
105 # return result is not printed
106 concmdlist-register concmd_simple_command_noprint
{
107 load -help { load Tcl source }
108 quit
-help { quit ZXEmut
}
109 reset
-help { reset emulator
110 reset
[forced
] [model
] [issue
] [memory] [trdos
]
111 48k
: [issue2|issue3|
2|
3]
112 pentagon
: [128|
512|
1024]
114 snapshot
-help { load or save snapshot
115 snapshot
<load|save
> name
123 tape
-help { tape command ?...?
126 save
filename (not yet
)
134 maxspeed on
/off
/toggle
135 detectloader on
/off
/toggle
136 autopause on
/off
/toggle
138 disk
-help { disk command ?...?
145 boot add
[name
] | remove | replace
[name
]
152 if filename starts with '
[A-D
]:'
153 it means virtual drive number
159 colormode
-help { set color mode
:
161 monochrome
(black-and-white
)
164 brightborder
-help { control pentagon border brighness
166 5|
6|
7: bit of ULA port used to control brightness
170 fldebug
-help { FlashLoad loader detector debugging
178 # return result is printed when the command is called without arguments
179 concmdlist-register concmd_simple_command
{
223 # result is always printed
224 concmdlist-register concmd_info_command
{
232 # this is called from `conexec`
233 # return "done" to stop processing
234 # other return values means "go on"
235 proc conexec_hook
{args
} {
240 proc conexec
{args
} {
242 if {[llength $args] > 0} {
244 set ::con::executing 1
245 if {[conexec_hook
$args] != "done"} {
246 #cputs [lindex $args 0]
247 if {[dict exists
$concmdlist [lindex $args 0]]} {
248 set fn
[dict get
$concmdlist [lindex $args 0]]
249 $fn [lindex $args 0] {*}[lrange $args 1 end
]
251 cputs
"unknown console command: [lindex $args 0]"
255 set ::con::executing 0
261 # called when debugger breakpoint hit
262 # [lindex args 0] is breakpoint type (number)
263 proc breakpointhit
{args
} {
264 # return "stop" or non-zero to activate debugger
265 #cputs "BREAKPOINT HIT! [z80 getreg pc]"
267 #cputs "BREAKPOINT HIT!"
272 # called when a command received from unix socket
274 # "close" to close connection
275 # "done" to indicate that no further processing required
276 # anything else to pass the command to console
277 proc usock_received
{args
} {
282 # called when we need to autocomplete a command
283 proc conexec_ac
{args
} {
284 #cputs "conexec_ac: [llength $args]"
285 #foreach arg $args { cputs " <$arg>" }
286 #set cmd [lindex $args 0]
288 set ::con::autocompletion 1
289 #return [$cmd " ?ac" {*}[lrange $args 1 end]]
290 #return [$cmd {*}[lrange $args 1 end]]
292 #cputs "res: conexec_ac: [llength $res]"
293 #foreach arg $args { cputs " <$arg>" }
297 set ::con::autocompletion 0
302 # this is my first complex function in Tcl; enjoy!
303 proc conautocomplete
{args
} {
307 if {[llength $argl] == 0} { return "" }
309 set cmd
[string map
{* _ ? _ . _
} [lindex $argl 0]]
310 #set lst [dict keys $concmdlist "$cmd*"]
311 set cl
[dict keys
$concmdlist]
312 set lst
[tcl
::prefix all
$cl $cmd]
316 if {[llength $argl] > 1} {
318 if {[llength $lst] == 1} {
319 # call command autocompleter
320 # FIXME: quote list items with spaces
321 set cmd
[lindex $lst 0]
322 if {$cmd eq
"help"} { tailcall
::con::helpcomplete {*}[lrange $argl 1 end
] }
323 return [conexec_ac
$cmd {*}[lrange $argl 1 end
]]
325 # shit! there is no such command!
329 if {[llength $lst] == 1} {
331 set res
[lindex $lst 0]
332 if {[string equal
$res $cmd]} {
333 if {$cmd eq
"help"} { tailcall
::con::helpcomplete {*}[lrange $argl 1 end
] }
334 return [conexec_ac
$cmd {*}[lrange $argl 1 end
]]
341 if {[llength $lst] > 1} {
342 set res
[tcl
::prefix longest
$lst $cmd]
344 foreach ccmd
[lsort $lst] { cputs
"\x01$ccmd" }