feat(saolei): 交互玩扫雷每一步自动出 PNG
- play_saolei.tcl: k 每执行一个按键动作就存 shots/NNN_<按键>.png,并覆盖 shots/latest.png(在 VS Code 里开着 latest.png 即可每步自动刷新);新增 view 命令 - fb2png.py: 新增 --quiet(只写 PNG 不打印,供脚本批量截图) - tb_saolei*.v: 仅格式调整(case 分支拆行),无语义变化 实测:k cuuuuc -> shots/001_c.png ... 006_c.png,每张 640x480 正常
This commit is contained in:
@@ -16,9 +16,15 @@
|
||||
# k p 只切换插旗模式开关(不点击)
|
||||
# k z 复位(等于重新上电,回到开始界面)
|
||||
# k uucc 可以连写:上、上、点、点
|
||||
# shot 不按键,只重画一遍当前画面
|
||||
# shot 不按键,只重画一遍当前画面 + 存一张 PNG
|
||||
# view 用系统看图器打开最新那张 PNG
|
||||
# help 键位说明
|
||||
#
|
||||
# 截图:k 每执行**一个**按键动作就自动存一张 PNG 到 shots/NNN_<按键>.png
|
||||
# (可以直接放进报告),同时覆盖 shots/latest.png。
|
||||
# 在 VS Code 里打开 shots/latest.png,每次操作后它都会自动刷新 —— 这就是
|
||||
# "每一步都能看到 PNG" 的用法。
|
||||
#
|
||||
# 原理:k 把字符写进 cmd.txt;tb_saolei_play 每 100 us 仿真时间轮询一次并执行按键,
|
||||
# 同时每 1 ms 把显存 dump 到 now.txt;k 再调 fb2png.py --term 把画面画到终端。
|
||||
# 仿真速度大约是 1 ms 仿真时间 = 0.5 s 墙钟,所以每步等 1~2 秒,比真实慢很多,
|
||||
@@ -67,12 +73,38 @@ proc help {} {
|
||||
puts " k u/d/l/r move cursor up/down/left/right (w/s/a/d work too)"
|
||||
puts " k f click in flag mode k p toggle flag switch only"
|
||||
puts " k z reset k uucc several actions at once"
|
||||
puts " shot redraw help this text quit exit"
|
||||
puts " PNG screenshot: py \"$::fb2png\" now.txt shot.png"
|
||||
puts " shot redraw+screenshot view open latest PNG"
|
||||
puts " help this text quit exit"
|
||||
puts " every key saved one PNG: shots/NNN_<key>.png and shots/latest.png"
|
||||
puts " ---------------------------------------------------------------------------"
|
||||
}
|
||||
|
||||
# one step: send the key -> advance simulation -> redraw
|
||||
# ---- every step saves one PNG: shots/001_c.png ... plus shots/latest.png ----
|
||||
set shot_dir "shots"
|
||||
file mkdir $shot_dir
|
||||
set shot_n 0
|
||||
|
||||
proc save_shot {tag} {
|
||||
global fb2png shot_dir
|
||||
if {![file exists "now.txt"]} { return }
|
||||
incr ::shot_n
|
||||
set name [format "%s/%03d_%s.png" $shot_dir $::shot_n $tag]
|
||||
if {[catch { exec py $fb2png --quiet now.txt $name } err]} {
|
||||
puts " (screenshot failed: $err)"
|
||||
return
|
||||
}
|
||||
catch { file copy -force $name "$shot_dir/latest.png" }
|
||||
puts " png -> $name"
|
||||
}
|
||||
|
||||
proc view {} {
|
||||
global shot_dir
|
||||
set f [file normalize "$shot_dir/latest.png"]
|
||||
if {![file exists $f]} { puts " (no screenshot yet)"; return }
|
||||
catch { exec cmd /c start "" $f }
|
||||
}
|
||||
|
||||
# one step: send the key -> advance simulation -> save PNG -> redraw
|
||||
proc k {keys} {
|
||||
set s [string map {" " "c"} [string tolower $keys]]
|
||||
foreach ch [split $s ""] {
|
||||
@@ -80,11 +112,15 @@ proc k {keys} {
|
||||
puts " >> $ch"
|
||||
send_char $ch
|
||||
run 1500 us
|
||||
save_shot $ch
|
||||
}
|
||||
render
|
||||
}
|
||||
|
||||
proc shot {} { render }
|
||||
proc shot {} {
|
||||
save_shot "shot"
|
||||
render
|
||||
}
|
||||
|
||||
# ---- opening: run a little so the start screen is drawn, then show it ----
|
||||
help
|
||||
|
||||
Reference in New Issue
Block a user